Add transfer amounts and active gas vents
This commit is contained in:
parent
31ebfa905e
commit
e4df9bc41a
8 changed files with 147 additions and 12 deletions
|
|
@ -5,12 +5,14 @@ extends Control
|
|||
# fleet on the left, the current building on the right. Horizontal arrows
|
||||
# make the result of a press visible before the player commits to it.
|
||||
|
||||
signal transfer_requested(resource_type: String, to_building: bool)
|
||||
signal transfer_requested(resource_type: String, to_building: bool, amount: int)
|
||||
|
||||
const HEADER_HEIGHT: float = 58.0
|
||||
const FLEET_COLOR: Color = Color(1.0, 0.78, 0.25)
|
||||
const LOCAL_COLOR: Color = Color(0.45, 0.9, 0.55)
|
||||
const RULE_COLOR: Color = Color(0.18, 0.38, 0.52)
|
||||
const ALL_AMOUNT: int = 1 << 30
|
||||
const AMOUNT_OPTIONS: Array[int] = [1, 5, 25, ALL_AMOUNT]
|
||||
|
||||
var building_id: int = 0
|
||||
var _destination_heading: Label
|
||||
|
|
@ -46,7 +48,7 @@ func _ready() -> void:
|
|||
unload.glow_color = colour
|
||||
unload.pressed.connect(_request_transfer.bind(resource_type, true))
|
||||
add_child(unload)
|
||||
var unload_label := _make_label("UNLOAD ALL →", 20, colour)
|
||||
var unload_label := _make_label("UNLOAD →", 20, colour)
|
||||
unload_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
add_child(unload_label)
|
||||
|
||||
|
|
@ -56,15 +58,37 @@ func _ready() -> void:
|
|||
load.glow_color = colour
|
||||
load.pressed.connect(_request_transfer.bind(resource_type, false))
|
||||
add_child(load)
|
||||
var load_label := _make_label("← LOAD ALL", 20, colour)
|
||||
var load_label := _make_label("← LOAD", 20, colour)
|
||||
load_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
add_child(load_label)
|
||||
|
||||
var decrease := IconButton.new()
|
||||
decrease.name = "%sDecreaseButton" % GameState.resource_name(resource_type)
|
||||
decrease.icon = IconButton.Icon.MINUS
|
||||
decrease.glow_color = colour
|
||||
decrease.pressed.connect(_change_amount.bind(resource_type, -1))
|
||||
add_child(decrease)
|
||||
var amount_label := _make_label("ALL", 24, colour)
|
||||
amount_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
add_child(amount_label)
|
||||
var increase := IconButton.new()
|
||||
increase.name = "%sIncreaseButton" % GameState.resource_name(resource_type)
|
||||
increase.icon = IconButton.Icon.PLUS
|
||||
increase.glow_color = colour
|
||||
increase.pressed.connect(_change_amount.bind(resource_type, 1))
|
||||
add_child(increase)
|
||||
var amount_caption := _make_label("AMOUNT", 16, Color(0.62, 0.78, 0.86))
|
||||
amount_caption.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
add_child(amount_caption)
|
||||
|
||||
_rows[resource_type] = {
|
||||
"glyph": glyph, "name": name_label,
|
||||
"fleet_amount": fleet_amount, "local_amount": local_amount,
|
||||
"unload": unload, "unload_label": unload_label,
|
||||
"load": load, "load_label": load_label,
|
||||
"decrease": decrease, "amount_label": amount_label,
|
||||
"increase": increase, "amount_caption": amount_caption,
|
||||
"amount_index": AMOUNT_OPTIONS.size() - 1,
|
||||
}
|
||||
|
||||
resized.connect(_layout)
|
||||
|
|
@ -83,7 +107,29 @@ func _make_label(text_value: String, font_size: int, colour: Color) -> Label:
|
|||
|
||||
|
||||
func _request_transfer(resource_type: String, to_building: bool) -> void:
|
||||
transfer_requested.emit(resource_type, to_building)
|
||||
var row: Dictionary = _rows.get(resource_type, {})
|
||||
if row.is_empty():
|
||||
return
|
||||
transfer_requested.emit(resource_type, to_building,
|
||||
AMOUNT_OPTIONS[int(row.amount_index)])
|
||||
|
||||
|
||||
func _change_amount(resource_type: String, direction: int) -> void:
|
||||
var row: Dictionary = _rows.get(resource_type, {})
|
||||
if row.is_empty():
|
||||
return
|
||||
row.amount_index = clampi(int(row.amount_index) + direction, 0, AMOUNT_OPTIONS.size() - 1)
|
||||
_refresh_amount_controls(row)
|
||||
|
||||
|
||||
func _refresh_amount_controls(row: Dictionary) -> void:
|
||||
var index: int = int(row.amount_index)
|
||||
var amount: int = AMOUNT_OPTIONS[index]
|
||||
row.amount_label.text = "ALL" if amount == ALL_AMOUNT else str(amount)
|
||||
row.decrease.enabled = index > 0
|
||||
row.increase.enabled = index < AMOUNT_OPTIONS.size() - 1
|
||||
row.decrease.queue_redraw()
|
||||
row.increase.queue_redraw()
|
||||
|
||||
|
||||
func set_destination(id: int, heading: String) -> void:
|
||||
|
|
@ -106,6 +152,7 @@ func refresh() -> void:
|
|||
row.load.enabled = local_amount > 0
|
||||
row.unload.queue_redraw()
|
||||
row.load.queue_redraw()
|
||||
_refresh_amount_controls(row)
|
||||
|
||||
|
||||
func _layout() -> void:
|
||||
|
|
@ -147,6 +194,17 @@ func _layout() -> void:
|
|||
row.unload_label.size = Vector2(side_width, 36.0)
|
||||
row.load_label.position = Vector2(right_x, caption_y)
|
||||
row.load_label.size = Vector2(side_width, 36.0)
|
||||
|
||||
var selector_size: float = minf(54.0, centre_width * 0.29)
|
||||
var selector_y: float = y + 126.0
|
||||
row.decrease.position = Vector2(side_width + 2.0, selector_y)
|
||||
row.decrease.size = Vector2(selector_size, selector_size)
|
||||
row.increase.position = Vector2(right_x - selector_size - 2.0, selector_y)
|
||||
row.increase.size = Vector2(selector_size, selector_size)
|
||||
row.amount_label.position = Vector2(side_width + selector_size + 2.0, selector_y)
|
||||
row.amount_label.size = Vector2(centre_width - selector_size * 2.0 - 4.0, selector_size)
|
||||
row.amount_caption.position = Vector2(side_width, selector_y + selector_size + 2.0)
|
||||
row.amount_caption.size = Vector2(centre_width, 30.0)
|
||||
row_index += 1
|
||||
queue_redraw()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue