PC controls: keyboard pan/zoom, Tab cycle, Escape stack, right-click deselect

Adds full PC keyboard+mouse support on top of existing touch controls. Touch
paths untouched. All input goes through named actions in project.godot.

Bindings:
- WASD / arrows: camera pan (speed scales with zoom)
- = / -: keyboard zoom in/out
- C / Home: center on selected pawn
- Tab / Shift+Tab: cycle through pawns (pans camera to selection)
- B / L / P / ,: toggle BuildDrawer / AlertsLog / WorkPriorityMatrix / Settings
- Escape: cancel active designation tool > close topmost panel > deselect pawn
- Right-click: cancel active tool or deselect pawn (RTS convention)
- F: speed_cycle (action restored; handler still TODO)
- pawn_prev action removed; Shift+Tab read via event.shift_pressed inline

Escape priority enforced by Designation._input running before _unhandled_input
plus each panel consuming its own cancel action when visible.

Also fixes a pre-existing pre-Phase-17 bug: WorkPriorityMatrix, AlertsLog,
StorytellerModal, LoadMenu, and SettingsMenu had MOUSE_FILTER_STOP Controls
(Backdrop / Dim) that remained input-active when the panel was "closed" —
their open/close paths only toggled _root.visible / _panel.visible, never
CanvasLayer.visible. World mouse events (right-click deselect, left-click
pawn-select) were silently eaten. Now each _set_visible / open / close
toggles self.visible (the CanvasLayer) so input dispatch shuts off properly.

Verified end-to-end via MCP runtime: WASD pan, zoom keys, Tab+Shift+Tab
cycle, B-open + Escape-close, right-click deselect, left-click pawn-select
all working in sequence with no input bleed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
megaproxy 2026-05-12 12:06:38 +01:00
parent b9093dd24b
commit 0b2e0fcd03
11 changed files with 300 additions and 1 deletions

View file

@ -62,6 +62,10 @@ var log_button: Button = null
func _ready() -> void:
layer = 19
_build_ui()
# Hide the whole CanvasLayer when closed so the Backdrop ColorRect (which
# has MOUSE_FILTER_STOP for click-outside-to-close) does not eat mouse
# events in `_unhandled_input` for the world below.
visible = false
_root.visible = false
EventBus.alert_added.connect(_on_alert_added)
@ -86,6 +90,7 @@ func _exit_tree() -> void:
func open() -> void:
_rebuild_list()
visible = true
_root.visible = true
_unread_count = 0
_update_badge()
@ -93,6 +98,7 @@ func open() -> void:
func close() -> void:
visible = false
_root.visible = false
Audit.log("alerts_log", "closed")
@ -277,6 +283,22 @@ func _pan_to(tile: Vector2i) -> void:
close()
func _unhandled_input(event: InputEvent) -> void:
# L — toggle the alerts log.
if event.is_action_pressed("open_log"):
if _root != null and _root.visible:
close()
else:
open()
get_viewport().set_input_as_handled()
return
# Escape — close if open.
if event.is_action_pressed("cancel") and _root != null and _root.visible:
close()
get_viewport().set_input_as_handled()
return
func _on_backdrop_input(event: InputEvent) -> void:
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
close()

View file

@ -371,6 +371,21 @@ func _on_cancel_pressed() -> void:
Audit.log("build_drawer", "tool cancelled")
# ── keyboard input ───────────────────────────────────────────────────────────
func _unhandled_input(event: InputEvent) -> void:
# B — toggle the build drawer.
if event.is_action_pressed("open_build"):
toggle()
get_viewport().set_input_as_handled()
return
# Escape — close if open (panel Escape runs before Selection deselect).
if event.is_action_pressed("cancel") and _open:
close()
get_viewport().set_input_as_handled()
return
# ── helpers — visibility ─────────────────────────────────────────────────────
func _set_panel_visible(v: bool) -> void:

View file

@ -43,6 +43,19 @@ func _exit_tree() -> void:
pass
func _unhandled_input(event: InputEvent) -> void:
# _set_visible drives _panel.visible, not CanvasLayer.visible — use _panel as the gate.
if _panel == null or not _panel.visible:
return
if event.is_action_pressed("cancel"):
# If the version-mismatch sub-dialog is open, dismiss it first.
if _warn_panel != null and _warn_panel.visible:
_on_warn_cancel()
else:
_close()
get_viewport().set_input_as_handled()
# ── public API ────────────────────────────────────────────────────────────────
func open() -> void:
@ -246,6 +259,10 @@ func _close() -> void:
func _set_visible(v: bool) -> void:
# Toggle CanvasLayer.visible so the dim Control (MOUSE_FILTER_STOP) does not
# eat _unhandled_input mouse events for the world below when modal is hidden.
# (The warning sub-dialog visibility is managed separately and lives inside.)
visible = v or (_warn_panel != null and _warn_panel.visible)
if _dim != null:
_dim.visible = v
if _panel != null:

View file

@ -227,6 +227,26 @@ func _collect_to_dict() -> Dictionary:
# ── interaction ───────────────────────────────────────────────────────────────
func _unhandled_input(event: InputEvent) -> void:
# Comma — toggle settings menu. Guard: don't open if already in a modal
# (this IS the modal, so just toggle based on current visibility).
if event.is_action_pressed("open_settings"):
if _dim != null and _dim.visible:
_set_visible(false)
Audit.log("settings_menu", "hotkey close")
else:
open()
Audit.log("settings_menu", "hotkey open")
get_viewport().set_input_as_handled()
return
# Escape — close if open (discards edits, same as Cancel button).
if event.is_action_pressed("cancel") and _dim != null and _dim.visible:
Audit.log("settings_menu", "escape: cancelled")
_set_visible(false)
get_viewport().set_input_as_handled()
return
func _on_save_pressed() -> void:
GameState.apply_settings(_collect_to_dict())
Audit.log("settings_menu", "settings saved")
@ -241,6 +261,9 @@ func _on_cancel_pressed() -> void:
# ── visibility ────────────────────────────────────────────────────────────────
func _set_visible(v: bool) -> void:
# Toggle CanvasLayer.visible so the dim Control (MOUSE_FILTER_STOP) does not
# eat _unhandled_input mouse events for the world below when modal is hidden.
visible = v
if _dim != null:
_dim.visible = v
if _panel != null:

View file

@ -172,6 +172,9 @@ func _on_go_there_pressed() -> void:
# ── helpers ──────────────────────────────────────────────────────────────────
func _set_visible(v: bool) -> void:
# Toggle CanvasLayer.visible so the dim Control (MOUSE_FILTER_STOP) does not
# eat _unhandled_input mouse events for the world below when modal is hidden.
visible = v
if _dim != null:
_dim.visible = v
if _panel != null:

View file

@ -69,6 +69,11 @@ var _cells: Array = []
func _ready() -> void:
layer = 17
_build_ui()
# Hide the whole CanvasLayer when closed so the Backdrop ColorRect (which
# has MOUSE_FILTER_STOP for click-outside-to-close) does not eat mouse
# events in `_unhandled_input` for the world below. Toggling _root.visible
# alone leaves the Backdrop alive and intercepting clicks.
visible = false
_root.visible = false
Audit.log("work_priority_ui", "WorkPriorityMatrix ready")
@ -78,12 +83,14 @@ func _ready() -> void:
## Open the matrix panel and rebuild the grid from current pawn state.
func open() -> void:
_rebuild_grid()
visible = true
_root.visible = true
Audit.log("work_priority_ui", "opened (pawns=%d)" % World.pawns.size())
## Close the panel.
func close() -> void:
visible = false
_root.visible = false
Audit.log("work_priority_ui", "closed")
@ -222,6 +229,22 @@ func _on_cell_pressed(pawn, category: StringName, btn: Button) -> void:
Audit.log("work_priority_ui", "%s: %s%d" % [pawn.pawn_name, String(category), next])
func _unhandled_input(event: InputEvent) -> void:
# P — toggle the work priority matrix.
if event.is_action_pressed("open_priorities"):
if _root != null and _root.visible:
close()
else:
open()
get_viewport().set_input_as_handled()
return
# Escape — close if open.
if event.is_action_pressed("cancel") and _root != null and _root.visible:
close()
get_viewport().set_input_as_handled()
return
func _on_backdrop_input(event: InputEvent) -> void:
# Tap on the backdrop (outside the panel) closes the matrix.
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT: