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

@ -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: