Refine context actions and preserve fleet landings
This commit is contained in:
parent
18a7d44db4
commit
663648d949
20 changed files with 197 additions and 103 deletions
|
|
@ -6,10 +6,8 @@ const VESSEL_DEFINITIONS = preload("res://VesselDefinitions.gd")
|
|||
# Space-side building UI. Owns:
|
||||
# - the build menu (place a mothership, ship crafter or command centre)
|
||||
# - the shared ACTION button, which adapts to whatever the fleet is
|
||||
# standing on (craft ships at a crafter, configure formation at a
|
||||
# command centre). The enter-atmosphere prompt uses the same slot, and
|
||||
# PlanetAtmosphereController suppresses itself while a building prompt
|
||||
# is showing so the two can never fight over it.
|
||||
# standing on (craft ships, configure formation, or land). One action
|
||||
# fires directly; multiple actions unfold horizontally.
|
||||
# - rebuilding a wiped-out fleet at the mothership
|
||||
#
|
||||
# Buildings themselves live in GameState (they must outlive the trip to a
|
||||
|
|
@ -23,6 +21,8 @@ const VESSEL_DEFINITIONS = preload("res://VesselDefinitions.gd")
|
|||
@onready var build_button: IconButton = get_node("../UI/BuildButton")
|
||||
@onready var action_button: IconButton = get_node("../UI/BuildActionButton")
|
||||
@onready var building_action_button: IconButton = get_node("../UI/BuildingActionButton")
|
||||
@onready var landing_button: IconButton = get_node("../UI/EnterAtmosphereButton")
|
||||
@onready var landing_controller: Node2D = get_node("../LandingController")
|
||||
|
||||
@onready var build_menu: Control = get_node("../UI/BuildMenu")
|
||||
@onready var build_close_button: IconButton = get_node("../UI/BuildMenu/CloseButton")
|
||||
|
|
@ -113,8 +113,9 @@ var lab_building_id: int = 0
|
|||
# --- the transfer panel (#24) ---------------------------------------------
|
||||
# Ore used to be moved from inside whichever panel happened to be open: "load
|
||||
# ore" lived in the research screen, "store ore here" in the ship crafter.
|
||||
# Both are now one top-level button that works at every building and in both
|
||||
# directions, so moving ore is never buried under an unrelated menu.
|
||||
# Both are now one top-level shortcut beside Build at resource-bearing
|
||||
# locations and work in both directions, so moving cargo is never buried
|
||||
# under an unrelated action foldout.
|
||||
@onready var transfer_button: IconButton = get_node("../UI/TransferButton")
|
||||
@onready var transfer_menu: Control = get_node("../UI/TransferMenu")
|
||||
@onready var transfer_status: Label = get_node("../UI/TransferMenu/StatusLabel")
|
||||
|
|
@ -165,6 +166,7 @@ var current_building: Node2D = null
|
|||
var pending_building: Node2D = null
|
||||
var current_extractor_index: int = -1
|
||||
var pending_extractor_index: int = -1
|
||||
var current_landing_planet: Node2D = null
|
||||
var pending_time: float = 0.0
|
||||
var context_actions_expanded: bool = false
|
||||
|
||||
|
|
@ -218,6 +220,7 @@ func _ready() -> void:
|
|||
transfer_menu.visible = false
|
||||
action_button.visible = false
|
||||
building_action_button.visible = false
|
||||
landing_button.visible = false
|
||||
transfer_button.visible = false
|
||||
hangar_button.visible = false
|
||||
hangar_menu.visible = false
|
||||
|
|
@ -239,10 +242,10 @@ func _configure_build_menu_entries() -> void:
|
|||
build_menu_entries.append([definition.definition_id, button, label, cost_number, definition])
|
||||
|
||||
|
||||
# True while a building prompt or panel owns the shared action slot, so the
|
||||
# enter-atmosphere prompt knows to stay out of the way.
|
||||
# True while a modal panel owns the shared context controls. A plain building
|
||||
# prompt is not modal: landing can coexist with its actions in the same foldout.
|
||||
func is_showing_building_prompt() -> bool:
|
||||
return current_building != null or build_menu.visible or craft_menu.visible \
|
||||
return build_menu.visible or craft_menu.visible \
|
||||
or formation_menu.visible or skill_menu.visible or transfer_menu.visible \
|
||||
or hangar_menu.visible
|
||||
|
||||
|
|
@ -309,8 +312,10 @@ func _process(delta: float) -> void:
|
|||
pending_building = null
|
||||
current_extractor_index = -1
|
||||
pending_extractor_index = -1
|
||||
current_landing_planet = null
|
||||
action_button.visible = false
|
||||
building_action_button.visible = false
|
||||
landing_button.visible = false
|
||||
transfer_button.visible = false
|
||||
hangar_button.visible = false
|
||||
context_actions_expanded = false
|
||||
|
|
@ -332,28 +337,27 @@ func _process(delta: float) -> void:
|
|||
else:
|
||||
pending_time += delta
|
||||
|
||||
var detected_landing_planet: Node2D = landing_controller.current_planet
|
||||
if pending_time < prompt_debounce_time or (pending_building == current_building \
|
||||
and pending_extractor_index == current_extractor_index):
|
||||
and pending_extractor_index == current_extractor_index \
|
||||
and detected_landing_planet == current_landing_planet):
|
||||
return
|
||||
|
||||
current_building = pending_building
|
||||
current_extractor_index = pending_extractor_index
|
||||
current_landing_planet = detected_landing_planet
|
||||
context_actions_expanded = false
|
||||
hangar_button.visible = false
|
||||
# Every building can hold ore, so the transfer button rides alongside the
|
||||
# action button rather than being one of the things the action button
|
||||
# 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 or current_extractor_index >= 0
|
||||
landing_button.visible = false
|
||||
transfer_button.visible = _has_transfer_context()
|
||||
var actions: Array = _context_action_buttons()
|
||||
action_button.visible = not actions.is_empty()
|
||||
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
|
||||
if not actions.is_empty():
|
||||
action_button.icon = int(actions[0].icon) if actions.size() == 1 else IconButton.Icon.ACTION_MENU
|
||||
action_button.queue_redraw()
|
||||
_layout_context_buttons()
|
||||
|
||||
|
|
@ -381,33 +385,41 @@ 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 = []
|
||||
for action in current_building.available_actions():
|
||||
var button: IconButton = _button_for_building_action(action)
|
||||
if button != null and button not in buttons:
|
||||
buttons.append(button)
|
||||
if current_building != null:
|
||||
for action in current_building.available_actions():
|
||||
var button: IconButton = _button_for_building_action(action)
|
||||
if button != null and button not in buttons:
|
||||
buttons.append(button)
|
||||
if current_landing_planet != null:
|
||||
buttons.append(landing_button)
|
||||
return buttons
|
||||
|
||||
|
||||
func _has_transfer_context() -> bool:
|
||||
if current_extractor_index >= 0:
|
||||
return true
|
||||
return current_building != null and current_building.available_actions().has("transfer")
|
||||
|
||||
|
||||
func _button_for_building_action(action: String) -> IconButton:
|
||||
if action == "transfer":
|
||||
return transfer_button
|
||||
return null
|
||||
if action == "hangar":
|
||||
return hangar_button
|
||||
return building_action_button
|
||||
|
||||
|
||||
func _on_context_action_pressed() -> void:
|
||||
if current_building == null and current_extractor_index < 0:
|
||||
if current_building == null and current_extractor_index < 0 \
|
||||
and current_landing_planet == null:
|
||||
return
|
||||
var actions: Array = _context_action_buttons()
|
||||
if actions.size() == 1:
|
||||
if actions[0] == transfer_button:
|
||||
_on_transfer_pressed()
|
||||
if actions[0] == landing_button:
|
||||
landing_controller._on_enter_pressed()
|
||||
elif actions[0] == hangar_button:
|
||||
_on_hangar_pressed()
|
||||
else:
|
||||
_on_action_pressed()
|
||||
return
|
||||
|
|
|
|||
Loading…
Reference in a new issue