A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
UI: a turn report after End turn, and top-bar numbers that explain their change (refs #1037) (#1074)
Eyal Golan99dbae895451
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 550c3930a..7ee79025c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,9 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB### Added- A short How to play screen in the side menu explains the monthly loop, Attention, cities, training, event decisions,the top bar, End turn and delegation, and the Why screen in English and Hebrew (refs #1041, #42).+- After End Turn, a short turn report names each top-bar number that changed, with the change the bar shows and its main+ causes, the sim's own cause messages, and a link to the Why screen; hovering or tapping a top-bar number shows the same+ explanation under the bar. English and Hebrew; no rule or number is computed in the UI (refs #1037).- The military unit record (GDD Phase 5 PR 2): a unit can hold a side, a strength and a standing order with its target,each written into the state hash only when set, so a halutz hashes as before and no golden moves. `unit_types.yaml`gains Israel's `veteran_soldier` (infantry), `artillery` and `armoured_car` (armour) with a `side` and a `class`; thediff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex 223d686fe..45ca8c8fd 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -57,6 +57,7 @@ namespace Statecraft.Game.UI/// <summary>Tests: the decision card of the last Begin.</summary>internal EventCardPresenter? Card => card;OutcomePresenter? outcomes;+ TurnReportPresenter? report;CameraRig? rig;List<(string, int, int, DateTime)>? drawn;/// <summary>The designated sites on the map (#381), made on first use beside the placements; and their states as drawn.</summary>@@ -234,6 +235,8 @@ namespace Statecraft.Game.UI// own settings must not leak into a test. Each Begin (New Game too) reads the file again.Own(new SettingsPresenter(root, text, Application.isPlaying ? SettingsStore.ForPlatform() : null));Own(new CabinetPresenter(root, bridge, text, portraits));+ // After End Turn, what changed in the top bar and the sim's causes (#1037); under an outcome clip, which plays first.+ report = Own(new TurnReportPresenter(root, bridge, text, nav!));var names = map.SettlementsFor(inputs.Map.SettlementsYaml).ToDictionary(s => s.Id, s => s.Name); // the map's parse (issue #321)// 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).@@ -433,7 +436,7 @@ namespace Statecraft.Game.UIif (card != null) { owned.Remove(card); card.Dispose(); }for (int i = owned.Count - 1; i >= 0; i--) owned[i].Dispose();owned.Clear();- minimap = null; labels = null; nav = null; start = null; card = null; outcomes = null; rig = null; drawn = null; drawnSites = null; units = null; Regions = null; logCamera = false;+ minimap = null; labels = null; nav = null; start = null; card = null; outcomes = null; report = null; rig = null; drawn = null; drawnSites = null; units = null; Regions = null; logCamera = false;// A ?profile run cut short (a stopped coroutine never reaches its restore line) must not leave the terrain at the// profile's pixel error (Task 24 review M1). Nothing else changes it, so restoring is always right.if (map != null && map.Terrain != null) map.Terrain.heightmapPixelError = MapBuilder.TerrainPixelError;@@ -558,12 +561,12 @@ namespace Statecraft.Game.UI// Game request (StartScreenPresenter.Escape; idempotent too).// 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).- if (UnityEngine.InputSystem.Keyboard.current?.escapeKey.wasPressedThisFrame == true) { bool done = outcomes?.SkipAll() == true || outcomes?.ClosedThisFrame == true; done |= start?.Escape() == true; done |= nav?.Close() == true; if (!done && document.rootVisualElement.focusController?.focusedElement == null) card?.Escape(); }+ if (UnityEngine.InputSystem.Keyboard.current?.escapeKey.wasPressedThisFrame == true) { bool done = outcomes?.SkipAll() == true || outcomes?.ClosedThisFrame == true; if (!done) done = report?.Close() == true || report?.ClosedThisFrame == true; done |= start?.Escape() == true; done |= nav?.Close() == true; if (!done && document.rootVisualElement.focusController?.focusedElement == null) 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).var keys = UnityEngine.InputSystem.Keyboard.current;- if (keys != null && outcomes?.Showing == null && !(keys.ctrlKey.isPressed || keys.altKey.isPressed || keys.shiftKey.isPressed || keys.leftMetaKey.isPressed || keys.rightMetaKey.isPressed))+ if (keys != null && outcomes?.Showing == null && report?.IsOpen != true && !(keys.ctrlKey.isPressed || keys.altKey.isPressed || keys.shiftKey.isPressed || keys.leftMetaKey.isPressed || keys.rightMetaKey.isPressed)){KeyScroll.Key? page = keys.pageUpKey.wasPressedThisFrame ? KeyScroll.Key.PageUp : keys.pageDownKey.wasPressedThisFrame ? KeyScroll.Key.PageDown: keys.homeKey.wasPressedThisFrame ? KeyScroll.Key.Home : keys.endKey.wasPressedThisFrame ? KeyScroll.Key.End : (KeyScroll.Key?)null;@@ -576,7 +579,7 @@ namespace Statecraft.Game.UI}/// <summary>Plays turns the way a player does: answers each open event by pressing the card's first option button- /// while the turn's Attention pays for an answer, then presses End Turn; a card left unanswered goes to its minister+ /// while the turn's Attention pays for an answer, then presses End Turn and closes the turn report it brings (#1037); a card left unanswered goes to its minister/// (since the GDD cutover, 15 July 1948 brings three cards at full war, where an answer costs 2 of the 4). Logs "SMOKE turn <n> <date> refused <k>" per turn through <paramref name="log"/>,/// then "SMOKE OK <n> turns <date> <hash>", or "SMOKE FAIL <reason>" when a press does not take effect./// Static, so an edit-mode test can drive it step by step.</summary>@@ -604,6 +607,13 @@ namespace Statecraft.Game.UIfinally { bridge.TurnEnded -= count; }if (!pressed) yield break;if (bridge.State.Turn != turn + 1) { log(FormattableString.Invariant($"SMOKE FAIL End Turn did not end turn {turn}")); yield break; }+ // The turn report (#1037) covers the HUD after End Turn: a player closes it before the next turn.+ var hud = root.Q("root") ?? root;+ if (hud.ClassListContains(TurnReportPresenter.OpenClass))+ {+ if (!Press(root.Q<Button>("turn-report-close"), log)) yield break;+ if (hud.ClassListContains(TurnReportPresenter.OpenClass)) { log(FormattableString.Invariant($"SMOKE FAIL the turn report after turn {turn} did not close")); yield break; }+ }var s = bridge.State;log(FormattableString.Invariant($"SMOKE turn {s.Turn} {s.Date:yyyy-MM-dd} refused {refused}"));}diff --git a/unity/Assets/Scripts/UI/HudModel.cs b/unity/Assets/Scripts/UI/HudModel.csindex b622149e6..1778b64dc 100644--- a/unity/Assets/Scripts/UI/HudModel.cs+++ b/unity/Assets/Scripts/UI/HudModel.cs@@ -1,5 +1,6 @@#nullable enableusing System;+using System.Collections.Generic;using System.Linq;using Statecraft.Sim;@@ -37,6 +38,44 @@ namespace Statecraft.Game.UIm.SayChange.Length == 0 ? t.Format("hud.say", name, m.SayValue): t.Format(m.Sign > 0 ? "hud.say_up" : "hud.say_down", name, m.SayValue, m.SayChange);+ /// <summary>The top bar's meters, in its order (Game.uxml's "meters"), by the ids their elements are named after.</summary>+ public static readonly string[] MeterIds = { "treasury", "immigration", "security", "support", "cohesion", "standing", "fx" };++ /// <summary>How many causes a meter's explanation names (#1037): the turn report and the bar's tip.</summary>+ public const int MaxCauses = 2;++ /// <summary>The meter named <paramref name="id"/> (one of <see cref="MeterIds"/>).</summary>+ public Meter For(string id) => id switch+ {+ "treasury" => Treasury, "immigration" => Immigration, "security" => Security, "support" => Support,+ "cohesion" => Cohesion, "standing" => Standing, "fx" => Fx,+ _ => throw new ArgumentOutOfRangeException(nameof(id), id, "not a top-bar meter"),+ };++ /// <summary>The main causes of a meter's change in <paramref name="turn"/> (#1037): the messages of the sim's own causes+ /// (StepResult.Why) for the quantity the meter shows, the largest change first (each meter's causes share its unit),+ /// the sim's order breaking a tie, at most <see cref="MaxCauses"/>. Nothing is computed or reworded here: a cause is+ /// matched by its target, as <see cref="From"/> reads the state (Money: the Treasury and the debt; Immigration: the+ /// population system's arrivals; Social cohesion: morale; International support: intl_standing; Foreign currency:+ /// fx_reserves; Security: security). Public support is an average the sim computes from the indicators+ /// (EffectsSystem.Approval) and no cause names it, so it has none.</summary>+ public static IReadOnlyList<string> Causes(StepResult? turn, string meter)+ {+ if (turn == null) return Array.Empty<string>();+ Func<Cause, bool> match = meter switch+ {+ "treasury" => w => w.Target == "treasury" || w.Target == "debt",+ "immigration" => w => w.System == "population",+ "security" => w => w.Target == "security",+ "cohesion" => w => w.Target == "morale",+ "standing" => w => w.Target == "intl_standing",+ "fx" => w => w.Target == "fx_reserves",+ _ => w => false,+ };+ return turn.Why.Select((w, i) => (w, i)).Where(x => match(x.w) && x.w.Delta != 0)+ .OrderByDescending(x => Math.Abs(x.w.Delta)).ThenBy(x => x.i).Take(MaxCauses).Select(x => x.w.Message).ToList();+ }+public static HudModel From(SimBridge b, UiText t){// After a reload the changes are the ones the player saw: GameSession.Load replays the save's own commands anddiff --git a/unity/Assets/Scripts/UI/HudPresenter.cs b/unity/Assets/Scripts/UI/HudPresenter.csindex 316fa4759..f602e987c 100644--- a/unity/Assets/Scripts/UI/HudPresenter.cs+++ b/unity/Assets/Scripts/UI/HudPresenter.cs@@ -105,6 +105,8 @@ namespace Statecraft.Game.UI/// <summary>The left icon column (promo 03): the screens' buttons (ScreenNav.Screens).</summary>public const string RailName = "left-column";readonly HoverTip? railTips, barTips;+ /// <summary>The meters' explanations under the bar (#1037): their words and the turn's causes.</summary>+ readonly MeterTip? meterTip;/// <summary>The panels under the bar (Statecraft.uss: top 456 px under the three-row bar), which PlaceUnderBar moves/// down by what the three-row bar grows past its 440 px.</summary>@@ -142,12 +144,13 @@ namespace Statecraft.Game.UIif (root.Q<Label>(HoverTip.TipName) != null)barTips = new HoverTip(root, new[] { newGame }, () => hudRoot.ClassListContains(UiLanguage.HebrewClass) ? HoverTip.Side.Right : HoverTip.Side.Left);}- foreach (var id in new[] { "treasury", "immigration", "security", "support", "cohesion", "standing", "fx" })+ foreach (var id in HudModel.MeterIds){var meter = root.Q<VisualElement>("meter-" + id); var caption = text["hud.caption." + id];meter.Q<Label>(className: "meter-name").text = caption; // the bar shows the words its tooltip sayssaid[id] = (meter, caption);}+ if (root.Q(MeterTip.TipName) != null) meterTip = new MeterTip(root, bridge, text, said.Values.Select(x => x.element));// The text floor: checked now and twice a second, since a window resized at the same shape changes the panel's// scale without changing its layout (no geometry event).smallText = bar.Query<Label>(className: "meter-name").ToList(); // the seven captions and Security's level@@ -170,7 +173,7 @@ namespace Statecraft.Game.UI/// <summary>Unsubscribes from the bridge and the button (the owner calls this when it is disabled).</summary>public void Dispose(){- railTips?.Dispose(); barTips?.Dispose();+ railTips?.Dispose(); barTips?.Dispose(); meterTip?.Dispose();floorCheck.Pause();foreach (var l in smallText) { l.style.fontSize = StyleKeyword.Null; l.style.whiteSpace = StyleKeyword.Null; l.style.maxWidth = StyleKeyword.Null; }turnBox.style.width = StyleKeyword.Null; turnBox.style.minWidth = StyleKeyword.Null;@@ -418,6 +421,7 @@ namespace Statecraft.Game.UISet("cohesion", m.Cohesion);said["cohesion"].element.style.display = m.ShowsCohesion ? DisplayStyle.Flex : DisplayStyle.None;root.Q<Button>("end-turn").SetEnabled(bridge.State.GameOver == null);+ meterTip?.Refresh(); // an open tip follows the new words}}}diff --git a/unity/Assets/Scripts/UI/MeterTip.cs b/unity/Assets/Scripts/UI/MeterTip.csnew file mode 100644index 000000000..f8add9b2a--- /dev/null+++ b/unity/Assets/Scripts/UI/MeterTip.cs@@ -0,0 +1,103 @@+#nullable enable+using System;+using System.Collections.Generic;+using UnityEngine;+using UnityEngine.UIElements;++namespace Statecraft.Game.UI+{+ /// <summary>Each top-bar number explains itself (#1037): while the pointer is over a meter, or after a tap on it (a+ /// touchscreen has no hover), a tip under the bar gives the meter in words (its tooltip, HudModel.Spoken: the value+ /// and this turn's change) and the turn's main causes, which are the sim's own messages (HudModel.Causes). A second+ /// tap on the same meter closes it, a tap on another moves it, and End Turn closes it. It shows only while the meter+ /// can take the pointer, so a report or an outcome clip over the bar hides it. The tip is centred under the meter+ /// and kept inside the window. Nothing is computed here; the tip takes no clicks. Its two labels are the meter's words+ /// in the UI's language and the causes, which the sim gives in English (#55), so each takes its own direction.</summary>+ public sealed class MeterTip : IDisposable+ {+ public const string TipName = "meter-tip";+ /// <summary>The gap between the tip and the window's edge, and between the meter and the tip.</summary>+ const float Margin = 8f;++ readonly VisualElement layer, tip; readonly Label words, causesLine; readonly SimBridge bridge; readonly UiText text;+ readonly List<VisualElement> meters = new List<VisualElement>();+ readonly EventCallback<PointerEnterEvent> onEnter; readonly EventCallback<PointerLeaveEvent> onLeave;+ readonly EventCallback<ClickEvent> onClick; readonly EventCallback<GeometryChangedEvent> onTipGeometry;+ readonly Action<IReadOnlyList<Statecraft.Sim.Rejection>> onTurn;+ VisualElement? hovered, pinned, shownFor;++ public MeterTip(VisualElement root, SimBridge bridge, UiText text, IEnumerable<VisualElement> meters)+ {+ tip = root.Q<VisualElement>(TipName); layer = tip.parent; this.bridge = bridge; this.text = text;+ words = tip.Q<Label>("meter-tip-words"); causesLine = tip.Q<Label>("meter-tip-causes");+ onEnter = e => { hovered = (VisualElement)e.currentTarget; Refresh(); };+ onLeave = e => { if (hovered == e.currentTarget) hovered = null; Refresh(); };+ onClick = e => { var m = (VisualElement)e.currentTarget; pinned = pinned == m ? null : m; Refresh(); };+ onTipGeometry = _ => Place();+ onTurn = _ => { pinned = null; Refresh(); };+ foreach (var m in meters)+ {+ m.RegisterCallback(onEnter); m.RegisterCallback(onLeave); m.RegisterCallback(onClick);+ this.meters.Add(m);+ }+ tip.RegisterCallback(onTipGeometry);+ bridge.TurnEnded += onTurn;+ Hide();+ }++ /// <summary>The meter the tip is shown for, or null.</summary>+ public VisualElement? ShownFor => shownFor;++ /// <summary>The tip's two lines for <paramref name="meter"/> (an element named "meter-" + a HudModel.MeterIds id): its+ /// words, with the causes' heading when there are causes, and the causes ("" when none).</summary>+ public (string words, string causes) Lines(VisualElement meter)+ {+ var causes = HudModel.Causes(bridge.Session.Last, meter.name.Substring("meter-".Length));+ return causes.Count == 0 ? (meter.tooltip, "") : (meter.tooltip + "\n" + text["hud.causes"], string.Join("\n", causes));+ }++ /// <summary>Shows the tip for the hovered meter, else the tapped one, with today's words (HudPresenter.Render calls+ /// this after it sets the tooltips), or hides it.</summary>+ public void Refresh()+ {+ var target = hovered ?? pinned;+ if (target == null || !target.enabledInHierarchy || string.IsNullOrEmpty(target.tooltip) || !(target.worldBound.width > 0)) { Hide(); return; }+ var (w, c) = Lines(target);+ words.text = w; causesLine.text = c;+ causesLine.style.display = c.Length == 0 ? DisplayStyle.None : DisplayStyle.Flex;+ shownFor = target;+ tip.style.display = DisplayStyle.Flex;+ Place();+ }++ /// <summary>Under the meter, centred on it, inside the window: the tip's width is known once it is laid out, so this+ /// runs again on its geometry change.</summary>+ void Place()+ {+ if (shownFor == null) return;+ var r = layer.WorldToLocal(shownFor.worldBound);+ float w = tip.layout.width > 0 ? tip.layout.width : 0, room = layer.layout.width;+ float left = r.center.x - w / 2;+ left = Mathf.Max(Margin, Mathf.Min(left, room - w - Margin));+ if (Mathf.Abs(tip.style.left.value.value - left) > 0.5f || tip.style.left.keyword != StyleKeyword.Undefined) tip.style.left = left;+ var top = r.yMax + Margin;+ if (Mathf.Abs(tip.style.top.value.value - top) > 0.5f || tip.style.top.keyword != StyleKeyword.Undefined) tip.style.top = top;+ }++ void Hide()+ {+ tip.style.display = DisplayStyle.None;+ shownFor = null;+ }++ public void Dispose()+ {+ foreach (var m in meters) { m.UnregisterCallback(onEnter); m.UnregisterCallback(onLeave); m.UnregisterCallback(onClick); }+ meters.Clear();+ tip.UnregisterCallback(onTipGeometry);+ bridge.TurnEnded -= onTurn;+ hovered = pinned = null;+ Hide();+ }+ }+}diff --git a/unity/Assets/Scripts/UI/MeterTip.cs.meta b/unity/Assets/Scripts/UI/MeterTip.cs.metanew file mode 100644index 000000000..1cf947282--- /dev/null+++ b/unity/Assets/Scripts/UI/MeterTip.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 2621a3c27ebf432b85bf3eb98e1ff7a2diff --git a/unity/Assets/Scripts/UI/ScreenNav.cs b/unity/Assets/Scripts/UI/ScreenNav.csindex 87e692a14..834a8c280 100644--- a/unity/Assets/Scripts/UI/ScreenNav.cs+++ b/unity/Assets/Scripts/UI/ScreenNav.cs@@ -28,9 +28,11 @@ namespace Statecraft.Game.UI/// 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, the info panel and the decision layer. Called wherever one of those classes changes (StartScreenPresenter,- /// Open, HudPresenter's tier, EventCardPresenter, OutcomePresenter), so no caller re-enables a panel another still- /// covers.</summary>+ /// 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,+ /// Open, HudPresenter's tier, EventCardPresenter, OutcomePresenter, TurnReportPresenter), so no caller re-enables a+ /// panel another still covers.</summary>public static void DisableCovered(VisualElement root){var r = root.Q("root") ?? root;@@ -38,19 +40,27 @@ namespace Statecraft.Game.UIbool screen = r.ClassListContains(ScreenOpenClass);bool full = screen && r.ClassListContains(HudPresenter.TwoRowClass);bool outcome = r.ClassListContains(OutcomePresenter.OpenClass); // an End Turn outcome clip covers all but itself+ bool report = r.ClassListContains(TurnReportPresenter.OpenClass); // the turn report covers the HUD under itbool modal = r.ClassListContains(EventCardPresenter.OpenClass) && !start && !screen && !outcome;r.EnableInClassList(EventCardPresenter.ModalClass, modal);- r.Q("top-bar")?.SetEnabled(!(start || outcome));- r.Q("left-column")?.SetEnabled(!(start || outcome)); // the screens' buttons: usable wherever the top bar is- r.Q("right-column")?.SetEnabled(!(start || full || modal || outcome));- r.Q("info-panel")?.SetEnabled(!(start || full || modal || outcome || r.ClassListContains(WideOpenClass)));+ 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+ r.Q("right-column")?.SetEnabled(!(start || full || modal || outcome || report));+ r.Q("info-panel")?.SetEnabled(!(start || full || modal || outcome || report || r.ClassListContains(WideOpenClass)));var layer = r.Q("event-layer");if (layer != null){- bool was = layer.enabledSelf, now = !(start || screen || outcome);+ bool was = layer.enabledSelf, now = !(start || screen || outcome || report);layer.SetEnabled(now);if (!was && now) (layer.userData as System.Action)?.Invoke(); // EventCardPresenter: the open card takes the focus}+ var panel = r.Q(TurnReportPresenter.ElementName);+ if (panel != null)+ {+ bool was = panel.enabledSelf, now = report && !(start || outcome);+ panel.SetEnabled(now);+ if (!was && now) (panel.userData as System.Action)?.Invoke(); // TurnReportPresenter: Close takes the focus+ }}/// <summary>Asks to be told, synchronously, whenever the decision layer comes out from under the start screen, adiff --git a/unity/Assets/Scripts/UI/TurnReportPresenter.cs b/unity/Assets/Scripts/UI/TurnReportPresenter.csnew file mode 100644index 000000000..74728da68--- /dev/null+++ b/unity/Assets/Scripts/UI/TurnReportPresenter.cs@@ -0,0 +1,159 @@+#nullable enable+using System;+using System.Collections.Generic;+using Statecraft.Sim;+using UnityEngine.UIElements;++namespace Statecraft.Game.UI+{+ /// <summary>The turn report (#1037; the first outside play-test, #1038: "I see the values changing, but I don't really+ /// understand what's happening"). When a turn has run, a short panel names each top-bar number that changed, with the+ /// change the bar shows (HudModel.From) and its main causes, which are the sim's own cause messages+ /// (StepResult.Why, through HudModel.Causes). "See all" opens the Why screen with every cause; Close, Esc or Cancel+ /// closes it. Nothing is computed or reworded here, so no rule lives in the UI.+ /// <para>While it shows, the root has <see cref="OpenClass"/>: ScreenNav.DisableCovered disables the top bar, the panels+ /// and the decision layer under it, as under an End Turn outcome clip, which is drawn over the report (Game.uxml order)+ /// and disables it in turn; the report takes the keyboard focus when it is uncovered. A turn the sim refused outright+ /// (SimBridge.EndTurn's failure: Session.Last does not move) shows no report; a turn with a refused order does.</para></summary>+ public sealed class TurnReportPresenter : IDisposable+ {+ /// <summary>On the "root" element while the report shows.</summary>+ public const string OpenClass = "turn-report-open";+ public const string ElementName = "turn-report";++ readonly VisualElement hudRoot, report; readonly ScrollView rows; readonly SimBridge bridge; readonly UiText text;+ readonly ScreenNav nav; readonly Button close, all;+ readonly Action<IReadOnlyList<Rejection>> onTurn;+ readonly EventCallback<NavigationCancelEvent> onCancel;+ /// <summary>The turn last reported (or the session's last turn when this was made: a loaded game reports nothing).</summary>+ StepResult? seen;+ int closedAt = -1;++ public TurnReportPresenter(VisualElement root, SimBridge bridge, UiText text, ScreenNav nav)+ {+ this.bridge = bridge; this.text = text; this.nav = nav;+ hudRoot = root.Q("root") ?? root;+ report = root.Q<VisualElement>(ElementName);+ rows = report.Q<ScrollView>("turn-report-rows");+ report.Q<Label>("turn-report-title").text = text["report.title"];+ report.Q<Label>("turn-report-intro").text = text["report.intro"];+ close = report.Q<Button>("turn-report-close"); close.text = text["report.close"];+ all = report.Q<Button>("turn-report-all"); all.text = text["report.all"];+ close.clicked += OnClose;+ all.clicked += SeeAll;+ onCancel = e => { Close(); e.StopPropagation(); };+ report.RegisterCallback(onCancel);+ // Close takes the focus when the report comes out uncovered; again once styles resolve, as an element shown this+ // frame may not take it yet (OutcomePresenter's layer does the same).+ ScreenNav.OnUncovered(report, () =>+ {+ close.Focus();+ close.schedule.Execute(() => { if (IsOpen && report.enabledSelf && report.focusController?.focusedElement != close) close.Focus(); });+ });+ seen = bridge.Session.Last;+ onTurn = _ =>+ {+ // Guarded as a whole, as OutcomePresenter is: nothing here may throw out of TurnEnded, whose later handlers+ // include the turn's autosave.+ try+ {+ var last = bridge.Session.Last;+ if (last == null || ReferenceEquals(last, seen)) return;+ seen = last;+ Show();+ }+ catch (Exception e) { UnityEngine.Debug.LogException(e); Hide(); }+ };+ bridge.TurnEnded += onTurn;+ Hide();+ }++ /// <summary>True while the report shows.</summary>+ public bool IsOpen => hudRoot.ClassListContains(OpenClass);++ /// <summary>True in the frame the report closed: GameRoot's Escape poll then leaves the card alone (the same Escape+ /// key already closed the report through the Cancel event), as for OutcomePresenter.ClosedThisFrame.</summary>+ public bool ClosedThisFrame => closedAt == UnityEngine.Time.frameCount;++ /// <summary>One line of the report: the meter's id, its caption with the change the bar shows, and its main causes.</summary>+ public readonly struct Line+ {+ public readonly string Meter, Heading; public readonly IReadOnlyList<string> Causes;+ public Line(string meter, string heading, IReadOnlyList<string> causes) { Meter = meter; Heading = heading; Causes = causes; }+ }++ /// <summary>The report's lines for the session's last turn: each top-bar meter whose shown change is not empty, in+ /// the bar's order (the meters have different units, so no order by size is given without a rule).</summary>+ public static IReadOnlyList<Line> Lines(SimBridge bridge, UiText text)+ {+ var m = HudModel.From(bridge, text); var lines = new List<Line>();+ foreach (var id in HudModel.MeterIds)+ {+ if (id == "cohesion" && !m.ShowsCohesion) continue;+ var meter = m.For(id);+ if (meter.Delta.Length == 0) continue;+ lines.Add(new Line(id, text.Format("report.line", text["hud.caption." + id], meter.Delta), HudModel.Causes(bridge.Session.Last, id)));+ }+ return lines;+ }++ void Show()+ {+ rows.Clear();+ foreach (var line in Lines(bridge, text))+ {+ var row = new VisualElement { name = "turn-report-" + line.Meter };+ row.AddToClassList("turn-report-row");+ var heading = new Label(line.Heading) { name = "turn-report-heading-" + line.Meter };+ heading.AddToClassList("turn-report-heading");+ row.Add(heading);+ if (line.Causes.Count > 0)+ {+ var causes = new Label(string.Join("\n", line.Causes)) { name = "turn-report-causes-" + line.Meter };+ causes.AddToClassList("turn-report-causes");+ row.Add(causes);+ }+ rows.Add(row);+ }+ if (rows.childCount == 0) { Hide(); return; } // nothing in the bar moved: no report to dismiss+ nav.Close();+ report.style.display = DisplayStyle.Flex;+ hudRoot.AddToClassList(OpenClass);+ ScreenNav.DisableCovered(hudRoot); // the report comes out uncovered (or under an outcome clip) and takes the focus then+ }++ void OnClose() => Close();++ /// <summary>Closes the report; false when it was not open (GameRoot's Escape chain).</summary>+ public bool Close()+ {+ if (!IsOpen) return false;+ Hide();+ return true;+ }++ void Hide()+ {+ if (IsOpen) closedAt = UnityEngine.Time.frameCount;+ report.style.display = DisplayStyle.None;+ hudRoot.RemoveFromClassList(OpenClass);+ ScreenNav.DisableCovered(hudRoot); // the decision layer comes back: an open card takes the focus (OnUncovered)+ }++ void SeeAll()+ {+ Hide();+ nav.Open("why");+ }++ public void Dispose()+ {+ bridge.TurnEnded -= onTurn;+ close.clicked -= OnClose;+ all.clicked -= SeeAll;+ report.UnregisterCallback(onCancel);+ ScreenNav.OnUncovered(report, null);+ Hide();+ }+ }+}diff --git a/unity/Assets/Scripts/UI/TurnReportPresenter.cs.meta b/unity/Assets/Scripts/UI/TurnReportPresenter.cs.metanew file mode 100644index 000000000..b1d092d73--- /dev/null+++ b/unity/Assets/Scripts/UI/TurnReportPresenter.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: f5b5ab3f09ad4f83b5416cd0f5f53637diff --git a/unity/Assets/Tests/EditMode/MeterTipTests.cs b/unity/Assets/Tests/EditMode/MeterTipTests.csnew file mode 100644index 000000000..d1fabe70e--- /dev/null+++ b/unity/Assets/Tests/EditMode/MeterTipTests.cs@@ -0,0 +1,128 @@+#nullable enable+using System.Collections;+using System.Collections.Generic;+using NUnit.Framework;+using Statecraft.Game;+using Statecraft.Game.UI;+using Statecraft.Sim;+using UnityEditor;+using UnityEngine;+using UnityEngine.TestTools;+using UnityEngine.UIElements;+using Object = UnityEngine.Object;++/// <summary>Each top-bar number explains itself (#1037, MeterTip): on hover, or after a tap, a tip under the bar gives the+/// meter in words (its tooltip) and the turn's main causes from the sim (HudModel.Causes), inside the window.</summary>+public class MeterTipTests+{+ static readonly Content C = ContentLoader.Load(Paths.Content);+ 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");++ static void Enter(VisualElement e) { using var ev = PointerEnterEvent.GetPooled(new Event { type = EventType.MouseMove, mousePosition = e.worldBound.center }); ev.target = e; e.SendEvent(ev); }+ static void Leave(VisualElement e) { using var ev = PointerLeaveEvent.GetPooled(new Event { type = EventType.MouseMove, mousePosition = Vector2.zero }); ev.target = e; e.SendEvent(ev); }+ static void Tap(VisualElement e) { using var ev = ClickEvent.GetPooled(); ev.target = e; e.SendEvent(ev); }++ /// <summary>Shown only when MeterTip set it so (an unset inline display reads as Flex, the default).</summary>+ static bool Shown(VisualElement tip) => tip.style.display.keyword == StyleKeyword.Undefined && tip.style.display.value == DisplayStyle.Flex;+ static string Words(VisualElement root) => root.Q<Label>("meter-tip-words").text;+ static string CausesLine(VisualElement root) => root.Q<Label>("meter-tip-causes").text;++ /// <summary>After the fixed opening turn, at 1280x720 and 390x844 in English and Hebrew: hovering the bar's first and+ /// last numbers shows each one's words and the sim's causes under the bar and inside the window; leaving hides it.</summary>+ [UnityTest]+ public IEnumerator HoverExplainsANumberUnderTheBarInsideTheWindow()+ {+ var problems = new List<string>();+ foreach (var hebrew in new[] { false, true })+ foreach (var (w, h) in new[] { (1280, 720), (390, 844) })+ {+ string at = $"{(hebrew ? "he" : "en")} {w}x{h}";+ yield return Rendered(w, h, hebrew, Check);++ IEnumerator Check(VisualElement root, SimBridge bridge, UiText text)+ {+ var tip = root.Q(MeterTip.TipName);+ foreach (var id in new[] { "treasury", "fx", "security" })+ {+ var meter = root.Q("meter-" + id);+ Enter(meter);+ for (int i = 0; i < 3; i++) yield return null; // the tip is placed once its width is laid out+ var causes = HudModel.Causes(bridge.Session.Last, id);+ if (!Shown(tip)) { problems.Add($"{at} {id}: hovering shows no tip"); continue; }+ if (Words(root) != meter.tooltip + "\n" + text["hud.causes"]) problems.Add($"{at} {id}: the tip's words are '{Words(root)}', not its tooltip and the causes' heading");+ if (CausesLine(root) != string.Join("\n", causes)) problems.Add($"{at} {id}: the tip's causes are '{CausesLine(root)}', not the sim's '{string.Join(" | ", causes)}'");+ if (UiDirection.RightToLeft(Words(root)) != hebrew) problems.Add($"{at} {id}: the words are not in the UI's language");+ if (UiDirection.HasRightToLeft(CausesLine(root))) problems.Add($"{at} {id}: the sim's causes are expected in English (#55), in their own label");+ if (causes.Count == 0) problems.Add($"{at} {id}: precondition: the opening turn has causes for it");+ Rect t = tip.worldBound, m = meter.worldBound, win = root.worldBound;+ if (t.xMin < win.xMin - 0.5f || t.xMax > win.xMax + 0.5f || t.yMax > win.yMax + 0.5f) problems.Add($"{at} {id}: the tip {t} leaves the window {win}");+ if (t.yMin < m.yMax) problems.Add($"{at} {id}: the tip {t} is not under its number {m}");+ Leave(meter);+ if (Shown(tip)) problems.Add($"{at} {id}: the tip stays after the pointer leaves");+ }+ }+ }+ Assert.IsEmpty(problems, string.Join("\n", problems));+ }++ /// <summary>A touchscreen has no hover: a tap pins the tip, a tap on another number moves it, a second tap closes it, and+ /// End Turn closes it; the meter's tooltip stays its words alone (the accessibility text, HudModel.Spoken).</summary>+ [UnityTest]+ public IEnumerator ATapPinsTheTipAndASecondTapOrEndTurnClosesIt()+ {+ var problems = new List<string>();+ yield return Rendered(390, 844, false, Check);++ IEnumerator Check(VisualElement root, SimBridge bridge, UiText text)+ {+ var tip = root.Q(MeterTip.TipName);+ VisualElement money = root.Q("meter-treasury"), security = root.Q("meter-security");+ if (money.tooltip.Contains(text["hud.causes"])) problems.Add("the tooltip itself carries the causes");+ Enter(money); Tap(money); Leave(money);+ yield return null;+ if (!Shown(tip)) problems.Add("a tap does not keep the tip");+ Tap(security);+ yield return null;+ if (!Shown(tip) || !Words(root).StartsWith(security.tooltip)) problems.Add($"a tap on another number does not move the tip: '{Words(root)}'");+ Tap(security);+ if (Shown(tip)) problems.Add("a second tap does not close the tip");+ Tap(money);+ if (!Shown(tip)) problems.Add("a tap after closing does not open it again");+ bridge.EndTurn();+ if (Shown(tip)) problems.Add("End Turn does not close the tip");+ }+ Assert.IsEmpty(problems, string.Join("\n", problems));+ }++ /// <summary>Renders Game.uxml at w x h with the HUD after one turn, then runs <paramref name="check"/>, which may wait frames.</summary>+ static IEnumerator Rendered(int w, int h, bool hebrew, System.Func<VisualElement, SimBridge, UiText, IEnumerator> check)+ {+ var rt = new RenderTexture(w, h, 0);+ var ps = Object.Instantiate(AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel));+ ps.targetTexture = rt;+ var go = new GameObject("MeterTipLayout"); go.SetActive(false);+ var doc = go.AddComponent<UIDocument>(); doc.panelSettings = ps;+ doc.visualTreeAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(UiPaths.GameUxml);+ go.SetActive(true);+ var root = doc.rootVisualElement;+ root.Q("root").RemoveFromClassList("loading");+ if (hebrew) root.Q("root").AddToClassList(UiLanguage.HebrewClass);+ var text = hebrew ? He : En;+ var bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), text);+ var hud = new HudPresenter(root, bridge, text);+ try+ {+ bridge.EndTurn();+ for (int i = 0; i < 30 && !(root.Q("meter-fx").layout.width > 0); i++) yield return null;+ for (int i = 0; i < 3; i++) yield return null;+ var inner = check(root, bridge, text);+ while (inner.MoveNext()) yield return inner.Current;+ }+ finally+ {+ hud.Dispose();+ Object.DestroyImmediate(go); Object.DestroyImmediate(ps); rt.Release(); Object.DestroyImmediate(rt);+ }+ }+}diff --git a/unity/Assets/Tests/EditMode/MeterTipTests.cs.meta b/unity/Assets/Tests/EditMode/MeterTipTests.cs.metanew file mode 100644index 000000000..dff255282--- /dev/null+++ b/unity/Assets/Tests/EditMode/MeterTipTests.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: ec47144677234c3fb7fe744bdd783037diff --git a/unity/Assets/Tests/EditMode/TurnReportTests.cs b/unity/Assets/Tests/EditMode/TurnReportTests.csnew file mode 100644index 000000000..ca5aeaedc--- /dev/null+++ b/unity/Assets/Tests/EditMode/TurnReportTests.cs@@ -0,0 +1,240 @@+#nullable enable+using System.Collections;+using System.Collections.Generic;+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;+using Object = UnityEngine.Object;++/// <summary>The turn report (#1037): after End Turn, each top-bar number that changed, with the change the bar shows and its+/// main causes, which are the sim's own cause messages (StepResult.Why). The fixed turn is the opening one: GoldenRun.Seed,+/// Historical, no orders, so One Army goes to its minister.</summary>+public class TurnReportTests+{+ static readonly Content C = ContentLoader.Load(Paths.Content);+ 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>The HUD, the screens' navigation, the Why screen, the decision card and the report on Game.uxml.</summary>+ sealed class Kit : System.IDisposable+ {+ public readonly UiTestKit Ui = new UiTestKit();+ public readonly SimBridge Bridge; public readonly ScreenNav Nav; public readonly EventCardPresenter Card; public readonly TurnReportPresenter Report;+ readonly List<System.IDisposable> owned = new List<System.IDisposable>();++ public Kit(UiText text, System.Func<GameSession, IReadOnlyList<Command>, StepResult>? step = null)+ {+ Bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), text, step);+ owned.Add(new HudPresenter(Ui.Root, Bridge, text));+ owned.Add(Nav = new ScreenNav(Ui.Root));+ owned.Add(new WhyPresenter(Ui.Root, Bridge, text));+ owned.Add(Card = new EventCardPresenter(Ui.Root, Bridge, text, null));+ owned.Add(Report = new TurnReportPresenter(Ui.Root, Bridge, text, Nav));+ }++ public VisualElement Q(string name) => Ui.Q<VisualElement>(name);++ public void Dispose()+ {+ for (int i = owned.Count - 1; i >= 0; i--) owned[i].Dispose();+ Ui.Dispose();+ }+ }++ [Test]+ public void TheFixedTurnReportsEachChangedNumberWithTheSimsOwnCauses()+ {+ using var k = new Kit(En);+ Assert.IsFalse(k.Report.IsOpen, "no report before a turn");+ var turn = k.Bridge.EndTurn();+ Assert.IsTrue(k.Report.IsOpen, "End Turn opens the report");+ Assert.AreEqual(DisplayStyle.Flex, k.Q("turn-report").style.display.value);++ var m = HudModel.From(k.Bridge, En);+ var changed = HudModel.MeterIds.Where(id => m.For(id).Delta.Length > 0).ToArray();+ Assert.GreaterOrEqual(changed.Length, 3, "the opening turn moves at least three numbers in the bar");+ var rows = k.Ui.Q<ScrollView>("turn-report-rows").Children().ToList();+ CollectionAssert.AreEqual(changed.Select(id => "turn-report-" + id), rows.Select(r => r.name), "every changed number, in the bar's order, and no other");+ var messages = new HashSet<string>(turn.Why.Select(w => w.Message));+ foreach (var id in changed)+ {+ // The heading is the bar's caption and the very change the bar shows next to the number.+ var heading = k.Ui.Q<Label>("turn-report-heading-" + id).text;+ Assert.AreEqual(En.Format("report.line", En["hud.caption." + id], k.Ui.Q<Label>(id + "-delta").text), heading, id);+ var causes = k.Ui.Root.Q<Label>("turn-report-causes-" + id);+ var expected = HudModel.Causes(turn, id);+ if (expected.Count == 0) { Assert.IsNull(causes, id + ": no cause line without a cause"); continue; }+ var lines = causes!.text.Split('\n');+ CollectionAssert.AreEqual(expected, lines, id);+ Assert.LessOrEqual(lines.Length, HudModel.MaxCauses, id);+ foreach (var line in lines) Assert.IsTrue(messages.Contains(line), $"{id}: '{line}' is a cause of StepResult.Why, word for word");+ }+ // The fixed turn's own causes: Security moved by One Army, then by the border villages' effect, the larger first.+ var security = k.Ui.Q<Label>("turn-report-causes-security").text.Split('\n');+ Assert.AreEqual("Security +1.5% (One Army)", security[0]);+ StringAssert.EndsWith("(Border villages)", security[1]);+ StringAssert.StartsWith("Money ", k.Ui.Q<Label>("turn-report-causes-treasury").text, "Money's main cause is the economy's line");+ Assert.IsNull(k.Ui.Root.Q("turn-report-causes-support"), "no cause names Public support (an average of the indicators)");+ }++ [Test]+ public void ItCoversTheHudUntilClosedAndThenTheCardIsBack()+ {+ using var k = new Kit(En);+ k.Bridge.EndTurn(); // the second turn opens with The First Truce and The Altalena+ Assert.IsTrue(k.Report.IsOpen);+ Assert.IsFalse(k.Q("top-bar").enabledSelf, "the top bar is covered");+ Assert.IsFalse(k.Q("left-column").enabledSelf, "the screens' buttons are covered");+ Assert.IsFalse(k.Q("event-layer").enabledSelf, "the decision card is covered");+ Assert.IsTrue(k.Q("turn-report").enabledSelf, "the report itself takes input");+ UiTestKit.Press(k.Ui.Q<Button>("turn-report-close"));+ Assert.IsFalse(k.Report.IsOpen);+ Assert.AreEqual(DisplayStyle.None, k.Q("turn-report").style.display.value);+ Assert.IsTrue(k.Q("top-bar").enabledSelf && k.Q("left-column").enabledSelf && k.Q("event-layer").enabledSelf, "everything is back");+ Assert.IsFalse(k.Q("turn-report").enabledSelf, "a closed report takes no input");+ Assert.IsFalse(k.Report.Close(), "closing it again does nothing");+ }++ [Test]+ public void CancelClosesItAndSeeAllOpensTheWhyScreen()+ {+ using var k = new Kit(En);+ k.Bridge.EndTurn();+ var close = k.Ui.Q<Button>("turn-report-close");+ using (var e = NavigationCancelEvent.GetPooled()) { e.target = close; close.SendEvent(e); }+ Assert.IsFalse(k.Report.IsOpen, "Esc or a gamepad's Cancel closes it");+ var turn = k.Bridge.EndTurn();+ Assert.IsTrue(k.Report.IsOpen, "each turn has its own report");+ UiTestKit.Press(k.Ui.Q<Button>("turn-report-all"));+ Assert.IsFalse(k.Report.IsOpen);+ Assert.AreEqual("why", k.Nav.Current, "See all opens the Why screen");+ Assert.AreEqual(turn.Why.Count, k.Ui.Root.Q<ScrollView>("why-rows").Query<Label>(className: "why-line").ToList().Count, "with every cause of the turn");+ }++ [Test]+ public void AnOutcomeClipCoversTheReportAndHandsItBack()+ {+ using var k = new Kit(En);+ k.Bridge.EndTurn();+ var root = k.Q("root");+ root.AddToClassList(OutcomePresenter.OpenClass);+ ScreenNav.DisableCovered(root);+ Assert.IsFalse(k.Q("turn-report").enabledSelf, "under a clip the report takes no input");+ root.RemoveFromClassList(OutcomePresenter.OpenClass);+ ScreenNav.DisableCovered(root);+ Assert.IsTrue(k.Q("turn-report").enabledSelf, "and takes it again when the clip ends");+ Assert.IsFalse(k.Q("event-layer").enabledSelf, "the card stays covered by the report");+ }++ [Test]+ public void ARefusedOrderStillReportsTheTurnAndARefusedTurnDoesNot()+ {+ // A turn that ran with one order refused: the turn happened, so it is reported.+ using (var k = new Kit(En, (g, cmds) =>+ {+ var r = g.Step(cmds);+ return new StepResult(r.State, r.Why, new[] { new Rejection(new SetMobilization(0.5), "refused for the test") });+ }))+ {+ k.Bridge.EndTurn();+ Assert.IsTrue(k.Report.IsOpen, "a refused order does not hide the turn's report");+ }+ // A batch the sim refused outright (SimBridge.EndTurn's failure): nothing happened, so there is nothing to report.+ using (var k = new Kit(En, (g, cmds) => throw new System.ArgumentException("refused for the test")))+ {+ LogAssert.Expect(LogType.Warning, "End Turn refused: refused for the test");+ k.Bridge.EndTurn();+ Assert.IsFalse(k.Report.IsOpen, "a refused turn has no report");+ }+ }++ [Test]+ public void HebrewShowsTheHebrewWordsAndCaptions()+ {+ using var k = new Kit(He);+ k.Bridge.EndTurn();+ Assert.AreEqual(He["report.title"], k.Ui.Q<Label>("turn-report-title").text);+ Assert.AreEqual(He["report.intro"], k.Ui.Q<Label>("turn-report-intro").text);+ Assert.AreEqual(He["report.all"], k.Ui.Q<Button>("turn-report-all").text);+ Assert.AreEqual(He["report.close"], k.Ui.Q<Button>("turn-report-close").text);+ var heading = k.Ui.Q<Label>("turn-report-heading-security").text;+ StringAssert.StartsWith(He["hud.caption.security"] + ":", heading);+ // In a right-to-left line the change keeps its sign in front ("+2%", not "2%+"): UiText.Format marks it (#543).+ StringAssert.Contains(UiText.LeftToRightMark + k.Ui.Q<Label>("security-delta").text + UiText.LeftToRightMark, heading);+ CollectionAssert.AreEqual(HudModel.Causes(k.Bridge.Session.Last, "security"), k.Ui.Q<Label>("turn-report-causes-security").text.Split('\n'),+ "the causes are the sim's messages, as on the Why screen");+ }++ /// <summary>The smoke run plays as a player does: it closes each turn's report before the next turn (GameRoot.Smoke).</summary>+ [Test]+ public void TheSmokeRunClosesTheReportEachTurn()+ {+ using var k = new Kit(En);+ var log = new List<string>();+ var run = GameRoot.Smoke(k.Ui.Root, k.Bridge, k.Card, 3, log.Add);+ while (run.MoveNext()) { }+ StringAssert.StartsWith("SMOKE OK 3 turns", log[log.Count - 1], string.Join("\n", log));+ Assert.IsFalse(k.Report.IsOpen);+ }++ /// <summary>At a laptop's 1280x720 and a phone's 390x844, in English and Hebrew: the report lies in the window, every+ /// line within its panel, its two buttons shown, and the keyboard focus on Close.</summary>+ [UnityTest]+ public IEnumerator ItFitsLaptopAndPhoneInBothLanguages()+ {+ var problems = new List<string>();+ foreach (var hebrew in new[] { false, true })+ foreach (var (w, h) in new[] { (1280, 720), (390, 844) })+ {+ string at = $"{(hebrew ? "he" : "en")} {w}x{h}";+ var rt = new RenderTexture(w, h, 0);+ var ps = Object.Instantiate(AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel));+ ps.targetTexture = rt;+ var go = new GameObject("TurnReportLayout"); go.SetActive(false);+ var doc = go.AddComponent<UIDocument>(); doc.panelSettings = ps;+ doc.visualTreeAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(UiPaths.GameUxml);+ go.SetActive(true);+ var root = doc.rootVisualElement;+ root.Q("root").RemoveFromClassList("loading");+ if (hebrew) root.Q("root").AddToClassList(UiLanguage.HebrewClass);+ var text = hebrew ? He : En;+ var bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), text);+ var owned = new List<System.IDisposable>();+ owned.Add(new HudPresenter(root, bridge, text));+ var nav = new ScreenNav(root); owned.Add(nav);+ owned.Add(new EventCardPresenter(root, bridge, text, null));+ var report = new TurnReportPresenter(root, bridge, text, nav); owned.Add(report);+ try+ {+ bridge.EndTurn();+ for (int i = 0; i < 30 && !(root.Q("turn-report-panel").layout.width > 0); i++) yield return null;+ for (int i = 0; i < 3; i++) yield return null;+ var window = root.worldBound; var panel = root.Q("turn-report-panel").worldBound;+ if (!(panel.width > 0 && panel.height > 0)) problems.Add($"{at}: the report is not shown");+ if (panel.xMin < window.xMin - 0.5f || panel.yMin < window.yMin - 0.5f || panel.xMax > window.xMax + 0.5f || panel.yMax > window.yMax + 0.5f)+ problems.Add($"{at}: the report {panel} leaves the window {window}");+ foreach (var label in root.Q("turn-report-panel").Query<Label>().ToList().Where(l => !string.IsNullOrEmpty(l.text)))+ if (label.worldBound.xMin < panel.xMin - 1 || label.worldBound.xMax > panel.xMax + 1)+ problems.Add($"{at}: '{label.name}' {label.worldBound} is wider than the report {panel}");+ foreach (var name in new[] { "turn-report-all", "turn-report-close" })+ {+ var b = root.Q<Button>(name).worldBound;+ if (!(b.height > 0) || b.yMax > panel.yMax + 1 || b.xMin < panel.xMin - 1 || b.xMax > panel.xMax + 1) problems.Add($"{at}: {name} {b} is not inside the report {panel}");+ }+ if (root.focusController?.focusedElement != root.Q<Button>("turn-report-close")) problems.Add($"{at}: the focus is on {(root.focusController?.focusedElement as VisualElement)?.name ?? "nothing"}, not Close");+ }+ finally+ {+ for (int i = owned.Count - 1; i >= 0; i--) owned[i].Dispose();+ Object.DestroyImmediate(go); Object.DestroyImmediate(ps); rt.Release(); Object.DestroyImmediate(rt);+ }+ }+ Assert.IsEmpty(problems, string.Join("\n", problems));+ }+}diff --git a/unity/Assets/Tests/EditMode/TurnReportTests.cs.meta b/unity/Assets/Tests/EditMode/TurnReportTests.cs.metanew file mode 100644index 000000000..4fe6003f3--- /dev/null+++ b/unity/Assets/Tests/EditMode/TurnReportTests.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 7a9681df139241e288ac6a3209510287diff --git a/unity/Assets/UI/Game.uxml b/unity/Assets/UI/Game.uxmlindex be86bc98c..a8385d862 100644--- a/unity/Assets/UI/Game.uxml+++ b/unity/Assets/UI/Game.uxml@@ -329,6 +329,19 @@</ui:VisualElement><Statecraft.Game.UI.UiFrame /></ui:VisualElement>+ <!-- The turn report (#1037, TurnReportPresenter): after End Turn, each top-bar number that changed and the sim's causes.+ A backdrop over the HUD (ScreenNav.DisableCovered disables what it covers), under the outcome clips' layer. -->+ <ui:VisualElement name="turn-report" class="turn-report">+ <ui:VisualElement name="turn-report-panel" class="panel turn-report-panel">+ <ui:VisualElement class="screen-header"><ui:Label name="turn-report-title" class="title" /><ui:Label name="turn-report-intro" class="muted" /></ui:VisualElement>+ <ui:ScrollView name="turn-report-rows" class="turn-report-rows" />+ <ui:VisualElement class="row turn-report-actions">+ <ui:Button name="turn-report-all" />+ <ui:Button name="turn-report-close" />+ </ui:VisualElement>+ <Statecraft.Game.UI.UiFrame />+ </ui:VisualElement>+ </ui:VisualElement><!-- The End Turn outcome clip (OutcomePresenter): the historical order the player gave, as a 3.5 s silent clip in themiddle, captioned as the order; a click, Enter or Space skips it, Esc skips them all. After the screens, so itis drawn over them (an open screen is also closed when a clip starts); only the start screen and the toast come@@ -381,5 +394,12 @@<!-- The name of an icon-only button, beside it on hover and on keyboard focus (HoverTip; UI Toolkit draws `tooltip`only in Editor UI). Last, so it draws over the panels; it takes no clicks. --><ui:Label name="hud-tip" class="hud-tip" picking-mode="Ignore" />+ <!-- A top-bar number's explanation under the bar, on hover or after a tap (MeterTip, #1037); it takes no clicks. Two+ lines of their own: the meter in the UI's words, then the sim's causes, which are English (#55), so each label+ takes its own direction in the Hebrew UI (UiDirection). -->+ <ui:VisualElement name="meter-tip" class="meter-tip" picking-mode="Ignore">+ <ui:Label name="meter-tip-words" class="meter-tip-line" picking-mode="Ignore" />+ <ui:Label name="meter-tip-causes" class="meter-tip-line" picking-mode="Ignore" />+ </ui:VisualElement></ui:VisualElement></ui:UXML>diff --git a/unity/Assets/UI/Statecraft.uss b/unity/Assets/UI/Statecraft.ussindex 232242748..37217b09c 100644--- a/unity/Assets/UI/Statecraft.uss+++ b/unity/Assets/UI/Statecraft.uss@@ -433,6 +433,21 @@ Button.settings-choice-selected { -unity-font-definition: url("project://databas.why-group { -unity-font-definition: url("project://database/Assets/UI/Fonts/EBGaramond-SemiBold.ttf"); color: var(--gold); letter-spacing: 1px; margin-top: 10px; border-bottom-width: 1px; border-color: rgba(196, 160, 92, 0.25); }.why-line { white-space: normal; padding-left: 12px; }+/* The turn report (#1037): a backdrop over the HUD, as the outcome clips', with a reading panel in the middle. */+.turn-report { display: none; position: absolute; left: 0; top: 0; right: 0; bottom: 0; justify-content: center; align-items: center; background-color: rgba(5, 9, 18, 0.6); padding: 16px; }+.turn-report-panel { width: 640px; max-width: 100%; max-height: 100%; padding: 18px; background-color: rgb(11, 18, 32); }+.turn-report-rows { flex-shrink: 1; min-height: 0; }+.turn-report-row { margin-bottom: 10px; }+.turn-report-heading { white-space: normal; color: var(--gold-light); -unity-font-definition: url("project://database/Assets/UI/Fonts/EBGaramond-SemiBold.ttf"); }+.turn-report-causes { white-space: normal; padding-left: 12px; }+.turn-report-actions { justify-content: flex-end; margin-top: 8px; flex-shrink: 0; }+.turn-report-actions > Button { margin-left: 8px; }+/* A top-bar number's explanation (MeterTip, #1037): under the bar, wrapped, kept inside the window by MeterTip. */+.meter-tip {+ display: none; position: absolute; max-width: 420px; padding: 6px 10px;+ background-color: var(--navy-solid); border-color: var(--gold); border-width: 1px; border-radius: 3px;+}+.meter-tip-line { font-size: 16px; white-space: normal; color: var(--ink); margin: 0; padding: 0; }/* Wide screens (Cabinet and Defence, laid out as promo/final/04 and 08): from the left edge to the minimap column, over theinfo panel (an opaque reading screen; the info panel is about a hex, not needed while reading a screen). The event card@@ -732,7 +747,7 @@ Button.settings-choice-selected { -unity-font-definition: url("project://databasin it. Each rule above that names EB Garamond is listed here; HebrewUiTests fails for one that is missed, including theclasses only presenters add (it gives a label each). */.lang-he, .lang-he .title, .lang-he .button, .lang-he Button, .lang-he .year, .lang-he .end-turn, .lang-he .draft,-.lang-he .why-group, .lang-he .party-group-heading, .lang-he .section-title, .lang-he .card-initials, .lang-he .card-name, .lang-he .house-size,+.lang-he .why-group, .lang-he .turn-report-heading, .lang-he .party-group-heading, .lang-he .section-title, .lang-he .card-initials, .lang-he .card-name, .lang-he .house-size,.lang-he .big-figure, .lang-he .map-label, .lang-he .map-label-tooltip, .lang-he .start-title, .lang-he .start-button {-unity-font-definition: url("project://database/Assets/UI/Fonts/FrankRuhlLibre/FrankRuhlLibre-Medium.ttf");-unity-text-generator: advanced;diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yamlindex 0e8acd012..34e8fced4 100644--- a/unity/Assets/UI/strings.en.yaml+++ b/unity/Assets/UI/strings.en.yaml@@ -21,6 +21,7 @@ hud.say_down: "{0}: {1}, down {2} since last turn"hud.say_million: "{0}{1} million"hud.say_point: "{0:0} point"hud.say_points: "{0:0} points"+hud.causes: "Main causes this turn:"# The top-bar captions, as Game.uxml shows them (HudTests.TheSpokenCaptionsAreTheBarsCaptions), for the words above.hud.caption.treasury: "Money (net)"hud.caption.immigration: "Immigration"@@ -158,6 +159,12 @@ why.effects: "Ongoing effects"why.situations: "Situations"why.other: "Other"why.nothing: "Nothing notable happened this turn."+# The turn report (#1037, TurnReportPresenter): a line is a top-bar caption and the change the bar shows.+report.title: "What happened this turn"+report.intro: "What changed in the top bar, and the main causes:"+report.line: "{0}: {1}"+report.all: "See all in Why?"+report.close: "Close"cabinet.coalition: "Coalition: {0} of {1} {3} · stability {2}"cabinet.vacant: "(vacant)"cabinet.person: "{0} · {1} · competence {2}, loyalty {3}"diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yamlindex dd352a6f1..c76ca0033 100644--- a/unity/Assets/UI/strings.he.yaml+++ b/unity/Assets/UI/strings.he.yaml@@ -16,6 +16,7 @@ hud.say_down: "{0}: {1}, קיטון של {2} מאז התור הקודם"hud.say_million: "{0}{1} מיליון"hud.say_point: "{0:0} נקודה"hud.say_points: "{0:0} נקודות"+hud.causes: "הסיבות העיקריות בתור הזה:"# hud.caption.treasury: Money (R-MONEY-001, Q-MONEY-4); the owner's Hebrew word for it, כסף (Q-HUD-3, 15 October 2026, #375).hud.caption.treasury: "כסף (נטו)"hud.caption.immigration: "עלייה"@@ -164,6 +165,12 @@ why.effects: "השפעות מתמשכות"why.situations: "מצבים"why.other: "אחר"why.nothing: "לא קרה דבר ראוי לציון בתור הזה."+# The turn report (#1037, TurnReportPresenter): a line is a top-bar caption and the change the bar shows.+report.title: "מה קרה בתור הזה"+report.intro: "מה השתנה בסרגל העליון, ומה הסיבות העיקריות:"+report.line: "{0}: שינוי של {1}"+report.all: "הכול במסך למה?"+report.close: "סגירה"cabinet.coalition: "קואליציה: {0} מתוך {1} {3} · יציבות {2}"cabinet.vacant: "(פנוי)"cabinet.person: "{0} · {1} · כישורים {2}, נאמנות {3}"