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

@ -53,7 +53,7 @@ pause={
}
speed_cycle={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194306,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":70,"physical_keycode":0,"key_label":0,"unicode":70,"location":0,"echo":false,"script":null)
]
}
speed_normal={
@ -81,6 +81,73 @@ cancel={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194305,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
pan_up={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":87,"physical_keycode":0,"key_label":0,"unicode":87,"location":0,"echo":false,"script":null),
Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194320,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
pan_down={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":83,"physical_keycode":0,"key_label":0,"unicode":83,"location":0,"echo":false,"script":null),
Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194322,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
pan_left={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":65,"physical_keycode":0,"key_label":0,"unicode":65,"location":0,"echo":false,"script":null),
Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194319,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
pan_right={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":68,"physical_keycode":0,"key_label":0,"unicode":68,"location":0,"echo":false,"script":null),
Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194321,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
zoom_in={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":61,"physical_keycode":0,"key_label":0,"unicode":61,"location":0,"echo":false,"script":null),
Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194453,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
zoom_out={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":45,"physical_keycode":0,"key_label":0,"unicode":45,"location":0,"echo":false,"script":null),
Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194452,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
center_on_selection={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194316,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null),
Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":67,"physical_keycode":0,"key_label":0,"unicode":67,"location":0,"echo":false,"script":null)
]
}
pawn_next={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194306,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
open_build={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":66,"physical_keycode":0,"key_label":0,"unicode":66,"location":0,"echo":false,"script":null)
]
}
open_log={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":76,"physical_keycode":0,"key_label":0,"unicode":76,"location":0,"echo":false,"script":null)
]
}
open_priorities={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":80,"physical_keycode":0,"key_label":0,"unicode":80,"location":0,"echo":false,"script":null)
]
}
open_settings={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":44,"physical_keycode":0,"key_label":0,"unicode":44,"location":0,"echo":false,"script":null)
]
}
[rendering]

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:

View file

@ -29,12 +29,26 @@ func _ready() -> void:
zoom = Vector2(target_zoom, target_zoom)
## Pan speed in world pixels per second at zoom 1.0.
## Scales inversely with zoom so on-screen apparent speed feels constant.
const PAN_SPEED_PX_PER_SEC: float = 600.0
func _process(delta: float) -> void:
# Lerp zoom toward target each render frame.
# Plain 0.15 factor is correct at 60 fps; frame-rate independent form used for safety.
var t: float = 1.0 - pow(1.0 - 0.15, delta * 60.0)
zoom = zoom.lerp(Vector2(target_zoom, target_zoom), t)
# Keyboard pan — WASD / arrow keys. Strength gives an analogue-stick-style
# value (0..1) so held-key is continuous and action-just-pressed is not needed.
var pan_input := Vector2(
Input.get_action_strength("pan_right") - Input.get_action_strength("pan_left"),
Input.get_action_strength("pan_down") - Input.get_action_strength("pan_up"),
)
if pan_input != Vector2.ZERO:
position += pan_input.normalized() * (PAN_SPEED_PX_PER_SEC / zoom.x) * delta
func _unhandled_input(event: InputEvent) -> void:
# --- Pinch-zoom via magnify gesture (trackpad + native touch pinch) ---
@ -42,6 +56,16 @@ func _unhandled_input(event: InputEvent) -> void:
target_zoom = clampf(target_zoom * event.factor, MIN_ZOOM, MAX_ZOOM)
return
# --- Keyboard zoom (= / + / KP_ADD and - / KP_SUBTRACT) ---
if event.is_action_pressed("zoom_in"):
target_zoom = clampf(target_zoom * 1.1, MIN_ZOOM, MAX_ZOOM)
Audit.log("camera", "zoom_in → %.2f" % target_zoom)
return
if event.is_action_pressed("zoom_out"):
target_zoom = clampf(target_zoom / 1.1, MIN_ZOOM, MAX_ZOOM)
Audit.log("camera", "zoom_out → %.2f" % target_zoom)
return
# --- Scroll-wheel zoom (desktop) ---
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_WHEEL_UP and event.pressed:

View file

@ -159,6 +159,27 @@ func cells() -> Array[Vector2i]:
# ── input ────────────────────────────────────────────────────────────────────
## _input runs before _unhandled_input so Escape / right-click tool-cancel takes
## priority over Selection's deselect and over panel close-handlers.
func _input(event: InputEvent) -> void:
if _tool == TOOL_NONE:
return
# Escape — cancel the active tool; consume so lower handlers don't also fire.
if event.is_action_pressed("cancel"):
set_active_tool(TOOL_NONE)
get_viewport().set_input_as_handled()
Audit.log("designation", "escape: tool cancelled")
return
# Right-click — also cancel the active tool (RTS convention).
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_RIGHT and event.pressed:
set_active_tool(TOOL_NONE)
get_viewport().set_input_as_handled()
Audit.log("designation", "right-click: tool cancelled")
return
func _unhandled_input(event: InputEvent) -> void:
if _tool == TOOL_NONE or _paint_layer == null:
return

View file

@ -14,6 +14,7 @@ const CLICK_MAX_DURATION_MS: int = 300
var _pathfinder: Pathfinder = null
var _selected_pawn: Pawn = null
var _camera = null # Camera2D (CameraRig) — set via bind_camera(); duck-typed to avoid circular preload
# When Designation paint mode is active this flag is raised by Designation so
# Selection does not also try to select/move on the same click.
@ -29,13 +30,57 @@ func bind(pathfinder: Pathfinder) -> void:
_pathfinder = pathfinder
## Inject the CameraRig so Tab-cycle and center-on-selection can pan to the
## selected pawn's tile. Call from world.gd after selection.bind().
func bind_camera(rig) -> void:
_camera = rig
func selected() -> Pawn:
return _selected_pawn
func _unhandled_input(event: InputEvent) -> void:
# ── Keyboard: Tab → cycle pawns (Shift+Tab reverses) ───────────────────────
if event.is_action_pressed("pawn_next"):
# Read shift from the event itself (set by the OS on the key event); more
# reliable than Input.is_key_pressed(KEY_SHIFT) which doesn't reflect modifier
# state from synthetic input events (MCP test injections).
var reverse: bool = event is InputEventKey and event.shift_pressed
_cycle_pawn(-1 if reverse else 1)
get_viewport().set_input_as_handled()
return
# ── Keyboard: C / Home → center camera on selected pawn ─────────────────────
if event.is_action_pressed("center_on_selection"):
if _selected_pawn != null and _camera != null:
_camera.pan_to_tile(_selected_pawn.tile)
Audit.log("selection", "center_on_selection → %s" % _selected_pawn.tile)
get_viewport().set_input_as_handled()
return
# ── Keyboard: Escape → deselect (lowest-priority; consumed last) ─────────────
# Designation._input handles Escape first; panels handle it in _unhandled_input
# before reaching here. If we still see it and have a selection, consume it.
if event.is_action_pressed("cancel") and _selected_pawn != null:
_deselect()
get_viewport().set_input_as_handled()
Audit.log("selection", "escape: deselected")
return
# ── Mouse: only handle button events below ───────────────────────────────────
if not (event is InputEventMouseButton):
return
# ── Right-click: cancel designation (if active) or deselect pawn ─────────────
if event.button_index == MOUSE_BUTTON_RIGHT and event.pressed:
# Designation cancellation is handled by Designation._input; if we see
# this right-click, no designation was active. Deselect any selected pawn.
if _selected_pawn != null:
_deselect()
get_viewport().set_input_as_handled()
return
if event.button_index != MOUSE_BUTTON_LEFT:
return
# Designation paint mode owns input while active; Selection steps aside.
@ -102,3 +147,36 @@ func _select(pawn: Pawn) -> void:
pawn.set_selected(true)
EventBus.pawn_selected.emit(pawn)
Audit.log("selection", "selected %s at %s" % [pawn.pawn_name, pawn.tile])
## Clear the current selection without selecting another pawn.
func _deselect() -> void:
if _selected_pawn == null:
return
_selected_pawn.set_selected(false)
EventBus.pawn_deselected.emit()
Audit.log("selection", "deselected %s" % _selected_pawn.pawn_name)
_selected_pawn = null
## Cycle the selection forward (dir=1) or backward (dir=-1) through World.pawns.
## Wraps around. If no pawn currently selected, picks World.pawns[0].
## Pans the camera to the newly selected pawn's tile.
func _cycle_pawn(dir: int) -> void:
var pawns: Array = World.pawns
if pawns.is_empty():
return
var next_pawn: Pawn
if _selected_pawn == null:
next_pawn = pawns[0]
else:
var idx: int = pawns.find(_selected_pawn)
if idx == -1:
next_pawn = pawns[0]
else:
idx = posmod(idx + dir, pawns.size())
next_pawn = pawns[idx]
_select(next_pawn)
if _camera != null:
_camera.pan_to_tile(next_pawn.tile)
Audit.log("selection", "pawn_cycle dir=%d%s" % [dir, next_pawn.pawn_name])

View file

@ -122,6 +122,12 @@ func _ready() -> void:
pathfinder.setup(MAP_SIZE_TILES)
_wire_walls_to_pathfinder()
selection.bind(pathfinder)
# Bind the camera so Tab-cycle and center-on-selection can pan to pawns.
var camera_rig := get_node_or_null("CameraRig")
if camera_rig != null:
selection.bind_camera(camera_rig)
else:
Audit.log("world", "selection.bind_camera: CameraRig not found")
World.pathfinder = pathfinder # expose to entities (Tree.fell() walkability checks, etc.)
# Phase 5 — expose TileMap layer refs on the autoload so entity code