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.

Accessibility: Up and Down move between an open screen's rows (L4, Fixes #2495) (#2549)

Berib5b34e2140ba
diff --git a/changelog.d/2495-screen-rows-arrows.md b/changelog.d/2495-screen-rows-arrows.md
new file mode 100644
index 000000000..6e4003ff2
--- /dev/null
+++ b/changelog.d/2495-screen-rows-arrows.md
@@ -0,0 +1,5 @@
+### Changed
+- While a screen is open, the Up and Down arrows move the keyboard focus between its rows, so a long list such as the
+ Budget or the Cabinet's candidates is no longer Tab-only (#2495, accessibility audit L4). Hidden and disabled controls
+ are skipped, the focus stays in the screen, and moving presses nothing. Left and Right still pan the map, and with no
+ screen open all four arrows pan it as before.
diff --git a/unity/Assets/Scripts/Map/CameraController.cs b/unity/Assets/Scripts/Map/CameraController.cs
index 99a06aa4f..a272c3ce2 100644
--- a/unity/Assets/Scripts/Map/CameraController.cs
+++ b/unity/Assets/Scripts/Map/CameraController.cs
@@ -86,6 +86,10 @@ namespace Statecraft.Game.Map
public Func<bool>? HoldsMouseDrag;
/// <summary>The same for a one-finger drag and a tap (MapPointer.TouchTapCandidate).</summary>
public Func<bool>? HoldsTouchDrag;
+ /// <summary>True while a screen is open (GameRoot: ScreenNav.Current), when the Up and Down arrows move between the
+ /// screen's rows (NavigationGuard.Step, accessibility audit L4; the owner's answer on #2340, Q27: "do the recommended
+ /// for all") and do not pan. Left, Right and WASD still pan. Null: the arrows always pan (B6).</summary>
+ public Func<bool>? ScreenTakesUpDown;
/// <summary>The trackpad pinch since the last frame, as the summed NSEvent magnification (positive = the fingers
/// spread). macOS sends a pinch as magnify events, which Unity's player passes to neither the Input System nor the
/// wheel (the owner found zooming did nothing in the macOS player, 27 Oct 2026), so TrackpadPinch.mm collects them
@@ -225,7 +229,9 @@ namespace Statecraft.Game.Map
}
}
var modifier = ModifierHeld(Keyboard.current);
- var input = Gather(pan.ReadValue<Vector2>(), drag, zoomRaw, orbit.ReadValue<float>(), down, pointer, zoomKeys.ReadValue<float>(), modifier);
+ var keyPan = pan.ReadValue<Vector2>();
+ if (ScreenTakesUpDown?.Invoke() == true) keyPan = WithoutUpDownArrows(keyPan, Keyboard.current);
+ var input = Gather(keyPan, drag, zoomRaw, orbit.ReadValue<float>(), down, pointer, zoomKeys.ReadValue<float>(), modifier);
if (down) input.DragFromUi = fromUi; // latched at the actual press, even between camera frames
// Classify and filter the current gesture before draining earlier, already-approved motion.
// A new UI press owns only its own drag; OverUi must still block its wheel/magnify zoom.
@@ -234,6 +240,17 @@ namespace Statecraft.Game.Map
Step(rig, input, ClampDt(dt), Bounds, Ground, GroundTop, FixedNorth);
}
+ /// <summary>The keyboard pan with the Up and Down arrows taken out (ScreenTakesUpDown). The Pan action resolves its two
+ /// composites (WASD, the arrows) to one value, so while Up or Down is held the pan is rebuilt from the other keys:
+ /// across from A, D, Left and Right, along from W and S, a diagonal normalised as the composites do.</summary>
+ internal static Vector2 WithoutUpDownArrows(Vector2 pan, Keyboard? k)
+ {
+ if (k == null || !(k.upArrowKey.isPressed || k.downArrowKey.isPressed)) return pan;
+ var v = new Vector2((k.dKey.isPressed || k.rightArrowKey.isPressed ? 1f : 0f) - (k.aKey.isPressed || k.leftArrowKey.isPressed ? 1f : 0f),
+ (k.wKey.isPressed ? 1f : 0f) - (k.sKey.isPressed ? 1f : 0f));
+ return v.sqrMagnitude > 1f ? v.normalized : v;
+ }
+
/// <summary>Position history scoped to one press. Begin resets even if release/repress happens between
/// camera ticks. Event positions, rather than Mouse/delta, exclude pre-press movement and retain multiple
/// input updates. Completed touch travel is kept separately from the next press (ruling 3's camera half).</summary>
diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.cs
index 599d5577b..d692bb706 100644
--- a/unity/Assets/Scripts/UI/GameRoot.cs
+++ b/unity/Assets/Scripts/UI/GameRoot.cs
@@ -52,6 +52,7 @@ namespace Statecraft.Game.UI
internal MapRegions? Regions { get; private set; }
MapLabelsPresenter? labels;
ScreenNav? nav;
+ NavigationGuard? navGuard;
StartScreenPresenter? start;
OpeningPresenter? opening;
EventCardPresenter? card;
@@ -319,7 +320,7 @@ namespace Statecraft.Game.UI
Own(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)
- Own(new NavigationGuard(root)); // the camera keys (WASD, arrows) never move UI focus (B6)
+ navGuard = Own(new NavigationGuard(root, () => nav?.Current)); // the camera keys never move UI focus (B6), but Up/Down walk an open screen's rows (L4)
if (DiagLog.Nav) Own(new NavEventLog(root)); // ?navlog: every UI pointer/submit event (playtest 2, P2-4)
// The Illustration switch's silent loops (event-videos.yaml, Resources): none in the automated runs (CardVideo.ForcedOff).
var video = CardVideo.ForcedOff() ? null : Own(new CardVideo());
@@ -523,6 +524,9 @@ namespace Statecraft.Game.UI
Func<bool> holdsMouseDrag = () => pointer.RightTapCandidate || pointer.LeftTapCandidate,
holdsTouchDrag = () => pointer.TouchTapCandidate;
cameraController.HoldsMouseDrag = holdsMouseDrag; cameraController.HoldsTouchDrag = holdsTouchDrag;
+ // Audit L4: while a screen is open, the Up and Down arrows are its rows' (NavigationGuard.Step), not the camera's.
+ Func<bool> screenTakesUpDown = () => nav?.Current != null;
+ cameraController.ScreenTakesUpDown = screenTakesUpDown;
Action<int, int, bool> onHex = (q, r, cityPill) =>
{
OnHexClicked(map, unitLayer, info, q, r, UnityEngine.InputSystem.Pointer.current is UnityEngine.InputSystem.Touchscreen, cityPill);
@@ -589,6 +593,7 @@ namespace Statecraft.Game.UI
if (cameraController.IsOverUi == overUi) cameraController.IsOverUi = null;
if (cameraController.HoldsMouseDrag == holdsMouseDrag) cameraController.HoldsMouseDrag = null;
if (cameraController.HoldsTouchDrag == holdsTouchDrag) cameraController.HoldsTouchDrag = null;
+ if (cameraController.ScreenTakesUpDown == screenTakesUpDown) cameraController.ScreenTakesUpDown = null;
if (pointer.Map == map) pointer.Map = null;
cameraController.Bounds = oldBounds;
cameraController.Ground = oldGround; cameraController.GroundTop = oldTop;
@@ -1173,13 +1178,16 @@ namespace Statecraft.Game.UI
}
// PageUp, PageDown, Home and End, with no modifier, scroll the open screen or the open card's text, with or without
// focus (KeyScroll; accessibility audit H3), but not under an End Turn outcome clip, which covers them. The arrows
- // stay with the camera (NavigationGuard, B6).
+ // stay with the camera (NavigationGuard, B6), except that Up and Down move between an open screen's rows (audit L4;
+ // the owner's answer on #2340, Q27: "do the recommended for all"). The UI map reads no keyboard key (B6), so they
+ // arrive here.
var keys = UnityEngine.InputSystem.Keyboard.current;
if (keys != null && outcomes?.Showing == null && report?.IsOpen != true && end?.IsOpen != true && !(keys.ctrlKey.isPressed || keys.altKey.isPressed || keys.shiftKey.isPressed || keys.leftMetaKey.isPressed || keys.rightMetaKey.isPressed))
{
KeyScroll.Key? page = keys.pageUpKey.wasPressedThisFrame ? KeyScroll.Key.PageUp : keys.pageDownKey.wasPressedThisFrame ? KeyScroll.Key.PageDown
: keys.homeKey.wasPressedThisFrame ? KeyScroll.Key.Home : keys.endKey.wasPressedThisFrame ? KeyScroll.Key.End : (KeyScroll.Key?)null;
if (page != null) KeyScroll.Press(document.rootVisualElement, nav?.Current, card?.Shown != null && !card.Collapsed, page.Value);
+ if (keys.upArrowKey.wasPressedThisFrame || keys.downArrowKey.wasPressedThisFrame) navGuard?.Step(keys.upArrowKey.wasPressedThisFrame);
}
SyncMinimap();
if (!logCamera || rig == null || (rig.Distance == loggedDistance && rig.Yaw == loggedYaw)) return;
diff --git a/unity/Assets/Scripts/UI/KeyScroll.cs b/unity/Assets/Scripts/UI/KeyScroll.cs
index 6a4b564fd..eab7afda5 100644
--- a/unity/Assets/Scripts/UI/KeyScroll.cs
+++ b/unity/Assets/Scripts/UI/KeyScroll.cs
@@ -7,8 +7,8 @@ namespace Statecraft.Game.UI
{
/// <summary>PageUp, PageDown, Home and End scroll the open screen, or the open decision card's text, from the keyboard
/// (accessibility audit H3, #41). The Why list, the event text and the Defence body hold labels only, so Tab never
- /// reaches into them, and the arrows pan the camera and never move focus (NavigationGuard, ruling B6). GameRoot polls
- /// the keys beside its Escape poll, so they work with or without focus.</summary>
+ /// reaches into them, and the arrows pan the camera (NavigationGuard, ruling B6; Up and Down reach only an open screen's
+ /// controls, audit L4). GameRoot polls the keys beside its Escape poll, so they work with or without focus.</summary>
public static class KeyScroll
{
public enum Key { PageUp, PageDown, Home, End }
diff --git a/unity/Assets/Scripts/UI/NavigationGuard.cs b/unity/Assets/Scripts/UI/NavigationGuard.cs
index 3c433a9dd..51d32eed5 100644
--- a/unity/Assets/Scripts/UI/NavigationGuard.cs
+++ b/unity/Assets/Scripts/UI/NavigationGuard.cs
@@ -1,4 +1,6 @@
#nullable enable
+using System.Collections.Generic;
+using UnityEngine;
using UnityEngine.UIElements;
namespace Statecraft.Game.UI
@@ -7,20 +9,91 @@ namespace Statecraft.Game.UI
/// 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>
+ /// Previous) still move focus, so the HUD stays keyboard-reachable; Enter and Space still press the focused button.
+ /// One exception, accessibility audit L4: while a screen is open, Up and Down move the focus between that screen's rows
+ /// (<see cref="Step"/>), so a long list is not Tab-only. The owner's answer on #2340, Q27: "do the recommended for all"
+ /// (https://github.com/eyalgolan/statecraft-israel/issues/2340#issuecomment-6623136558); the recommended option let
+ /// Up/Down move between rows only while a screen is open. Left and Right stay dropped, and with no screen open all four
+ /// are, as B6 ruled.</summary>
public sealed class NavigationGuard : System.IDisposable
{
readonly VisualElement root;
+ readonly System.Func<string?>? openScreen;
+ readonly EventCallback<NavigationMoveEvent> onMove;
- static readonly EventCallback<NavigationMoveEvent> OnMove = e =>
+ /// <param name="openScreen">The open screen's name (ScreenNav.Current), or null for none. Without it every
+ /// directional move is dropped.</param>
+ public NavigationGuard(VisualElement root, System.Func<string?>? openScreen = null)
{
- if (e.direction == NavigationMoveEvent.Direction.Next || e.direction == NavigationMoveEvent.Direction.Previous) return;
- (e.target as VisualElement)?.focusController?.IgnoreEvent(e);
- e.StopImmediatePropagation();
- };
+ this.root = root; this.openScreen = openScreen;
+ onMove = e =>
+ {
+ if (e.direction == NavigationMoveEvent.Direction.Next || e.direction == NavigationMoveEvent.Direction.Previous) return;
+ if (e.direction == NavigationMoveEvent.Direction.Up || e.direction == NavigationMoveEvent.Direction.Down)
+ Step(e.direction == NavigationMoveEvent.Direction.Up);
+ (e.target as VisualElement)?.focusController?.IgnoreEvent(e);
+ e.StopImmediatePropagation();
+ };
+ root.RegisterCallback(onMove, TrickleDown.TrickleDown);
+ }
- public NavigationGuard(VisualElement root) { this.root = root; root.RegisterCallback(OnMove, TrickleDown.TrickleDown); }
+ public void Dispose() => root.UnregisterCallback(onMove, TrickleDown.TrickleDown);
- public void Dispose() => root.UnregisterCallback(OnMove, TrickleDown.TrickleDown);
+ /// <summary>Up or Down while a screen is open (audit L4): focuses the nearest visible, enabled control in the row above
+ /// or below the focused one, the one closest to it across, and never leaves the screen or presses anything. With the
+ /// focus outside the screen, Down takes the screen's first control and Up its last, in document order. GameRoot calls it
+ /// for the arrow keys, which the UI map does not read (B6). False when no screen is open or nothing moved.</summary>
+ public bool Step(bool up)
+ {
+ var name = openScreen?.Invoke();
+ var screen = name == null ? null : root.Q<VisualElement>("screen-" + name);
+ if (screen == null) return false;
+ var rows = new List<VisualElement>();
+ // The header's X (ScreenNav's .screen-close) is no row (#2549 review): Up from the first row stops there.
+ screen.Query<VisualElement>().ForEach(e => { if (Reachable(e, screen) && !e.ClassListContains("screen-close")) rows.Add(e); });
+ if (rows.Count == 0) return false;
+ var at = root.panel?.focusController?.focusedElement as VisualElement;
+ var to = at == null || !rows.Contains(at) ? rows[up ? rows.Count - 1 : 0] : Beyond(rows, at.worldBound, up);
+ if (to == null || to == at) return false;
+ to.Focus();
+ return true;
+ }
+
+ /// <summary>The control in the nearest row wholly above (or below) <paramref name="from"/>: the closest edge picks the
+ /// row, everything overlapping it vertically is in that row, and the one nearest across wins (the first in
+ /// document order on a tie). A 1 px overlap is allowed for touching borders.</summary>
+ static VisualElement? Beyond(List<VisualElement> rows, Rect from, bool up)
+ {
+ VisualElement? edge = null;
+ foreach (var r in rows)
+ {
+ var b = r.worldBound;
+ if (up ? b.yMax > from.yMin + 1f : b.yMin < from.yMax - 1f) continue;
+ if (edge == null || (up ? b.yMax > edge.worldBound.yMax : b.yMin < edge.worldBound.yMin)) edge = r;
+ }
+ if (edge == null) return null;
+ Rect row = edge.worldBound;
+ VisualElement? best = null; float bestDx = float.MaxValue;
+ foreach (var r in rows)
+ {
+ var b = r.worldBound;
+ if (b.yMin >= row.yMax || b.yMax <= row.yMin) continue;
+ if (up ? b.yMax > from.yMin + 1f : b.yMin < from.yMax - 1f) continue;
+ var dx = Mathf.Abs(b.center.x - from.center.x);
+ if (dx < bestDx) { best = r; bestDx = dx; }
+ }
+ return best;
+ }
+
+ /// <summary>A control Tab could reach: focusable, enabled, laid out, and neither it nor anything up to the screen
+ /// hidden.</summary>
+ static bool Reachable(VisualElement e, VisualElement screen)
+ {
+ if (!e.focusable || !e.canGrabFocus || e.tabIndex < 0 || !e.enabledInHierarchy) return false;
+ for (var p = e; p != null && p != screen.parent; p = p.parent)
+ if (p.resolvedStyle.display == DisplayStyle.None || p.resolvedStyle.visibility == Visibility.Hidden) return false;
+ var b = e.worldBound;
+ return b.width > 0f && b.height > 0f && !float.IsNaN(b.x) && !float.IsNaN(b.y);
+ }
}
}
diff --git a/unity/Assets/Tests/EditMode/CameraInputTests.cs b/unity/Assets/Tests/EditMode/CameraInputTests.cs
index f5fccac51..b7ae15471 100644
--- a/unity/Assets/Tests/EditMode/CameraInputTests.cs
+++ b/unity/Assets/Tests/EditMode/CameraInputTests.cs
@@ -1258,3 +1258,55 @@ public class CameraPointerZoomThroughTheFrameTests : SharedCameraActionsFixture
Assert.IsFalse(plugin.GetCompatibleWithPlatform(other), other + " does not build AppKit code");
}
}
+
+/// <summary>Accessibility audit L4 against B6, the camera half: while a screen is open (ScreenTakesUpDown) the Up and Down
+/// arrows move between the screen's rows and do not pan; Left, Right and W still pan; with no screen open Up pans as
+/// before. The owner's answer on #2340, Q27: "do the recommended for all"
+/// (https://github.com/eyalgolan/statecraft-israel/issues/2340#issuecomment-6623136558). The keys go through the Input
+/// System test fixture, the project-wide Camera actions and CameraController's frame, as in the zoom-keys test.</summary>
+public class CameraArrowsWithAScreenOpenTests : SharedCameraActionsFixture
+{
+ static void Send(CameraController c, string message) =>
+ typeof(CameraController).GetMethod(message, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
+ .Invoke(c, null);
+
+ [Test]
+ public void UpAndDownPanOnlyWithNoScreenOpenL4()
+ {
+ InputSystem.actions = AssetDatabase.LoadAssetAtPath<InputActionAsset>("Assets/InputSystem_Actions.inputactions");
+ var keyboard = InputSystem.AddDevice<Keyboard>();
+ var go = new GameObject("ArrowPanTest", typeof(Camera));
+ var rig = go.AddComponent<CameraRig>();
+ rig.Distance = 100000f;
+ var c = go.AddComponent<CameraController>();
+ c.Bounds = new Rect(0, 0, 1000000, 1000000);
+ var open = true;
+ c.ScreenTakesUpDown = () => open;
+ Send(c, "Awake"); Send(c, "OnEnable");
+ try
+ {
+ Vector3 Held(params UnityEngine.InputSystem.Controls.KeyControl[] keys)
+ {
+ rig.LookAt = new Vector3(500000, 0, 500000);
+ foreach (var k in keys) Press(k);
+ for (int i = 0; i < 5; i++) c.Tick(0.1f);
+ foreach (var k in keys) Release(k);
+ c.Tick(0.1f);
+ return rig.LookAt - new Vector3(500000, 0, 500000);
+ }
+ Assert.AreEqual(Vector3.zero, Held(keyboard.upArrowKey), "screen open: Up does not pan");
+ Assert.AreEqual(Vector3.zero, Held(keyboard.downArrowKey), "screen open: Down does not pan");
+ var right = Held(keyboard.rightArrowKey);
+ Assert.Greater(right.magnitude, 1f, "screen open: Right still pans");
+ Assert.AreEqual(right.x, Held(keyboard.upArrowKey, keyboard.rightArrowKey).x, 1f, "screen open: Up with Right pans as Right alone");
+ Assert.Greater(Held(keyboard.leftArrowKey).magnitude, 1f, "screen open: Left still pans");
+ var w = Held(keyboard.wKey);
+ Assert.Greater(w.magnitude, 1f, "screen open: W still pans");
+ Assert.AreEqual(w, Held(keyboard.wKey, keyboard.downArrowKey), "screen open: Down held with W leaves W's pan");
+ open = false;
+ Assert.Greater(Held(keyboard.upArrowKey).magnitude, 1f, "no screen open: Up pans (B6)");
+ Assert.Greater(Held(keyboard.downArrowKey).magnitude, 1f, "no screen open: Down pans (B6)");
+ }
+ finally { Send(c, "OnDisable"); Object.DestroyImmediate(go); }
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/ScreenRowArrowTests.cs b/unity/Assets/Tests/EditMode/ScreenRowArrowTests.cs
new file mode 100644
index 000000000..d107cd8d0
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/ScreenRowArrowTests.cs
@@ -0,0 +1,246 @@
+#nullable enable
+using System;
+using System.Collections;
+using System.IO;
+using System.Linq;
+using NUnit.Framework;
+using Statecraft.Game;
+using Statecraft.Game.Map;
+using Statecraft.Game.UI;
+using UnityEditor;
+using UnityEditor.SceneManagement;
+using UnityEngine;
+using UnityEngine.InputSystem;
+using UnityEngine.InputSystem.LowLevel;
+using UnityEngine.TestTools;
+using UnityEngine.UIElements;
+using Object = UnityEngine.Object;
+
+/// <summary>Accessibility audit L4, against integration bug B6: while a screen is open, Up and Down move the focus between
+/// its rows; Left and Right never move it, and with no screen open none of the four does. The owner's answer on #2340,
+/// Q27: "do the recommended for all" (https://github.com/eyalgolan/statecraft-israel/issues/2340#issuecomment-6623136558).
+/// Same harness as KeyboardTurnTests: Map.unity at 1280x720 with GameRoot's own NavigationGuard, a new GDD game, and the
+/// moves sent as the NavigationMoveEvent the UI provider raises; one test presses the real arrow keys through GameRoot's
+/// frame, on the camera tests' input fixture.</summary>
+public class ScreenRowArrowTests : SharedCameraActionsFixture
+{
+ string saveDir = "";
+ RenderTexture? rt; PanelSettings? ps;
+ VisualElement ui = null!;
+ GameRoot root = null!;
+ int presses;
+
+ [SetUp] public void TempSaves() => saveDir = Path.Combine(Path.GetTempPath(), "statecraft-rows-" + Guid.NewGuid().ToString("N"));
+
+ [TearDown]
+ public void DiscardScene()
+ {
+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
+ if (ps != null) Object.DestroyImmediate(ps);
+ if (rt != null) { rt.Release(); Object.DestroyImmediate(rt); }
+ if (Directory.Exists(saveDir)) Directory.Delete(saveDir, true);
+ }
+
+ Focusable? Focused => ui.panel?.focusController?.focusedElement;
+ string FocusedName => (Focused as VisualElement)?.name is string n && n.Length > 0 ? n : Focused == null ? "none" : Focused.GetType().Name;
+ IEnumerator Frames(int n) { for (int i = 0; i < n; i++) yield return null; }
+
+ IEnumerator Move(NavigationMoveEvent.Direction d)
+ {
+ var at = Focused as VisualElement ?? ui;
+ using (var e = NavigationMoveEvent.GetPooled(d)) { e.target = at; at.SendEvent(e); }
+ yield return null;
+ }
+
+ IEnumerator Focus(string name)
+ {
+ var b = ui.Q<VisualElement>(name);
+ Assert.IsNotNull(b, name);
+ b.Focus();
+ for (int i = 0; i < 10 && Focused != b; i++) yield return null;
+ Assert.AreEqual(name, FocusedName, "precondition: focused");
+ }
+
+ /// <summary>Boots the game, answers the opening card from the keyboard (Tab, Enter) and counts every button press
+ /// from here on, so a move that presses anything shows. <paramref name="hebrew"/> sets the UI's language before Begin.</summary>
+ IEnumerator Boot(bool hebrew = false)
+ {
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ var doc = Object.FindFirstObjectByType<UIDocument>();
+ rt = new RenderTexture(1280, 720, 0);
+ ps = Object.Instantiate(doc.panelSettings);
+ ps.targetTexture = rt;
+ doc.panelSettings = ps;
+ Object.FindFirstObjectByType<MapScene>().Build(MapFocusTests.Inputs.Map);
+ root = Object.FindFirstObjectByType<GameRoot>();
+ root.Store = new SaveStore(saveDir);
+ root.Language = hebrew ? UiLanguage.Hebrew : UiLanguage.English;
+ root.Begin(MapFocusTests.Inputs, 0);
+ ui = doc.rootVisualElement;
+ for (int i = 0; i < 30 && !(ui.Q("top-bar").worldBound.height > 0); i++) yield return null;
+ yield return Frames(5);
+ yield return Move(NavigationMoveEvent.Direction.Next);
+ var at = (VisualElement)Focused!;
+ using (var k = KeyDownEvent.GetPooled('\n', KeyCode.Return, EventModifiers.None)) { k.target = at; at.SendEvent(k); }
+ using (var s = NavigationSubmitEvent.GetPooled()) { s.target = at; at.SendEvent(s); }
+ yield return Frames(3);
+ presses = 0;
+ foreach (var b in ui.Query<Button>().ToList()) b.clicked += () => presses++;
+ }
+
+ IEnumerator Open(string screen)
+ {
+ UiTestKit.Press(ui.Q<Button>("nav-" + screen));
+ presses = 0; // the nav press itself
+ yield return Frames(5);
+ Assert.IsTrue(ui.Q("screen-" + screen).resolvedStyle.display == DisplayStyle.Flex, "precondition: " + screen + " is open");
+ }
+
+ /// <summary>The Settings row (.settings-row) the focus is in, as its index among the screen's rows, or -1.</summary>
+ int SettingsRow()
+ {
+ var rows = ui.Q("screen-settings").Query(className: "settings-row").ToList();
+ var at = Focused as VisualElement;
+ return rows.FindIndex(r => at != null && r.Contains(at));
+ }
+
+ /// <summary>L4 and B6, a multi-row screen: in Settings, Down walks the option rows one at a time, from a choice button to
+ /// the choice in the next row nearest below it, and Up walks back; Left and Right leave the focus where it is; the focus
+ /// never leaves the screen at either end, nor reaches the header's X, which is no row (#2549 review), and no move
+ /// presses anything.</summary>
+ [UnityTest] public IEnumerator UpAndDownWalkTheSettingsRowsL4() => SettingsRows(false);
+
+ /// <summary>The same in the Hebrew UI (GameRoot.Language), right to left.</summary>
+ [UnityTest] public IEnumerator UpAndDownWalkTheSettingsRowsInHebrewL4() => SettingsRows(true);
+
+ IEnumerator SettingsRows(bool hebrew)
+ {
+ yield return Boot(hebrew);
+ Assert.AreEqual(hebrew, ui.Q("root").ClassListContains(UiLanguage.HebrewClass), "precondition: the UI's language");
+ yield return Open("settings");
+ yield return Focus("settings-tiltshift");
+ Assert.AreEqual(0, SettingsRow());
+ // The rows with a control to take the focus: in this editor the companion's row shows none (WebCompanion.Available).
+ var reachable = ui.Q("screen-settings").Query(className: "settings-row").ToList()
+ .Select((r, i) => (r, i))
+ .Where(x => x.r.resolvedStyle.display == DisplayStyle.Flex && x.r.Query<Button>().ToList().Any(b =>
+ b.enabledInHierarchy && b.resolvedStyle.display == DisplayStyle.Flex && b.resolvedStyle.visibility == Visibility.Visible))
+ .Select(x => x.i).ToList();
+ Assert.GreaterOrEqual(reachable.Count, 6, "precondition: the option rows");
+ for (int k = 1; k < reachable.Count; k++)
+ {
+ yield return Move(NavigationMoveEvent.Direction.Down);
+ Assert.AreEqual(reachable[k], SettingsRow(), $"Down moves to row {reachable[k]}, at {FocusedName}");
+ }
+ for (int i = 0; i < 5; i++) yield return Move(NavigationMoveEvent.Direction.Down);
+ Assert.IsTrue(ui.Q("screen-settings").Contains((VisualElement)Focused!), "Down past the last row stays in the screen, at " + FocusedName);
+ yield return Focus("settings-sound-high");
+ yield return Move(NavigationMoveEvent.Direction.Up);
+ Assert.AreEqual("settings-quality-low", FocusedName, "Up goes to the choice straight above");
+ foreach (var d in new[] { NavigationMoveEvent.Direction.Left, NavigationMoveEvent.Direction.Right })
+ {
+ yield return Move(d);
+ Assert.AreEqual("settings-quality-low", FocusedName, d + " leaves the focus where it is");
+ }
+ for (int i = 0; i < 12; i++) yield return Move(NavigationMoveEvent.Direction.Up);
+ Assert.IsTrue(ui.Q("screen-settings").Contains((VisualElement)Focused!), "Up past the first row stays in the screen, at " + FocusedName);
+ Assert.AreEqual(reachable[0], SettingsRow(), "Up past the first row stays on it, not the header's X, at " + FocusedName);
+ Assert.AreEqual(DisplayStyle.Flex, ui.Q("screen-settings").resolvedStyle.display, "the screen is still open");
+ Assert.AreEqual(0, presses, "moving pressed nothing");
+ }
+
+ /// <summary>L4 and B6, a list: in the Budget, Down goes from a line's - to the next line's -, skipping a line whose
+ /// buttons are disabled and one that is hidden, and Up comes back the same way; nothing is pressed.</summary>
+ [UnityTest]
+ public IEnumerator UpAndDownWalkTheBudgetLinesSkippingHiddenAndDisabledL4()
+ {
+ yield return Boot();
+ yield return Open("budget");
+ var lines = ui.Q<ScrollView>("budget-rows").contentContainer.Children().Where(r => r.Q<Button>(r.name + "-down") != null).ToList();
+ Assert.GreaterOrEqual(lines.Count, 5, "precondition: the budget has its lines");
+ yield return Focus(lines[0].name + "-down");
+ yield return Move(NavigationMoveEvent.Direction.Down);
+ Assert.AreEqual(lines[1].name + "-down", FocusedName, "Down: the next line's -");
+ lines[2].Q<Button>(lines[2].name + "-down").SetEnabled(false);
+ lines[2].Q<Button>(lines[2].name + "-up").SetEnabled(false);
+ lines[3].style.display = DisplayStyle.None;
+ yield return Frames(3);
+ yield return Move(NavigationMoveEvent.Direction.Down);
+ Assert.AreEqual(lines[4].name + "-down", FocusedName, "a disabled line and a hidden one are skipped");
+ yield return Move(NavigationMoveEvent.Direction.Up);
+ Assert.AreEqual(lines[1].name + "-down", FocusedName, "and Up skips them too");
+ Assert.AreEqual(0, presses, "moving pressed nothing");
+ }
+
+ /// <summary>L4 and B6 through GameRoot (#2549 review): the real Up and Down keys, read by GameRoot's own key poll in
+ /// its frame, walk the Budget's lines, and the camera GameRoot wired (ScreenTakesUpDown) does not pan on them while
+ /// the screen is open; once it is closed, the same keys pan and leave the focus where it is. In English and in Hebrew
+ /// (right to left), so the real key path is proven both ways (#2549 review).</summary>
+ [UnityTest]
+ public IEnumerator TheArrowKeysThroughGameRootWalkTheRowsAndPanOnlyWithTheScreenClosedL4([Values(false, true)] bool hebrew)
+ {
+ // The keys as state events: the fixture's Press (Set) does not run in an edit-mode [UnityTest], and Boot needs frames.
+ InputSystem.actions = AssetDatabase.LoadAssetAtPath<InputActionAsset>("Assets/InputSystem_Actions.inputactions");
+ var keyboard = InputSystem.AddDevice<Keyboard>();
+ // Warm both keys: ButtonControl.wasPressedThisFrame takes an old path on its first call ever and can miss a press
+ // (as in MapPointerTickTests); in the game GameRoot asks every frame, so they are warm.
+ _ = keyboard.upArrowKey.wasPressedThisFrame; _ = keyboard.downArrowKey.wasPressedThisFrame;
+ yield return Boot(hebrew);
+ var cam = Object.FindFirstObjectByType<CameraController>();
+ var rig = cam.GetComponent<CameraRig>();
+ Send(cam, "Awake"); Send(cam, "OnEnable");
+ try
+ {
+ yield return Open("budget");
+ var lines = ui.Q<ScrollView>("budget-rows").contentContainer.Children().Where(r => r.Q<Button>(r.name + "-down") != null).ToList();
+ yield return Focus(lines[0].name + "-down");
+ // One frame with the key down: GameRoot's poll (Update) and the camera's (Tick) both read it.
+ Vector3 Hold(UnityEngine.InputSystem.Key k)
+ {
+ var from = rig.LookAt;
+ InputSystem.QueueStateEvent(keyboard, new KeyboardState(k)); InputSystem.Update();
+ Assert.IsTrue(keyboard[k].wasPressedThisFrame, "precondition: " + k + " went down this frame");
+ Send(root, "Update");
+ for (int i = 0; i < 5; i++) cam.Tick(0.1f);
+ InputSystem.QueueStateEvent(keyboard, new KeyboardState()); InputSystem.Update();
+ cam.Tick(0.1f);
+ return rig.LookAt - from;
+ }
+ Assert.AreEqual(Vector3.zero, Hold(UnityEngine.InputSystem.Key.DownArrow), "screen open: Down does not pan");
+ Assert.AreEqual(lines[1].name + "-down", FocusedName, "Down: the next line's -");
+ Assert.AreEqual(Vector3.zero, Hold(UnityEngine.InputSystem.Key.UpArrow), "screen open: Up does not pan");
+ Assert.AreEqual(lines[0].name + "-down", FocusedName, "Up: back to the first line's -");
+ UiTestKit.Press(ui.Q<Button>("nav-budget"));
+ yield return Frames(5);
+ Assert.AreEqual(DisplayStyle.None, ui.Q("screen-budget").resolvedStyle.display, "precondition: the Budget is closed");
+ yield return Focus("nav-budget");
+ presses = 0;
+ Assert.Greater(Hold(UnityEngine.InputSystem.Key.UpArrow).magnitude + Hold(UnityEngine.InputSystem.Key.DownArrow).magnitude, 1f, "no screen open: Up and Down pan (B6)");
+ Assert.AreEqual("nav-budget", FocusedName, "no screen open: the focus stays (B6)");
+ Assert.AreEqual(0, presses, "no key pressed a button");
+ }
+ finally { Send(cam, "OnDisable"); }
+ }
+
+ static void Send(MonoBehaviour c, string message) =>
+ c.GetType().GetMethod(message, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!.Invoke(c, null);
+
+ /// <summary>B6 with no screen open, through GameRoot's guard: none of the four directions moves the focus off a HUD
+ /// button or presses it.</summary>
+ [UnityTest]
+ public IEnumerator WithNoScreenOpenNoArrowMovesTheFocusB6()
+ {
+ yield return Boot();
+ Assert.IsFalse(ui.Q("root").ClassListContains(ScreenNav.ScreenOpenClass), "precondition: no screen is open");
+ foreach (var name in new[] { "nav-cabinet", "nav-budget", "end-turn" })
+ {
+ yield return Focus(name);
+ foreach (var d in new[] { NavigationMoveEvent.Direction.Up, NavigationMoveEvent.Direction.Down, NavigationMoveEvent.Direction.Left, NavigationMoveEvent.Direction.Right })
+ {
+ yield return Move(d);
+ Assert.AreEqual(name, FocusedName, $"{d} left the focus on {name}");
+ }
+ }
+ Assert.AreEqual(0, presses, "no arrow pressed a button");
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/ScreenRowArrowTests.cs.meta b/unity/Assets/Tests/EditMode/ScreenRowArrowTests.cs.meta
new file mode 100644
index 000000000..c180b0bdc
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/ScreenRowArrowTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: c465995a77620fb65b9024226bb3c3bd
\ No newline at end of file