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: a screen closed with its X by the mouse leaves no tip on its rail button (Fixes #1323) (#1354)

Eyal Golan8c126f2b485b
diff --git a/changelog.d/rail-tip-after-close-1323.md b/changelog.d/rail-tip-after-close-1323.md
new file mode 100644
index 000000000..47682122f
--- /dev/null
+++ b/changelog.d/rail-tip-after-close-1323.md
@@ -0,0 +1,4 @@
+### Fixed
+- Closing a screen (Cabinet, Budget, Objectives and the rest) with its X by mouse or touch no longer lights up its button
+ in the left column and pops up the button's name beside it. Closed from the keyboard, the focus still goes back to
+ that button and its name still shows (#1323).
diff --git a/unity/Assets/Scripts/UI/ScreenNav.cs b/unity/Assets/Scripts/UI/ScreenNav.cs
index e844690bd..e8888a5c7 100644
--- a/unity/Assets/Scripts/UI/ScreenNav.cs
+++ b/unity/Assets/Scripts/UI/ScreenNav.cs
@@ -170,6 +170,7 @@ namespace Statecraft.Game.UI
readonly List<Button> closes = new List<Button>();
readonly EventCallback<NavigationCancelEvent> onCancel;
readonly EventCallback<GeometryChangedEvent> onGeometry;
+ readonly PressSource presses;
/// <summary>A layer over the screens that takes Escape first (GameRoot: the report panel, #1169, and the share panel, #1170): true when it used the
/// key, and the open screen under it stays open. This handler trickles down from the root, so it runs before the layer's own.</summary>
@@ -185,6 +186,7 @@ namespace Statecraft.Game.UI
root.RegisterCallback(onCancel, TrickleDown.TrickleDown);
onGeometry = e => FitCloseButtons();
root.RegisterCallback(onGeometry);
+ presses = new PressSource(root);
foreach (var s in Screens)
{
var screen = s;
@@ -194,10 +196,12 @@ namespace Statecraft.Game.UI
hooks.Add((b, h));
// an X on the screen itself closes it: a phone has no Escape, and re-tapping the lit rail button is not
- // discoverable (playtest v0.1.1). The same Close() as Escape, so the focus return is identical.
+ // discoverable (playtest v0.1.1). The same Close as Escape: pressed from the keyboard, the focus returns as
+ // after Escape; pressed with the pointer it moves nowhere (PointerBlur's rule), else the rail button would
+ // light up and show its tip (#1323).
var header = root.Q("screen-" + screen)?.Q(className: "screen-header");
if (header == null) continue;
- var x = new Button(() => Close()) { name = "screen-close-" + screen, text = "X" };
+ var x = new Button(() => Close(handFocus: presses.ByKeyboard)) { name = "screen-close-" + screen, text = "X" };
x.AddToClassList("screen-close");
header.Add(x);
closes.Add(x);
@@ -253,6 +257,7 @@ namespace Statecraft.Game.UI
closes.Clear();
root.UnregisterCallback(onCancel, TrickleDown.TrickleDown);
root.UnregisterCallback(onGeometry);
+ presses.Dispose();
var r = root.Q("root") ?? root;
r.RemoveFromClassList(WideOpenClass); r.RemoveFromClassList(ScreenOpenClass);
DisableCovered(root);
@@ -261,14 +266,17 @@ namespace Statecraft.Game.UI
/// <summary>Closes the open screen (Escape); false when none was open. When the focus was on the screen's contents it
/// goes to the screen's top-bar button, so the next Tab carries on from there (#41 M1); an open decision card
/// takes it instead (EventCardPresenter, when its cover closes).</summary>
- public bool Close()
+ public bool Close() => Close(handFocus: true);
+
+ /// <param name="handFocus">False when the screen's X was pressed with the pointer: the focus is not handed on.</param>
+ bool Close(bool handFocus)
{
if (Current == null) return false;
var screen = root.Q<VisualElement>("screen-" + Current); var button = root.Q<Button>("nav-" + Current);
var focused = root.panel?.focusController?.focusedElement as VisualElement;
var inside = focused != null && (focused == screen || screen.Contains(focused));
Open(null);
- if (inside && !(root.Q("root") ?? root).ClassListContains(EventCardPresenter.ModalClass)) FocusReturn.To(button);
+ if (handFocus && inside && !(root.Q("root") ?? root).ClassListContains(EventCardPresenter.ModalClass)) FocusReturn.To(button);
return true;
}
diff --git a/unity/Assets/Tests/EditMode/LeftColumnTests.cs b/unity/Assets/Tests/EditMode/LeftColumnTests.cs
index 1d3c42dfb..92dd4d991 100644
--- a/unity/Assets/Tests/EditMode/LeftColumnTests.cs
+++ b/unity/Assets/Tests/EditMode/LeftColumnTests.cs
@@ -310,6 +310,58 @@ public class LeftColumnTests
Assert.IsEmpty(problems, string.Join("\n", problems));
}
+ /// <summary>#1323 (owner, v0.2.0): a screen closed with its X by the mouse hands no focus on (PointerBlur's rule), so its
+ /// button in the column shows neither its tip nor the focus fill. Closed from the keyboard (Escape, even after a mouse
+ /// press on the X; Enter on the X) the focus goes back to that button and its tip shows, and Tab moves the tip on.</summary>
+ [UnityTest]
+ public IEnumerator ClosingAScreenWithTheMouseShowsNoTipAndTheKeyboardKeepsIt()
+ {
+ var problems = new List<string>();
+ var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
+ yield return Rendered(1280, 720, false, g, (root, nav) =>
+ {
+ var tip = root.Q<Label>(HoverTip.TipName);
+ var focus = root.panel.focusController;
+ // HoverTip shows the tip inline (display: flex) and hides it inline; with no inline value the stylesheet hides it
+ bool Shown() => tip.style.display.keyword == StyleKeyword.Undefined && tip.style.display.value == DisplayStyle.Flex;
+ bool TipFor(VisualElement b) => Shown() && tip.text == b.tooltip;
+ Assert.IsFalse(root.Q("root").ClassListContains(EventCardPresenter.ModalClass), "precondition: the decision card is hidden (open, it takes the focus when a screen closes)");
+ foreach (var s in ScreenNav.Screens)
+ {
+ var button = root.Q<Button>("nav-" + s); var x = root.Q<Button>("screen-close-" + s);
+ nav.Open(s);
+ PressWithPointer(x);
+ if (nav.Current != null) problems.Add($"{s}: the X pressed with the mouse closes the screen");
+ if (focus.focusedElement == button) problems.Add($"{s}: the X pressed with the mouse puts the focus on {button.name}");
+ if (Shown()) problems.Add($"{s}: the X pressed with the mouse shows the tip '{tip.text}'");
+
+ nav.Open(s); x.Focus();
+ using (var e = NavigationCancelEvent.GetPooled()) { e.target = x; x.SendEvent(e); }
+ if (nav.Current != null || focus.focusedElement != button || !TipFor(button)) problems.Add($"{s}: Escape after a mouse press gives {button.name} the focus and its tip");
+
+ nav.Open(s); x.Focus(); UiTestKit.Press(x);
+ if (nav.Current != null || focus.focusedElement != button || !TipFor(button)) problems.Add($"{s}: Enter on the X gives {button.name} the focus and its tip");
+
+ using (var e = NavigationMoveEvent.GetPooled(NavigationMoveEvent.Direction.Next)) { e.target = button; button.SendEvent(e); }
+ var next = focus.focusedElement as VisualElement;
+ if (next == null || next == button || !TipFor(next)) problems.Add($"{s}: Tab from {button.name} moves the tip to the next button (focus on {next?.name ?? "nothing"}, tip '{tip.text}')");
+ }
+ }, act: (root, nav) => UiTestKit.Press(root.Q<Button>("event-hide"))); // turn 0's card (One Army) put behind "Decision waiting", as the owner had it
+ Assert.IsEmpty(problems, string.Join("\n", problems));
+ }
+
+ /// <summary>A mouse press as the player makes it (StartScreenTests' helper): pointer down, which also gives the button the
+ /// focus, then the button's Clickable fires `clicked` on pointer up. UiTestKit.Press is the keyboard's Submit instead.</summary>
+ static void PressWithPointer(Button b)
+ {
+ b.Focus();
+ using (var down = PointerDownEvent.GetPooled()) { down.target = b; b.SendEvent(down); }
+ using var click = ClickEvent.GetPooled();
+ click.target = b;
+ typeof(Clickable).GetMethod("Invoke", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic,
+ null, new[] { typeof(EventBase) }, null)!.Invoke(b.clickable, new object[] { click });
+ }
+
/// <summary>#1109: the Cabinet disc wears a small gold badge, and its tip says why, while the sim has a vacant seat the
/// player can fill this turn (SimBridge.Vacancies, Cabinet.Vacancies); queuing an appointment to every such seat takes
/// it off. No other disc has a badge. Education is vacant from 19 May 1951 (as Minority Affairs, which has no holder