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: a keyboard map pick that opens the Move confirmation focuses it (Refs #2340) (#2912)

Beridd56e9db869a
diff --git a/changelog.d/2340-move-confirmation-focus.md b/changelog.d/2340-move-confirmation-focus.md
new file mode 100644
index 000000000..8ea10726a
--- /dev/null
+++ b/changelog.d/2340-move-confirmation-focus.md
@@ -0,0 +1,5 @@
+### Fixed
+
+- Picking a friendly unit's hex or a city with the keyboard, to send the selected unit there, now puts the focus on
+ the "Send ... to ..." confirmation, so Enter takes it. It used to be several Tabs away. A pick with the pointer
+ moves no focus, as before. (#2340)
diff --git a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
index 61727d2e3..246febc20 100644
--- a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
+++ b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
@@ -145,6 +145,8 @@ namespace Statecraft.Game.UI
gdd = panel.Q<VisualElement>(GddHexPanel.HostName);
projects = panel.Q<VisualElement>(GddHexPanel.ProjectsHostName);
mapFocus = root.Q<VisualElement>("map-focus");
+ mapFocus?.RegisterCallback<NavigationSubmitEvent>(OnStopSubmit, TrickleDown.TrickleDown);
+ mapFocus?.RegisterCallback<KeyDownEvent>(OnStopKey, TrickleDown.TrickleDown);
foreach (var row in panel.Query(className: RowClass).ToList()) rows.Add((row, row.Q<Label>()));
campButton = panel.Q<Button>("build-camp"); housingButton = panel.Q<Button>("build-housing");
onCamp = () => Build(MapActions.TransitCamp); onHousing = () => Build(MapActions.Housing);
@@ -190,7 +192,7 @@ namespace Statecraft.Game.UI
void OnHudGeometry(GeometryChangedEvent e) => panel.EnableInClassList(ShortClass, e.newRect.height < ShortBelowPx);
/// <summary>Unsubscribes from the bridge and the buttons (the owner calls this when disabled).</summary>
- public void Dispose() { pioneerReturn.clicked -= onPioneerReturn; pioneerList.Clear(); panel.UnregisterCallback(onCancel); presses.Dispose(); bridge.Changed -= OnStateChanged; ScreenNav.InfoIntentCovered -= OnInfoCovered; confirmMove.UnregisterCallback<KeyDownEvent>(OnConfirmKey); confirmMove.clicked -= ConfirmMove; confirmMove.RemoveFromHierarchy(); panel.parent?.UnregisterCallback<GeometryChangedEvent>(OnHudGeometry); campButton.clicked -= onCamp; housingButton.clicked -= onHousing; defenceButton.clicked -= onDefence; moveButton.clicked -= onMove; fortifyButton.clicked -= onFortify; holdButton.clicked -= onHold; attackButton.clicked -= onAttack; sendHomeButton.clicked -= onSendHome; skipButton.clicked -= onSkip; reinforceButton.clicked -= onReinforce; EndPick(); }
+ public void Dispose() { mapFocus?.UnregisterCallback<NavigationSubmitEvent>(OnStopSubmit, TrickleDown.TrickleDown); mapFocus?.UnregisterCallback<KeyDownEvent>(OnStopKey, TrickleDown.TrickleDown); pioneerReturn.clicked -= onPioneerReturn; pioneerList.Clear(); panel.UnregisterCallback(onCancel); presses.Dispose(); bridge.Changed -= OnStateChanged; ScreenNav.InfoIntentCovered -= OnInfoCovered; confirmMove.UnregisterCallback<KeyDownEvent>(OnConfirmKey); confirmMove.clicked -= ConfirmMove; confirmMove.RemoveFromHierarchy(); panel.parent?.UnregisterCallback<GeometryChangedEvent>(OnHudGeometry); campButton.clicked -= onCamp; housingButton.clicked -= onHousing; defenceButton.clicked -= onDefence; moveButton.clicked -= onMove; fortifyButton.clicked -= onFortify; holdButton.clicked -= onHold; attackButton.clicked -= onAttack; sendHomeButton.clicked -= onSendHome; skipButton.clicked -= onSkip; reinforceButton.clicked -= onReinforce; EndPick(); }
/// <summary>Below this window height (logical px; 1366x657 is about 998) the panel gets ShortClass, and the city's own
/// hex folds its projects behind their toggle as on a stacked bar (GddHexPanel.ToggleName): there the full list ran into
@@ -511,6 +513,12 @@ namespace Statecraft.Game.UI
/// even while Move picks (owner, 25 Oct 2026: "Clicking another unit or a city still selects it").</summary>
public bool IsCity(int q, int r) => GameRoot.CityAt(bridge.Content, bridge.State, q, r) != null;
+ // True for the one event dispatch of an Enter or Space on the map stop: the pick it makes (MapFocusPresenter) runs inside it.
+ bool stopPress;
+ void OnStopSubmit(NavigationSubmitEvent e) => FlagStopPress();
+ void OnStopKey(KeyDownEvent e) { if (e.keyCode == UnityEngine.KeyCode.Space) FlagStopPress(); }
+ void FlagStopPress() { stopPress = true; mapFocus!.schedule.Execute(() => stopPress = false); }
+
void DiscardMove()
{
pendingMove = null;
@@ -555,6 +563,9 @@ namespace Statecraft.Game.UI
pendingMove = (command, p.session, p.turn);
confirmMove.text = text.Format("unit.confirm_move", mover, target);
confirmMove.style.display = DisplayStyle.Flex;
+ // A pick made at the map stop (its Enter or Space) is a keyboard pick: the offer takes the focus, so Enter
+ // takes it and it is not several Tabs away (#2340). A pointer pick gets none, even while the stop still has it.
+ if (stopPress) FocusReturn.To(confirmMove);
};
}
diff --git a/unity/Assets/Tests/EditMode/KeyboardOrdersTests.cs b/unity/Assets/Tests/EditMode/KeyboardOrdersTests.cs
index 8886918e1..ca614b310 100644
--- a/unity/Assets/Tests/EditMode/KeyboardOrdersTests.cs
+++ b/unity/Assets/Tests/EditMode/KeyboardOrdersTests.cs
@@ -46,7 +46,7 @@ public class KeyboardOrdersTests
/// <summary>Map.unity on a 1280x720 panel, a new GDD game begun as GameBoot.Ready does with no start screen, and the
/// opening turn's two event cards (One Army, then the defence of Degania, R-EVT-006) answered from the keyboard (the
/// first hands the focus to the second, the second to End Turn).</summary>
- IEnumerator Boot()
+ IEnumerator Boot(string? language = null)
{
EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
var doc = Object.FindFirstObjectByType<UIDocument>();
@@ -57,6 +57,7 @@ public class KeyboardOrdersTests
Object.FindFirstObjectByType<MapScene>().Build(MapFocusTests.Inputs.Map);
root = Object.FindFirstObjectByType<GameRoot>();
root.Store = new SaveStore(saveDir);
+ root.Language = language;
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;
@@ -103,8 +104,9 @@ public class KeyboardOrdersTests
IEnumerator TabTo(string name) => TabTo(v => v.name == name, name);
- /// <summary>Tab to the map stop, pan the hex (q, r) under its ring, Enter.</summary>
- IEnumerator EnterOnTheMapAt(int q, int r)
+ /// <summary>Tab to the map stop, pan the hex (q, r) under its ring, Enter. <paramref name="stays"/>: where the focus is
+ /// afterwards (the map stop, or the Move confirmation when the pick offers it).</summary>
+ IEnumerator EnterOnTheMapAt(int q, int r, string stays = "map-focus")
{
yield return TabTo("map-focus");
var map = Object.FindFirstObjectByType<MapScene>();
@@ -116,7 +118,7 @@ public class KeyboardOrdersTests
rig.Apply();
yield return Frames(3);
yield return Enter();
- Assert.AreEqual("map-focus", FocusedName, "the focus stays on the map stop");
+ Assert.AreEqual(stays, FocusedName, stays == "map-focus" ? "the focus stays on the map stop" : "the focus is on " + stays);
}
/// <summary>Selects Golani from the keyboard (Enter on the map stop over its hex) and hands back its sim id.</summary>
@@ -204,7 +206,7 @@ public class KeyboardOrdersTests
}
var expected = layer.UnitToSelectAt(target.q, target.r);
var near = Movement.Reachable(c, s, id, Bridge.Spent).ContainsKey((target.q, target.r));
- yield return EnterOnTheMapAt(target.q, target.r);
+ yield return EnterOnTheMapAt(target.q, target.r, stays: "info-confirm-move"); // #2340: the offer takes the focus, no Tab
Assert.IsEmpty(Bridge.Session.Committed, "the pick itself gives no order");
Assert.AreEqual(expected, layer.Selected, "ordinary selection stays");
var send = ui.Q<Button>("info-confirm-move");
@@ -227,4 +229,24 @@ public class KeyboardOrdersTests
u.OrderTarget, "beyond reach: Golani's go-to");
Assert.AreEqual(DisplayStyle.None, send.resolvedStyle.display, "the offer is used up");
}
+
+ /// <summary>#2340: a keyboard pick that opens the Move confirmation puts the focus on it, so Enter takes it with no Tab
+ /// (it was several Tabs away). English and Hebrew.</summary>
+ [UnityTest]
+ public IEnumerator AKeyboardPickThatOffersTheMoveFocusesTheOffer([Values(false, true)] bool hebrew)
+ {
+ yield return Boot(hebrew ? UiLanguage.Hebrew : UiLanguage.English);
+ var id = -1;
+ yield return SelectGolani(i => id = i);
+ var layer = Object.FindFirstObjectByType<UnitLayer>();
+ var city = Bridge.Content.SettlementHexes.First(x => x.Id == "tel_aviv" && layer.UnitToSelectAt(x.Q, x.R) == null);
+ yield return EnterOnTheMapAt(city.Q, city.R, stays: "info-confirm-move");
+ var send = ui.Q<Button>("info-confirm-move");
+ Assert.AreEqual(DisplayStyle.Flex, send.resolvedStyle.display, "the offer shows");
+ Assert.AreEqual(hebrew, send.text.Any(ch => ch >= '\u0590' && ch <= '\u05FF'), "the offer is in the game's language");
+ Assert.IsEmpty(Bridge.Session.Committed, "focusing the offer gives no order");
+ yield return Enter();
+ Assert.AreEqual(1, Bridge.Session.Committed.Count, "Enter on the focused offer gives Golani's order");
+ Assert.AreEqual("map-focus", FocusedName, "the focus goes back to the map stop, as before");
+ }
}
diff --git a/unity/Assets/Tests/EditMode/SelectThenClickMoveTests.cs b/unity/Assets/Tests/EditMode/SelectThenClickMoveTests.cs
index 1dfce7edc..42f299179 100644
--- a/unity/Assets/Tests/EditMode/SelectThenClickMoveTests.cs
+++ b/unity/Assets/Tests/EditMode/SelectThenClickMoveTests.cs
@@ -367,12 +367,14 @@ public class SelectThenClickMoveTests
// The tapped hex is where B's token is drawn (its anchor), which can differ from B's sim hex.
var from = rig.At(id); (int q, int r) target = (pair.b.Q, pair.b.R); var otherAt = rig.At(other);
rig.Select(pair.a);
+ var stop = rig.Ui.Root.Q("map-focus"); stop.Focus(); // Tabbed there, then clicked on the map
rig.Click(target.q, target.r, touch);
Assert.IsEmpty(rig.Bridge.Session.Committed, "selection itself gives no order");
Assert.AreEqual(pair.b.Token.Unit.Id, rig.Layer.Selected, "ordinary selection stays");
var send = rig.Ui.Root.Q<Button>("info-confirm-move");
Assert.IsNotNull(send, "a visible confirmation is offered");
Assert.AreEqual(DisplayStyle.Flex, send.style.display.value);
+ Assert.AreSame(stop, rig.Ui.Root.panel.focusController.focusedElement, "a pointer pick moves no focus, even from the map stop (#2340)");
StringAssert.Contains(UnitCard.For(pair.a, rig.Bridge.State, Text, C.IsGdd, C).Title, send.text);
StringAssert.Contains(HexPlaces.Of(string.Format(System.Globalization.CultureInfo.InvariantCulture,
"{0},{1}", target.q, target.r), C, Text, null), send.text);