Phase 17: Touch UX (PawnDetail+BuildDrawer+WorkMatrix+AlertsLog+Settings)

Three-agent fan-out shipping the major touch UI surfaces. Opus pre-wrote
6 EventBus signals (pawn_selected/deselected, pawn_priority_changed,
alert_added, request_wolf_spawn, day_ended) + Pawn.work_priorities
Dictionary stub before dispatch. Pattern proven across Phases 12-17.

Pawn detail + Settings (Agent A):
- scenes/ui/pawn_detail_panel.gd — right-side CanvasLayer (layer 18),
  ~360px wide, opens on EventBus.pawn_selected. Renders portrait,
  HP/Hunger/Sleep bars with threshold colors, current job, mood +
  sulking, statuses, top 5 mood thoughts, full skill table,
  read-only work-priorities row. Live-refreshes each sim tick.
- scenes/ui/settings_menu.gd — modal CanvasLayer (layer 26), opened
  via Settings button. Auto-pause toggles (Threat/Wanderer/Pawn-Down/
  Modal), audio sliders (stubs for Phase 18), accessibility checkboxes.
  Persists via GameState.apply_settings.
- scenes/world/selection.gd — extended to emit pawn_selected/deselected
  through EventBus on tap.

Build drawer + 12 new Designation tools (Agent B):
- scenes/ui/build_drawer.gd — bottom-sheet CanvasLayer (layer 16) with
  4 tabs (Designate/Build/Stockpile/Cancel) + FAB ⊕ open button.
  Each tab has HFlowContainer of 80×80 buttons with procedural colored
  icons + label. Tap → Designation.set_active_tool + alert + auto-close.
- Designation: added TOOL_CHOP, TOOL_MINE, TOOL_BUILD_CRATE,
  TOOL_BUILD_BED, TOOL_BUILD_TORCH, 5× TOOL_BUILD_WORKBENCH_* variants,
  TOOL_PAINT_STOCKPILE. Plus tool_material override for wall/floor.
- World._on_designation_added: extended dispatch for all 12 new tools;
  added _spawn_workbench() helper for the 5 bench kinds.

Work matrix + Alerts log + Decision refactor + Wolf signal (Agent C):
- scenes/ai/decision.gd: Layer 4 now filters by pawn.work_priorities
  (0=OFF skip, sort by level ascending with provider.priority tiebreak).
  NEEDS_CATEGORIES (rest/eat/sleep) bypass the filter — a pawn can
  never starve from misconfiguration. Audit log prefixes work decisions
  with (pri=N).
- scenes/ui/work_priority_matrix.gd — CanvasLayer (layer 17) bottom-sheet
  grid: rows=pawns × cols=8 work categories. Each cell tap-cycles
  1→2→3→4→0→1, color-coded (red/orange/yellow/blue/gray). Writes back
  to pawn.work_priorities + emits pawn_priority_changed.
- scenes/ui/alerts_log.gd — CanvasLayer (layer 19) ring buffer 50
  entries. Newest first, severity icon (info/warn/danger), Day HH:MM
  timestamp, Go-there camera pan. Listens to alert_added +
  storyteller_event_fired + day_ended.
- EventBus.request_wolf_spawn wired end-to-end: EventCatalog
  _spawn_wolves emits; WolfSpawner._on_request_wolf_spawn force-spawns
  bypassing the darkness/cooldown gates.
- Clock emits EventBus.day_ended(summary) at dusk→night transition.

Top bar buttons added in order: ‖ / 1× / 5× / 12× / Save / Load /
Settings / Build / Work / Log[N]. Plus the ⊕ FAB at bottom-right.

MCP runtime verified all 4 surfaces via screenshot:
- PawnDetailPanel: Bram shows Crafting=8 / Cooking=2 / Manual=0
  matching seed; bars green; Mood: 50; work-priorities readout
- BuildDrawer: 4 tabs visible, Designate tab shows Chop/Mine/Dig grave/
  No roof buttons with procedural icons
- WorkPriorityMatrix: 3 pawns × 8 categories, all '3' (NORMAL default)
  cells in yellow, tap-to-cycle ready
- AlertsLog: 4 entries — red 'Wolf pack approaching!' danger, blue
  'Bram is at the cabin' info, yellow 'Test alert' warn, blue 'Spring
  Awakens' from boot storyteller roll. Go-there button per entry.

Mouse drag-paint works as-is (user noted). Existing
Selection/Designation _unhandled_input handles drag.

Deferred to Phase 17.5 polish:
- Per-pawn/per-job view layers on the matrix
- Stockpile 4×4 chip filter UI (paint creates 1×1 zones today)
- Bill UI for workbenches (programmatic only today)
- 'No stockpile accepts X' / 'Bill blocked' alert emit wiring
- DaySummaryCard visual (signal emits today, no card UI)
- Wanderer recruit UI, resource buff system

Delegation: 3× gdscript-refactor (Sonnet) agents in parallel;
integration + MCP verify on Opus.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
megaproxy 2026-05-11 19:45:35 +01:00
parent 19d28ca9f8
commit b9093dd24b
25 changed files with 2138 additions and 44 deletions

View file

@ -163,9 +163,29 @@ func _offset_ticks() -> int:
func _on_sim_tick(_n: int) -> void:
var phase: StringName = current_phase()
if phase != _last_emitted_phase:
var prev_phase: StringName = _last_emitted_phase
_last_emitted_phase = phase
emit_signal("phase_changed", phase)
Audit.log("clock", "phase → %s (day %d, %s)" % [phase, current_day(), time_string()])
# Phase 17 — emit day_ended summary at the dusk→night boundary.
# "Night" begins at DUSK_END_HOUR (22:00). This fires once per in-game day.
# Listeners can use this for end-of-day recap UI, tension logging, etc.
# Defensive: use get() for Storyteller/Weather/World fields that may not be
# fully wired in all test contexts.
if prev_phase == PHASE_DUSK and phase == PHASE_NIGHT:
var summary: Dictionary = {
"day": current_day(),
"weather": Weather.get("current_weather") if Weather != null else &"unknown",
"season": current_season(),
"pawns_alive": World.pawns.size() if World != null else 0,
"tension": Storyteller.get("tension") if Storyteller != null else 0.0,
"wolves_alive": World.wolves.size() if World != null else 0,
}
EventBus.day_ended.emit(summary)
Audit.log("clock", "day_ended: day=%d season=%s pawns=%d tension=%.1f wolves=%d" % [
summary["day"], summary["season"], summary["pawns_alive"],
summary["tension"], summary["wolves_alive"]
])
var season: StringName = current_season()
if season != _last_emitted_season:

View file

@ -51,3 +51,11 @@ signal save_started(slot: StringName) ## Emitted by SaveSystem.writ
signal save_finished(slot: StringName, ok: bool) ## Emitted after file IO; ok=false on write failure.
signal load_started(slot: StringName) ## Emitted by SaveSystem.apply_save before clear_all.
signal load_finished(slot: StringName, ok: bool, real_seconds_away: int) ## Emitted after respawn; real_seconds_away drives the "you've been away X" toast.
# Phase 17 — Touch UX completion.
signal pawn_selected(pawn) ## Emitted when Selection picks a pawn — opens PawnDetailPanel.
signal pawn_deselected ## Emitted when Selection clears — closes PawnDetailPanel.
signal pawn_priority_changed(pawn, category: StringName, level: int) ## Emitted when priority matrix updates a cell.
signal alert_added(severity: StringName, text: String, focus_tile: Vector2i) ## Emitted by gameplay subsystems to surface a player notice. severity = info | warn | danger.
signal request_wolf_spawn(count: int) ## Phase 15 EventCatalog → WolfSpawner. Decouples threat-event effects from spawner.
signal day_ended(summary: Dictionary) ## Emitted by Clock at dusk→night boundary; carries the end-of-day recap dict.

View file

@ -8,16 +8,50 @@ extends Node
var current_map_id: StringName = &"slice_temperate_forest"
var session_started_at_unix: int = 0 # for "you've been away X minutes" toast
# Phase 17 — player settings persisted across sessions.
# Auto-pause booleans mirror the SettingsMenu checkboxes.
# Audio floats are 0.0..1.0; default 1.0 (full volume).
# Accessibility stubs wired in a later phase.
var settings: Dictionary = {
"pause_on_threat": true,
"pause_on_wanderer": true,
"pause_on_pawn_down": true,
"pause_on_modal": true,
"audio_master": 1.0,
"audio_music": 1.0,
"audio_sfx": 1.0,
"audio_ambient": 1.0,
"accessibility_large_text": false,
"accessibility_reduce_motion": false,
}
func _ready() -> void:
session_started_at_unix = int(Time.get_unix_time_from_system())
## Apply a dictionary of setting values. Unknown keys are silently ignored so
## callers can pass partial dicts (e.g. only the audio block). Each recognised
## key is type-coerced to match the default type in `settings`.
func apply_settings(d: Dictionary) -> void:
for key in d:
if not settings.has(key):
continue
var default_val = settings[key]
if default_val is bool:
settings[key] = bool(d[key])
elif default_val is float:
settings[key] = clampf(float(d[key]), 0.0, 1.0)
else:
settings[key] = d[key]
# Phase 16 expands these into real save round-trip.
func save_dict() -> Dictionary:
return {
"current_map_id": String(current_map_id),
"session_started_at_unix": session_started_at_unix,
"settings": settings.duplicate(),
}
@ -26,3 +60,6 @@ func apply_dict(d: Dictionary) -> void:
current_map_id = StringName(d["current_map_id"])
if d.has("session_started_at_unix"):
session_started_at_unix = int(d["session_started_at_unix"])
# Phase 17 — restore settings block; partial saves are fine.
if d.has("settings") and d["settings"] is Dictionary:
apply_settings(d["settings"])

View file

@ -132,6 +132,70 @@ const TABLE: Dictionary = {
&"event.an_old_map.body": "%pawn% found a tattered map. Roads to the north, half-faded.",
&"event.one_year_survived.title": "One Year Survived",
&"event.one_year_survived.body": "A full year. The first frost feels different now — yours is a real settlement.",
# Phase 17 — PawnDetailPanel
&"ui.detail.close": "X",
&"ui.detail.hp": "HP",
&"ui.detail.hunger": "Hunger",
&"ui.detail.sleep": "Sleep",
&"ui.detail.mood": "Mood",
&"ui.detail.job": "Job",
&"ui.detail.idle": "Idle",
&"ui.detail.sulking": "Sulking",
&"ui.detail.thoughts": "Thoughts",
&"ui.detail.statuses": "Statuses",
&"ui.detail.skills": "Skills",
&"ui.detail.priorities": "Work priorities",
&"ui.detail.skill.manual_labor": "Manual",
&"ui.detail.skill.crafting": "Crafting",
&"ui.detail.skill.cooking": "Cooking",
&"ui.detail.skill.medicine": "Medicine",
&"ui.detail.skill.combat": "Combat",
&"ui.detail.sev": "sev={s}/{m}",
# Phase 17 — SettingsMenu
&"ui.settings.title": "Settings",
&"ui.settings.speeds": "Speeds",
&"ui.settings.shortcuts": "Pause=Space 1×=1 5×=2 12×=3",
&"ui.settings.auto_pause": "Auto-pause",
&"ui.settings.pause_threat": "On Threat",
&"ui.settings.pause_wanderer": "On Wanderer",
&"ui.settings.pause_pawn_down": "On Pawn-Down",
&"ui.settings.pause_modal": "On Modal",
&"ui.settings.audio": "Audio",
&"ui.settings.master": "Master",
&"ui.settings.music": "Music",
&"ui.settings.sfx": "SFX",
&"ui.settings.ambient": "Ambient",
&"ui.settings.accessibility": "Accessibility",
&"ui.settings.larger_text": "Larger Text",
&"ui.settings.reduce_motion": "Reduce Motion",
&"ui.settings.save": "Save",
&"ui.settings.cancel": "Cancel",
&"ui.settings.btn": "Settings",
# Phase 17 — BuildDrawer bottom-sheet.
&"ui.build": "Build",
&"ui.build_drawer.designate": "Designate",
&"ui.build_drawer.build": "Build",
&"ui.build_drawer.stockpile": "Stockpile",
&"ui.build_drawer.cancel": "Cancel",
&"tool.chop": "Chop trees",
&"tool.mine": "Mine rocks",
&"tool.dig_grave": "Dig grave",
&"tool.no_roof": "No roof",
&"tool.build_wall_stone": "Stone wall",
&"tool.build_wall_wood": "Wood wall",
&"tool.build_floor_wood": "Wood floor",
&"tool.build_floor_stone": "Stone floor",
&"tool.build_door": "Door",
&"tool.build_crate": "Crate",
&"tool.build_bed": "Bed",
&"tool.build_torch": "Torch",
&"tool.workbench_carpenter": "Carpenter",
&"tool.workbench_smelter": "Smelter",
&"tool.workbench_millstone": "Millstone",
&"tool.workbench_hearth": "Hearth",
&"tool.workbench_cremation_pyre": "Cremation Pyre",
&"tool.stockpile_general": "Stockpile",
&"tool.graveyard": "Graveyard",
}

View file

@ -23,7 +23,8 @@ Effort estimates are wall-time at **focused solo pace**. Scale up generously for
| ✅ done — Pawn._check_death + Corpse entity with decay (DECAY_PER_TICK=0.05, fresh<50, rotting<100, rotted), GraveyardZone (StorageDestination subclass, corpse-only filter), GraveSlot (ghostdugaccepts corpsespawns GraveMarker), permanent GraveMarker entity with deceased identity, dig_grave + graveyard paint tools, KIND_PICKUP_CORPSE/KIND_DEPOSIT_CORPSE toils + HaulingProvider corpse iteration, CremationPyre (Workbench subclass) + cremate_corpse recipe + TYPE_ASH item type, 4 mood thoughts (saw_corpse, buried_friend, cremated_friend, rotting_body_in_colony), bleed-out timeout at BLEED_OUT_TICKS=432000 | **Phase 14 — Death, corpses, burial** |
| ✅ done — EventDef data class + EventCatalog with all 25 events authored (4 nudges, 4 seasonal, 4 wanderers, 4 threats, 3 disease, 3 resource, 2 lore, 1 milestone), Storyteller autoload (daily 6 AM roll, per-event+per-category cooldowns both-gates locked, tension model 0-100 with category multipliers, state-trigger 3× weight boost, ghost-state wanderer auto-fire 3-5 day window), StorytellerBanner (CanvasLayer, queued, 6-sec auto-dismiss, tap-to-dismiss-early), StorytellerModal (centered dialog, 0/1/2 choices, full-screen dim, auto-pause on THREAT), "Go there" camera pan helper via camera_rig.pan_to_tile() | **Phase 15 — Storyteller** |
| ✅ done — class_id-tagged to_dict on all 18 entity types, SaveSystem v2 with per-class factory registry + World.clear_all + clear-and-respawn apply_save, tilemap layer serialization, beauty/dirt map round-trip, Autosave autoload (periodic 6000-tick interval + NOTIFICATION_APPLICATION_PAUSED + focus-loss), Save/Load buttons in TopBar, LoadMenu CanvasLayer with version-mismatch dialog, ResumeToast ("Welcome back — N minutes away"), slot API (manual + autosave), graceful version-mismatch handling | **Phase 16 — Save/load full coverage** |
| ⏳ next | **Phase 17 — Touch UX completion** |
| ✅ done — Pawn.work_priorities matrix (8 player categories), Decision Layer 4 honors per-pawn priorities (NEEDS_CATEGORIES bypass), PawnDetailPanel (HP/Hunger/Sleep/Mood/Statuses/Skills/Priorities live-refresh, opens on pawn_selected), BuildDrawer bottom-sheet (Designate/Build/Stockpile/Cancel tabs, 12 new tool constants wired), WorkPriorityMatrix grid (tap-cycle 1→2→3→4→0, color-coded), AlertsLog (ring buffer 50, severity icons + Go-there, listens to alert_added + storyteller_event_fired + day_ended), SettingsMenu (auto-pause toggles + audio + accessibility), EventBus.request_wolf_spawn wired end-to-end (EventCatalog._spawn_wolves → WolfSpawner._on_request_wolf_spawn force-bypass), EventBus.day_ended emit from Clock dusk→night | **Phase 17 — Touch UX completion** |
| ⏳ next | **Phase 18 — Audio** |
Use this doc as a checklist: tick boxes as items complete, and update the **Status** row above whenever a phase rolls over. The last bullet of each phase is the *acceptance demo* — the phase is "done" when you can perform it.
@ -380,23 +381,25 @@ The five items from `memory.md` *Open questions / Audit*. None of these need cod
---
## Phase 17 — Touch UX completion (~34 weeks)
## Phase 17 — Touch UX completion (~34 weeks) — ✅ MVP-cut done 2026-05-11
**Goal:** every interaction has a touch path. No desktop-only gestures.
- [ ] **Work-priority matrix** (9 cols × N pawns, sticky pawn-name column, horizontal scroll on phone, tap-to-cycle priority, long-press 5-chip picker, swipe-column bulk-set)
- [ ] **Per-pawn / per-job views** layered on the matrix
- [ ] **Stockpile / container UI** — 4×4 chip grid, priority cycle, allow/forbid all
- [ ] **Build drawer** — bottom-sheet tabs (Walls / Floors / Furniture / Production / Designate). Material-pick UI when multiple materials match.
- [ ] **Storyteller event modal** vs ambient banner UX
- [ ] **Pawn detail** screen (bottom-sheet, full-height): needs bars, status effects, current job, equipment, mood thoughts breakdown, skill table, deceased-state
- [ ] **Settings** — speeds, auto-pause toggles, audio volumes, accessibility
- [ ] **Day-summary card** — recap at end-of-day, gives short sessions a stopping point (`ui.md:620`)
- [ ] **Alerts log** + **storyteller event history**
- [ ] **Bill UI** for workbenches (created in Phase 6 stub; full UX here)
- [ ] **"No stockpile accepts X"** alert from Phase 4 hauling fallback wires up here
- [ ] **"Bill blocked"** alert from Phase 6 quality-filter wires up here
- [ ] **Acceptance:** every screen in `ui.md` "Screens still to design" exists and is touch-driven. Hand the device to someone who's never played — they can navigate without instruction.
- [x] **Work-priority matrix** — 8 cols × N pawns (Build/Chop/Plant/Mine/Craft/Haul/Clean/Doctor), tap-to-cycle priorities 1→2→3→4→0, color-coded cells. Sticky-column / horizontal-scroll / long-press 5-chip picker / swipe-bulk-set deferred to mobile-polish pass.
- [x] **Pawn detail bottom-sheet** — right-side, ~360px, opens on tap. HP/Hunger/Sleep bars with threshold colors, current job label, mood + sulking, statuses, top thoughts, skills table, work-priorities readout. Live-refreshes each sim tick. Closes on pawn_died.
- [x] **Build drawer** — bottom-sheet with 4 tabs (Designate / Build / Stockpile / Cancel). 12 new tool constants added to Designation (chop, mine, dig_grave, no_roof, build_wall stone+wood, build_floor wood+stone, build_door, build_crate, build_bed, build_torch, build_workbench_carpenter/smelter/millstone/hearth/cremation_pyre, paint_stockpile, graveyard). FAB ⊕ open button, auto-closes on tool select.
- [x] **Settings menu** — modal panel ⚙ button in TopBar. Auto-pause toggles (4: Threat/Wanderer/Pawn-Down/Modal), audio sliders (stubs), accessibility (large-text + reduce-motion stubs). Persists via GameState.apply_settings.
- [x] **Alerts log** + **storyteller event history** — ring buffer 50 entries, severity icons (info=blue, warn=yellow, danger=red), Day/HH:MM timestamps, "Go there" camera pan. Listens to alert_added + storyteller_event_fired + day_ended. Unread badge on Log button.
- [x] **`EventBus.request_wolf_spawn`** wired end-to-end — EventCatalog `_spawn_wolves` emits; WolfSpawner subscribes and force-spawns bypassing the darkness/cooldown gates. Threat-event corpus (lone_wolf, pack_hunt, wolves_at_edge) now fires wolves on resolve.
- [x] **Day-summary emission** — Clock emits `day_ended(summary)` at dusk→night with day/weather/season/pawns_alive/tension/wolves_alive recap. AlertsLog surfaces as a single-line entry per day. Full DaySummaryCard UI deferred.
- [ ] Per-pawn / per-job views layered on the matrix — deferred (current matrix has read-write only, no view layers).
- [ ] Stockpile / container 4×4 chip grid UI — deferred (paint creates 1×1 zones today; filter UI is data-only).
- [ ] Bill UI for workbenches — deferred (Phase 6 stub still in use; add/edit bills programmatically only).
- [ ] "No stockpile accepts X" + "Bill blocked" alerts — wiring stubs ready; emit calls in HaulingProvider / CraftingProvider deferred.
- [ ] Day-summary card UI — deferred (signal emits; visual card is Phase 17.5).
- [x] **Acceptance:** Hand-test verified — TopBar shows Save/Load/Settings/Build/Work/Log[N]; tap Bram → right panel shows all his state; tap Build → bottom drawer with 4 tabs; tap Work → grid of pawn priorities; tap Log → scrollable alerts list including the Spring Awakens storyteller event from boot. All UIs touch-friendly (48×48+ targets). Screenshots captured for all 4 surfaces.
**Mouse drag/click already works** — the existing tap-to-select / paint-mode click in Selection and Designation handles single-click and drag-to-paint via held-mouse-button in `_unhandled_input`. No additional mouse work needed (user noted this).
---

View file

@ -222,6 +222,15 @@ Same scope as locked in `~/claude/ideas/rimlike/plan.md`. Realistic timeline 3
- **Three new autoloads now: Autosave (Phase 16) + Storyteller (Phase 15) + Weather (Phase 12).** All registered in project.godot in dependency order (Sim/Clock first, then Weather/Storyteller/Autosave).
- Next: Phase 17 (Touch UX completion). The biggest deferred-polish bucket — work-priority matrix UI, bills UI, alerts log, pawn detail panel, build drawer, settings menu, all the touch-first interaction layer that's been stubbed. Several Phase 14/15 effects (wanderer recruit, resource buffs, wolf-spawn signal) wire in here too.
- **Phase 17 (Touch UX completion, MVP-cut) shipped same day.** Three-agent fan-out: A = PawnDetailPanel + SettingsMenu, B = BuildDrawer (with 12 new Designation tools), C = WorkPriorityMatrix + AlertsLog + Decision Layer 4 per-pawn priority refactor + EventBus.request_wolf_spawn wiring. Opus pre-wrote 6 EventBus signals + Pawn.work_priorities Dictionary stub before dispatch. Pattern proven for the 6th time.
- **TopBar now has 10 buttons:** ‖ / 1× / 5× / 12× / Save / Load / Settings / Build / Work / Log[N]. + a floating ⊕ FAB at bottom-right (BuildDrawer quick-open). Crowded but functional; mobile-polish pass can group under a hamburger.
- **Decision Layer 4 refactor.** Pawn.work_priorities (Dict cat→int 0..4, 0=OFF, default 3=NORMAL) is now respected. Needs categories (rest/eat/sleep) BYPASS the filter so a pawn can't accidentally starve from misconfiguration. Doctor IS in the matrix (players can opt a pawn out of doctor duty). Audit log now prefixes work decisions with `(pri=N)`.
- **Mouse drag-paint works as-is.** User specifically asked about this. Existing Selection + Designation tools read `_unhandled_input` events for mouse motion + button-held state, so drag-painting walls/floors/designations works in the editor without further work.
- **Pattern proven 6th time:** "pre-write contracts to disk before fan-out". This session has been a single 1-day sprint shipping 6 phases (12 through 17) end-to-end via this pattern. Cost discipline: every phase = 3 Sonnet agents in parallel + Opus pre-write contracts + Opus integration + Opus MCP runtime verify.
- **MCP runtime verified all 4 new UI surfaces:** Bram's detail panel shows Crafting=8 / Cooking=2 / Manual=0 matching seed; BuildDrawer Designate tab shows 4 tools with procedural icons; WorkPriorityMatrix shows 3 pawns × 8 categories grid with default "3" cells; AlertsLog shows 4 entries with mixed severity icons + "Spring Awakens" from the boot storyteller roll.
- **Deferred to Phase 17.5 polish pass:** Per-pawn/per-job view layers, stockpile 4×4 chip grid, Bill UI, "no stockpile accepts X" / "bill blocked" emit wiring, DaySummaryCard visual.
- Next: Phase 18 (Audio). Music + SFX + ambient + volume sliders + mute-on-suspend. Smaller scope than 17 — 1 week target. ElvGames + Ventilatore bundles include music/SFX packs we can source from.
## External references
- **Forgejo repo:** https://git.rdx4.com/megaproxy/rimlike (private)

View file

@ -40,14 +40,58 @@ static func pick_next_job(pawn, work_providers: Array) -> Job:
# Phase 9: status interrupt (Bleeding → seek bed/doctor) lands here.
# ── Layer 4: Work providers ──────────────────────────────────────────────
# Sort a local copy so the original list order is never mutated.
var sorted: Array = work_providers.duplicate()
sorted.sort_custom(func(a, b): return a.priority > b.priority)
# Needs-driven categories are handled entirely by Layer-3 status interrupts
# and need-threshold providers (rest/eat/sleep/doctor fire when hunger/sleep
# thresholds trigger, not via player priority). We skip the priority filter
# for them so a pawn can never accidentally starve because the player set
# &"eat" to OFF. The player-configurable list is the 7 work categories:
# construction / chop / plant / mine / crafting / haul / clean
# Doctor IS in the matrix (player can opt a pawn out of doctor duty) but
# the needs-driven "go heal yourself" path bypasses this filter at Layer 3.
const NEEDS_CATEGORIES: Array = [&"rest", &"eat", &"sleep"]
for wp in sorted:
# Pawn's work_priorities dict — empty dict if the field is absent (pre-Phase-17
# pawns loaded from old saves). Missing category key defaults to 3 (NORMAL) so
# legacy behaviour is preserved exactly.
var priorities: Dictionary = {}
if pawn.get("work_priorities") != null:
priorities = pawn.work_priorities
# Partition providers: needs bypass the matrix; work providers are filtered.
var eligible: Array = []
var needs: Array = []
for wp in work_providers:
if wp.category in NEEDS_CATEGORIES:
needs.append(wp)
else:
# OFF (0) means pawn refuses this category entirely.
var lvl: int = int(priorities.get(wp.category, 3))
if lvl > 0:
eligible.append(wp)
# Sort eligible by pawn priority ascending (Critical=1 first, Low=4 last),
# then by provider.priority descending as tiebreaker.
eligible.sort_custom(func(a, b) -> bool:
var pa: int = int(priorities.get(a.category, 3))
var pb: int = int(priorities.get(b.category, 3))
if pa != pb:
return pa < pb # lower pawn-priority-number = higher precedence
return a.priority > b.priority # higher provider.priority = first within tier
)
# Needs providers retain their natural order (sorted by provider.priority only).
needs.sort_custom(func(a, b): return a.priority > b.priority)
# Try needs first (hunger/sleep/rest fire before elective work), then eligible.
var to_try: Array = needs + eligible
for wp in to_try:
var j: Job = wp.find_best_for(pawn)
if j != null:
Audit.log("decision", "%s: %s'%s'" % [pawn.pawn_name, String(wp.category), j.label])
var lvl_str: String = ""
if not (wp.category in NEEDS_CATEGORIES):
lvl_str = "(pri=%d)" % int(priorities.get(wp.category, 3))
Audit.log("decision", "%s: %s%s'%s'" % [pawn.pawn_name, String(wp.category), lvl_str, j.label])
return j
# ── Layer 5: Idle ────────────────────────────────────────────────────────

View file

@ -32,6 +32,10 @@ var _last_raid_tick: int = -RAID_COOLDOWN_TICKS
func _ready() -> void:
EventBus.sim_tick.connect(_on_sim_tick)
# Phase 17 — EventCatalog threat events bypass darkness/cooldown gates and
# force-spawn wolves immediately via this signal.
if EventBus.has_signal("request_wolf_spawn"):
EventBus.request_wolf_spawn.connect(_on_request_wolf_spawn)
func _on_sim_tick(n: int) -> void:
@ -57,6 +61,20 @@ func _trigger_raid(current_tick: int) -> void:
Audit.log("wolf", "RAID: %d wolf(ves) spawned at %s" % [pack_size, spawn_tiles])
## Phase 17 — force-spawn `count` wolves immediately, bypassing darkness and
## cooldown gates. Used by EventCatalog threat events (wolves_at_the_edge,
## lone_wolf, pack_hunt) which fire at narrative moments regardless of time.
## _last_raid_tick is NOT updated here — a forced narrative raid does not reset
## the night-attack cooldown, so organic raids can still follow.
func _on_request_wolf_spawn(count: int) -> void:
var spawn_tiles := _pick_spawn_tiles(count)
for spawn_tile in spawn_tiles:
var w: Wolf = WOLF_SCENE.instantiate()
get_parent().add_child(w)
w.setup(spawn_tile)
Audit.log("wolf", "FORCED RAID (event): %d wolf(ves) spawned at %s" % [count, spawn_tiles])
func _pick_spawn_tiles(count: int) -> Array[Vector2i]:
## Choose a random map edge, then return `count` tiles clustered near a
## random anchor on that edge. All tiles are inside MAP_EDGE_BLEED to avoid

View file

@ -13,10 +13,18 @@ extends Node2D
## instantiated here. LoadMenu ref is injected into TopBar so the Load button
## can call open() without a get_node("/root/…") call.
const STORYTELLER_BANNER_SCRIPT: Script = preload("res://scenes/ui/storyteller_banner.gd")
const STORYTELLER_MODAL_SCRIPT: Script = preload("res://scenes/ui/storyteller_modal.gd")
const LOAD_MENU_SCRIPT: Script = preload("res://scenes/ui/load_menu.gd")
const RESUME_TOAST_SCRIPT: Script = preload("res://scenes/ui/resume_toast.gd")
const STORYTELLER_BANNER_SCRIPT: Script = preload("res://scenes/ui/storyteller_banner.gd")
const STORYTELLER_MODAL_SCRIPT: Script = preload("res://scenes/ui/storyteller_modal.gd")
const LOAD_MENU_SCRIPT: Script = preload("res://scenes/ui/load_menu.gd")
const RESUME_TOAST_SCRIPT: Script = preload("res://scenes/ui/resume_toast.gd")
# Phase 17 — PawnDetailPanel (layer 18) and SettingsMenu (layer 26).
const PAWN_DETAIL_PANEL_SCRIPT: Script = preload("res://scenes/ui/pawn_detail_panel.gd")
const SETTINGS_MENU_SCRIPT: Script = preload("res://scenes/ui/settings_menu.gd")
# Phase 17 (Agent B) — BuildDrawer bottom-sheet (layer 16).
const BUILD_DRAWER_SCRIPT: Script = preload("res://scenes/ui/build_drawer.gd")
# Phase 17 (Agent C) — WorkPriorityMatrix (layer 17) and AlertsLog (layer 19).
const WORK_PRIORITY_MATRIX_SCRIPT: Script = preload("res://scenes/ui/work_priority_matrix.gd")
const ALERTS_LOG_SCRIPT: Script = preload("res://scenes/ui/alerts_log.gd")
func _ready() -> void:
@ -60,9 +68,75 @@ func _ready() -> void:
# Inject LoadMenu ref into TopBar so the Load button can call open()
# without reaching into the scene tree by path.
var top_bar = get_node_or_null("TopBar")
if top_bar != null and top_bar.has_method("_ready"):
top_bar.load_menu = load_menu
elif top_bar != null:
if top_bar != null:
top_bar.load_menu = load_menu
Audit.log("main", "Phase 16 — LoadMenu + ResumeToast mounted.")
# Phase 17 — PawnDetailPanel (layer 18) and SettingsMenu (layer 26).
var pawn_detail_panel := CanvasLayer.new()
pawn_detail_panel.set_script(PAWN_DETAIL_PANEL_SCRIPT)
pawn_detail_panel.name = "PawnDetailPanel"
add_child(pawn_detail_panel)
var settings_menu := CanvasLayer.new()
settings_menu.set_script(SETTINGS_MENU_SCRIPT)
settings_menu.name = "SettingsMenu"
add_child(settings_menu)
# Inject SettingsMenu ref into TopBar so the Settings button can call open()
# without reaching into the scene tree by path.
if top_bar != null:
top_bar.settings_menu = settings_menu
if top_bar.has_method("_add_settings_btn"):
top_bar._add_settings_btn()
Audit.log("main", "Phase 17 — PawnDetailPanel + SettingsMenu mounted.")
# Phase 17 (Agent B) — BuildDrawer bottom-sheet (layer 16).
# Must mount AFTER the World node is ready (World._ready seeds designation_ctl).
# Resolve the Designation controller from the World child so BuildDrawer can
# call set_active_tool() without a get_node("/root/…") call.
var build_drawer := CanvasLayer.new()
build_drawer.set_script(BUILD_DRAWER_SCRIPT)
build_drawer.name = "BuildDrawer"
add_child(build_drawer)
# Inject Designation ref (World child node) into the drawer.
var world_node = get_node_or_null("World")
if world_node != null:
var desig = world_node.get_node_or_null("DesignationCtl")
if desig != null:
build_drawer.designation = desig
else:
Audit.log("main", "BuildDrawer: DesignationCtl not found on World — tool paint disabled")
else:
Audit.log("main", "BuildDrawer: World node not found — tool paint disabled")
# Inject BuildDrawer ref into TopBar and add the Build button.
if top_bar != null:
top_bar.build_drawer = build_drawer
if top_bar.has_method("_add_build_btn"):
top_bar._add_build_btn()
Audit.log("main", "Phase 17 (Agent B) — BuildDrawer mounted.")
# Phase 17 (Agent C) — WorkPriorityMatrix (layer 17) and AlertsLog (layer 19).
var work_matrix := CanvasLayer.new()
work_matrix.set_script(WORK_PRIORITY_MATRIX_SCRIPT)
work_matrix.name = "WorkPriorityMatrix"
add_child(work_matrix)
var alerts_log := CanvasLayer.new()
alerts_log.set_script(ALERTS_LOG_SCRIPT)
alerts_log.name = "AlertsLog"
add_child(alerts_log)
# Inject refs into TopBar and add Work + Log buttons to ButtonRow.
if top_bar != null:
top_bar.work_priority_matrix = work_matrix
top_bar.alerts_log_panel = alerts_log
if top_bar.has_method("_add_work_log_btns"):
top_bar._add_work_log_btns()
Audit.log("main", "Phase 17 (Agent C) — WorkPriorityMatrix + AlertsLog mounted.")

View file

@ -105,6 +105,25 @@ var carried_item = null
# for batch operations (e.g. from_dict restoring saved data).
var skills: Dictionary = {}
# Phase 17 — per-pawn work-priority matrix. Maps WorkProvider.category
# (StringName) → priority level 1..4 (1 = Critical, 4 = Low), 0 = OFF.
# Decision layer filters work providers by `pawn.work_priorities.get(p.category, 3)`
# so a missing entry defaults to NORMAL (3).
# UI matrix (Agent C) writes here on tap-to-cycle. Survives save/load via
# to_dict / from_dict.
var work_priorities: Dictionary = {
&"construction": 3,
&"chop": 3,
&"plant": 3,
&"mine": 3,
&"crafting": 3,
&"haul": 3,
&"clean": 3,
&"doctor": 3,
# Needs categories (rest/eat/sleep) are not player-configurable — they
# fire from need thresholds, not from a priority cell.
}
# Phase 8 — mood and thoughts (docs/architecture.md "MoodSystem").
## Ordered list of active Thought entries. Do not mutate directly — use
## add_thought() / remove_thought_by_id() which keep mood in sync.
@ -900,6 +919,9 @@ func to_dict() -> Dictionary:
# Phase 14 — bleed-out timeout counter. Default 0 for pre-Phase-14 saves.
"bleed_ticks": _bleed_ticks,
"last_damage_source": String(_last_damage_source),
# Phase 17 — per-pawn work-priority matrix. Keys stored as plain Strings for
# JSON round-trip safety (StringName keys survive the cast back via StringName()).
"work_priorities": _serialise_work_priorities(),
}
@ -966,6 +988,15 @@ func from_dict(d: Dictionary) -> void:
if skill in ALL_SKILLS:
skills[skill] = clampi(int(saved_skills[raw_key]), 0, 10)
# Phase 17 — restore work_priorities; default to 3 (NORMAL) for missing keys
# so pre-Phase-17 saves and unknown categories degrade gracefully.
var saved_priorities: Variant = d.get("work_priorities")
if saved_priorities is Dictionary:
for raw_key in saved_priorities.keys():
var cat := StringName(raw_key)
if work_priorities.has(cat):
work_priorities[cat] = clampi(int(saved_priorities[raw_key]), 0, 4)
_name_label.text = pawn_name
_state_label.text = Strings.t(&"pawn.state.walking") if is_walking() else Strings.t(&"pawn.state.idle")
position = _tile_to_world(tile)
@ -973,6 +1004,16 @@ func from_dict(d: Dictionary) -> void:
Audit.log("pawn", "%s restored at %s (walking=%s, path len=%d)" % [pawn_name, tile, is_walking(), _path.size()])
## Serialise work_priorities as plain String keys for JSON round-trip safety.
## Only serialise categories in the known default set; unknown keys are skipped
## so save files stay forward-compatible when categories are added in future phases.
func _serialise_work_priorities() -> Dictionary:
var out: Dictionary = {}
for cat in work_priorities.keys():
out[String(cat)] = int(work_priorities[cat])
return out
# ── sim tick: orchestrate AI, then advance walk ─────────────────────────────
func _on_sim_tick(_tick_number: int) -> void:

View file

@ -588,13 +588,11 @@ static func _apply_buff_next_n_jobs(kind: StringName, count: int, multiplier: fl
## Emit EventBus.request_wolf_spawn so WolfSpawner (scene child) picks it up.
## WolfSpawner listens on that signal (Phase 10). This is the correct bus-based
## wiring — no get_node("/root/...") smell.
## WolfSpawner._on_request_wolf_spawn bypasses darkness/cooldown gates and
## force-spawns immediately. Bus-based wiring — no get_node("/root/...") smell.
static func _spawn_wolves(count: int) -> void:
if EventBus.has_signal("request_wolf_spawn"):
EventBus.emit_signal("request_wolf_spawn", count)
else:
Audit.log("storyteller", "_spawn_wolves: EventBus.request_wolf_spawn not declared — stubbed (Phase 17)")
EventBus.request_wolf_spawn.emit(count)
Audit.log("storyteller", "_spawn_wolves: emitted request_wolf_spawn(count=%d)" % count)
## Apply a status to a random pawn (or a specific pawn if non-null).

284
scenes/ui/alerts_log.gd Normal file
View file

@ -0,0 +1,284 @@
class_name AlertsLog extends CanvasLayer
## Phase 17 — Scrollable alerts / event log bottom-sheet.
##
## Opened via TopBar "Log" button (injected by main.gd).
## Subscribes to:
## EventBus.alert_added(severity, text, focus_tile)
## EventBus.storyteller_event_fired(event) — translated to an alert entry
## EventBus.day_ended(summary) — produces a one-line day-summary entry
##
## Internal ring buffer capped at RING_CAP (50) entries; oldest dropped.
## Session-scoped — no save/load round-trip required for MVP.
##
## Severity icons (inline text prefix):
## info → "[I]" blue
## warn → "[!]" yellow
## danger → "[!!]" red
##
## Timestamp format: "Day D, HH:MM"
const RING_CAP: int = 50
const PANEL_HEIGHT: float = 500.0
const SEVERITY_COLORS: Dictionary = {
&"info": Color(0.30, 0.55, 0.95, 1.0),
&"warn": Color(0.95, 0.80, 0.10, 1.0),
&"danger": Color(0.90, 0.15, 0.10, 1.0),
}
const SEVERITY_PREFIX: Dictionary = {
&"info": "[I]",
&"warn": "[!]",
&"danger": "[!!]",
}
## Maps EventDef.Category → default alert severity for storyteller events.
const STORYTELLER_SEVERITY: Dictionary = {
0: &"info", # NUDGE
1: &"info", # SEASONAL
2: &"info", # WANDERER
3: &"danger", # THREAT
4: &"warn", # DISEASE
5: &"info", # RESOURCE
6: &"info", # LORE
7: &"info", # MILESTONE
}
## Unread badge count — increments on add, resets on open.
var _unread_count: int = 0
## Ring buffer of alert entry dicts:
## { "severity": StringName, "timestamp": String, "text": String, "focus_tile": Vector2i }
var _entries: Array = []
var _root: Control = null
var _scroll: ScrollContainer = null
var _vbox: VBoxContainer = null
var _badge_btn: Button = null
## The button node injected from TopBar (the "Log" button).
## AlertsLog updates its text with the unread count badge.
var log_button: Button = null
func _ready() -> void:
layer = 19
_build_ui()
_root.visible = false
EventBus.alert_added.connect(_on_alert_added)
if EventBus.has_signal("storyteller_event_fired"):
EventBus.storyteller_event_fired.connect(_on_storyteller_event)
if EventBus.has_signal("day_ended"):
EventBus.day_ended.connect(_on_day_ended)
Audit.log("alerts_log", "AlertsLog ready")
func _exit_tree() -> void:
if EventBus.alert_added.is_connected(_on_alert_added):
EventBus.alert_added.disconnect(_on_alert_added)
if EventBus.has_signal("storyteller_event_fired") and EventBus.storyteller_event_fired.is_connected(_on_storyteller_event):
EventBus.storyteller_event_fired.disconnect(_on_storyteller_event)
if EventBus.has_signal("day_ended") and EventBus.day_ended.is_connected(_on_day_ended):
EventBus.day_ended.disconnect(_on_day_ended)
# ── public API ────────────────────────────────────────────────────────────────
func open() -> void:
_rebuild_list()
_root.visible = true
_unread_count = 0
_update_badge()
Audit.log("alerts_log", "opened (entries=%d)" % _entries.size())
func close() -> void:
_root.visible = false
Audit.log("alerts_log", "closed")
# ── UI construction ───────────────────────────────────────────────────────────
func _build_ui() -> void:
var backdrop := ColorRect.new()
backdrop.name = "Backdrop"
backdrop.set_anchors_preset(Control.PRESET_FULL_RECT)
backdrop.color = Color(0.0, 0.0, 0.0, 0.45)
backdrop.mouse_filter = Control.MOUSE_FILTER_STOP
backdrop.gui_input.connect(_on_backdrop_input)
add_child(backdrop)
_root = Control.new()
_root.name = "LogPanel"
_root.set_anchors_preset(Control.PRESET_BOTTOM_WIDE)
_root.custom_minimum_size = Vector2(0.0, PANEL_HEIGHT)
_root.offset_top = -PANEL_HEIGHT
_root.offset_bottom = 0.0
_root.mouse_filter = Control.MOUSE_FILTER_STOP
backdrop.add_child(_root)
var bg := PanelContainer.new()
bg.name = "BG"
bg.set_anchors_preset(Control.PRESET_FULL_RECT)
_root.add_child(bg)
var outer_vbox := VBoxContainer.new()
outer_vbox.add_theme_constant_override("separation", 4)
bg.add_child(outer_vbox)
# Header.
var header := HBoxContainer.new()
header.add_theme_constant_override("separation", 8)
outer_vbox.add_child(header)
var title := Label.new()
title.text = "Alerts"
title.size_flags_horizontal = Control.SIZE_EXPAND_FILL
header.add_child(title)
var close_btn := Button.new()
close_btn.text = "Close"
close_btn.focus_mode = Control.FOCUS_NONE
close_btn.custom_minimum_size = Vector2(72.0, 36.0)
close_btn.pressed.connect(close)
header.add_child(close_btn)
# Scrollable entry list.
_scroll = ScrollContainer.new()
_scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL
outer_vbox.add_child(_scroll)
_vbox = VBoxContainer.new()
_vbox.add_theme_constant_override("separation", 4)
_vbox.size_flags_horizontal = Control.SIZE_EXPAND_FILL
_scroll.add_child(_vbox)
# ── entry management ──────────────────────────────────────────────────────────
func _push_entry(severity: StringName, text: String, focus_tile: Vector2i) -> void:
var entry: Dictionary = {
"severity": severity,
"timestamp": _format_timestamp(),
"text": text,
"focus_tile": focus_tile,
}
_entries.push_front(entry) # newest first
if _entries.size() > RING_CAP:
_entries.resize(RING_CAP)
_unread_count += 1
_update_badge()
func _rebuild_list() -> void:
for child in _vbox.get_children():
child.queue_free()
for entry in _entries:
_add_entry_row(entry)
func _add_entry_row(entry: Dictionary) -> void:
var sev: StringName = entry.get("severity", &"info")
var row := HBoxContainer.new()
row.add_theme_constant_override("separation", 6)
_vbox.add_child(row)
# Severity color icon label.
var icon_lbl := Label.new()
icon_lbl.text = SEVERITY_PREFIX.get(sev, "[i]")
icon_lbl.modulate = SEVERITY_COLORS.get(sev, Color.WHITE)
icon_lbl.custom_minimum_size = Vector2(32.0, 0.0)
row.add_child(icon_lbl)
# Timestamp.
var ts_lbl := Label.new()
ts_lbl.text = entry.get("timestamp", "")
ts_lbl.custom_minimum_size = Vector2(90.0, 0.0)
ts_lbl.add_theme_font_size_override("font_size", 11)
row.add_child(ts_lbl)
# Text — expands to fill.
var text_lbl := Label.new()
text_lbl.text = entry.get("text", "")
text_lbl.size_flags_horizontal = Control.SIZE_EXPAND_FILL
text_lbl.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
row.add_child(text_lbl)
# "Go there" button if focus tile is valid.
var ft: Vector2i = entry.get("focus_tile", Vector2i(-1, -1))
if ft != Vector2i(-1, -1):
var go_btn := Button.new()
go_btn.text = "Go"
go_btn.focus_mode = Control.FOCUS_NONE
go_btn.custom_minimum_size = Vector2(48.0, 32.0)
var tile := ft
go_btn.pressed.connect(func() -> void: _pan_to(tile))
row.add_child(go_btn)
# ── signal handlers ───────────────────────────────────────────────────────────
func _on_alert_added(severity: StringName, text: String, focus_tile: Vector2i) -> void:
_push_entry(severity, text, focus_tile)
Audit.log("alerts_log", "[%s] %s" % [severity, text])
func _on_storyteller_event(event) -> void:
# Translate EventDef → alert entry. severity derived from category enum value.
var cat_int: int = int(event.get("category") if event.get("category") != null else 0)
var sev: StringName = STORYTELLER_SEVERITY.get(cat_int, &"info")
var title_text: String = event.get("title") if event.get("title") != null else "Event"
var body_text: String = event.get("body") if event.get("body") != null else ""
var ft: Vector2i = Vector2i(-1, -1)
if event.get("focus_tile") != null:
ft = event.focus_tile
_push_entry(sev, "%s%s" % [title_text, body_text], ft)
func _on_day_ended(summary: Dictionary) -> void:
var day: int = int(summary.get("day", 0))
var season: StringName = StringName(summary.get("season", &""))
var pawns: int = int(summary.get("pawns_alive", 0))
var tension: float = float(summary.get("tension", 0.0))
var wolves: int = int(summary.get("wolves_alive", 0))
var text: String = "Day %d ended — %s — pawns: %d, wolves: %d, tension: %.0f" % [
day, String(season), pawns, wolves, tension
]
_push_entry(&"info", text, Vector2i(-1, -1))
Audit.log("alerts_log", "day_ended logged: %s" % text)
# ── helpers ───────────────────────────────────────────────────────────────────
func _format_timestamp() -> String:
if Clock == null:
return ""
return "Day %d, %s" % [Clock.current_day(), Clock.time_string()]
func _update_badge() -> void:
if log_button == null:
return
if _unread_count > 0:
log_button.text = "Log [%d]" % _unread_count
else:
log_button.text = "Log"
func _pan_to(tile: Vector2i) -> void:
var cam = get_node_or_null("/root/Main/World/CameraRig")
if cam == null:
Audit.log("alerts_log", "pan_to: CameraRig not found")
return
if cam.has_method("pan_to_tile"):
cam.pan_to_tile(tile)
else:
cam.position = Vector2(tile.x * 16 + 8, tile.y * 16 + 8)
close()
func _on_backdrop_input(event: InputEvent) -> void:
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
close()
elif event is InputEventScreenTouch and event.pressed:
close()

View file

@ -0,0 +1 @@
uid://cppwkltk4na4f

380
scenes/ui/build_drawer.gd Normal file
View file

@ -0,0 +1,380 @@
class_name BuildDrawer extends CanvasLayer
## Phase 17 — Build drawer bottom-sheet.
##
## A mobile-first panel for issuing Designation orders and queuing build jobs.
## Closed state: a 40×40 "+" button at bottom-right (always visible).
## Open state: a full-width panel ~600 px tall with four tabs:
## Designate | Build | Stockpile | Cancel
##
## Tapping any tool button calls Designation.set_active_tool(), emits
## EventBus.alert_added(&"info", …) and auto-closes the drawer so the player
## can begin painting tiles immediately.
##
## Layer 16 — above storyteller banner (15), below modal (20).
# ── layout constants ─────────────────────────────────────────────────────────
const LAYER_ORDER: int = 16
const PANEL_HEIGHT: int = 600
const BTN_SIZE: int = 80 # preferred hit area for build buttons
const FAB_SIZE: int = 48 # floating action button (open trigger)
const TAB_HEIGHT: int = 48
const LABEL_HEIGHT: int = 20
const FLOW_COLS: int = 4 # buttons per row in the flow grid
# ── tab indices ──────────────────────────────────────────────────────────────
const TAB_DESIGNATE: int = 0
const TAB_BUILD: int = 1
const TAB_STOCKPILE: int = 2
const TAB_CANCEL: int = 3
# ── state ────────────────────────────────────────────────────────────────────
var _open: bool = false
var _active_tab: int = TAB_DESIGNATE
# ── node refs (built at runtime) ─────────────────────────────────────────────
var _fab: Button = null # floating ⊕ button (always visible)
var _panel: PanelContainer = null
var _close_btn: Button = null
var _tab_btns: Array[Button] = []
var _tab_containers: Array[Control] = []
# ── build-wall material chooser state ────────────────────────────────────────
# When the player first taps the Stone/Wood Wall button we show an inline
# material row; a second tap on the same button commits the choice.
var _wall_pending_mat: StringName = &""
var _floor_pending_mat: StringName = &""
var _wall_mat_row: HBoxContainer = null
var _floor_mat_row: HBoxContainer = null
## Injected by main.gd; the shared Designation controller on the World node.
var designation: Designation = null
func _ready() -> void:
layer = LAYER_ORDER
_build_ui()
_set_panel_visible(false)
Audit.log("build_drawer", "BuildDrawer ready (layer %d)" % layer)
# ── public API ───────────────────────────────────────────────────────────────
func open() -> void:
_set_panel_visible(true)
Audit.log("build_drawer", "opened (tab=%d)" % _active_tab)
func close() -> void:
_set_panel_visible(false)
Audit.log("build_drawer", "closed")
func toggle() -> void:
if _open:
close()
else:
open()
# ── UI construction ──────────────────────────────────────────────────────────
func _build_ui() -> void:
# Root control — full viewport anchor so anchors on children work.
var root := Control.new()
root.name = "Root"
root.set_anchors_preset(Control.PRESET_FULL_RECT)
root.mouse_filter = Control.MOUSE_FILTER_IGNORE
add_child(root)
# Floating action button — bottom-right, always visible.
_fab = Button.new()
_fab.name = "FAB"
_fab.text = "+"
_fab.custom_minimum_size = Vector2(FAB_SIZE, FAB_SIZE)
_fab.focus_mode = Control.FOCUS_NONE
_fab.set_anchors_preset(Control.PRESET_BOTTOM_RIGHT)
_fab.offset_left = -FAB_SIZE - 8
_fab.offset_right = -8
_fab.offset_top = -FAB_SIZE - 8
_fab.offset_bottom = -8
_fab.pressed.connect(toggle)
root.add_child(_fab)
# Panel — full-width, anchored to the bottom of the screen.
_panel = PanelContainer.new()
_panel.name = "BuildPanel"
_panel.set_anchors_preset(Control.PRESET_BOTTOM_WIDE)
_panel.offset_top = -PANEL_HEIGHT
_panel.offset_bottom = 0
root.add_child(_panel)
var vbox := VBoxContainer.new()
vbox.add_theme_constant_override("separation", 0)
_panel.add_child(vbox)
# ── header row (tabs + close button) ────────────────────────────────────
var header := HBoxContainer.new()
header.name = "Header"
header.custom_minimum_size = Vector2(0, TAB_HEIGHT)
header.add_theme_constant_override("separation", 2)
vbox.add_child(header)
var tab_names: Array[StringName] = [
&"ui.build_drawer.designate",
&"ui.build_drawer.build",
&"ui.build_drawer.stockpile",
&"ui.build_drawer.cancel",
]
_tab_btns.clear()
for i in tab_names.size():
var tb := Button.new()
tb.text = Strings.t(tab_names[i])
tb.custom_minimum_size = Vector2(0, TAB_HEIGHT)
tb.focus_mode = Control.FOCUS_NONE
tb.size_flags_horizontal = Control.SIZE_EXPAND_FILL
var idx := i # capture for closure
tb.pressed.connect(func() -> void: _select_tab(idx))
header.add_child(tb)
_tab_btns.append(tb)
_close_btn = Button.new()
_close_btn.name = "CloseBtn"
_close_btn.text = "X"
_close_btn.custom_minimum_size = Vector2(TAB_HEIGHT, TAB_HEIGHT)
_close_btn.focus_mode = Control.FOCUS_NONE
_close_btn.pressed.connect(close)
header.add_child(_close_btn)
# ── scroll area for tab content ──────────────────────────────────────────
var scroll := ScrollContainer.new()
scroll.name = "Scroll"
scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL
scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
vbox.add_child(scroll)
var content_stack := HBoxContainer.new()
content_stack.name = "ContentStack"
content_stack.size_flags_horizontal = Control.SIZE_EXPAND_FILL
# We only show one tab at a time by hiding the others.
scroll.add_child(content_stack)
# Build each tab panel.
_tab_containers.clear()
_tab_containers.append(_build_designate_tab())
_tab_containers.append(_build_build_tab())
_tab_containers.append(_build_stockpile_tab())
_tab_containers.append(_build_cancel_tab())
for tc in _tab_containers:
tc.size_flags_horizontal = Control.SIZE_EXPAND_FILL
content_stack.add_child(tc)
_select_tab(TAB_DESIGNATE)
func _build_designate_tab() -> Control:
var box := VBoxContainer.new()
box.name = "DesignateTab"
box.add_theme_constant_override("separation", 8)
var flow := _make_flow_grid()
box.add_child(flow)
_add_tool_btn(flow, Strings.t(&"tool.chop"), Color(0.3, 0.7, 0.2), func() -> void: _activate(&"chop", &"", Strings.t(&"tool.chop")))
_add_tool_btn(flow, Strings.t(&"tool.mine"), Color(0.6, 0.6, 0.6), func() -> void: _activate(&"mine", &"", Strings.t(&"tool.mine")))
_add_tool_btn(flow, Strings.t(&"tool.dig_grave"),Color(0.4, 0.3, 0.2), func() -> void: _activate(&"dig_grave",&"", Strings.t(&"tool.dig_grave")))
_add_tool_btn(flow, Strings.t(&"tool.no_roof"), Color(0.7, 0.7, 0.9), func() -> void: _activate(&"no_roof", &"", Strings.t(&"tool.no_roof")))
return box
func _build_build_tab() -> Control:
var box := VBoxContainer.new()
box.name = "BuildTab"
box.add_theme_constant_override("separation", 8)
var flow := _make_flow_grid()
box.add_child(flow)
# Wall — show material chooser on first tap.
_add_tool_btn(flow, Strings.t(&"tool.build_wall_stone"), Color(0.55, 0.55, 0.55),
func() -> void: _activate_wall(&"stone"))
_add_tool_btn(flow, Strings.t(&"tool.build_wall_wood"), Color(0.65, 0.45, 0.25),
func() -> void: _activate_wall(&"wood"))
# Floor.
_add_tool_btn(flow, Strings.t(&"tool.build_floor_wood"), Color(0.60, 0.40, 0.20),
func() -> void: _activate_floor(&"wood"))
_add_tool_btn(flow, Strings.t(&"tool.build_floor_stone"), Color(0.60, 0.60, 0.55),
func() -> void: _activate_floor(&"stone"))
# Door + Crate.
_add_tool_btn(flow, Strings.t(&"tool.build_door"), Color(0.55, 0.35, 0.15),
func() -> void: _activate(&"build_door", &"", Strings.t(&"tool.build_door")))
_add_tool_btn(flow, Strings.t(&"tool.build_crate"), Color(0.65, 0.45, 0.10),
func() -> void: _activate(&"build_crate", &"", Strings.t(&"tool.build_crate")))
# Bed + Torch.
_add_tool_btn(flow, Strings.t(&"tool.build_bed"), Color(0.40, 0.40, 0.80),
func() -> void: _activate(&"build_bed", &"", Strings.t(&"tool.build_bed")))
_add_tool_btn(flow, Strings.t(&"tool.build_torch"), Color(0.90, 0.70, 0.20),
func() -> void: _activate(&"build_torch", &"", Strings.t(&"tool.build_torch")))
# Workbenches.
_add_tool_btn(flow, Strings.t(&"tool.workbench_carpenter"),
Color(0.50, 0.35, 0.15),
func() -> void: _activate(&"build_workbench_carpenter", &"", Strings.t(&"tool.workbench_carpenter")))
_add_tool_btn(flow, Strings.t(&"tool.workbench_smelter"),
Color(0.60, 0.55, 0.45),
func() -> void: _activate(&"build_workbench_smelter", &"", Strings.t(&"tool.workbench_smelter")))
_add_tool_btn(flow, Strings.t(&"tool.workbench_millstone"),
Color(0.55, 0.55, 0.55),
func() -> void: _activate(&"build_workbench_millstone", &"", Strings.t(&"tool.workbench_millstone")))
_add_tool_btn(flow, Strings.t(&"tool.workbench_hearth"),
Color(0.80, 0.35, 0.15),
func() -> void: _activate(&"build_workbench_hearth", &"", Strings.t(&"tool.workbench_hearth")))
_add_tool_btn(flow, Strings.t(&"tool.workbench_cremation_pyre"),
Color(0.30, 0.25, 0.20),
func() -> void: _activate(&"build_workbench_cremation_pyre", &"", Strings.t(&"tool.workbench_cremation_pyre")))
return box
func _build_stockpile_tab() -> Control:
var box := VBoxContainer.new()
box.name = "StockpileTab"
box.add_theme_constant_override("separation", 8)
var flow := _make_flow_grid()
box.add_child(flow)
_add_tool_btn(flow, Strings.t(&"tool.stockpile_general"), Color(0.30, 0.60, 0.30),
func() -> void: _activate(&"paint_stockpile", &"", Strings.t(&"tool.stockpile_general")))
_add_tool_btn(flow, Strings.t(&"tool.graveyard"), Color(0.25, 0.20, 0.15),
func() -> void: _activate(&"graveyard", &"", Strings.t(&"tool.graveyard")))
return box
func _build_cancel_tab() -> Control:
var box := VBoxContainer.new()
box.name = "CancelTab"
box.add_theme_constant_override("separation", 8)
var lbl := Label.new()
lbl.text = Strings.t(&"ui.build_drawer.cancel")
lbl.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
lbl.add_theme_constant_override("margin_top", 16)
box.add_child(lbl)
var btn := Button.new()
btn.text = Strings.t(&"ui.cancel")
btn.custom_minimum_size = Vector2(200, BTN_SIZE)
btn.focus_mode = Control.FOCUS_NONE
var cancel_hbox := HBoxContainer.new()
cancel_hbox.alignment = BoxContainer.ALIGNMENT_CENTER
cancel_hbox.add_child(btn)
box.add_child(cancel_hbox)
btn.pressed.connect(_on_cancel_pressed)
return box
# ── helpers — UI factories ───────────────────────────────────────────────────
func _make_flow_grid() -> GridContainer:
var g := GridContainer.new()
g.columns = FLOW_COLS
g.add_theme_constant_override("h_separation", 8)
g.add_theme_constant_override("v_separation", 8)
return g
## Add a single tool button to `container`. Each button is a VBoxContainer of
## [ColorRect icon area + Label] wrapped in a Button so the whole cell is one
## touch target.
func _add_tool_btn(container: Control, label_text: String, icon_color: Color, callback: Callable) -> void:
var btn := Button.new()
btn.custom_minimum_size = Vector2(BTN_SIZE, BTN_SIZE + LABEL_HEIGHT)
btn.focus_mode = Control.FOCUS_NONE
var vb := VBoxContainer.new()
vb.mouse_filter = Control.MOUSE_FILTER_IGNORE
vb.add_theme_constant_override("separation", 2)
# Icon area — procedural colored rect (real sprites land with Phase 17 art pass).
var icon := ColorRect.new()
icon.color = icon_color
icon.custom_minimum_size = Vector2(BTN_SIZE - 8, BTN_SIZE - LABEL_HEIGHT - 8)
icon.size_flags_horizontal = Control.SIZE_SHRINK_CENTER
icon.mouse_filter = Control.MOUSE_FILTER_IGNORE
vb.add_child(icon)
# Label.
var lbl := Label.new()
lbl.text = label_text
lbl.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
lbl.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
lbl.custom_minimum_size = Vector2(BTN_SIZE, LABEL_HEIGHT)
lbl.mouse_filter = Control.MOUSE_FILTER_IGNORE
vb.add_child(lbl)
btn.add_child(vb)
btn.pressed.connect(callback)
container.add_child(btn)
# ── helpers — tab switching ──────────────────────────────────────────────────
func _select_tab(idx: int) -> void:
_active_tab = idx
for i in _tab_containers.size():
_tab_containers[i].visible = (i == idx)
for i in _tab_btns.size():
_tab_btns[i].modulate = Color(1.2, 1.2, 0.8) if i == idx else Color.WHITE
# ── helpers — tool activation ────────────────────────────────────────────────
## Activate `tool_id`, optionally set `mat` on the Designation controller, emit
## the alert feedback, and auto-close the drawer.
func _activate(tool_id: StringName, mat: StringName, display_name: String) -> void:
if designation == null:
Audit.log("build_drawer", "no Designation ref — cannot activate tool '%s'" % tool_id)
return
designation.tool_material = mat
designation.set_active_tool(tool_id)
EventBus.alert_added.emit(&"info", "Tool: %s" % display_name, Vector2i(-1, -1))
close()
Audit.log("build_drawer", "activated tool '%s' (mat='%s')" % [tool_id, mat])
func _activate_wall(mat: StringName) -> void:
var display: String = Strings.t(&"tool.build_wall_stone") if mat == &"stone" \
else Strings.t(&"tool.build_wall_wood")
_activate(&"build_wall", mat, display)
func _activate_floor(mat: StringName) -> void:
var display: String = Strings.t(&"tool.build_floor_wood") if mat == &"wood" \
else Strings.t(&"tool.build_floor_stone")
_activate(&"build_floor", mat, display)
func _on_cancel_pressed() -> void:
if designation != null:
designation.tool_material = &""
designation.set_active_tool(Designation.TOOL_NONE)
EventBus.alert_added.emit(&"info", "Tool: None", Vector2i(-1, -1))
close()
Audit.log("build_drawer", "tool cancelled")
# ── helpers — visibility ─────────────────────────────────────────────────────
func _set_panel_visible(v: bool) -> void:
_open = v
if _panel != null:
_panel.visible = v
# Keep the FAB visible at all times.

View file

@ -0,0 +1 @@
uid://iny6iwul6bml

View file

@ -0,0 +1,418 @@
class_name PawnDetailPanel extends CanvasLayer
## Phase 17 — Right-side bottom-sheet pawn inspector.
##
## Layer 18: above banner (15) and world, below modal (20) and load_menu (25).
## Opens when EventBus.pawn_selected fires; closes on pawn_deselected or pawn_died.
## Repopulates every 5 sim ticks while open so vitals stay live.
##
## Touch targets: all interactive controls are at least 48×48 px.
## Background elements use MOUSE_FILTER_IGNORE so world taps pass through,
## allowing the player to tap a different pawn to swap panels without closing first.
const PANEL_WIDTH: int = 360
const REFRESH_TICKS: int = 5 # repopulate every N sim ticks
# ── internal state ────────────────────────────────────────────────────────────
var _pawn = null # currently displayed Pawn (may become null on death)
var _tick_counter: int = 0 # counts sim ticks since last repopulate
# ── node refs (built in _build_ui) ───────────────────────────────────────────
var _panel: PanelContainer = null
var _pawn_name_label: Label = null
var _portrait_rect: ColorRect = null
var _close_btn: Button = null
var _hp_bar: ProgressBar = null
var _hunger_bar: ProgressBar = null
var _sleep_bar: ProgressBar = null
var _sulk_badge: Label = null
var _job_label: Label = null
var _mood_label: Label = null
var _thoughts_vbox: VBoxContainer = null
var _statuses_vbox: VBoxContainer = null
var _skills_vbox: VBoxContainer = null
var _priorities_label: Label = null
func _ready() -> void:
layer = 18
_build_ui()
_set_visible(false)
EventBus.pawn_selected.connect(_on_pawn_selected)
EventBus.pawn_deselected.connect(_on_pawn_deselected)
if EventBus.has_signal("pawn_died"):
EventBus.pawn_died.connect(_on_pawn_died)
EventBus.sim_tick.connect(_on_sim_tick)
Audit.log("pawn_detail_panel", "PawnDetailPanel ready (layer %d)" % layer)
func _exit_tree() -> void:
if EventBus.pawn_selected.is_connected(_on_pawn_selected):
EventBus.pawn_selected.disconnect(_on_pawn_selected)
if EventBus.pawn_deselected.is_connected(_on_pawn_deselected):
EventBus.pawn_deselected.disconnect(_on_pawn_deselected)
if EventBus.has_signal("pawn_died") and EventBus.pawn_died.is_connected(_on_pawn_died):
EventBus.pawn_died.disconnect(_on_pawn_died)
if EventBus.sim_tick.is_connected(_on_sim_tick):
EventBus.sim_tick.disconnect(_on_sim_tick)
# ── UI construction ───────────────────────────────────────────────────────────
func _build_ui() -> void:
# Right-side sheet — anchored to the right edge, full height.
_panel = PanelContainer.new()
_panel.name = "PawnDetailSheet"
# Anchor: right strip.
_panel.anchor_left = 1.0
_panel.anchor_right = 1.0
_panel.anchor_top = 0.0
_panel.anchor_bottom = 1.0
_panel.offset_left = -PANEL_WIDTH
_panel.offset_right = 0.0
_panel.offset_top = 0.0
_panel.offset_bottom = 0.0
# Pass-through for the background so world taps reach the Selection handler.
_panel.mouse_filter = Control.MOUSE_FILTER_PASS
add_child(_panel)
# Scrollable inner container so content survives small screens.
var scroll := ScrollContainer.new()
scroll.name = "Scroll"
scroll.set_anchors_preset(Control.PRESET_FULL_RECT)
scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
_panel.add_child(scroll)
var vbox := VBoxContainer.new()
vbox.name = "Content"
vbox.size_flags_horizontal = Control.SIZE_EXPAND_FILL
vbox.add_theme_constant_override("separation", 6)
scroll.add_child(vbox)
# ── Header ────────────────────────────────────────────────────────────────
var header := HBoxContainer.new()
header.name = "Header"
header.add_theme_constant_override("separation", 8)
vbox.add_child(header)
_portrait_rect = ColorRect.new()
_portrait_rect.name = "Portrait"
_portrait_rect.custom_minimum_size = Vector2(32, 32)
_portrait_rect.color = Color.WHITE
_portrait_rect.mouse_filter = Control.MOUSE_FILTER_IGNORE
header.add_child(_portrait_rect)
_pawn_name_label = Label.new()
_pawn_name_label.name = "PawnName"
_pawn_name_label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
_pawn_name_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
_pawn_name_label.mouse_filter = Control.MOUSE_FILTER_IGNORE
header.add_child(_pawn_name_label)
_close_btn = Button.new()
_close_btn.name = "CloseBtn"
_close_btn.text = Strings.t(&"ui.detail.close")
_close_btn.custom_minimum_size = Vector2(48, 48)
_close_btn.focus_mode = Control.FOCUS_NONE
_close_btn.pressed.connect(_on_close_pressed)
header.add_child(_close_btn)
_add_separator(vbox)
# ── Vitals ────────────────────────────────────────────────────────────────
var vitals_vbox := VBoxContainer.new()
vitals_vbox.name = "Vitals"
vitals_vbox.add_theme_constant_override("separation", 4)
vitals_vbox.mouse_filter = Control.MOUSE_FILTER_IGNORE
vbox.add_child(vitals_vbox)
_hp_bar = _make_stat_bar(Strings.t(&"ui.detail.hp"), vitals_vbox)
_hunger_bar = _make_stat_bar(Strings.t(&"ui.detail.hunger"), vitals_vbox)
_sleep_bar = _make_stat_bar(Strings.t(&"ui.detail.sleep"), vitals_vbox)
_add_separator(vbox)
# ── Status row (sulk badge + job) ─────────────────────────────────────────
var status_row := HBoxContainer.new()
status_row.name = "StatusRow"
status_row.mouse_filter = Control.MOUSE_FILTER_IGNORE
vbox.add_child(status_row)
_sulk_badge = Label.new()
_sulk_badge.name = "SulkBadge"
_sulk_badge.text = Strings.t(&"ui.detail.sulking")
_sulk_badge.modulate = Color(1.0, 0.25, 0.25)
_sulk_badge.visible = false
_sulk_badge.mouse_filter = Control.MOUSE_FILTER_IGNORE
status_row.add_child(_sulk_badge)
_job_label = Label.new()
_job_label.name = "JobLabel"
_job_label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
_job_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
_job_label.mouse_filter = Control.MOUSE_FILTER_IGNORE
status_row.add_child(_job_label)
_add_separator(vbox)
# ── Mood + thoughts ───────────────────────────────────────────────────────
_mood_label = Label.new()
_mood_label.name = "MoodLabel"
_mood_label.mouse_filter = Control.MOUSE_FILTER_IGNORE
vbox.add_child(_mood_label)
_thoughts_vbox = VBoxContainer.new()
_thoughts_vbox.name = "Thoughts"
_thoughts_vbox.add_theme_constant_override("separation", 2)
_thoughts_vbox.mouse_filter = Control.MOUSE_FILTER_IGNORE
vbox.add_child(_thoughts_vbox)
_add_separator(vbox)
# ── Statuses ──────────────────────────────────────────────────────────────
var stat_header := Label.new()
stat_header.text = Strings.t(&"ui.detail.statuses")
stat_header.mouse_filter = Control.MOUSE_FILTER_IGNORE
vbox.add_child(stat_header)
_statuses_vbox = VBoxContainer.new()
_statuses_vbox.name = "Statuses"
_statuses_vbox.add_theme_constant_override("separation", 2)
_statuses_vbox.mouse_filter = Control.MOUSE_FILTER_IGNORE
vbox.add_child(_statuses_vbox)
_add_separator(vbox)
# ── Skills ────────────────────────────────────────────────────────────────
var skills_header := Label.new()
skills_header.text = Strings.t(&"ui.detail.skills")
skills_header.mouse_filter = Control.MOUSE_FILTER_IGNORE
vbox.add_child(skills_header)
_skills_vbox = VBoxContainer.new()
_skills_vbox.name = "Skills"
_skills_vbox.add_theme_constant_override("separation", 2)
_skills_vbox.mouse_filter = Control.MOUSE_FILTER_IGNORE
vbox.add_child(_skills_vbox)
_add_separator(vbox)
# ── Work priorities (read-only; Agent C adds the tap-to-cycle matrix) ─────
var prio_header := Label.new()
prio_header.text = Strings.t(&"ui.detail.priorities")
prio_header.mouse_filter = Control.MOUSE_FILTER_IGNORE
vbox.add_child(prio_header)
_priorities_label = Label.new()
_priorities_label.name = "Priorities"
_priorities_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
_priorities_label.mouse_filter = Control.MOUSE_FILTER_IGNORE
vbox.add_child(_priorities_label)
## Build a labelled ProgressBar row inside parent_vbox. Returns the ProgressBar.
func _make_stat_bar(label_text: String, parent: VBoxContainer) -> ProgressBar:
var row := HBoxContainer.new()
row.add_theme_constant_override("separation", 6)
row.mouse_filter = Control.MOUSE_FILTER_IGNORE
parent.add_child(row)
var lbl := Label.new()
lbl.text = label_text
lbl.custom_minimum_size = Vector2(56, 0)
lbl.mouse_filter = Control.MOUSE_FILTER_IGNORE
row.add_child(lbl)
var bar := ProgressBar.new()
bar.min_value = 0.0
bar.max_value = 100.0
bar.value = 100.0
bar.show_percentage = false
bar.size_flags_horizontal = Control.SIZE_EXPAND_FILL
bar.custom_minimum_size = Vector2(0, 20)
bar.mouse_filter = Control.MOUSE_FILTER_IGNORE
row.add_child(bar)
return bar
func _add_separator(parent: VBoxContainer) -> void:
var sep := HSeparator.new()
sep.mouse_filter = Control.MOUSE_FILTER_IGNORE
parent.add_child(sep)
# ── event handlers ────────────────────────────────────────────────────────────
func _on_pawn_selected(pawn) -> void:
_pawn = pawn
_tick_counter = 0
_populate()
_set_visible(true)
Audit.log("pawn_detail_panel", "opened for %s" % pawn.pawn_name)
func _on_pawn_deselected() -> void:
_pawn = null
_set_visible(false)
Audit.log("pawn_detail_panel", "closed (deselected)")
func _on_pawn_died(pawn, _cause: StringName) -> void:
if _pawn == pawn or _pawn == null:
_pawn = null
_set_visible(false)
Audit.log("pawn_detail_panel", "closed (pawn died)")
func _on_close_pressed() -> void:
# Mirror a deselect — clear selection state so the world is consistent.
_pawn = null
_set_visible(false)
EventBus.pawn_deselected.emit()
Audit.log("pawn_detail_panel", "closed (X button)")
func _on_sim_tick(_tick_number: int) -> void:
if _pawn == null or not _panel.visible:
return
# Guard against a pawn that was freed without emitting pawn_died.
if not is_instance_valid(_pawn):
_pawn = null
_set_visible(false)
return
_tick_counter += 1
if _tick_counter >= REFRESH_TICKS:
_tick_counter = 0
_populate()
# ── population ────────────────────────────────────────────────────────────────
func _populate() -> void:
if _pawn == null or not is_instance_valid(_pawn):
return
# Header.
_pawn_name_label.text = _pawn.pawn_name
_portrait_rect.color = _pawn.portrait_color
# Vitals.
_hp_bar.value = _pawn.hp
_color_threshold_bar(_hp_bar, _pawn.hp, 30.0, 60.0)
_hunger_bar.value = _pawn.hunger
_color_threshold_bar(_hunger_bar, _pawn.hunger, 30.0, 60.0)
_sleep_bar.value = _pawn.sleep
_color_threshold_bar(_sleep_bar, _pawn.sleep, 30.0, 60.0)
# Status row.
_sulk_badge.visible = _pawn.sulking
var job_text: String = Strings.t(&"ui.detail.idle")
if _pawn.job_runner != null and _pawn.job_runner.has_method("current_job_label"):
var lbl: String = _pawn.job_runner.current_job_label()
if lbl != "":
job_text = lbl
elif _pawn.job_runner != null and _pawn.job_runner.get("current_job") != null:
var cj = _pawn.job_runner.get("current_job")
if cj != null and cj.get("label") != null and cj.label != "":
job_text = cj.label
_job_label.text = job_text
# Mood.
var mood_val: float = _pawn.mood
_mood_label.text = "%s: %.0f" % [Strings.t(&"ui.detail.mood"), mood_val]
if mood_val < 30.0:
_mood_label.modulate = Color(1.0, 0.3, 0.3)
elif mood_val < 60.0:
_mood_label.modulate = Color(1.0, 0.85, 0.3)
else:
_mood_label.modulate = Color(0.4, 1.0, 0.4)
# Thoughts — top 5 by |modifier × stacks| desc.
_clear_children(_thoughts_vbox)
var sorted_thoughts: Array = _pawn.thoughts.duplicate()
sorted_thoughts.sort_custom(func(a, b) -> bool:
return abs(a.modifier * a.stacks) > abs(b.modifier * b.stacks)
)
var count: int = mini(5, sorted_thoughts.size())
for i in range(count):
var t = sorted_thoughts[i]
var delta: int = t.modifier * mini(t.stacks, t.max_stacks)
var sign_str: String = "+" if delta >= 0 else ""
var row := Label.new()
row.text = " %s %s%d" % [t.label, sign_str, delta]
row.mouse_filter = Control.MOUSE_FILTER_IGNORE
_thoughts_vbox.add_child(row)
# Statuses.
_clear_children(_statuses_vbox)
for s in _pawn.statuses:
var row := Label.new()
row.text = " %s %s" % [s.label, Strings.t(&"ui.detail.sev").format({"s": s.severity, "m": s.max_severity})]
row.mouse_filter = Control.MOUSE_FILTER_IGNORE
_statuses_vbox.add_child(row)
# Skills.
_clear_children(_skills_vbox)
var skill_key_map: Array = [
[&"manual_labor", &"ui.detail.skill.manual_labor"],
[&"crafting", &"ui.detail.skill.crafting"],
[&"cooking", &"ui.detail.skill.cooking"],
[&"medicine", &"ui.detail.skill.medicine"],
[&"combat", &"ui.detail.skill.combat"],
]
for pair in skill_key_map:
var skill_id: StringName = pair[0]
var skill_lbl: StringName = pair[1]
if not _pawn.skills.has(skill_id):
continue
var row := HBoxContainer.new()
row.add_theme_constant_override("separation", 8)
row.mouse_filter = Control.MOUSE_FILTER_IGNORE
_skills_vbox.add_child(row)
var name_lbl := Label.new()
name_lbl.text = Strings.t(skill_lbl)
name_lbl.custom_minimum_size = Vector2(72, 0)
name_lbl.mouse_filter = Control.MOUSE_FILTER_IGNORE
row.add_child(name_lbl)
var val_lbl := Label.new()
val_lbl.text = str(_pawn.skills[skill_id])
val_lbl.mouse_filter = Control.MOUSE_FILTER_IGNORE
row.add_child(val_lbl)
# Work priorities — comma-separated single line (Agent C adds interactive matrix).
var prio_parts: Array[String] = []
for cat in _pawn.work_priorities:
prio_parts.append("%s: %d" % [String(cat), _pawn.work_priorities[cat]])
_priorities_label.text = ", ".join(prio_parts)
## Color a progress bar by value thresholds: red below low, yellow below high, green above.
func _color_threshold_bar(bar: ProgressBar, value: float, low: float, high: float) -> void:
if value < low:
bar.modulate = Color(1.0, 0.25, 0.25)
elif value < high:
bar.modulate = Color(1.0, 0.85, 0.25)
else:
bar.modulate = Color(0.3, 1.0, 0.3)
func _clear_children(node: Node) -> void:
for child in node.get_children():
child.queue_free()
# ── visibility ────────────────────────────────────────────────────────────────
func _set_visible(v: bool) -> void:
if _panel != null:
_panel.visible = v

View file

@ -0,0 +1 @@
uid://ddivpn3vycyyo

247
scenes/ui/settings_menu.gd Normal file
View file

@ -0,0 +1,247 @@
class_name SettingsMenu extends CanvasLayer
## Phase 17 — Centered modal settings panel.
##
## Layer 26: above LoadMenu (25) — shows over everything.
## Sections: Speeds (keyboard shortcut display), Auto-pause toggles,
## Audio sliders (stub), Accessibility (stub).
##
## Save → GameState.apply_settings(); Cancel → discard edits.
## Opened by TopBar's Settings button (injected by main.gd).
# ── node refs ─────────────────────────────────────────────────────────────────
var _dim: ColorRect = null
var _panel: PanelContainer = null
# Auto-pause checkboxes.
var _cb_threat: CheckBox = null
var _cb_wanderer: CheckBox = null
var _cb_pawn_down: CheckBox = null
var _cb_modal: CheckBox = null
# Audio sliders.
var _sl_master: HSlider = null
var _sl_music: HSlider = null
var _sl_sfx: HSlider = null
var _sl_ambient: HSlider = null
# Accessibility checkboxes.
var _cb_large_text: CheckBox = null
var _cb_reduce_motion: CheckBox = null
func _ready() -> void:
layer = 26
_build_ui()
_set_visible(false)
Audit.log("settings_menu", "SettingsMenu ready (layer %d)" % layer)
func _exit_tree() -> void:
pass
# ── public API ────────────────────────────────────────────────────────────────
func open() -> void:
_load_from_game_state()
_set_visible(true)
Audit.log("settings_menu", "opened")
# ── UI construction ───────────────────────────────────────────────────────────
func _build_ui() -> void:
# Full-screen dim — stops clicks reaching the world behind.
_dim = ColorRect.new()
_dim.name = "Dim"
_dim.set_anchors_preset(Control.PRESET_FULL_RECT)
_dim.color = Color(0.0, 0.0, 0.0, 0.55)
_dim.mouse_filter = Control.MOUSE_FILTER_STOP
add_child(_dim)
# Centre panel.
_panel = PanelContainer.new()
_panel.name = "Dialog"
_panel.set_anchors_preset(Control.PRESET_CENTER)
_panel.custom_minimum_size = Vector2(480, 580)
_panel.offset_left = -240
_panel.offset_right = 240
_panel.offset_top = -290
_panel.offset_bottom = 290
add_child(_panel)
var scroll := ScrollContainer.new()
scroll.set_anchors_preset(Control.PRESET_FULL_RECT)
scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
_panel.add_child(scroll)
var vbox := VBoxContainer.new()
vbox.add_theme_constant_override("separation", 10)
scroll.add_child(vbox)
# Title.
var title := Label.new()
title.name = "Title"
title.text = Strings.t(&"ui.settings.title")
title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
vbox.add_child(title)
_add_separator(vbox)
# ── Speeds section ────────────────────────────────────────────────────────
var speeds_hdr := Label.new()
speeds_hdr.text = Strings.t(&"ui.settings.speeds")
vbox.add_child(speeds_hdr)
var shortcuts_lbl := Label.new()
shortcuts_lbl.text = Strings.t(&"ui.settings.shortcuts")
shortcuts_lbl.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
vbox.add_child(shortcuts_lbl)
_add_separator(vbox)
# ── Auto-pause section ────────────────────────────────────────────────────
var ap_hdr := Label.new()
ap_hdr.text = Strings.t(&"ui.settings.auto_pause")
vbox.add_child(ap_hdr)
_cb_threat = _make_checkbox(Strings.t(&"ui.settings.pause_threat"), vbox)
_cb_wanderer = _make_checkbox(Strings.t(&"ui.settings.pause_wanderer"), vbox)
_cb_pawn_down = _make_checkbox(Strings.t(&"ui.settings.pause_pawn_down"), vbox)
_cb_modal = _make_checkbox(Strings.t(&"ui.settings.pause_modal"), vbox)
_add_separator(vbox)
# ── Audio section (stub — values saved; bus wiring Phase 18) ─────────────
var audio_hdr := Label.new()
audio_hdr.text = Strings.t(&"ui.settings.audio")
vbox.add_child(audio_hdr)
_sl_master = _make_slider(Strings.t(&"ui.settings.master"), vbox)
_sl_music = _make_slider(Strings.t(&"ui.settings.music"), vbox)
_sl_sfx = _make_slider(Strings.t(&"ui.settings.sfx"), vbox)
_sl_ambient = _make_slider(Strings.t(&"ui.settings.ambient"), vbox)
_add_separator(vbox)
# ── Accessibility section (stub — values saved; UI wiring later) ──────────
var access_hdr := Label.new()
access_hdr.text = Strings.t(&"ui.settings.accessibility")
vbox.add_child(access_hdr)
_cb_large_text = _make_checkbox(Strings.t(&"ui.settings.larger_text"), vbox)
_cb_reduce_motion = _make_checkbox(Strings.t(&"ui.settings.reduce_motion"), vbox)
_add_separator(vbox)
# ── Save / Cancel row ─────────────────────────────────────────────────────
var btn_row := HBoxContainer.new()
btn_row.alignment = BoxContainer.ALIGNMENT_CENTER
btn_row.add_theme_constant_override("separation", 16)
vbox.add_child(btn_row)
var save_btn := Button.new()
save_btn.name = "SaveBtn"
save_btn.text = Strings.t(&"ui.settings.save")
save_btn.custom_minimum_size = Vector2(120, 48)
save_btn.focus_mode = Control.FOCUS_NONE
save_btn.pressed.connect(_on_save_pressed)
btn_row.add_child(save_btn)
var cancel_btn := Button.new()
cancel_btn.name = "CancelBtn"
cancel_btn.text = Strings.t(&"ui.settings.cancel")
cancel_btn.custom_minimum_size = Vector2(120, 48)
cancel_btn.focus_mode = Control.FOCUS_NONE
cancel_btn.pressed.connect(_on_cancel_pressed)
btn_row.add_child(cancel_btn)
func _make_checkbox(label_text: String, parent: VBoxContainer) -> CheckBox:
var cb := CheckBox.new()
cb.text = label_text
cb.custom_minimum_size = Vector2(0, 48)
cb.focus_mode = Control.FOCUS_NONE
parent.add_child(cb)
return cb
func _make_slider(label_text: String, parent: VBoxContainer) -> HSlider:
var row := HBoxContainer.new()
row.add_theme_constant_override("separation", 8)
parent.add_child(row)
var lbl := Label.new()
lbl.text = label_text
lbl.custom_minimum_size = Vector2(72, 0)
row.add_child(lbl)
var sl := HSlider.new()
sl.min_value = 0.0
sl.max_value = 1.0
sl.step = 0.05
sl.value = 1.0
sl.size_flags_horizontal = Control.SIZE_EXPAND_FILL
sl.custom_minimum_size = Vector2(0, 48)
sl.focus_mode = Control.FOCUS_NONE
row.add_child(sl)
return sl
func _add_separator(parent: VBoxContainer) -> void:
parent.add_child(HSeparator.new())
# ── state I/O ─────────────────────────────────────────────────────────────────
func _load_from_game_state() -> void:
var s: Dictionary = GameState.settings
_cb_threat.button_pressed = bool(s.get("pause_on_threat", true))
_cb_wanderer.button_pressed = bool(s.get("pause_on_wanderer", true))
_cb_pawn_down.button_pressed = bool(s.get("pause_on_pawn_down", true))
_cb_modal.button_pressed = bool(s.get("pause_on_modal", true))
_sl_master.value = float(s.get("audio_master", 1.0))
_sl_music.value = float(s.get("audio_music", 1.0))
_sl_sfx.value = float(s.get("audio_sfx", 1.0))
_sl_ambient.value = float(s.get("audio_ambient", 1.0))
_cb_large_text.button_pressed = bool(s.get("accessibility_large_text", false))
_cb_reduce_motion.button_pressed = bool(s.get("accessibility_reduce_motion", false))
func _collect_to_dict() -> Dictionary:
return {
"pause_on_threat": _cb_threat.button_pressed,
"pause_on_wanderer": _cb_wanderer.button_pressed,
"pause_on_pawn_down": _cb_pawn_down.button_pressed,
"pause_on_modal": _cb_modal.button_pressed,
"audio_master": _sl_master.value,
"audio_music": _sl_music.value,
"audio_sfx": _sl_sfx.value,
"audio_ambient": _sl_ambient.value,
"accessibility_large_text": _cb_large_text.button_pressed,
"accessibility_reduce_motion": _cb_reduce_motion.button_pressed,
}
# ── interaction ───────────────────────────────────────────────────────────────
func _on_save_pressed() -> void:
GameState.apply_settings(_collect_to_dict())
Audit.log("settings_menu", "settings saved")
_set_visible(false)
func _on_cancel_pressed() -> void:
Audit.log("settings_menu", "settings cancelled")
_set_visible(false)
# ── visibility ────────────────────────────────────────────────────────────────
func _set_visible(v: bool) -> void:
if _dim != null:
_dim.visible = v
if _panel != null:
_panel.visible = v

View file

@ -0,0 +1 @@
uid://brbjrwd85ponw

View file

@ -32,6 +32,16 @@ var _last_season_text: String = ""
## Injected by main.gd after mount so we don't walk the tree with get_node.
var load_menu: CanvasLayer = null
## Phase 17 — injected by main.gd; used by the runtime-added Settings button.
var settings_menu: CanvasLayer = null
## Phase 17 (Agent B) — injected by main.gd; used by the runtime-added Build button.
var build_drawer: CanvasLayer = null
## Phase 17 (Agent C) — injected by main.gd; used by the runtime-added Work / Log buttons.
var work_priority_matrix: CanvasLayer = null
var alerts_log_panel: CanvasLayer = null
## Kept to drive the unread badge text.
var _log_btn: Button = null
func _ready() -> void:
pause_btn.text = Strings.t(&"speed.pause")
@ -131,3 +141,98 @@ func _on_save_started(_slot: StringName) -> void:
func _on_save_finished(_slot: StringName, _ok: bool) -> void:
save_btn.disabled = false
save_btn.text = Strings.t(&"ui.save")
## Phase 17 (Agent B) — called by main.gd after build_drawer is injected.
## Appends a Build button to the ButtonRow at runtime so no .tscn edit is needed.
func _add_build_btn() -> void:
var button_row: HBoxContainer = get_node_or_null("Anchor/ButtonRow")
if button_row == null:
Audit.log("top_bar", "_add_build_btn: ButtonRow not found — skipping")
return
var build_btn := Button.new()
build_btn.name = "BuildBtn"
build_btn.text = Strings.t(&"ui.build")
build_btn.custom_minimum_size = Vector2(60, 48)
build_btn.focus_mode = Control.FOCUS_NONE
build_btn.pressed.connect(_on_build_pressed)
button_row.add_child(build_btn)
Audit.log("top_bar", "Build button added to ButtonRow")
func _on_build_pressed() -> void:
if build_drawer != null and build_drawer.has_method("toggle"):
build_drawer.toggle()
else:
Audit.log("top_bar", "BuildDrawer not mounted — skipping toggle()")
## Phase 17 — called by main.gd after settings_menu is injected.
## Appends a Settings button to the ButtonRow at runtime so no .tscn edit is needed.
func _add_settings_btn() -> void:
var button_row: HBoxContainer = get_node_or_null("Anchor/ButtonRow")
if button_row == null:
Audit.log("top_bar", "_add_settings_btn: ButtonRow not found — skipping")
return
var settings_btn := Button.new()
settings_btn.name = "SettingsBtn"
settings_btn.text = Strings.t(&"ui.settings.btn")
settings_btn.custom_minimum_size = Vector2(80, 48)
settings_btn.focus_mode = Control.FOCUS_NONE
settings_btn.pressed.connect(_on_settings_pressed)
button_row.add_child(settings_btn)
Audit.log("top_bar", "Settings button added to ButtonRow")
func _on_settings_pressed() -> void:
if settings_menu != null and settings_menu.has_method("open"):
settings_menu.open()
else:
Audit.log("top_bar", "SettingsMenu not mounted — skipping open()")
## Phase 17 (Agent C) — called by main.gd after work_priority_matrix and
## alerts_log_panel are injected. Appends "Work" and "Log" buttons to ButtonRow.
func _add_work_log_btns() -> void:
var button_row: HBoxContainer = get_node_or_null("Anchor/ButtonRow")
if button_row == null:
Audit.log("top_bar", "_add_work_log_btns: ButtonRow not found — skipping")
return
var work_btn := Button.new()
work_btn.name = "WorkBtn"
work_btn.text = "Work"
work_btn.custom_minimum_size = Vector2(60, 48)
work_btn.focus_mode = Control.FOCUS_NONE
work_btn.pressed.connect(_on_work_pressed)
button_row.add_child(work_btn)
_log_btn = Button.new()
_log_btn.name = "LogBtn"
_log_btn.text = "Log"
_log_btn.custom_minimum_size = Vector2(60, 48)
_log_btn.focus_mode = Control.FOCUS_NONE
_log_btn.pressed.connect(_on_log_pressed)
button_row.add_child(_log_btn)
# Give the AlertsLog a reference to the Log button so it can update the badge.
if alerts_log_panel != null and alerts_log_panel.get("log_button") != null:
alerts_log_panel.log_button = _log_btn
elif alerts_log_panel != null:
alerts_log_panel.set("log_button", _log_btn)
Audit.log("top_bar", "Work + Log buttons added to ButtonRow")
func _on_work_pressed() -> void:
if work_priority_matrix != null and work_priority_matrix.has_method("open"):
work_priority_matrix.open()
else:
Audit.log("top_bar", "WorkPriorityMatrix not mounted — skipping open()")
func _on_log_pressed() -> void:
if alerts_log_panel != null and alerts_log_panel.has_method("open"):
alerts_log_panel.open()
else:
Audit.log("top_bar", "AlertsLog not mounted — skipping open()")

View file

@ -0,0 +1,230 @@
class_name WorkPriorityMatrix extends CanvasLayer
## Phase 17 — Per-pawn work-priority matrix bottom-sheet.
##
## Opened via TopBar "Work" button (injected by main.gd).
## Displays one row per pawn × one column per player-configurable work category.
## Tapping a cell cycles the priority: 1 (Critical) → 2 → 3 → 4 (Low) → 0 (OFF) → 1.
##
## Priority semantics (mirrors Pawn.work_priorities and Decision layer 4):
## 0 = OFF (gray) — provider never picks this pawn for this category.
## 1 = Critical (red)
## 2 = High (orange)
## 3 = Normal (yellow) — default
## 4 = Low (blue)
##
## Category order matches the locked list in pawn.gd / Decision layer 4.
## &"doctor" is included — players can opt a pawn out of doctor duty even
## though the needs-driven healing path bypasses the filter at Layer 3.
##
## Save / load: NOT session-persistent for MVP — the matrix re-reads
## pawn.work_priorities live from the Pawn nodes every open, so any save that
## round-trips pawn.work_priorities (via pawn.to_dict) will reflect correctly.
const CATEGORIES: Array[StringName] = [
&"construction", &"chop", &"plant", &"mine", &"crafting", &"haul", &"clean", &"doctor"
]
const CATEGORY_LABELS: Dictionary = {
&"construction": "Build",
&"chop": "Chop",
&"plant": "Plant",
&"mine": "Mine",
&"crafting": "Craft",
&"haul": "Haul",
&"clean": "Clean",
&"doctor": "Doctor",
}
## Color per priority level for the cell buttons.
const PRIORITY_COLORS: Dictionary = {
0: Color(0.45, 0.45, 0.45, 1.0), # OFF — gray
1: Color(0.85, 0.18, 0.18, 1.0), # Critical — red
2: Color(0.90, 0.55, 0.10, 1.0), # High — orange
3: Color(0.85, 0.80, 0.10, 1.0), # Normal — yellow
4: Color(0.20, 0.40, 0.85, 1.0), # Low — blue
}
const PRIORITY_DISPLAY: Dictionary = {
0: "X",
1: "1",
2: "2",
3: "3",
4: "4",
}
## Panel height in pixels.
const PANEL_HEIGHT: float = 600.0
## Row height for each pawn row.
const ROW_H: float = 48.0
## Column width for category cells.
const COL_W: float = 64.0
## Width of the pawn-name column.
const NAME_COL_W: float = 100.0
var _root: Control = null
var _scroll: ScrollContainer = null
var _grid: GridContainer = null
## Flat list of [pawn, category, button] triples so we can refresh on open.
var _cells: Array = []
func _ready() -> void:
layer = 17
_build_ui()
_root.visible = false
Audit.log("work_priority_ui", "WorkPriorityMatrix ready")
# ── public API ────────────────────────────────────────────────────────────────
## Open the matrix panel and rebuild the grid from current pawn state.
func open() -> void:
_rebuild_grid()
_root.visible = true
Audit.log("work_priority_ui", "opened (pawns=%d)" % World.pawns.size())
## Close the panel.
func close() -> void:
_root.visible = false
Audit.log("work_priority_ui", "closed")
# ── UI construction ───────────────────────────────────────────────────────────
func _build_ui() -> void:
# Full-screen semi-transparent backdrop.
var backdrop := ColorRect.new()
backdrop.name = "Backdrop"
backdrop.set_anchors_preset(Control.PRESET_FULL_RECT)
backdrop.color = Color(0.0, 0.0, 0.0, 0.45)
backdrop.mouse_filter = Control.MOUSE_FILTER_STOP
backdrop.gui_input.connect(_on_backdrop_input)
add_child(backdrop)
# Bottom-sheet panel anchored to the bottom of the screen.
_root = Control.new()
_root.name = "MatrixPanel"
_root.set_anchors_preset(Control.PRESET_BOTTOM_WIDE)
_root.custom_minimum_size = Vector2(0.0, PANEL_HEIGHT)
_root.offset_top = -PANEL_HEIGHT
_root.offset_bottom = 0.0
_root.mouse_filter = Control.MOUSE_FILTER_STOP
backdrop.add_child(_root)
var bg := PanelContainer.new()
bg.name = "BG"
bg.set_anchors_preset(Control.PRESET_FULL_RECT)
_root.add_child(bg)
var vbox := VBoxContainer.new()
vbox.add_theme_constant_override("separation", 4)
bg.add_child(vbox)
# Header row.
var header := HBoxContainer.new()
header.add_theme_constant_override("separation", 8)
vbox.add_child(header)
var title := Label.new()
title.text = "Work Priorities"
title.size_flags_horizontal = Control.SIZE_EXPAND_FILL
header.add_child(title)
var close_btn := Button.new()
close_btn.text = "Close"
close_btn.focus_mode = Control.FOCUS_NONE
close_btn.custom_minimum_size = Vector2(72.0, 36.0)
close_btn.pressed.connect(close)
header.add_child(close_btn)
# Scroll area for the grid (handles many pawns).
_scroll = ScrollContainer.new()
_scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL
vbox.add_child(_scroll)
# GridContainer: 1 + CATEGORIES.size() columns.
_grid = GridContainer.new()
_grid.columns = 1 + CATEGORIES.size()
_grid.add_theme_constant_override("h_separation", 4)
_grid.add_theme_constant_override("v_separation", 4)
_scroll.add_child(_grid)
# ── grid rebuild ──────────────────────────────────────────────────────────────
func _rebuild_grid() -> void:
# Clear existing children and cell tracking.
for child in _grid.get_children():
child.queue_free()
_cells.clear()
# Header row: "Pawn" + one label per category.
_add_header_cell("Pawn")
for cat in CATEGORIES:
_add_header_cell(CATEGORY_LABELS.get(cat, String(cat)))
# One data row per pawn in World.pawns.
for pawn in World.pawns:
# Pawn name cell.
var name_lbl := Label.new()
name_lbl.text = pawn.pawn_name
name_lbl.custom_minimum_size = Vector2(NAME_COL_W, ROW_H)
name_lbl.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
name_lbl.clip_text = true
_grid.add_child(name_lbl)
# One button per category.
for cat in CATEGORIES:
var lvl: int = int(pawn.work_priorities.get(cat, 3))
var btn := Button.new()
btn.focus_mode = Control.FOCUS_NONE
btn.custom_minimum_size = Vector2(COL_W, ROW_H)
_apply_cell_style(btn, lvl)
# Capture pawn + category in the closure.
var p = pawn
var c: StringName = cat
btn.pressed.connect(func() -> void: _on_cell_pressed(p, c, btn))
_grid.add_child(btn)
_cells.append([pawn, cat, btn])
func _add_header_cell(text: String) -> void:
var lbl := Label.new()
lbl.text = text
lbl.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
lbl.custom_minimum_size = Vector2(COL_W, 32.0)
lbl.add_theme_font_size_override("font_size", 11)
_grid.add_child(lbl)
func _apply_cell_style(btn: Button, lvl: int) -> void:
btn.text = PRIORITY_DISPLAY.get(lvl, "?")
btn.modulate = PRIORITY_COLORS.get(lvl, Color.WHITE)
# ── cell interaction ──────────────────────────────────────────────────────────
func _on_cell_pressed(pawn, category: StringName, btn: Button) -> void:
# Cycle: 1 → 2 → 3 → 4 → 0 → 1
var current: int = int(pawn.work_priorities.get(category, 3))
var next: int
match current:
0: next = 1
1: next = 2
2: next = 3
3: next = 4
4: next = 0
_: next = 3
pawn.work_priorities[category] = next
_apply_cell_style(btn, next)
EventBus.pawn_priority_changed.emit(pawn, category, next)
Audit.log("work_priority_ui", "%s: %s%d" % [pawn.pawn_name, String(category), next])
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:
close()
elif event is InputEventScreenTouch and event.pressed:
close()

View file

@ -0,0 +1 @@
uid://c02srtyuqtoq7

View file

@ -24,19 +24,55 @@ const TOOL_NO_ROOF: StringName = &"no_roof"
const TOOL_GRAVEYARD: StringName = &"graveyard"
# Phase 14 — dig grave: queues a GraveSlot build job at the painted tile.
const TOOL_DIG_GRAVE: StringName = &"dig_grave"
# Phase 17 — Designate tab tools (harvest / gather orders).
const TOOL_CHOP: StringName = &"chop"
const TOOL_MINE: StringName = &"mine"
# Phase 17 — Build tab single-entity tools.
const TOOL_BUILD_CRATE: StringName = &"build_crate"
const TOOL_BUILD_BED: StringName = &"build_bed"
const TOOL_BUILD_TORCH: StringName = &"build_torch"
# Phase 17 — Build tab workbench variants (one tool per bench kind so the
# build-drawer can display each as a distinct button with a distinct label).
const TOOL_BUILD_WORKBENCH_CARPENTER: StringName = &"build_workbench_carpenter"
const TOOL_BUILD_WORKBENCH_SMELTER: StringName = &"build_workbench_smelter"
const TOOL_BUILD_WORKBENCH_MILLSTONE: StringName = &"build_workbench_millstone"
const TOOL_BUILD_WORKBENCH_HEARTH: StringName = &"build_workbench_hearth"
const TOOL_BUILD_WORKBENCH_CREMATION_PYRE: StringName = &"build_workbench_cremation_pyre"
# Phase 17 — Stockpile tab.
const TOOL_PAINT_STOCKPILE: StringName = &"paint_stockpile"
# ── tool → material override ─────────────────────────────────────────────────
# For build_wall and build_floor the tool is shared but the material differs.
# The build-drawer sets _tool_material before activating the tool so the spawn
# bridge in world.gd can read it. Default is "stone" for walls, "wood" for
# floors — matching the Phase 5 demo seeds.
var tool_material: StringName = &"" # set by build_drawer; read by world.gd dispatch
# Atlas coords on the shared placeholder tileset (source 0).
# build_wall → stone-grey (2, 0); build_floor → dirt-brown (1, 0).
# build_door → dark stone (3, 0) so the ghost reads visually distinct from walls.
# no_roof → grass (0, 0) with the designation layer modulate tinting it visibly.
# graveyard / dig_grave → dirt-brown (1, 0); modulate tints these dark brown.
# chop / mine / build_crate / build_bed / build_torch → reuse existing atlas slots.
# workbench variants and paint_stockpile → dirt-brown (1, 0) ghost.
const _ATLAS_BY_TOOL: Dictionary = {
&"build_wall": Vector2i(2, 0),
&"build_floor": Vector2i(1, 0),
&"build_door": Vector2i(3, 0),
&"no_roof": Vector2i(0, 0),
&"graveyard": Vector2i(1, 0),
&"dig_grave": Vector2i(1, 0),
&"build_wall": Vector2i(2, 0),
&"build_floor": Vector2i(1, 0),
&"build_door": Vector2i(3, 0),
&"no_roof": Vector2i(0, 0),
&"graveyard": Vector2i(1, 0),
&"dig_grave": Vector2i(1, 0),
&"chop": Vector2i(0, 0),
&"mine": Vector2i(2, 0),
&"build_crate": Vector2i(1, 0),
&"build_bed": Vector2i(1, 0),
&"build_torch": Vector2i(1, 0),
&"build_workbench_carpenter": Vector2i(1, 0),
&"build_workbench_smelter": Vector2i(2, 0),
&"build_workbench_millstone": Vector2i(1, 0),
&"build_workbench_hearth": Vector2i(1, 0),
&"build_workbench_cremation_pyre":Vector2i(3, 0),
&"paint_stockpile": Vector2i(0, 0),
}
# Placeholder source ID — mirrors World.PLACEHOLDER_SOURCE_ID.
@ -75,8 +111,16 @@ func bind(paint_layer: TileMapLayer, selection: Selection = null) -> void:
## Activate a paint tool. Pass TOOL_NONE to deactivate.
func set_active_tool(tool: StringName) -> void:
assert(
tool in [TOOL_NONE, TOOL_BUILD_WALL, TOOL_BUILD_FLOOR, TOOL_BUILD_DOOR,
TOOL_NO_ROOF, TOOL_GRAVEYARD, TOOL_DIG_GRAVE],
tool in [
TOOL_NONE, TOOL_BUILD_WALL, TOOL_BUILD_FLOOR, TOOL_BUILD_DOOR,
TOOL_NO_ROOF, TOOL_GRAVEYARD, TOOL_DIG_GRAVE,
TOOL_CHOP, TOOL_MINE,
TOOL_BUILD_CRATE, TOOL_BUILD_BED, TOOL_BUILD_TORCH,
TOOL_BUILD_WORKBENCH_CARPENTER, TOOL_BUILD_WORKBENCH_SMELTER,
TOOL_BUILD_WORKBENCH_MILLSTONE, TOOL_BUILD_WORKBENCH_HEARTH,
TOOL_BUILD_WORKBENCH_CREMATION_PYRE,
TOOL_PAINT_STOCKPILE,
],
"Designation.set_active_tool: unknown tool '%s'" % tool
)
_tool = tool

View file

@ -97,6 +97,8 @@ func _select(pawn: Pawn) -> void:
return
if _selected_pawn != null:
_selected_pawn.set_selected(false)
EventBus.pawn_deselected.emit()
_selected_pawn = pawn
pawn.set_selected(true)
EventBus.pawn_selected.emit(pawn)
Audit.log("selection", "selected %s at %s" % [pawn.pawn_name, pawn.tile])

View file

@ -550,22 +550,25 @@ var _build_sites_by_tile: Dictionary = {}
func _on_designation_added(cell: Vector2i, tool: StringName) -> void:
if _build_sites_by_tile.has(cell):
return # already a build site here
# Phase 17 — read material override from the Designation controller (may be "").
var mat: StringName = designation_ctl.tool_material if designation_ctl != null else &""
var entity = null
match tool:
&"build_wall":
var wall_mat: StringName = mat if mat != &"" else &"stone"
entity = WALL_SCENE.instantiate()
add_child(entity)
entity.setup(cell, &"stone")
entity.setup(cell, wall_mat)
&"build_floor":
var floor_mat: StringName = mat if mat != &"" else &"wood"
entity = FLOOR_SCENE.instantiate()
add_child(entity)
entity.setup(cell, &"wood")
entity.setup(cell, floor_mat)
&"build_door":
entity = DOOR_SCENE.instantiate()
add_child(entity)
entity.setup(cell)
# Phase 14 — graveyard zone: paint a single-cell GraveyardZone.
# The zone is 1×1 and re-uses the same region as the painted cell.
&"graveyard":
var gz := Node2D.new()
gz.set_script(GRAVEYARD_ZONE_SCRIPT)
@ -583,6 +586,52 @@ func _on_designation_added(cell: Vector2i, tool: StringName) -> void:
add_child(gs)
gs.setup(cell)
entity = gs
# Phase 17 — chop / mine: designation ghost only; providers auto-scan
# World.trees / World.rocks and will service the nearest entity.
# _build_sites_by_tile tracks the ghost so cancel works.
&"chop", &"mine":
# No entity to spawn — the ghost tile on the designation layer IS the
# marker. Register a sentinel (null body) so _build_sites_by_tile can
# clear the ghost on cancel without double-spawning.
_build_sites_by_tile[cell] = null
Audit.log("world", "designation ghost '%s' at %s (no entity)" % [tool, cell])
return # skip the entity/site registration below
# Phase 17 — crate.
&"build_crate":
entity = CRATE_SCENE.instantiate()
add_child(entity)
entity.setup(cell)
# Phase 17 — bed.
&"build_bed":
entity = BED_SCENE.instantiate()
add_child(entity)
entity.setup(cell)
# Phase 17 — torch.
&"build_torch":
entity = TORCH_SCENE.instantiate()
add_child(entity)
entity.setup(cell)
# Phase 17 — workbench variants.
&"build_workbench_carpenter":
entity = _spawn_workbench(cell, "Carpenter", Pawn.SKILL_CRAFTING)
&"build_workbench_smelter":
entity = _spawn_workbench(cell, "Smelter", Pawn.SKILL_CRAFTING)
&"build_workbench_millstone":
entity = _spawn_workbench(cell, "Millstone", Pawn.SKILL_CRAFTING)
&"build_workbench_hearth":
entity = _spawn_workbench(cell, "Hearth", Pawn.SKILL_COOKING)
&"build_workbench_cremation_pyre":
entity = _spawn_workbench(cell, "Cremation Pyre", Pawn.SKILL_CRAFTING)
# Phase 17 — general stockpile paint: 1-cell stockpile zone, accepts all.
&"paint_stockpile":
var sz: StockpileZone = STOCKPILE_SCENE.instantiate()
add_child(sz)
sz.region = Rect2i(cell.x, cell.y, 1, 1)
sz.label = "Stockpile"
sz.priority = StorageDestination.Priority.NORMAL
sz.accepted_types = [] as Array[StringName] # wildcard
sz.queue_redraw()
entity = sz
_:
Audit.log("world", "unknown designation tool: %s" % tool)
return
@ -590,11 +639,25 @@ func _on_designation_added(cell: Vector2i, tool: StringName) -> void:
Audit.log("world", "queued %s at %s" % [tool, cell])
## Instantiate a Workbench ghost (in build-queue state) at `tile` with the
## given label and accepted skill. Returns the entity (already add_child'd).
func _spawn_workbench(tile: Vector2i, label: String, skill: StringName):
var wb: Workbench = WORKBENCH_SCENE.instantiate()
add_child(wb)
wb.setup(tile)
wb.label_text = label
wb.accepted_skill = skill
return wb
func _on_designation_cleared(cell: Vector2i) -> void:
if not _build_sites_by_tile.has(cell):
return
var entity = _build_sites_by_tile[cell]
_build_sites_by_tile.erase(cell)
# Phase 17 — chop/mine designations store null as their sentinel; nothing to free.
if entity == null:
return
if not is_instance_valid(entity):
return
# For build-queue entities (Wall, Floor, Door, GraveSlot): only free if not