Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

UI: the end screen shows the end report (refs #812) (#1156)

Beri3afb171f3d85
diff --git a/changelog.d/ui-end-screen-812.md b/changelog.d/ui-end-screen-812.md
new file mode 100644
index 000000000..8de08f23c
--- /dev/null
+++ b/changelog.d/ui-end-screen-812.md
@@ -0,0 +1,4 @@
+- When the game ends, an end screen shows the sim's end report in English and Hebrew: the outcome, the score, each
+ objective's date beside its historical date, Social cohesion, International Support and the population beside its
+ CBS anchor. Close leaves the map to look at (orders stay refused), and New Game is the usual two presses; showing the
+ screen keeps the save (refs #812).
diff --git a/unity/Assets/Scripts/UI/EndScreenPresenter.cs b/unity/Assets/Scripts/UI/EndScreenPresenter.cs
new file mode 100644
index 000000000..1093ee91a
--- /dev/null
+++ b/unity/Assets/Scripts/UI/EndScreenPresenter.cs
@@ -0,0 +1,145 @@
+#nullable enable
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using Statecraft.Sim;
+using UnityEngine.UIElements;
+
+namespace Statecraft.Game.UI
+{
+ /// <summary>The end screen (GDD Phase 7 PR 9, #812; D-H4): once the game is over it shows the sim's end report
+ /// (EndReport.For, #810) and nothing else: the outcome, the score, each objective's card with the player's date beside the
+ /// historical date, the two national parameters and the population beside its CBS anchor. It formats the report only; no
+ /// number is computed here. It shows when a turn ends the game and when an ended game is loaded or rebuilt in the other
+ /// language; Close leaves the map to inspect (End Turn stays disabled and SimBridge refuses orders once the game is over),
+ /// and New Game is the existing two presses (NewGamePresenter.Press), so showing the screen never deletes the save.
+ /// <para>While it shows, the root has <see cref="OpenClass"/>: ScreenNav.DisableCovered covers the HUD under it as under
+ /// the turn report, and the screen takes the keyboard focus when it is uncovered.</para></summary>
+ public sealed class EndScreenPresenter : IDisposable
+ {
+ /// <summary>On the "root" element while the end screen shows.</summary>
+ public const string OpenClass = "end-screen-open";
+ public const string ElementName = "end-screen";
+
+ readonly VisualElement hudRoot, screen; readonly ScrollView rows; readonly SimBridge bridge; readonly UiText text;
+ readonly Button close, newGame; readonly Action? pressNewGame;
+ readonly Action<IReadOnlyList<Rejection>> onTurn; readonly Action onChanged;
+ readonly EventCallback<NavigationCancelEvent> onCancel;
+ int closedAt = -1;
+
+ /// <param name="pressNewGame">NewGamePresenter.Press; null in a smoke run, which has no New Game (GameRoot).</param>
+ /// <param name="show">False keeps an ended game's screen closed: the language switch rebuilds the UI over a game whose
+ /// end screen the player had closed (GameRoot.SwitchLanguage).</param>
+ public EndScreenPresenter(VisualElement root, SimBridge bridge, UiText text, Action? pressNewGame, bool show = true)
+ {
+ this.bridge = bridge; this.text = text; this.pressNewGame = pressNewGame;
+ hudRoot = root.Q("root") ?? root;
+ screen = root.Q<VisualElement>(ElementName);
+ rows = screen.Q<ScrollView>("end-screen-rows");
+ screen.Q<Label>("end-screen-title").text = text["end.title"];
+ close = screen.Q<Button>("end-screen-close"); close.text = text["report.close"];
+ newGame = screen.Q<Button>("end-screen-new-game"); newGame.text = text["hud.new_game"];
+ newGame.style.display = pressNewGame == null ? DisplayStyle.None : DisplayStyle.Flex;
+ close.clicked += OnClose;
+ newGame.clicked += OnNewGame;
+ onCancel = e => { Close(); e.StopPropagation(); };
+ screen.RegisterCallback(onCancel);
+ ScreenNav.OnUncovered(screen, () =>
+ {
+ close.Focus();
+ close.schedule.Execute(() => { if (IsOpen && screen.enabledSelf && screen.focusController?.focusedElement != close) close.Focus(); });
+ });
+ // Guarded as TurnReportPresenter's handler is: TurnEnded's later handlers include the turn's autosave.
+ onTurn = _ =>
+ {
+ try { if (bridge.State.GameOver != null) Show(); }
+ catch (Exception e) { UnityEngine.Debug.LogException(e); Hide(); }
+ };
+ bridge.TurnEnded += onTurn;
+ onChanged = () => { if (bridge.State.GameOver == null) Hide(); }; // a new game (New Game's second press) is not over
+ bridge.Changed += onChanged;
+ if (bridge.State.GameOver != null && show) Show(); else Hide(); // a loaded or rebuilt ended game opens on its end screen
+ }
+
+ /// <summary>True while the end screen shows.</summary>
+ public bool IsOpen => hudRoot.ClassListContains(OpenClass);
+
+ /// <summary>True in the frame the screen closed (GameRoot's Escape poll, as TurnReportPresenter.ClosedThisFrame).</summary>
+ public bool ClosedThisFrame => closedAt == UnityEngine.Time.frameCount;
+
+ /// <summary>The screen's lines for an ended game, in order: the outcome, the score, one per objective, Social cohesion,
+ /// International Support and the population with its CBS anchor. Every value is the report's.</summary>
+ public static IReadOnlyList<(string Name, string Text)> Lines(Content c, GameState s, UiText t)
+ {
+ var r = EndReport.For(c, s);
+ string Date(DateTime d) => t.Format("date.day_month_year", d.Day, t["date.month_" + d.Month], d.Year);
+ // The GDD loop ends only as the MVP end or a defeat (R-END-002, R-END-005); the legacy codes get the generic line.
+ var outcome = "end.outcome." + r.Outcome;
+ var lines = new List<(string, string)>
+ {
+ ("outcome", t.Has(outcome) ? t[outcome] : t["order.game_over"]),
+ ("score", t.Format("hud.score", r.Score)),
+ };
+ foreach (var o in r.Objectives)
+ {
+ var title = EventSystem.Title(c, s, c.Events.First(e => e.Id == o.Card)); // as the objective's card shows it
+ lines.Add(("objective-" + o.Id, o.Completed is DateTime done
+ ? t.Format("end.objective_done", title, Date(done), Date(o.Historical))
+ : t.Format("end.objective_open", title, Date(o.Historical))));
+ }
+ lines.Add(("cohesion", t.Format("end.parameter", t["hud.caption.cohesion"], PlayerText.Percent(r.SocialCohesion))));
+ lines.Add(("standing", t.Format("end.parameter", t["hud.caption.standing"], PlayerText.Percent(r.InternationalSupport))));
+ string People(double n) => n.ToString("N0", CultureInfo.InvariantCulture);
+ lines.Add(("population", r.PopulationHistory is PopulationAnchor a
+ ? t.Format("end.population_history", People(r.Population), Date(a.Date), People(a.Jews))
+ : t.Format("end.population", People(r.Population))));
+ return lines;
+ }
+
+ void Show()
+ {
+ rows.Clear();
+ foreach (var (name, line) in Lines(bridge.Content, bridge.State, text))
+ {
+ var label = new Label(line) { name = "end-screen-" + name };
+ label.AddToClassList(name == "outcome" ? "end-screen-outcome" : "end-screen-line");
+ rows.Add(label);
+ }
+ screen.style.display = DisplayStyle.Flex;
+ hudRoot.AddToClassList(OpenClass);
+ ScreenNav.DisableCovered(hudRoot); // uncovered (no start screen over it), it takes the focus
+ }
+
+ void OnClose() => Close();
+
+ /// <summary>Closes the screen, leaving the map to inspect; false when it was not open (GameRoot's Escape chain).</summary>
+ public bool Close()
+ {
+ if (!IsOpen) return false;
+ Hide();
+ return true;
+ }
+
+ void OnNewGame() => pressNewGame?.Invoke();
+
+ void Hide()
+ {
+ if (IsOpen) closedAt = UnityEngine.Time.frameCount;
+ screen.style.display = DisplayStyle.None;
+ hudRoot.RemoveFromClassList(OpenClass);
+ ScreenNav.DisableCovered(hudRoot);
+ }
+
+ public void Dispose()
+ {
+ bridge.TurnEnded -= onTurn;
+ bridge.Changed -= onChanged;
+ close.clicked -= OnClose;
+ newGame.clicked -= OnNewGame;
+ screen.UnregisterCallback(onCancel);
+ ScreenNav.OnUncovered(screen, null);
+ Hide();
+ }
+ }
+}
diff --git a/unity/Assets/Scripts/UI/EndScreenPresenter.cs.meta b/unity/Assets/Scripts/UI/EndScreenPresenter.cs.meta
new file mode 100644
index 000000000..6779e1968
--- /dev/null
+++ b/unity/Assets/Scripts/UI/EndScreenPresenter.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 8e1c222bb18763147b4a0633c25a6eb0
\ No newline at end of file
diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.cs
index 3f78ddb94..f81935e73 100644
--- a/unity/Assets/Scripts/UI/GameRoot.cs
+++ b/unity/Assets/Scripts/UI/GameRoot.cs
@@ -61,6 +61,9 @@ namespace Statecraft.Game.UI
string? hoveredCity; // the city HoverCity lit (#1063)
OutcomePresenter? outcomes;
TurnReportPresenter? report;
+ EndScreenPresenter? end;
+ /// <summary>Set by SwitchLanguage for its Begin: the player had closed the end screen, so the rebuilt one stays closed.</summary>
+ bool endClosed;
FirstTurnGuidePresenter? guide;
/// <summary>Tests: the first-turn guide of the last Begin.</summary>
internal FirstTurnGuidePresenter? Guide => guide;
@@ -325,6 +328,10 @@ namespace Statecraft.Game.UI
newGame = Own(new NewGamePresenter(root, bridge, store, toast, text, GameStart.NewSeed));
Own(GameStart.Autosave(bridge, store, text, toast.Append)); // appends: the turn's refusals stay visible
}
+ // Once the game is over, the sim's end report (#812); after the autosave, so the last turn is saved first. New Game
+ // is its two presses; a smoke run has none.
+ end = Own(new EndScreenPresenter(root, bridge, text, newGame == null ? null : newGame.Press, show: !endClosed));
+ endClosed = false;
// An outcome clip holds the pointer while it shows and in the frame it closes (the skipping click selects no hex).
Func<Vector2, bool> overUi = p => outcomes?.HoldsThePointer == true || UiPointer.IsOverUi(root.panel, p, Screen.height);
@@ -472,6 +479,7 @@ namespace Statecraft.Game.UI
{
if (Bridge == null || smokeRun) return;
Language = language;
+ endClosed = end != null && !end.IsOpen; // read before Begin disposes it
Begin(inputs, 0, keep: Bridge);
nav?.Open("settings");
document.rootVisualElement.Q<Button>("settings-language-" + language)?.Focus();
@@ -544,7 +552,7 @@ namespace Statecraft.Game.UI
for (int i = owned.Count - 1; i >= 0; i--) owned[i].Dispose();
owned.Clear();
if (hoveredCity != null) { hoveredCity = null; HandCursor(false); } // the next Begin's pills start unlit
- minimap = null; labels = null; nav = null; start = null; card = null; outcomes = null; report = null; guide = 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; end = null; guide = 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;
@@ -677,12 +685,12 @@ namespace Statecraft.Game.UI
// 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).
- 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) done = guide?.Escape() == 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 = 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(); }
// 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 && report?.IsOpen != true && !(keys.ctrlKey.isPressed || keys.altKey.isPressed || keys.shiftKey.isPressed || keys.leftMetaKey.isPressed || keys.rightMetaKey.isPressed))
+ if (keys != null && outcomes?.Showing == null && report?.IsOpen != true && end?.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;
diff --git a/unity/Assets/Scripts/UI/ScreenNav.cs b/unity/Assets/Scripts/UI/ScreenNav.cs
index 6145e5ed5..179be958e 100644
--- a/unity/Assets/Scripts/UI/ScreenNav.cs
+++ b/unity/Assets/Scripts/UI/ScreenNav.cs
@@ -43,7 +43,8 @@ namespace Statecraft.Game.UI
bool 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 it
+ bool end = r.ClassListContains(EndScreenPresenter.OpenClass); // the end screen (#812) covers the HUD and the report
+ bool report = r.ClassListContains(TurnReportPresenter.OpenClass) || end; // the turn report covers the HUD under it
bool modal = r.ClassListContains(EventCardPresenter.OpenClass) && !start && !screen && !outcome;
r.EnableInClassList(EventCardPresenter.ModalClass, modal);
r.Q("top-bar")?.SetEnabled(!(start || outcome || report));
@@ -63,10 +64,17 @@ namespace Statecraft.Game.UI
var panel = r.Q(TurnReportPresenter.ElementName);
if (panel != null)
{
- bool was = panel.enabledSelf, now = report && !(start || outcome);
+ bool was = panel.enabledSelf, now = r.ClassListContains(TurnReportPresenter.OpenClass) && !(start || outcome || end);
panel.SetEnabled(now);
if (!was && now) (panel.userData as System.Action)?.Invoke(); // TurnReportPresenter: Close takes the focus
}
+ var over = r.Q(EndScreenPresenter.ElementName);
+ if (over != null)
+ {
+ bool was = over.enabledSelf, now = end && !(start || outcome);
+ over.SetEnabled(now);
+ if (!was && now) (over.userData as System.Action)?.Invoke(); // EndScreenPresenter: Close takes the focus
+ }
}
/// <summary>Asks to be told, synchronously, whenever the decision layer comes out from under the start screen, a
diff --git a/unity/Assets/Tests/EditMode/EndScreenTests.cs b/unity/Assets/Tests/EditMode/EndScreenTests.cs
new file mode 100644
index 000000000..b4f82f88b
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/EndScreenTests.cs
@@ -0,0 +1,215 @@
+#nullable enable
+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.UIElements;
+
+/// <summary>The end screen (#812; D-H4): once the game is over it shows the sim's end report (EndReport.For, #810), formatted
+/// only, over the real final state; closing, rebuilding (the language switch) and New Game's first press keep that state and
+/// the saved bytes, and only New Game's second press starts over.</summary>
+public class EndScreenTests
+{
+ 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 toast, New Game, the autosave and the end screen on Game.uxml, over a fresh Historical game.</summary>
+ sealed class Kit : System.IDisposable
+ {
+ public readonly UiTestKit Ui = new UiTestKit();
+ public readonly SimBridge Bridge; public readonly SaveStore Store; public readonly NewGamePresenter NewGame; public readonly TurnReportPresenter Report;
+ public EndScreenPresenter End;
+ readonly List<System.IDisposable> owned = new List<System.IDisposable>();
+ readonly string dir = Path.Combine(Path.GetTempPath(), "statecraft-end-" + System.Guid.NewGuid().ToString("N"));
+
+ public Kit(UiText text, System.Action<GameState>? setUp = null)
+ {
+ var session = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
+ setUp?.Invoke(session.State);
+ Bridge = new SimBridge(session, text);
+ Store = new SaveStore(dir);
+ owned.Add(new HudPresenter(Ui.Root, Bridge, text));
+ var nav = new ScreenNav(Ui.Root); owned.Add(nav);
+ owned.Add(Report = new TurnReportPresenter(Ui.Root, Bridge, text, nav));
+ var toast = new ToastPresenter(Ui.Root, Bridge, text); owned.Add(toast);
+ owned.Add(NewGame = new NewGamePresenter(Ui.Root, Bridge, Store, toast, text, () => GoldenRun.Seed));
+ owned.Add(GameStart.Autosave(Bridge, Store, text));
+ End = new EndScreenPresenter(Ui.Root, Bridge, text, NewGame.Press);
+ }
+
+ /// <summary>The end screen built again over the same game, as Settings' language switch does (GameRoot.SwitchLanguage):
+ /// open again only if it was open.</summary>
+ public void Rebuild(UiText text)
+ {
+ bool open = End.IsOpen;
+ End.Dispose();
+ End = new EndScreenPresenter(Ui.Root, Bridge, text, NewGame.Press, show: open);
+ }
+
+ /// <summary>The end screen made again as a load or a restart makes it (GameRoot.Begin with no keep).</summary>
+ public void Dispose_End_Reload(UiText text)
+ {
+ End.Dispose();
+ End = new EndScreenPresenter(Ui.Root, Bridge, text, NewGame.Press);
+ }
+
+ public VisualElement Q(string name) => Ui.Q<VisualElement>(name);
+ public string Line(string name) => Ui.Q<Label>("end-screen-" + name).text;
+
+ public void Dispose()
+ {
+ End.Dispose();
+ for (int i = owned.Count - 1; i >= 0; i--) owned[i].Dispose();
+ Ui.Dispose();
+ try { if (Directory.Exists(dir)) Directory.Delete(dir, true); } catch (IOException) { }
+ }
+ }
+
+ /// <summary>Money and Food exhausted and kept so (as the sim's DefeatTests): the debt far over the ceiling, an empty stock
+ /// and a foreign currency crisis deep enough to last, so nothing is imported (R-END-001).</summary>
+ static void Exhausted(GameState s)
+ {
+ s.Debt = 1e12;
+ s.Food = 0;
+ s.FxReserves = -1e12;
+ s.ActiveSituations.Add(EconomySystem.FxCrisis);
+ }
+
+ /// <summary>A game on its last day, ended as the MVP ends, with the first objective completed a month early.</summary>
+ static void Ended(GameState s)
+ {
+ var first = C.Objectives[0];
+ Objectives.Record(C, s, C.RulesAt(s.Date).Mvp!, first.Id, first.ReferenceDate.AddMonths(-1), new List<Cause>());
+ s.Date = C.End;
+ s.GameOver = GameOverCodes.MvpEnded;
+ }
+
+ [Test]
+ public void OpensOnGameOverAndADefeatShowsItsCause()
+ {
+ using var k = new Kit(En, Exhausted);
+ Assert.IsFalse(k.End.IsOpen, "no end screen while the game is on");
+ for (int turn = 0; turn < 3 && k.Bridge.State.GameOver == null; turn++) k.Bridge.EndTurn();
+ Assert.AreEqual(GameOverCodes.DefeatEconomy, k.Bridge.State.GameOver, "three exhausted turn ends are the economic defeat");
+ Assert.IsTrue(k.End.IsOpen, "the turn that ends the game opens the end screen");
+ Assert.AreEqual(DisplayStyle.Flex, k.Q("end-screen").style.display.value);
+ Assert.AreEqual(En["end.outcome.defeat_economy"], k.Line("outcome"));
+ Assert.IsFalse(k.Q("top-bar").enabledSelf, "the screen covers the HUD");
+ Assert.IsTrue(k.Q("end-screen").enabledSelf, "and takes input itself");
+ }
+
+ [Test]
+ public void ShowsEveryPartOfTheReportAndNothingElse()
+ {
+ using var k = new Kit(En, Ended);
+ Assert.IsTrue(k.End.IsOpen, "a loaded ended game opens on its end screen");
+ var s = k.Bridge.State; var r = EndReport.For(C, s);
+ var names = k.Ui.Q<ScrollView>("end-screen-rows").Children().Select(x => x.name).ToList();
+ var expected = new[] { "outcome", "score" }.Concat(r.Objectives.Select(o => "objective-" + o.Id))
+ .Concat(new[] { "cohesion", "standing", "population" }).Select(n => "end-screen-" + n);
+ CollectionAssert.AreEqual(expected, names, "the report's parts, in order");
+ Assert.AreEqual(En["end.outcome.mvp_ended"], k.Line("outcome"));
+ Assert.AreEqual(En.Format("hud.score", s.Score), k.Line("score"));
+ Assert.Greater(s.Score, 0);
+ // The first objective: the card's title, the player's date and the historical date (Q-END-1).
+ var first = C.Objectives[0];
+ string Date(System.DateTime d) => En.Format("date.day_month_year", d.Day, En["date.month_" + d.Month], d.Year);
+ var title = EventSystem.Title(C, s, C.Events.First(e => e.Id == first.Card));
+ Assert.AreEqual(En.Format("end.objective_done", title, Date(first.ReferenceDate.AddMonths(-1)), Date(first.ReferenceDate)), k.Line("objective-" + first.Id));
+ foreach (var o in C.Objectives.Skip(1))
+ StringAssert.Contains(Date(o.ReferenceDate), k.Line("objective-" + o.Id), "an open objective still shows its historical date");
+ Assert.AreEqual(En.Format("end.parameter", En["hud.caption.cohesion"], PlayerText.Percent(r.SocialCohesion)), k.Line("cohesion"));
+ Assert.AreEqual(En.Format("end.parameter", En["hud.caption.standing"], PlayerText.Percent(r.InternationalSupport)), k.Line("standing"));
+ // The one comparison with history: the population beside its CBS anchor (Q-END-2, R-END-006).
+ var anchor = r.PopulationHistory!;
+ Assert.AreEqual(En.Format("end.population_history", r.Population.ToString("N0", System.Globalization.CultureInfo.InvariantCulture),
+ Date(anchor.Date), anchor.Jews.ToString("N0", System.Globalization.CultureInfo.InvariantCulture)), k.Line("population"));
+ }
+
+ [Test]
+ public void CloseRebuildAndTheFirstNewGamePressKeepTheStateAndTheSave()
+ {
+ using var k = new Kit(En, Exhausted);
+ for (int turn = 0; turn < 3 && k.Bridge.State.GameOver == null; turn++) k.Bridge.EndTurn();
+ Assert.IsTrue(k.End.IsOpen);
+ var hash = k.Bridge.State.Hash();
+ var saved = File.ReadAllBytes(k.Store.AutosavePath);
+
+ k.Report.Close(); // the last turn's report, under the end screen
+ UiTestKit.Press(k.Ui.Q<Button>("end-screen-close"));
+ Assert.IsFalse(k.End.IsOpen, "Close leaves the map to inspect");
+ Assert.IsTrue(k.Q("top-bar").enabledSelf, "the HUD is back");
+ Assert.AreEqual(hash, k.Bridge.State.Hash(), "closing changes nothing");
+ CollectionAssert.AreEqual(saved, File.ReadAllBytes(k.Store.AutosavePath), "nor the saved game");
+ Assert.IsFalse(k.Ui.Q<Button>("end-turn").enabledSelf, "End Turn stays disabled after the end");
+ Assert.AreEqual(En["order.game_over"], k.Bridge.Queue(new BuyArms(1)), "the map is read-only: an order is refused");
+
+ k.Rebuild(He); // the language switch builds the screens again over the same game
+ Assert.IsFalse(k.End.IsOpen, "a screen the player closed stays closed in the other language");
+ Assert.IsTrue(k.Q("top-bar").enabledSelf);
+ k.Dispose_End_Reload(He);
+ Assert.IsTrue(k.End.IsOpen, "a loaded ended game opens on its end screen again");
+ Assert.AreEqual(He["end.title"], k.Ui.Q<Label>("end-screen-title").text);
+ Assert.AreEqual(He["end.outcome.defeat_economy"], k.Line("outcome"));
+
+ UiTestKit.Press(k.Ui.Q<Button>("end-screen-new-game"));
+ Assert.IsTrue(k.NewGame.Armed, "the first press only asks");
+ Assert.IsTrue(k.End.IsOpen);
+ Assert.AreEqual(hash, k.Bridge.State.Hash(), "showing, closing and rebuilding the screen change nothing");
+ CollectionAssert.AreEqual(saved, File.ReadAllBytes(k.Store.AutosavePath), "nor the saved game");
+
+ UiTestKit.Press(k.Ui.Q<Button>("end-screen-new-game"));
+ Assert.IsNull(k.Bridge.State.GameOver, "the second press starts a new game");
+ Assert.IsFalse(k.End.IsOpen, "which has no end screen");
+ Assert.IsFalse(File.Exists(k.Store.AutosavePath), "New Game removes the old save, as it always has");
+ }
+
+ [Test]
+ public void CancelClosesItAndClosedItTakesNoInput()
+ {
+ using var k = new Kit(En, Ended);
+ var close = k.Ui.Q<Button>("end-screen-close");
+ using (var e = NavigationCancelEvent.GetPooled()) { e.target = close; close.SendEvent(e); }
+ Assert.IsFalse(k.End.IsOpen, "Esc or a gamepad's Cancel closes it");
+ Assert.IsFalse(k.Q("end-screen").enabledSelf, "a closed screen takes no input");
+ Assert.IsFalse(k.End.Close(), "closing it again does nothing");
+ }
+
+ [Test]
+ public void TheLastTurnsReportWaitsUnderTheEndScreenAndADisposedScreenStaysShut()
+ {
+ using var k = new Kit(En, Exhausted);
+ for (int turn = 0; turn < 3 && k.Bridge.State.GameOver == null; turn++) k.Bridge.EndTurn();
+ Assert.IsTrue(k.End.IsOpen && k.Report.IsOpen, "the last turn brings both");
+ Assert.IsFalse(k.Q("turn-report").enabledSelf, "the report takes no input under the end screen");
+ Assert.IsTrue(k.Q("end-screen").enabledSelf);
+ UiTestKit.Press(k.Ui.Q<Button>("end-screen-close"));
+ Assert.IsTrue(k.Q("turn-report").enabledSelf, "and takes it again when the end screen closes");
+ Assert.IsFalse(k.Q("top-bar").enabledSelf, "the report still covers the HUD");
+ k.Report.Close();
+ k.End.Dispose();
+ var again = GameSession.New(C, GoldenRun.Seed, Mode.Historical); Exhausted(again.State);
+ k.Bridge.Replace(again);
+ for (int turn = 0; turn < 3 && k.Bridge.State.GameOver == null; turn++) k.Bridge.EndTurn();
+ Assert.IsNotNull(k.Bridge.State.GameOver);
+ Assert.AreEqual(DisplayStyle.None, k.Q("end-screen").style.display.value, "a disposed end screen listens to no turn");
+ k.Dispose_End_Reload(En); // the kit disposes it once more at the end
+ }
+
+ [Test]
+ public void HebrewShowsTheHebrewWords()
+ {
+ using var k = new Kit(He, Ended);
+ Assert.AreEqual(He["end.title"], k.Ui.Q<Label>("end-screen-title").text);
+ Assert.AreEqual(He["end.outcome.mvp_ended"], k.Line("outcome"));
+ Assert.AreEqual(He["report.close"], k.Ui.Q<Button>("end-screen-close").text);
+ Assert.AreEqual(He["hud.new_game"], k.Ui.Q<Button>("end-screen-new-game").text);
+ StringAssert.StartsWith(He["hud.caption.cohesion"] + ":", k.Line("cohesion"));
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/EndScreenTests.cs.meta b/unity/Assets/Tests/EditMode/EndScreenTests.cs.meta
new file mode 100644
index 000000000..4aabea2e4
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/EndScreenTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 8592ad0e8c9a021b597c30e889be00f3
\ No newline at end of file
diff --git a/unity/Assets/UI/Game.uxml b/unity/Assets/UI/Game.uxml
index 565b57aee..1cc7b8408 100644
--- a/unity/Assets/UI/Game.uxml
+++ b/unity/Assets/UI/Game.uxml
@@ -416,6 +416,19 @@
<Statecraft.Game.UI.UiFrame />
</ui:VisualElement>
</ui:VisualElement>
+ <!-- The end screen (#812, EndScreenPresenter): the sim's end report once the game is over. Over the turn report the
+ last turn brings, under the outcome clips' layer; the same backdrop and panel as the report. -->
+ <ui:VisualElement name="end-screen" class="turn-report">
+ <ui:VisualElement name="end-screen-panel" class="panel turn-report-panel">
+ <ui:VisualElement class="screen-header"><ui:Label name="end-screen-title" class="title" /></ui:VisualElement>
+ <ui:ScrollView name="end-screen-rows" class="turn-report-rows" />
+ <ui:VisualElement class="row turn-report-actions">
+ <ui:Button name="end-screen-new-game" />
+ <ui:Button name="end-screen-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 the
middle, captioned as the order; a click, Enter or Space skips it, Esc skips them all. After the screens, so it
is drawn over them (an open screen is also closed when a clip starts); only the start screen and the toast come
diff --git a/unity/Assets/UI/Statecraft.uss b/unity/Assets/UI/Statecraft.uss
index 3294ab90f..307122c7e 100644
--- a/unity/Assets/UI/Statecraft.uss
+++ b/unity/Assets/UI/Statecraft.uss
@@ -501,6 +501,9 @@ Button.settings-choice-selected { -unity-font-definition: url("project://databas
.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; }
+/* The end screen (#812) reuses the report's backdrop and panel: its outcome in the heading face, one line per part. */
+.end-screen-outcome { white-space: normal; margin-bottom: 10px; color: var(--gold-light); -unity-font-definition: url("project://database/Assets/UI/Fonts/EBGaramond-SemiBold.ttf"); }
+.end-screen-line { white-space: normal; margin-bottom: 6px; }
.turn-report-actions { justify-content: flex-end; margin-top: 8px; flex-shrink: 0; }
.turn-report-actions > Button { margin-left: 8px; }
/* The first-turn guide (#42, FirstTurnGuidePresenter): shown while the root has guide-open. The layer and the ring take no
@@ -853,7 +856,7 @@ Button.settings-choice-selected { -unity-font-definition: url("project://databas
in it. Each rule above that names EB Garamond is listed here; HebrewUiTests fails for one that is missed, including the
classes 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 .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 .why-group, .lang-he .turn-report-heading, .lang-he .end-screen-outcome, .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.yaml
index 5fc1dd75b..a68246230 100644
--- a/unity/Assets/UI/strings.en.yaml
+++ b/unity/Assets/UI/strings.en.yaml
@@ -220,6 +220,16 @@ 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"
+# The end screen (#812; D-H4): the sim's end report (EndReport.For, #810), formatted only. {0} the card's title, {1} the
+# player's date, {2} the historical date; the population's {1} is the date of its CBS anchor and {2} the anchor's count.
+end.title: "The game has ended"
+end.outcome.mvp_ended: "The game has reached its last turn."
+end.outcome.defeat_economy: "Money and Food ran out."
+end.objective_done: "{0}: completed on {1}; historically {2}"
+end.objective_open: "{0}: not completed; historically {1}"
+end.parameter: "{0}: {1}"
+end.population: "Population: {0}"
+end.population_history: "Population: {0}; CBS, {1}: {2}"
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.yaml
index 191c9a3fd..8b0e0df39 100644
--- a/unity/Assets/UI/strings.he.yaml
+++ b/unity/Assets/UI/strings.he.yaml
@@ -229,6 +229,15 @@ report.intro: "מה השתנה בסרגל העליון, ומה הסיבות הע
report.line: "{0}: שינוי של {1}"
report.all: "הכול במסך למה?"
report.close: "סגירה"
+# The end screen (#812; D-H4): the sim's end report, formatted only. For the native reviewer (#564).
+end.title: "המשחק הסתיים"
+end.outcome.mvp_ended: "המשחק הגיע לתורו האחרון."
+end.outcome.defeat_economy: "הכסף והמזון אזלו."
+end.objective_done: "יעד {0}: הושלם ב־{1}; בהיסטוריה ב־{2}"
+end.objective_open: "יעד {0}: לא הושלם; בהיסטוריה ב־{1}"
+end.parameter: "{0}: {1}"
+end.population: "אוכלוסייה: {0}"
+end.population_history: "אוכלוסייה: {0}; לפי הלמ״ס {2} ב־{1}"
cabinet.coalition: "קואליציה: {0} מתוך {1} {3} · יציבות {2}"
cabinet.vacant: "(פנוי)"
cabinet.person: "{0} · {1} · כישורים {2}, נאמנות {3}"