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.

Start screen: choose the language (English / עברית) before playing (#2054) (#2061)

Eyal Golan0bd30ee1fe12
diff --git a/changelog.d/2054-start-language.md b/changelog.d/2054-start-language.md
new file mode 100644
index 000000000..238f379f8
--- /dev/null
+++ b/changelog.d/2054-start-language.md
@@ -0,0 +1,3 @@
+- The start screen offers the language before you play: "English" and "עברית", each in its own language, with the one
+ in use marked. A choice switches the game at once, keeps the start screen up and is the same choice Settings shows and
+ keeps; "?lang=he" still wins for that visit (#2054).
diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.cs
index b4dd9ce1e..341fd7309 100644
--- a/unity/Assets/Scripts/UI/GameRoot.cs
+++ b/unity/Assets/Scripts/UI/GameRoot.cs
@@ -67,6 +67,8 @@ namespace Statecraft.Game.UI
EndScreenPresenter? end;
/// <summary>Set by SwitchLanguage for its Begin: the player had closed the end screen, so the rebuilt one stays closed.</summary>
bool endClosed;
+ /// <summary>Set by SwitchLanguage for its Begin (#2054): whether the start screen it rebuilds offered Continue.</summary>
+ bool keptResumed = true;
AdvisorPresenter? advisor;
/// <summary>Tests supply an in-memory approval copy for Hebrew layout; the shipped review fields are unchanged.</summary>
internal AdvisorCatalog? AdvisorCatalogForTests { get; set; }
@@ -227,7 +229,8 @@ namespace Statecraft.Game.UI
var store = Store ?? SaveStore.ForPlatform();
var notes = new List<string>();
// A smoke run is reproducible: a fresh game with the golden seed, never the player's autosave.
- bool resumed = true;
+ bool resumed = keep == null || keptResumed; // a language switch offers Continue as the start screen it rebuilds did
+ keptResumed = true;
var session = keep?.Session ?? (smoke > 0
? GameStart.Begin(inputs.Content, store, () => GoldenRun.Seed, notes, text, out resumed, fresh: true)
: GameStart.Begin(inputs.Content, store, GameStart.NewSeed, notes, text, out resumed));
@@ -304,7 +307,8 @@ namespace Statecraft.Game.UI
// Presentation only (#40): never the sim or the save. Outside Play mode (EditMode tests) no file: the developer's
// own settings must not leak into a test. Each Begin (New Game too) reads the file again.
// The language switch (#1036) builds every screen again in the new language over this game (SwitchLanguage).
- Own(new SettingsPresenter(root, text, SettingsFile(), language => SwitchLanguage(inputs, language), panel: document.panelSettings, audio: audio, advisors: AdvisorSession.Settings));
+ Action<string> switchLanguage = language => SwitchLanguage(inputs, language); // the start screen's too (#2054)
+ Own(new SettingsPresenter(root, text, SettingsFile(), switchLanguage, panel: document.panelSettings, audio: audio, advisors: AdvisorSession.Settings));
// "Report a bug or idea" (#1169), from Settings and the start screen: the version line names the content GameBoot logged.
feedback = Own(new FeedbackPresenter(root, text, ReportLinks.Version(Application.version, inputs.Content.Hash)));
var feedbackPanel = feedback;
@@ -520,7 +524,7 @@ namespace Statecraft.Game.UI
{
if (cam != null) cam.enabled = !shown;
if (!shown) { if (start?.Resumed == false) advisor?.NewGame(); else advisor?.Resume(); }
- }, recording, text));
+ }, recording, text, SettingsFile(), switchLanguage));
start.Show();
}
// It shows by itself only where the start screen does (never in the automated runs, nor under ?firstcard, which
@@ -632,17 +636,21 @@ namespace Statecraft.Game.UI
else if (Application.isPlaying && VisualShots.Requested()) StartCoroutine(VisualShots.Run(camRig, map.Frame, Debug.Log));
}
- /// <summary>Settings' language switch (#1036): every screen again in <paramref name="language"/> at once, no reload,
- /// over the same game with this turn's orders (Begin's keep), and Settings open again with the focus on the choice
- /// just made (for a mouse press too: the rebuilt UI has no focus to keep). Not in a smoke run (smokeRun).</summary>
+ /// <summary>The language switch of Settings (#1036) and of the start screen (#2054): every screen again in
+ /// <paramref name="language"/> at once, no reload, over the same game with this turn's orders (Begin's keep), and the
+ /// place it was pressed in open again with the focus on the choice just made (for a mouse press too: the rebuilt UI
+ /// has no focus to keep): the start screen, offering Continue only if it did, or else Settings. Not in a smoke run
+ /// (smokeRun).</summary>
void SwitchLanguage(GameInputs inputs, string language)
{
if (Bridge == null || smokeRun) return;
Language = language;
endClosed = end != null && !end.IsOpen; // read before Begin disposes it
- Begin(inputs, 0, keep: Bridge);
- nav?.Open("settings");
- document.rootVisualElement.Q<Button>("settings-language-" + language)?.Focus();
+ bool fromStart = start?.IsOpen == true;
+ 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();
}
/// <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/LanguageButtons.cs b/unity/Assets/Scripts/UI/LanguageButtons.cs
new file mode 100644
index 000000000..efde318b9
--- /dev/null
+++ b/unity/Assets/Scripts/UI/LanguageButtons.cs
@@ -0,0 +1,66 @@
+#nullable enable
+using System;
+using System.IO;
+using UnityEngine;
+using UnityEngine.UIElements;
+
+namespace Statecraft.Game.UI
+{
+ /// <summary>The UI's language buttons, in Settings (#1036) and on the start screen (#2054). Each names its language in
+ /// that language, so a player who cannot read the UI's one still finds their own, and the one in use is marked
+ /// (SettingsPresenter.SelectedClass). A press keeps the choice under SettingsPresenter.LanguageKey, which
+ /// UiLanguage.AtStart reads, and then switches the UI (GameRoot.SwitchLanguage), so the two places share one choice. A
+ /// new language is one more entry in All and a button named for it in each place in Game.uxml.</summary>
+ public sealed class LanguageButtons : IDisposable
+ {
+ /// <summary>Each language's code and its name in itself.</summary>
+ public static readonly (string language, string name)[] All = { (UiLanguage.English, "English"), (UiLanguage.Hebrew, "עברית") };
+
+ readonly (Button button, string language, Action pick)[] buttons;
+ readonly string current;
+ readonly SettingsStore? store;
+ readonly Action<string>? switchLanguage;
+
+ /// <param name="prefix">The buttons' names before the language's code ("settings-language-", "start-language-").</param>
+ /// <param name="current">The UI's language (its strings' "ui.lang").</param>
+ /// <param name="store">Where the choice is kept; null keeps nothing.</param>
+ /// <param name="switchLanguage">Puts the UI in the language pressed (GameRoot builds the screens again); null changes
+ /// nothing but the stored choice, read at the next start.</param>
+ public LanguageButtons(VisualElement scope, string prefix, string current, SettingsStore? store, Action<string>? switchLanguage)
+ {
+ this.current = current; this.store = store; this.switchLanguage = switchLanguage;
+ buttons = Array.ConvertAll(All, l =>
+ {
+ var b = scope.Q<Button>(prefix + l.language);
+ b.text = l.name;
+ Action pick = () => Pick(l.language);
+ b.clicked += pick;
+ return (b, l.language, pick);
+ });
+ Mark();
+ }
+
+ /// <summary>Marks the language in use.</summary>
+ public void Mark()
+ {
+ foreach (var (b, l, _) in buttons) b.EnableInClassList(SettingsPresenter.SelectedClass, l == current);
+ }
+
+ /// <summary>Keeps the choice first: the switch disposes these buttons with the rest of the UI.</summary>
+ void Pick(string language)
+ {
+ if (language == current) return;
+ try { store?.Write(SettingsPresenter.LanguageKey, language); }
+ catch (Exception e) when (e is IOException || e is UnauthorizedAccessException)
+ {
+ Debug.LogWarning($"Settings: could not keep the language choice ({e.Message}); it holds until the page is closed");
+ }
+ switchLanguage?.Invoke(language);
+ }
+
+ public void Dispose()
+ {
+ foreach (var (b, _, pick) in buttons) b.clicked -= pick;
+ }
+ }
+}
diff --git a/unity/Assets/Scripts/UI/LanguageButtons.cs.meta b/unity/Assets/Scripts/UI/LanguageButtons.cs.meta
new file mode 100644
index 000000000..ab5d54e08
--- /dev/null
+++ b/unity/Assets/Scripts/UI/LanguageButtons.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 092861ad3689c44898ef66109558b26b
\ No newline at end of file
diff --git a/unity/Assets/Scripts/UI/SettingsPresenter.cs b/unity/Assets/Scripts/UI/SettingsPresenter.cs
index d04857c48..dbf0416fe 100644
--- a/unity/Assets/Scripts/UI/SettingsPresenter.cs
+++ b/unity/Assets/Scripts/UI/SettingsPresenter.cs
@@ -33,13 +33,12 @@ namespace Statecraft.Game.UI
public static readonly (string level, float volume)[] SoundLevels = { ("off", 0f), ("low", 0.35f), ("high", 1f) };
readonly SettingsStore? store; readonly UiText text; readonly VisualElement root, screen; readonly Button tiltShift;
readonly (Button button, GraphicsQuality.Choice choice, Action pick)[] quality;
- readonly (Button button, string language, Action pick)[] languages;
+ readonly LanguageButtons languages;
readonly (Button button, string level, Action pick)[] sound;
readonly AdvisorSettings? advisors;
readonly (Button button, string level, Action pick)[] helpLevels;
readonly GameAudio? audio;
string soundLevel;
- readonly Action<string>? switchLanguage;
readonly PanelSettings? panel; readonly Vector2Int reference; int uiScale = UiScales[0], chosen = UiScales[0];
readonly (Button button, int percent, Action pick)[] scales;
readonly Action unbindStar;
@@ -52,7 +51,7 @@ namespace Statecraft.Game.UI
/// <param name="audio">The sound effects the volume applies to; null keeps only the choice.</param>
public SettingsPresenter(VisualElement root, UiText text, SettingsStore? store, Action<string>? switchLanguage = null, PanelSettings? panel = null, GameAudio? audio = null, AdvisorSettings? advisors = null)
{
- this.store = store; this.text = text; this.switchLanguage = switchLanguage; this.root = root; this.audio = audio; this.advisors = advisors;
+ this.store = store; this.text = text; this.root = root; this.audio = audio; this.advisors = advisors;
screen = root.Q<VisualElement>("screen-settings");
screen.Q<Label>("settings-screen-title").text = text["settings.title"];
screen.Q<Label>("settings-tiltshift-label").text = text["settings.tiltshift"];
@@ -75,17 +74,9 @@ namespace Statecraft.Game.UI
var start = GraphicsQuality.AtStart(store?.Read(QualityKey), Application.absoluteURL, Environment.GetCommandLineArgs(),
Application.platform == RuntimePlatform.WebGLPlayer);
if (start != GraphicsQuality.Current) GraphicsQuality.Apply(start);
- // The UI's language (#1036): each button names its language in that language, so a player who cannot read the
- // UI's one still finds their own; the one in use is marked. UiLanguage.AtStart reads the stored choice.
+ // The UI's language (#1036): the same buttons as the start screen's (LanguageButtons), the one in use marked.
screen.Q<Label>("settings-language-label").text = text["settings.language"];
- languages = Array.ConvertAll(new[] { (UiLanguage.English, "English"), (UiLanguage.Hebrew, "עברית") }, l =>
- {
- var b = screen.Q<Button>("settings-language-" + l.Item1);
- b.text = l.Item2;
- Action pick = () => PickLanguage(l.Item1);
- b.clicked += pick;
- return (b, l.Item1, pick);
- });
+ languages = new LanguageButtons(screen, "settings-language-", text["ui.lang"], store, switchLanguage);
// Sound effects (#39): three volume steps, the one that is set marked, applied to GameAudio at once and kept.
screen.Q<Label>("settings-sound-label").text = text["settings.sound"];
var storedSound = store?.Read(SoundKey);
@@ -145,7 +136,7 @@ namespace Statecraft.Game.UI
{
tiltShift.clicked -= Flip;
foreach (var (b, _, pick) in quality) b.clicked -= pick;
- foreach (var (b, _, pick) in languages) b.clicked -= pick;
+ languages.Dispose();
foreach (var (b, _, pick) in sound) b.clicked -= pick;
foreach (var (b, _, pick) in scales) b.clicked -= pick;
foreach (var (b, _, pick) in helpLevels) b.clicked -= pick;
@@ -195,18 +186,6 @@ namespace Statecraft.Game.UI
if (audio != null) audio.Volume = Array.Find(SoundLevels, l => l.level == soundLevel).volume;
}
- /// <summary>Keeps the choice first: the switch disposes this presenter with the rest of the UI.</summary>
- void PickLanguage(string language)
- {
- if (language == text["ui.lang"]) return;
- try { store?.Write(LanguageKey, language); }
- catch (Exception e) when (e is IOException || e is UnauthorizedAccessException)
- {
- Debug.LogWarning($"Settings: could not keep the language choice ({e.Message}); it holds until the page is closed");
- }
- switchLanguage?.Invoke(language);
- }
-
void PickScale(int percent)
{
chosen = percent;
@@ -251,7 +230,7 @@ namespace Statecraft.Game.UI
{
tiltShift.text = text[TiltShift.Enabled ? "settings.on" : "settings.off"];
foreach (var (b, c, _) in quality) b.EnableInClassList(SelectedClass, c == GraphicsQuality.Current);
- foreach (var (b, l, _) in languages) b.EnableInClassList(SelectedClass, l == text["ui.lang"]);
+ languages.Mark();
foreach (var (b, l, _) in sound) b.EnableInClassList(SelectedClass, l == soundLevel);
foreach (var (b, level, _) in helpLevels) b.EnableInClassList(SelectedClass, level == advisors?.Level);
foreach (var (b, p, _) in scales)
diff --git a/unity/Assets/Scripts/UI/StartScreenPresenter.cs b/unity/Assets/Scripts/UI/StartScreenPresenter.cs
index 52e098514..e8d246902 100644
--- a/unity/Assets/Scripts/UI/StartScreenPresenter.cs
+++ b/unity/Assets/Scripts/UI/StartScreenPresenter.cs
@@ -18,7 +18,8 @@ namespace Statecraft.Game.UI
/// press never wipes the save (#175, B6). Continue and Escape withdraw an open request.
/// While it shows, the root has OpenClass (Statecraft.uss hides the HUD under it, so Tab reaches only these buttons)
/// and <c>shownChanged</c> is told, so GameRoot can stop the camera keys. The panel's source line says the painting is
- /// AI-generated. Beside New game, "Star on GitHub" opens the repository in a new tab (#1168, ExternalLink). Under ?navlog it
+ /// AI-generated. Beside New game, "Star on GitHub" opens the repository in a new tab (#1168, ExternalLink). At the foot,
+ /// the UI's language can be chosen before playing (#2054) with Settings' own buttons (LanguageButtons). Under ?navlog it
/// logs where its buttons are (ButtonCentres), so tools/web_check.py clicks them wherever the layout puts them.</summary>
public sealed class StartScreenPresenter : IDisposable
{
@@ -57,6 +58,7 @@ namespace Statecraft.Game.UI
readonly Button starButton;
readonly EventCallback<GeometryChangedEvent> onLaidOut;
readonly VisualElement[] laidOut;
+ readonly LanguageButtons languages;
string? loggedCentres;
/// <summary>The buttons ButtonCentres reports, by name.</summary>
@@ -72,8 +74,11 @@ namespace Statecraft.Game.UI
/// <param name="text">The UI's strings for the source line and the two buttons (#193); null keeps Game.uxml's English
/// (tests). The title is the game's name and the English lines are the Declaration's official translation: neither
/// is translated.</param>
+ /// <param name="settings">Where the language choice is kept (Settings' file); null keeps nothing.</param>
+ /// <param name="switchLanguage">Settings' language switch (GameRoot.SwitchLanguage); null changes nothing but the
+ /// stored choice.</param>
public StartScreenPresenter(VisualElement root, NewGamePresenter newGame, bool resumed, Action<bool>? shownChanged = null,
- DeclarationRecording? recording = null, UiText? text = null)
+ DeclarationRecording? recording = null, UiText? text = null, SettingsStore? settings = null, Action<string>? switchLanguage = null)
{
this.recording = recording;
this.newGame = newGame; this.shownChanged = shownChanged; Resumed = resumed;
@@ -93,6 +98,7 @@ namespace Statecraft.Game.UI
starButton = screen.Q<Button>("start-star");
unbindStar = ExternalLink.Bind(starButton, ExternalLink.Repository); // #1168
starButton.generateVisualContent += PaintStarSigns;
+ languages = new LanguageButtons(screen, "start-language-", text?["ui.lang"] ?? UiLanguage.English, settings, switchLanguage);
onContinue = Continue; onNewGame = NewGame; onStarted = Started;
continueButton.clicked += onContinue;
newGameButton.clicked += onNewGame;
@@ -263,6 +269,7 @@ namespace Statecraft.Game.UI
newGame.Started -= onStarted;
unbindStar();
starButton.generateVisualContent -= PaintStarSigns;
+ languages.Dispose();
screen.UnregisterCallback(onCancel);
screen.UnregisterCallback(onGeometry);
panel.UnregisterCallback(onGeometry);
diff --git a/unity/Assets/Tests/EditMode/HebrewUiTests.cs b/unity/Assets/Tests/EditMode/HebrewUiTests.cs
index 0e1f37d63..a3a1a2fcc 100644
--- a/unity/Assets/Tests/EditMode/HebrewUiTests.cs
+++ b/unity/Assets/Tests/EditMode/HebrewUiTests.cs
@@ -185,6 +185,86 @@ public class HebrewUiTests
Assert.AreEqual(UiLanguage.English, UiLanguage.AtStart(UiLanguage.Hebrew, null, new[] { "-lang", "en" }, webgl: false));
}
+ // --- The start screen's language choice (#2054) ------------------------------------------------------------------
+
+ GameRoot BootWithStartScreen(SettingsStore settings, string? language)
+ {
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ Object.FindFirstObjectByType<MapScene>().Build(Inputs.Map);
+ var game = Object.FindFirstObjectByType<GameRoot>();
+ game.Store = new SaveStore(saveDir);
+ game.Settings = settings;
+ game.Language = language;
+ game.Begin(Inputs, 0, startScreen: true);
+ return game;
+ }
+
+ static bool StartOpen => Ui.Q("root").ClassListContains(StartScreenPresenter.OpenClass);
+ static bool Marked(string name) => Ui.Q<Button>(name).ClassListContains(SettingsPresenter.SelectedClass);
+
+ /// <summary>The start screen offers the same two languages as Settings, each named in itself, with the one in use
+ /// marked, in both languages.</summary>
+ [Test]
+ public void TheStartScreenOffersBothLanguagesWithTheOneInUseMarked()
+ {
+ var settings = new SettingsStore(Path.Combine(saveDir, "settings"));
+ BootWithStartScreen(settings, null); // no file and no flag: English
+ Assert.IsTrue(StartOpen, "precondition: the start screen shows");
+ Assert.AreEqual("English", Ui.Q<Button>("start-language-en").text);
+ Assert.AreEqual("עברית", Ui.Q<Button>("start-language-he").text, "each language is named in itself");
+ Assert.IsTrue(Marked("start-language-en"), "English is marked");
+ Assert.IsFalse(Marked("start-language-he"));
+
+ BootWithStartScreen(settings, UiLanguage.Hebrew);
+ Assert.IsTrue(StartOpen);
+ Assert.AreEqual("English", Ui.Q<Button>("start-language-en").text, "not translated");
+ Assert.AreEqual("עברית", Ui.Q<Button>("start-language-he").text);
+ Assert.IsTrue(Marked("start-language-he"), "Hebrew is marked");
+ Assert.IsFalse(Marked("start-language-en"));
+ }
+
+ /// <summary>A choice on the start screen goes through Settings' own switch: the UI changes at once over the same game,
+ /// the start screen stays up (Continue still only with a save) with the focus on the choice, the choice is kept under
+ /// Settings' key, and Settings shows it. The other way round, a choice in Settings is what the next start screen
+ /// shows: the two can never disagree.</summary>
+ [Test]
+ public void TheStartScreenAndSettingsShareOneLanguageChoice()
+ {
+ var settings = new SettingsStore(Path.Combine(saveDir, "settings"));
+ var game = BootWithStartScreen(settings, null);
+ var session = game.Bridge!.Session;
+ Assert.AreEqual(DisplayStyle.None, Ui.Q<Button>("start-continue").style.display.value, "precondition: no save, no Continue");
+
+ UiTestKit.Press(Ui.Q<Button>("start-language-he"));
+ Assert.IsTrue(Ui.Q("root").ClassListContains(UiLanguage.HebrewClass), "Hebrew at once, no reload");
+ Assert.AreEqual(He.Format("hud.turn", game.Bridge!.State.Turn), Ui.Q<Label>("turn").text);
+ Assert.AreSame(session, game.Bridge.Session, "the same game goes on");
+ Assert.IsTrue(StartOpen, "the start screen stays up");
+ Assert.IsFalse(ScreenNav.IsOpen(Ui.Q("screen-settings")), "Settings does not open over it");
+ Assert.AreEqual(DisplayStyle.None, Ui.Q<Button>("start-continue").style.display.value, "still no save to continue");
+ Assert.AreEqual(He["start.new_game"], Ui.Q<Button>("start-new-game").text);
+ Assert.AreSame(Ui.Q<Button>("start-language-he"), Ui.focusController?.focusedElement, "the focus stays on the choice");
+ Assert.IsTrue(Marked("start-language-he"), "Hebrew is marked on the start screen");
+ Assert.IsFalse(Marked("start-language-en"));
+ Assert.AreEqual(UiLanguage.Hebrew, settings.Read(SettingsPresenter.LanguageKey), "kept under Settings' key");
+ Assert.IsTrue(Marked("settings-language-he"), "and Settings shows Hebrew");
+ Assert.IsFalse(Marked("settings-language-en"));
+
+ // The other way: New game (no save) closes the screen; English in Settings is what the next start screen shows.
+ UiTestKit.Press(Ui.Q<Button>("start-new-game"));
+ Assert.IsFalse(StartOpen, "precondition: on the map");
+ UiTestKit.Press(Ui.Q<Button>("nav-settings"));
+ UiTestKit.Press(Ui.Q<Button>("settings-language-en"));
+ Assert.IsFalse(Ui.Q("root").ClassListContains(UiLanguage.HebrewClass), "English at once");
+ Assert.IsFalse(StartOpen, "a switch in Settings brings no start screen back");
+ Assert.AreEqual(UiLanguage.English, settings.Read(SettingsPresenter.LanguageKey));
+ game.Language = null; // a reload: only the file remains
+ game.Begin(Inputs, 0, startScreen: true);
+ Assert.IsTrue(StartOpen);
+ Assert.IsTrue(Marked("start-language-en"), "the start screen shows Settings' choice");
+ Assert.IsFalse(Marked("start-language-he"));
+ }
+
static void TheDeclarationStaysRightToLeft(string after)
{
var lines = Ui.Query<TextElement>(className: "start-he").ToList();
@@ -649,13 +729,16 @@ public class HebrewUiTests
root.Add(l);
}
// The start screen's Hebrew lines are Hebrew in both languages (the Declaration's own text), and so is Settings'
- // button that names Hebrew in Hebrew (#1036).
- var texts = root.Query<TextElement>().ToList().Where(e => !e.ClassListContains("start-he") && e.name != "settings-language-he").ToList();
+ // button that names Hebrew in Hebrew (#1036), and the start screen's (#2054).
+ var texts = root.Query<TextElement>().ToList().Where(e => !e.ClassListContains("start-he") && e.name != "settings-language-he" && e.name != "start-language-he").ToList();
Assert.Greater(texts.Count, 30, "Game.uxml's labels and buttons");
for (int i = 0; i < 3; i++) yield return null; // resolved styles need a style pass
foreach (var e in texts)
Assert.AreNotSame(hebrew, FontOf(e), $"English: '{e.name}' ({string.Join(" ", e.GetClasses())})");
Assert.AreSame(hebrew, FontOf(root.Q<TextElement>("settings-language-he")), "English: 'עברית' has the Hebrew face");
+ Assert.AreSame(hebrew, FontOf(root.Q<TextElement>("start-language-he")), "English: the start screen's 'עברית' has the Hebrew face");
+ Assert.AreEqual("Advanced", root.Q<TextElement>("start-language-he").resolvedStyle.unityTextGenerator.ToString(),
+ "English: the start screen's 'עברית' is laid out right to left");
root.AddToClassList(UiLanguage.HebrewClass);
for (int i = 0; i < 3; i++) yield return null;
foreach (var e in texts)
diff --git a/unity/Assets/Tests/EditMode/StartScreenLanguageShots.cs b/unity/Assets/Tests/EditMode/StartScreenLanguageShots.cs
new file mode 100644
index 000000000..9c9077a1f
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/StartScreenLanguageShots.cs
@@ -0,0 +1,91 @@
+#nullable enable
+using System;
+using System.Collections;
+using System.IO;
+using NUnit.Framework;
+using Statecraft.Game;
+using Statecraft.Game.Map;
+using Statecraft.Game.UI;
+using UnityEditor.SceneManagement;
+using UnityEngine;
+using UnityEngine.TestTools;
+using UnityEngine.UIElements;
+using Object = UnityEngine.Object;
+
+/// <summary>Writes the start screen's stills for #2054 (the language choice), in English and Hebrew at 1920x1080 and 390x844,
+/// to `.superpowers/start-language-2054/` (local, not committed), or to the folder STATECRAFT_SHOT_DIR names. "after"
+/// is the screen as it is; "before" then hides the new row, which leaves the panel as main lays it out. Explicit, so it does not run with
+/// the checks.</summary>
+[Explicit("writes stills for a pull request, not a check")]
+public class StartScreenLanguageShots
+{
+ string saveDir = "";
+ string shotDir = "";
+ RenderTexture? rt; PanelSettings? ps;
+
+ [SetUp]
+ public void TempSaves()
+ {
+ saveDir = Path.Combine(Path.GetTempPath(), "statecraft-start-shots-" + Guid.NewGuid().ToString("N"));
+ shotDir = Environment.GetEnvironmentVariable("STATECRAFT_SHOT_DIR") is string d && d.Length > 0
+ ? d : Path.Combine(Directory.GetCurrentDirectory(), ".superpowers", "start-language-2054");
+ Directory.CreateDirectory(shotDir);
+ }
+
+ [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);
+ }
+
+ static IEnumerator Frames(int n) { for (int i = 0; i < n; i++) yield return null; }
+
+ void Shot(string name)
+ {
+ var prev = RenderTexture.active;
+ RenderTexture.active = rt;
+ var tex = new Texture2D(rt!.width, rt.height, TextureFormat.RGB24, false);
+ tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
+ tex.Apply();
+ RenderTexture.active = prev;
+ File.WriteAllBytes(Path.Combine(shotDir, name + ".png"), tex.EncodeToPNG());
+ Object.DestroyImmediate(tex);
+ Debug.Log($"SHOT {name}");
+ }
+
+ IEnumerator Shots(bool hebrew, int width, int height)
+ {
+ // The whole game in Hebrew at 390x844 logs "Layout update is struggling" on main too (31 Oct 2026, before #2054):
+ // not this tool's to judge, so the stills are still written.
+ LogAssert.ignoreFailingMessages = true;
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ var doc = Object.FindFirstObjectByType<UIDocument>();
+ rt = new RenderTexture(width, height, 24);
+ ps = Object.Instantiate(doc.panelSettings);
+ ps.targetTexture = rt;
+ doc.panelSettings = ps;
+ Object.FindFirstObjectByType<MapScene>().Build(MapFocusTests.Inputs.Map);
+ var root = Object.FindFirstObjectByType<GameRoot>();
+ root.Store = new SaveStore(saveDir);
+ root.Language = hebrew ? UiLanguage.Hebrew : UiLanguage.English;
+ root.Begin(MapFocusTests.Inputs, 0, startScreen: true);
+ var ui = doc.rootVisualElement;
+ var panel = ui.Q("start-panel");
+ for (int i = 0; i < 60 && !(panel.worldBound.height > 0); i++) yield return null;
+ yield return Frames(10);
+ var name = $"{(hebrew ? "he" : "en")}-{width}x{height}";
+ Shot($"after-{name}");
+ var row = ui.Q("start-language"); // null on main, which has no row
+ if (row != null) row.style.display = DisplayStyle.None; // main's panel: no language row
+ yield return Frames(10);
+ Shot($"before-{name}");
+ }
+
+ [UnityTest] public IEnumerator English1920x1080() { yield return Shots(false, 1920, 1080); }
+ [UnityTest] public IEnumerator Hebrew1920x1080() { yield return Shots(true, 1920, 1080); }
+ [UnityTest] public IEnumerator English390x844() { yield return Shots(false, 390, 844); }
+ [UnityTest] public IEnumerator Hebrew390x844() { yield return Shots(true, 390, 844); }
+}
diff --git a/unity/Assets/Tests/EditMode/StartScreenLanguageShots.cs.meta b/unity/Assets/Tests/EditMode/StartScreenLanguageShots.cs.meta
new file mode 100644
index 000000000..941a4a2f4
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/StartScreenLanguageShots.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 69165df4d797f4da988df7e12ef7a88c
\ No newline at end of file
diff --git a/unity/Assets/Tests/EditMode/StartScreenTests.cs b/unity/Assets/Tests/EditMode/StartScreenTests.cs
index a92ebd87f..f0337022b 100644
--- a/unity/Assets/Tests/EditMode/StartScreenTests.cs
+++ b/unity/Assets/Tests/EditMode/StartScreenTests.cs
@@ -377,9 +377,10 @@ public class StartScreenTests
var cont = rig.Ui.Q<Button>("start-continue");
cont.Focus();
Assert.AreSame(cont, rig.Ui.Root.focusController?.focusedElement, "Continue has the focus");
- // Tab walks the screen's buttons only: Continue, New Game, the recording's button, Star on GitHub (#1168) and Report a bug or idea (#1169).
+ // Tab walks the screen's buttons only: Continue, New Game, the recording's button, Star on GitHub (#1168), Report a
+ // bug or idea (#1169) and the two languages (#2054), English then Hebrew.
var seen = new List<string>();
- for (int i = 0; i < 4; i++)
+ for (int i = 0; i < 6; i++)
{
var at = (VisualElement)rig.Ui.Root.focusController!.focusedElement;
using (var e = NavigationMoveEvent.GetPooled(NavigationMoveEvent.Direction.Next)) { e.target = at; at.SendEvent(e); }
@@ -387,7 +388,10 @@ public class StartScreenTests
seen.Add((rig.Ui.Root.focusController.focusedElement as VisualElement)?.name ?? "none");
}
Assert.AreEqual("start-new-game", seen[0], "Tab moves from Continue to New Game: " + string.Join(", ", seen));
- Assert.IsTrue(seen.All(n => n == "start-continue" || n == "start-new-game" || n == "start-listen" || n == "start-star" || n == "start-report"), "Tab stays on the screen's buttons: " + string.Join(", ", seen));
+ Assert.IsTrue(seen.All(n => n == "start-continue" || n == "start-new-game" || n == "start-listen" || n == "start-star" || n == "start-report"
+ || n == "start-language-en" || n == "start-language-he"), "Tab stays on the screen's buttons: " + string.Join(", ", seen));
+ var en = seen.IndexOf("start-language-en");
+ Assert.IsTrue(en >= 0 && en + 1 < seen.Count && seen[en + 1] == "start-language-he", "Tab reaches English, then Hebrew: " + string.Join(", ", seen));
CollectionAssert.Contains(seen, "start-listen", "Tab reaches the recording's button: " + string.Join(", ", seen));
rig.Ui.Press("start-continue");
yield return null; yield return null;
diff --git a/unity/Assets/UI/Game.uxml b/unity/Assets/UI/Game.uxml
index 84e92fe58..4a99c0cd0 100644
--- a/unity/Assets/UI/Game.uxml
+++ b/unity/Assets/UI/Game.uxml
@@ -616,9 +616,16 @@
<ui:Button name="start-star" text="Star on GitHub" class="start-button start-star" />
</ui:VisualElement>
<!-- "Report a bug or idea" (#1169, FeedbackPresenter): a quiet button under the actions that opens the
- report panel. -->
+ report panel, and the language choice (#2054). -->
<ui:VisualElement name="start-community" class="start-community">
<ui:Button name="start-report" text="Report a bug or idea" class="start-report" />
+ <!-- The UI's language (#2054), chosen before playing, beside it (the panel keeps its height): Settings'
+ own buttons (LanguageButtons), each language named in itself, the one in use carrying
+ .settings-choice-selected. A row, so the pair mirrors in Hebrew as in Settings. -->
+ <ui:VisualElement name="start-language" class="row start-language">
+ <ui:Button name="start-language-en" class="start-language-button" />
+ <ui:Button name="start-language-he" class="start-language-button" />
+ </ui:VisualElement>
</ui:VisualElement>
<ui:VisualElement name="start-caption" class="start-caption" picking-mode="Ignore">
<ui:Label name="start-caption-he" text="…אנו מכריזים בזאת על הקמת מדינה יהודית בארץ־ישראל, היא מדינת ישראל." class="start-he start-caption-he" language-direction="RTL" picking-mode="Ignore" />
diff --git a/unity/Assets/UI/Statecraft.uss b/unity/Assets/UI/Statecraft.uss
index db0eb5867..72afc4622 100644
--- a/unity/Assets/UI/Statecraft.uss
+++ b/unity/Assets/UI/Statecraft.uss
@@ -520,8 +520,8 @@ Button:disabled { color: var(--ink-dim); border-color: rgba(120, 120, 120, 0.4);
the Hebrew face in Hebrew. */
Button.settings-choice-selected { -unity-font-definition: url("project://database/Assets/UI/Fonts/EBGaramond-SemiBold.ttf"); }
/* The language choice (#1036): "עברית" is in the Hebrew face in the English UI too (EB Garamond has no Hebrew), by id so
- that it beats the selected button's face above. */
-#settings-language-he {
+ that it beats the selected button's face above; the start screen's too (#2054). */
+#settings-language-he, #start-language-he {
-unity-font-definition: url("project://database/Assets/UI/Fonts/FrankRuhlLibre/FrankRuhlLibre-Medium.ttf");
-unity-text-generator: advanced;
}
@@ -938,6 +938,10 @@ Button.settings-choice-selected { -unity-font-definition: url("project://databas
whole-pixel height: a fractional one shifts the panel's lines off whole pixels, and on a phone held upright the band
layout (StartScreenPresenter.Fit) then rounds the panel's top back and forth, a layout that never settles. */
.start-community { flex-direction: row; justify-content: center; align-items: center; height: 40px; margin-top: 8px; }
+/* The language choice (#2054) beside it, as quiet, with Settings' gold mark on the language in use
+ (.settings-choice-selected). In the same row, so the panel keeps its height (StartScreenTests.ItFitsEveryWindowSize). */
+.start-language { margin-left: 8px; }
+.start-language-button { font-size: 18px; min-width: 96px; padding: 4px 16px; margin: 2px 4px; -unity-text-align: middle-center; }
/* Star on GitHub (#1168): a .start-button, New game's size, beside it (the row wraps it under New game in a narrow
window). Its star and GitHub mark are painted into the left padding (the right in Hebrew; StartScreenPresenter
PaintStarSigns). Secondary to New game in colour: no fill and a grey edge instead of the gold one; hover and keyboard
@@ -974,7 +978,7 @@ Button.settings-choice-selected { -unity-font-definition: url("project://databas
.lang-he .button, .lang-he Button, .lang-he #event-options Button, .lang-he #capture-options Button { -unity-text-align: middle-right; }
/* The buttons and cards whose text is centred stay centred (the rule above is the more specific one). */
.lang-he .nav-button, .lang-he .seat { -unity-text-align: upper-center; }
-.lang-he .event-reopen, .lang-he .event-hide, .lang-he .event-illustration, .lang-he .start-button, .lang-he .start-listen, .lang-he .start-report { -unity-text-align: middle-center; }
+.lang-he .event-reopen, .lang-he .event-hide, .lang-he .event-illustration, .lang-he .start-button, .lang-he .start-listen, .lang-he .start-report, .lang-he .start-language-button { -unity-text-align: middle-center; }
.lang-he .card-stat-name { -unity-text-align: middle-right; }
.lang-he .card-stat-value { -unity-text-align: middle-left; }
/* The Hebrew plate shows the first name's initial and the surname ("י. ידין", PersonCard.InitialAndSurname), not two