diff --git a/README.md b/README.md index fa86d76..80d7ac8 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ > visual direction, and Linux integrations are expected to change. [![Status: work in progress](https://img.shields.io/badge/status-work_in_progress-f59e0b)](#project-status) -[![Phase: 5 local gate passed](https://img.shields.io/badge/phase-5_local_gate_passed-22c55e)](#current-status) +[![Phase: 6 frontend foundation](https://img.shields.io/badge/phase-6_frontend_foundation-22c55e)](#current-status) [![License: BSD-3-Clause](https://img.shields.io/badge/license-BSD--3--Clause-22c55e)](LICENSE) [![CI](https://github.com/MoazMustafa-stack/Velora/actions/workflows/ci.yml/badge.svg)](https://github.com/MoazMustafa-stack/Velora/actions/workflows/ci.yml) [![Buy me a coffee](https://img.shields.io/badge/Support-Ko--fi-ff5e5b)](https://ko-fi.com/moazmustafa) @@ -30,9 +30,14 @@ normal desktop remains available if Velora exits. ## Current status -Phases 1–4 are complete and merged to `main`. Phase 5 (D-Bus media and -notifications) is implemented on `dbus-media-core`; its cumulative local -release gate passes, and the work is awaiting commit/review/merge. +Phases 1–5 are complete and merged to `main` (Phase 5: PR #8). +Phase 6 is the frontend experience pass, not another system integration. +Its D6.01–D6.04 foundation introduces semantic design tokens, shared panel +and list primitives, a bounded UI-only preferences API, and one modal/input +coordinator. See the [visual inventory](frontend/godot/ASSET_INVENTORY.md) +and [settings contract](config/README.md). Settings screens, onboarding, +art redesign, accessibility controls, audio, remapping UI, and station +customization remain later Phase 6 work. Phase 1.01–1.10 provides a Godot 4.7 pixel-perfect foundation, a 16 px tile hub, eight-direction movement with four-direction facing, sprinting, physical diff --git a/config/README.md b/config/README.md new file mode 100644 index 0000000..06e6695 --- /dev/null +++ b/config/README.md @@ -0,0 +1,22 @@ +# Configuration boundaries + +The old `default.toml` was never loaded and advertised protocol v1. It has +been removed; the current wire version is owned by `velora-protocol`, not +user configuration. Core runtime options remain the environment variables +documented in the root README. + +Frontend UI preferences use `scripts/settings_store.gd` in the Godot project. +The store owns `user://velora-settings.json` with schema version 1 and a +16 KiB maximum. Loading or constructing the store never creates a file. +Only explicit save/reset operations write, and reset removes only that file. + +Allowlisted preferences: onboarding completion, reduced motion, UI-audio mute +and volume (0–1), up to four keyboard keys per named action, and fixed +editor/browser/terminal slots containing syntactically validated desktop IDs. +Missing values use defaults; invalid files use all defaults; unknown fields +are ignored and never written back. No live system data is stored. + +This is a foundation API, not a new settings UI or remapping feature. +Later Phase 6 cards consume these preferences. A stored desktop ID must still +resolve against the live trusted registry before a launch can be requested. +It is never a command, path, argument list, or permission to bypass Core. diff --git a/config/default.toml b/config/default.toml deleted file mode 100644 index f4cefd6..0000000 --- a/config/default.toml +++ /dev/null @@ -1,18 +0,0 @@ -[general] -protocol_version = 1 - -[frontend] -immersive_mode = false - -[world] -default_room = "hub" - -[telemetry] -enabled = true -interval_ms = 1000 - -[applications] -auto_discover = true - -[hyprland] -enabled = true diff --git a/frontend/godot/ASSET_INVENTORY.md b/frontend/godot/ASSET_INVENTORY.md new file mode 100644 index 0000000..093c94c --- /dev/null +++ b/frontend/godot/ASSET_INVENTORY.md @@ -0,0 +1,46 @@ +# Fixed-canvas visual inventory + +Baseline: merged Phase 5 `5bdf1dc`, 320 × 180, nearest integer scaling, +Godot Compatibility renderer. No downloaded art or fonts are introduced. + +| Surface | Source and visual contract | +| --- | --- | +| Floor, walls, path, threshold | `scripts/pixel_art.gd`: generated 64 × 16 atlas of four 16 × 16 tiles; hub builds boundary/collisions | +| Player | Generated 16 × 24 sprites, four directions × two steps; player caches textures | +| Application stations | Generated workstation texture; three registry-backed objects and state markers | +| HUD and pause | `scenes/main.tscn`, `ui/hud.gd`; fixed status/connection/prompt regions, scene-local styles | +| Notification feed | Four fixed two-line rows; `!! CRIT`, `! NORM`, `. LOW`; 32 tracked entries | +| Media console | Three fixed two-line rows; `+ PLAY`, `= PAUSE`, `. STOP`; 16 tracked players, capability-specific controls | +| Workspace map | Five-column, maximum 20-cell grid; active `>`, urgent `!`, special `~` markers | +| Typography | Godot default font; body 7 px, title/counter 8 px; clipped fixed-region labels | +| Spacing | 4 px base, 16 px tile; list panels at (40,24), width 240; map at (40,30) | + +`ui/design_tokens.gd` owns shared semantic colors, geometry and font sizes. +Ready cyan, waiting amber and failure red supplement labels and symbols. +World amber/text retain their slightly different original values, intentionally. +Sprite-local skin, clothing and texture-detail shades are not UI palette roles. +Scene-authored HUD styles remain serialized scene resources, not panel constants. + +Rendered baseline on Intel UHD (CML GT2), Wayland: 60.00 FPS average, +18.43 ms p95, 600 frames. Resource baseline: 0.0% sampled idle Core CPU, +20 KiB RSS growth; private-D-Bus overhead 1752 KiB, 0 KiB growth. +Synthetic baseline images are private local evidence, not live session captures. + +The token-only migration was byte-identical across hub, notification feed, +empty media and workspace fixtures. The later workspace primitive migration +deliberately gives cells a readable fixed width and tighter vertical margins; +all 20 cells and the footer now fit inside the canvas. Selection follows the +workspace handle rather than jumping back to the active workspace on updates. + +For reproducible synthetic visual review (requires a graphical session): + +```bash +capture_dir="$(mktemp -d /tmp/velora-visual.XXXXXX)" +VELORA_VISUAL_DIR="$capture_dir" godot --path frontend/godot \ + --script res://tests/visual_foundation_fixture.gd +``` + +The fixture disables backend auto-connect and exports native and scaled +frames for populated, empty, waiting, unavailable, stale, and crowded views. +It reads no live notifications, media or compositor data. Review these frames +alongside `./scripts/velora.sh gate` and `./scripts/velora.sh perf`. diff --git a/frontend/godot/FOUNDATION_REVIEW.md b/frontend/godot/FOUNDATION_REVIEW.md new file mode 100644 index 0000000..931b274 --- /dev/null +++ b/frontend/godot/FOUNDATION_REVIEW.md @@ -0,0 +1,55 @@ +# D6.01–D6.04 foundation acceptance + +Reviewed on 2026-09-26 against merged Phase 5 baseline `5bdf1dc`. +This records local evidence, not a claim that GitHub CI ran. + +| Card | Evidence | +| --- | --- | +| D6.01 | Token tests; byte-identical before/after token-migration frames for hub, feed, empty media and workspace map; inventory in `ASSET_INVENTORY.md` | +| D6.02 | Existing notification/media suites retained; cursor tests for bounds, wrap, deletion and stable keys; workspace handle preservation; counters and 20-cell geometry regression tests | +| D6.03 | Temporary-file round trips, defaults, corrupt/oversized/unknown/partial files, malformed bindings/IDs, field allowlist, mutable-copy isolation, reset isolation; unused v1 config removed | +| D6.04 | 30 cycles through all modal states; late close rejection; live status while paused; real prompt restoration; actual viewport key events; context-specific media keys and InputMap substitution | + +## Validation + +- `./scripts/velora.sh gate`: passed, including 224 Rust tests, strict Clippy, + all prior frontend tests, the five new foundation suites, security checks, + and Core/private-D-Bus resource gates. +- `./scripts/check-ipc.sh`: passed isolated handshake/restart/reconnect. +- `./scripts/check-dev.sh`: passed normal-exit and signal child cleanup. +- `./scripts/velora.sh perf`: passed on Intel UHD (CML GT2), Wayland, + Compatibility renderer, 600 frames. Before: 60.00 FPS, 18.43 ms p95. + After: 60.00 FPS, 17.09 ms p95. These samples show no budget regression; + they are not a claim of a statistically significant speedup. +- Core idle CPU: 0.0%, RSS growth 20 KiB. Private-D-Bus overhead: 1756 KiB, + growth 0 KiB during the sample window. +- Input-action and overlay suites also passed with the real Wayland renderer. +- Agent inspected native 320 × 180 and integer-scaled synthetic frames: + populated/empty feed, restricted state, populated/stale media, crowded + workspaces and pause. No live data was captured. +- `git diff --check`: passed. No Core/protocol changes in this branch, + no system configuration writes, no private docs or generated media staged. + +## Review findings resolved + +- Clipped counters were squeezed to zero width next to an expanding title: + reserve a bounded counter region and test its width. +- Clipped workspace cells collapsed to unreadable strips: assign a fixed + column width and preserve the selection by handle across updates. +- A full 20-cell map exceeded the canvas by six pixels: tighten cell vertical + margins; verify the complete panel/footer fits within 180 px. +- A settings file could grow between its size check and read: bound both. + +## Boundaries and follow-up + +This is an implementation self-review, not an independent human approval. +Rendered keyboard tests use synthetic input; the owner's real-system Phase 5 +acceptance is recorded on PR #8. No new live application launch is claimed. + +Existing pause copy still says Phase 1 and its telemetry/HUD layering needs +the planned D6.06/D6.08 pass. The settings API deliberately does not introduce +a settings UI, apply remapping, or make saved station IDs launchable. +Those remain later cards, along with color/grayscale accessibility refinement. + +Next: D6.05 — unified world-object art and hub layout. Phase 6 as a whole is +not complete; D6.05–D6.13 remain. diff --git a/frontend/godot/scripts/input_actions.gd b/frontend/godot/scripts/input_actions.gd new file mode 100644 index 0000000..f0e814a --- /dev/null +++ b/frontend/godot/scripts/input_actions.gd @@ -0,0 +1,38 @@ +extends RefCounted +## Shared defaults. Existing bindings are never overwritten by registration. +## Context decides which actions are active (N is next only inside media). + +const DEFAULTS := { + "move_up": [KEY_W, KEY_UP], "move_down": [KEY_S, KEY_DOWN], + "move_left": [KEY_A, KEY_LEFT], "move_right": [KEY_D, KEY_RIGHT], + "sprint": [KEY_SHIFT], "interact": [KEY_E, KEY_ENTER], + "menu": [KEY_ESCAPE], "back": [KEY_ESCAPE], + "workspace_map": [KEY_TAB, KEY_M], "notification_feed": [KEY_N], + "media_console": [KEY_P], "confirm": [KEY_ENTER, KEY_KP_ENTER], + "nav_up": [KEY_UP, KEY_W], "nav_down": [KEY_DOWN, KEY_S], + "nav_left": [KEY_LEFT, KEY_A], "nav_right": [KEY_RIGHT, KEY_D], + "page_up": [KEY_PAGEUP], "page_down": [KEY_PAGEDOWN], + "first": [KEY_HOME], "last": [KEY_END], + "media_toggle": [KEY_SPACE, KEY_E, KEY_ENTER, KEY_KP_ENTER], + "media_next": [KEY_N, KEY_RIGHT, KEY_D], + "media_previous": [KEY_B, KEY_LEFT, KEY_A], + "media_stop": [KEY_X], "media_play": [KEY_KP_0], "media_pause": [KEY_KP_2], +} + +static func ensure_registered() -> void: + for action in DEFAULTS: + if not InputMap.has_action(action): + InputMap.add_action(action) + if not InputMap.action_get_events(action).is_empty(): + continue + for key in DEFAULTS[action]: + var event := InputEventKey.new() + event.physical_keycode = key + InputMap.action_add_event(action, event) + +static func pressed(event: InputEvent, action: StringName) -> bool: + if event is InputEventKey and event.physical_keycode == 0: + # Synthetic/accessibility key events may carry only a logical keycode. + event = event.duplicate() + event.physical_keycode = event.keycode + return event.is_action_pressed(action, false) diff --git a/frontend/godot/scripts/main.gd b/frontend/godot/scripts/main.gd index b93d033..e9be96d 100644 --- a/frontend/godot/scripts/main.gd +++ b/frontend/godot/scripts/main.gd @@ -1,5 +1,7 @@ extends Node2D +const Actions = preload("res://scripts/input_actions.gd") +const Overlay = preload("res://ui/overlay_coordinator.gd") const SessionBinding = preload("res://scripts/session_binding.gd") @onready var player: CharacterBody2D = $World/Player @@ -9,13 +11,25 @@ const SessionBinding = preload("res://scripts/session_binding.gd") @onready var notification_feed: CanvasLayer = $NotificationFeed @onready var media_console: CanvasLayer = $MediaConsole -var menu_open := false -var map_open := false -var feed_open := false -var media_open := false +var overlays: RefCounted +# Read-only compatibility views; the coordinator is the only state owner. +var menu_open: bool: + get: return overlays.current == Overlay.Mode.PAUSE +var map_open: bool: + get: return overlays.current == Overlay.Mode.WORKSPACES +var feed_open: bool: + get: return overlays.current == Overlay.Mode.NOTIFICATIONS +var media_open: bool: + get: return overlays.current == Overlay.Mode.MEDIA var _stations: Array[Node] = [] func _ready() -> void: + Actions.ensure_registered() + overlays = Overlay.new(player, hud, { + Overlay.Mode.WORKSPACES: workspace_map, + Overlay.Mode.NOTIFICATIONS: notification_feed, + Overlay.Mode.MEDIA: media_console, + }) player.interaction_changed.connect(hud.set_interaction_prompt) player.interaction_requested.connect(_on_interaction_requested) player.menu_requested.connect(_toggle_menu) @@ -52,53 +66,45 @@ func _ready() -> void: _on_applications_changed(backend.applications) hud.set_status("VELORA // POCKET TERMINAL") +func _input(event: InputEvent) -> void: + if Actions.pressed(event, "back") or Actions.pressed(event, "menu"): + get_viewport().set_input_as_handled() + _toggle_menu() + func _unhandled_input(event: InputEvent) -> void: - if menu_open or map_open or feed_open or media_open or not event is InputEventKey: + if overlays.current != Overlay.Mode.NONE: return - if not event.pressed or event.echo: - return - if event.keycode in [KEY_TAB, KEY_M]: + if Actions.pressed(event, "workspace_map"): get_viewport().set_input_as_handled() _toggle_workspace_map() - elif event.keycode == KEY_N: + elif Actions.pressed(event, "notification_feed"): get_viewport().set_input_as_handled() _toggle_notification_feed() - elif event.keycode == KEY_P: + elif Actions.pressed(event, "media_console"): get_viewport().set_input_as_handled() _toggle_media_console() func _toggle_workspace_map() -> void: - map_open = true - player.set_input_enabled(false) - workspace_map.open() + overlays.toggle(Overlay.Mode.WORKSPACES) func _on_map_closed() -> void: - map_open = false - player.set_input_enabled(true) + overlays.close(Overlay.Mode.WORKSPACES) func _toggle_notification_feed() -> void: - feed_open = true - player.set_input_enabled(false) - # Scene-driven refresh: the client fetches once per connection, so the - # panel asks for a fresh single-flight feed whenever it is inspected. - backend.request_notifications() - notification_feed.open() + if not feed_open: + backend.request_notifications() + overlays.toggle(Overlay.Mode.NOTIFICATIONS) func _on_feed_closed() -> void: - feed_open = false - player.set_input_enabled(true) + overlays.close(Overlay.Mode.NOTIFICATIONS) func _toggle_media_console() -> void: - media_open = true - player.set_input_enabled(false) - # Scene-driven refresh: the client fetches once per connection, so the - # console asks for a fresh single-flight snapshot whenever it is opened. - backend.request_media_snapshot() - media_console.open() + if not media_open: + backend.request_media_snapshot() + overlays.toggle(Overlay.Mode.MEDIA) func _on_media_console_closed() -> void: - media_open = false - player.set_input_enabled(true) + overlays.close(Overlay.Mode.MEDIA) func _on_session_snapshot_changed(snapshot: Dictionary) -> void: workspace_map.update_session(snapshot) @@ -199,6 +205,7 @@ func _on_applications_changed(applications: Array) -> void: station.bind_application(applications_by_id.get(station.desktop_id, {})) func _toggle_menu() -> void: - menu_open = not menu_open - player.set_input_enabled(not menu_open) - hud.set_menu_visible(menu_open) + if overlays.current != Overlay.Mode.NONE: + overlays.back() + else: + overlays.open(Overlay.Mode.PAUSE) diff --git a/frontend/godot/scripts/pixel_art.gd b/frontend/godot/scripts/pixel_art.gd index 7e8ea44..8848b89 100644 --- a/frontend/godot/scripts/pixel_art.gd +++ b/frontend/godot/scripts/pixel_art.gd @@ -1,18 +1,20 @@ class_name VeloraPixelArt extends RefCounted -const TILE_SIZE := Vector2i(16, 16) -const DEEP_NAVY := Color("0b1020") -const FLOOR_BLUE := Color("17233b") -const FLOOR_LIGHT := Color("1d2c49") -const STEEL_BLUE := Color("293858") -const STEEL_LIGHT := Color("41577c") -const CYAN := Color("41d6c3") -const CYAN_LIGHT := Color("9af4e7") -const AMBER := Color("f5b942") -const RED := Color("e05a67") -const SOFT_WHITE := Color("dce6f2") -const SHADOW := Color("070a13") +const Tokens = preload("res://ui/design_tokens.gd") + +const TILE_SIZE := Tokens.TILE_SIZE +const DEEP_NAVY := Tokens.WORLD_BACKGROUND +const FLOOR_BLUE := Tokens.WORLD_FLOOR +const FLOOR_LIGHT := Tokens.WORLD_FLOOR_LIGHT +const STEEL_BLUE := Tokens.WORLD_STEEL +const STEEL_LIGHT := Tokens.WORLD_STEEL_LIGHT +const CYAN := Tokens.WORLD_ACCENT +const CYAN_LIGHT := Tokens.READY +const AMBER := Tokens.WORLD_AMBER +const RED := Tokens.FAILURE +const SOFT_WHITE := Tokens.WORLD_TEXT +const SHADOW := Tokens.WORLD_SHADOW static func create_tileset() -> TileSet: var image := Image.create_empty(64, 16, false, Image.FORMAT_RGBA8) @@ -130,7 +132,7 @@ static func _draw_wall_tile(image: Image, origin: Vector2i) -> void: image.fill_rect(Rect2i(origin, TILE_SIZE), DEEP_NAVY) image.fill_rect(Rect2i(origin + Vector2i(1, 1), Vector2i(14, 14)), STEEL_BLUE) image.fill_rect(Rect2i(origin + Vector2i(1, 1), Vector2i(14, 3)), STEEL_LIGHT) - image.fill_rect(Rect2i(origin + Vector2i(3, 7), Vector2i(10, 2)), Color("1d2c49")) + image.fill_rect(Rect2i(origin + Vector2i(3, 7), Vector2i(10, 2)), Tokens.WORLD_FLOOR_LIGHT) image.set_pixelv(origin + Vector2i(3, 12), AMBER) static func _draw_threshold_tile(image: Image, origin: Vector2i) -> void: diff --git a/frontend/godot/scripts/player.gd b/frontend/godot/scripts/player.gd index f2ca040..3f53871 100644 --- a/frontend/godot/scripts/player.gd +++ b/frontend/godot/scripts/player.gd @@ -1,5 +1,6 @@ extends CharacterBody2D +const Actions = preload("res://scripts/input_actions.gd") const PixelArt = preload("res://scripts/pixel_art.gd") signal interaction_changed(prompt: String) @@ -22,14 +23,14 @@ var _last_prompt := "" var _texture_cache: Dictionary = {} func _ready() -> void: - _register_controls() + Actions.ensure_registered() _update_detector_position() _update_sprite() func _unhandled_input(event: InputEvent) -> void: - if event.is_action_pressed("menu"): + if Actions.pressed(event, "menu"): menu_requested.emit() - elif input_enabled and event.is_action_pressed("interact") and active_interactable: + elif input_enabled and Actions.pressed(event, "interact") and active_interactable: interaction_requested.emit(active_interactable) func _physics_process(delta: float) -> void: @@ -54,6 +55,10 @@ func set_input_enabled(enabled: bool) -> void: _last_prompt = "" interaction_changed.emit("") +func refresh_interaction() -> void: + if input_enabled: + _update_interaction() + func _set_facing_from_movement(movement: Vector2) -> void: if absf(movement.x) > absf(movement.y): facing = Vector2.RIGHT if movement.x > 0 else Vector2.LEFT @@ -114,22 +119,3 @@ func _update_interaction() -> void: if prompt != _last_prompt: _last_prompt = prompt interaction_changed.emit(prompt) - -func _register_controls() -> void: - _ensure_action("move_up", [KEY_W, KEY_UP]) - _ensure_action("move_down", [KEY_S, KEY_DOWN]) - _ensure_action("move_left", [KEY_A, KEY_LEFT]) - _ensure_action("move_right", [KEY_D, KEY_RIGHT]) - _ensure_action("sprint", [KEY_SHIFT]) - _ensure_action("interact", [KEY_E, KEY_ENTER]) - _ensure_action("menu", [KEY_ESCAPE]) - -func _ensure_action(action: StringName, keys: Array[int]) -> void: - if not InputMap.has_action(action): - InputMap.add_action(action) - if not InputMap.action_get_events(action).is_empty(): - return - for keycode in keys: - var event := InputEventKey.new() - event.physical_keycode = keycode - InputMap.action_add_event(action, event) diff --git a/frontend/godot/scripts/settings_store.gd b/frontend/godot/scripts/settings_store.gd new file mode 100644 index 0000000..5aca0cf --- /dev/null +++ b/frontend/godot/scripts/settings_store.gd @@ -0,0 +1,176 @@ +extends RefCounted +## UI-only preferences. Construction/load never writes. Runtime snapshots must +## never enter this store. Bindings and station mappings are future UI inputs, +## not authorization to launch: IDs still require the live trusted registry. + +const VERSION := 1 +const DEFAULT_PATH := "user://velora-settings.json" +const MAX_BYTES := 16384 +const MAX_BINDINGS := 4 +const ACTIONS := ["move_up", "move_down", "move_left", "move_right", "sprint", + "interact", "menu", "workspace_map", "notification_feed", "media_console", + "back", "confirm", "nav_up", "nav_down", "nav_left", "nav_right", + "page_up", "page_down", "first", "last", "media_toggle", "media_next", + "media_previous", "media_stop", "media_play", "media_pause"] +const SLOTS := ["editor", "browser", "terminal"] + +var _path: String +var _onboarding := false +var _reduced_motion := false +var _muted := false +var _volume := 0.5 +var _bindings: Dictionary = {} +var _stations: Dictionary = {} + +func _init(path: String = DEFAULT_PATH) -> void: + _path = path + +func onboarding_completed() -> bool: + return _onboarding + +func set_onboarding_completed(value: bool) -> void: + _onboarding = value + +func reduced_motion() -> bool: + return _reduced_motion + +func set_reduced_motion(value: bool) -> void: + _reduced_motion = value + +func audio_muted() -> bool: + return _muted + +func set_audio_muted(value: bool) -> void: + _muted = value + +func audio_volume() -> float: + return _volume + +func set_audio_volume(value: float) -> void: + _volume = clampf(value, 0.0, 1.0) if is_finite(value) else 0.5 + +## Empty means no override: the input contract supplies the default bindings. +func action_keys(action: String) -> Array[int]: + var result: Array[int] = [] + result.assign(_bindings.get(action, [])) + return result + +func set_action_keys(action: String, keys: Array) -> bool: + if action not in ACTIONS or not _valid_keys(keys): + return false + _bindings[action] = keys.duplicate() + return true + +func station_desktop_id(slot: String) -> String: + return _stations.get(slot, "") + +func set_station_desktop_id(slot: String, desktop_id: String) -> bool: + if slot not in SLOTS or not _valid_desktop_id(desktop_id): + return false + _stations[slot] = desktop_id + return true + +func load_settings() -> Error: + _defaults() + if not FileAccess.file_exists(_path): + return OK + var file := FileAccess.open(_path, FileAccess.READ) + if file == null: + return FileAccess.get_open_error() + if file.get_length() > MAX_BYTES: + return ERR_INVALID_DATA + # Bound the actual read too, in case another process grows the file. + var bytes := file.get_buffer(MAX_BYTES + 1) + if bytes.size() > MAX_BYTES: + return ERR_INVALID_DATA + var parser := JSON.new() + if parser.parse(bytes.get_string_from_utf8()) != OK or not parser.data is Dictionary: + return ERR_PARSE_ERROR + var data: Dictionary = parser.data + if data.get("version") != VERSION: + return ERR_INVALID_DATA + if data.get("onboarding_completed") is bool: + _onboarding = data.onboarding_completed + if data.get("reduced_motion") is bool: + _reduced_motion = data.reduced_motion + if data.get("audio_muted") is bool: + _muted = data.audio_muted + if data.get("audio_volume") is float or data.get("audio_volume") is int: + set_audio_volume(float(data.audio_volume)) + if data.get("bindings") is Dictionary: + for action in ACTIONS: + if data.bindings.get(action) is Array: + set_action_keys(action, data.bindings[action]) + if data.get("stations") is Dictionary: + for slot in SLOTS: + if data.stations.get(slot) is String: + set_station_desktop_id(slot, data.stations[slot]) + return OK + +func save_settings() -> Error: + var payload := JSON.stringify({"version": VERSION, + "onboarding_completed": _onboarding, "reduced_motion": _reduced_motion, + "audio_muted": _muted, "audio_volume": _volume, + "bindings": _bindings, "stations": _stations}) + if payload.to_utf8_buffer().size() > MAX_BYTES: + return ERR_INVALID_DATA + # Same-directory replacement leaves the previous file intact on write failure. + var temporary := _path + ".tmp" + var file := FileAccess.open(temporary, FileAccess.WRITE) + if file == null: + return FileAccess.get_open_error() + file.store_string(payload) + file.flush() + var error := file.get_error() + file.close() + if error == OK: + error = DirAccess.rename_absolute(temporary, _path) + if error != OK: + DirAccess.remove_absolute(temporary) + return error + +func reset() -> Error: + _defaults() + if FileAccess.file_exists(_path): + return DirAccess.remove_absolute(_path) + return OK + +func _defaults() -> void: + _onboarding = false + _reduced_motion = false + _muted = false + _volume = 0.5 + _bindings.clear() + _stations.clear() + +static func _valid_keys(keys: Array) -> bool: + if keys.is_empty() or keys.size() > MAX_BINDINGS: + return false + var seen := {} + for value in keys: + if not (value is int or value is float) or not is_finite(float(value)) or float(value) != floorf(float(value)): + return false + if float(value) < 0 or float(value) > KEY_SPECIAL + 256: + return false + var key := int(value) + # Named keyboard keys only, no modifier bit fields or arbitrary integers. + if not ((key >= KEY_A and key <= KEY_Z) or (key >= KEY_0 and key <= KEY_9) + or key in [KEY_SPACE, KEY_ESCAPE, KEY_TAB, KEY_ENTER, KEY_KP_ENTER, + KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, KEY_SHIFT, KEY_CTRL, KEY_ALT, + KEY_HOME, KEY_END, KEY_PAGEUP, KEY_PAGEDOWN, KEY_KP_0, KEY_KP_2]): + return false + if seen.has(key): + return false + seen[key] = true + return true + +static func _valid_desktop_id(value: String) -> bool: + if value.length() <= 8 or value.length() > 255 or not value.ends_with(".desktop"): + return false + if value.begins_with(".") or value.contains(".."): + return false + for character in value: + if not (character >= "a" and character <= "z" or character >= "A" and character <= "Z" + or character >= "0" and character <= "9" or character in [".", "-", "_"]): + return false + return true diff --git a/frontend/godot/tests/design_tokens_validation.gd b/frontend/godot/tests/design_tokens_validation.gd new file mode 100644 index 0000000..6165242 --- /dev/null +++ b/frontend/godot/tests/design_tokens_validation.gd @@ -0,0 +1,13 @@ +extends SceneTree + +const Tokens = preload("res://ui/design_tokens.gd") + +func _initialize() -> void: + assert(Tokens.CANVAS == Vector2i(320, 180)) + assert(Tokens.TILE_SIZE == Vector2i(16, 16)) + assert(Tokens.TONES == {"ready": Color("9af4e7"), "waiting": Color("f5b943"), "failure": Color("e05a67")}) + assert(Tokens.WORLD_AMBER == Color("f5b942")) + assert(Tokens.WORLD_TEXT == Color("dce6f2")) + assert(Tokens.PANEL_POSITION.x + Tokens.PANEL_WIDTH <= Tokens.CANVAS.x) + print("D6.01 design token validation passed.") + quit() diff --git a/frontend/godot/tests/input_actions_validation.gd b/frontend/godot/tests/input_actions_validation.gd new file mode 100644 index 0000000..cba9fdc --- /dev/null +++ b/frontend/godot/tests/input_actions_validation.gd @@ -0,0 +1,65 @@ +extends SceneTree + +const Actions = preload("res://scripts/input_actions.gd") +const Store = preload("res://scripts/settings_store.gd") +var failures: Array[String] = [] + +func _initialize() -> void: + call_deferred("_run") + +func check(value: bool, message: String) -> void: + if not value: + failures.append(message) + push_error(message) + +func key(code: int, pressed: bool = true) -> InputEventKey: + var event := InputEventKey.new() + event.keycode = code + event.physical_keycode = code + event.pressed = pressed + return event + +func tap(code: int) -> void: + Input.parse_input_event(key(code)) + await process_frame + Input.parse_input_event(key(code, false)) + await process_frame + +func _run() -> void: + Actions.ensure_registered() + var store := Store.new("/tmp/velora-input-test-unused.json") + for action in Actions.DEFAULTS: + check(store.set_action_keys(action, Actions.DEFAULTS[action]), "Default bindings fit the settings allowlist") + check(not InputMap.action_get_events(action).is_empty(), "Every action has defaults") + var main = load("res://scenes/main.tscn").instantiate() + main.get_node("BackendClient").auto_connect = false + root.add_child(main) + await process_frame + for code in [KEY_M, KEY_TAB, KEY_N, KEY_P]: + await tap(code) + check(not main.player.input_enabled, "Top-level action opens a modal") + await tap(KEY_ESCAPE) + check(main.player.input_enabled, "Escape closes modal without opening pause") + await tap(KEY_ESCAPE) + check(main.menu_open, "Escape from world opens pause") + await tap(KEY_ESCAPE) + check(not main.menu_open and main.player.input_enabled, "Escape resumes") + await tap(KEY_P) + await tap(KEY_N) + check(main.media_open and not main.feed_open, "Media next does not open notifications") + await tap(KEY_P) + check(main.player.input_enabled, "Panel toggle closes its own modal") + # A named action follows InputMap, rather than retaining a hidden raw-key path. + InputMap.action_erase_events("workspace_map") + InputMap.action_add_event("workspace_map", key(KEY_G)) + Actions.ensure_registered() + await tap(KEY_M) + check(not main.map_open, "Removed default is not silently reinstalled") + await tap(KEY_G) + check(main.map_open, "Top-level dispatch follows the named action") + await tap(KEY_ESCAPE) + main.queue_free() + await process_frame + if failures.is_empty(): + print("D6.04 input action validation passed.") + quit(0 if failures.is_empty() else 1) diff --git a/frontend/godot/tests/overlay_validation.gd b/frontend/godot/tests/overlay_validation.gd new file mode 100644 index 0000000..89f7917 --- /dev/null +++ b/frontend/godot/tests/overlay_validation.gd @@ -0,0 +1,51 @@ +extends SceneTree + +const Overlay = preload("res://ui/overlay_coordinator.gd") +var failures: Array[String] = [] + +func _initialize() -> void: + call_deferred("_run") + +func check(value: bool, message: String) -> void: + if not value: + failures.append(message) + push_error(message) + +func _run() -> void: + var main = load("res://scenes/main.tscn").instantiate() + main.get_node("BackendClient").auto_connect = false + root.add_child(main) + await process_frame + var coordinator: RefCounted = main.overlays + for _cycle in range(30): + for mode in [Overlay.Mode.PAUSE, Overlay.Mode.WORKSPACES, Overlay.Mode.NOTIFICATIONS, Overlay.Mode.MEDIA]: + coordinator.open(mode) + var count := int(main.hud.menu_overlay.visible) + int(main.workspace_map.visible) + int(main.notification_feed.visible) + int(main.media_console.visible) + check(count == 1 and not main.player.input_enabled, "Exactly one modal owns input") + main.backend.ux_status_changed.emit("reconnecting", "RECONNECTING", "waiting", -1.0) + coordinator.close(Overlay.Mode.NONE) + check(coordinator.current == mode and not main.player.input_enabled, "Stale close cannot unlock a newer modal") + coordinator.back() + check(main.player.input_enabled, "Back always restores movement") + main._toggle_menu() + main.backend.ux_status_changed.emit("ready", "READY", "ready", -1.0) + check(main.hud.menu_connection.text == "CONNECTED", "Backend state updates while paused") + main._toggle_menu() + check(main.hud.status.text == "VELORA // READY", "Pause preserves useful status") + main.player.global_position = Vector2(160, 82) + main.player.facing = Vector2.UP + main.player._update_detector_position() + await physics_frame + await physics_frame + main.player.refresh_interaction() + var prompt: String = main.hud.prompt.text + check(not prompt.is_empty(), "Prompt recovery fixture has an actual station target") + main._toggle_menu() + check(not main.hud.prompt_panel.visible, "Modal hides world prompt") + main._toggle_menu() + check(main.hud.prompt.text == prompt, "Close restores the current world prompt") + main.queue_free() + await process_frame + if failures.is_empty(): + print("D6.04 overlay coordination validation passed.") + quit(0 if failures.is_empty() else 1) diff --git a/frontend/godot/tests/panel_primitives_validation.gd b/frontend/godot/tests/panel_primitives_validation.gd new file mode 100644 index 0000000..aabc264 --- /dev/null +++ b/frontend/godot/tests/panel_primitives_validation.gd @@ -0,0 +1,40 @@ +extends SceneTree + +const Cursor = preload("res://ui/list_cursor.gd") +const Shell = preload("res://ui/panel_shell.gd") + +func _initialize() -> void: + call_deferred("_run") + +func _run() -> void: + var cursor := Cursor.new(4) + cursor.select(99, 10) + assert(cursor.selected == 9 and cursor.offset == 6) + cursor.move(1, 10) + assert(cursor.selected == 0 and cursor.offset == 0) + cursor.move(-1, 10) + assert(cursor.selected == 9 and cursor.offset == 6) + cursor.preserve(["b", "a"], "a", 0) + assert(cursor.selected == 1 and cursor.offset == 0) + cursor.preserve(["c"], "missing", 9) + assert(cursor.selected == 0) + cursor.select(1, 0) + assert(cursor.selected == -1 and cursor.offset == 0) + var layer := CanvasLayer.new() + root.add_child(layer) + var shell := Shell.new(layer) + var rows := VBoxContainer.new() + shell.box.add_child(rows) + var row := Shell.row(rows) + row.summary.text = "Long text ".repeat(100) + shell.title.text = "TITLE ".repeat(100) + shell.finish("ARROWS SELECT") + await process_frame + await process_frame + assert(shell.panel.position.x + shell.panel.size.x <= 320) + assert(shell.counter.size.x >= 24) + assert(row.summary.clip_text and row.detail.clip_text and shell.hint.clip_text) + layer.queue_free() + await process_frame + print("D6.02 panel primitives validation passed.") + quit() diff --git a/frontend/godot/tests/settings_validation.gd b/frontend/godot/tests/settings_validation.gd new file mode 100644 index 0000000..5b8ae03 --- /dev/null +++ b/frontend/godot/tests/settings_validation.gd @@ -0,0 +1,68 @@ +extends SceneTree + +const Store = preload("res://scripts/settings_store.gd") +var failures: Array[String] = [] +var path := "" + +func _initialize() -> void: + # A unique injected path, never the default user settings. + path = "/tmp/velora-settings-test-%d-%d.json" % [OS.get_process_id(), Time.get_ticks_usec()] + call_deferred("_run") + +func check(value: bool, message: String) -> void: + if not value: + failures.append(message) + push_error(message) + +func write(text: String) -> void: + var file := FileAccess.open(path, FileAccess.WRITE) + file.store_string(text) + file.close() + +func _run() -> void: + var settings := Store.new(path) + check(settings.load_settings() == OK and not FileAccess.file_exists(path), "Missing settings do not write") + check(not settings.reduced_motion() and settings.audio_volume() == 0.5, "Safe defaults") + settings.set_onboarding_completed(true) + settings.set_reduced_motion(true) + settings.set_audio_muted(true) + settings.set_audio_volume(9.0) + check(settings.audio_volume() == 1.0, "Volume clamps") + settings.set_audio_volume(NAN) + check(settings.audio_volume() == 0.5, "Non-finite volume defaults") + check(settings.set_action_keys("interact", [KEY_E, KEY_ENTER]), "Allowlisted bindings") + check(not settings.set_action_keys("execute", [KEY_E]), "Unknown actions rejected") + for keys in [[], [KEY_E, KEY_E], [KEY_A, KEY_B, KEY_C, KEY_D, KEY_F], [1.5], ["E"], [-1]]: + check(not settings.set_action_keys("interact", keys), "Malformed bindings rejected") + check(settings.set_station_desktop_id("editor", "org.example.Editor.desktop"), "Desktop ID accepted") + for id in ["/usr/bin/app", "../app.desktop", "sh -c app.desktop", "a;id.desktop", "$HOME.desktop", "org.mpris.MediaPlayer2.foo", "x".repeat(256) + ".desktop"]: + check(not settings.set_station_desktop_id("editor", id), "Unsafe station mapping rejected") + check(not settings.set_station_desktop_id("unknown", "app.desktop"), "Fixed slots only") + var copy := settings.action_keys("interact") + copy.clear() + check(settings.action_keys("interact").size() == 2, "Accessors do not leak mutable state") + check(settings.save_settings() == OK, "Save succeeds") + var restored := Store.new(path) + check(restored.load_settings() == OK and restored.onboarding_completed() and restored.audio_muted() and restored.reduced_motion(), "Typed preferences round trip") + check(restored.action_keys("interact") == [KEY_E, KEY_ENTER], "Bindings round trip") + check(restored.station_desktop_id("editor") == "org.example.Editor.desktop", "Desktop ID round trip") + write('{"version":1,"reduced_motion":true,"audio_volume":"bad","bindings":{"execute":[65]},"notifications":["private"],"media":{"title":"private"}}') + check(settings.load_settings() == OK and settings.reduced_motion() and settings.audio_volume() == 0.5, "Partial data defaults field by field") + check(settings.save_settings() == OK, "Validated fields save") + var saved := FileAccess.get_file_as_string(path) + check(not saved.contains("private") and not saved.contains("execute") and not saved.contains("notifications"), "Unknown/live data is never persisted") + for invalid in ["not json", "[]", '{"version":99,"reduced_motion":true}', '{"reduced_motion":true}', "x".repeat(Store.MAX_BYTES + 1)]: + write(invalid) + check(settings.load_settings() != OK and not settings.reduced_motion(), "Corrupt/oversized/unsupported settings fail safe") + var unrelated := path + ".unrelated" + var other := FileAccess.open(unrelated, FileAccess.WRITE) + other.store_string("untouched") + other.close() + check(settings.reset() == OK and not FileAccess.file_exists(path), "Reset removes own file") + check(FileAccess.file_exists(unrelated), "Reset preserves other files") + DirAccess.remove_absolute(unrelated) + DirAccess.remove_absolute(path) + DirAccess.remove_absolute(path + ".tmp") + if failures.is_empty(): + print("D6.03 settings validation passed.") + quit(0 if failures.is_empty() else 1) diff --git a/frontend/godot/tests/visual_foundation_fixture.gd b/frontend/godot/tests/visual_foundation_fixture.gd new file mode 100644 index 0000000..9c680c1 --- /dev/null +++ b/frontend/godot/tests/visual_foundation_fixture.gd @@ -0,0 +1,71 @@ +extends SceneTree + +func _initialize() -> void: + call_deferred("_run") + +func _run() -> void: + var main = load("res://scenes/main.tscn").instantiate() + main.get_node("BackendClient").auto_connect = false + root.add_child(main) + await process_frame + main.player.set_physics_process(false) + main.hud.set_status("VELORA // POCKET TERMINAL") + await _capture("hub") + main.notification_feed.update_feed({"notifications": [ + {"handle": "fixture-1", "app_name": "Demo", "summary": "Build complete", "body": "Synthetic notification", "urgency": "normal", "timestamp_unix_ms": 1}, + {"handle": "fixture-2", "app_name": "Demo", "summary": "A very long synthetic message that must remain inside the panel", "body": "No live data is read by this fixture", "urgency": "critical", "timestamp_unix_ms": 2} + ]}) + main.notification_feed.set_availability("available") + main.notification_feed.open() + await _capture("notifications") + main.notification_feed.close() + main.media_console.set_availability("unavailable") + main.media_console.open() + await _capture("media-empty") + main.media_console.update_media({"active_player_handle": "fixture-player", "players": [ + {"handle": "fixture-player", "identity": "Synthetic Player", "status": "playing", "title": "An intentionally long synthetic title to verify clipping in the console", "artist": "Demo Artist", "can_control": true, "can_play": true, "can_pause": true, "can_go_next": true, "can_go_previous": true} + ]}) + main.media_console.set_availability("available") + await _capture("media-populated") + main.media_console.set_availability("unavailable") + await _capture("media-stale") + main.media_console.close() + main.workspace_map.update_session({"workspaces": [ + {"handle": "workspace-1", "index": 1, "name": "1", "window_count": 2, "is_active": true}, + {"handle": "workspace-2", "index": 2, "name": "2", "window_count": 0} + ]}) + main.workspace_map.open() + await _capture("workspaces") + var crowded: Array = [] + for index in range(20): + crowded.append({"handle": "w-%d" % index, "index": index, "name": "Workspace with a long name", "monitor": "Synthetic monitor", "window_count": 99, "is_urgent": index == 2, "is_special": index == 3, "is_active": index == 0}) + main.workspace_map.update_session({"workspaces": crowded}) + await _capture("workspaces-full") + if main.workspace_map._panel.position.y + main.workspace_map._panel.size.y > 180: + push_error("Workspace panel exceeds canvas: " + str(main.workspace_map._panel.get_rect())) + quit(1) + return + main.workspace_map.close() + main._toggle_menu() + await _capture("pause") + main._toggle_menu() + main.notification_feed.update_feed({"notifications": []}) + for state in ["waiting", "unavailable", "restricted", "available"]: + main.notification_feed.set_availability(state) + main.notification_feed.open() + await _capture("notifications-" + state) + main.notification_feed.close() + main.queue_free() + await process_frame + quit() + +func _capture(label: String) -> void: + await process_frame + await process_frame + await RenderingServer.frame_post_draw + var frame := root.get_texture().get_image() + var output := OS.get_environment("VELORA_VISUAL_DIR") + assert(not output.is_empty(), "Set VELORA_VISUAL_DIR to a private evidence directory") + assert(frame.save_png(output.path_join(label + "-scaled.png")) == OK) + frame.resize(320, 180, Image.INTERPOLATE_NEAREST) + assert(frame.save_png(output.path_join(label + ".png")) == OK) diff --git a/frontend/godot/tests/workspace_map_validation.gd b/frontend/godot/tests/workspace_map_validation.gd index 64a3213..c12bbe7 100644 --- a/frontend/godot/tests/workspace_map_validation.gd +++ b/frontend/godot/tests/workspace_map_validation.gd @@ -118,9 +118,23 @@ func _run() -> void: map.update_session({"sequence": 2, "workspaces": fixture_workspaces.slice(0, 10)}) _check( - map._grid.get_child_count() == 10 and map.selected_index == 1, - "P3.07 refreshed sessions rebuild cells and reselect the active workspace" + map._grid.get_child_count() == 10 and map.selected_index == 0, + "D6.02 refreshed sessions preserve the selected workspace handle" ) + map.update_session({"workspaces": fixture_workspaces.slice(1, 10)}) + _check(map.selected_index == 0, "D6.02 removed selection falls back to the active workspace") + await process_frame + await process_frame + _check(map._panel.position.x + map._panel.size.x <= 320, "D6.02 grid stays within the canvas") + _check(map._cells[0].panel.size.x >= 40, "D6.02 clipped cells retain readable width") + var crowded: Array = [] + for index in range(20): + crowded.append({"handle": "crowded-%d" % index, "index": index, + "name": "A long workspace name", "monitor": "A long monitor name", "window_count": 99}) + map.update_session({"workspaces": crowded}) + await process_frame + await process_frame + _check(map._panel.position.y + map._panel.size.y <= 180, "D6.02 all 20 cells and the footer fit vertically") map.close() _check(not map.visible, "P3.07 close() hides the map again") diff --git a/frontend/godot/ui/design_tokens.gd b/frontend/godot/ui/design_tokens.gd new file mode 100644 index 0000000..bf4753a --- /dev/null +++ b/frontend/godot/ui/design_tokens.gd @@ -0,0 +1,33 @@ +extends RefCounted +## Semantic palette and fixed-canvas geometry. World variants deliberately +## retain their original values; this foundation does not recolor the art. + +const CANVAS := Vector2i(320, 180) +const TILE_SIZE := Vector2i(16, 16) +const SPACE := 4 +const FONT_BODY := 7 +const FONT_TITLE := 8 +const READY := Color("9af4e7") +const WAITING := Color("f5b943") +const FAILURE := Color("e05a67") +const TEXT := Color("dce4f0") +const MUTED := Color("586a80") +const SURFACE := Color("0c1c33") +const SELECTED := Color("16324f") +const PANEL := Color("071226") +const SHADE := Color(0.027451, 0.039216, 0.07451, 0.901961) +const TONES := {"ready": READY, "waiting": WAITING, "failure": FAILURE} +const PANEL_POSITION := Vector2(40, 24) +const PANEL_WIDTH := 240 +const MAP_POSITION := Vector2(40, 30) +const MAP_MINIMUM := Vector2(240, 110) + +const WORLD_BACKGROUND := Color("0b1020") +const WORLD_FLOOR := Color("17233b") +const WORLD_FLOOR_LIGHT := Color("1d2c49") +const WORLD_STEEL := Color("293858") +const WORLD_STEEL_LIGHT := Color("41577c") +const WORLD_ACCENT := Color("41d6c3") +const WORLD_AMBER := Color("f5b942") +const WORLD_TEXT := Color("dce6f2") +const WORLD_SHADOW := Color("070a13") diff --git a/frontend/godot/ui/hud.gd b/frontend/godot/ui/hud.gd index a6f44b8..6ac220a 100644 --- a/frontend/godot/ui/hud.gd +++ b/frontend/godot/ui/hud.gd @@ -1,10 +1,8 @@ extends CanvasLayer -const TONE_COLORS := { - "ready": Color("9af4e7"), - "waiting": Color("f5b943"), - "failure": Color("e05a67"), -} +const Tokens = preload("res://ui/design_tokens.gd") + +const TONE_COLORS := Tokens.TONES @onready var status: Label = $StatusPanel/Margin/Status @onready var connection: Label = $ConnectionPanel/Margin/Connection @@ -26,7 +24,7 @@ func _ready() -> void: _telemetry = Label.new() _telemetry.position = Vector2(8, 146) _telemetry.size = Vector2(304, 12) - _telemetry.add_theme_font_size_override("font_size", 7) + _telemetry.add_theme_font_size_override("font_size", Tokens.FONT_BODY) _telemetry.clip_text = true add_child(_telemetry) set_telemetry_availability("waiting") diff --git a/frontend/godot/ui/list_cursor.gd b/frontend/godot/ui/list_cursor.gd new file mode 100644 index 0000000..922e5c0 --- /dev/null +++ b/frontend/godot/ui/list_cursor.gd @@ -0,0 +1,28 @@ +extends RefCounted +## Bounded navigation only. Owners decide ordering, stable keys and fallback. + +var selected := -1 +var offset := 0 +var page_size: int + +func _init(visible_count: int = 1) -> void: + page_size = maxi(1, visible_count) + +func select(index: int, count: int) -> void: + if count <= 0: + selected = -1 + offset = 0 + return + selected = clampi(index, 0, count - 1) + if selected < offset: + offset = selected + elif selected >= offset + page_size: + offset = selected - page_size + 1 + offset = clampi(offset, 0, maxi(0, count - page_size)) + +func move(step: int, count: int) -> void: + select(0 if selected < 0 or count <= 0 else posmod(selected + step, count), count) + +func preserve(keys: Array, key: String, fallback: int) -> void: + var index := keys.find(key) if not key.is_empty() else -1 + select(index if index >= 0 else fallback, keys.size()) diff --git a/frontend/godot/ui/media_console.gd b/frontend/godot/ui/media_console.gd index 4a297bb..91cf038 100644 --- a/frontend/godot/ui/media_console.gd +++ b/frontend/godot/ui/media_console.gd @@ -1,5 +1,10 @@ extends CanvasLayer +const Actions = preload("res://scripts/input_actions.gd") +const Shell = preload("res://ui/panel_shell.gd") +const Cursor = preload("res://ui/list_cursor.gd") +const Tokens = preload("res://ui/design_tokens.gd") + signal control_requested(player_handle: String, verb: String) signal console_closed @@ -15,15 +20,11 @@ signal console_closed # no animated transitions, so the panel writes nothing to disk and the # reduced-motion guarantee holds by construction. -const TONE_COLORS := { - "ready": Color("9af4e7"), - "waiting": Color("f5b943"), - "failure": Color("e05a67"), -} -const TEXT_COLOR := Color("dce4f0") -const DIM_COLOR := Color("586a80") -const ROW_BG := Color("0c1c33") -const ROW_BG_SELECTED := Color("16324f") +const TONE_COLORS := Tokens.TONES +const TEXT_COLOR := Tokens.TEXT +const DIM_COLOR := Tokens.MUTED +const ROW_BG := Tokens.SURFACE +const ROW_BG_SELECTED := Tokens.SELECTED # Status never relies on color alone: every level renders a distinct marker # glyph plus its spelled name, and color is only a secondary channel. An # unrecognized status is labelled UNKNOWN instead of being guessed. @@ -38,9 +39,9 @@ const STATUS_LABELS := { "stopped": "STOP", } const STATUS_COLORS := { - "playing": Color("9af4e7"), - "paused": Color("f5b943"), - "stopped": Color("586a80"), + "playing": Tokens.READY, + "paused": Tokens.WAITING, + "stopped": Tokens.MUTED, } const VERB_LABELS := { "play": "PLAY", @@ -64,8 +65,12 @@ const MAX_VISIBLE_PLAYERS := 3 const MAX_TRACKED_PLAYERS := 16 var players: Array[Dictionary] = [] -var selected_index := -1 -var scroll_offset := 0 +var _cursor := Cursor.new(MAX_VISIBLE_PLAYERS) +var selected_index: int: + get: return _cursor.selected +var scroll_offset: int: + get: return _cursor.offset +var _shell: RefCounted var availability := "waiting" var active_handle := "" @@ -78,57 +83,52 @@ var _hint: Label var _rows: Array[Dictionary] = [] func _ready() -> void: + Actions.ensure_registered() visible = false _build_ui() func _unhandled_input(event: InputEvent) -> void: if not visible: return - if event is InputEventKey and event.pressed and not event.echo: - match event.keycode: - KEY_ESCAPE, KEY_P: - get_viewport().set_input_as_handled() - close() - KEY_UP, KEY_W: - get_viewport().set_input_as_handled() - _move_selection(-1) - KEY_DOWN, KEY_S: - get_viewport().set_input_as_handled() - _move_selection(1) - KEY_PAGEUP: - get_viewport().set_input_as_handled() - _move_selection(-MAX_VISIBLE_PLAYERS) - KEY_PAGEDOWN: - get_viewport().set_input_as_handled() - _move_selection(MAX_VISIBLE_PLAYERS) - KEY_HOME: - get_viewport().set_input_as_handled() - _select_index(0) - KEY_END: - get_viewport().set_input_as_handled() - _select_index(players.size() - 1) - KEY_SPACE, KEY_E, KEY_ENTER, KEY_KP_ENTER: - get_viewport().set_input_as_handled() - _request_toggle() - KEY_N, KEY_RIGHT, KEY_D: - get_viewport().set_input_as_handled() - _request_verb("next") - KEY_B, KEY_LEFT, KEY_A: - get_viewport().set_input_as_handled() - _request_verb("previous") - KEY_X: - get_viewport().set_input_as_handled() - _request_verb("stop") - # All six allowlisted verbs are keyboard reachable. Standalone - # Play and Pause ride the numpad play/pause glyphs, which the - # world menu already uses for its numeric shortcuts, while - # the primary keys resolve the same verbs from capability. - KEY_KP_0: - get_viewport().set_input_as_handled() - _request_verb("play") - KEY_KP_2: - get_viewport().set_input_as_handled() - _request_verb("pause") + if Actions.pressed(event, "back") or Actions.pressed(event, "media_console"): + get_viewport().set_input_as_handled() + close() + elif Actions.pressed(event, "nav_up"): + get_viewport().set_input_as_handled() + _move_selection(-1) + elif Actions.pressed(event, "nav_down"): + get_viewport().set_input_as_handled() + _move_selection(1) + elif Actions.pressed(event, "page_up"): + get_viewport().set_input_as_handled() + _move_selection(-MAX_VISIBLE_PLAYERS) + elif Actions.pressed(event, "page_down"): + get_viewport().set_input_as_handled() + _move_selection(MAX_VISIBLE_PLAYERS) + elif Actions.pressed(event, "first"): + get_viewport().set_input_as_handled() + _select_index(0) + elif Actions.pressed(event, "last"): + get_viewport().set_input_as_handled() + _select_index(players.size() - 1) + elif Actions.pressed(event, "media_toggle"): + get_viewport().set_input_as_handled() + _request_toggle() + elif Actions.pressed(event, "media_next"): + get_viewport().set_input_as_handled() + _request_verb("next") + elif Actions.pressed(event, "media_previous"): + get_viewport().set_input_as_handled() + _request_verb("previous") + elif Actions.pressed(event, "media_stop"): + get_viewport().set_input_as_handled() + _request_verb("stop") + elif Actions.pressed(event, "media_play"): + get_viewport().set_input_as_handled() + _request_verb("play") + elif Actions.pressed(event, "media_pause"): + get_viewport().set_input_as_handled() + _request_verb("pause") func open() -> void: visible = true @@ -139,12 +139,6 @@ func close() -> void: visible = false console_closed.emit() -func toggle() -> void: - if visible: - close() - else: - open() - func set_availability(next_availability: String) -> void: availability = next_availability _refresh_title() @@ -219,37 +213,15 @@ func _selected_player() -> Dictionary: return {} func _preserve_selection(handle: String) -> void: - if not handle.is_empty(): - for index in range(players.size()): - if String(players[index].get("handle", "")) == handle: - _select_index(index) - return - _select_index(_default_selection()) + _cursor.preserve(players.map(func(player: Dictionary): return player["handle"]), handle, _default_selection()) + _refresh_rows() func _move_selection(step: int) -> void: - if players.is_empty(): - return - if selected_index < 0: - _select_index(0) - return - var count := players.size() - var next_index := selected_index + step - while next_index < 0: - next_index += count - _select_index(next_index % count) + _cursor.move(step, players.size()) + _refresh_rows() func _select_index(index: int) -> void: - if players.is_empty(): - selected_index = -1 - scroll_offset = 0 - _refresh_rows() - return - selected_index = clampi(index, 0, players.size() - 1) - if selected_index < scroll_offset: - scroll_offset = selected_index - elif selected_index >= scroll_offset + MAX_VISIBLE_PLAYERS: - scroll_offset = selected_index - MAX_VISIBLE_PLAYERS + 1 - scroll_offset = clampi(scroll_offset, 0, maxi(0, players.size() - MAX_VISIBLE_PLAYERS)) + _cursor.select(index, players.size()) _refresh_rows() func _refresh_title() -> void: @@ -471,98 +443,16 @@ func _as_text(value: Variant, fallback: String) -> String: return fallback func _build_ui() -> void: - var shade := ColorRect.new() - shade.name = "Shade" - shade.color = Color(0.027451, 0.039216, 0.07451, 0.901961) - shade.set_anchors_preset(Control.PRESET_FULL_RECT) - add_child(shade) - - _panel = PanelContainer.new() - _panel.position = Vector2(40, 24) - _panel.custom_minimum_size = Vector2(240, 0) - add_child(_panel) - - var margin := MarginContainer.new() - margin.add_theme_constant_override("margin_left", 8) - margin.add_theme_constant_override("margin_top", 5) - margin.add_theme_constant_override("margin_right", 8) - margin.add_theme_constant_override("margin_bottom", 5) - _panel.add_child(margin) - - var box := VBoxContainer.new() - box.add_theme_constant_override("separation", 4) - margin.add_child(box) - - var header := HBoxContainer.new() - box.add_child(header) - - _title = Label.new() + _shell = Shell.new(self) + _panel = _shell.panel + _title = _shell.title _title.text = "MEDIA // WAITING" - _title.add_theme_font_size_override("font_size", 8) - _title.add_theme_color_override("font_color", TONE_COLORS["waiting"]) - _title.size_flags_horizontal = Control.SIZE_EXPAND_FILL - _title.clip_text = true - _title.text_overrun_behavior = 3 - header.add_child(_title) - - _counter = Label.new() - _counter.text = "0/0" - _counter.add_theme_font_size_override("font_size", 8) - _counter.add_theme_color_override("font_color", DIM_COLOR) - header.add_child(_counter) - + _counter = _shell.counter _rows_box = VBoxContainer.new() - _rows_box.add_theme_constant_override("separation", 2) - box.add_child(_rows_box) - - # The row structure is fixed and every row keeps the same two clipped - # lines regardless of content, so snapshot bursts can never reflow the - # panel. + _rows_box.add_theme_constant_override("separation", Tokens.SPACE / 2) + _shell.box.add_child(_rows_box) for _row_index in range(MAX_VISIBLE_PLAYERS): - _rows.append(_build_row()) - - _feedback = Label.new() - _feedback.text = "" - _feedback.add_theme_font_size_override("font_size", 7) - _feedback.add_theme_color_override("font_color", DIM_COLOR) - _feedback.clip_text = true - _feedback.text_overrun_behavior = 3 - box.add_child(_feedback) - - _hint = Label.new() - _hint.text = "P CLOSE" - _hint.add_theme_font_size_override("font_size", 7) - _hint.add_theme_color_override("font_color", DIM_COLOR) - _hint.clip_text = true - _hint.text_overrun_behavior = 3 - box.add_child(_hint) - -func _build_row() -> Dictionary: - var row := PanelContainer.new() - var style := StyleBoxFlat.new() - style.bg_color = ROW_BG - style.content_margin_left = 4 - style.content_margin_right = 4 - style.content_margin_top = 2 - style.content_margin_bottom = 2 - row.add_theme_stylebox_override("panel", style) - _rows_box.add_child(row) - - var lines := VBoxContainer.new() - lines.add_theme_constant_override("separation", 0) - row.add_child(lines) - - var summary := Label.new() - summary.add_theme_font_size_override("font_size", 7) - summary.clip_text = true - summary.text_overrun_behavior = 3 - lines.add_child(summary) - - var detail := Label.new() - detail.add_theme_font_size_override("font_size", 7) - detail.add_theme_color_override("font_color", DIM_COLOR) - detail.clip_text = true - detail.text_overrun_behavior = 3 - lines.add_child(detail) - - return {"panel": row, "style": style, "summary": summary, "detail": detail} + _rows.append(Shell.row(_rows_box)) + _feedback = Shell.label() + _shell.box.add_child(_feedback) + _hint = _shell.finish("P CLOSE") diff --git a/frontend/godot/ui/notification_feed.gd b/frontend/godot/ui/notification_feed.gd index 0448aa1..5cf6d1d 100644 --- a/frontend/godot/ui/notification_feed.gd +++ b/frontend/godot/ui/notification_feed.gd @@ -1,5 +1,10 @@ extends CanvasLayer +const Actions = preload("res://scripts/input_actions.gd") +const Shell = preload("res://ui/panel_shell.gd") +const Cursor = preload("res://ui/list_cursor.gd") +const Tokens = preload("res://ui/design_tokens.gd") + signal feed_closed # P5.10 notification feed panel. @@ -11,14 +16,10 @@ signal feed_closed # applied instantly with no animated transitions, so the panel writes # nothing to disk and the reduced-motion guarantee holds by construction. -const TONE_COLORS := { - "ready": Color("9af4e7"), - "waiting": Color("f5b943"), - "failure": Color("e05a67"), -} -const DIM_COLOR := Color("586a80") -const ROW_BG := Color("0c1c33") -const ROW_BG_SELECTED := Color("16324f") +const TONE_COLORS := Tokens.TONES +const DIM_COLOR := Tokens.MUTED +const ROW_BG := Tokens.SURFACE +const ROW_BG_SELECTED := Tokens.SELECTED # Urgency never relies on color alone: every level renders a distinct marker # glyph plus its spelled name, and color is only a secondary channel. const URGENCY_MARKERS := { @@ -32,9 +33,9 @@ const URGENCY_LABELS := { "low": "LOW", } const URGENCY_COLORS := { - "critical": Color("e05a67"), - "normal": Color("dce4f0"), - "low": Color("586a80"), + "critical": Tokens.FAILURE, + "normal": Tokens.TEXT, + "low": Tokens.MUTED, } const FALLBACK_URGENCY := "normal" const MAX_VISIBLE_ENTRIES := 4 @@ -43,8 +44,12 @@ const MAX_VISIBLE_ENTRIES := 4 const MAX_TRACKED_ENTRIES := 32 var entries: Array[Dictionary] = [] -var selected_index := -1 -var scroll_offset := 0 +var _cursor := Cursor.new(MAX_VISIBLE_ENTRIES) +var selected_index: int: + get: return _cursor.selected +var scroll_offset: int: + get: return _cursor.offset +var _shell: RefCounted var availability := "waiting" var _panel: PanelContainer @@ -55,35 +60,34 @@ var _hint: Label var _rows: Array[Dictionary] = [] func _ready() -> void: + Actions.ensure_registered() visible = false _build_ui() func _unhandled_input(event: InputEvent) -> void: if not visible: return - if event is InputEventKey and event.pressed and not event.echo: - match event.keycode: - KEY_ESCAPE, KEY_N: - get_viewport().set_input_as_handled() - close() - KEY_UP, KEY_W: - get_viewport().set_input_as_handled() - _move_selection(-1) - KEY_DOWN, KEY_S: - get_viewport().set_input_as_handled() - _move_selection(1) - KEY_LEFT, KEY_A, KEY_PAGEUP: - get_viewport().set_input_as_handled() - _move_selection(-MAX_VISIBLE_ENTRIES) - KEY_RIGHT, KEY_D, KEY_PAGEDOWN: - get_viewport().set_input_as_handled() - _move_selection(MAX_VISIBLE_ENTRIES) - KEY_HOME: - get_viewport().set_input_as_handled() - _select_index(0) - KEY_END: - get_viewport().set_input_as_handled() - _select_index(entries.size() - 1) + if Actions.pressed(event, "back") or Actions.pressed(event, "notification_feed"): + get_viewport().set_input_as_handled() + close() + elif Actions.pressed(event, "nav_up"): + get_viewport().set_input_as_handled() + _move_selection(-1) + elif Actions.pressed(event, "nav_down"): + get_viewport().set_input_as_handled() + _move_selection(1) + elif Actions.pressed(event, "page_up") or Actions.pressed(event, "nav_left"): + get_viewport().set_input_as_handled() + _move_selection(-MAX_VISIBLE_ENTRIES) + elif Actions.pressed(event, "page_down") or Actions.pressed(event, "nav_right"): + get_viewport().set_input_as_handled() + _move_selection(MAX_VISIBLE_ENTRIES) + elif Actions.pressed(event, "first"): + get_viewport().set_input_as_handled() + _select_index(0) + elif Actions.pressed(event, "last"): + get_viewport().set_input_as_handled() + _select_index(entries.size() - 1) func open() -> void: visible = true @@ -93,12 +97,6 @@ func close() -> void: visible = false feed_closed.emit() -func toggle() -> void: - if visible: - close() - else: - open() - func set_availability(next_availability: String) -> void: availability = next_availability _refresh_title() @@ -138,12 +136,8 @@ func _selected_handle() -> String: return "" func _preserve_selection(handle: String) -> void: - if not handle.is_empty(): - for index in range(entries.size()): - if String(entries[index].get("handle", "")) == handle: - _select_index(index) - return - _select_index(selected_index) + _cursor.preserve(entries.map(func(entry: Dictionary): return entry["handle"]), handle, selected_index) + _refresh_rows() func _newest_first(a: Dictionary, b: Dictionary) -> bool: var a_time := int(a.get("timestamp_unix_ms", 0)) @@ -154,29 +148,11 @@ func _newest_first(a: Dictionary, b: Dictionary) -> bool: return String(a.get("handle", "")) < String(b.get("handle", "")) func _move_selection(step: int) -> void: - if entries.is_empty(): - return - if selected_index < 0: - _select_index(0) - return - var count := entries.size() - var next_index := selected_index + step - while next_index < 0: - next_index += count - _select_index(next_index % count) + _cursor.move(step, entries.size()) + _refresh_rows() func _select_index(index: int) -> void: - if entries.is_empty(): - selected_index = -1 - scroll_offset = 0 - _refresh_rows() - return - selected_index = clampi(index, 0, entries.size() - 1) - if selected_index < scroll_offset: - scroll_offset = selected_index - elif selected_index >= scroll_offset + MAX_VISIBLE_ENTRIES: - scroll_offset = selected_index - MAX_VISIBLE_ENTRIES + 1 - scroll_offset = clampi(scroll_offset, 0, maxi(0, entries.size() - MAX_VISIBLE_ENTRIES)) + _cursor.select(index, entries.size()) _refresh_rows() func _refresh_title() -> void: @@ -255,87 +231,14 @@ func _refresh_counter() -> void: _counter.text = "%d/%d" % [selected_index + 1, entries.size()] func _build_ui() -> void: - var shade := ColorRect.new() - shade.name = "Shade" - shade.color = Color(0.027451, 0.039216, 0.07451, 0.901961) - shade.set_anchors_preset(Control.PRESET_FULL_RECT) - add_child(shade) - - _panel = PanelContainer.new() - _panel.position = Vector2(40, 24) - _panel.custom_minimum_size = Vector2(240, 0) - add_child(_panel) - - var margin := MarginContainer.new() - margin.add_theme_constant_override("margin_left", 8) - margin.add_theme_constant_override("margin_top", 5) - margin.add_theme_constant_override("margin_right", 8) - margin.add_theme_constant_override("margin_bottom", 5) - _panel.add_child(margin) - - var box := VBoxContainer.new() - box.add_theme_constant_override("separation", 4) - margin.add_child(box) - - var header := HBoxContainer.new() - box.add_child(header) - - _title = Label.new() + _shell = Shell.new(self) + _panel = _shell.panel + _title = _shell.title _title.text = "NOTIFICATIONS // WAITING" - _title.add_theme_font_size_override("font_size", 8) - _title.add_theme_color_override("font_color", TONE_COLORS["waiting"]) - _title.size_flags_horizontal = Control.SIZE_EXPAND_FILL - _title.clip_text = true - _title.text_overrun_behavior = 3 - header.add_child(_title) - - _counter = Label.new() - _counter.text = "0/0" - _counter.add_theme_font_size_override("font_size", 8) - _counter.add_theme_color_override("font_color", DIM_COLOR) - header.add_child(_counter) - + _counter = _shell.counter _rows_box = VBoxContainer.new() - _rows_box.add_theme_constant_override("separation", 2) - box.add_child(_rows_box) - - # The row structure is fixed and every row keeps the same two clipped - # lines regardless of content, so feed bursts can never reflow the panel. + _rows_box.add_theme_constant_override("separation", Tokens.SPACE / 2) + _shell.box.add_child(_rows_box) for _row_index in range(MAX_VISIBLE_ENTRIES): - _rows.append(_build_row()) - - _hint = Label.new() - _hint.text = "ARROWS SCROLL N CLOSE" - _hint.add_theme_font_size_override("font_size", 7) - _hint.add_theme_color_override("font_color", DIM_COLOR) - box.add_child(_hint) - -func _build_row() -> Dictionary: - var row := PanelContainer.new() - var style := StyleBoxFlat.new() - style.bg_color = ROW_BG - style.content_margin_left = 4 - style.content_margin_right = 4 - style.content_margin_top = 2 - style.content_margin_bottom = 2 - row.add_theme_stylebox_override("panel", style) - _rows_box.add_child(row) - - var lines := VBoxContainer.new() - lines.add_theme_constant_override("separation", 0) - row.add_child(lines) - - var summary := Label.new() - summary.add_theme_font_size_override("font_size", 7) - summary.clip_text = true - summary.text_overrun_behavior = 3 - lines.add_child(summary) - - var detail := Label.new() - detail.add_theme_font_size_override("font_size", 7) - detail.add_theme_color_override("font_color", DIM_COLOR) - detail.clip_text = true - detail.text_overrun_behavior = 3 - lines.add_child(detail) - - return {"panel": row, "style": style, "summary": summary, "detail": detail} + _rows.append(Shell.row(_rows_box)) + _hint = _shell.finish("ARROWS SCROLL N CLOSE") diff --git a/frontend/godot/ui/overlay_coordinator.gd b/frontend/godot/ui/overlay_coordinator.gd new file mode 100644 index 0000000..c261325 --- /dev/null +++ b/frontend/godot/ui/overlay_coordinator.gd @@ -0,0 +1,54 @@ +extends RefCounted +## Single owner of modal state, world input lock and focus restoration. + +enum Mode { NONE, PAUSE, WORKSPACES, NOTIFICATIONS, MEDIA } + +var _mode: Mode = Mode.NONE +var current: Mode: + get: return _mode +var _player: CharacterBody2D +var _hud: CanvasLayer +var _panels: Dictionary +var _prior_focus: WeakRef + +func _init(player: CharacterBody2D, hud: CanvasLayer, panels: Dictionary) -> void: + _player = player + _hud = hud + _panels = panels + +func open(mode: Mode) -> void: + if mode == _mode or mode < Mode.NONE or mode > Mode.MEDIA: + return + var was_world := _mode == Mode.NONE + _mode = mode + for panel in _panels.values(): + # Hide without emitting a close event that could reenter the coordinator. + panel.visible = false + _hud.set_menu_visible(mode == Mode.PAUSE) + if was_world: + var viewport := _player.get_viewport() + var focus := viewport.gui_get_focus_owner() + _prior_focus = weakref(focus) if focus != null else null + viewport.gui_release_focus() + _player.set_input_enabled(false) + if mode == Mode.NONE: + _player.set_input_enabled(true) + _player.refresh_interaction() + if _prior_focus != null: + var control = _prior_focus.get_ref() + if is_instance_valid(control) and control.is_visible_in_tree(): + control.grab_focus() + _prior_focus = null + elif _panels.has(mode): + _panels[mode].open() + +func close(expected: Mode) -> void: + # Ignore a late close from a panel that no longer owns input. + if _mode == expected: + open(Mode.NONE) + +func toggle(mode: Mode) -> void: + open(Mode.NONE if _mode == mode else mode) + +func back() -> void: + open(Mode.NONE) diff --git a/frontend/godot/ui/panel_shell.gd b/frontend/godot/ui/panel_shell.gd new file mode 100644 index 0000000..38de23a --- /dev/null +++ b/frontend/godot/ui/panel_shell.gd @@ -0,0 +1,79 @@ +extends RefCounted +## Composed fixed-canvas frame; no backend or domain behavior belongs here. + +const Tokens = preload("res://ui/design_tokens.gd") + +var panel: PanelContainer +var box: VBoxContainer +var title: Label +var counter: Label +var hint: Label + +func _init(parent: CanvasLayer, position: Vector2 = Tokens.PANEL_POSITION, + minimum: Vector2 = Vector2(Tokens.PANEL_WIDTH, 0), vertical_margin: int = 5, + with_counter: bool = true) -> void: + var shade := ColorRect.new() + shade.name = "Shade" + shade.color = Tokens.SHADE + shade.set_anchors_preset(Control.PRESET_FULL_RECT) + parent.add_child(shade) + panel = PanelContainer.new() + panel.position = position + panel.custom_minimum_size = minimum + parent.add_child(panel) + var margin := MarginContainer.new() + for edge in ["left", "right"]: + margin.add_theme_constant_override("margin_" + edge, Tokens.SPACE * 2) + for edge in ["top", "bottom"]: + margin.add_theme_constant_override("margin_" + edge, vertical_margin) + panel.add_child(margin) + box = VBoxContainer.new() + box.add_theme_constant_override("separation", Tokens.SPACE) + margin.add_child(box) + title = label("", Tokens.FONT_TITLE, Tokens.WAITING) + if with_counter: + var header := HBoxContainer.new() + box.add_child(header) + title.size_flags_horizontal = Control.SIZE_EXPAND_FILL + header.add_child(title) + counter = label("0/0", Tokens.FONT_TITLE) + # Clipped labels otherwise have zero minimum width beside an expanding title. + counter.custom_minimum_size.x = 24 + counter.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT + header.add_child(counter) + else: + box.add_child(title) + +func finish(hint_text: String) -> Label: + hint = label(hint_text) + box.add_child(hint) + return hint + +static func label(text: String = "", font_size: int = Tokens.FONT_BODY, + color: Color = Tokens.MUTED) -> Label: + var result := Label.new() + result.text = text + result.add_theme_font_size_override("font_size", font_size) + result.add_theme_color_override("font_color", color) + result.clip_text = true + result.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS + return result + +static func row(parent: Container) -> Dictionary: + var panel_row := PanelContainer.new() + var style := StyleBoxFlat.new() + style.bg_color = Tokens.SURFACE + style.content_margin_left = Tokens.SPACE + style.content_margin_right = Tokens.SPACE + style.content_margin_top = Tokens.SPACE / 2 + style.content_margin_bottom = Tokens.SPACE / 2 + panel_row.add_theme_stylebox_override("panel", style) + parent.add_child(panel_row) + var lines := VBoxContainer.new() + lines.add_theme_constant_override("separation", 0) + panel_row.add_child(lines) + var summary := label("", Tokens.FONT_BODY, Tokens.TEXT) + var detail := label() + lines.add_child(summary) + lines.add_child(detail) + return {"panel": panel_row, "style": style, "summary": summary, "detail": detail} diff --git a/frontend/godot/ui/workspace_map.gd b/frontend/godot/ui/workspace_map.gd index 616c6bf..f45529f 100644 --- a/frontend/godot/ui/workspace_map.gd +++ b/frontend/godot/ui/workspace_map.gd @@ -1,23 +1,26 @@ extends CanvasLayer +const Actions = preload("res://scripts/input_actions.gd") +const Shell = preload("res://ui/panel_shell.gd") +const Cursor = preload("res://ui/list_cursor.gd") +const Tokens = preload("res://ui/design_tokens.gd") + signal switch_requested(workspace_handle: String) signal map_closed -const TONE_COLORS := { - "ready": Color("9af4e7"), - "waiting": Color("f5b943"), - "failure": Color("e05a67"), -} -const TEXT_COLOR := Color("dce4f0") -const DIM_COLOR := Color("586a80") -const PANEL_BG := Color("071226") -const CELL_BG := Color("0c1c33") -const CELL_BG_SELECTED := Color("16324f") +const TONE_COLORS := Tokens.TONES +const TEXT_COLOR := Tokens.TEXT +const DIM_COLOR := Tokens.MUTED +const CELL_BG := Tokens.SURFACE +const CELL_BG_SELECTED := Tokens.SELECTED const COLUMNS := 5 const MAX_VISIBLE_WORKSPACES := 20 var visible_workspaces: Array[Dictionary] = [] -var selected_index := -1 +var _cursor := Cursor.new(MAX_VISIBLE_WORKSPACES) +var selected_index: int: + get: return _cursor.selected +var _shell: RefCounted var _panel: PanelContainer var _title: Label @@ -26,38 +29,37 @@ var _hint: Label var _cells: Array[Dictionary] = [] func _ready() -> void: + Actions.ensure_registered() visible = false _build_ui() func _unhandled_input(event: InputEvent) -> void: if not visible: return - if event is InputEventKey and event.pressed and not event.echo: - match event.keycode: - KEY_TAB, KEY_M, KEY_ESCAPE: - get_viewport().set_input_as_handled() - close() - KEY_LEFT, KEY_A: - get_viewport().set_input_as_handled() - _move_selection(-1) - KEY_RIGHT, KEY_D: - get_viewport().set_input_as_handled() - _move_selection(1) - KEY_UP, KEY_W: - get_viewport().set_input_as_handled() - _move_selection(-COLUMNS) - KEY_DOWN, KEY_S: - get_viewport().set_input_as_handled() - _move_selection(COLUMNS) - KEY_HOME: - get_viewport().set_input_as_handled() - _select_index(0) - KEY_END: - get_viewport().set_input_as_handled() - _select_index(visible_workspaces.size() - 1) - KEY_ENTER, KEY_KP_ENTER: - get_viewport().set_input_as_handled() - _confirm_selection() + if Actions.pressed(event, "back") or Actions.pressed(event, "workspace_map"): + get_viewport().set_input_as_handled() + close() + elif Actions.pressed(event, "nav_left"): + get_viewport().set_input_as_handled() + _move_selection(-1) + elif Actions.pressed(event, "nav_right"): + get_viewport().set_input_as_handled() + _move_selection(1) + elif Actions.pressed(event, "nav_up"): + get_viewport().set_input_as_handled() + _move_selection(-COLUMNS) + elif Actions.pressed(event, "nav_down"): + get_viewport().set_input_as_handled() + _move_selection(COLUMNS) + elif Actions.pressed(event, "first"): + get_viewport().set_input_as_handled() + _select_index(0) + elif Actions.pressed(event, "last"): + get_viewport().set_input_as_handled() + _select_index(visible_workspaces.size() - 1) + elif Actions.pressed(event, "confirm"): + get_viewport().set_input_as_handled() + _confirm_selection() func open() -> void: visible = true @@ -67,12 +69,6 @@ func close() -> void: visible = false map_closed.emit() -func toggle() -> void: - if visible: - close() - else: - open() - func set_availability(availability: String) -> void: match availability: "available": @@ -82,19 +78,22 @@ func set_availability(availability: String) -> void: _title.text = "WORKSPACES // NO HYPRLAND" _title.add_theme_color_override("font_color", TONE_COLORS["failure"]) visible_workspaces.clear() - selected_index = -1 + _cursor.select(-1, 0) _refresh_grid() "incompatible": _title.text = "WORKSPACES // INCOMPATIBLE" _title.add_theme_color_override("font_color", TONE_COLORS["failure"]) visible_workspaces.clear() - selected_index = -1 + _cursor.select(-1, 0) _refresh_grid() _: _title.text = "WORKSPACES // WAITING" _title.add_theme_color_override("font_color", TONE_COLORS["waiting"]) func update_session(snapshot: Dictionary) -> void: + var selected_handle := "" + if selected_index >= 0 and selected_index < visible_workspaces.size(): + selected_handle = String(visible_workspaces[selected_index]["handle"]) var raw_workspaces = snapshot.get("workspaces", []) if not raw_workspaces is Array: return @@ -111,7 +110,7 @@ func update_session(snapshot: Dictionary) -> void: ) visible_workspaces = workspaces.slice(0, MAX_VISIBLE_WORKSPACES) set_availability("available") - selected_index = _default_selection() + _cursor.preserve(visible_workspaces.map(func(workspace: Dictionary): return workspace["handle"]), selected_handle, _default_selection()) _refresh_grid() func _default_selection() -> int: @@ -122,10 +121,10 @@ func _default_selection() -> int: func _select_index(index: int) -> void: if visible_workspaces.is_empty(): - selected_index = -1 + _cursor.select(-1, 0) return var previous := selected_index - selected_index = clampi(index, 0, visible_workspaces.size() - 1) + _cursor.select(index, visible_workspaces.size()) if _cells.size() != visible_workspaces.size(): _refresh_grid() return @@ -133,16 +132,10 @@ func _select_index(index: int) -> void: _set_cell_selected(selected_index, true) func _move_selection(step: int) -> void: - if visible_workspaces.is_empty(): - return - if selected_index < 0: - _select_index(0) - return - var count := visible_workspaces.size() - var next := selected_index + step - while next < 0: - next += count - _select_index(next % count) + var previous := selected_index + _cursor.move(step, visible_workspaces.size()) + _set_cell_selected(previous, false) + _set_cell_selected(selected_index, true) func _confirm_selection() -> void: if selected_index < 0 or selected_index >= visible_workspaces.size(): @@ -160,7 +153,7 @@ func _refresh_grid() -> void: if visible_workspaces.is_empty(): var empty_label := Label.new() empty_label.text = "NO SESSION DATA" - empty_label.add_theme_font_size_override("font_size", 7) + empty_label.add_theme_font_size_override("font_size", Tokens.FONT_BODY) empty_label.add_theme_color_override("font_color", DIM_COLOR) _grid.add_child(empty_label) return @@ -198,12 +191,14 @@ func _build_cell(index: int, workspace: Dictionary) -> Dictionary: tone_color = TONE_COLORS["waiting"] var cell := PanelContainer.new() + # Explicit width keeps clipped text readable rather than collapsing cells. + cell.custom_minimum_size.x = floorf((Tokens.PANEL_WIDTH - 16 - 3 * (COLUMNS - 1)) / COLUMNS) var style := StyleBoxFlat.new() style.bg_color = CELL_BG_SELECTED if index == selected_index else CELL_BG style.content_margin_left = 4 style.content_margin_right = 4 - style.content_margin_top = 2 - style.content_margin_bottom = 2 + style.content_margin_top = 1 + style.content_margin_bottom = 1 cell.add_theme_stylebox_override("panel", style) var box := VBoxContainer.new() @@ -212,7 +207,7 @@ func _build_cell(index: int, workspace: Dictionary) -> Dictionary: var header := Label.new() header.text = "%s%s" % [marker, display_name] - header.add_theme_font_size_override("font_size", 7) + header.add_theme_font_size_override("font_size", Tokens.FONT_BODY) header.add_theme_color_override("font_color", tone_color) header.clip_text = true header.text_overrun_behavior = 3 @@ -225,7 +220,7 @@ func _build_cell(index: int, workspace: Dictionary) -> Dictionary: detail_parts.append(monitor) var detail := Label.new() detail.text = " ".join(detail_parts) - detail.add_theme_font_size_override("font_size", 7) + detail.add_theme_font_size_override("font_size", Tokens.FONT_BODY) detail.add_theme_color_override("font_color", DIM_COLOR) detail.clip_text = true detail.text_overrun_behavior = 3 @@ -234,44 +229,14 @@ func _build_cell(index: int, workspace: Dictionary) -> Dictionary: return {"panel": cell, "style": style} func _build_ui() -> void: - var shade := ColorRect.new() - shade.name = "Shade" - shade.color = Color(0.027451, 0.039216, 0.07451, 0.901961) - shade.set_anchors_preset(Control.PRESET_FULL_RECT) - add_child(shade) - - _panel = PanelContainer.new() - _panel.position = Vector2(40, 30) - _panel.custom_minimum_size = Vector2(240, 110) - add_child(_panel) - - var margin := MarginContainer.new() - margin.add_theme_constant_override("margin_left", 8) - margin.add_theme_constant_override("margin_top", 6) - margin.add_theme_constant_override("margin_right", 8) - margin.add_theme_constant_override("margin_bottom", 6) - _panel.add_child(margin) - - var box := VBoxContainer.new() - box.add_theme_constant_override("separation", 4) - margin.add_child(box) - - _title = Label.new() + _shell = Shell.new(self, Tokens.MAP_POSITION, Tokens.MAP_MINIMUM, 6, false) + _panel = _shell.panel + _title = _shell.title _title.text = "WORKSPACES // WAITING" - _title.add_theme_font_size_override("font_size", 8) - _title.add_theme_color_override("font_color", TONE_COLORS["waiting"]) - box.add_child(_title) - _grid = GridContainer.new() _grid.columns = COLUMNS _grid.add_theme_constant_override("h_separation", 3) _grid.add_theme_constant_override("v_separation", 3) - box.add_child(_grid) - - _hint = Label.new() - _hint.text = "ARROWS SELECT TAB CLOSE" - _hint.add_theme_font_size_override("font_size", 7) - _hint.add_theme_color_override("font_color", DIM_COLOR) - box.add_child(_hint) - + _shell.box.add_child(_grid) + _hint = _shell.finish("ARROWS SELECT TAB CLOSE") _refresh_grid() diff --git a/scripts/check-godot.sh b/scripts/check-godot.sh index 4cb92c9..880d4a5 100755 --- a/scripts/check-godot.sh +++ b/scripts/check-godot.sh @@ -36,6 +36,11 @@ run_godot() { } run_godot scene --quit-after 5 +run_godot design-tokens --script res://tests/design_tokens_validation.gd +run_godot panel-primitives --script res://tests/panel_primitives_validation.gd +run_godot settings --script res://tests/settings_validation.gd +run_godot overlays --script res://tests/overlay_validation.gd +run_godot input-actions --script res://tests/input_actions_validation.gd echo "Godot scene validation passed." run_godot phase1 --script res://tests/phase1_validation.gd