Collapse contextual building actions
This commit is contained in:
parent
1c9ac62e8c
commit
d79c756d5b
4 changed files with 110 additions and 34 deletions
|
|
@ -19,6 +19,7 @@ extends Node2D
|
|||
@onready var world_map: Control = get_node("../UI/WorldMap")
|
||||
@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 build_menu: Control = get_node("../UI/BuildMenu")
|
||||
@onready var build_mothership_button: IconButton = get_node("../UI/BuildMenu/MothershipButton")
|
||||
|
|
@ -209,6 +210,7 @@ var transfer_building_id: int = 0
|
|||
var current_building: Node2D = null
|
||||
var pending_building: Node2D = null
|
||||
var pending_time: float = 0.0
|
||||
var context_actions_expanded: bool = false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
@ -230,7 +232,8 @@ func _ready() -> void:
|
|||
info_close_button.pressed.connect(_close_info)
|
||||
info_build_button.pressed.connect(_confirm_build)
|
||||
|
||||
action_button.pressed.connect(_on_action_pressed)
|
||||
action_button.pressed.connect(_on_context_action_pressed)
|
||||
building_action_button.pressed.connect(_on_action_pressed)
|
||||
|
||||
craft_interceptor_button.pressed.connect(_on_craft_interceptor)
|
||||
craft_transporter_button.pressed.connect(_on_craft_transporter)
|
||||
|
|
@ -266,6 +269,7 @@ func _ready() -> void:
|
|||
lab_menu.visible = false
|
||||
transfer_menu.visible = false
|
||||
action_button.visible = false
|
||||
building_action_button.visible = false
|
||||
transfer_button.visible = false
|
||||
hangar_button.visible = false
|
||||
hangar_menu.visible = false
|
||||
|
|
@ -281,6 +285,12 @@ func is_showing_building_prompt() -> bool:
|
|||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if context_actions_expanded and (event is InputEventScreenTouch and event.pressed \
|
||||
or event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT):
|
||||
# Buttons consume their own touch; reaching this handler means the tap
|
||||
# landed somewhere else, which dismisses an expanded action list.
|
||||
_collapse_context_actions()
|
||||
|
||||
# The formation editor and the skill tree are driven from here rather than
|
||||
# via _gui_input, for the same reason as the joystick: a Control that
|
||||
# consumes touches through the GUI system swallows them before they get
|
||||
|
|
@ -337,8 +347,10 @@ func _process(delta: float) -> void:
|
|||
current_building = null
|
||||
pending_building = null
|
||||
action_button.visible = false
|
||||
building_action_button.visible = false
|
||||
transfer_button.visible = false
|
||||
hangar_button.visible = false
|
||||
context_actions_expanded = false
|
||||
return
|
||||
|
||||
# Debounced exactly like the enter-atmosphere prompt, so the action
|
||||
|
|
@ -355,7 +367,7 @@ func _process(delta: float) -> void:
|
|||
return
|
||||
|
||||
current_building = pending_building
|
||||
action_button.visible = current_building != null
|
||||
context_actions_expanded = false
|
||||
# The hangar is where finished vessels are delivered (#23), so it belongs
|
||||
# at the mothership and nowhere else.
|
||||
hangar_button.visible = current_building != null \
|
||||
|
|
@ -363,26 +375,68 @@ func _process(delta: float) -> void:
|
|||
# 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 = current_building != null
|
||||
transfer_button.visible = false
|
||||
building_action_button.visible = false
|
||||
action_button.visible = current_building != null
|
||||
if current_building != null:
|
||||
action_button.icon = _action_icon_for(current_building.building_type)
|
||||
var actions: Array = _context_action_buttons()
|
||||
building_action_button.icon = _action_icon_for(current_building.building_type)
|
||||
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()
|
||||
_layout_context_buttons()
|
||||
|
||||
|
||||
func _layout_context_buttons() -> void:
|
||||
# Every contextual action uses a distinct, fixed berth above Build. This
|
||||
# replaces the old hand-picked offsets where Hangar overlapped Action at a
|
||||
# mothership (#25).
|
||||
var buttons: Array = [action_button, transfer_button]
|
||||
if hangar_button.visible:
|
||||
buttons.append(hangar_button)
|
||||
# Build is permanently under the resource counter. The contextual berth
|
||||
# directly below it is compact until it has more than one real choice.
|
||||
action_button.offset_top = 324
|
||||
action_button.offset_bottom = 472
|
||||
var buttons: Array = _context_action_buttons()
|
||||
if not context_actions_expanded:
|
||||
for button in buttons:
|
||||
button.visible = false
|
||||
return
|
||||
for i in range(buttons.size()):
|
||||
var button: Control = buttons[i]
|
||||
button.offset_top = -720 + i * 164
|
||||
button.visible = true
|
||||
button.offset_top = 488 + i * 164
|
||||
button.offset_bottom = button.offset_top + 148
|
||||
|
||||
|
||||
func _context_action_buttons() -> Array:
|
||||
if current_building == null:
|
||||
return []
|
||||
var actions: Array = [transfer_button]
|
||||
if current_building.building_type in [GameState.BUILDING_MOTHERSHIP, GameState.BUILDING_SHIP_CRAFTER,
|
||||
GameState.BUILDING_SHIP_LAB, GameState.BUILDING_COMMAND_CENTER]:
|
||||
actions.push_front(building_action_button)
|
||||
if current_building.building_type == GameState.BUILDING_MOTHERSHIP:
|
||||
actions.append(hangar_button)
|
||||
return actions
|
||||
|
||||
|
||||
func _on_context_action_pressed() -> void:
|
||||
if current_building == null:
|
||||
return
|
||||
var actions: Array = _context_action_buttons()
|
||||
if actions.size() == 1:
|
||||
if actions[0] == transfer_button:
|
||||
_on_transfer_pressed()
|
||||
else:
|
||||
_on_action_pressed()
|
||||
return
|
||||
context_actions_expanded = not context_actions_expanded
|
||||
_layout_context_buttons()
|
||||
|
||||
|
||||
func _collapse_context_actions() -> void:
|
||||
if not context_actions_expanded:
|
||||
return
|
||||
context_actions_expanded = false
|
||||
_layout_context_buttons()
|
||||
|
||||
|
||||
func _action_icon_for(type: String) -> int:
|
||||
match type:
|
||||
GameState.BUILDING_SHIP_CRAFTER:
|
||||
|
|
|
|||
Loading…
Reference in a new issue