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.

Hebrew: direction as texts join the panel; tour Next keeps focus after a switch (Refs #1915) (#1918)

agamrafaeli-instinct4442a7db0620
diff --git a/changelog.d/1915.md b/changelog.d/1915.md
new file mode 100644
index 000000000..b02176ada
--- /dev/null
+++ b/changelog.d/1915.md
@@ -0,0 +1,7 @@
+- Hebrew at startup (#1915): the city panel's lines and project buttons are now written where they stand (GddHexPanel's
+ Line and Button set the words once the element is on the panel), so each takes its paragraph direction at once and a
+ city panel opened in a game started in Hebrew reads its Hebrew-and-number lines and project buttons in the right
+ order from the first frame, as they already did after a language switch; and a language switch partway through the
+ opening tour hands the Next button its focus (and its gold focus fill) back once no screen is open over it, so Enter
+ goes on. Settings' language switch now also retries the choice's focus a frame later, so the reopened screen
+ really takes it (#1036 end to end).
diff --git a/unity/Assets/Scripts/UI/AdvisorPresenter.cs b/unity/Assets/Scripts/UI/AdvisorPresenter.cs
index d27c97a92..b9cf071a3 100644
--- a/unity/Assets/Scripts/UI/AdvisorPresenter.cs
+++ b/unity/Assets/Scripts/UI/AdvisorPresenter.cs
@@ -87,6 +87,14 @@ namespace Statecraft.Game.UI
IVisualElementScheduledItem? fading;
float flooredFor;
bool disposed, hidden = true;
+ /// <summary>Set when a rebuild resumes a tour while a screen is open (#1915): the next uncover hands Next
+ /// the focus once, instead of every cover change (a resize, a meter's width) moving it. Cleared when it fires
+ /// and when the chain opens or closes, so a finished tour cannot hand its pending focus to the next one.</summary>
+ bool focusNextWhenUncovered;
+ /// <summary>Set when the screen over a resumed tour closes while the popup is still coming back from its hide
+ /// (#1915): Place() hands Next the focus once the popup is visible again. Cleared on Place's hand-off, on any
+ /// Hide (a screen opening again hides), and when the chain opens or closes.</summary>
+ bool focusNextOnPlace;
/// <summary>The frame Escape closed it in (FeedbackPresenter's pattern): GameRoot's poll then knows the key is used.</summary>
int escapedAt = -1;
/// <summary>The message a layer covered, to show again or drop when the layer closes (spec 4.2).</summary>
@@ -166,9 +174,23 @@ namespace Statecraft.Game.UI
if (chain[session.Chain.Step].ApprovedIn(hebrew) && this.hooks.Card?.Shown != null && !this.hooks.Card.Collapsed)
this.hooks.Card.Collapse(takeFocus: false);
RenderChain();
+ // A rebuild (a language switch) resumes the chain with Settings still open over it (#1036 reopens the
+ // screen): Next takes the focus only once no screen is open, so Enter goes on (spec 16) and its gold
+ // focus fill shows, without stealing the screen's focus (#1915). The check waits a frame: SwitchLanguage
+ // reopens the screen only after Begin returns, so at construction no screen is open yet.
+ if (InChain)
+ layer.schedule.Execute(() =>
+ {
+ if (disposed || !InChain) return;
+ if (ScreenOpen()) focusNextWhenUncovered = true; else TakeFocusFromTheCard();
+ });
}
}
+ /// <summary>A screen is open over the tour. On the one-row HUD a side screen does not mark the HUD covered, so
+ /// Covered(hudRoot) alone misses Settings, and Next's focus would steal the screen's own (#1915).</summary>
+ bool ScreenOpen() => Covered(hudRoot) || hudRoot.ClassListContains(ScreenNav.ScreenOpenClass);
+
/// <summary>A modal layer is open (spec 4.2): the start screen, the opening (#530), the open decision card, the capture
/// dialog, the turn report, an outcome clip, the end screen; and, on the two-row HUD, any side screen (it takes the full width).</summary>
public static bool Covered(VisualElement hudRoot) =>
@@ -328,6 +350,7 @@ namespace Statecraft.Game.UI
void Hide()
{
StopWatching();
+ focusNextOnPlace = false; // even when already hidden: a screen opening again cancels a pending hand-off (#1915)
if (hidden) return;
hidden = true;
ring.style.display = DisplayStyle.None;
@@ -353,7 +376,12 @@ namespace Statecraft.Game.UI
if (disposed) return;
if (Media?.Playing == true && (HardMediaCover() || CurrentScreens() != watchScreens)) StopWatching();
if (hudRoot.ClassListContains(OverlayOpenClass)) return;
- if (session.Chain.Step >= 0) { RenderChain(); return; }
+ if (session.Chain.Step >= 0)
+ {
+ RenderChain();
+ if (focusNextWhenUncovered && InChain && !ScreenOpen()) { focusNextWhenUncovered = false; FocusNextOnPlace(); } // a screen closed over a resumed tour (#1915)
+ return;
+ }
if (Covered(hudRoot)) { if (Shown != null) covered = Shown; Hide(); return; }
if (covered is AdvisorCatalog.Message m)
{
@@ -452,6 +480,7 @@ namespace Statecraft.Game.UI
if (disposed) return;
var first = NextChainStep(-1);
if (first < 0) return; // no unreviewed Hebrew, even when explicitly asked
+ focusNextWhenUncovered = false; focusNextOnPlace = false; // a reopened tour starts without a stale pending hand-off (#1915)
hooks.CloseScreens?.Invoke();
openingGame = bridge.Session;
if (session.Chain.Step < 0)
@@ -481,6 +510,7 @@ namespace Statecraft.Game.UI
{
if (disposed || session.Chain.Step < 0) return;
session.Chain.Step = -1; session.Chain.PutBack = null; adopted = null;
+ focusNextWhenUncovered = false; focusNextOnPlace = false; // a tour ending cancels a pending Next hand-off (#1915)
Shown = null; covered = null;
ClearTarget();
Hide();
@@ -543,6 +573,33 @@ namespace Statecraft.Game.UI
gotIt.schedule.Execute(() => { if (!disposed && InChain) gotIt.Focus(); });
}
+ /// <summary>The screen over a resumed tour just closed and Next takes the focus (#1915). While the popup is
+ /// still coming back from its hide under the screen (display and visibility not restored yet) a Focus() does
+ /// nothing - the gate log read canGrabFocus=false, display=None, visibility=Hidden - so the hand-off waits for
+ /// Place() to make the popup visible again. A popup still on screen takes the focus at once.</summary>
+ void FocusNextOnPlace()
+ {
+ if (disposed || !InChain || ScreenOpen()) return;
+ if (NextCanTakeFocus()) { FocusReturn.To(gotIt); return; }
+ focusNextOnPlace = true;
+ }
+
+ /// <summary>Next can take the focus now (#1915). The button's own canGrabFocus, not the popup's resolved visibility:
+ /// an inline visibility set on the popup reads back at once on the popup itself, but its children inherit it only on
+ /// the next style pass, and a Focus() on a still-hidden Next releases the screen's focus to nothing.</summary>
+ bool NextCanTakeFocus() => FocusReturn.CanTakeFocus(gotIt) && gotIt.canGrabFocus;
+
+ /// <summary>Place() just restored the popup's visibility for the deferred Next hand-off (#1915), but Next inherits it
+ /// only on the next style pass. The hand-off waits that out: a few scheduler ticks until Next can take the focus,
+ /// then hands it over once.</summary>
+ void FocusNextWhenPlaced(int ticksLeft = 10)
+ {
+ if (disposed || !InChain || ScreenOpen()) return;
+ if (NextCanTakeFocus()) { FocusReturn.To(gotIt); return; }
+ if (ticksLeft <= 0) return;
+ gotIt.schedule.Execute(() => FocusNextWhenPlaced(ticksLeft - 1));
+ }
+
void ShowMe()
{
StopWatching();
@@ -724,6 +781,11 @@ namespace Statecraft.Game.UI
popup.style.left = at.xMin; popup.style.top = at.yMin;
popup.style.width = Mathf.Max(0f, at.width); popup.style.maxHeight = Mathf.Max(0f, slot.height);
popup.style.visibility = Visibility.Visible;
+ if (focusNextOnPlace && InChain && !ScreenOpen())
+ {
+ focusNextOnPlace = false;
+ FocusNextWhenPlaced();
+ }
return at;
}
diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.cs
index 42b35a2ab..88075d8dd 100644
--- a/unity/Assets/Scripts/UI/GameRoot.cs
+++ b/unity/Assets/Scripts/UI/GameRoot.cs
@@ -705,7 +705,13 @@ namespace Statecraft.Game.UI
keptResumed = start?.Resumed ?? true;
Begin(inputs, 0, startScreen: fromStart, keep: Bridge);
if (!fromStart) nav?.Open("settings");
- document.rootVisualElement.Q<Button>((fromStart ? "start-language-" : "settings-language-") + language)?.Focus();
+ // Focus the choice again a frame later: a screen shown this same tick cannot take the focus until its
+ // styles resolve, and a bare Focus() then leaves it wherever it was (#1915's tour test read end-turn).
+ if (document.rootVisualElement.Q<Button>((fromStart ? "start-language-" : "settings-language-") + language) is Button choice)
+ {
+ choice.Focus();
+ choice.schedule.Execute(() => { if (choice.panel != null) choice.Focus(); });
+ }
}
/// <summary>The 1948 localities in a hex (by the hex their point lies in, as the map picks hexes), for the info panel.</summary>
diff --git a/unity/Assets/Scripts/UI/GddHexPanel.cs b/unity/Assets/Scripts/UI/GddHexPanel.cs
index 9170229a3..f40f9d969 100644
--- a/unity/Assets/Scripts/UI/GddHexPanel.cs
+++ b/unity/Assets/Scripts/UI/GddHexPanel.cs
@@ -433,9 +433,10 @@ namespace Statecraft.Game.UI
static Label Line(VisualElement parent, string name, string value)
{
- var l = new Label(value) { name = name };
+ var l = new Label { name = name };
l.AddToClassList("wrap"); l.AddToClassList(LineClass);
parent.Add(l);
+ l.text = value; // set once on the panel, so UiDirection's change callback gives it its direction (#1915)
return l;
}
@@ -449,8 +450,9 @@ namespace Statecraft.Game.UI
static Button Button(VisualElement parent, string name, string label, Action onClick)
{
- var b = new Button(onClick) { name = name, text = label };
+ var b = new Button(onClick) { name = name };
parent.Add(b);
+ b.text = label; // set once on the panel, so UiDirection's change callback gives it its direction (#1915)
return b;
}
}
diff --git a/unity/Assets/Tests/EditMode/AdvisorOpeningParityTests.cs b/unity/Assets/Tests/EditMode/AdvisorOpeningParityTests.cs
index db8e4054a..253fa292a 100644
--- a/unity/Assets/Tests/EditMode/AdvisorOpeningParityTests.cs
+++ b/unity/Assets/Tests/EditMode/AdvisorOpeningParityTests.cs
@@ -1235,4 +1235,43 @@ public class AdvisorOpeningNoAttentionGameRootTests
}
}
}
+
+ // #1915: a mid-tour language switch rebuilds the UI and resumes the tour; Next keeps the focus, so Enter goes on
+ // and its gold focus fill shows. Red-first: the rebuilt presenter resumed the chain without giving Next the focus
+ // back, and the button stayed dark for the rest of the tour.
+ [UnityTest]
+ public IEnumerator SettingsSwitchToHebrewKeepsTheTourNextFocused()
+ {
+ var inputs = new GameInputs { Content = AdvisorTour1688Fixture.Content(),
+ Map = GameInputs.MapFromDisk(Paths.Content, Paths.StreamingMap), Goldens = new GoldenData() };
+ var settings = new SettingsStore(TempDir());
+ var game = AdvisorGameTests.OpenScene(new SaveStore(TempDir()), settings);
+ game.Language = UiLanguage.English;
+ game.AdvisorCatalogForTests = AdvisorCatalog.Parse(File.ReadAllText(AdvisorCatalog.Path)
+ .Replace("he_review: pending", "he_review: approved"));
+ game.Begin(inputs, 0, startScreen: true);
+ UiTestKit.Press(Ui.Q<Button>("start-new-game"));
+ game.Advisor!.OpenChain();
+ Assert.IsTrue(game.Advisor.InChain);
+
+ UiTestKit.Press(Ui.Q<Button>("nav-settings"));
+ UiTestKit.Press(Ui.Q<Button>("settings-language-" + UiLanguage.Hebrew));
+ Assert.IsTrue(Ui.Q("root").ClassListContains(UiLanguage.HebrewClass));
+ Assert.IsTrue(game.Advisor!.InChain, "the rebuilt presenter resumes the tour");
+ // A quiet EditMode panel runs its styles, layout and scheduler only on player-loop requests (SafeAreaTests), so each
+ // wait asks for one; bare yields would leave every scheduled step unrun and both checks below vacuous.
+ for (int i = 0; i < 5; i++) { EditorApplication.QueuePlayerLoopUpdate(); yield return null; }
+ Assert.IsTrue(Ui.Q("root").ClassListContains(ScreenNav.ScreenOpenClass), "Settings reopens over the resumed tour (#1036)");
+ Assert.AreSame(Ui.Q<Button>("settings-language-" + UiLanguage.Hebrew), Ui.Q("root").focusController.focusedElement,
+ "Next does not steal Settings' focus while the screen is open (#1915)");
+
+ UiTestKit.Press(Ui.Q<Button>("nav-settings")); // Settings closes over the resumed tour
+ var next = Ui.Q<Button>("advisor-got-it");
+ for (int i = 0; i < 10 && Ui.Q("root").focusController.focusedElement != next; i++)
+ { EditorApplication.QueuePlayerLoopUpdate(); yield return null; } // the popup comes back and the hand-off runs
+ for (int i = 0; i < 3; i++) { EditorApplication.QueuePlayerLoopUpdate(); yield return null; } // and it stays there
+ Assert.IsFalse(Ui.Q("root").ClassListContains(ScreenNav.ScreenOpenClass));
+ Assert.AreSame(next, Ui.Q("root").focusController.focusedElement,
+ "once no screen is open Next has the focus: Enter goes on, and its gold focus fill shows (#1915)");
+ }
}
diff --git a/unity/Assets/Tests/EditMode/HebrewUiTests.cs b/unity/Assets/Tests/EditMode/HebrewUiTests.cs
index af5aa6c04..fefdb157e 100644
--- a/unity/Assets/Tests/EditMode/HebrewUiTests.cs
+++ b/unity/Assets/Tests/EditMode/HebrewUiTests.cs
@@ -421,7 +421,43 @@ public class HebrewUiTests
finally { restore(); }
}
- static void Directed(IList<TextElement> texts, string after)
+ /// <summary>#1915: a city panel built in a game started in Hebrew reads in the right order from the first frame: its
+ /// right-column lines and its project buttons are built where they stand (GddHexPanel's Line and Button set the words
+ /// once the element is on the panel), so UiDirection's change callback gives each its own direction. Uses the #1688
+ /// tour fixture's city - the one in the issue's capture - whose projects show. Red-first: the lines and buttons were
+ /// built with their words before they joined the panel, no text change reached UiDirection, and no trigger walks the
+ /// tree before the player reads the panel.</summary>
+ [UnityTest]
+ public IEnumerator TheCityPanelReadsRightToLeftWhenTheGameStartsInHebrew()
+ {
+ var restore = OnTexture(1920, 1080);
+ try
+ {
+ var inputs = new GameInputs { Content = AdvisorTour1688Fixture.Content(),
+ Map = GameInputs.MapFromDisk(Paths.Content, Paths.StreamingMap), Goldens = new GoldenData() };
+ var game = Object.FindFirstObjectByType<GameRoot>();
+ game.Store = new SaveStore(saveDir);
+ game.Language = UiLanguage.Hebrew;
+ game.Begin(inputs, 0);
+ for (int i = 0; i < 2; i++) yield return null;
+
+ var city = AdvisorTargets.CityHex(game.Bridge!.Content, game.Bridge.State)!.Value;
+ game.Info!.Show(city.q, city.r); // built by the tour or a map click: no UI submit, click or turn follows
+ for (int i = 0; i < 2; i++) yield return null;
+
+ var texts = Ui.Q<VisualElement>(GddHexPanel.HostName).Query<TextElement>().ToList()
+ .Where(t => !string.IsNullOrEmpty(t.text)).ToList();
+ Assert.IsNotEmpty(texts, "the city panel's right column has lines");
+ Assert.IsTrue(texts.Any(t => UiDirection.HasRightToLeft(t.text)), "the column mixes Hebrew with numbers");
+ Directed(texts, "the city panel's lines in a game started in Hebrew");
+ var buttons = Ui.Q<VisualElement>(GddHexPanel.ProjectsHostName).Query<Button>().ToList();
+ Assert.IsTrue(buttons.Any(b => b.name.StartsWith("city-project-", StringComparison.Ordinal) && b.name != GddHexPanel.ToggleName), "the city in the #1915 capture shows its project buttons");
+ Directed(buttons, "the city panel's project buttons in a game started in Hebrew");
+ }
+ finally { restore(); }
+ }
+
+ static void Directed(IReadOnlyList<TextElement> texts, string after)
{
Assert.IsNotEmpty(texts, after);
foreach (var t in texts)