A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Screens: each close button keeps its X and gets a localized "Close <screen>" tooltip (Fixes #2566) (#2577)
Eyal Golan51a345aa3536
diff --git a/changelog.d/2566-close-button-label.md b/changelog.d/2566-close-button-label.mdnew file mode 100644index 000000000..8a69c4da0--- /dev/null+++ b/changelog.d/2566-close-button-label.md@@ -0,0 +1,3 @@+### Fixed++- Every screen's close button keeps its visible X and now has a localized tooltip naming the screen (#2566).diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex cdc978cbb..d74eb18e2 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -304,7 +304,7 @@ namespace Statecraft.Game.UIvar toast = Own(new ToastPresenter(root, bridge, text));unseenSkipped = () => toast.Show(text["toast.unit_unseen_skipped"]);var hudPresenter = Own(new HudPresenter(root, bridge, text, selectUnit: _ => FocusNextUnit()));- nav = Own(new ScreenNav(root)); // every screen starts hidden (USS); ScreenNav opens one at a time+ nav = Own(new ScreenNav(root, text)); // every screen starts hidden (USS); ScreenNav opens one at a timeOwn(new PointerBlur(root)); // a mouse click leaves no focus fill behind (keyboard keeps it)Own(new FocusScroll(root)); // keyboard focus scrolls its ScrollView to it (a11y H1)FocusScroll.NoScrollBarIsATabStop(root); // no scroll bar takes a Tab stop (#41 K3, widened from the Cabinet's two)diff --git a/unity/Assets/Scripts/UI/ScreenNav.cs b/unity/Assets/Scripts/UI/ScreenNav.csindex 91dd44aa5..4afdc0074 100644--- a/unity/Assets/Scripts/UI/ScreenNav.cs+++ b/unity/Assets/Scripts/UI/ScreenNav.cs@@ -179,6 +179,7 @@ namespace Statecraft.Game.UIreadonly VisualElement root;readonly List<(Button, System.Action)> hooks = new List<(Button, System.Action)>();readonly List<Button> closes = new List<Button>();+ readonly HoverTip? closeTips;readonly EventCallback<NavigationCancelEvent> onCancel;readonly EventCallback<GeometryChangedEvent> onGeometry;readonly PressSource presses;@@ -187,7 +188,9 @@ namespace Statecraft.Game.UI/// key, and the open screen under it stays open. This handler trickles down from the root, so it runs before the layer's own.</summary>public System.Func<bool>? TakesEscape;- public ScreenNav(VisualElement root)+ public ScreenNav(VisualElement root) : this(root, null) { }++ public ScreenNav(VisualElement root, UiText? text){this.root = root;// Escape (the UI map's Cancel, from any focused element or the panel) closes the open screen. NavigationGuard@@ -212,11 +215,24 @@ namespace Statecraft.Game.UI// light up and show its tip (#1323).var header = root.Q("screen-" + screen)?.Q(className: "screen-header");if (header == null) continue;- var x = new Button(() => Close(handFocus: presses.ByKeyboard)) { name = "screen-close-" + screen, text = "X" };+ var x = new Button(() => Close(handFocus: presses.ByKeyboard))+ {+ name = "screen-close-" + screen,+ text = "X",+ // HudPresenter has already localized the rail button. Keep the visible X, but give the icon button+ // the screen-specific name HoverTip and the Web companion read (#2566).+ tooltip = text == null ? b.text : text.Format("screen.close", b.text),+ };x.AddToClassList("screen-close");header.Add(x);closes.Add(x);}+ if (closes.Count > 0 && root.Q<Label>(HoverTip.TipName) != null)+ {+ var uiRoot = root.Q("root") ?? root;+ closeTips = new HoverTip(root, closes,+ () => uiRoot.ClassListContains(UiLanguage.HebrewClass) ? HoverTip.Side.Right : HoverTip.Side.Left);+ }Open(null);FitCloseButtons();}@@ -264,6 +280,7 @@ namespace Statecraft.Game.UI{foreach (var (b, h) in hooks) b.clicked -= h;hooks.Clear();+ closeTips?.Dispose();foreach (var x in closes) x.RemoveFromHierarchy();closes.Clear();root.UnregisterCallback(onCancel, TrickleDown.TrickleDown);diff --git a/unity/Assets/Tests/EditMode/UiFoundationTests.cs b/unity/Assets/Tests/EditMode/UiFoundationTests.csindex 799bb75a9..0bd4ffd2b 100644--- a/unity/Assets/Tests/EditMode/UiFoundationTests.cs+++ b/unity/Assets/Tests/EditMode/UiFoundationTests.cs@@ -40,6 +40,43 @@ public class UiFoundationTests}}+ /// <summary>#2566: the visible X is not the close button's only name. Static red-first: on main every tooltip is+ /// empty, so the first English assertion (Cabinet) fails.</summary>+ [Test]+ public void EveryScreenCloseButtonHasItsLocalizedNameInEnglishAndHebrew()+ {+ var keys = new[] { "hud.nav.cabinet", "hud.nav.budget", "hud.nav.defence", "hud.nav.why", "nav.timeline",+ "hud.nav.encyclopedia", "hud.nav.objectives", "hud.nav.settings" };+ var expected = new[]+ {+ new[] { "Close Cabinet", "Close Budget", "Close Defence", "Close Why?", "Close Timeline",+ "Close Encyclopedia", "Close Objectives", "Close Settings" },+ new[] { "סגירה: ממשלה", "סגירה: תקציב", "סגירה: ביטחון", "סגירה: למה?", "סגירה: ציר הזמן",+ "סגירה: אנציקלופדיה", "סגירה: יעדים", "סגירה: הגדרות" },+ };+ for (int language = 0; language < expected.Length; language++)+ {+ var path = language == 0 ? UiPaths.Strings : UiPaths.StringsHebrew;+ var text = UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(path).text,+ language == 0 ? "strings.en.yaml" : "strings.he.yaml");+ using var ui = new UiTestKit();+ for (int i = 0; i < ScreenNav.Screens.Length; i++)+ ui.Q<Button>("nav-" + ScreenNav.Screens[i]).text = text[keys[i]];+ // Reflection keeps this red-first test source-compatible with main, where the UiText overload is absent:+ // it falls back to main's one-argument constructor and reaches the tooltip assertion below.+ var localized = typeof(ScreenNav).GetConstructor(new[] { typeof(VisualElement), typeof(UiText) });+ using var nav = localized == null ? new ScreenNav(ui.Root)+ : (ScreenNav)localized.Invoke(new object[] { ui.Root, text });++ for (int i = 0; i < ScreenNav.Screens.Length; i++)+ {+ var tooltip = ui.Q<Button>("screen-close-" + ScreenNav.Screens[i]).tooltip;+ Assert.AreEqual(expected[language][i], tooltip, $"{path}: {ScreenNav.Screens[i]}");+ Assert.AreNotEqual("X", tooltip, $"{path}: {ScreenNav.Screens[i]} is named, not just its glyph");+ }+ }+ }+/// <summary>#1035's ruling: the X's hit area is 44 screen px at every window size, so in panel units it grows as/// the panel shrinks. On the web a screen pixel is a CSS pixel, so the device-pixel ratio multiplies the target/// (44 device px was about 15 CSS px on a DPR-3 phone; the ruling's own phone figure is in CSS px).</summary>diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yamlindex 1269868e8..ed359baa9 100644--- a/unity/Assets/UI/strings.en.yaml+++ b/unity/Assets/UI/strings.en.yaml@@ -61,6 +61,8 @@ hud.nav.why: "Why?"hud.nav.encyclopedia: "Encyclopedia"hud.nav.objectives: "Objectives"hud.nav.settings: "Settings"+# An icon-only screen-header button: {0} is that screen's localized rail name (#2566).+screen.close: "Close {0}"hud.new_game: "New game"hud.end_turn: "End turn"hud.end_turn_needs_orders: "A unit needs orders"diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yamlindex d432eaa84..977c525dc 100644--- a/unity/Assets/UI/strings.he.yaml+++ b/unity/Assets/UI/strings.he.yaml@@ -58,6 +58,9 @@ hud.nav.encyclopedia: "אנציקלופדיה"hud.nav.objectives: "יעדים"# For the native reviewer (#564)hud.nav.settings: "הגדרות"+# An icon-only screen-header button: {0} is that screen's localized rail name (#2566). Agent-composed from the existing+# report.close and rail-name translations; for the native reviewer (#564).+screen.close: "סגירה: {0}"hud.new_game: "משחק חדש"hud.end_turn: "סיום התור"# Civ movement U4: agent-drafted Hebrew; native review: owner, 3 Nov 2026 (HE batch 1: "All fine as they are").