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 Settings screen from the left column, first option the tilt-shift blur on/off (refs #40) (#778)
Beri7e519df73167
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ea3ab1652..78fae1d63 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -96,6 +96,10 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB(Q-CUT-8). Every golden moves; the cutover re-pins them once.### Added+- A Settings screen, opened from a gear at the foot of the left column (refs #40, first slice). Its first option turns+ the tilt-shift blur off and on, at once; the choice is kept per browser in `/idbfs/statecraft-settings/settings.txt`+ (a fixed folder, as the autosave's), never in the sim or the save, so the goldens do not move. `?notiltshift` still+ boots without the blur.- The info panel of Tiberias' hex adds "Tiberias is shown here because its own hex is water." (Hebrew too, with thetown's Hebrew name), so the hillside hex's70 m does not read as the town's (refs #204). It is worked out in Unity from the town's own lon/lat and the hex griddiff --git a/unity/Assets/Scripts/SettingsStore.cs b/unity/Assets/Scripts/SettingsStore.csnew file mode 100644index 000000000..af27704bf--- /dev/null+++ b/unity/Assets/Scripts/SettingsStore.cs@@ -0,0 +1,57 @@+#nullable enable+using System.Collections.Generic;+using System.IO;+using UnityEngine;++namespace Statecraft.Game+{+ /// <summary>Where the player's settings live (#40): presentation only, never the sim or the save, so the golden hashes do+ /// not move. On WebGL a fixed folder under the /idbfs IndexedDB mount, as the autosave's (SaveStore): persistentDataPath+ /// hashes the page's URL and itch.io serves every upload from a new URL, which would forget the settings. The template+ /// sets autoSyncPersistentDataPath, so closing the file persists it. One "key=value" line per setting; a line the game+ /// does not know is kept as it is.</summary>+ public class SettingsStore+ {+ public const string WebDirectory = "/idbfs/statecraft-settings";+ public const string FileName = "settings.txt";++ public string Directory { get; }+ public SettingsStore(string directory) { Directory = directory; }++ public static SettingsStore ForPlatform() => new SettingsStore(DirectoryFor(Application.platform, Application.persistentDataPath));++ /// <summary>The settings folder for a platform. On the web it is the fixed folder and ignores persistentDataPath.</summary>+ public static string DirectoryFor(RuntimePlatform platform, string persistentDataPath) =>+ platform == RuntimePlatform.WebGLPlayer ? WebDirectory : Path.Combine(persistentDataPath, "settings");++ public string FilePath => Path.Combine(Directory, FileName);++ /// <summary>The stored value of <paramref name="key"/>, or null: no file, no such line, or a file that cannot be read+ /// (a setting is never worth a failed start; the option keeps its default).</summary>+ public string? Read(string key)+ {+ foreach (var line in Lines())+ if (line.StartsWith(key + "=", System.StringComparison.Ordinal)) return line.Substring(key.Length + 1);+ return null;+ }++ /// <summary>Sets <paramref name="key"/>'s line, keeping every other line. Throws on a failed write (the caller logs it:+ /// the choice still holds for this session). Not written through a .tmp as the autosave is: a cut-off file only+ /// costs the options their defaults (Read fails soft), never a game.</summary>+ public void Write(string key, string value)+ {+ var lines = new List<string>();+ foreach (var line in Lines()) if (!line.StartsWith(key + "=", System.StringComparison.Ordinal)) lines.Add(line);+ lines.Add(key + "=" + value);+ System.IO.Directory.CreateDirectory(Directory);+ File.WriteAllLines(FilePath, lines);+ }++ string[] Lines()+ {+ try { return File.Exists(FilePath) ? File.ReadAllLines(FilePath) : new string[0]; }+ catch (IOException) { return new string[0]; }+ catch (System.UnauthorizedAccessException) { return new string[0]; }+ }+ }+}diff --git a/unity/Assets/Scripts/SettingsStore.cs.meta b/unity/Assets/Scripts/SettingsStore.cs.metanew file mode 100644index 000000000..03e3277eb--- /dev/null+++ b/unity/Assets/Scripts/SettingsStore.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 0d2c14c8c933258b1ac66f28a2aa59ea\ No newline at end of filediff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex 735342645..33f2dbb21 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -224,6 +224,9 @@ namespace Statecraft.Game.UIOwn(new DefencePresenter(root, bridge, text, portraits));Own(new BudgetPresenter(root, bridge, text));Own(new WhyPresenter(root, bridge, text));+ // 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.+ Own(new SettingsPresenter(root, text, Application.isPlaying ? SettingsStore.ForPlatform() : null));Own(new CabinetPresenter(root, bridge, text, portraits));var names = map.SettlementsFor(inputs.Map.SettlementsYaml).ToDictionary(s => s.Id, s => s.Name); // the map's parse (issue #321)// The 1948 sub-districts, outlined on the map, and each front's 1949 armistice line from its agreement's datediff --git a/unity/Assets/Scripts/UI/HudPresenter.cs b/unity/Assets/Scripts/UI/HudPresenter.csindex 8c2cac0a0..43218bd50 100644--- a/unity/Assets/Scripts/UI/HudPresenter.cs+++ b/unity/Assets/Scripts/UI/HudPresenter.cs@@ -63,7 +63,7 @@ namespace Statecraft.Game.UIstatic readonly (string name, string key)[] Texts ={("nav-cabinet", "hud.nav.cabinet"), ("nav-budget", "hud.nav.budget"), ("nav-defence", "hud.nav.defence"),- ("nav-why", "hud.nav.why"), ("new-game", "hud.new_game"), ("end-turn", "hud.end_turn"),+ ("nav-why", "hud.nav.why"), ("nav-settings", "hud.nav.settings"), ("new-game", "hud.new_game"), ("end-turn", "hud.end_turn"),};/// <summary>The owner's text floor (#624, 15 October 2026): the bar's small text (the six captions, Security's level@@ -95,7 +95,7 @@ namespace Statecraft.Game.UIreadonly IVisualElementScheduledItem floorCheck;float smallTextSize = SmallTextPx;- /// <summary>The left icon column (promo 03): the four screens' buttons.</summary>+ /// <summary>The left icon column (promo 03): the screens' buttons (ScreenNav.Screens).</summary>public const string RailName = "left-column";readonly HoverTip? railTips, barTips;diff --git a/unity/Assets/Scripts/UI/ScreenNav.cs b/unity/Assets/Scripts/UI/ScreenNav.csindex ba34aa7b8..fed80092c 100644--- a/unity/Assets/Scripts/UI/ScreenNav.cs+++ b/unity/Assets/Scripts/UI/ScreenNav.cs@@ -4,13 +4,13 @@ using UnityEngine.UIElements;namespace Statecraft.Game.UI{- /// <summary>The top-bar buttons open the Cabinet, Budget, Defence and Why screens, one at a time; pressing the open+ /// <summary>The top-bar buttons open the Cabinet, Budget, Defence, Why and Settings screens, one at a time; pressing the open/// screen's button again closes it. Every press toggles, synchronously, with no debounce: two presses in one frame (a/// double click, or a click plus Enter) open and close again, so the result depends only on the number of presses/// (HudTests.TwoPressesInOneFrameToggleTwice; playtest 1, item 11).</summary>public sealed class ScreenNav : System.IDisposable{- public static readonly string[] Screens = { "cabinet", "budget", "defence", "why" };+ public static readonly string[] Screens = { "cabinet", "budget", "defence", "why", "settings" };/// <summary>The class on the open screen's button (Statecraft.uss lights its ring).</summary>public const string OpenClass = "nav-open";/// <summary>The class on the "root" element while a wide screen (class <see cref="WideClass"/>: Cabinet, Defence) isdiff --git a/unity/Assets/Scripts/UI/SettingsPresenter.cs b/unity/Assets/Scripts/UI/SettingsPresenter.csnew file mode 100644index 000000000..9f13e1e40--- /dev/null+++ b/unity/Assets/Scripts/UI/SettingsPresenter.cs@@ -0,0 +1,53 @@+#nullable enable+using System;+using System.IO;+using Statecraft.Game.Map;+using UnityEngine;+using UnityEngine.UIElements;++namespace Statecraft.Game.UI+{+ /// <summary>The Settings screen (#40), opened from the left column's gear like the other screens (ScreenNav). Its one+ /// option so far turns the tilt-shift blur off and on: applied at once (TiltShift.Enabled, what the "tiltshift" toggle+ /// sets) and kept in the SettingsStore, so it holds after a reload. A stored "off" only ever turns the blur off, so+ /// ?notiltshift still boots without it. The button says what is set ("On" / "Off"), not only a colour: the player's+ /// choice (Enabled), not the web tier's automatic last fallback step (TiltShift.FallbackOff), which it never changes.</summary>+ public sealed class SettingsPresenter : IDisposable+ {+ public const string TiltShiftKey = "tiltshift";+ readonly SettingsStore? store; readonly UiText text; readonly VisualElement screen; readonly Button tiltShift;++ /// <param name="store">Where the choice is kept; null keeps nothing (the option still works until the page closes).</param>+ public SettingsPresenter(VisualElement root, UiText text, SettingsStore? store)+ {+ this.store = store; this.text = text;+ 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"];+ tiltShift = screen.Q<Button>("settings-tiltshift");+ if (store?.Read(TiltShiftKey) == "off") TiltShift.Enabled = false;+ tiltShift.clicked += Flip;+ ScreenNav.OnOpened(screen, Show); // a dev toggle may have changed it while the screen was shut+ Show();+ }++ public void Dispose()+ {+ tiltShift.clicked -= Flip;+ if (screen.userData is Action) screen.userData = null;+ }++ void Flip()+ {+ TiltShift.Enabled = !TiltShift.Enabled;+ Show();+ try { store?.Write(TiltShiftKey, TiltShift.Enabled ? "on" : "off"); }+ catch (Exception e) when (e is IOException || e is UnauthorizedAccessException)+ {+ Debug.LogWarning($"Settings: could not keep the tilt-shift choice ({e.Message}); it holds until the page is closed");+ }+ }++ void Show() => tiltShift.text = text[TiltShift.Enabled ? "settings.on" : "settings.off"];+ }+}diff --git a/unity/Assets/Scripts/UI/SettingsPresenter.cs.meta b/unity/Assets/Scripts/UI/SettingsPresenter.cs.metanew file mode 100644index 000000000..22ec6e389--- /dev/null+++ b/unity/Assets/Scripts/UI/SettingsPresenter.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: a6aa04c2da2b7a50c9545043c8d72c73\ No newline at end of filediff --git a/unity/Assets/Scripts/UI/UiIcon.cs b/unity/Assets/Scripts/UI/UiIcon.csindex 26d62622b..e65c52add 100644--- a/unity/Assets/Scripts/UI/UiIcon.cs+++ b/unity/Assets/Scripts/UI/UiIcon.cs@@ -41,7 +41,7 @@ namespace Statecraft.Game.UIstatic readonly Dictionary<string, Painter> Painters = new Dictionary<string, Painter>{["coin"] = Coin, ["people"] = People, ["crowd"] = Crowd, ["shield"] = Shield, ["globe"] = Globe, ["banknote"] = Banknote,- ["columns"] = Columns, ["scales"] = Scales, ["helmet"] = Helmet, ["question"] = Question, ["restart"] = Restart,+ ["columns"] = Columns, ["scales"] = Scales, ["helmet"] = Helmet, ["question"] = Question, ["restart"] = Restart, ["gear"] = Gear,["chevron"] = Chevron, ["chevron-back"] = ChevronBack, ["hourglass"] = Hourglass,["region"] = Region, ["house"] = House, ["village"] = Village, ["flag"] = Flag,["peaks"] = Peaks, ["skyline"] = Skyline, ["ledger"] = Ledger,@@ -244,6 +244,25 @@ namespace Statecraft.Game.UIp.BeginPath(); p.MoveTo(at(13.6f, 2.6f)); p.LineTo(at(20.4f, 5.4f)); p.LineTo(at(15.0f, 10.4f)); p.ClosePath(); p.Fill();}+ /// <summary>A cog (the Settings screen, #40): eight teeth round a ring and a hole, in gold line. Each tooth is+ /// GearTooth: (degrees from the tooth's middle, radius) pairs, root, tip, tip, root.</summary>+ static readonly (float deg, float r)[] GearTooth = { (-13f, 7f), (-7f, 9.8f), (7f, 9.8f), (13f, 7f) };++ static void Gear(Painter2D p, Func<float, float, Vector2> at, float s, Color gold)+ {+ p.strokeColor = gold; p.lineWidth = 1.8f * s;+ p.BeginPath();+ for (int i = 0; i < 8; i++)+ foreach (var (deg, r) in GearTooth)+ {+ float a = (i * 45f + deg) * Mathf.Deg2Rad;+ var v = at(12 + r * Mathf.Cos(a), 12 + r * Mathf.Sin(a));+ if (i == 0 && deg == GearTooth[0].deg) p.MoveTo(v); else p.LineTo(v);+ }+ p.ClosePath(); p.Stroke();+ Circle(p, at(12, 12), 3.2f * s); p.Stroke();+ }+static void Chevron(Painter2D p, Func<float, float, Vector2> at, float s, Color gold){p.strokeColor = gold; p.lineWidth = 2.2f * s;diff --git a/unity/Assets/Tests/EditMode/HebrewUiTests.cs b/unity/Assets/Tests/EditMode/HebrewUiTests.csindex 7aa69440f..f3de894cc 100644--- a/unity/Assets/Tests/EditMode/HebrewUiTests.cs+++ b/unity/Assets/Tests/EditMode/HebrewUiTests.cs@@ -222,6 +222,7 @@ public class HebrewUiTests("budget-screen-title", "budget.title"), ("budget-reset", "budget.reset"), ("budget-submit", "budget.submit"),("defence-screen-title", "defence.title"), ("de-escalate", "defence.lower"), ("escalate", "defence.raise"),("why-screen-title", "why.title"),+ ("nav-settings", "hud.nav.settings"), ("settings-screen-title", "settings.title"), ("settings-tiltshift-label", "settings.tiltshift"),("start-source", "start.source"), ("start-recording-credit", "start.recording_credit"),("start-continue", "start.continue"), ("start-new-game", "start.new_game"),};diff --git a/unity/Assets/Tests/EditMode/LeftColumnTests.cs b/unity/Assets/Tests/EditMode/LeftColumnTests.csindex b2f7976f3..d6b20e0db 100644--- a/unity/Assets/Tests/EditMode/LeftColumnTests.cs+++ b/unity/Assets/Tests/EditMode/LeftColumnTests.cs@@ -16,7 +16,7 @@ using UnityEngine.UIElements;/// <summary>HUD round 2, part 2 (#398): promo/final/03's left icon column. It holds the four screens' buttons, moved from/// the top bar (no new action): Cabinet, Budget, Defence, Why?. They are round icons with no caption; each one's name is its/// text (clear) and its tooltip, which HoverTip shows beside it. The Hebrew UI mirrors rows, not the screen's corners (#550),-/// so the column stays at the left. Tab still runs Cabinet, Budget, Defence, Why?, New Game, End Turn.</summary>+/// so the column stays at the left. Tab still runs Cabinet, Budget, Defence, Why?, then Settings (#40), New Game, End Turn.</summary>public class LeftColumnTests{static readonly Content C = ContentLoader.Load(Paths.Content);@@ -33,6 +33,7 @@ public class LeftColumnTests{("nav-cabinet", "hud.nav.cabinet", "columns"), ("nav-budget", "hud.nav.budget", "ledger"),("nav-defence", "hud.nav.defence", "helmet"), ("nav-why", "hud.nav.why", "question"),+ ("nav-settings", "hud.nav.settings", "gear"),};/// <summary>InfoPanelLayoutTests' 19 window sizes.</summary>@@ -96,10 +97,10 @@ public class LeftColumnTests}}- /// <summary>The column holds the four screens, in the top bar's old order, each a round icon whose name is its text and+ /// <summary>The column holds the four screens, in the top bar's old order, then Settings (#40), each a round icon whose name is its text and/// its tooltip in both languages; the top bar keeps New Game and End Turn only. No new button: the screens are ScreenNav's.</summary>[Test]- public void TheColumnHoldsTheFourScreensAsRoundIconsNamedInBothLanguages()+ public void TheColumnHoldsTheScreensAsRoundIconsNamedInBothLanguages(){foreach (var hebrew in new[] { false, true }){@@ -201,7 +202,7 @@ public class LeftColumnTestsstatic Rect Hull(VisualElement root) => root.Q(Column).Query<Button>().ToList().Select(b => b.worldBound).Aggregate((a, b) => Rect.MinMaxRect(Mathf.Min(a.xMin, b.xMin), Mathf.Min(a.yMin, b.yMin), Mathf.Max(a.xMax, b.xMax), Mathf.Max(a.yMax, b.yMax)));- /// <summary>The audit's focus order is kept: Cabinet, Budget, Defence, Why?, New Game, End Turn (then the minimap's+ /// <summary>The audit's focus order is kept: Cabinet, Budget, Defence, Why?, Settings, New Game, End Turn (then the minimap's/// buttons, out of reach under the open card). The column is out of Tab's reach under the start screen and an outcome clip, as the top bar is, and usable/// under the decision card, as the top bar is.</summary>[UnityTest]@@ -215,7 +216,7 @@ public class LeftColumnTestsvar order = root.Query<VisualElement>().Where(e => e.focusable && e.canGrabFocus && e.tabIndex >= 0 && e is Button).ToList().Select(e => e.name).Where(n => n.StartsWith("nav-") || n == "new-game" || n == "end-turn" || n.StartsWith("minimap-")).ToList();// Under the open card the minimap column is out of reach (the backdrop covers it); the column and the bar are not.- CollectionAssert.AreEqual(new[] { "nav-cabinet", "nav-budget", "nav-defence", "nav-why", "new-game", "end-turn" },+ CollectionAssert.AreEqual(new[] { "nav-cabinet", "nav-budget", "nav-defence", "nav-why", "nav-settings", "new-game", "end-turn" },order, $"{at}: the Tab order under the open card");var r = root.Q("root");Assert.IsTrue(r.ClassListContains(EventCardPresenter.ModalClass), at + ": precondition: the card is open");diff --git a/unity/Assets/Tests/EditMode/PromoHudTests.cs b/unity/Assets/Tests/EditMode/PromoHudTests.csindex c2dff1477..70551d302 100644--- a/unity/Assets/Tests/EditMode/PromoHudTests.cs+++ b/unity/Assets/Tests/EditMode/PromoHudTests.cs@@ -39,7 +39,8 @@ public class PromoHudTests{using var ui = new UiTestKit();foreach (var (button, name, glyph) in new[] { ("nav-cabinet", "Cabinet", "columns"), ("nav-budget", "Budget", "ledger"),- ("nav-defence", "Defence", "helmet"), ("nav-why", "Why?", "question"), ("new-game", "New game", "restart") })+ ("nav-defence", "Defence", "helmet"), ("nav-why", "Why?", "question"), ("nav-settings", "Settings", "gear"),+ ("new-game", "New game", "restart") }){var b = ui.Q<Button>(button);Assert.AreEqual(name, b.text, button + ": the name stays the button's text (legible, and what the event log records)");diff --git a/unity/Assets/Tests/EditMode/SettingsScreenTests.cs b/unity/Assets/Tests/EditMode/SettingsScreenTests.csnew file mode 100644index 000000000..0b2fa9487--- /dev/null+++ b/unity/Assets/Tests/EditMode/SettingsScreenTests.cs@@ -0,0 +1,174 @@+#nullable enable+using System.Collections;+using System.IO;+using NUnit.Framework;+using Statecraft.Game;+using Statecraft.Game.Map;+using Statecraft.Game.UI;+using Statecraft.Sim;+using UnityEditor;+using UnityEngine;+using UnityEngine.TestTools;+using UnityEngine.UIElements;+using Object = UnityEngine.Object;++/// <summary>The Settings screen (#40): opened from the left column's gear like the other screens, its tilt-shift option+/// applied at once and kept in the SettingsStore across a reload, and laid out at 1280x720 in both languages. A reload+/// here is what a page reload leaves: the statics start over (TiltShift.Enabled back on) and only the file remains.</summary>+public class SettingsScreenTests+{+ static UiText En => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings).text);+ static UiText He => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.StringsHebrew).text, "strings.he.yaml");++ string dir = "";++ [SetUp]+ public void SetUp()+ {+ dir = Path.Combine(Path.GetTempPath(), "sc-settings-" + System.Guid.NewGuid().ToString("N"));+ TiltShift.Enabled = true;+ }++ [TearDown]+ public void TearDown()+ {+ TiltShift.Enabled = true;+ if (Directory.Exists(dir)) Directory.Delete(dir, true);+ }++ [Test]+ public void TheGearInTheLeftColumnOpensAndClosesTheSettingsScreen()+ {+ using var ui = new UiTestKit();+ using var nav = new ScreenNav(ui.Root);+ using var settings = new SettingsPresenter(ui.Root, En, new SettingsStore(dir));+ var screen = ui.Q<VisualElement>("screen-settings");+ Assert.IsFalse(ScreenNav.IsOpen(screen), "hidden at start");+ ui.Press("nav-settings");+ Assert.IsTrue(ScreenNav.IsOpen(screen), "the gear opens it");+ Assert.AreEqual("settings", nav.Current);+ ui.Press("nav-settings");+ Assert.IsFalse(ScreenNav.IsOpen(screen), "pressed again, it closes");+ }++ [Test]+ public void TheTiltShiftOptionTakesEffectAtOnceAndSurvivesAReload([Values(false, true)] bool hebrew)+ {+ var text = hebrew ? He : En;+ using (var ui = new UiTestKit())+ using (new SettingsPresenter(ui.Root, text, new SettingsStore(dir)))+ {+ var button = ui.Q<Button>("settings-tiltshift");+ Assert.IsTrue(TiltShift.Enabled, "on by default, with no file");+ Assert.AreEqual(text["settings.on"], button.text);+ UiTestKit.Press(button);+ Assert.IsFalse(TiltShift.Enabled, "off at once, with no apply step");+ Assert.AreEqual(text["settings.off"], button.text, "the button says what is set");+ }+ TiltShift.Enabled = true; // the reload+ using (var ui = new UiTestKit())+ using (new SettingsPresenter(ui.Root, text, new SettingsStore(dir)))+ {+ Assert.IsFalse(TiltShift.Enabled, "still off after the reload");+ var button = ui.Q<Button>("settings-tiltshift");+ Assert.AreEqual(text["settings.off"], button.text);+ UiTestKit.Press(button);+ Assert.IsTrue(TiltShift.Enabled, "and on again at once");+ Assert.AreEqual(text["settings.on"], button.text);+ }+ TiltShift.Enabled = true; // the reload+ using (var ui = new UiTestKit())+ using (new SettingsPresenter(ui.Root, text, new SettingsStore(dir)))+ Assert.IsTrue(TiltShift.Enabled, "on survives a reload too");+ }++ /// <summary>?notiltshift (TiltShift.OffRequested) boots with the blur off; a stored "on" does not turn it back on.</summary>+ [Test]+ public void AStoredOnDoesNotOverrideNoTiltShift()+ {+ new SettingsStore(dir).Write(SettingsPresenter.TiltShiftKey, "on");+ TiltShift.Enabled = false; // what CameraRig.Init does for ?notiltshift+ using var ui = new UiTestKit();+ using var settings = new SettingsPresenter(ui.Root, En, new SettingsStore(dir));+ Assert.IsFalse(TiltShift.Enabled);+ Assert.AreEqual(En["settings.off"], ui.Q<Button>("settings-tiltshift").text);+ }++ /// <summary>A file the game cannot use (another key, a value it does not know, a line without "=") is no reason to fail+ /// a start: the option keeps its default.</summary>+ [Test]+ public void AnUnusableFileLeavesTheDefault()+ {+ Directory.CreateDirectory(dir);+ File.WriteAllText(new SettingsStore(dir).FilePath, "junk\nscale=2\ntiltshift=maybe\n");+ using var ui = new UiTestKit();+ using var settings = new SettingsPresenter(ui.Root, En, new SettingsStore(dir));+ Assert.IsTrue(TiltShift.Enabled);+ UiTestKit.Press(ui.Q<Button>("settings-tiltshift"));+ Assert.AreEqual("off", new SettingsStore(dir).Read(SettingsPresenter.TiltShiftKey));+ Assert.AreEqual("2", new SettingsStore(dir).Read("scale"), "another key's line is kept");+ }++ /// <summary>On the web the file sits in a fixed /idbfs folder, as the autosave does (SaveStore), not under+ /// persistentDataPath, which hashes the page's URL: itch.io serves every upload from a new URL. It is not the save's+ /// folder: the settings never touch the save.</summary>+ [Test]+ public void OnTheWebTheFolderIsFixedAndIsNotTheSaves()+ {+ Assert.AreEqual("/idbfs/statecraft-settings", SettingsStore.DirectoryFor(RuntimePlatform.WebGLPlayer, "/idbfs/0123456789abcdef"));+ Assert.AreNotEqual(SaveStore.WebDirectory, SettingsStore.WebDirectory);+ Assert.AreEqual(Path.Combine("/home/p", "settings"), SettingsStore.DirectoryFor(RuntimePlatform.LinuxPlayer, "/home/p"));+ }++ /// <summary>The open screen at 1280x720 (the issue's size), in English and Hebrew: the title, the option's name and its+ /// button inside the screen, below the top bar and inside the window, each text whole (on one line or wrapped).</summary>+ [UnityTest]+ public IEnumerator TheOpenScreenFitsAt1280x720InBothLanguages()+ {+ var c = ContentLoader.Load(Paths.Content);+ foreach (var hebrew in new[] { false, true })+ {+ var text = hebrew ? He : En;+ string at = hebrew ? "he" : "en";+ var rt = new RenderTexture(1280, 720, 0);+ var ps = Object.Instantiate(AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel));+ ps.targetTexture = rt;+ var go = new GameObject("SettingsLayoutTest");+ go.SetActive(false);+ var doc = go.AddComponent<UIDocument>();+ doc.panelSettings = ps;+ doc.visualTreeAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(UiPaths.GameUxml);+ go.SetActive(true);+ var root = doc.rootVisualElement;+ root.Q("root").RemoveFromClassList("loading");+ if (hebrew) root.Q("root").AddToClassList(UiLanguage.HebrewClass);+ var hud = new HudPresenter(root, new SimBridge(GameSession.New(c, GoldenRun.Seed, Mode.Historical), text), text);+ var nav = new ScreenNav(root);+ var settings = new SettingsPresenter(root, text, new SettingsStore(dir));+ try+ {+ nav.Open("settings");+ for (int i = 0; i < 30 && !(root.Q("screen-settings").layout.width > 0); i++) yield return null;+ for (int i = 0; i < 3; i++) yield return null;+ var screen = root.Q("screen-settings").worldBound;+ Assert.IsTrue(Inside(screen, root.worldBound), $"{at}: the screen {screen} leaves the window {root.worldBound}");+ Assert.GreaterOrEqual(screen.yMin, root.Q("top-bar").worldBound.yMax - 0.5f, at + ": the screen starts below the top bar");+ foreach (var name in new[] { "settings-screen-title", "settings-tiltshift-label", "settings-tiltshift" })+ {+ var e = root.Q<TextElement>(name);+ Assert.IsFalse(string.IsNullOrWhiteSpace(e.text), $"{at}: {name} has its text");+ Assert.IsTrue(Inside(e.worldBound, screen), $"{at}: {name} {e.worldBound} leaves the screen {screen}");+ Assert.IsTrue(UiLayoutTests.TextFits(e), $"{at}: {name} '{e.text}' is cut ({e.contentRect})");+ }+ }+ finally+ {+ settings.Dispose(); nav.Dispose(); hud.Dispose();+ Object.DestroyImmediate(go); Object.DestroyImmediate(ps); rt.Release(); Object.DestroyImmediate(rt);+ }+ }+ }++ static bool Inside(Rect inner, Rect outer) =>+ inner.xMin >= outer.xMin - 0.5f && inner.xMax <= outer.xMax + 0.5f && inner.yMin >= outer.yMin - 0.5f && inner.yMax <= outer.yMax + 0.5f;+}diff --git a/unity/Assets/Tests/EditMode/SettingsScreenTests.cs.meta b/unity/Assets/Tests/EditMode/SettingsScreenTests.cs.metanew file mode 100644index 000000000..6a2a17b05--- /dev/null+++ b/unity/Assets/Tests/EditMode/SettingsScreenTests.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 4e298fe1c4972f62ba3f7c83267cdcc1\ No newline at end of filediff --git a/unity/Assets/Tests/EditMode/TopBarTests.cs b/unity/Assets/Tests/EditMode/TopBarTests.csindex a9a6d4e95..4cdc38864 100644--- a/unity/Assets/Tests/EditMode/TopBarTests.cs+++ b/unity/Assets/Tests/EditMode/TopBarTests.cs@@ -417,7 +417,7 @@ public class TopBarTestsAssert.IsEmpty(problems, string.Join("\n", problems));}- /// <summary>The audit's Tab order is kept: Cabinet, Budget, Defence, Why? (the left column), New Game, End Turn, then the+ /// <summary>The audit's Tab order is kept: Cabinet, Budget, Defence, Why?, Settings (the left column), New Game, End Turn, then the/// minimap's buttons.</summary>[UnityTest]public IEnumerator TheTabOrderIsKept()@@ -427,7 +427,7 @@ public class TopBarTests{var order = root.Query<Button>().ToList().Where(e => e.focusable && e.canGrabFocus && e.tabIndex >= 0).Select(e => e.name).Where(n => n.StartsWith("nav-") || n == "new-game" || n == "end-turn" || n.StartsWith("minimap-")).ToList();- CollectionAssert.AreEqual(new[] { "nav-cabinet", "nav-budget", "nav-defence", "nav-why", "new-game", "end-turn", "minimap-overview", "minimap-labels", "minimap-borders" },+ CollectionAssert.AreEqual(new[] { "nav-cabinet", "nav-budget", "nav-defence", "nav-why", "nav-settings", "new-game", "end-turn", "minimap-overview", "minimap-labels", "minimap-borders" },order, (hebrew ? "he" : "en") + ": the Tab order");}, widest: false);}diff --git a/unity/Assets/Tests/EditMode/UiLayoutTests.cs b/unity/Assets/Tests/EditMode/UiLayoutTests.csindex 767eb0591..3b99a1090 100644--- a/unity/Assets/Tests/EditMode/UiLayoutTests.cs+++ b/unity/Assets/Tests/EditMode/UiLayoutTests.cs@@ -431,7 +431,7 @@ public class UiLayoutTests}/// <summary>A button's text fits its content box: on one line, or wrapped (white-space normal) within its height.</summary>- static bool TextFits(TextElement b)+ internal static bool TextFits(TextElement b){var box = b.contentRect;var natural = b.MeasureTextSize(b.text, 0, VisualElement.MeasureMode.Undefined, 0, VisualElement.MeasureMode.Undefined);diff --git a/unity/Assets/UI/Game.uxml b/unity/Assets/UI/Game.uxmlindex c49f9378e..b4e0e2bfe 100644--- a/unity/Assets/UI/Game.uxml+++ b/unity/Assets/UI/Game.uxml@@ -7,7 +7,7 @@<ui:VisualElement name="map-labels" class="map-labels" picking-mode="Ignore" /><!-- HUD round 2, part 2 (#398): promo 03's left icon column, the four screens (ScreenNav), icon-only; each one's nameis its text (the event log records it), hidden, and its tooltip, shown beside it on hover and on focus- (HoverTip). Before the top bar in the tree, so Tab still runs Cabinet, Budget, Defence, Why?, New Game, End Turn. -->+ (HoverTip). Before the top bar in the tree, so Tab still runs Cabinet, Budget, Defence, Why?, Settings, New Game, End Turn. --><!-- The left column's strip of the decision card's backdrop (review of #602): dimmed and taking the pointer while thecard is open (event-modal), so the map is blocked between and below the discs as it is everywhere else; beforethe column in the tree, so the column's buttons stay above it and usable. -->@@ -17,6 +17,7 @@<ui:Button name="nav-budget" text="Budget" class="nav-button rail-button"><Statecraft.Game.UI.UiIcon glyph="ledger" class="nav-disc" /></ui:Button><ui:Button name="nav-defence" text="Defence" class="nav-button rail-button"><Statecraft.Game.UI.UiIcon glyph="helmet" class="nav-disc" /></ui:Button><ui:Button name="nav-why" text="Why?" class="nav-button rail-button"><Statecraft.Game.UI.UiIcon glyph="question" class="nav-disc" /></ui:Button>+ <ui:Button name="nav-settings" text="Settings" class="nav-button rail-button"><Statecraft.Game.UI.UiIcon glyph="gear" class="nav-disc" /></ui:Button></ui:VisualElement><ui:VisualElement name="top-bar" class="panel top-bar"><Statecraft.Game.UI.UiFrame corners="false" rule="false" />@@ -282,6 +283,16 @@<ui:ScrollView name="why-rows" class="grow" /><Statecraft.Game.UI.UiFrame /></ui:VisualElement>+ <!-- Settings (#40, SettingsPresenter): the player's presentation options, kept per browser (SettingsStore), never in+ the sim or the save. Each option is a row: its name, and a button that says what is set. -->+ <ui:VisualElement name="screen-settings" class="panel screen">+ <ui:VisualElement class="screen-header"><ui:Label name="settings-screen-title" text="Settings" class="title" /></ui:VisualElement>+ <ui:VisualElement class="row settings-row">+ <ui:Label name="settings-tiltshift-label" text="Blur at the top and bottom of the map" class="settings-name" />+ <ui:Button name="settings-tiltshift" class="settings-switch" />+ </ui:VisualElement>+ <Statecraft.Game.UI.UiFrame />+ </ui:VisualElement><!-- The End Turn outcome clip (OutcomePresenter): the historical order the player gave, as a 3.5 s silent clip in themiddle, captioned as the order; a click, Enter or Space skips it, Esc skips them all. After the screens, so itis drawn over them (an open screen is also closed when a clip starts); only the start screen and the toast comediff --git a/unity/Assets/UI/Statecraft.uss b/unity/Assets/UI/Statecraft.ussindex 71c98e1cd..2dd7b3988 100644--- a/unity/Assets/UI/Statecraft.uss+++ b/unity/Assets/UI/Statecraft.uss@@ -175,7 +175,7 @@ Button:disabled { color: var(--ink-dim); border-color: rgba(120, 120, 120, 0.4);bottom-right. The right-hand column keeps its 480 px width, so the screens and the border layer's caption stay wherethey were; it now holds only the minimap. */.right-column { position: absolute; right: 16px; top: 112px; bottom: 16px; width: 480px; }-/* HUD round 2, part 2 (#398): promo 03's left icon column, the four screens' round buttons under the bar at the left edge+/* HUD round 2, part 2 (#398): promo 03's left icon column, the screens' round buttons under the bar at the left edge(promo 03: discs about 5.3% of the frame's height, 6.3% apart). Icon-only: the caption is the button's text (the eventlog and the strings read it) but drawn clear; HoverTip shows it beside the disc on hover and on focus. The decisioncard's backdrop, the screens and the toast start right of it (68 px: its 56 px and a 12 px gap), so nothing covers it@@ -323,7 +323,7 @@ Button:disabled { color: var(--ink-dim); border-color: rgba(120, 120, 120, 0.4);color: var(--ink); background-color: var(--navy-solid); border-color: var(--gold); border-width: 1px; border-radius: 3px;}-/* Full screens (Cabinet, Budget, Defence, Why) open in the centre, one at a time. */+/* Full screens (Cabinet, Budget, Defence, Why, Settings) open in the centre, one at a time. *//* Hidden until ScreenNav opens one (never visible while loading; playtest 2, P2-1). Right edge clear of the 480px column. */.screen { display: none; position: absolute; left: 552px; right: 512px; top: 112px; bottom: 16px; padding: 18px; background-color: rgb(11, 18, 32); } /* opaque: a reading screen, and the map labels must not show through */.screen-header { flex-direction: column; align-items: stretch; border-bottom-width: 1px; border-color: var(--gold-dim); margin-bottom: 10px; padding-bottom: 4px; }@@ -339,6 +339,10 @@ Button:disabled { color: var(--ink-dim); border-color: rgba(120, 120, 120, 0.4);lists to it, so a long list scrolls instead of growing out of the screen. */.screen .row.grow { align-items: stretch; flex-basis: 0; flex-shrink: 1; min-height: 0; }.screen .row.grow > .grow { min-height: 0; flex-shrink: 1; }+/* Settings (#40): an option's name takes the row's width and wraps; its button keeps room for "On" / "Off". */+.settings-row { margin-top: 8px; }+.settings-name { flex-grow: 1; flex-shrink: 1; min-width: 0; white-space: normal; }+.settings-switch { flex-shrink: 0; min-width: 96px; -unity-text-align: middle-center; }/* The toast sits in the map's free top-left corner, above the info panel: opaque, and never over an open screen's title orthe minimap column (B7). */diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yamlindex 80ba2b579..3688b2aaf 100644--- a/unity/Assets/UI/strings.en.yaml+++ b/unity/Assets/UI/strings.en.yaml@@ -34,6 +34,7 @@ hud.nav.cabinet: "Cabinet"hud.nav.budget: "Budget"hud.nav.defence: "Defence"hud.nav.why: "Why?"+hud.nav.settings: "Settings"hud.new_game: "New game"hud.end_turn: "End turn"# The screens' titles and buttons, the decision card's draft mark, the start screen and the loading line (GameRoot).@@ -44,6 +45,11 @@ defence.title: "Defence"defence.lower: "Lower the level"defence.raise: "Raise the level"why.title: "Why did this happen?"+# The Settings screen (#40): its title, the tilt-shift option and the button that says what is set.+settings.title: "Settings"+settings.tiltshift: "Blur at the top and bottom of the map"+settings.on: "On"+settings.off: "Off"event.draft: "DRAFT"start.source: "From the Declaration of the Establishment of the State of Israel (Official Gazette No. 1, 14 May 1948) and its official English translation. Painting: AI-generated."start.recording_credit: "Recording: Ralph Hellinger, Israel State Archives"diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yamlindex 542f4d7e0..e5029e2a0 100644--- a/unity/Assets/UI/strings.he.yaml+++ b/unity/Assets/UI/strings.he.yaml@@ -27,6 +27,7 @@ hud.nav.cabinet: "ממשלה"hud.nav.budget: "תקציב"hud.nav.defence: "ביטחון"hud.nav.why: "למה?"+hud.nav.settings: "הגדרות"hud.new_game: "משחק חדש"hud.end_turn: "סיום התור"budget.title: "תקציב"@@ -36,6 +37,11 @@ defence.title: "ביטחון"defence.lower: "הורדת הדרגה"defence.raise: "העלאת הדרגה"why.title: "למה זה קרה?"+# The Settings screen (#40). "On" / "Off" as a switch's state, not a command. For the native reviewer (#564).+settings.title: "הגדרות"+settings.tiltshift: "טשטוש בחלק העליון ובחלק התחתון של המפה"+settings.on: "מופעל"+settings.off: "כבוי"event.draft: "טיוטה"start.source: "מתוך ההכרזה על הקמת מדינת ישראל (עיתון רשמי מס׳ 1, 14 במאי 1948) ותרגומה הרשמי לאנגלית. הציור נוצר בבינה מלאכותית."# The recordist's name as the Israel State Archives spells it in its own description of item