Refactor multi-resource UI and transfers
This commit is contained in:
parent
af5e08e5a1
commit
8231e165ff
20 changed files with 648 additions and 435 deletions
|
|
@ -125,25 +125,14 @@ var lab_building_id: int = 0
|
|||
@onready var transfer_menu: Control = get_node("../UI/TransferMenu")
|
||||
@onready var transfer_status: Label = get_node("../UI/TransferMenu/StatusLabel")
|
||||
@onready var transfer_close_button: IconButton = get_node("../UI/TransferMenu/CloseButton")
|
||||
@onready var to_building_label: Label = get_node("../UI/TransferMenu/ToBuildingLabel")
|
||||
@onready var to_building_batch_button: IconButton = get_node("../UI/TransferMenu/ToBuildingBatchButton")
|
||||
@onready var to_building_batch_label: Label = get_node("../UI/TransferMenu/ToBuildingBatchLabel")
|
||||
@onready var to_building_all_label: Label = get_node("../UI/TransferMenu/ToBuildingAllLabel")
|
||||
@onready var to_building_all_button: IconButton = get_node("../UI/TransferMenu/ToBuildingAllButton")
|
||||
@onready var to_fleet_label: Label = get_node("../UI/TransferMenu/ToFleetLabel")
|
||||
@onready var to_fleet_batch_button: IconButton = get_node("../UI/TransferMenu/ToFleetBatchButton")
|
||||
@onready var to_fleet_batch_label: Label = get_node("../UI/TransferMenu/ToFleetBatchLabel")
|
||||
@onready var to_fleet_all_label: Label = get_node("../UI/TransferMenu/ToFleetAllLabel")
|
||||
@onready var to_fleet_all_button: IconButton = get_node("../UI/TransferMenu/ToFleetAllButton")
|
||||
@onready var gas_to_building_button: IconButton = get_node("../UI/TransferMenu/GasToBuildingButton")
|
||||
@onready var gas_to_fleet_button: IconButton = get_node("../UI/TransferMenu/GasToFleetButton")
|
||||
@onready var transfer_list: ResourceTransferList = get_node("../UI/TransferMenu/ResourceList")
|
||||
|
||||
# Every building menu carries the same header (#24). Held as a list because
|
||||
# the only thing any of them needs is to be told which building it is
|
||||
# reporting on when its panel opens.
|
||||
@onready var resource_bars: Array = [
|
||||
get_node("../UI/CraftMenu/Bar"), get_node("../UI/SkillMenu/Bar"),
|
||||
get_node("../UI/LabMenu/Bar"), get_node("../UI/TransferMenu/Bar"),
|
||||
get_node("../UI/LabMenu/Bar"),
|
||||
]
|
||||
|
||||
@onready var skill_menu: Control = get_node("../UI/SkillMenu")
|
||||
|
|
@ -253,12 +242,7 @@ func _ready() -> void:
|
|||
for i in range(queue_slots.size()):
|
||||
queue_slots[i].pressed.connect(_on_queue_slot.bind(i))
|
||||
transfer_close_button.pressed.connect(func(): transfer_menu.visible = false)
|
||||
to_building_batch_button.pressed.connect(_on_transfer.bind(true, GameState.CARGO_LOAD_BATCH))
|
||||
to_building_all_button.pressed.connect(_on_transfer.bind(true, ALL))
|
||||
to_fleet_batch_button.pressed.connect(_on_transfer.bind(false, GameState.CARGO_LOAD_BATCH))
|
||||
to_fleet_all_button.pressed.connect(_on_transfer.bind(false, ALL))
|
||||
gas_to_building_button.pressed.connect(_on_gas_transfer.bind(true))
|
||||
gas_to_fleet_button.pressed.connect(_on_gas_transfer.bind(false))
|
||||
transfer_list.transfer_requested.connect(_on_resource_transfer)
|
||||
|
||||
formation_close_button.pressed.connect(func(): formation_menu.visible = false)
|
||||
formation_reset_button.pressed.connect(_on_reset_formation)
|
||||
|
|
@ -978,40 +962,45 @@ func _on_transfer_pressed() -> void:
|
|||
if current_building == null:
|
||||
return
|
||||
transfer_building_id = current_building.building_id
|
||||
for bar in resource_bars:
|
||||
bar.building_id = transfer_building_id
|
||||
transfer_menu.visible = true
|
||||
transfer_status.text = ""
|
||||
_refresh_transfer()
|
||||
|
||||
|
||||
func _on_transfer(to_building: bool, amount: int) -> void:
|
||||
_on_resource_transfer(GameState.RESOURCE_ORE, to_building, amount)
|
||||
|
||||
|
||||
func _on_resource_transfer(resource_type: String, to_building: bool, amount: int = ALL) -> void:
|
||||
if transfer_building_id == 0:
|
||||
transfer_status.text = "No building selected - reopen this panel from the building"
|
||||
return
|
||||
|
||||
var moved: int = 0
|
||||
if to_building:
|
||||
moved = GameState.transfer_to_building(transfer_building_id, amount)
|
||||
else:
|
||||
moved = GameState.transfer_to_fleet(transfer_building_id, amount)
|
||||
var moved: int = GameState.transfer_resource_to_building(
|
||||
transfer_building_id, resource_type, amount
|
||||
) if to_building else GameState.transfer_resource_to_fleet(
|
||||
transfer_building_id, resource_type, amount
|
||||
)
|
||||
var resource_name: String = GameState.resource_name(resource_type).to_lower()
|
||||
|
||||
# Nothing moving is the common case at an empty end, and a silent no-op
|
||||
# is the dead-button problem this panel exists to remove. Say which side
|
||||
# was empty rather than just refusing.
|
||||
if moved <= 0:
|
||||
if to_building:
|
||||
transfer_status.text = "The fleet is carrying nothing to unload"
|
||||
transfer_status.text = "The fleet is carrying nothing to unload (no %s)" % resource_name
|
||||
else:
|
||||
transfer_status.text = "%s has no ore to load" % _transfer_place_name()
|
||||
transfer_status.text = "%s has no %s to load" % [_transfer_place_name().capitalize(), resource_name]
|
||||
elif to_building:
|
||||
transfer_status.text = "Moved %d ore into %s" % [moved, _transfer_place_name()]
|
||||
transfer_status.text = "Moved %d %s into %s" % [moved, resource_name, _transfer_place_name()]
|
||||
else:
|
||||
transfer_status.text = "Loaded %d ore into the fleet" % moved
|
||||
transfer_status.text = "Loaded %d %s into the fleet" % [moved, resource_name]
|
||||
_refresh_transfer()
|
||||
|
||||
func _on_gas_transfer(to_building: bool) -> void:
|
||||
var moved: int = GameState.transfer_gas_to_building(transfer_building_id, ALL) if to_building else GameState.transfer_gas_to_fleet(transfer_building_id, ALL)
|
||||
transfer_status.text = "Moved %d gas" % moved if moved > 0 else "No gas available on that side"
|
||||
_refresh_transfer()
|
||||
_on_resource_transfer(GameState.RESOURCE_GAS, to_building)
|
||||
|
||||
|
||||
func _transfer_place_name() -> String:
|
||||
|
|
@ -1026,38 +1015,11 @@ func _transfer_place_name() -> String:
|
|||
|
||||
|
||||
func _refresh_transfer() -> void:
|
||||
for bar in resource_bars:
|
||||
bar.building_id = transfer_building_id
|
||||
|
||||
var hold: int = GameState.fleet_cargo
|
||||
var here: int = GameState.building_holdings(transfer_building_id)
|
||||
var batch: int = GameState.CARGO_LOAD_BATCH
|
||||
|
||||
to_building_label.text = "ORE"
|
||||
to_fleet_label.text = "GAS"
|
||||
to_building_batch_button.visible = false
|
||||
to_building_batch_label.visible = false
|
||||
to_fleet_batch_button.visible = false
|
||||
to_fleet_batch_label.visible = false
|
||||
to_building_all_label.text = "Unload all"
|
||||
to_fleet_all_label.text = "Load all"
|
||||
# The batch buttons say what they would actually move, not the nominal
|
||||
# batch size: offering "25" when the hold has 4 in it is a promise the
|
||||
# press cannot keep.
|
||||
to_building_batch_label.text = "%d" % mini(batch, hold)
|
||||
to_fleet_batch_label.text = "%d" % mini(batch, here)
|
||||
|
||||
to_building_batch_button.enabled = hold > 0
|
||||
to_building_all_button.enabled = hold > 0
|
||||
to_fleet_batch_button.enabled = here > 0
|
||||
to_fleet_all_button.enabled = here > 0
|
||||
for button in [to_building_batch_button, to_building_all_button,
|
||||
to_fleet_batch_button, to_fleet_all_button]:
|
||||
button.queue_redraw()
|
||||
gas_to_building_button.enabled = GameState.fleet_gas_cargo > 0
|
||||
gas_to_fleet_button.enabled = GameState.building_gas_holdings(transfer_building_id) > 0
|
||||
gas_to_building_button.queue_redraw()
|
||||
gas_to_fleet_button.queue_redraw()
|
||||
var building: Dictionary = GameState.find_building(transfer_building_id)
|
||||
var heading: String = "This building"
|
||||
if not building.is_empty() and building.type == GameState.BUILDING_MOTHERSHIP:
|
||||
heading = "Mothership bank"
|
||||
transfer_list.set_destination(transfer_building_id, heading)
|
||||
|
||||
|
||||
func _refresh_queue() -> void:
|
||||
|
|
|
|||
Loading…
Reference in a new issue