A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Accessibility: a language switch keeps the map selection (Refs #2340) (#2922)
Berif87e54b8c0f7
diff --git a/changelog.d/2340-language-switch-selection.md b/changelog.d/2340-language-switch-selection.mdnew file mode 100644index 000000000..c22a91935--- /dev/null+++ b/changelog.d/2340-language-switch-selection.md@@ -0,0 +1,5 @@+### Fixed++- Switching the language keeps what was selected on the map: the hex with its outline, the unit with its card, or a+ pioneer group's card. Before, the rebuilt info panel showed nothing while the old hex outline stayed on the map+ (Refs #2340).diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex 2f80a7414..cfa1fc807 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -844,9 +844,26 @@ namespace Statecraft.Game.UIbool fromStart = start?.IsOpen == true;keptResumed = start?.Resumed ?? true;keptBudgetDraft = budgetScreen?.Draft; // read before Begin disposes it; the new screen copies it+ // #2340: the selection, read before Begin disposes the panel and the unit layer (a pioneer card has no token).+ var pioneer = info?.Pioneer;+ var unit = info?.ShowsUnit == true ? units?.Selected : null;+ var hex = info?.ShowsUnit == true ? null : info?.Selected;// Cleared even if Begin throws, so the next ordinary Begin (a New game, a load) never picks it up.try { Begin(inputs, 0, startScreen: fromStart, keep: Bridge); }finally { keptBudgetDraft = null; }+ // Put back before Settings opens again: a screen that covers the panel would ignore it. The map's hex outline+ // outlives Begin, so it is set to match (before, the new panel showed nothing under the old outline).+ if (info != null && units != null)+ {+ if (pioneer is int pioneerId) info.ShowPioneer(pioneerId); // clears the token and the outline itself+ else+ {+ units.Select(unit);+ if (units.Selected != null) { map.ClearSelection(); info.ShowUnit(); }+ else if (hex is (int q, int r)) { map.Select(q, r); info.Show(q, r); }+ else map.ClearSelection();+ }+ }if (!fromStart) nav?.Open("settings");// Focus the choice again a frame later: a screen shown this same tick cannot take the focus until its// styles resolve, and a bare Focus() then leaves it wherever it was (#1915's tour test read end-turn).diff --git a/unity/Assets/Tests/EditMode/HebrewUiTests.cs b/unity/Assets/Tests/EditMode/HebrewUiTests.csindex 788448cd7..68c518154 100644--- a/unity/Assets/Tests/EditMode/HebrewUiTests.cs+++ b/unity/Assets/Tests/EditMode/HebrewUiTests.cs@@ -318,6 +318,66 @@ public class HebrewUiTestsCollectionAssert.DoesNotContain(game.Bridge.NeedsOrders.ToList(), skipped);}+ /// <summary>#2340: the language switch rebuilds the info panel and the unit layer, and the player's selection comes back+ /// with them: a hex with its outline, a unit with its card and no hex outline, a pioneer group's card. Before, the new+ /// panel showed nothing while the old hex outline stayed on the map. Both ways, English to Hebrew and back.</summary>+ [Test]+ public void TheLanguageSwitchKeepsTheSelection()+ {+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);+ var map = Object.FindFirstObjectByType<MapScene>();+ map.Build(Inputs.Map);+ var game = Object.FindFirstObjectByType<GameRoot>();+ game.Store = new SaveStore(saveDir);+ game.Settings = new SettingsStore(Path.Combine(saveDir, "settings"));+ game.Begin(Inputs, 0);+ // The opening cards answered, not hidden: an open card disables the info panel, and the rebuild opens a hidden card+ // again (the other half of that #2340 item), so no pioneer card could be shown over it.+ for (int i = 0; i < 5 && game.Card!.Shown != null; i++) UiTestKit.Press(Ui.Q("event-options").Query<Button>().First());+ Assert.IsNull(game.Card!.Shown, "precondition: no card over the info panel");+ var bridge = game.Bridge!;+ bool Outlined() => map.Terrain.transform.Find(MapScene.SelectionName) is Transform t && t.GetComponent<MeshRenderer>().enabled;+ var hex = bridge.Content.Hexes.First(h => h.Land && game.Units!.UnitToSelectAt(h.Q, h.R) == null+ && !bridge.Content.SettlementHexes.Any(x => x.Q == h.Q && x.R == h.R) && !bridge.Content.Sites.Any(x => x.Q == h.Q && x.R == h.R));+ var unit = game.Units!.Tokens.First(t => t.Token.Unit.Side == Statecraft.Game.Map.Units.UnitData.Israel).Token.Unit.Id;+ var pioneer = PioneerCardTests.Add(bridge.State, hex.Q, hex.R);+ string language = UiLanguage.English;+ void Switch()+ {+ language = language == UiLanguage.English ? UiLanguage.Hebrew : UiLanguage.English;+ UiTestKit.Press(Ui.Q<Button>("nav-settings"));+ UiTestKit.Press(Ui.Q<Button>("settings-language-" + language));+ Assert.AreEqual(language == UiLanguage.Hebrew, Ui.Q("root").ClassListContains(UiLanguage.HebrewClass), "precondition: the UI was rebuilt");+ if (Ui.Q("root").ClassListContains(ScreenNav.ScreenOpenClass)) UiTestKit.Press(Ui.Q<Button>("nav-settings"));+ }++ for (int round = 0; round < 2; round++) // to Hebrew, then back to English+ {+ GameRoot.OnHexClicked(map, game.Units!, game.Info!, hex.Q, hex.R);+ Assert.AreEqual((hex.Q, hex.R), game.Info!.Selected, "precondition: the hex is selected");+ Switch();+ Assert.AreEqual((hex.Q, hex.R), game.Info!.Selected, language + ": the hex is still selected");+ Assert.IsFalse(game.Info.ShowsUnit, language + ": as a hex");+ Assert.IsTrue(Outlined(), language + ": with its outline");++ game.FocusUnit(unit);+ Assert.AreEqual(unit, game.Units!.Selected, "precondition: the unit is selected");+ Switch();+ Assert.AreEqual(unit, game.Units!.Selected, language + ": the unit is still selected");+ Assert.IsTrue(game.Info!.ShowsUnit, language + ": its card is shown");+ Assert.IsNull(game.Info.Pioneer, language + ": the unit's card, not a pioneer's");+ Assert.IsFalse(Outlined(), language + ": and no hex outline");++ game.Info.Show(hex.Q, hex.R);+ UiTestKit.Press(PioneerCardTests.Link(Ui, pioneer));+ Assert.AreEqual(pioneer, game.Info.Pioneer, "precondition: the pioneer group's card");+ Switch();+ Assert.AreEqual(pioneer, game.Info!.Pioneer, language + ": the pioneer group's card is still shown");+ Assert.IsNull(game.Units!.Selected, language + ": with no unit token selected");+ Assert.IsFalse(Outlined(), language + ": and no hex outline");+ }+ }+/// <summary>#2708: the language switch rebuilds the Budget screen over the same game, and the new screen keeps the/// player's unsubmitted draft (and says it is unsubmitted) instead of starting again from the submitted budget.</summary>[Test]