Add manual extractor resource transfers
This commit is contained in:
parent
e2d4297ee5
commit
db0e6a0ec2
7 changed files with 180 additions and 14 deletions
|
|
@ -159,9 +159,12 @@ var craft_message_until: int = 0
|
|||
# current_building while any menu is open, so by the next frame the panel
|
||||
# would not know which building it belongs to.
|
||||
var transfer_building_id: int = 0
|
||||
var transfer_extractor_index: int = -1
|
||||
|
||||
var current_building: Node2D = null
|
||||
var pending_building: Node2D = null
|
||||
var current_extractor_index: int = -1
|
||||
var pending_extractor_index: int = -1
|
||||
var pending_time: float = 0.0
|
||||
var context_actions_expanded: bool = false
|
||||
|
||||
|
|
@ -304,6 +307,8 @@ func _process(delta: float) -> void:
|
|||
or transfer_menu.visible or hangar_menu.visible:
|
||||
current_building = null
|
||||
pending_building = null
|
||||
current_extractor_index = -1
|
||||
pending_extractor_index = -1
|
||||
action_button.visible = false
|
||||
building_action_button.visible = false
|
||||
transfer_button.visible = false
|
||||
|
|
@ -314,17 +319,25 @@ func _process(delta: float) -> void:
|
|||
# Debounced exactly like the enter-atmosphere prompt, so the action
|
||||
# button can't flicker while the fleet drifts on the interact boundary.
|
||||
var detected: Node2D = building_field.get_building_fleet_is_on()
|
||||
var detected_extractor: int = -1
|
||||
if detected == null:
|
||||
var planet: Node2D = _planet_under_fleet()
|
||||
if planet != null:
|
||||
detected_extractor = GameState.extractor_index_at(planet.planet_id)
|
||||
|
||||
if detected != pending_building:
|
||||
if detected != pending_building or detected_extractor != pending_extractor_index:
|
||||
pending_building = detected
|
||||
pending_extractor_index = detected_extractor
|
||||
pending_time = 0.0
|
||||
else:
|
||||
pending_time += delta
|
||||
|
||||
if pending_time < prompt_debounce_time or pending_building == current_building:
|
||||
if pending_time < prompt_debounce_time or (pending_building == current_building \
|
||||
and pending_extractor_index == current_extractor_index):
|
||||
return
|
||||
|
||||
current_building = pending_building
|
||||
current_extractor_index = pending_extractor_index
|
||||
context_actions_expanded = false
|
||||
hangar_button.visible = false
|
||||
# Every building can hold ore, so the transfer button rides alongside the
|
||||
|
|
@ -332,13 +345,16 @@ func _process(delta: float) -> void:
|
|||
# turns into - the two are independent choices at the same structure.
|
||||
transfer_button.visible = false
|
||||
building_action_button.visible = false
|
||||
action_button.visible = current_building != null
|
||||
action_button.visible = current_building != null or current_extractor_index >= 0
|
||||
if current_building != null:
|
||||
var actions: Array = _context_action_buttons()
|
||||
building_action_button.icon = int(current_building.definition.action_icon)
|
||||
building_action_button.queue_redraw()
|
||||
action_button.icon = building_action_button.icon if actions.size() == 1 else IconButton.Icon.ACTION_MENU
|
||||
action_button.queue_redraw()
|
||||
elif current_extractor_index >= 0:
|
||||
action_button.icon = IconButton.Icon.TRANSFER
|
||||
action_button.queue_redraw()
|
||||
_layout_context_buttons()
|
||||
|
||||
|
||||
|
|
@ -365,6 +381,8 @@ func _layout_context_buttons() -> void:
|
|||
|
||||
|
||||
func _context_action_buttons() -> Array:
|
||||
if current_extractor_index >= 0:
|
||||
return [transfer_button]
|
||||
if current_building == null:
|
||||
return []
|
||||
var buttons: Array = []
|
||||
|
|
@ -384,7 +402,7 @@ func _button_for_building_action(action: String) -> IconButton:
|
|||
|
||||
|
||||
func _on_context_action_pressed() -> void:
|
||||
if current_building == null:
|
||||
if current_building == null and current_extractor_index < 0:
|
||||
return
|
||||
var actions: Array = _context_action_buttons()
|
||||
if actions.size() == 1:
|
||||
|
|
@ -877,9 +895,10 @@ const ALL: int = 1 << 30
|
|||
|
||||
|
||||
func _on_transfer_pressed() -> void:
|
||||
if current_building == null:
|
||||
if current_building == null and current_extractor_index < 0:
|
||||
return
|
||||
transfer_building_id = current_building.building_id
|
||||
transfer_building_id = current_building.building_id if current_building != null else 0
|
||||
transfer_extractor_index = current_extractor_index
|
||||
for bar in resource_bars:
|
||||
bar.building_id = transfer_building_id
|
||||
transfer_menu.visible = true
|
||||
|
|
@ -892,15 +911,17 @@ func _on_transfer(to_building: bool, amount: int) -> void:
|
|||
|
||||
|
||||
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"
|
||||
if transfer_building_id == 0 and transfer_extractor_index < 0:
|
||||
transfer_status.text = "No resource store selected - reopen this panel from its action"
|
||||
return
|
||||
|
||||
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 moved: int
|
||||
if transfer_extractor_index >= 0:
|
||||
moved = GameState.transfer_resource_to_extractor(transfer_extractor_index, resource_type, amount) \
|
||||
if to_building else GameState.transfer_resource_from_extractor(transfer_extractor_index, resource_type, amount)
|
||||
else:
|
||||
moved = 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
|
||||
|
|
@ -922,6 +943,8 @@ func _on_gas_transfer(to_building: bool) -> void:
|
|||
|
||||
|
||||
func _transfer_place_name() -> String:
|
||||
if transfer_extractor_index >= 0:
|
||||
return "the extractor"
|
||||
var b: Dictionary = GameState.find_building(transfer_building_id)
|
||||
if b.is_empty():
|
||||
return "this building"
|
||||
|
|
@ -933,6 +956,9 @@ func _transfer_place_name() -> String:
|
|||
|
||||
|
||||
func _refresh_transfer() -> void:
|
||||
if transfer_extractor_index >= 0:
|
||||
transfer_list.set_extractor_destination(transfer_extractor_index, "Planet extractor")
|
||||
return
|
||||
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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue