A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Unity: the capture dialog (GDD Phase 6 PR 10, refs #802) (#1317)
Eyal Golancab2ac417711
diff --git a/changelog.d/unity-capture-dialog-802.md b/changelog.d/unity-capture-dialog-802.mdnew file mode 100644index 000000000..f18a7822c--- /dev/null+++ b/changelog.d/unity-capture-dialog-802.md@@ -0,0 +1,7 @@+- The capture dialog, GDD Phase 6 PR 10 (#802): when a settlement the player has captured awaits a decision, a dialog in+ the decision card's place names it and lists the options the sim's `SettlementControl.CaptureOptions` offers, in the+ sim's order, each with a one-line plain description and the sim's preview of what it changes at once. Nothing is+ pre-selected, and there is no picture, sound or video. A choice queues `ResolveCapture` and takes effect at End turn;+ Hide or Escape leaves the decision waiting. Only Raid and withdraw is offered until Occupy and Deport are built. The+ dialog's wording waits for the owner's sensitivity review, and the Hebrew for a native speaker's read (#564). The+ shipped target list is still empty, so no game shows the dialog yet.diff --git a/unity/Assets/Scripts/UI/CaptureDialogPresenter.cs b/unity/Assets/Scripts/UI/CaptureDialogPresenter.csnew file mode 100644index 000000000..6a7e840b4--- /dev/null+++ b/unity/Assets/Scripts/UI/CaptureDialogPresenter.cs@@ -0,0 +1,239 @@+#nullable enable+using System;+using System.Collections.Generic;+using System.Linq;+using Statecraft.Sim;+using UnityEngine.UIElements;++namespace Statecraft.Game.UI+{+ /// <summary>The capture dialog (GDD Phase 6 PR 10, #802; docs/gdd/settlement-control.md): when a settlement's record+ /// awaits the player's choice (SettlementControl.AwaitingChoice), the first such place in the sim's ordinal order, with+ /// its name in the UI's language and one button per option that SettlementControl.CaptureOptions offers, in the+ /// helper's order: the option's name (the GDD's words, Q-UI-1 (b)), its plain description, and the helper's preview of+ /// what it changes at once (Q-UI-2 (a)). The target row's operation line is not shown (owner, 22 October 2026, #1317).+ /// An option the helper refuses (today Occupy, #798, and Deport, #800, "not built yet") is not shown, so a newly built+ /// one appears by itself. The dialog holds no order, cost or rule of its own (Q-TECH-5): it formats the sim's numbers+ /// as the top bar does, and nothing more.+ /// <para>It sits in the decision card's place and style (Game.uxml "capture-card"), modal like it (OpenClass; ScreenNav.+ /// DisableCovered), and waits while a decision card is open: one window at a time. A choice is an order+ /// (ResolveCapture, through SimBridge.Queue): it takes effect at End Turn, and the dialog goes on to the next capture.+ /// Opening puts the focus on the dialog itself, so no option is lit as if recommended; Tab reaches the options in order,+ /// then Hide. Hide, or Escape, collapses it to "Decision waiting: place" without choosing; an unanswered capture waits,+ /// its units staying (R-CTRL-008). No picture, no sound, no video (impact plan section 4.1 item 6).</para></summary>+ public sealed class CaptureDialogPresenter : IDisposable+ {+ /// <summary>On the "root" element while the dialog shows: Statecraft.uss shows the decision layer's backdrop, and+ /// ScreenNav.DisableCovered takes the panels under it out of reach.</summary>+ public const string OpenClass = "capture-open";+ /// <summary>The class on each option button, beside the decision card's EventCardPresenter.OptionClass look.</summary>+ public const string OptionClass = "capture-option";++ readonly VisualElement card, layer, hudRoot, options; readonly Label title, intro, none, count;+ readonly Button hide, reopen; readonly Button? endTurn;+ readonly SimBridge bridge; readonly UiText text; readonly EventCardPresenter? eventCard;+ readonly IReadOnlyDictionary<string, string>? namesHe;+ readonly Func<Content, GameState, string, IReadOnlyList<CaptureOption>> optionsFor;+ readonly Action onHide, onReopen, onUncovered, onRender;+ readonly EventCallback<PointerDownEvent> onHidePointer;+ readonly EventCallback<NavigationSubmitEvent> onHideSubmit;+ readonly EventCallback<NavigationCancelEvent> onCancel;+ readonly PressSource presses;+ /// <summary>The last Hide came from the pointer (PointerBlur's rule: no focus fill left behind for a mouse click).</summary>+ bool hideByPointer;+ /// <summary>The session the dialog last showed: a new one (New Game, a load) forgets what was collapsed or focused.</summary>+ GameSession? session;+ /// <summary>The place the player hid the dialog on, or null; another place opens it again.</summary>+ string? collapsedFor;+ /// <summary>The place whose dialog last took the focus, so a dialog already open never takes it again.</summary>+ string? focusedFor;++ /// <param name="eventCard">The decision card, which goes first: the dialog shows only while it is not open, and follows+ /// it (EventCardPresenter.Rendered). Null: no card (the dialog then follows SimBridge.Changed itself).</param>+ /// <param name="namesHe">Each settlement's Hebrew name, by id (the map's parse of settlements_1948.yaml, as the info+ /// panel gets it; ContentNames.Settlement).</param>+ /// <param name="helper">Test seam: the options helper; null is SettlementControl.CaptureOptions.</param>+ public CaptureDialogPresenter(VisualElement root, SimBridge bridge, UiText text, EventCardPresenter? eventCard,+ IReadOnlyDictionary<string, string>? namesHe = null,+ Func<Content, GameState, string, IReadOnlyList<CaptureOption>>? helper = null)+ {+ this.bridge = bridge; this.text = text; this.eventCard = eventCard; this.namesHe = namesHe;+ optionsFor = helper ?? SettlementControl.CaptureOptions;+ card = root.Q<VisualElement>("capture-card"); layer = card.parent; hudRoot = root.Q("root") ?? root;+ endTurn = hudRoot.Q<Button>("end-turn");+ title = card.Q<Label>("capture-title");+ intro = card.Q<Label>("capture-intro"); none = card.Q<Label>("capture-none"); count = card.Q<Label>("capture-count");+ options = card.Q<VisualElement>("capture-options");+ hide = card.Q<Button>("capture-hide"); reopen = layer.Q<Button>("capture-reopen");+ hide.text = text["event.hide"];+ none.text = text["capture.none"];+ onHide = Collapse; onReopen = Reopen; onRender = Render;+ onUncovered = () => { focusedFor = null; if (Showing) FocusCard(Shown!, force: true); };+ onHidePointer = _ => hideByPointer = true;+ onHideSubmit = _ => hideByPointer = false;+ onCancel = e => { if (Escape()) e.StopPropagation(); };+ hide.clicked += onHide; reopen.clicked += onReopen;+ card.focusable = true; card.tabIndex = 0; // the dialog takes the focus itself (FocusCard); Statecraft.uss .event-card:focus+ hide.RegisterCallback(onHidePointer, TrickleDown.TrickleDown);+ hide.RegisterCallback(onHideSubmit, TrickleDown.TrickleDown);+ card.RegisterCallback(onCancel); // Escape on the open dialog, or on anything in it, is Hide (GameRoot polls it too)+ ScreenNav.AlsoOnUncovered(layer, onUncovered); // a screen or the start screen over the layer has closed+ presses = new PressSource(options);+ if (eventCard != null) eventCard.Rendered += onRender; else bridge.Changed += onRender;+ Render();+ }++ /// <summary>The place awaiting the choice that the dialog is for (open or hidden), or null when every capture awaiting+ /// the choice has a queued answer, or there is none.</summary>+ public string? Shown { get; private set; }++ /// <summary>True while the dialog is hidden behind "Decision waiting: place" (Hide, Escape).</summary>+ public bool Collapsed => Shown != null && collapsedFor == Shown;++ /// <summary>The options the dialog shows: the helper's, those it does not refuse, in its order.</summary>+ public IReadOnlyList<CaptureOption> Offered { get; private set; } = Array.Empty<CaptureOption>();++ /// <summary>The decision card is open: the dialog waits behind it.</summary>+ bool CardOpen => eventCard?.Shown != null && !eventCard.Collapsed;++ bool Showing => Shown != null && !Collapsed && !CardOpen && layer.enabledInHierarchy;++ public void Render()+ {+ var c = bridge.Content; var s = bridge.State;+ if (bridge.Session != session) { session = bridge.Session; collapsedFor = null; focusedFor = null; }+ // The sim's order (Settlements is ordinal); a place with a queued answer has had its choice.+ var waiting = s.Settlements.Where(kv => kv.Value.State == SettlementControl.AwaitingChoice+ && bridge.QueuedLike(new ResolveCapture(kv.Key, "")) == null).Select(kv => kv.Key).ToList();+ Shown = waiting.FirstOrDefault();+ if (Shown == null) collapsedFor = null;+ var shown = Shown != null && !Collapsed && !CardOpen;+ if (!shown) focusedFor = null; // hidden (behind the card, or by Hide): shown again, it takes the focus again+ ScreenNav.Show(card, shown);+ card.SetEnabled(shown); // a child of an undisplayed element can still take the focus (#400)+ // In Decision waiting's place, so only while the card has no button there (it is neither open nor waiting).+ reopen.style.display = Collapsed && eventCard?.Shown == null ? DisplayStyle.Flex : DisplayStyle.None;+ hudRoot.EnableInClassList(OpenClass, shown);+ ScreenNav.DisableCovered(hudRoot);+ options.Clear();+ if (Shown == null) { Offered = Array.Empty<CaptureOption>(); return; }+ var id = Shown;+ var name = ContentNames.Settlement(text, c, id, namesHe);+ title.text = name;+ intro.text = text.Format("capture.intro", name);+ reopen.text = text.Format("capture.reopen", name);+ Offered = optionsFor(c, s, id).Where(o => o.Refusal == null && o.Preview != null).ToList();+ foreach (var o in Offered)+ {+ var outcome = o.Outcome;+ var b = new Button(() => Choose(id, outcome)) { name = "capture-option-" + outcome, text = text["capture.option." + outcome] };+ b.AddToClassList(EventCardPresenter.OptionClass); b.AddToClassList(OptionClass);+ options.Add(b);+ // Under the option, not in it: the button's label stays the choice itself, and a Label takes no Tab stop.+ var about = new Label(text["capture.about." + outcome]) { name = "capture-about-" + outcome };+ about.AddToClassList("capture-about");+ options.Add(about);+ var preview = new Label(PreviewText(c, s, o.Preview!, text)) { name = "capture-preview-" + outcome };+ preview.AddToClassList("muted"); preview.AddToClassList("capture-preview");+ options.Add(preview);+ }+ none.style.display = Offered.Count == 0 ? DisplayStyle.Flex : DisplayStyle.None;+ count.text = waiting.Count > 1 ? text.Format("event.more", waiting.Count - 1) : "";+ if (shown && focusedFor != id) FocusCard(id, force: false);+ }++ /// <summary>The preview's lines (Q-UI-2 (a)): a heading, then each quantity the option changes at once, in+ /// CapturePreview's order, in the turn report's form (report.line: the caption, then the change as the top bar shows+ /// it): Attention; Money, the net change of the Treasury less the debt, as the bar's "Money (net)"; Food; Arms; Social+ /// cohesion and International support as the difference of the two shown 0-100 values; the score. A change the bar+ /// would show as nothing is left out, as there; with none left, capture.changes_none. Every number is the helper's.</summary>+ public static string PreviewText(Content c, GameState s, CapturePreview p, UiText t)+ {+ var lines = new List<string>();+ void Line(string caption, string change) => lines.Add(t.Format("report.line", t[caption], change));+ if (p.Attention != 0) Line("capture.caption.attention", t.Format("capture.delta_attention", p.Attention));+ var money = Math.Round(p.Money - p.Debt, 1, MidpointRounding.AwayFromZero);+ if (money != 0) Line("hud.caption.treasury", PlayerText.MoneyChange(c, "treasury", money));+ if (p.Food != 0) Line("capture.caption.food", t.Format("capture.delta_count", p.Food));+ if (p.Arms != 0) Line("capture.caption.arms", t.Format("capture.delta_count", p.Arms));+ void Points(string caption, string indicator, double change)+ {+ var before = s.Indicators.TryGetValue(indicator, out var v) ? v : 0;+ if (PlayerText.ShownPoints(before + change) != PlayerText.ShownPoints(before)) Line(caption, PlayerText.PercentChangeShown(before, before + change));+ }+ Points("hud.caption.cohesion", "morale", p.SocialCohesion);+ Points("hud.caption.standing", "intl_standing", p.InternationalSupport);+ if (p.Score != 0) Line("capture.caption.score", t.Format("capture.delta_count", p.Score));+ return lines.Count == 0 ? t["capture.changes_none"] : t["capture.changes"] + "\n" + string.Join("\n", lines);+ }++ /// <summary>Hide: the dialog gives the map back and waits behind "Decision waiting: place", which takes the focus when+ /// Hide came from the keyboard. Nothing is chosen.</summary>+ public void Collapse()+ {+ if (Shown == null) return;+ collapsedFor = Shown;+ Render();+ if (hideByPointer) { hideByPointer = false; return; }+ reopen.Focus();+ // Tried again once styles resolve: the button was hidden a moment ago and may not take it yet.+ reopen.schedule.Execute(() => { if (Collapsed && reopen.focusController?.focusedElement != reopen) reopen.Focus(); });+ }++ /// <summary>Escape: Hide, when the dialog is open and in reach. True when it did.</summary>+ public bool Escape()+ {+ if (!Showing) return false;+ hideByPointer = false;+ Collapse();+ return true;+ }++ /// <summary>"Decision waiting: place": the dialog opens again and takes the focus.</summary>+ public void Reopen()+ {+ collapsedFor = null; focusedFor = null;+ Render();+ }++ /// <summary>A newly shown dialog puts the keyboard focus on itself (as the decision card, #41): the next Tab reaches its+ /// first option, and no option is lit before the player picks. Not while the layer is out of reach: the dialog takes+ /// the focus when the cover closes (onUncovered, <paramref name="force"/>). Tried again once styles resolve, from+ /// nothing or from End turn: the decision card hands the focus there when its last event is answered from the keyboard+ /// (#41 M1), which is the moment this dialog opens.</summary>+ void FocusCard(string id, bool force)+ {+ if (!layer.enabledInHierarchy) return;+ focusedFor = id;+ card.Focus();+ card.schedule.Execute(() =>+ {+ if (Shown != id || !Showing) { if (focusedFor == id && !layer.enabledInHierarchy) focusedFor = null; return; }+ var now = card.focusController?.focusedElement;+ if (card.panel != null && now != card && (force || now == null || now == endTurn)) card.Focus();+ });+ }++ void Choose(string id, string outcome)+ {+ // The bridge raises Refused (the toast shows it) or Changed (the dialog goes on to the next capture, which takes+ // the focus). Answered from the keyboard with no capture left, the focus goes to End turn (#41 M1).+ bridge.Queue(new ResolveCapture(id, outcome));+ if (Shown == null && presses.ByKeyboard) FocusReturn.To(endTurn);+ }++ public void Dispose()+ {+ if (eventCard != null) eventCard.Rendered -= onRender; else bridge.Changed -= onRender;+ hide.clicked -= onHide; reopen.clicked -= onReopen;+ hide.UnregisterCallback(onHidePointer, TrickleDown.TrickleDown); hide.UnregisterCallback(onHideSubmit, TrickleDown.TrickleDown);+ card.UnregisterCallback(onCancel);+ ScreenNav.NotOnUncovered(layer, onUncovered);+ presses.Dispose();+ options.Clear(); card.style.display = DisplayStyle.None;+ reopen.style.display = DisplayStyle.None;+ hudRoot.RemoveFromClassList(OpenClass);+ ScreenNav.DisableCovered(hudRoot);+ }+ }+}diff --git a/unity/Assets/Scripts/UI/CaptureDialogPresenter.cs.meta b/unity/Assets/Scripts/UI/CaptureDialogPresenter.cs.metanew file mode 100644index 000000000..1543f35f3--- /dev/null+++ b/unity/Assets/Scripts/UI/CaptureDialogPresenter.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 702e8e2df03a24e569e29e2fb82069c3\ No newline at end of filediff --git a/unity/Assets/Scripts/UI/ContentNames.cs b/unity/Assets/Scripts/UI/ContentNames.csindex de860886a..f8103556d 100644--- a/unity/Assets/Scripts/UI/ContentNames.cs+++ b/unity/Assets/Scripts/UI/ContentNames.cs@@ -1,5 +1,6 @@#nullable enableusing System;+using System.Collections.Generic;using Statecraft.Sim;namespace Statecraft.Game.UI@@ -18,6 +19,11 @@ namespace Statecraft.Game.UIpublic static string Of(UiText text, Legislature l) => Pick(text, l.Body, l.BodyHe);/// <summary>A city project kind's name: its draft name_he, pending a native speaker's review (#564, #1122).</summary>public static string Of(UiText text, ProjectKind k) => Pick(text, k.Name, k.NameHe);+ /// <summary>A settlement's name (map/settlements_1948.yaml): its name_he from <paramref name="namesHe"/>, by id (the+ /// map's parse, as the info panel gets it; null: none), and the sim's English name (PlayerText.Settlement) where it+ /// has none.</summary>+ public static string Settlement(UiText text, Content c, string id, IReadOnlyDictionary<string, string>? namesHe) =>+ Pick(text, PlayerText.Settlement(c, id), namesHe != null && namesHe.TryGetValue(id, out var he) && !string.IsNullOrWhiteSpace(he) ? he : "");/// <summary>The office's title for <paramref name="holder"/> (null: the office itself, masculine): a woman is given/// the row's feminine title_he_f, which every office with a Hebrew title has (owner on #861: "Move to content"), sodiff --git a/unity/Assets/Scripts/UI/EventCardPresenter.cs b/unity/Assets/Scripts/UI/EventCardPresenter.csindex 084550bdb..0de4bc1a0 100644--- a/unity/Assets/Scripts/UI/EventCardPresenter.cs+++ b/unity/Assets/Scripts/UI/EventCardPresenter.cs@@ -203,7 +203,17 @@ namespace Statecraft.Game.UI/// under the start screen, is collapsed or is hidden in a capture run (GameAudio's cue, #39).</summary>public event System.Action<string>? Opened;+ /// <summary>Raised at the end of every render, whatever it showed: the capture dialog (CaptureDialogPresenter) waits+ /// while this card is open, and follows it when it is hidden, answered or opened again.</summary>+ public event System.Action? Rendered;+public void Render()+ {+ try { RenderCard(); }+ finally { Rendered?.Invoke(); }+ }++ void RenderCard(){var c = bridge.Content; var s = bridge.State;var pending = s.PendingEvents.Select(id => c.Events.First(e => e.Id == id)).ToList();diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex 7b92e91d3..771af5174 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -56,6 +56,9 @@ namespace Statecraft.Game.UIEventCardPresenter? card;/// <summary>Tests: the decision card of the last Begin.</summary>internal EventCardPresenter? Card => card;+ CaptureDialogPresenter? capture;+ /// <summary>Tests: the capture dialog of the last Begin.</summary>+ internal CaptureDialogPresenter? Capture => capture;/// <summary>Tests: the settlement name pills of the last Begin.</summary>internal MapLabelsPresenter? Labels => labels;string? hoveredCity; // the city HoverCity lit (#1063)@@ -295,6 +298,10 @@ namespace Statecraft.Game.UI// Both panels in one hook: the same Escape never closes the screen under the panel too.nav!.TakesEscape = () => feedbackPanel.Escape() || sharePanel.Escape();var names = map.SettlementsFor(inputs.Map.SettlementsYaml).ToDictionary(s => s.Id, s => s.Name); // the map's parse (issue #321)+ // The capture dialog (GDD Phase 6 PR 10, #802): in the decision layer, after the card, which goes first; the+ // places' Hebrew names from the same parse.+ capture = Own(new CaptureDialogPresenter(root, bridge, text, card,+ map.SettlementsFor(inputs.Map.SettlementsYaml).ToDictionary(s => s.Id, s => s.NameHe)));// The 1948 sub-districts, outlined on the map, and each front's 1949 armistice line from its agreement's date// where the line exists (display only: the sim never reads them; docs/visual-v1.md, owner rulings 2026-10-11).// Since the owner's rulings of 2026-10-14 the areas are coloured by side (control_hexes_1948_49.yaml), from 15 May 1948@@ -748,9 +755,10 @@ namespace Statecraft.Game.UI// Game request (StartScreenPresenter.Escape; idempotent too).// With no screen to close, Escape skips the first-turn guide (FirstTurnGuidePresenter.Escape).// With nothing else to close, Escape on the open decision card is Hide (EventCardPresenter.Escape; the card itself- // takes the Cancel event when it has the focus).+ // takes the Cancel event when it has the focus), and so on the open capture dialog (CaptureDialogPresenter.Escape),+ // which shows only while the card does not.// The report panel (#1169) and the share panel (#1170) are over everything: their Escape goes no further.- if (UnityEngine.InputSystem.Keyboard.current?.escapeKey.wasPressedThisFrame == true && feedback?.Escape() != true && share?.Escape() != true) { bool done = outcomes?.SkipAll() == true || outcomes?.ClosedThisFrame == true; if (!done) done = end?.Close() == true || end?.ClosedThisFrame == true; if (!done) done = report?.Close() == true || report?.ClosedThisFrame == true; done |= start?.Escape() == true; done |= nav?.Close() == true; if (!done) done = guide?.Escape() == true; if (!done && document.rootVisualElement.focusController?.focusedElement == null) card?.Escape(); }+ if (UnityEngine.InputSystem.Keyboard.current?.escapeKey.wasPressedThisFrame == true && feedback?.Escape() != true && share?.Escape() != true) { bool done = outcomes?.SkipAll() == true || outcomes?.ClosedThisFrame == true; if (!done) done = end?.Close() == true || end?.ClosedThisFrame == true; if (!done) done = report?.Close() == true || report?.ClosedThisFrame == true; done |= start?.Escape() == true; done |= nav?.Close() == true; if (!done) done = guide?.Escape() == true; if (!done && document.rootVisualElement.focusController?.focusedElement == null && capture?.Escape() != true) card?.Escape(); }// PageUp, PageDown, Home and End, with no modifier, scroll the open screen or the open card's text, with or without// focus (KeyScroll; accessibility audit H3), but not under an End Turn outcome clip, which covers them. The arrows// stay with the camera (NavigationGuard, B6).diff --git a/unity/Assets/Scripts/UI/ScreenNav.cs b/unity/Assets/Scripts/UI/ScreenNav.csindex 435aea2c9..e844690bd 100644--- a/unity/Assets/Scripts/UI/ScreenNav.cs+++ b/unity/Assets/Scripts/UI/ScreenNav.cs@@ -30,7 +30,8 @@ namespace Statecraft.Game.UI/// open screen covers the decision layer (it sits where the card does), and in the two-row HUD also the minimap/// column and the info panel; a wide screen covers the info panel; the open decision card's backdrop/// (EventCardPresenter.OpenClass, with no start screen or screen over it: ModalClass, set here) covers the minimap- /// column and the info panel; an End Turn outcome clip (OutcomePresenter.OpenClass) covers the top bar, the minimap+ /// column and the info panel, and so does the open capture dialog's (CaptureDialogPresenter.OpenClass, in the same+ /// layer); an End Turn outcome clip (OutcomePresenter.OpenClass) covers the top bar, the minimap/// column, the info panel and the decision layer. The turn report (TurnReportPresenter.OpenClass, #1037) covers them/// too, and is itself enabled only while it shows and no start screen or outcome clip covers it; when it comes out it/// takes the focus (OnUncovered on its element). Called wherever one of those classes changes (StartScreenPresenter,@@ -45,7 +46,7 @@ namespace Statecraft.Game.UIbool outcome = r.ClassListContains(OutcomePresenter.OpenClass); // an End Turn outcome clip covers all but itselfbool end = r.ClassListContains(EndScreenPresenter.OpenClass); // the end screen (#812) covers the HUD and the reportbool report = r.ClassListContains(TurnReportPresenter.OpenClass) || end; // the turn report covers the HUD under it- bool modal = r.ClassListContains(EventCardPresenter.OpenClass) && !start && !screen && !outcome;+ bool modal = (r.ClassListContains(EventCardPresenter.OpenClass) || r.ClassListContains(CaptureDialogPresenter.OpenClass)) && !start && !screen && !outcome;r.EnableInClassList(EventCardPresenter.ModalClass, modal);r.Q("top-bar")?.SetEnabled(!(start || outcome || report));r.Q("left-column")?.SetEnabled(!(start || outcome || report)); // the screens' buttons: usable wherever the top bar is@@ -82,6 +83,12 @@ namespace Statecraft.Game.UI/// screen or an outcome clip (DisableCovered enables it again); null stops it.</summary>public static void OnUncovered(VisualElement layer, System.Action? action) => layer.userData = action;+ /// <summary>A second listener on the decision layer, beside the one <see cref="OnUncovered"/> set (the capture dialog+ /// shares the event card's layer): added after it, and taken away again with <see cref="NotOnUncovered"/>.</summary>+ public static void AlsoOnUncovered(VisualElement layer, System.Action action) => layer.userData = (layer.userData as System.Action) + action;++ public static void NotOnUncovered(VisualElement layer, System.Action action) => layer.userData = (layer.userData as System.Action) - action;+/// <summary>Asks to be told, synchronously, whenever <paramref name="screen"/> is opened (a presenter that skips/// rendering while its screen is hidden catches up then).</summary>public static void OnOpened(VisualElement screen, System.Action action) => screen.userData = action;diff --git a/unity/Assets/Tests/EditMode/CaptureDialogTests.cs b/unity/Assets/Tests/EditMode/CaptureDialogTests.csnew file mode 100644index 000000000..7e7655fb5--- /dev/null+++ b/unity/Assets/Tests/EditMode/CaptureDialogTests.cs@@ -0,0 +1,554 @@+#nullable enable+using System.Collections;+using System.Collections.Generic;+using System.IO;+using System.Linq;+using NUnit.Framework;+using Statecraft.Game;+using Statecraft.Game.UI;+using Statecraft.Sim;+using UnityEditor;+using UnityEngine;+using UnityEngine.TestTools;+using UnityEngine.UIElements;++/// <summary>The capture dialog (GDD Phase 6 PR 10, #802; plan 2026-10-15-gdd-phase-6.md, PR 10): when a settlement's record+/// awaits the player's choice, the dialog names the place and lists exactly the options SettlementControl.CaptureOptions+/// offers, in its order, each with the sim's preview; nothing is pre-selected; a choice queues ResolveCapture through+/// SimBridge; Escape hides it without choosing; it plays no sound and shows no video; a decision card goes first. The+/// target rows here are test fixtures on the real content (Lydda and Ramle, which share a hex), with a made-up operation+/// line (the content requires one; the dialog does not show it): the real target list ships empty until its research and+/// review are done.</summary>+public class CaptureDialogTests+{+ const string Operation = "Fixture operation (a test value, not a source)";++ /// <summary>The real content with Lydda and Ramle as targets; <paramref name="price"/> sets attention_cost.resolve_capture+ /// (0 in the content), so the sim's Attention preview has a number to show.</summary>+ static Content Targets(double price = 0)+ {+ var dir = Paths.Content;+ var events = Directory.GetFiles(Path.Combine(dir, "events"), "*.yaml").Select(f => "events/" + Path.GetFileName(f)).ToList();+ string Row(string id) => $" - {{ id: {id}, q: -3, r: 21, operation: \"{Operation}\", sources: [{{ url: \"https://example.org/{id}\", checked: 2026-10-21 }}], status: draft }}\n";+ return ContentLoader.Load(rel =>+ {+ var path = Path.Combine(dir, rel);+ if (!File.Exists(path)) return null;+ var text = File.ReadAllText(path);+ if (rel == "settlement_targets.yaml") return "targets:\n" + Row("lod") + Row("ramla");+ if (rel == "rules.yaml" && price != 0)+ {+ Assert.IsTrue(text.Contains(" resolve_capture: 0 "), "rules.yaml prices resolve_capture at 0");+ text = text.Replace(" resolve_capture: 0 ", " resolve_capture: " + price.ToString(System.Globalization.CultureInfo.InvariantCulture) + " ");+ }+ return text;+ }, events);+ }++ static readonly Content C = Targets();+ static UiText En => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings).text);+ static UiText He => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.StringsHebrew).text, "strings.he.yaml");++ /// <summary>A new game with no event pending and each of <paramref name="places"/> captured and awaiting the choice.</summary>+ static GameSession Awaiting(Content c, params string[] places)+ {+ var g = GameSession.New(c, GoldenRun.Seed, Mode.Historical);+ g.State.PendingEvents.Clear();+ foreach (var id in places) g.State.Settlements[id] = new SettlementControl(Movement.PlayerSide, SettlementControl.AwaitingChoice, g.State.Date);+ return g;+ }++ /// <summary>The settlements' Hebrew names as GameRoot hands them over (the map's parse of settlements_1948.yaml).</summary>+ static IReadOnlyDictionary<string, string> NamesHe() =>+ Statecraft.Game.Map.SettlementPlacer.Parse(File.ReadAllText(Path.Combine(Paths.Content, "map", "settlements_1948.yaml"))).ToDictionary(s => s.Id, s => s.NameHe);++ sealed class Rig : System.IDisposable+ {+ public readonly VisualElement Root; public readonly SimBridge Bridge; public readonly ScreenNav Nav;+ public readonly EventCardPresenter Card; public readonly CaptureDialogPresenter Dialog; public readonly UiText Text;+ readonly GameObject go; readonly PanelSettings ps; readonly RenderTexture rt; readonly List<System.IDisposable> owned = new List<System.IDisposable>();++ public Rig(GameSession g, UiText? text = null, int w = 1920, int h = 1080,+ System.Func<Content, GameState, string, IReadOnlyList<CaptureOption>>? options = null)+ {+ Text = text ?? En;+ rt = new RenderTexture(w, h, 0);+ ps = Object.Instantiate(AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel));+ ps.targetTexture = rt;+ go = new GameObject("CaptureDialogTest");+ go.SetActive(false);+ var doc = go.AddComponent<UIDocument>();+ doc.panelSettings = ps;+ doc.visualTreeAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(UiPaths.GameUxml);+ go.SetActive(true);+ Root = doc.rootVisualElement;+ Root.Q("root").RemoveFromClassList("loading");+ Root.Q("root").EnableInClassList(UiLanguage.HebrewClass, Text["ui.lang"] == UiLanguage.Hebrew); // as GameRoot+ Bridge = new SimBridge(g, Text);+ owned.Add(new HudPresenter(Root, Bridge, Text));+ Nav = new ScreenNav(Root); owned.Add(Nav);+ owned.Add(new InfoPanelPresenter(Root, Bridge, Text, g.Content.SettlementHexes.ToDictionary(x => x.Id, x => x.Id)));+ Card = new EventCardPresenter(Root, Bridge, Text, null); owned.Add(Card); // as GameRoot: the card first+ Dialog = new CaptureDialogPresenter(Root, Bridge, Text, Card, NamesHe(), helper: options); owned.Add(Dialog);+ }++ public void Dispose()+ {+ for (int i = owned.Count - 1; i >= 0; i--) owned[i].Dispose();+ Object.DestroyImmediate(go); Object.DestroyImmediate(ps); rt.Release(); Object.DestroyImmediate(rt);+ }++ public VisualElement Element => Root.Q("capture-card");+ public List<Button> Options => Root.Q("capture-options").Query<Button>().ToList();+ public Button Hide => Root.Q<Button>("capture-hide");+ public Button Waiting => Root.Q<Button>("capture-reopen");+ public Focusable? Focused => Root.panel.focusController.focusedElement;+ public bool Shows(string name) => Root.Q(name).resolvedStyle.display == DisplayStyle.Flex;+ public VisualElement Hud => Root.Q("root");+ }++ static IEnumerator Frames(int n) { for (int i = 0; i < n; i++) yield return null; }++ static void Press(Button b)+ {+ using (var e = NavigationSubmitEvent.GetPooled()) { e.target = b; b.SendEvent(e); }+ }++ static void Cancel(VisualElement on)+ {+ using (var e = NavigationCancelEvent.GetPooled()) { e.target = on; on.SendEvent(e); }+ }++ static void Tab(VisualElement from)+ {+ using (var e = NavigationMoveEvent.GetPooled(NavigationMoveEvent.Direction.Next)) { e.target = from; from.SendEvent(e); }+ }++ /// <summary>A stand-in for the options helper that offers every outcome with a preview, in <paramref name="order"/>, and+ /// refuses <paramref name="refused"/>: the dialog must render whatever the helper returns (Occupy, #798, and Deport, #800,+ /// are refused by the real helper today).</summary>+ static System.Func<Content, GameState, string, IReadOnlyList<CaptureOption>> Helper(string[] order, params string[] refused) =>+ (c, s, id) => order.Select(o => refused.Contains(o) ? new CaptureOption(o, "refused in this test", null)+ : new CaptureOption(o, null, Full)).ToList();++ /// <summary>A preview that changes every quantity (seven lines): the most a preview can show.</summary>+ static readonly CapturePreview Full = new CapturePreview(-1, -2, 0.5, -3, -4, -0.05, -0.1, -5);++ /// <summary>The three options with previews of the size the rules give them (docs/gdd/settlement-control.md): Raid changes+ /// nothing at once, Occupy costs Money, Deport costs Social cohesion and International support. Test values.</summary>+ static IReadOnlyList<CaptureOption> Plausible(Content c, GameState s, string id) => new List<CaptureOption>+ {+ new CaptureOption("raid", null, new CapturePreview(0, 0, 0, 0, 0, 0, 0, 0)),+ new CaptureOption("occupy", null, new CapturePreview(0, -0.4, 0, 0, 0, 0, 0, 0)),+ new CaptureOption("deport", null, new CapturePreview(0, 0, 0, 0, 0, -0.08, -0.12, 0)),+ };++ // ---- The dialog opens for a record awaiting the choice ----++ [UnityTest]+ public IEnumerator TheDialogOpensForACaptureAwaitingTheChoice()+ {+ using (var r = new Rig(Awaiting(C, "lod")))+ {+ yield return Frames(4);+ Assert.AreEqual("lod", r.Dialog.Shown);+ Assert.IsTrue(r.Shows("capture-card"), "the dialog shows");+ Assert.AreEqual("Lydda", r.Root.Q<Label>("capture-title").text, "the place's name (settlements_1948.yaml)");+ Assert.IsFalse(r.Root.Q("capture-card").Query<Label>().ToList().Any(l => l.text.Contains(Operation)),+ "the target row's operation line is not shown (owner, 22 October 2026, #1317)");+ Assert.AreEqual(En.Format("capture.intro", "Lydda"), r.Root.Q<Label>("capture-intro").text);+ Assert.IsTrue(r.Hud.ClassListContains(CaptureDialogPresenter.OpenClass) && r.Hud.ClassListContains(EventCardPresenter.ModalClass),+ "the root says the dialog is open, and it is modal like the decision card");+ Assert.IsTrue(r.Shows("event-scrim"), "the backdrop shows");+ Assert.IsFalse(r.Root.Q("info-panel").enabledSelf, "the panels under the backdrop are out of reach");+ Assert.IsFalse(r.Shows("capture-reopen"), "no waiting button while it is open");+ }+ using (var r = new Rig(Awaiting(C)))+ {+ yield return Frames(3);+ Assert.IsNull(r.Dialog.Shown);+ Assert.IsFalse(r.Shows("capture-card") || r.Shows("capture-reopen"), "no capture, no dialog");+ Assert.IsFalse(r.Hud.ClassListContains(CaptureDialogPresenter.OpenClass));+ Assert.IsTrue(r.Root.Q("info-panel").enabledSelf);+ }+ // A record in another state (a later outcome) is not awaiting the choice.+ var g = Awaiting(C);+ g.State.Settlements["lod"] = new SettlementControl(Movement.PlayerSide, "occupied", g.State.Date);+ using (var r = new Rig(g))+ {+ yield return Frames(3);+ Assert.IsNull(r.Dialog.Shown, "only awaiting_choice opens the dialog");+ Assert.IsFalse(r.Shows("capture-card"));+ }+ }++ /// <summary>The dialog follows the sim's state: a capture the turn makes opens it after End Turn.</summary>+ [UnityTest]+ public IEnumerator ACaptureFromTheTurnOpensTheDialog()+ {+ using var r = new Rig(Awaiting(C));+ yield return Frames(3);+ Assert.IsNull(r.Dialog.Shown);+ r.Bridge.State.Settlements["ramla"] = new SettlementControl(Movement.PlayerSide, SettlementControl.AwaitingChoice, r.Bridge.State.Date);+ r.Bridge.Replace(r.Bridge.Session); // Changed, as after a turn+ yield return Frames(3);+ Assert.AreEqual("ramla", r.Dialog.Shown);+ Assert.IsTrue(r.Shows("capture-card"));+ Assert.AreEqual("Ramle", r.Root.Q<Label>("capture-title").text);+ }++ // ---- The options: exactly the helper's, in its order ----++ /// <summary>Plan PR 10, CaptureDialogTests.TheOrderIsTheSims: the buttons are the options the real helper offers, in its+ /// order (today Raid alone: Occupy and Deport are refused as not built), named in the GDD's words.</summary>+ [UnityTest]+ public IEnumerator TheOrderIsTheSims()+ {+ using var r = new Rig(Awaiting(C, "lod"));+ yield return Frames(4);+ var offered = SettlementControl.CaptureOptions(r.Bridge.Content, r.Bridge.State, "lod").Where(o => o.Refusal == null).Select(o => o.Outcome).ToList();+ Assert.IsNotEmpty(offered, "precondition: the sim offers an option here");+ CollectionAssert.AreEqual(offered, r.Dialog.Offered.Select(o => o.Outcome).ToList(), "the dialog's options are the helper's offered ones");+ CollectionAssert.AreEqual(offered.Select(o => "capture-option-" + o).ToList(), r.Options.Select(b => b.name).ToList(), "one button each, in the helper's order");+ CollectionAssert.AreEqual(offered.Select(o => En["capture.option." + o]).ToList(), r.Options.Select(b => b.text).ToList());+ foreach (var o in offered)+ Assert.AreEqual(En["capture.about." + o], r.Root.Q<Label>("capture-about-" + o).text, $"{o}: its plain description");+ Assert.IsFalse(r.Shows("capture-none"));+ }++ /// <summary>The dialog renders whatever the helper returns: every offered outcome, in the helper's order whatever it is,+ /// and none it refuses. So Occupy and Deport appear by themselves once the sim builds them, and never before.</summary>+ [UnityTest]+ public IEnumerator ItShowsWhateverTheHelperOffersInItsOrder()+ {+ foreach (var (order, refused) in new[]+ {+ (new[] { "raid", "occupy", "deport" }, new string[0]),+ (new[] { "deport", "raid", "occupy" }, new string[0]), // not a UI order: the helper's+ (new[] { "raid", "occupy", "deport" }, new[] { "occupy", "deport" }),+ (new[] { "raid", "occupy", "deport" }, new[] { "raid" }),+ })+ {+ using var r = new Rig(Awaiting(C, "lod"), options: Helper(order, refused));+ yield return Frames(3);+ var want = order.Where(o => !refused.Contains(o)).ToList();+ var where = $"[{string.Join(",", order)}] refusing [{string.Join(",", refused)}]";+ CollectionAssert.AreEqual(want.Select(o => "capture-option-" + o).ToList(), r.Options.Select(b => b.name).ToList(), where);+ foreach (var o in refused) Assert.IsNull(r.Root.Q("capture-option-" + o), $"{where}: a refused option is not shown");+ }+ }++ /// <summary>No option the sim offers can be chosen (a Raid with no free hex): the dialog says so, the capture waits.</summary>+ [UnityTest]+ public IEnumerator WithNothingOfferedTheDialogSaysTheDecisionWaits()+ {+ using var r = new Rig(Awaiting(C, "lod"), options: Helper(new[] { "raid", "occupy", "deport" }, "raid", "occupy", "deport"));+ yield return Frames(3);+ Assert.IsEmpty(r.Options);+ Assert.IsTrue(r.Shows("capture-none"));+ Assert.AreEqual(En["capture.none"], r.Root.Q<Label>("capture-none").text);+ Assert.IsTrue(r.Shows("capture-hide"), "Hide is still there");+ }++ // ---- Nothing is pre-selected ----++ /// <summary>Plan PR 10, CaptureDialogTests.NothingIsPreselected: on opening the focus is on the dialog itself, no button+ /// has it, and every option looks the same (no default style); Tab then reaches the options in order, then Hide.</summary>+ [UnityTest]+ public IEnumerator NothingIsPreselected()+ {+ using var r = new Rig(Awaiting(C, "lod"), options: Plausible);+ yield return Frames(4);+ Assert.AreSame(r.Element, r.Focused, "the dialog itself has the focus, not an option");+ var classes = r.Options.Select(b => string.Join(" ", b.GetClasses().OrderBy(x => x))).Distinct().ToList();+ Assert.AreEqual(1, classes.Count, "every option has the same classes: " + string.Join(" | ", classes));+ Assert.IsTrue(r.Options.All(b => b.enabledSelf), "every option can be chosen");+ // Tab: the options in the helper's order, then Hide.+ VisualElement at = r.Element;+ foreach (var expected in r.Options.Cast<VisualElement>().Append(r.Hide))+ {+ Tab(at);+ yield return Frames(1);+ Assert.AreSame(expected, r.Focused, $"Tab from {at.name} reaches {expected.name}");+ at = expected;+ }+ Assert.IsEmpty(r.Bridge.Queued, "moving the focus chooses nothing");+ }++ // ---- The preview is the sim's ----++ /// <summary>Plan PR 10, CaptureDialogTests.ThePreviewIsTheSims: under each option, the helper's own preview, formatted as+ /// the top bar formats each quantity; with resolve_capture priced at 1 the sim's Attention change shows.</summary>+ [UnityTest]+ public IEnumerator ThePreviewIsTheSims()+ {+ var c = Targets(price: 1);+ using var r = new Rig(Awaiting(c, "lod"));+ yield return Frames(4);+ var helper = SettlementControl.CaptureOptions(r.Bridge.Content, r.Bridge.State, "lod").Where(o => o.Refusal == null).ToList();+ Assert.IsNotEmpty(helper);+ foreach (var o in helper)+ {+ var shown = r.Root.Q<Label>("capture-preview-" + o.Outcome).text;+ Assert.AreEqual(CaptureDialogPresenter.PreviewText(r.Bridge.Content, r.Bridge.State, o.Preview!, En), shown, $"{o.Outcome}: the helper's preview");+ Assert.Less(o.Preview!.Attention, 0, "precondition: the sim charges Attention for the order");+ StringAssert.Contains(En.Format("report.line", En["capture.caption.attention"], En.Format("capture.delta_attention", o.Preview.Attention)), shown,+ $"{o.Outcome}: the sim's own Attention change");+ Assert.AreEqual(-r.Bridge.Price(new ResolveCapture("lod", o.Outcome)), o.Preview.Attention, 1e-9, "the order's price at this turn's prices");+ }+ using var free = new Rig(Awaiting(C, "lod"));+ yield return Frames(3);+ Assert.AreEqual(En["capture.changes_none"], free.Root.Q<Label>("capture-preview-raid").text, "Raid changes nothing at once (R-CTRL-010)");+ }++ /// <summary>Each quantity of the preview as the top bar shows it, in CapturePreview's order, a change that rounds to+ /// nothing left out: Money is the net change (the Treasury less the debt, PlayerText.MoneyChange), the 0-1 indicators are+ /// the difference of the two shown 0-100 values (PlayerText.PercentChangeShown).</summary>+ [Test]+ public void ThePreviewTextFormatsEachQuantityAsTheTopBarDoes()+ {+ var s = GameSession.New(C, GoldenRun.Seed, Mode.Historical).State;+ var morale = s.Indicators["morale"]; var standing = s.Indicators["intl_standing"];+ var p = new CapturePreview(-1, -2, 0.5, -3, -4, -0.05, -0.1, -5);+ var expected = string.Join("\n", new[]+ {+ En["capture.changes"],+ En.Format("report.line", En["capture.caption.attention"], "-1.0"),+ En.Format("report.line", En["hud.caption.treasury"], PlayerText.MoneyChange(C, "treasury", -2.5)),+ En.Format("report.line", En["capture.caption.food"], "-3"),+ En.Format("report.line", En["capture.caption.arms"], "-4"),+ En.Format("report.line", En["hud.caption.cohesion"], PlayerText.PercentChangeShown(morale, morale - 0.05)),+ En.Format("report.line", En["hud.caption.standing"], PlayerText.PercentChangeShown(standing, standing - 0.1)),+ En.Format("report.line", En["capture.caption.score"], "-5"),+ });+ Assert.AreEqual(expected, CaptureDialogPresenter.PreviewText(C, s, p, En));+ StringAssert.Contains("Score: -5", expected);+ Assert.AreEqual(En["capture.changes_none"], CaptureDialogPresenter.PreviewText(C, s, new CapturePreview(0, 0.01, 0, 0, 0, 0.001, 0, 0), En),+ "changes too small to show are left out, as on the top bar");+ var he = CaptureDialogPresenter.PreviewText(C, s, p, He);+ StringAssert.StartsWith(He["capture.changes"], he);+ StringAssert.Contains(He.Format("report.line", He["capture.caption.attention"], "-1.0"), he, "the Hebrew line marks the number left to right");+ }++ // ---- Choosing issues ResolveCapture ----++ /// <summary>A choice is an order: it queues ResolveCapture(place, outcome) through SimBridge, the dialog goes on to the+ /// next capture in the sim's (ordinal) order, and End Turn carries it out.</summary>+ [UnityTest]+ public IEnumerator ChoosingIssuesResolveCapture()+ {+ using var r = new Rig(Awaiting(C, "ramla", "lod"));+ yield return Frames(4);+ Assert.AreEqual("lod", r.Dialog.Shown, "the first in the sim's order");+ Assert.AreEqual(En.Format("event.more", 1), r.Root.Q<Label>("capture-count").text);+ Press(r.Root.Q<Button>("capture-option-raid"));+ yield return Frames(3);+ var queued = r.Bridge.Queued.OfType<ResolveCapture>().ToList();+ Assert.AreEqual(1, queued.Count);+ Assert.AreEqual(("lod", SettlementControl.Raid), (queued[0].Settlement, queued[0].Outcome));+ Assert.AreEqual("ramla", r.Dialog.Shown, "the next capture");+ Press(r.Root.Q<Button>("capture-option-raid"));+ yield return Frames(3);+ CollectionAssert.AreEqual(new[] { "lod", "ramla" }, r.Bridge.Queued.OfType<ResolveCapture>().Select(x => x.Settlement).ToList());+ Assert.IsNull(r.Dialog.Shown, "every capture answered");+ Assert.IsFalse(r.Shows("capture-card"));+ Assert.AreSame(r.Root.Q<Button>("end-turn"), r.Focused, "answered from the keyboard, the focus goes to End turn");+ var result = r.Bridge.EndTurn();+ Assert.IsEmpty(result.Rejected.Where(x => x.Command is ResolveCapture), "the sim takes both");+ Assert.IsFalse(r.Bridge.State.Settlements.ContainsKey("lod") || r.Bridge.State.Settlements.ContainsKey("ramla"), "Raid ended both records");+ }++ // ---- Escape does not choose ----++ /// <summary>Escape on the open dialog is Hide, as on the decision card: nothing is queued, "Decision waiting: place" takes+ /// the focus and brings the dialog back; Escape on a hidden dialog, or under a screen, does nothing.</summary>+ [UnityTest]+ public IEnumerator EscapeHidesAndDoesNotChoose()+ {+ using var r = new Rig(Awaiting(C, "lod"));+ yield return Frames(4);+ Cancel(r.Element);+ yield return Frames(3);+ Assert.IsTrue(r.Dialog.Collapsed, "Escape hides the dialog");+ Assert.IsEmpty(r.Bridge.Queued, "and chooses nothing");+ Assert.IsFalse(r.Shows("capture-card"));+ Assert.IsTrue(r.Shows("capture-reopen"));+ Assert.AreEqual(En.Format("capture.reopen", "Lydda"), r.Waiting.text);+ Assert.AreSame(r.Waiting, r.Focused, "from the keyboard, the waiting button has the focus");+ Assert.IsFalse(r.Hud.ClassListContains(CaptureDialogPresenter.OpenClass) || r.Hud.ClassListContains(EventCardPresenter.ModalClass), "the map is free");+ Assert.IsFalse(r.Dialog.Escape(), "Escape on a hidden dialog does nothing");+ Press(r.Waiting);+ yield return Frames(3);+ Assert.IsFalse(r.Dialog.Collapsed);+ Assert.AreSame(r.Element, r.Focused, "opened again, the dialog has the focus");+ // Escape from an option: still Hide, never the option.+ Cancel(r.Options[0]);+ yield return Frames(2);+ Assert.IsTrue(r.Dialog.Collapsed);+ Assert.IsEmpty(r.Bridge.Queued);+ Press(r.Waiting);+ yield return Frames(2);+ r.Nav.Open("why");+ yield return Frames(2);+ Assert.IsFalse(r.Dialog.Escape(), "under a screen Escape is the screen's");+ Assert.IsFalse(r.Dialog.Collapsed);+ r.Nav.Close();+ yield return Frames(3);+ Assert.AreSame(r.Element, r.Focused, "closing the screen gives the open dialog the focus");+ Assert.IsEmpty(r.Bridge.Queued);+ }++ // ---- The decision card goes first ----++ /// <summary>One window at a time in the decision layer: while a decision card is open the dialog waits, hidden with no+ /// button of its own; hiding or answering the card brings it; reopening the card puts it back behind.</summary>+ [UnityTest]+ public IEnumerator TheDecisionCardGoesFirst()+ {+ var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical); // a new game opens on a decision card+ Assert.IsNotEmpty(g.State.PendingEvents, "precondition: an event is pending");+ g.State.Settlements["lod"] = new SettlementControl(Movement.PlayerSide, SettlementControl.AwaitingChoice, g.State.Date);+ using var r = new Rig(g);+ yield return Frames(4);+ Assert.IsNotNull(r.Card.Shown, "precondition: a decision card is open");+ Assert.AreEqual("lod", r.Dialog.Shown, "the capture is pending");+ Assert.IsFalse(r.Shows("capture-card") || r.Shows("capture-reopen"), "but waits behind the card");+ r.Card.Collapse();+ yield return Frames(3);+ Assert.IsTrue(r.Shows("capture-card"), "the card hidden, the dialog opens");+ Assert.IsTrue(r.Shows("event-reopen") && !r.Shows("capture-reopen"), "the card's Decision waiting stays, alone in its place");+ r.Card.Reopen();+ yield return Frames(3);+ Assert.IsTrue(r.Shows("event-card") && !r.Shows("capture-card"), "the card again, the dialog behind it");+ Press(r.Root.Q("event-options").Q<Button>());+ yield return Frames(3);+ Assert.IsNull(r.Card.Shown, "precondition: the card is answered");+ Assert.IsTrue(r.Shows("capture-card"), "then the dialog");+ Assert.AreSame(r.Element, r.Focused, "answered from the keyboard, the dialog that opens takes the focus (not End turn)");+ }++ // ---- No sound and no video ----++ sealed class Speaker : GameAudio.IOutput+ {+ public readonly List<string> Played = new List<string>();+ public void Play(AudioClip clip, float volume) => Played.Add(clip.name);+ public void Dispose() { }+ }++ /// <summary>Plan PR 10, CaptureDialogTests.NoSoundAndNoVideo (impact plan section 4.1 item 6): opening the dialog and+ /// choosing play no clip and no sound (GameAudio, with every cue's clip present, plays nothing), and the dialog holds no+ /// picture, no video player and no audio of its own.</summary>+ [UnityTest]+ public IEnumerator NoSoundAndNoVideo()+ {+ var made = new List<AudioClip>();+ var speaker = new Speaker();+ using var r = new Rig(Awaiting(C, "lod"));+ var audio = new GameAudio(r.Bridge, r.Card, path => { var a = AudioClip.Create(path, 441, 1, 44100, false); made.Add(a); return a; }, speaker);+ try+ {+ r.Dialog.Reopen(); // opened again with the speaker listening+ yield return Frames(4);+ Assert.IsTrue(r.Shows("capture-card"));+ Press(r.Root.Q<Button>("capture-option-raid"));+ yield return Frames(3);+ Assert.IsNotEmpty(r.Bridge.Queued, "precondition: chosen");+ Assert.IsEmpty(speaker.Played, "no sound on opening or choosing");+ foreach (var e in r.Element.Query<VisualElement>().ToList().Prepend(r.Element).Where(e => e.GetFirstAncestorOfType<Scroller>() == null && !(e is Scroller)))+ Assert.IsNull(e.resolvedStyle.backgroundImage.texture, $"{e.name}: no picture in the dialog");+ var kinds = typeof(CaptureDialogPresenter).GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public)+ .Select(f => f.FieldType).ToList();+ foreach (var banned in new[] { typeof(CardVideo), typeof(GameAudio), typeof(AudioSource), typeof(AudioClip) })+ Assert.IsFalse(kinds.Contains(banned), $"the dialog holds no {banned.Name}");+ }+ finally+ {+ audio.Dispose();+ foreach (var a in made) Object.DestroyImmediate(a);+ }+ }++ // ---- The strings ----++ /// <summary>Every outcome the helper lists, offered or not (Raid, Occupy, Deport), has its name and its description in+ /// English and Hebrew, so a newly built outcome shows in both at once; the Hebrew ones are Hebrew.</summary>+ [Test]+ public void EveryOutcomeHasItsStringsInBothLanguages()+ {+ var g = Awaiting(C, "lod");+ var outcomes = SettlementControl.CaptureOptions(C, g.State, "lod").Select(o => o.Outcome).ToList();+ CollectionAssert.AreEqual(new[] { SettlementControl.Raid, SettlementControl.Occupy, SettlementControl.Deport }, outcomes, "precondition: the helper lists the three");+ var keys = outcomes.SelectMany(o => new[] { "capture.option." + o, "capture.about." + o })+ .Concat(new[] { "capture.intro", "capture.changes", "capture.changes_none", "capture.caption.attention", "capture.caption.food",+ "capture.caption.arms", "capture.caption.score", "capture.delta_attention", "capture.delta_count", "capture.none", "capture.reopen" });+ foreach (var key in keys)+ {+ Assert.IsTrue(En.Has(key), $"strings.en.yaml: {key}");+ Assert.IsTrue(He.Has(key), $"strings.he.yaml: {key}");+ if (!key.StartsWith("capture.delta_")) Assert.IsTrue(UiDirection.HasRightToLeft(He[key]), $"strings.he.yaml: {key} is Hebrew: {He[key]}");+ }+ }++ /// <summary>In Hebrew the dialog names the place by its name_he and shows the Hebrew strings.</summary>+ [UnityTest]+ public IEnumerator InHebrewTheDialogIsHebrew()+ {+ using var r = new Rig(Awaiting(C, "lod"), He);+ using var direction = new UiDirection(r.Root, r.Bridge); // as GameRoot in Hebrew+ yield return Frames(4);+ Assert.AreEqual("לוד", r.Root.Q<Label>("capture-title").text);+ Assert.AreEqual(He.Format("capture.intro", "לוד"), r.Root.Q<Label>("capture-intro").text);+ Assert.AreEqual(He["capture.option.raid"], r.Root.Q<Button>("capture-option-raid").text);+ Assert.AreEqual(He["capture.about.raid"], r.Root.Q<Label>("capture-about-raid").text);+ Assert.AreEqual(He["capture.changes_none"], r.Root.Q<Label>("capture-preview-raid").text);+ Assert.AreEqual(He["event.hide"], r.Hide.text);+ foreach (var name in new[] { "capture-title", "capture-intro", "capture-option-raid", "capture-about-raid", "capture-preview-raid" })+ Assert.AreEqual(LanguageDirection.RTL, r.Root.Q<TextElement>(name).languageDirection, $"{name} reads right to left");+ }++ // ---- The layout ----++ static bool Inside(Rect inner, Rect outer, float slack = 1f) =>+ inner.xMin >= outer.xMin - slack && inner.yMin >= outer.yMin - slack && inner.xMax <= outer.xMax + slack && inner.yMax <= outer.yMax + slack;++ /// <summary>The window shapes of UiLayoutTests.EveryEventCardFitsTheDecisionLayer.</summary>+ static readonly (int w, int h)[] Windows =+ {+ (1920, 1080), (1280, 720), (1366, 768), (1760, 1000), (1920, 1200), (1440, 900), (1024, 768), (1280, 1024),+ (1024, 1024), (960, 1080), (800, 1000), (390, 844), (960, 600), (1531, 784), (1568, 752), (2560, 1080), (1920, 900), (1366, 657),+ };++ /// <summary>At every window shape the decision card is checked at, in English and Hebrew, with all three options: the+ /// dialog lies in the decision layer below the top bar, Hide inside it, every option and line no wider than the dialog,+ /// each option's text inside its button. With previews of the size the rules give (Plausible), a window logically at+ /// least EventCardPresenter.ScrollFallbackHeight tall shows everything without scrolling; with every quantity changed+ /// for every option (Full, seven lines each) the text and options scroll and Hide stays in view.</summary>+ [UnityTest]+ public IEnumerator ItFitsEveryWindowInBothLanguages()+ {+ var problems = new List<string>();+ foreach (var text in new[] { En, He })+ foreach (var (w, h) in Windows)+ foreach (var full in new[] { false, true })+ {+ var at = $"{text["ui.lang"]} {w}x{h}{(full ? " full previews" : "")}";+ using var r = new Rig(Awaiting(C, "lod"), text, w, h, full ? Helper(new[] { "raid", "occupy", "deport" }) : Plausible);+ yield return Frames(4);+ var card = r.Element.worldBound; var layer = r.Root.Q("event-layer").worldBound; var bar = r.Root.Q("top-bar").worldBound;+ if (!(card.width > 0 && card.height > 0)) { problems.Add($"{at}: the dialog is not shown"); continue; }+ if (!Inside(card, layer)) problems.Add($"{at}: the dialog {card} leaves the decision layer {layer}");+ if (card.yMin < bar.yMax - 0.5f) problems.Add($"{at}: the dialog {card} starts over the top bar {bar}");+ if (!Inside(r.Hide.worldBound, card)) problems.Add($"{at}: Hide {r.Hide.worldBound} is cut off by the dialog {card}");+ foreach (var e in r.Root.Q("capture-options").Query<TextElement>().ToList().Concat(new[] { r.Root.Q<Label>("capture-title"), r.Root.Q<Label>("capture-intro") }))+ {+ if (e.worldBound.xMin < card.xMin - 1 || e.worldBound.xMax > card.xMax + 1) problems.Add($"{at}: '{e.name}' {e.worldBound} is wider than the dialog {card}");+ if (!UiLayoutTests.TextFits(e)) problems.Add($"{at}: the text of '{e.name}' does not fit {e.contentRect}");+ }+ var scroll = r.Root.Q<ScrollView>("capture-scroll");+ if (!full && r.Root.panel.visualTree.layout.height >= EventCardPresenter.ScrollFallbackHeight && scroll.contentContainer.layout.height > scroll.contentViewport.layout.height + 1f)+ problems.Add($"{at}: the dialog scrolls ({scroll.contentContainer.layout.height:0} px in {scroll.contentViewport.layout.height:0} px)");+ }+ Assert.IsEmpty(problems, string.Join("\n", problems));+ }+}diff --git a/unity/Assets/Tests/EditMode/CaptureDialogTests.cs.meta b/unity/Assets/Tests/EditMode/CaptureDialogTests.cs.metanew file mode 100644index 000000000..f080bb8fb--- /dev/null+++ b/unity/Assets/Tests/EditMode/CaptureDialogTests.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 8c66ae6ce1fc047e78aa95cc2adab0ed\ No newline at end of filediff --git a/unity/Assets/UI/Game.uxml b/unity/Assets/UI/Game.uxmlindex 2a4eb40bc..eeee663d8 100644--- a/unity/Assets/UI/Game.uxml+++ b/unity/Assets/UI/Game.uxml@@ -216,7 +216,29 @@<ui:Button name="event-illustration" class="event-illustration" /><Statecraft.Game.UI.UiFrame filigree="true" /></ui:VisualElement>+ <!-- The capture dialog (GDD Phase 6 PR 10, #802; CaptureDialogPresenter): in the decision card's place and style,+ shown while no decision card is open. The place's name and the options the sim offers+ (SettlementControl.CaptureOptions), in the sim's order, each with its plain description and the sim's preview+ of what it changes at once. No picture, no sound, no video. The text and the options scroll together+ on a short window; Hide stays in view. Focus order: the card, the options, Hide. -->+ <ui:VisualElement name="capture-card" class="panel event-card capture-card">+ <ui:Label name="capture-title" class="title event-title" />+ <ui:VisualElement class="gold-rule" />+ <ui:ScrollView name="capture-scroll" class="event-scroll capture-scroll">+ <ui:Label name="capture-intro" class="event-text" />+ <ui:Label name="capture-none" class="event-delegate capture-none" />+ <ui:VisualElement name="capture-options" />+ </ui:ScrollView>+ <ui:VisualElement name="capture-foot" class="event-foot">+ <ui:Label name="capture-count" class="muted event-count" />+ <ui:Button name="capture-hide" class="event-hide" />+ </ui:VisualElement>+ <Statecraft.Game.UI.UiFrame filigree="true" />+ </ui:VisualElement><ui:Button name="event-reopen" class="event-reopen" />+ <!-- The hidden capture dialog's button, in Decision waiting's place: it shows only while no decision card is open or+ waiting, so the two never show together. -->+ <ui:Button name="capture-reopen" class="event-reopen" /></ui:VisualElement><!-- The Cabinet as promo/final/04 (CabinetPresenter): a wide screen; the Prime Minister's card and the appointmentlist at the side; the legislature's seats (Hemicycle) with its legend above a grid of person cards. -->diff --git a/unity/Assets/UI/Statecraft.uss b/unity/Assets/UI/Statecraft.ussindex 80eb2903b..a31767b1b 100644--- a/unity/Assets/UI/Statecraft.uss+++ b/unity/Assets/UI/Statecraft.uss@@ -271,13 +271,13 @@ Button:disabled { color: var(--ink-dim); border-color: rgba(120, 120, 120, 0.4);waiting" button at the layer's top right (EventCardPresenter), which takes no more room than itself. */.event-layer { position: absolute; left: 16px; right: 16px; top: 112px; bottom: 16px; justify-content: center; align-items: center; }.event-scrim { display: none; position: absolute; left: 56px; right: -16px; top: 0; bottom: -16px; background-color: rgba(5, 9, 18, 0.55); }-.event-open .event-scrim { display: flex; }+.event-open .event-scrim, .capture-open .event-scrim { display: flex; }/* The backdrop reaches up to the bar's bottom at every tier: a full-width band from the bar to the layer's top (42 px under the70 px one-row bar, where the date plate hangs; 16 px under the taller tiers' bars), then the layer's own part right ofthe left column, and the column's strip (event-gutter) beside and below its discs. No strip of map stays live under acard, and the hanging plate is dimmed evenly (review of #624). */.event-scrim-top { display: none; position: absolute; left: -16px; right: -16px; top: -42px; height: 42px; background-color: rgba(5, 9, 18, 0.55); }-.event-open .event-scrim-top { display: flex; }+.event-open .event-scrim-top, .capture-open .event-scrim-top { display: flex; }.hud-narrow .event-scrim-top, .hud-two-row .event-scrim-top, .hud-three-row .event-scrim-top { top: -16px; height: 16px; }.event-reopen {display: none; position: absolute; right: 0; top: 0; margin: 0; padding: 6px 18px; font-size: 20px; -unity-text-align: middle-center;@@ -344,7 +344,7 @@ Button:disabled { color: var(--ink-dim); border-color: rgba(120, 120, 120, 0.4);.event-office { white-space: normal; -unity-text-align: middle-center; font-size: 18px; }/* Options wrap inside the card (playtest 2, P2-2). No sign beside the text: a chevron read as "expand", but the presschooses (#1105); the gold rim and the hover and focus fills (Button:hover, :focus) mark it as a button. */-#event-options Button { white-space: normal; -unity-text-align: middle-left; }+#event-options Button, #capture-options Button { white-space: normal; -unity-text-align: middle-left; }.event-option { min-height: 42px; padding: 5px 12px; margin: 3px 0; border-color: rgba(196, 160, 92, 0.6); }.event-title { -unity-text-align: middle-center; margin-bottom: 4px; white-space: normal; font-size: 28px; } /* centred, as before, in the card */.event-text { white-space: normal; margin-bottom: 8px; }@@ -359,6 +359,10 @@ Button:disabled { color: var(--ink-dim); border-color: rgba(120, 120, 120, 0.4);.lang-he .event-rejoin { margin: -1px 46px 4px 0; }/* The line over the greyed-out options when the Attention left cannot pay for an answer (#1034). */.event-delegate { display: none; white-space: normal; margin: 4px 0; color: var(--gold-light); }+/* The capture dialog (CaptureDialogPresenter): under each option its plain description, then the sim's preview of what+ it changes at once, in the muted ink; neither takes a Tab stop. */+.capture-about { white-space: normal; margin: 0 4px 2px 4px; }+.capture-preview { white-space: normal; margin: 0 4px 8px 4px; }.draft { display: none; color: var(--down); -unity-font-definition: url("project://database/Assets/UI/Fonts/EBGaramond-SemiBold.ttf"); -unity-text-align: middle-center; }/* The info panel: the hex's terrain sign (UiIcon on the biome's map colour, InfoPanelPresenter) beside its facts. It startsright of the left icon lane (84 px, as the toast; #1236: Star, Report and Share sit at the lane's foot) and keeps its right@@ -938,7 +942,7 @@ Button.settings-choice-selected { -unity-font-definition: url("project://databasstays where it is: the minimap column, the info panel, the toast and the screens' position. Each text's paragraphdirection is set in code from its own words (UiDirection), because dates, money and names are still English (#55). */.lang-he { -unity-text-align: upper-right; }-.lang-he .button, .lang-he Button, .lang-he #event-options Button { -unity-text-align: middle-right; }+.lang-he .button, .lang-he Button, .lang-he #event-options Button, .lang-he #capture-options Button { -unity-text-align: middle-right; }/* The buttons and cards whose text is centred stay centred (the rule above is the more specific one). */.lang-he .nav-button, .lang-he .seat { -unity-text-align: upper-center; }.lang-he .event-reopen, .lang-he .event-hide, .lang-he .event-illustration, .lang-he .start-button, .lang-he .start-listen, .lang-he .start-report { -unity-text-align: middle-center; }diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yamlindex 230521bc9..8bdf7f82a 100644--- a/unity/Assets/UI/strings.en.yaml+++ b/unity/Assets/UI/strings.en.yaml@@ -163,6 +163,33 @@ event.objective_late_one: "Completed 1 month later than in history."event.alt_origin: "Alternative course. It follows the government's decision: {0} ({1}). In the record: {2}."event.alt_origin_no_record: "Alternative course. It follows the government's decision: {0} ({1})."event.rejoin: "Returns to the recorded course."+# The capture dialog (GDD Phase 6 PR 10, #802; CaptureDialogPresenter). SENSITIVE: the owner reviews every line here, in+# both languages, before any shareable build (plan 2026-10-15-gdd-phase-6.md, PR 10's gate). Q-UI-1 (b) (owner, 18 October+# 2026, #783): the GDD's words for the options, with a one-line plain description under each; the descriptions state the+# rules in docs/gdd/settlement-control.md and hold no number. Q-UI-2 (a): the preview is the sim's resource and parameter+# changes only (SettlementControl.CaptureOptions), each a top-bar caption or capture.caption.* with its change.+# {0} the place's name.+capture.intro: "Israeli units hold {0}, and no enemy unit is there. Choose what happens next. Your choice takes effect at End turn; until you choose, the units stay."+capture.option.raid: "Raid and withdraw"+capture.option.occupy: "Occupy"+capture.option.deport: "Deport"+capture.about.raid: "The units leave at once, and the place is under enemy control again. Its residents are unchanged."+capture.about.occupy: "One unit stays and holds the place for a set number of turns, at a Money cost each turn. Its residents are not affected."+capture.about.deport: "The residents are displaced, and the place is depopulated. Social cohesion and International support fall, and International support keeps falling for the rest of the game."+# The heading over the changes, one per line in the turn report's form (report.line: the caption, then the change as the+# top bar would show it), or the line when nothing changes.+capture.changes: "Changes at once:"+capture.changes_none: "Changes at once: none"+capture.caption.attention: "Attention"+capture.caption.food: "Food"+capture.caption.arms: "Arms"+capture.caption.score: "Score"+capture.delta_attention: "{0:+0.0;-0.0}"+capture.delta_count: "{0:+#,##0;-#,##0}"+# No option the sim offers can be chosen this turn (a Raid with no free hex to withdraw to, R-CTRL-010): the capture waits.+capture.none: "None of the choices can be made this turn. The units stay, and the decision waits."+# The hidden dialog's button. {0} the place's name.+capture.reopen: "Decision waiting: {0}"start.listen: "Play the recording"start.stop: "Stop the recording"start.loading: "Loading the recording…"diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yamlindex 252599e9a..f507aea78 100644--- a/unity/Assets/UI/strings.he.yaml+++ b/unity/Assets/UI/strings.he.yaml@@ -174,6 +174,27 @@ event.objective_late_one: "הושלם באיחור של חודש אחד לעומevent.alt_origin: "מסלול חלופי. הוא נובע מהחלטת הממשלה: {0} ({1}). בהיסטוריה: {2}."event.alt_origin_no_record: "מסלול חלופי. הוא נובע מהחלטת הממשלה: {0} ({1})."event.rejoin: "חוזר למסלול ההיסטורי."+# The capture dialog (GDD Phase 6 PR 10, #802). SENSITIVE: the owner reviews every line before any shareable build.+# Agent-drafted, for the native reviewer (#564). Q-UI-1 (b): direct Hebrew equivalents of the GDD's words, except the+# owner's own (22 October 2026, #1317): Occupy is "שחרור", and the Deport line is the owner's "displaced" wording.+# Gender-neutral phrasing ("יש לבחור").+capture.intro: "כוחות ישראליים מחזיקים ב־{0}, ואין שם כוחות אויב. יש לבחור מה יקרה עכשיו. הבחירה תיכנס לתוקף בסיום התור; עד שתיבחר אפשרות, הכוחות נשארים במקום."+capture.option.raid: "פשיטה ונסיגה"+capture.option.occupy: "שחרור"+capture.option.deport: "גירוש"+capture.about.raid: "הכוחות יוצאים מיד, והמקום חוזר לשליטת האויב. מצב התושבים לא משתנה."+capture.about.occupy: "יחידה אחת נשארת ומחזיקה במקום מספר קבוע של תורות, בעלות כספית בכל תור. התושבים לא מושפעים."+capture.about.deport: "התושבים נעקרים ממקומם, והמקום מתרוקן מתושביו. הלכידות החברתית והתמיכה הבינלאומית יורדות, והתמיכה הבינלאומית ממשיכה לרדת עד סוף המשחק."+capture.changes: "שינויים מיידיים:"+capture.changes_none: "שינויים מיידיים: אין"+capture.caption.attention: "תשומת לב"+capture.caption.food: "מזון"+capture.caption.arms: "נשק"+capture.caption.score: "ניקוד"+capture.delta_attention: "{0:+0.0;-0.0}"+capture.delta_count: "{0:+#,##0;-#,##0}"+capture.none: "אף אחת מהאפשרויות אינה זמינה בתור הזה. הכוחות נשארים במקום, וההחלטה ממתינה."+capture.reopen: "החלטה ממתינה: {0}"start.listen: "השמעת ההקלטה"start.stop: "עצירת ההקלטה"start.loading: "טוען את ההקלטה…"