A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
UI: End turn hides an open capture dialog so the unit can be skipped (#2436)
Eyal Golan1540c01ece2b
diff --git a/changelog.d/capture-endturn.md b/changelog.d/capture-endturn.mdnew file mode 100644index 000000000..aacb5fab1--- /dev/null+++ b/changelog.d/capture-endturn.md@@ -0,0 +1,3 @@+### Fixed+- End turn, when a unit still needs orders, now hides an open capture dialog (nothing chosen; it waits behind+ "Decision waiting") so the unit it selects can be given an order or skipped.diff --git a/unity/Assets/Scripts/UI/CaptureDialogPresenter.cs b/unity/Assets/Scripts/UI/CaptureDialogPresenter.csindex d8133cd1d..62b0645a0 100644--- a/unity/Assets/Scripts/UI/CaptureDialogPresenter.cs+++ b/unity/Assets/Scripts/UI/CaptureDialogPresenter.cs@@ -206,12 +206,17 @@ namespace Statecraft.Game.UI/// <summary>Hide: the dialog gives the map back and waits behind "Decision waiting: place", which takes the focus when/// Hide came from the keyboard. Nothing is chosen.</summary>- public void Collapse()+ public void Collapse() => Collapse(takeFocus: true);++ /// <summary>Hide; with <paramref name="takeFocus"/> false (End turn showing a unit, GameRoot.FocusNextUnit), "Decision+ /// waiting: place" does not take the focus, as EventCardPresenter.Collapse(takeFocus).</summary>+ public void Collapse(bool takeFocus){if (Shown == null) return;collapsedFor = Shown;Render();if (hideByPointer) { hideByPointer = false; return; }+ if (!takeFocus) return;reopen.Focus();// Tried again once styles resolve: the button was hidden a moment ago and may not take it yet.reopen.schedule.Execute(() => { if (Collapsed && reopen.focusController?.focusedElement != reopen) reopen.Focus(); });diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex ddfbf28ee..a7d1b4def 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -884,6 +884,8 @@ namespace Statecraft.Game.UI// An open event card is modal and disables the unit card (ScreenNav.DisableCovered), so the unit End turn selects// could take no order: the card waits behind "Decision waiting", as its Hide button does.card?.Collapse(takeFocus: false);+ // The capture dialog is modal like the card (#802): End turn must show a unit that can take an order (#1680).+ capture?.Collapse(takeFocus: false);// A side screen can still cover the card (#210). Reveal it through normal navigation, not by// bypassing Covered: End turn must show the unit whose orders it asks for (#1680).if (info?.Covered == true) nav?.Open(null);diff --git a/unity/Assets/Tests/EditMode/EndTurnCycleSceneTests.cs b/unity/Assets/Tests/EditMode/EndTurnCycleSceneTests.csindex 37c634aa8..cdadedf64 100644--- a/unity/Assets/Tests/EditMode/EndTurnCycleSceneTests.cs+++ b/unity/Assets/Tests/EditMode/EndTurnCycleSceneTests.cs@@ -51,6 +51,34 @@ public class EndTurnCycleSceneTestsyield return null;Assert.AreEqual(needs - 1, bridge.NeedsOrders.Count, "Skip took the selected unit out of the cycle");}++ // The capture dialog is modal like the event card (#802): End turn hides it too, nothing chosen, so the unit it selects+ // can take an order. Found by the v0.3.5 WebGL smoke, stuck on 15 Aug 1948 behind Ramla's dialog (#2087's card order).+ [UnityTest]+ public IEnumerator BlockedEndTurnHidesAnOpenCaptureDialogSoTheUnitCanBeSkipped()+ {+ VisualElement ui = null!; GameRoot root = null!;+ dir = Path.Combine(Path.GetTempPath(), "statecraft-endturn-capture-" + Guid.NewGuid().ToString("N"));+ yield return CivMovementShots.Boot(false, dir, (t, p, u, g) => { rt = t; ps = p; ui = u; root = g; });+ var bridge = root.Bridge!;+ var g = Statecraft.Sim.GameSession.New(bridge.Content, Statecraft.Sim.GoldenRun.Seed, Statecraft.Sim.Mode.Historical);+ g.State.PendingEvents.Clear();+ g.State.Settlements["ramla"] = new Statecraft.Sim.SettlementControl(Statecraft.Sim.Movement.PlayerSide,+ Statecraft.Sim.SettlementControl.AwaitingChoice, g.State.Date);+ bridge.Replace(g);+ for (int i = 0; i < 5; i++) yield return null;+ Assert.IsTrue(ui.Q("root").ClassListContains(CaptureDialogPresenter.OpenClass), "precondition: Ramla's capture dialog is open");+ Assert.IsFalse(ui.Q("info-panel").enabledInHierarchy, "precondition: the open dialog disables the unit card");+ var needs = bridge.NeedsOrders.Count;+ Assert.Greater(needs, 0, "precondition: units need orders");+ UiTestKit.Press(ui.Q<Button>("end-turn"));+ yield return null;+ Assert.IsTrue(ui.Q("info-panel").enabledInHierarchy, "the selected unit's card takes orders");+ UiTestKit.Press(ui.Q<Button>("info-skip"));+ yield return null;+ Assert.AreEqual(needs - 1, bridge.NeedsOrders.Count, "Skip took the selected unit out of the cycle");+ Assert.AreEqual("ramla", root.Capture!.Shown, "nothing was chosen: the capture still waits, behind Decision waiting");+ }[UnityTest]public IEnumerator BlockedEndTurnClosesDefenceAndShowsTheUnit() =>BlockedEndTurnRevealsTheUnit("defence", twoRows: false);