A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
UI: the map from the keyboard, a Tab stop with a centre ring (a11y B1b, Fixes #1116, refs #41) (#1134)
Beribb8c382f7812
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b596ab673..4035b5476 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -27,6 +27,12 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIBpriced by the sim's new `AttentionSystem.Price`/`Left`, which `SimBridge` now uses too); the UI only reads it (refs #1109).- Unit cards show the sourced Hebrew unit name in the Hebrew UI, with an English fallback. INS Haganah gains itssourced Hebrew name, still flagged for a native speaker's review (#902).+- The map can be used from the keyboard: Tab reaches a map stop right after End Turn, a gold ring with a dark outline+ marks the centre of the view while it has the focus, the camera keys pan the map under it, and Enter or Space selects+ the hex under the ring through the same pick as a click, with the focus staying on the map. The next Tabs reach the+ info panel's actions. Covering screens and the start screen take the stop out of reach, and mouse and touch clicks pass+ through it as before. The empty info panel's hint says so in English and Hebrew, and keeps the right-drag (Hebrew+ flagged for a native speaker's review; Fixes #1116, refs #41).### Fixed- Keep the opt-in hex terrain overlay out of automatic neighboring with the real map terrain.- Keep the capsule-collider dependency used while creating hex unit stand-ins in stripped player builds; the temporary collider is still removed.diff --git a/scripts/unity_compile/Tests.csproj b/scripts/unity_compile/Tests.csprojindex 7586c3bd9..79a9e9eff 100644--- a/scripts/unity_compile/Tests.csproj+++ b/scripts/unity_compile/Tests.csproj@@ -7,7 +7,7 @@<ItemGroup><Reference Include="$(Editor)/Resources/Scripting/UnityReferenceAssemblies/unity-4.8-api/*.dll" Private="false" /><Reference Include="$(Editor)/Resources/Scripting/UnityReferenceAssemblies/unity-4.8-api/Facades/*.dll" Private="false" />- <Reference Include="$(Lib)/ScriptAssemblies/UnityEngine.TestRunner.dll;$(Lib)/ScriptAssemblies/UnityEditor.TestRunner.dll" Private="false" />+ <Reference Include="$(Lib)/ScriptAssemblies/UnityEngine.TestRunner.dll;$(Lib)/ScriptAssemblies/UnityEditor.TestRunner.dll;$(Lib)/ScriptAssemblies/Unity.InputSystem.TestFramework.dll" Private="false" /><Reference Include="$(Lib)/PackageCache/com.unity.ext.nunit@*/net40/unity-custom/nunit.framework.dll" Private="false" /><ProjectReference Include="Game.csproj" /><Compile Include="$(Src)/Assets/Tests/EditMode/**/*.cs" />diff --git a/scripts/unity_compile/compile.sh b/scripts/unity_compile/compile.shindex af0530311..aa5ec065b 100755--- a/scripts/unity_compile/compile.sh+++ b/scripts/unity_compile/compile.sh@@ -21,7 +21,7 @@ lib=unity/Libraryfor f in "$contents/Resources/Scripting/Managed/UnityEngine/UnityEngine.CoreModule.dll" \"$contents/Resources/Scripting/NetStandard/ref/2.1.0/netstandard.dll" \"$lib"/ScriptAssemblies/{Unity.RenderPipelines.Core.Runtime,Unity.RenderPipelines.Universal.Runtime}.dll \- "$lib"/ScriptAssemblies/{Unity.InputSystem,UnityEngine.TestRunner,UnityEditor.TestRunner}.dll; do+ "$lib"/ScriptAssemblies/{Unity.InputSystem,Unity.InputSystem.TestFramework,UnityEngine.TestRunner,UnityEditor.TestRunner}.dll; do[ -f "$f" ] || { echo "missing: $f (open the project in Unity once so it builds its Library)"; exit 1; }donenunit=("$lib"/PackageCache/com.unity.ext.nunit@*/net40/unity-custom/nunit.framework.dll)diff --git a/unity/Assets/Scripts/Map/MapPointer.cs b/unity/Assets/Scripts/Map/MapPointer.csindex 7561c9ac7..982b864be 100644--- a/unity/Assets/Scripts/Map/MapPointer.cs+++ b/unity/Assets/Scripts/Map/MapPointer.cs@@ -98,6 +98,15 @@ namespace Statecraft.Game.Mapvar overUi = IsOverUi != null && IsOverUi(pos);Boot.DiagLog.NavLine(FormattableString.Invariant($"map click at ({pos.x:0}, {pos.y:0}) overUi={overUi}"));if (overUi) return false; // the UI is asked first, whatever else is missing+ return PickAt(pos);+ }++ /// <summary>The pick without the UI check: the hex under <paramref name="pos"/> (screen pixels) is outlined and raised+ /// as HexClicked, as for a click. The keyboard's map stop (MapFocusPresenter, #41 B1b) picks here at the projected+ /// look-at point: that is not a pointer, and on a narrow window the info panel may sit over the centre. Returns+ /// whether a hex was picked.</summary>+ public bool PickAt(Vector2 pos)+ {if (Map == null || Map.Terrain == null) return false;var cam = Camera.main;var collider = Map.Terrain.GetComponent<TerrainCollider>();diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex 52a2d7724..5096592ea 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -333,6 +333,8 @@ namespace Statecraft.Game.UIvar camRig = rig = cameraController.GetComponent<CameraRig>();Own(new TopBarInset(root, camRig)); // the map is framed below the top barOwn(new SafeAreaFit(root)); // the HUD keeps clear of the phone's notch+ // the map's keyboard stop (#41 B1b): Enter or Space picks the hex under the look-at point, as a click there would+ Own(new MapFocusPresenter(root, cameraController.GetComponent<Camera>(), camRig, at => pointer.PickAt(at)));var mini = minimap = Own(new MinimapPresenter(root, map.Hexes, text));var labelCamera = cameraController.GetComponent<Camera>();labels = Own(new MapLabelsPresenter(root, map, labelCamera, null,diff --git a/unity/Assets/Scripts/UI/MapFocusPresenter.cs b/unity/Assets/Scripts/UI/MapFocusPresenter.csnew file mode 100644index 000000000..cd5454f06--- /dev/null+++ b/unity/Assets/Scripts/UI/MapFocusPresenter.cs@@ -0,0 +1,72 @@+#nullable enable+using System;+using Statecraft.Game.Map;+using UnityEngine;+using UnityEngine.UIElements;++namespace Statecraft.Game.UI+{+ /// <summary>The map's keyboard stop (#41 B1b, #1116; docs/superpowers/plans/2026-10-14-a11y-keyboard-map.md): Game.uxml's+ /// "map-focus" takes a place in the Tab order after End Turn. While it has the focus the stylesheet shows its ring, which+ /// this places on the camera's look-at point; the camera keys keep panning (NavigationGuard), so the player moves the map+ /// under the ring. Enter (the UI's Submit) or Space picks the hex under it through <paramref name="pick"/>, the map's own+ /// pick (MapPointer.PickAt), and the focus stays on the stop. Its own handlers only: disposing (a restart, a language+ /// switch) leaves the element as Game.uxml made it.</summary>+ public sealed class MapFocusPresenter : IDisposable+ {+ readonly VisualElement stop, mark;+ readonly Camera camera; readonly CameraRig rig; readonly Action<Vector2> pick;+ readonly IVisualElementScheduledItem follow;++ /// <param name="pick">Picks the hex under a screen point (pixels, y up), as a click there would.</param>+ public MapFocusPresenter(VisualElement root, Camera camera, CameraRig rig, Action<Vector2> pick)+ {+ stop = root.Q("map-focus"); mark = root.Q("map-focus-mark");+ this.camera = camera; this.rig = rig; this.pick = pick;+ stop.RegisterCallback<NavigationSubmitEvent>(OnSubmit);+ stop.RegisterCallback<KeyDownEvent>(OnKey);+ stop.RegisterCallback<FocusInEvent>(OnFocus);+ // every panel update, which runs after the camera's (CameraController.Update): the ring never trails a pan+ follow = stop.schedule.Execute(Place).Every(0);+ }++ void OnFocus(FocusInEvent e) => Place();++ // Enter arrives as Submit (the only key with the Submit usage); Space only as a key, so it is caught here.+ void OnSubmit(NavigationSubmitEvent e) { Pick(); e.StopPropagation(); }++ void OnKey(KeyDownEvent e)+ {+ if (e.keyCode != KeyCode.Space) return;+ Pick();+ e.StopPropagation();+ }++ void Pick()+ {+ if (camera == null || rig == null) return; // the camera went first (scene teardown)+ var s = camera.WorldToScreenPoint(rig.LookAt);+ pick(new Vector2(s.x, s.y)); // off the terrain nothing is picked, as for a click there+ }++ /// <summary>Puts the ring's centre on the look-at point (Statecraft.uss centres the ring on its left/top), while the+ /// stop has the focus. The look-at point sits in the middle of the map area below the top bar (CameraRig.TopInset).</summary>+ void Place()+ {+ var panel = stop.panel;+ if (panel == null || camera == null || rig == null || panel.focusController.focusedElement != stop) return;+ var p = MapLabelsPresenter.ToPanel(camera.WorldToViewportPoint(rig.LookAt), camera.rect, panel.visualTree.layout.size,+ stop.worldBound.position);+ mark.style.left = p.x;+ mark.style.top = p.y;+ }++ public void Dispose()+ {+ follow.Pause();+ stop.UnregisterCallback<NavigationSubmitEvent>(OnSubmit);+ stop.UnregisterCallback<KeyDownEvent>(OnKey);+ stop.UnregisterCallback<FocusInEvent>(OnFocus);+ }+ }+}diff --git a/unity/Assets/Scripts/UI/MapFocusPresenter.cs.meta b/unity/Assets/Scripts/UI/MapFocusPresenter.cs.metanew file mode 100644index 000000000..444900fc9--- /dev/null+++ b/unity/Assets/Scripts/UI/MapFocusPresenter.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: a75c572a25ac6e1c4b6c3d71d85705b2\ No newline at end of filediff --git a/unity/Assets/Scripts/UI/MapLabelsPresenter.cs b/unity/Assets/Scripts/UI/MapLabelsPresenter.csindex 9d9a6446e..95aef396a 100644--- a/unity/Assets/Scripts/UI/MapLabelsPresenter.cs+++ b/unity/Assets/Scripts/UI/MapLabelsPresenter.cs@@ -667,7 +667,7 @@ namespace Statecraft.Game.UI/// <summary>Viewport to the layer's coordinates through the camera's own rect, not/// RuntimePanelUtils.CameraTransformWorldToPanel: that flips y with Screen.height, which is wrong whenever the camera/// draws to a texture of another size (edit-mode tests, captures).</summary>- static Vector2 ToPanel(Vector3 v, Rect cameraRect, Vector2 screen, Vector2 origin) =>+ internal static Vector2 ToPanel(Vector3 v, Rect cameraRect, Vector2 screen, Vector2 origin) =>new Vector2((cameraRect.x + v.x * cameraRect.width) * screen.x, (1f - (cameraRect.y + v.y * cameraRect.height)) * screen.y) - origin;static float Gap(Rect r, Vector2 p) =>diff --git a/unity/Assets/Scripts/UI/ScreenNav.cs b/unity/Assets/Scripts/UI/ScreenNav.csindex f7fd9278f..50cc00600 100644--- a/unity/Assets/Scripts/UI/ScreenNav.cs+++ b/unity/Assets/Scripts/UI/ScreenNav.cs@@ -46,7 +46,10 @@ namespace Statecraft.Game.UIr.Q("top-bar")?.SetEnabled(!(start || outcome || report));r.Q("left-column")?.SetEnabled(!(start || outcome || report)); // the screens' buttons: usable wherever the top bar isr.Q("right-column")?.SetEnabled(!(start || full || modal || outcome || report));- r.Q("info-panel")?.SetEnabled(!(start || full || modal || outcome || report || r.ClassListContains(WideOpenClass)));+ bool infoCovered = start || full || modal || outcome || report || r.ClassListContains(WideOpenClass);+ r.Q("info-panel")?.SetEnabled(!infoCovered);+ // the map's keyboard stop (#41 B1b): out of reach exactly when the info panel is, so a pick is never refused (#210)+ r.Q("map-focus")?.SetEnabled(!infoCovered);var layer = r.Q("event-layer");if (layer != null){diff --git a/unity/Assets/Tests/EditMode/GameSceneTests.cs b/unity/Assets/Tests/EditMode/GameSceneTests.csindex e1d4052f3..5bacc57fe 100644--- a/unity/Assets/Tests/EditMode/GameSceneTests.cs+++ b/unity/Assets/Tests/EditMode/GameSceneTests.cs@@ -110,7 +110,7 @@ public class GameSceneTestsvar root = Boot();Assert.IsNotNull(root.Bridge);Assert.AreEqual(root.Bridge!.State.Date.Year.ToString(System.Globalization.CultureInfo.InvariantCulture), Ui.Q<Label>("year").text);- Assert.AreEqual("Click the map to inspect a hex", Ui.Q<Label>("info-title").text);+ Assert.AreEqual(Text["info.hint"], Ui.Q<Label>("info-title").text);Assert.AreEqual(new DateTime(1948, 5, 15), root.Bridge.State.Date, "no autosave: a new game");var pointer = Object.FindFirstObjectByType<MapPointer>();Assert.AreSame(Object.FindFirstObjectByType<MapScene>(), pointer.Map);diff --git a/unity/Assets/Tests/EditMode/MapActionUiTests.cs b/unity/Assets/Tests/EditMode/MapActionUiTests.csindex 478a0d0b2..5fe78f7cb 100644--- a/unity/Assets/Tests/EditMode/MapActionUiTests.cs+++ b/unity/Assets/Tests/EditMode/MapActionUiTests.cs@@ -57,7 +57,7 @@ public class MapActionUiTests{using var ui = new UiTestKit();var info = Panel(ui, At(new DateTime(1949, 6, 1)));- Assert.AreEqual("Click the map to inspect a hex", ui.Q<Label>("info-title").text);+ Assert.AreEqual(Text["info.hint"], ui.Q<Label>("info-title").text);var tlv = C.SettlementHexes.Single(s => s.Id == "tel_aviv");info.Show(tlv.Q, tlv.R);Assert.AreEqual("Tel Aviv", ui.Q<Label>("info-title").text);diff --git a/unity/Assets/Tests/EditMode/MapFocusTests.cs b/unity/Assets/Tests/EditMode/MapFocusTests.csnew file mode 100644index 000000000..0b153ffb8--- /dev/null+++ b/unity/Assets/Tests/EditMode/MapFocusTests.cs@@ -0,0 +1,425 @@+#nullable enable+using System;+using System.Collections;+using System.Collections.Generic;+using System.IO;+using System.Linq;+using NUnit.Framework;+using Statecraft.Game;+using Statecraft.Game.Boot;+using Statecraft.Game.Map;+using Statecraft.Game.UI;+using Statecraft.Sim;+using UnityEditor;+using UnityEditor.SceneManagement;+using UnityEngine;+using UnityEngine.InputSystem;+using UnityEngine.TestTools;+using UnityEngine.UIElements;+using Object = UnityEngine.Object;++/// <summary>#41 B1b (#1116): the map's keyboard stop. Map.unity as the player gets it, at 1280x720: Tab reaches the stop+/// after End Turn, a gold ring shows at the camera's look-at point only while the stop has the focus, Enter or Space picks+/// the hex under it through the map's own pick and leaves the focus on the stop, and the info panel's actions follow it in+/// the Tab order. Covered (a wide screen, the start screen) the stop is out of reach; a restart or a language switch leaves+/// one pick per key press. Keys reach the UI here as the UI Toolkit events the Input System's UI provider makes of them+/// (Tab: NavigationMoveEvent Next; Enter: KeyDownEvent then NavigationSubmitEvent; Space: KeyDownEvent only, as only+/// Enter carries the Submit usage): an edit-mode panel gets no device input (a queued Tab moves nothing there), so the+/// browser check drives the real keys (PR evidence). The camera keys go through the Input System itself+/// (MapFocusCameraKeysTests).</summary>+public class MapFocusTests+{+ static GameInputs? inputs;+ internal static GameInputs Inputs => inputs ??= GameInputs.FromDisk(Paths.Content, Paths.StreamingMap);+ static UiText TextHe => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.StringsHebrew).text, "strings.he.yaml");+ static UiText Text => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings).text);++ string saveDir = "";+ RenderTexture? rt; PanelSettings? ps;+ VisualElement ui = null!;+ GameRoot root = null!;++ [SetUp] public void TempSaves() => saveDir = Path.Combine(Path.GetTempPath(), "statecraft-mapfocus-" + 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);+ }++ /// <summary>Map.unity on a 1280x720 panel, the map built and the game started as GameBoot.Ready does (no start screen+ /// unless asked), laid out, the camera over Tel Aviv, the opening card hidden.</summary>+ IEnumerator Boot(bool startScreen = 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(Inputs.Map);+ root = Object.FindFirstObjectByType<GameRoot>();+ root.Store = new SaveStore(saveDir);+ root.Begin(Inputs, 0, startScreen);+ ui = doc.rootVisualElement;+ for (int i = 0; i < 30 && !(ui.Q("top-bar").worldBound.height > 0); i++) yield return null;+ if (!startScreen) GameSceneTests.HideTheOpeningCard(ui);+ LookAtTelAviv();+ yield return Frames(3);+ }++ static IEnumerator Frames(int n) { for (int i = 0; i < n; i++) yield return null; }++ static (int q, int r) TelAviv()+ {+ var tlv = Inputs.Content.SettlementHexes.Single(s => s.Id == "tel_aviv");+ return (tlv.Q, tlv.R);+ }++ /// <summary>Moves the camera's look-at point onto Tel Aviv's hex, on the ground, as a pan would.</summary>+ static void LookAtTelAviv()+ {+ var map = Object.FindFirstObjectByType<MapScene>();+ var (q, r) = TelAviv();+ var hex = Inputs.Content.HexAt(q, r)!;+ var ground = map.Frame.ToWorld(hex.Lon, hex.Lat, 0);+ ground.y = map.Terrain.SampleHeight(ground) + map.Terrain.transform.position.y;+ var rig = Camera.main.GetComponent<CameraRig>();+ rig.LookAt = ground; rig.Distance = 30000f;+ rig.Apply();+ }++ VisualElement Stop => ui.Q("map-focus") ?? throw new AssertionException("Game.uxml has no map-focus stop");+ VisualElement Mark => ui.Q("map-focus-mark") ?? throw new AssertionException("the stop has no map-focus-mark");+ Focusable? Focused => ui.panel.focusController.focusedElement;+ string FocusedName => (Focused as VisualElement)?.name ?? "none";++ IEnumerator FocusOn(VisualElement e)+ {+ e.Focus();+ for (int i = 0; i < 10 && Focused != e; i++) { yield return null; e.Focus(); }+ Assert.AreSame(e, Focused, e.name + ": precondition, focused");+ }++ /// <summary>Tab, as the UI provider sends it: NavigationMoveEvent Next to the focused element.</summary>+ IEnumerator Tab()+ {+ var at = (VisualElement)Focused!;+ using (var e = NavigationMoveEvent.GetPooled(NavigationMoveEvent.Direction.Next)) { e.target = at; at.SendEvent(e); }+ yield return null;+ }++ /// <summary>A key press on the focused element as the UI provider delivers it: the key, then for Enter (the only key+ /// with the Submit usage) the submit.</summary>+ IEnumerator Key(KeyCode key)+ {+ var at = (VisualElement)Focused!;+ using (var e = KeyDownEvent.GetPooled(key == KeyCode.Space ? ' ' : '\n', key, EventModifiers.None)) { e.target = at; at.SendEvent(e); }+ if (key == KeyCode.Return)+ using (var e = NavigationSubmitEvent.GetPooled()) { e.target = at; at.SendEvent(e); }+ yield return null;+ }++ bool MarkShown => Mark.resolvedStyle.display == DisplayStyle.Flex && Mark.worldBound.width > 0;++ /// <summary>Where the look-at point is on the panel: the camera's viewport scaled to the panel, which the view fills.</summary>+ Vector2 LookAtOnPanel()+ {+ var cam = Camera.main;+ var v = cam.WorldToViewportPoint(cam.GetComponent<CameraRig>().LookAt);+ var size = ui.panel.visualTree.layout.size;+ return new Vector2(v.x * size.x, (1f - v.y) * size.y);+ }++ /// <summary>Tab from End Turn reaches the stop; the ring shows at the look-at point; Enter picks Tel Aviv through the+ /// map pointer (outline and info panel), the focus stays; the next Tabs reach the city's actions in the info panel+ /// before the order starts again.</summary>+ [UnityTest]+ public IEnumerator TabReachesTheStopAfterEndTurnAndEnterPicksTheCentreHex()+ {+ yield return Boot();+ var pointer = Object.FindFirstObjectByType<MapPointer>();+ var picked = new List<(int, int)>();+ Action<int, int> onPick = (q, r) => picked.Add((q, r));+ pointer.HexClicked += onPick;+ try+ {+ Assert.IsFalse(MarkShown, "no ring before the stop has the focus");+ yield return FocusOn(ui.Q<Button>("end-turn"));+ yield return Tab();+ Assert.AreEqual("map-focus", FocusedName, "Tab from End Turn reaches the map stop");+ yield return Frames(2);+ Assert.IsTrue(MarkShown, "the ring shows while the stop has the focus");+ var at = LookAtOnPanel();+ Assert.AreEqual(at.x, Mark.worldBound.center.x, 2f, $"the ring is on the look-at point ({at}), not {Mark.worldBound}");+ Assert.AreEqual(at.y, Mark.worldBound.center.y, 2f, $"the ring is on the look-at point ({at}), not {Mark.worldBound}");++ yield return Key(KeyCode.Return);+ CollectionAssert.AreEqual(new[] { TelAviv() }, picked, "Enter picks the hex under the ring, once");+ Assert.AreEqual("Tel Aviv", ui.Q<Label>("info-title").text, "the info panel shows it");+ var sel = Object.FindFirstObjectByType<MapScene>().Terrain.transform.Find(MapScene.SelectionName);+ Assert.IsTrue(sel != null && sel.GetComponent<MeshRenderer>().enabled, "the map outlines it, as for a click");+ Assert.AreEqual("map-focus", FocusedName, "the focus stays on the stop, so the player can pan and pick again");++ var seen = new List<string>();+ for (int i = 0; i < 12; i++)+ {+ yield return Tab();+ seen.Add(FocusedName);+ if (ui.Q("info-panel").Contains((VisualElement)Focused!)) break;+ }+ Assert.IsTrue(ui.Q("info-panel").Contains((VisualElement)Focused!), "Tab goes on to the info panel's actions: " + string.Join(", ", seen));+ Assert.IsFalse(seen.Any(n => n.StartsWith("nav-", StringComparison.Ordinal) || n == "end-turn"),+ "the info actions come before the order starts again: " + string.Join(", ", seen));+ Assert.IsFalse(MarkShown, "the ring goes with the focus");+ }+ finally { pointer.HexClicked -= onPick; }+ }++ /// <summary>Space picks too; a key that is not Enter or Space (a camera key) picks nothing; a pan under the ring picks+ /// the new centre hex.</summary>+ [UnityTest]+ public IEnumerator SpacePicksAndTheCameraKeysDoNot()+ {+ yield return Boot();+ var pointer = Object.FindFirstObjectByType<MapPointer>();+ var picked = new List<(int, int)>();+ Action<int, int> onPick = (q, r) => picked.Add((q, r));+ pointer.HexClicked += onPick;+ try+ {+ yield return FocusOn(Stop);+ foreach (var k in new[] { KeyCode.W, KeyCode.D, KeyCode.UpArrow, KeyCode.LeftArrow, KeyCode.Q, KeyCode.E })+ yield return Key(k);+ Assert.IsEmpty(picked, "the camera keys pick nothing");+ Assert.AreEqual("map-focus", FocusedName, "and leave the focus on the stop");+ yield return Key(KeyCode.Space);+ CollectionAssert.AreEqual(new[] { TelAviv() }, picked, "Space picks the centre hex");+ var rig = Camera.main.GetComponent<CameraRig>();+ rig.LookAt += new Vector3(20000f, 0, 0); rig.Apply(); // a pan of four hexes east+ yield return Frames(2);+ var at = LookAtOnPanel();+ Assert.AreEqual(at.x, Mark.worldBound.center.x, 2f, "the ring follows the look-at point");+ yield return Key(KeyCode.Space);+ Assert.AreEqual(2, picked.Count);+ Assert.AreNotEqual(TelAviv(), picked[1], "a pan moves the hex under the ring");+ }+ finally { pointer.HexClicked -= onPick; }+ }++ /// <summary>The stop takes no pointer: the panel picks nothing at the ring, and a click at the centre of the map still+ /// reaches the map and picks the hex there (mouse and touch go through MapPointer's press queue).</summary>+ [UnityTest]+ public IEnumerator MouseAndTouchStillClickThroughTheStop()+ {+ yield return Boot();+ yield return FocusOn(Stop);+ yield return Frames(2);+ Assert.IsTrue(MarkShown, "precondition: the ring shows");+ Assert.IsNull(ui.panel.Pick(Mark.worldBound.center), "neither the stop nor its ring takes the pointer");+ var pointer = Object.FindFirstObjectByType<MapPointer>();+ var picked = new List<(int, int)>();+ Action<int, int> onPick = (q, r) => picked.Add((q, r));+ pointer.HexClicked += onPick;+ try+ {+ var cam = Camera.main;+ var s = cam.WorldToScreenPoint(cam.GetComponent<CameraRig>().LookAt);+ pointer.OnPress(new Vector2(s.x, s.y)); // a click or a tap, as MapPointer queues them+ pointer.ProcessPresses();+ CollectionAssert.AreEqual(new[] { TelAviv() }, picked, "the click under the ring picks the hex there");+ }+ finally { pointer.HexClicked -= onPick; }+ }++ /// <summary>Under a wide screen (Cabinet) or the decision card's backdrop the stop is disabled: out of Tab's reach, no+ /// ring, no pick; closing the screen brings it back. Under the start screen it is out of reach too.</summary>+ [UnityTest]+ public IEnumerator CoveringScreensTakeTheStopOutOfReach()+ {+ yield return Boot();+ var pointer = Object.FindFirstObjectByType<MapPointer>();+ var picked = 0;+ Action<int, int> onPick = (q, r) => picked++;+ pointer.HexClicked += onPick;+ try+ {+ yield return FocusOn(Stop);+ UiTestKit.Press(ui.Q<Button>("nav-cabinet"));+ yield return Frames(2);+ Assert.IsFalse(Stop.canGrabFocus, "under the Cabinet the stop is out of reach");+ Assert.AreNotEqual("map-focus", FocusedName, "and loses the focus (Escape's nothing-focused case stays reachable)");+ Assert.IsFalse(MarkShown, "and shows no ring");+ yield return FocusOn(ui.Q<Button>("end-turn"));+ yield return Tab();+ Assert.AreNotEqual("map-focus", FocusedName, "Tab skips it");+ Assert.AreEqual(0, picked);+ UiTestKit.Press(ui.Q<Button>("nav-cabinet"));+ yield return Frames(2);+ Assert.IsTrue(Stop.canGrabFocus, "closing the screen brings it back");++ UiTestKit.Press(ui.Q<Button>("event-reopen")); // the decision card again: its backdrop covers the map+ yield return Frames(2);+ Assert.IsFalse(Stop.canGrabFocus, "under the open decision card the stop is out of reach");+ }+ finally { pointer.HexClicked -= onPick; }+ }++ [UnityTest]+ public IEnumerator TheStartScreenTakesTheStopOutOfReach()+ {+ yield return Boot(startScreen: true);+ Assert.IsTrue((ui.Q("root") ?? ui).ClassListContains(StartScreenPresenter.OpenClass), "precondition: the start screen shows");+ Assert.IsFalse(Stop.canGrabFocus, "the stop is out of reach under the start screen");+ Stop.Focus();+ yield return Frames(2);+ Assert.AreNotEqual("map-focus", FocusedName);+ Assert.IsFalse(MarkShown);+ }++ /// <summary>A restart (New Game's Begin) and the language switch build every presenter again over the same document:+ /// one key press is still one pick, and no ring is left over from before.</summary>+ [UnityTest]+ public IEnumerator ARestartOrALanguageSwitchLeavesOnePickAndNoStaleRing()+ {+ yield return Boot();+ yield return FocusOn(Stop);+ root.Begin(Inputs, 0); // a restart over the same document+ GameSceneTests.HideTheOpeningCard(ui);+ LookAtTelAviv();+ yield return Frames(3);+ if (Focused != Stop) Assert.IsFalse(MarkShown, "no ring left without the focus");++ root.Language = UiLanguage.Hebrew; // the language switch's Begin, over this game+ root.Begin(Inputs, 0);+ GameSceneTests.HideTheOpeningCard(ui);+ LookAtTelAviv();+ yield return Frames(3);+ Assert.AreEqual(TextHe["info.hint"], ui.Q<Label>("info-title").text, "precondition: the Hebrew build");+ Assert.IsFalse(Focused == Stop && !Stop.canGrabFocus, "the focus is not left on a disabled stop");++ var pointer = Object.FindFirstObjectByType<MapPointer>();+ var picked = 0;+ Action<int, int> onPick = (q, r) => picked++;+ pointer.HexClicked += onPick;+ try+ {+ yield return FocusOn(Stop);+ yield return Frames(2);+ Assert.IsTrue(MarkShown, "the ring shows again");+ Assert.AreEqual(LookAtOnPanel().x, Mark.worldBound.center.x, 2f, "at the look-at point");+ yield return Key(KeyCode.Return);+ Assert.AreEqual(1, picked, "one Enter, one pick: no handler is left from the earlier builds");+ yield return Key(KeyCode.Space);+ Assert.AreEqual(2, picked, "one Space, one pick");+ }+ finally { pointer.HexClicked -= onPick; root.Language = null; }+ }++ /// <summary>The hint names the keyboard way in both languages and keeps the mouse's right-drag.</summary>+ [Test]+ public void TheHintNamesTabAndEnterAndKeepsRightDrag()+ {+ StringAssert.Contains("Tab", Text["info.hint"]);+ StringAssert.Contains("Enter", Text["info.hint"]);+ StringAssert.Contains("right-drag", Text["info.hint"]);+ StringAssert.Contains("Tab", TextHe["info.hint"]);+ StringAssert.Contains("Enter", TextHe["info.hint"]);+ StringAssert.Contains("גרירה", TextHe["info.hint"]);+ }++ static float Luminance(Color c) => 0.2126f * c.linear.r + 0.7152f * c.linear.g + 0.0722f * c.linear.b;+ static float Contrast(float x, float y) => (Mathf.Max(x, y) + 0.05f) / (Mathf.Min(x, y) + 0.05f);++ /// <summary>WCAG 1.4.11: the ring is gold-light between two dark outlines, so against any map colour one of its two+ /// colours keeps at least 3:1 (the worst background, a mid grey of luminance 0.14, still gets 3.4:1); the map's own sea,+ /// sand and ground colours are checked by name, and the gold against its outline. Colours as the stylesheet resolves+ /// them on the focused stop.</summary>+ [UnityTest]+ public IEnumerator TheRingKeepsThreeToOneOnAnyMapColour()+ {+ using var kit = new UiTestKit();+ kit.Q<VisualElement>("root").RemoveFromClassList("loading");+ var stop = kit.Q<VisualElement>("map-focus");+ stop.Focus();+ for (int i = 0; i < 10; i++) yield return null;+ var outer = kit.Q<VisualElement>("map-focus-mark").resolvedStyle;+ var ring = kit.Q<VisualElement>("map-focus-mark").Q(className: "map-focus-ring").resolvedStyle;+ Assert.Greater(outer.borderTopWidth, 0f, "a dark outline");+ Assert.Greater(ring.borderTopWidth, 0f, "a gold ring");+ float gold = Luminance(ring.borderTopColor), dark = Luminance(outer.borderTopColor);+ Assert.GreaterOrEqual(Contrast(gold, dark), 3f, "the gold against its own outline");+ var worst = float.MaxValue;+ for (int i = 0; i <= 1000; i++)+ {+ var l = i / 1000f;+ worst = Mathf.Min(worst, Mathf.Max(Contrast(gold, l), Contrast(dark, l)));+ }+ Assert.GreaterOrEqual(worst, 3f, $"the worst map colour leaves {worst:0.00}:1");+ var named = new Dictionary<string, Color>+ {+ ["sea (the clear colour)"] = MapBuilder.BiomeColours["sea"],+ ["sand (desert ground)"] = MapPalette.Ground["desert"],+ ["coastal plain ground"] = MapPalette.Ground["coastal_plain"],+ ["hills ground"] = MapPalette.Ground["hills"],+ };+ foreach (var (name, c) in named)+ {+ var best = Mathf.Max(Contrast(gold, Luminance(c)), Contrast(dark, Luminance(c)));+ Assert.GreaterOrEqual(best, 3f, $"{name}: {best:0.00}:1");+ Debug.Log(FormattableString.Invariant($"MAPFOCUS contrast {name}: gold {Contrast(gold, Luminance(c)):0.00}, outline {Contrast(dark, Luminance(c)):0.00}"));+ }+ Debug.Log(FormattableString.Invariant($"MAPFOCUS contrast worst case {worst:0.00}, gold vs outline {Contrast(gold, dark):0.00}"));+ }+}++/// <summary>#41 B1b: the camera keys through the Input System's own path (a virtual keyboard from its test fixture and the+/// project-wide Camera actions), with the map stop focused and its presenter listening: the same keys reach the stop as+/// UI key events, the camera still pans, the focus stays on the stop and nothing is picked. Synchronous, as InputTestFixture allows in edit mode.</summary>+public class MapFocusCameraKeysTests : InputTestFixture+{+ static void Send(MonoBehaviour c, string message) =>+ c.GetType().GetMethod(message, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!.Invoke(c, null);++ [Test]+ public void TheCameraKeysStillPanWithTheStopFocused()+ {+ InputSystem.actions = AssetDatabase.LoadAssetAtPath<InputActionAsset>("Assets/InputSystem_Actions.inputactions");+ var keyboard = InputSystem.AddDevice<Keyboard>();+ using var kit = new UiTestKit();+ kit.Q<VisualElement>("root").RemoveFromClassList("loading");+ var stop = kit.Q<VisualElement>("map-focus");+ stop.Focus();+ Assert.AreSame(stop, kit.Root.panel.focusController.focusedElement, "precondition: the stop has the focus");+ var go = new GameObject("MapFocusKeys", typeof(Camera));+ var rig = go.AddComponent<CameraRig>();+ rig.LookAt = new Vector3(500000, 0, 500000); rig.Distance = 100000f;+ var c = go.AddComponent<CameraController>();+ c.Bounds = new Rect(0, 0, 1000000, 1000000);+ var picked = 0;+ var presenter = new MapFocusPresenter(kit.Root, go.GetComponent<Camera>(), rig, _ => picked++);+ Send(c, "Awake"); Send(c, "OnEnable");+ try+ {+ var from = rig.LookAt;+ var pan = InputSystem.actions.FindAction("Camera/Pan", true);+ // CameraController's frame with a fixed step: edit mode's Time.unscaledDeltaTime is not a frame's+ void Frame() => CameraController.Step(rig, c.Gather(pan.ReadValue<Vector2>(), Vector2.zero, 0, 0, false, null), 0.1f, c.Bounds);+ // the UI gets the same keys as KeyDownEvents on the focused stop+ void UiKey(KeyCode k) { using (var e = KeyDownEvent.GetPooled('\0', k, EventModifiers.None)) { e.target = stop; stop.SendEvent(e); } }+ Press(keyboard.dKey); UiKey(KeyCode.D);+ for (int i = 0; i < 5; i++) Frame();+ Release(keyboard.dKey);+ Press(keyboard.upArrowKey); UiKey(KeyCode.UpArrow);+ for (int i = 0; i < 5; i++) Frame();+ Release(keyboard.upArrowKey);+ Assert.AreNotEqual(from, rig.LookAt, "D and Up still pan the camera");+ Assert.AreSame(stop, kit.Root.panel.focusController.focusedElement, "the focus stays on the stop");+ Assert.AreEqual(0, picked, "a pan picks nothing");+ }+ finally { presenter.Dispose(); Send(c, "OnDisable"); Object.DestroyImmediate(go); }+ }+}diff --git a/unity/Assets/Tests/EditMode/MapFocusTests.cs.meta b/unity/Assets/Tests/EditMode/MapFocusTests.cs.metanew file mode 100644index 000000000..1c80ce28b--- /dev/null+++ b/unity/Assets/Tests/EditMode/MapFocusTests.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 94d9c6a6a7aa768a8b4a9e5f351a8bce\ No newline at end of filediff --git a/unity/Assets/Tests/EditMode/MinimapReliefTests.cs b/unity/Assets/Tests/EditMode/MinimapReliefTests.csindex e9f33642d..cf6da7e1a 100644--- a/unity/Assets/Tests/EditMode/MinimapReliefTests.cs+++ b/unity/Assets/Tests/EditMode/MinimapReliefTests.cs@@ -175,11 +175,13 @@ public class MinimapReliefTestsAssert.GreaterOrEqual(bt.tabIndex, 0, $"{at}: {bt.name} is in the Tab order");Assert.AreEqual(text[keys[i]], bt.tooltip, $"{at}: {bt.name} has its name");}- // Tree order is Tab order: End Turn, then the three buttons, then nothing else of the minimap.+ // Tree order is Tab order: End Turn, the map's keyboard stop (#41 B1b), then the three buttons, then nothing else+ // of the minimap.var order = root.Query<VisualElement>().Where(e => e.focusable && e.canGrabFocus && e.tabIndex >= 0).ToList().Select(e => e.name).ToList();int end = order.IndexOf("end-turn");Assert.GreaterOrEqual(end, 0, at + ": End Turn takes focus");- CollectionAssert.AreEqual(ButtonNames, order.Skip(end + 1).Take(3).ToArray(), $"{at}: the Tab order after End Turn: {string.Join(", ", order)}");+ Assert.AreEqual("map-focus", order.ElementAtOrDefault(end + 1), $"{at}: the map stop follows End Turn: {string.Join(", ", order)}");+ CollectionAssert.AreEqual(ButtonNames, order.Skip(end + 2).Take(3).ToArray(), $"{at}: the Tab order after End Turn: {string.Join(", ", order)}");});}diff --git a/unity/Assets/Tests/EditMode/Statecraft.Tests.EditMode.asmdef b/unity/Assets/Tests/EditMode/Statecraft.Tests.EditMode.asmdefindex 58def7824..ea9881bf1 100644--- a/unity/Assets/Tests/EditMode/Statecraft.Tests.EditMode.asmdef+++ b/unity/Assets/Tests/EditMode/Statecraft.Tests.EditMode.asmdef@@ -1 +1 @@-{ "name": "Statecraft.Tests.EditMode", "references": ["Statecraft.Game", "Unity.RenderPipelines.Core.Runtime", "Unity.RenderPipelines.Universal.Runtime", "Unity.InputSystem", "UnityEngine.TestRunner", "UnityEditor.TestRunner"], "includePlatforms": ["Editor"], "overrideReferences": true, "precompiledReferences": ["nunit.framework.dll", "Statecraft.Sim.dll", "YamlDotNet.dll"], "defineConstraints": ["UNITY_INCLUDE_TESTS"] }+{ "name": "Statecraft.Tests.EditMode", "references": ["Statecraft.Game", "Unity.RenderPipelines.Core.Runtime", "Unity.RenderPipelines.Universal.Runtime", "Unity.InputSystem", "Unity.InputSystem.TestFramework", "UnityEngine.TestRunner", "UnityEditor.TestRunner"], "includePlatforms": ["Editor"], "overrideReferences": true, "precompiledReferences": ["nunit.framework.dll", "Statecraft.Sim.dll", "YamlDotNet.dll"], "defineConstraints": ["UNITY_INCLUDE_TESTS"] }diff --git a/unity/Assets/UI/Game.uxml b/unity/Assets/UI/Game.uxmlindex 91e939d38..b6cec91b2 100644--- a/unity/Assets/UI/Game.uxml+++ b/unity/Assets/UI/Game.uxml@@ -97,6 +97,17 @@<ui:Button name="end-turn" text="End turn" class="end-turn" /></ui:VisualElement></ui:VisualElement>+ <!-- The map's keyboard stop (#41 B1b, #1116): after End Turn in the Tab order, before the minimap's buttons and the+ info panel's actions. It takes no pointer (clicks and taps fall through to the map); while it has the focus a+ gold ring with a dark outline marks the camera's look-at point (MapFocusPresenter places it), and Enter or+ Space picks the hex under it. ScreenNav.DisableCovered takes it out of reach with the info panel. -->+ <ui:VisualElement name="map-focus" class="map-focus" focusable="true" tabindex="0" picking-mode="Ignore">+ <ui:VisualElement name="map-focus-mark" class="map-focus-mark" picking-mode="Ignore">+ <ui:VisualElement class="map-focus-ring" picking-mode="Ignore">+ <ui:VisualElement class="map-focus-inner" picking-mode="Ignore" />+ </ui:VisualElement>+ </ui:VisualElement>+ </ui:VisualElement><!-- The right-hand column: the minimap, with the border layer's caption beside it. --><ui:VisualElement name="right-column" class="right-column" picking-mode="Ignore"><ui:VisualElement class="right-gap" picking-mode="Ignore" />diff --git a/unity/Assets/UI/Statecraft.uss b/unity/Assets/UI/Statecraft.ussindex 882f20e34..f467b0447 100644--- a/unity/Assets/UI/Statecraft.uss+++ b/unity/Assets/UI/Statecraft.uss@@ -658,6 +658,19 @@ Button.settings-choice-selected { -unity-font-definition: url("project://databason the marker's top. Hidden while the game loads. */.map-labels { position: absolute; left: 0; top: 0; right: 0; bottom: 0; }.loading .map-labels { display: none; }+/* The map's keyboard stop (#41 B1b, #1116): the whole map area, invisible; only its ring shows, and only while the stop+ has the keyboard focus (and is enabled: ScreenNav disables it under a covering screen). The ring is gold-light between+ two navy-deep outlines, so one of its colours keeps >= 3:1 against any map colour (WCAG 1.4.11; MapFocusTests). The+ outlines are 3 panel px so they stay two screen px at 1280x720 (the panel draws at about 2/3 there).+ MapFocusPresenter puts left/top on the camera's look-at point; the translate centres the ring there. */+.map-focus { position: absolute; left: 0; top: 0; right: 0; bottom: 0; }+.map-focus-mark {+ display: none; position: absolute; width: 40px; height: 40px; translate: -50% -50%;+ border-width: 3px; border-color: var(--navy-deep); border-radius: 20px;+}+.map-focus:focus:enabled > .map-focus-mark { display: flex; }+.map-focus-ring { flex-grow: 1; border-width: 4px; border-color: var(--gold-light); border-radius: 17px; }+.map-focus-inner { flex-grow: 1; border-width: 3px; border-color: var(--navy-deep); border-radius: 13px; }.map-label-slot { position: absolute; left: 0; top: 0; width: 0; height: 0; overflow: visible; }.map-label {position: absolute;diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yamlindex 41e04015c..049a764cd 100644--- a/unity/Assets/UI/strings.en.yaml+++ b/unity/Assets/UI/strings.en.yaml@@ -217,7 +217,8 @@ defence.section_leadership: "Leadership"defence.section_ladder: "Security level"defence.section_callup: "Reserve call-up"defence.section_budget: "Defence share of the budget"-info.hint: "Click the map to inspect a hex"+# The empty info panel's hint: the mouse, the keyboard's map stop (#41 B1b, #1116) and the right-drag pan (#998).+info.hint: "Click the map, or Tab to it and press Enter, to inspect a hex; right-drag to move the map"info.off_map: "Off the map"info.hex: "{0} · elevation {1:N0} m"info.region: "{0}, {1} (Mandate sub-districts, 1947)"diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yamlindex 805518344..506246306 100644--- a/unity/Assets/UI/strings.he.yaml+++ b/unity/Assets/UI/strings.he.yaml@@ -212,7 +212,9 @@ card.offices_separator: " · "# The tag on the selected Cabinet seat's card (PersonCard; #41 M6). Not "נבחר": on a minister's card in a game about the# Knesset it reads as "elected". "מסומן" agrees with the card (כרטיס), masculine. For the native reviewer (#564).card.selected: "מסומן"-info.hint: "יש ללחוץ על המפה כדי לבדוק משושה"+# The empty info panel's hint: a click, or Tab to the map's stop and Enter (#41 B1b, #1116), and the right-drag pan (#998).+# "Tab" and "Enter" are the keys' printed names. For the native reviewer (#564).+info.hint: "יש ללחוץ על המפה, או לעבור אליה ב־Tab וללחוץ Enter, כדי לבדוק משושה; גרירה בלחצן הימני מזיזה את המפה"info.off_map: "מחוץ למפה"info.hex: "{0} · גובה {1:N0} מ׳"info.region: "{0}, {1} (נפות המנדט, 1947)"