A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
City panel: Train stays enabled when only the Attention is short (Fixes #2978) (#3001)
nikitaa00101-sourcea2b0f373f8c6
diff --git a/changelog.d/train-enabled-short-attention.md b/changelog.d/train-enabled-short-attention.mdnew file mode 100644index 000000000..27ca1d275--- /dev/null+++ b/changelog.d/train-enabled-short-attention.md@@ -0,0 +1,5 @@+### Fixed++- A Train button in the city panel no longer turns grey just because the Attention left can't pay for the order. It+ stays enabled, as Build does, and pressing it says why: "Not enough attention (need 2.0, have 1.0)". It still turns+ grey when the city has no civilian free to train or the Arms stock can't cover the group.diff --git a/unity/Assets/Scripts/UI/GddHexPanel.cs b/unity/Assets/Scripts/UI/GddHexPanel.csindex 55ace7c40..480128d99 100644--- a/unity/Assets/Scripts/UI/GddHexPanel.cs+++ b/unity/Assets/Scripts/UI/GddHexPanel.cs@@ -171,6 +171,19 @@ namespace Statecraft.Game.UI// queue) and as ArmsPurchasePresenter asks it.var preview = Simulation.Preview(c, bridge.TurnStart, bridge.Session.Committed.Concat(queue).ToList());var accepted = !preview.Rejected.Any(x => ReferenceEquals(x.Command, press));+ // #2978 (owner, 9 November 2026: "Enabled + toast (Recommended)"): an order the Attention left cannot pay for+ // keeps its Train button, as Build does: the bridge refuses the press and says why (order.no_attention,+ // SimBridge.Queue). The preview above charges Attention, so only Training's own rule is asked, on a copy of the+ // state the queue leaves, with the press run last, as End turn would. No Train of this type is queued here:+ // CanPay refunds a queued order of the same key, and every Train order costs the same, so with one queued the+ // press can pay. As the preview did, an ended game refuses it (SimBridge.Queue says so; under gdd-0.3+ // OrderButton disables it anyway).+ if (!bridge.CanPay(press))+ {+ var left = Simulation.Preview(c, bridge.TurnStart, bridge.Session.Committed.Concat(bridge.Queued).ToList()).State;+ accepted = s.GameOver == null+ && Training.Start(c, left, id, type.Id, ordered + 1, new System.Collections.Generic.List<Cause>()) == null;+ }// Nor may the press make End turn refuse a queued order it accepts now (its civilians, Arms or anything else).var causesNoNewRefusal = !bridge.Queued.Any(x => preview.Rejected.Any(r => ReferenceEquals(r.Command, x)) && !current.Rejected.Any(r => ReferenceEquals(r.Command, x)));var row = Row(host, $"city-train-{type.Id}-row");diff --git a/unity/Assets/Tests/EditMode/CityPanelTests.cs b/unity/Assets/Tests/EditMode/CityPanelTests.csindex 533b0c11a..bf4115a91 100644--- a/unity/Assets/Tests/EditMode/CityPanelTests.cs+++ b/unity/Assets/Tests/EditMode/CityPanelTests.cs@@ -1570,6 +1570,55 @@ public class CityPanelTestsAssert.AreEqual(text.Format("city.workers", GddHexPanel.Groups(text, before)), ui.Q<Label>("city-workers").text);}+ // #2978 (owner, 9 November 2026: "Enabled + toast (Recommended)"): an order the Attention left cannot pay for keeps its+ // button, and the press is refused with a toast that says why, as Build does (CityProjectPanelTests). Red first: Train+ // asked End turn's preview, which charges Attention, so it greyed out with nothing to say why.+ [Test]+ public void ATrainOrderTheAttentionCannotPayStaysEnabledAndTheBridgeSaysWhy([Values] bool hebrew)+ {+ var t = hebrew ? He : En;+ var refusals = new System.Collections.Generic.List<string>();+ using var ui = new UiTestKit();+ var bridge = Bridge(t, s => s.Attention = 1.0);+ bridge.Refused += refusals.Add;+ using var panel = Panel(ui, bridge, t);+ panel.Show(CityHex.q, CityHex.r);+ var order = new Train(City, "recruit", 1);+ Assert.IsFalse(bridge.CanPay(order), "precondition: 1.0 Attention left, a Train order costs 2.0 at level 5");+ foreach (var track in new[] { "recruit", "halutz", "artillery", "armoured_car" })+ Assert.IsTrue(ui.Q<Button>("city-train-" + track).enabledSelf, track + ": only the Attention is short, so the button stays");+ UiTestKit.Press(ui.Q<Button>("city-train-recruit"));+ Assert.IsEmpty(bridge.Queued, "the bridge refuses the press");+ Assert.AreEqual(1.0, bridge.AttentionLeft!.Value, 1e-9, "the refused press spends nothing");+ Assert.AreEqual(new[] { t.Format("order.no_attention", bridge.Price(order)!.Value, 1.0) }, refusals);+ }++ // The guard for that path: with the Attention short, a Train order the rules refuse anyway still greys out. With no Arms+ // a recruit group is refused (R-ARMS-003), while a halutz group takes none and keeps its button.+ [Test]+ public void WithTheAttentionShortTrainStillGreysOutForItsOwnRules()+ {+ using var ui = new UiTestKit();+ var bridge = Bridge(En, s => { s.Attention = 1.0; s.Arms = 0; });+ using var panel = Panel(ui, bridge, En);+ panel.Show(CityHex.q, CityHex.r);+ Assert.IsFalse(bridge.CanPay(new Train(City, "recruit", 1)), "precondition: the Attention is short");+ Assert.IsFalse(ui.Q<Button>("city-train-recruit").enabledSelf, "R-ARMS-003: the stock cannot cover one recruit group");+ Assert.IsTrue(ui.Q<Button>("city-train-halutz").enabledSelf, "pioneer training takes no Arms");+ }++ // And with every civilian in work (R-TRAIN-001), no Train button is offered, whatever the Attention.+ [Test]+ public void WithTheAttentionShortTrainStillNeedsACivilianWithoutWork()+ {+ using var ui = new UiTestKit();+ var bridge = Bridge(En, s => { s.Attention = 1.0; Counts(50, 50)(s); });+ using var panel = Panel(ui, bridge, En);+ panel.Show(CityHex.q, CityHex.r);+ foreach (var track in new[] { "recruit", "halutz" })+ Assert.IsFalse(ui.Q<Button>("city-train-" + track).enabledSelf, track + ": no civilian is free to train");+ }+[Test]public void TheWorkersLineAlsoPricesATrainOrder([Values] bool hebrew){