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 badge on the Budget disc while an edited budget is not submitted (refs #1109; rule proposed, owner may veto) (#1352)
Beri453940b987ae
diff --git a/changelog.d/1109-budget-badge.md b/changelog.d/1109-budget-badge.mdnew file mode 100644index 000000000..e957c098a--- /dev/null+++ b/changelog.d/1109-budget-badge.md@@ -0,0 +1,5 @@+- The Budget disc in the side menu shows the Cabinet disc's gold badge while the Budget screen has changes that are not+ submitted and Submit could still apply them this turn, and its tip says so in English and draft Hebrew. Such changes+ survive End turn but are never applied, so the badge points at that trap. The sim's `EconomySystem.Unsubmitted`+ decides it (the draft differs from the queued budget, else today's; the game is not over; and the Attention left+ pays for the allocation, or Submit only withdraws a queued one); the UI only reads it (refs #1109).diff --git a/sim/Statecraft.Sim.Tests/EconomyTests.cs b/sim/Statecraft.Sim.Tests/EconomyTests.csindex b256d2672..00879df50 100644--- a/sim/Statecraft.Sim.Tests/EconomyTests.cs+++ b/sim/Statecraft.Sim.Tests/EconomyTests.cs@@ -154,3 +154,48 @@ public class EconomyCoverageTestsAssert.Equal(shares, s.Budget);}}++/// <summary>#1109: the side menu's Budget badge reads EconomySystem.Unsubmitted, true while the Budget screen's draft differs+/// from what End turn will apply (a queued budget's shares, else today's) and Submit can change that this turn.</summary>+public class EconomyUnsubmittedTests+{+ static readonly Content C = ContentLoader.Load(RealContentTests.ContentRoot());++ static Dictionary<string, double> Moved(IReadOnlyDictionary<string, double> shares)+ {+ var d = new Dictionary<string, double>(shares);+ d["defense_minister"] += 0.05; d["finance_minister"] -= 0.05;+ return d;+ }++ [Theory]+ // case, expected: Attention 4 = a full turn (rules.yaml attention_per_turn), allocate_budget costs 2.+ [InlineData("untouched", false)]+ [InlineData("edited", true)]+ [InlineData("edited_and_submitted", false)]+ [InlineData("edited_after_submitting", true)] // Submit again: the queued budget is refunded first+ [InlineData("edited_after_submitting_refund", true)] // Attention 2 = the queued budget's price: only its refund pays+ [InlineData("back_to_today_after_submitting", true)] // Submit withdraws the queued budget, which costs nothing+ [InlineData("back_to_today_no_attention", true)]+ [InlineData("game_over", false)]+ [InlineData("no_attention", false)]+ [InlineData("attention_queued", false)] // Attention 2.5 less set_mobilization 1 leaves 1.5 < 2+ public void TrueOnlyWhileADraftDiffersAndSubmitCanApplyIt(string probe, bool expected)+ {+ var s = new GameState { Date = new DateTime(1949, 6, 1), Attention = probe.Contains("no_attention") ? 0 : probe == "attention_queued" ? 2.5 : probe.EndsWith("_refund") ? 2 : 4 };+ EconomySystem.Init(C, s);+ var today = new Dictionary<string, double>(s.Budget);+ var edited = Moved(today);+ if (probe == "game_over") s.GameOver = GameOverCodes.CoalitionCollapse;+ var (draft, pending) = probe switch+ {+ "untouched" => (today, new Command[0]),+ "edited_and_submitted" => (edited, new Command[] { new AllocateBudget(new Dictionary<string, double>(edited)) }),+ "edited_after_submitting" or "edited_after_submitting_refund" => (Moved(edited), new Command[] { new AllocateBudget(new Dictionary<string, double>(edited)) }),+ "back_to_today_after_submitting" or "back_to_today_no_attention" => (today, new Command[] { new AllocateBudget(new Dictionary<string, double>(edited)) }),+ "attention_queued" => (edited, new Command[] { new SetMobilization(0.5) }),+ _ => (edited, new Command[0]),+ };+ Assert.Equal(expected, EconomySystem.Unsubmitted(C, s, draft, pending));+ }+}diff --git a/sim/Statecraft.Sim/EconomySystem.cs b/sim/Statecraft.Sim/EconomySystem.csindex 1216cee97..405e910f0 100644--- a/sim/Statecraft.Sim/EconomySystem.cs+++ b/sim/Statecraft.Sim/EconomySystem.cs@@ -106,5 +106,24 @@ namespace Statecraft.Sims.Budget = new Dictionary<string, double>(shares);return null;}++ /// <summary>#1109: whether the Budget screen's <paramref name="draft"/> differs from what End turn will apply (the+ /// AllocateBudget in <paramref name="pending"/>, this turn's queue, else today's budget) and Submit can still make them+ /// agree this turn: a draft back at today's budget withdraws the queued one for nothing; any other needs the Attention+ /// left once a queued budget is refunded (SimBridge.CanPay's rule) to pay for allocate_budget. False when the game is+ /// over. A query only: the side menu's Budget badge reads it, so the trap of an edited budget that End turn never+ /// applies is visible.</summary>+ public static bool Unsubmitted(Content c, GameState s, IReadOnlyDictionary<string, double> draft, IEnumerable<Command> pending)+ {+ var list = pending.ToList();+ var queued = list.OfType<AllocateBudget>().LastOrDefault();+ if (s.GameOver != null || Same(draft, queued?.Shares ?? s.Budget)) return false;+ return Same(draft, s.Budget)+ || AttentionSystem.Cost(c, s, "allocate_budget") <= AttentionSystem.Left(c, s, list.Where(x => !(x is AllocateBudget))) + 1e-9;+ }++ /// <summary>The Budget screen's comparison: every line of either map within 1e-9, a missing line counting as 0.</summary>+ static bool Same(IReadOnlyDictionary<string, double> a, IReadOnlyDictionary<string, double> b) =>+ a.Keys.Union(b.Keys).All(k => Math.Abs((a.TryGetValue(k, out var x) ? x : 0) - (b.TryGetValue(k, out var y) ? y : 0)) <= 1e-9);}}diff --git a/unity/Assets/Scripts/UI/BudgetPresenter.cs b/unity/Assets/Scripts/UI/BudgetPresenter.csindex 4f99e37fa..6709fc82f 100644--- a/unity/Assets/Scripts/UI/BudgetPresenter.cs+++ b/unity/Assets/Scripts/UI/BudgetPresenter.cs@@ -15,6 +15,8 @@ namespace Statecraft.Game.UIpublic const double Step = 0.05;readonly VisualElement screen; readonly SimBridge bridge; readonly UiText text;readonly Button reset, submit;+ /// <summary>The side menu's Budget disc, whose badge (#1109) this screen lights: only it knows the draft.</summary>+ readonly Button nav;Dictionary<string, double> draft = new Dictionary<string, double>();GameSession session;@@ -22,6 +24,7 @@ namespace Statecraft.Game.UI{screen = root.Q<VisualElement>("screen-budget"); this.bridge = bridge; this.text = text;reset = screen.Q<Button>("budget-reset"); submit = screen.Q<Button>("budget-submit");+ nav = root.Q<Button>("nav-budget");screen.Q<Label>("budget-screen-title").text = text["budget.title"];reset.text = text["budget.reset"]; submit.text = text["budget.submit"];reset.clicked += Reset; submit.clicked += Submit;@@ -160,6 +163,10 @@ namespace Statecraft.Game.UIscreen.Q<Label>("budget-status").text = queuedShares != null ? (Same(draft, queuedShares) ? text["budget.queued"] : text["budget.unsaved"]): Dirty ? text["budget.unsaved"] : "";submit.SetEnabled(Dirty || queuedShares != null);+ // #1109: an edited draft End turn would not apply, and Submit could, lights the Budget disc's badge; its tip says why.+ bool unsubmitted = bridge.BudgetUnsubmitted(draft);+ nav.EnableInClassList(HudPresenter.ActionClass, unsubmitted);+ nav.tooltip = unsubmitted ? text["hud.nav.budget_unsubmitted"] : nav.text;}}}diff --git a/unity/Assets/Scripts/UI/HudPresenter.cs b/unity/Assets/Scripts/UI/HudPresenter.csindex f09b0b4e9..8ac399deb 100644--- a/unity/Assets/Scripts/UI/HudPresenter.cs+++ b/unity/Assets/Scripts/UI/HudPresenter.cs@@ -114,7 +114,8 @@ namespace Statecraft.Game.UI/// <summary>The left icon column (promo 03): the screens' buttons (ScreenNav.Screens).</summary>public const string RailName = "left-column";/// <summary>#1109: the class on a side-menu button whose screen has something the player can do this turn- /// (Statecraft.uss shows the button's BadgeClass dot). Only Cabinet has one: a vacant seat to fill (SimBridge.Vacancies).</summary>+ /// (Statecraft.uss shows the button's BadgeClass dot). Cabinet has one: a vacant seat to fill (SimBridge.Vacancies); Budget+ /// another, an edited budget not submitted (BudgetPresenter, SimBridge.BudgetUnsubmitted).</summary>public const string ActionClass = "nav-action", BadgeClass = "nav-badge";readonly HoverTip? railTips, barTips;/// <summary>The meters' explanations under the bar (#1037): their words and the turn's causes.</summary>diff --git a/unity/Assets/Scripts/UI/SimBridge.cs b/unity/Assets/Scripts/UI/SimBridge.csindex 0e03cabfc..8571a5ac7 100644--- a/unity/Assets/Scripts/UI/SimBridge.cs+++ b/unity/Assets/Scripts/UI/SimBridge.cs@@ -84,6 +84,10 @@ namespace Statecraft.Game.UI/// side menu's Cabinet badge (#1109).</summary>public IReadOnlyList<Office> Vacancies => Cabinet.Vacancies(Content, State, queue);+ /// <summary>Whether the Budget screen's <paramref name="draft"/> is not what End turn will apply and Submit can apply it+ /// (EconomySystem.Unsubmitted): the side menu's Budget badge (#1109).</summary>+ public bool BudgetUnsubmitted(IReadOnlyDictionary<string, double> draft) => EconomySystem.Unsubmitted(Content, State, draft, queue);+/// <summary>Attention left after paying for the queued orders at this turn's prices.</summary>public double AttentionLeft => AttentionSystem.Left(Content, State, queue);diff --git a/unity/Assets/Tests/EditMode/LeftColumnTests.cs b/unity/Assets/Tests/EditMode/LeftColumnTests.csindex 92dd4d991..cfaaa7968 100644--- a/unity/Assets/Tests/EditMode/LeftColumnTests.cs+++ b/unity/Assets/Tests/EditMode/LeftColumnTests.cs@@ -396,7 +396,7 @@ public class LeftColumnTestsvar disc = cabinet.Q(className: "nav-disc").worldBound; var dot = badge.worldBound;Assert.IsTrue(dot.width > 0 && dot.center.x > disc.center.x && dot.center.y < disc.center.y && disc.Overlaps(dot),$"the badge sits on the disc's upper right ({dot} on {disc})");- foreach (var other in ScreenNav.Screens.Where(x => x != "cabinet"))+ foreach (var other in ScreenNav.Screens.Where(x => x != "cabinet" && x != "budget")) // Budget's: the next testAssert.IsNull(ui.Q<Button>("nav-" + other).Q(className: HudPresenter.BadgeClass), other + ": no badge");foreach (var office in Cabinet.Vacancies(C, g.State, new Command[0]))@@ -407,4 +407,52 @@ public class LeftColumnTestsAssert.AreEqual(text["hud.nav.cabinet"], cabinet.tooltip, "the tip is the name again");}}++ /// <summary>#1109: the Budget disc wears the same badge, and its tip says why, while the Budget screen's draft differs from+ /// what End turn will apply and Submit can apply it (EconomySystem.Unsubmitted through SimBridge.BudgetUnsubmitted): an+ /// edit lights it, Submit takes it off, an edit after Submit lights it again, and with no Attention left for an+ /// allocation it goes off, since Submit would be refused.</summary>+ [UnityTest]+ public IEnumerator TheBudgetDiscShowsABadgeWhileAnEditedBudgetIsNotSubmitted()+ {+ foreach (var hebrew in new[] { false, true })+ {+ var text = hebrew ? He : En;+ using var ui = new UiTestKit();+ ui.Root.Q("root").RemoveFromClassList("loading");+ var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);+ g.State.Attention = 4; // the opening rung 5 prices an allocation at 2 x (1 + 4 x 0.25) = 4: just affordable+ var bridge = new SimBridge(g, text);+ using var hud = new HudPresenter(ui.Root, bridge, text);+ using var screen = new BudgetPresenter(ui.Root, bridge, text);+ var nav = ui.Q<Button>("nav-budget");+ var badge = nav.Q(className: HudPresenter.BadgeClass);+ Assert.IsNotNull(badge, "the Budget disc carries a badge element");+ for (int i = 0; i < 3; i++) yield return null;+ Assert.IsFalse(nav.ClassListContains(HudPresenter.ActionClass), "untouched: nothing to submit");+ Assert.AreEqual(DisplayStyle.None, badge.resolvedStyle.display, "untouched: the badge is hidden");+ Assert.AreEqual(text["hud.nav.budget"], nav.tooltip, "untouched: the tip is the disc's name");++ UiTestKit.Press(ui.Q<Button>("budget-education_minister-up"));+ for (int i = 0; i < 3; i++) yield return null;+ Assert.IsTrue(nav.ClassListContains(HudPresenter.ActionClass), "edited: not submitted");+ Assert.AreEqual(DisplayStyle.Flex, badge.resolvedStyle.display, "edited: the badge shows");+ Assert.AreEqual(text["hud.nav.budget_unsubmitted"], nav.tooltip, "edited: the tip says why");+ Assert.AreEqual(text["hud.nav.budget"], nav.text, "the name stays the text (the event log records it)");+ var disc = nav.Q(className: "nav-disc").worldBound; var dot = badge.worldBound;+ Assert.IsTrue(dot.width > 0 && dot.center.x > disc.center.x && dot.center.y < disc.center.y && disc.Overlaps(dot),+ $"the badge sits on the disc's upper right ({dot} on {disc})");++ ui.Press("budget-submit");+ for (int i = 0; i < 3; i++) yield return null;+ Assert.IsFalse(nav.ClassListContains(HudPresenter.ActionClass), "submitted: the badge goes");+ Assert.AreEqual(text["hud.nav.budget"], nav.tooltip, "submitted: the tip is the name again");++ UiTestKit.Press(ui.Q<Button>("budget-education_minister-up"));+ Assert.IsTrue(nav.ClassListContains(HudPresenter.ActionClass), "edited after Submit: not submitted again (the queued budget's 4 is refunded first)");+ g.State.Attention = 0;+ screen.Render();+ Assert.IsFalse(nav.ClassListContains(HudPresenter.ActionClass), "no Attention left: Submit could not apply it");+ }+ }}diff --git a/unity/Assets/UI/Game.uxml b/unity/Assets/UI/Game.uxmlindex 11b8cdfc8..e4f71743d 100644--- a/unity/Assets/UI/Game.uxml+++ b/unity/Assets/UI/Game.uxml@@ -14,7 +14,7 @@<ui:VisualElement name="event-gutter" class="event-gutter" /><ui:VisualElement name="left-column" class="left-column" picking-mode="Ignore"><ui:Button name="nav-cabinet" text="Cabinet" class="nav-button rail-button"><Statecraft.Game.UI.UiIcon glyph="columns" class="nav-disc" /><ui:VisualElement class="nav-badge" picking-mode="Ignore" /></ui:Button>- <ui:Button name="nav-budget" text="Budget" class="nav-button rail-button"><Statecraft.Game.UI.UiIcon glyph="ledger" class="nav-disc" /></ui:Button>+ <ui:Button name="nav-budget" text="Budget" class="nav-button rail-button"><Statecraft.Game.UI.UiIcon glyph="ledger" class="nav-disc" /><ui:VisualElement class="nav-badge" picking-mode="Ignore" /></ui:Button><ui:Button name="nav-defence" text="Defence" class="nav-button rail-button"><Statecraft.Game.UI.UiIcon glyph="helmet" class="nav-disc" /></ui:Button><ui:Button name="nav-why" text="Why?" class="nav-button rail-button"><Statecraft.Game.UI.UiIcon glyph="question" class="nav-disc" /></ui:Button><ui:Button name="nav-timeline" text="Timeline" class="nav-button rail-button"><Statecraft.Game.UI.UiIcon glyph="hourglass" class="nav-disc" /></ui:Button>diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yamlindex 800bceaaf..45c215653 100644--- a/unity/Assets/UI/strings.en.yaml+++ b/unity/Assets/UI/strings.en.yaml@@ -38,6 +38,8 @@ hud.nav.cabinet: "Cabinet"# The Cabinet disc's tip while a seat is vacant that the player can fill (#1109).hud.nav.cabinet_vacant: "Cabinet: a post is vacant. You can appoint someone to it."hud.nav.budget: "Budget"+# The Budget disc's tip while the Budget screen has changes that are not submitted and could be (#1109).+hud.nav.budget_unsubmitted: "Budget: your changes are not submitted. End turn will not apply them until you submit them."hud.nav.defence: "Defence"hud.nav.why: "Why?"hud.nav.how_to_play: "How to play"diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yamlindex 355531455..b83074dfa 100644--- a/unity/Assets/UI/strings.he.yaml+++ b/unity/Assets/UI/strings.he.yaml@@ -31,6 +31,9 @@ hud.nav.cabinet: "ממשלה"# The Cabinet disc's tip while a seat is vacant that the player can fill (#1109). For the native reviewer (#564).hud.nav.cabinet_vacant: "ממשלה: יש תפקיד פנוי. אפשר למנות אליו מישהו."hud.nav.budget: "תקציב"+# The Budget disc's tip while the Budget screen has changes that are not submitted and could be (#1109). For the native reviewer (#564).+# Approved by Beri, a native speaker, on #1352 (22 Oct 2026).+hud.nav.budget_unsubmitted: "תקציב: השינויים עוד לא הוגשו. בלי הגשה, סיום התור לא יחיל אותם."hud.nav.defence: "ביטחון"hud.nav.why: "למה?"hud.nav.how_to_play: "איך משחקים"