Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

ui: camera keys never move HUD focus; Cabinet heading, toast and caption fixes (#175)

Eyal Golan16c9573fee01
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 44729acb0..cead89e1e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -68,3 +68,10 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
- The browser build downloads a smaller heightmap: `heightmap.r16z` (4.1 MB, packed losslessly: row deltas in byte
planes, one zlib stream) replaces the raw 8.4 MB `heightmap.r16`, which was served outside Unity's build compression.
It decodes to the same bytes, so the terrain is unchanged (#44).
+
+### Fixed
+- The camera keys (WASD and the arrows) no longer move keyboard focus through the HUD. Before, panning could walk focus
+ onto New Game or End Turn, so a stray Enter or Space could press it. Tab still moves focus.
+- The Cabinet's "Appoint to …" heading has its own column again and stays clear of the portrait grid's scroll bar.
+- The "Not done" toast is opaque and sits clear of the open screen.
+- "International Standing" keeps to one line on a full-width bar.
diff --git a/unity/Assets/InputSystem_Actions.inputactions b/unity/Assets/InputSystem_Actions.inputactions
index 50e6cb854..5287270ff 100644
--- a/unity/Assets/InputSystem_Actions.inputactions
+++ b/unity/Assets/InputSystem_Actions.inputactions
@@ -736,105 +736,6 @@
"isComposite": false,
"isPartOfComposite": true
},
- {
- "name": "Keyboard",
- "id": "ff527021-f211-4c02-933e-5976594c46ed",
- "path": "2DVector",
- "interactions": "",
- "processors": "",
- "groups": "",
- "action": "Navigate",
- "isComposite": true,
- "isPartOfComposite": false
- },
- {
- "name": "up",
- "id": "563fbfdd-0f09-408d-aa75-8642c4f08ef0",
- "path": "<Keyboard>/w",
- "interactions": "",
- "processors": "",
- "groups": "Keyboard&Mouse",
- "action": "Navigate",
- "isComposite": false,
- "isPartOfComposite": true
- },
- {
- "name": "up",
- "id": "eb480147-c587-4a33-85ed-eb0ab9942c43",
- "path": "<Keyboard>/upArrow",
- "interactions": "",
- "processors": "",
- "groups": "Keyboard&Mouse",
- "action": "Navigate",
- "isComposite": false,
- "isPartOfComposite": true
- },
- {
- "name": "down",
- "id": "2bf42165-60bc-42ca-8072-8c13ab40239b",
- "path": "<Keyboard>/s",
- "interactions": "",
- "processors": "",
- "groups": "Keyboard&Mouse",
- "action": "Navigate",
- "isComposite": false,
- "isPartOfComposite": true
- },
- {
- "name": "down",
- "id": "85d264ad-e0a0-4565-b7ff-1a37edde51ac",
- "path": "<Keyboard>/downArrow",
- "interactions": "",
- "processors": "",
- "groups": "Keyboard&Mouse",
- "action": "Navigate",
- "isComposite": false,
- "isPartOfComposite": true
- },
- {
- "name": "left",
- "id": "74214943-c580-44e4-98eb-ad7eebe17902",
- "path": "<Keyboard>/a",
- "interactions": "",
- "processors": "",
- "groups": "Keyboard&Mouse",
- "action": "Navigate",
- "isComposite": false,
- "isPartOfComposite": true
- },
- {
- "name": "left",
- "id": "cea9b045-a000-445b-95b8-0c171af70a3b",
- "path": "<Keyboard>/leftArrow",
- "interactions": "",
- "processors": "",
- "groups": "Keyboard&Mouse",
- "action": "Navigate",
- "isComposite": false,
- "isPartOfComposite": true
- },
- {
- "name": "right",
- "id": "8607c725-d935-4808-84b1-8354e29bab63",
- "path": "<Keyboard>/d",
- "interactions": "",
- "processors": "",
- "groups": "Keyboard&Mouse",
- "action": "Navigate",
- "isComposite": false,
- "isPartOfComposite": true
- },
- {
- "name": "right",
- "id": "4cda81dc-9edd-4e03-9d7c-a71a14345d0b",
- "path": "<Keyboard>/rightArrow",
- "interactions": "",
- "processors": "",
- "groups": "Keyboard&Mouse",
- "action": "Navigate",
- "isComposite": false,
- "isPartOfComposite": true
- },
{
"name": "",
"id": "9e92bb26-7e3b-4ec4-b06b-3c8f8e498ddc",
diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.cs
index 7bf046f89..e6fcf2765 100644
--- a/unity/Assets/Scripts/UI/GameRoot.cs
+++ b/unity/Assets/Scripts/UI/GameRoot.cs
@@ -133,6 +133,7 @@ namespace Statecraft.Game.UI
Own(new HudPresenter(root, bridge, text));
Own(new ScreenNav(root)); // every screen starts hidden (USS); ScreenNav opens one at a time
Own(new PointerBlur(root)); // a mouse click leaves no focus fill behind (keyboard keeps it)
+ Own(new NavigationGuard(root)); // the camera keys (WASD, arrows) never move UI focus (B6)
if (DiagLog.Nav) Own(new NavEventLog(root)); // ?navlog: every UI pointer/submit event (playtest 2, P2-4)
var card = Own(new EventCardPresenter(root, bridge, text, portraits));
Own(new DefencePresenter(root, bridge, text));
diff --git a/unity/Assets/Scripts/UI/HudPresenter.cs b/unity/Assets/Scripts/UI/HudPresenter.cs
index cb11248a7..378813d21 100644
--- a/unity/Assets/Scripts/UI/HudPresenter.cs
+++ b/unity/Assets/Scripts/UI/HudPresenter.cs
@@ -42,8 +42,9 @@ namespace Statecraft.Game.UI
/// editor's; PromoHudTests.EveryWindowShapeFitsTheBarAfterATurn asserts it).</summary>
public const float SpareShare = 0.05f;
- /// <summary>The meters' predicted growth when roomy: six icons 30 -> 38 px, values 22 -> 25 px (about 14% wider).</summary>
- public static float RoomyGrowth(float valueWidths) => 6 * 8f + 0.14f * valueWidths;
+ /// <summary>The meters' predicted growth when roomy: six icons 30 -> 38 px, values 22 -> 25 px (about 14% wider), and
+ /// each wrapped caption back to its one-line width (<paramref name="captionGrowth"/>).</summary>
+ public static float RoomyGrowth(float valueWidths, float captionGrowth = 0f) => 6 * 8f + 0.14f * valueWidths + captionGrowth;
public HudPresenter(VisualElement root, SimBridge bridge, UiText text)
{
@@ -94,7 +95,14 @@ namespace Statecraft.Game.UI
else
{
var values = meters.Sum(m => m.Q<Label>(className: "meter-value")?.worldBound.width ?? 0f);
- if (spare - RoomyGrowth(values) >= SpareShare * used + 8f) bar.AddToClassList(RoomyClass);
+ var captions = meters.Sum(m =>
+ {
+ var c = m.Q<Label>(className: "meter-name");
+ if (c == null || string.IsNullOrEmpty(c.text)) return 0f;
+ var oneLine = c.MeasureTextSize(c.text, 0, VisualElement.MeasureMode.Undefined, 0, VisualElement.MeasureMode.Undefined).x;
+ return UnityEngine.Mathf.Max(0f, oneLine - c.worldBound.width);
+ });
+ if (spare - RoomyGrowth(values, captions) >= SpareShare * used + 8f) bar.AddToClassList(RoomyClass);
}
}
diff --git a/unity/Assets/Scripts/UI/NavigationGuard.cs b/unity/Assets/Scripts/UI/NavigationGuard.cs
new file mode 100644
index 000000000..3c433a9dd
--- /dev/null
+++ b/unity/Assets/Scripts/UI/NavigationGuard.cs
@@ -0,0 +1,26 @@
+#nullable enable
+using UnityEngine.UIElements;
+
+namespace Statecraft.Game.UI
+{
+ /// <summary>Keeps the camera keys off the UI (integration bug B6). The project's UI action map, which UI Toolkit reads for
+ /// navigation, no longer binds WASD or the arrows (they pan the camera); this guard also drops any directional
+ /// NavigationMoveEvent (up, down, left, right) at the root before it can move focus, whatever device sent it, so panning
+ /// the map never walks focus along the HUD and never lands it on New Game or End Turn. Tab and Shift+Tab (Next and
+ /// Previous) still move focus, so the HUD stays keyboard-reachable; Enter and Space still press the focused button.</summary>
+ public sealed class NavigationGuard : System.IDisposable
+ {
+ readonly VisualElement root;
+
+ static readonly EventCallback<NavigationMoveEvent> OnMove = e =>
+ {
+ if (e.direction == NavigationMoveEvent.Direction.Next || e.direction == NavigationMoveEvent.Direction.Previous) return;
+ (e.target as VisualElement)?.focusController?.IgnoreEvent(e);
+ e.StopImmediatePropagation();
+ };
+
+ public NavigationGuard(VisualElement root) { this.root = root; root.RegisterCallback(OnMove, TrickleDown.TrickleDown); }
+
+ public void Dispose() => root.UnregisterCallback(OnMove, TrickleDown.TrickleDown);
+ }
+}
diff --git a/unity/Assets/Scripts/UI/NavigationGuard.cs.meta b/unity/Assets/Scripts/UI/NavigationGuard.cs.meta
new file mode 100644
index 000000000..711267e54
--- /dev/null
+++ b/unity/Assets/Scripts/UI/NavigationGuard.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 297843c649e2a4059a6e36cdc859961f
\ No newline at end of file
diff --git a/unity/Assets/Tests/EditMode/PromoHudTests.cs b/unity/Assets/Tests/EditMode/PromoHudTests.cs
index 43f04ebe2..f0b661472 100644
--- a/unity/Assets/Tests/EditMode/PromoHudTests.cs
+++ b/unity/Assets/Tests/EditMode/PromoHudTests.cs
@@ -173,6 +173,9 @@ public class PromoHudTests
Assert.GreaterOrEqual(icon.worldBound.width, 36f, $"1920x1080: the {icon.Glyph} icon is promo-sized");
foreach (var v in root.Q("meters").Query<Label>(className: "meter-value").ToList())
Assert.GreaterOrEqual(v.resolvedStyle.fontSize, 24f, $"1920x1080: '{v.text}' is promo-sized");
+ // Integration bug B8: on the roomy bar every caption keeps one line, as in the promo.
+ foreach (var c in root.Q("meters").Query<Label>(className: "meter-name").ToList().Where(c => c.name != "security-level"))
+ Assert.Less(c.worldBound.height, c.resolvedStyle.fontSize * 2f, $"1920x1080: '{c.text}' wraps");
}
// The widest realistic changes, formatted as HudModel formats them, and the widest date line.
foreach (var (name, delta) in new[] { ("treasury", PlayerText.MoneyChange(C, "treasury", -12.4)), ("immigration", Text.Format("hud.delta_people", 12345.0)),
@@ -402,4 +405,122 @@ public class PromoHudTests
}
finally { Object.DestroyImmediate(go); Object.DestroyImmediate(ps); rt.Release(); Object.DestroyImmediate(rt); }
}
+
+ /// <summary>Integration bug B6: the camera keys never move UI focus or press a button. The UI action map binds no
+ /// keyboard keys to Navigate, and NavigationGuard drops every directional move at the root, so with focus on a HUD button
+ /// the WASD/arrow moves (and the W/A/S/D key presses) leave focus where it is, press nothing and never arm New Game.
+ /// Tab (Next) still moves focus, so the HUD stays keyboard-reachable.</summary>
+ [UnityTest]
+ public IEnumerator CameraKeysNeverMoveFocusOrPressAButton()
+ {
+ // The input asset: no keyboard binding on the UI map's Navigate action.
+ var actions = AssetDatabase.LoadAssetAtPath<UnityEngine.InputSystem.InputActionAsset>("Assets/InputSystem_Actions.inputactions");
+ Assert.IsNotNull(actions);
+ foreach (var b in actions.FindActionMap("UI", true).FindAction("Navigate", true).bindings)
+ StringAssert.DoesNotStartWith("<Keyboard>", b.path, "Navigate must not read a camera key");
+
+ using var ui = new UiTestKit();
+ var dir = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "statecraft-b6-" + System.Guid.NewGuid().ToString("N"));
+ var bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), Text);
+ var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
+ while (!g.State.PendingEvents.Contains("armistice_egypt")) g.Step(new Command[0]);
+ bridge.Replace(g);
+ var toast = new ToastPresenter(ui.Root, bridge, Text);
+ var newGame = new NewGamePresenter(ui.Root, bridge, new SaveStore(dir), toast, Text, () => 4UL);
+ var card = new EventCardPresenter(ui.Root, bridge, Text, null);
+ var guard = new NavigationGuard(ui.Root);
+ ui.Q<VisualElement>("root").RemoveFromClassList("loading");
+ var presses = 0;
+ var buttons = ui.Root.Query<Button>().ToList();
+ System.Action count = () => presses++;
+ foreach (var b in buttons) b.clicked += count;
+ try
+ {
+ foreach (var name in new[] { "nav-cabinet", "new-game", "end-turn", "option-sign" })
+ {
+ var start = ui.Q<Button>(name);
+ start.Focus();
+ for (int i = 0; i < 10 && start.focusController.focusedElement != start; i++) yield return null;
+ Assert.AreSame(start, start.focusController.focusedElement, name + ": precondition, focused");
+ foreach (var d in new[] { NavigationMoveEvent.Direction.Right, NavigationMoveEvent.Direction.Left,
+ NavigationMoveEvent.Direction.Up, NavigationMoveEvent.Direction.Down })
+ {
+ using (var e = NavigationMoveEvent.GetPooled(d)) { e.target = start; start.SendEvent(e); }
+ yield return null;
+ Assert.AreSame(start, start.focusController.focusedElement, $"{name}: a {d} move left focus where it was");
+ }
+ foreach (var key in new[] { KeyCode.W, KeyCode.A, KeyCode.S, KeyCode.D, KeyCode.UpArrow, KeyCode.DownArrow, KeyCode.LeftArrow, KeyCode.RightArrow, KeyCode.Q, KeyCode.E })
+ {
+ using (var e = KeyDownEvent.GetPooled((char)0, key, EventModifiers.None)) { e.target = start; start.SendEvent(e); }
+ yield return null;
+ Assert.AreSame(start, start.focusController.focusedElement, $"{name}: {key} left focus where it was");
+ }
+ Assert.AreEqual(0, presses, name + ": the camera keys pressed no button");
+ Assert.IsFalse(newGame.Armed, name + ": New Game is not armed");
+ }
+ // Tab still moves focus: the HUD stays reachable from the keyboard.
+ var from = ui.Q<Button>("nav-cabinet");
+ from.Focus();
+ for (int i = 0; i < 10 && from.focusController.focusedElement != from; i++) yield return null;
+ using (var e = NavigationMoveEvent.GetPooled(NavigationMoveEvent.Direction.Next)) { e.target = from; from.SendEvent(e); }
+ yield return null;
+ Assert.AreNotSame(from, from.focusController.focusedElement, "Tab moves focus on");
+ Assert.AreEqual(0, presses, "Tab pressed no button");
+ }
+ finally
+ {
+ foreach (var b in buttons) b.clicked -= count;
+ guard.Dispose(); card.Dispose(); newGame.Dispose(); toast.Dispose();
+ if (System.IO.Directory.Exists(dir)) System.IO.Directory.Delete(dir, true);
+ }
+ }
+
+ /// <summary>Integration bug B7: the toast is opaque and never covers an open screen or the event column.</summary>
+ [UnityTest]
+ public IEnumerator TheToastIsOpaqueAndClearOfTheScreens()
+ {
+ using var ui = new UiTestKit();
+ var nav = new ScreenNav(ui.Root);
+ ui.Q<VisualElement>("root").RemoveFromClassList("loading");
+ var toast = ui.Q<Label>("toast");
+ toast.text = "Not done: Not enough attention (need 4.0, have 2.0)";
+ toast.style.display = DisplayStyle.Flex;
+ try
+ {
+ foreach (var s in ScreenNav.Screens)
+ {
+ nav.Open(s);
+ for (int i = 0; i < 3; i++) yield return null;
+ Assert.AreEqual(1f, toast.resolvedStyle.backgroundColor.a, 1e-3f, "opaque");
+ Assert.IsFalse(toast.worldBound.Overlaps(ui.Q<VisualElement>("screen-" + s).worldBound), $"the toast {toast.worldBound} covers {s}");
+ Assert.IsFalse(toast.worldBound.Overlaps(ui.Q<VisualElement>("right-column").worldBound), "the toast covers the event column");
+ Assert.GreaterOrEqual(toast.worldBound.yMin, ui.Q<VisualElement>("top-bar").worldBound.yMax, "the toast starts under the bar");
+ }
+ }
+ finally { nav.Dispose(); }
+ }
+
+ /// <summary>Integration bug B5: in the Cabinet the "Appoint to ..." heading has its own column, clear of the portrait
+ /// grid and its scroll bar, and does not wrap a word to a line.</summary>
+ [UnityTest]
+ public IEnumerator TheAppointHeadingHasRoom()
+ {
+ using var ui = new UiTestKit();
+ var bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), Text);
+ var nav = new ScreenNav(ui.Root);
+ var cabinet = new CabinetPresenter(ui.Root, bridge, Text, null);
+ ui.Q<VisualElement>("root").RemoveFromClassList("loading");
+ try
+ {
+ nav.Open("cabinet");
+ cabinet.Select("health_minister");
+ for (int i = 0; i < 5; i++) yield return null;
+ var title = ui.Q<Label>("cabinet-pick-title");
+ StringAssert.StartsWith("Appoint to ", title.text);
+ var seats = ui.Q<ScrollView>("cabinet-seats").worldBound;
+ Assert.GreaterOrEqual(title.worldBound.xMin, seats.xMax, $"the heading {title.worldBound} starts inside the portrait grid {seats}");
+ Assert.LessOrEqual(title.worldBound.height, title.resolvedStyle.fontSize * 2.2f, $"'{title.text}' wraps to more than one line ({title.worldBound.height:0} px)");
+ }
+ finally { cabinet.Dispose(); nav.Dispose(); }
+ }
}
diff --git a/unity/Assets/UI/Statecraft.uss b/unity/Assets/UI/Statecraft.uss
index 8c6c7d0dc..4ccb2214f 100644
--- a/unity/Assets/UI/Statecraft.uss
+++ b/unity/Assets/UI/Statecraft.uss
@@ -98,7 +98,10 @@ Button:disabled { color: var(--ink-dim); border-color: rgba(120, 120, 120, 0.4);
.top-bar--roomy .meter-icon { width: 38px; height: 38px; margin-right: 7px; }
.top-bar--roomy .meter-value { font-size: 25px; }
.meter-body { flex-shrink: 1; flex-grow: 1; min-width: 0; }
-.meter-name { font-size: 16px; color: var(--ink); white-space: normal; max-width: 120px; } /* a long caption wraps rather than widen its meter */
+.meter-name { font-size: 16px; color: var(--ink); white-space: normal; }
+/* In the bar a long caption wraps rather than widen its meter; on the roomy bar it keeps one line, as in the promo (B8). */
+.meter .meter-name { max-width: 120px; }
+.top-bar--roomy .meter .meter-name { max-width: none; white-space: nowrap; }
#security-level { font-size: 14px; color: var(--ink-dim); }
.meter-row { flex-direction: row; align-items: flex-end; }
.meter-value { font-size: 22px; color: var(--ink); }
@@ -213,7 +216,12 @@ Button:disabled { color: var(--ink-dim); border-color: rgba(120, 120, 120, 0.4);
.screen .row.grow { align-items: stretch; flex-basis: 0; flex-shrink: 1; min-height: 0; }
.screen .row.grow > .grow { min-height: 0; flex-shrink: 1; }
-.toast { display: none; position: absolute; left: 30%; right: 30%; top: 112px; -unity-text-align: middle-center; white-space: normal; border-color: var(--gold); }
+/* The toast sits in the map's free top-left corner, above the info panel: opaque, and never over an open screen's title or
+ the event column (B7). */
+.toast {
+ display: none; position: absolute; left: 16px; width: 520px; top: 112px; -unity-text-align: middle-center; white-space: normal;
+ background-color: var(--navy-solid); border-color: var(--gold); border-width: 1.5px;
+}
/* Scroll bars in the theme: a slim gold thumb on a faint track, no arrow buttons. */
.unity-scroller--vertical { width: 10px; border-width: 0; background-color: rgba(0, 0, 0, 0); margin-left: 4px; }
@@ -225,6 +233,9 @@ Button:disabled { color: var(--ink-dim); border-color: rgba(120, 120, 120, 0.4);
.why-group { -unity-font-definition: url("project://database/Assets/UI/Fonts/EBGaramond-SemiBold.ttf"); color: var(--gold); letter-spacing: 1px; margin-top: 10px; border-bottom-width: 1px; border-color: rgba(196, 160, 92, 0.25); }
.why-line { white-space: normal; padding-left: 12px; }
+/* The candidate column (B5): a fixed share beside the portrait grid, clear of the grid's scroll bar, its heading on one line. */
+#cabinet-pick { flex-grow: 0; flex-shrink: 0; width: 42%; margin-left: 14px; }
+#cabinet-pick-title { white-space: normal; }
/* The Cabinet as the promo's portrait cards (promo/final/04): the lineup wraps into a grid of cards, each a gold-framed
portrait over the office and its holder; a long lineup scrolls. */
#cabinet-seats .unity-scroll-view__content-container { flex-direction: row; flex-wrap: wrap; }