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: Settings gets a UI scale choice, 100% / 125% / 150% (refs #40) (#1011)

Beriaa4a7c00dc00
diff --git a/CHANGELOG.md b/CHANGELOG.md
index af63118c1..c86fe026f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -55,6 +55,11 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
priced by the sim's new `AttentionSystem.Price`/`Left`, which `SimBridge` now uses too); the UI only reads it (refs #1109).
- Unit cards show the sourced Hebrew unit name in the Hebrew UI, with an English fallback. INS Haganah gains its
sourced Hebrew name, still flagged for a native speaker's review (#902).
+- Settings: a UI scale choice, 100%, 125% or 150%, default 100% (refs #40, third slice; owner decision of 18 Oct 2026).
+ It scales the whole UI at once (the one panel's reference resolution divided by the scale) and is kept in
+ `settings.txt` (key `uiscale`), never in the sim or the save. Only the scales verified to fit the window are
+ offered, 100% always (owner ruling of 19 Oct 2026 on #1011): the layout suites do not pass at 125% or 150% yet, so
+ for now the row offers 100% alone, and a saved 125% or 150% starts at 100% (the file keeps the choice).
### Changed
- The map pans left and right from the first frame (#1062, player report): the game opens at 90 km, not 120 km, under
the ~106 km where a 16:9 view is wider than the map and held centred (#174). A 21:9 window still opens centred
diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.cs
index 5096592ea..356c670ac 100644
--- a/unity/Assets/Scripts/UI/GameRoot.cs
+++ b/unity/Assets/Scripts/UI/GameRoot.cs
@@ -252,7 +252,7 @@ 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)));
+ Own(new SettingsPresenter(root, text, SettingsFile(), language => SwitchLanguage(inputs, language), document.panelSettings));
Own(new CabinetPresenter(root, bridge, text, portraits));
// After End Turn, what changed in the top bar and the sim's causes (#1037); under an outcome clip, which plays first.
report = Own(new TurnReportPresenter(root, bridge, text, nav!));
diff --git a/unity/Assets/Scripts/UI/SettingsPresenter.cs b/unity/Assets/Scripts/UI/SettingsPresenter.cs
index efe57365e..103033fc7 100644
--- a/unity/Assets/Scripts/UI/SettingsPresenter.cs
+++ b/unity/Assets/Scripts/UI/SettingsPresenter.cs
@@ -1,32 +1,47 @@
#nullable enable
using System;
+using System.Collections.Generic;
using System.IO;
using Statecraft.Game.Map;
+using Statecraft.Sim;
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 options:
- /// the graphics quality (GraphicsQuality: Auto / High / Low), the UI's language (#1036) and the tilt-shift blur. The
- /// blur option turns it 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
+ /// the graphics quality (GraphicsQuality: Auto / High / Low), the UI's language (#1036), the UI scale (100% / 125% / 150%)
+ /// and the tilt-shift blur. The blur option turns it 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", QualityKey = "quality", LanguageKey = "lang", SelectedClass = "settings-choice-selected";
- readonly SettingsStore? store; readonly UiText text; readonly VisualElement screen; readonly Button tiltShift;
+ public const string TiltShiftKey = "tiltshift", QualityKey = "quality", LanguageKey = "lang", UiScaleKey = "uiscale", SelectedClass = "settings-choice-selected";
+ /// <summary>The owner's UI scales (#40, 18 Oct 2026), in percent; the first is the default.</summary>
+ public static readonly int[] UiScales = { 100, 125, 150 };
+ /// <summary>The owner's ruling on #1011 (19 Oct 2026): Settings offers only the UI scales verified to fit, and 100% always,
+ /// as the fallback. A scale above 100% is verified on the window shapes (width / height, narrowest to widest) where
+ /// the layout suites pass with the panel at that scale: UiLayoutTests, InfoPanelLayoutTests, TopBarScoreLayoutTests,
+ /// HebrewUiTests, LeftColumnTests, PromoScreensTests and TopBarTests, whose windows run from 360x800 to 2560x1080.
+ /// None is yet: at 125% and 150% those suites fail on every window shape (PR #1011, 18 Oct 2026), so the game offers
+ /// 100% only. To offer a scale, run the suites at it and enter the narrowest and widest shapes where they all pass.
+ /// Tests enter shapes here to drive the rule and put the table back.</summary>
+ public static readonly Dictionary<int, (float narrowest, float widest)> VerifiedShapes = new Dictionary<int, (float, float)>();
+ 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 Action<string>? switchLanguage;
+ readonly PanelSettings? panel; readonly Vector2Int reference; int uiScale = UiScales[0], chosen = UiScales[0];
+ readonly (Button button, int percent, Action pick)[] scales;
/// <param name="store">Where the choice is kept; null keeps nothing (the option still works until the page closes).</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 SettingsPresenter(VisualElement root, UiText text, SettingsStore? store, Action<string>? switchLanguage = null)
+ /// <param name="panel">The UI's panel, which the UI scale scales; null leaves the scale alone.</param>
+ public SettingsPresenter(VisualElement root, UiText text, SettingsStore? store, Action<string>? switchLanguage = null, PanelSettings? panel = null)
{
- this.store = store; this.text = text; this.switchLanguage = switchLanguage;
+ this.store = store; this.text = text; this.switchLanguage = switchLanguage; this.root = root;
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"];
@@ -61,6 +76,27 @@ namespace Statecraft.Game.UI
b.clicked += pick;
return (b, l.Item1, pick);
});
+ // UI scale (#40): the panel scales with the screen from its 1920x1080 reference (ScaleWithScreenSize); dividing the
+ // reference by the choice multiplies that scale by it, whatever the window. The whole UI is one panel. Dispose
+ // puts the reference back: in the editor the panel is a project asset, and a choice must not stay in it.
+ this.panel = panel;
+ reference = panel != null ? panel.referenceResolution : default;
+ screen.Q<Label>("settings-uiscale-label").text = text["settings.uiscale"];
+ scales = Array.ConvertAll(UiScales, percent =>
+ {
+ var b = screen.Q<Button>("settings-uiscale-" + percent);
+ b.text = PlayerText.Percent(Level(percent));
+ Action pick = () => PickScale(percent);
+ b.clicked += pick;
+ return (b, percent, pick);
+ });
+ var storedScale = store?.Read(UiScaleKey);
+ int startScale = Array.Find(UiScales, p => p.ToString() == storedScale); // 0 when the file names none of them
+ chosen = startScale > 0 ? startScale : UiScales[0];
+ ApplyScale(Fits(chosen) ? chosen : UiScales[0]);
+ // The fit depends on the window's shape, which a resize changes: the offer and the applied scale follow the
+ // root's geometry (as TopBarInset does). The file keeps the choice, so a shape that holds it again gets it back.
+ root.RegisterCallback<GeometryChangedEvent>(OnGeometry);
ScreenNav.OnOpened(screen, Show); // a dev toggle may have changed it while the screen was shut
Show();
}
@@ -70,6 +106,9 @@ 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;
+ foreach (var (b, _, pick) in scales) b.clicked -= pick;
+ root.UnregisterCallback<GeometryChangedEvent>(OnGeometry);
+ if (panel != null) panel.referenceResolution = reference;
if (screen.userData is Action) screen.userData = null;
}
@@ -108,11 +147,56 @@ namespace Statecraft.Game.UI
switchLanguage?.Invoke(language);
}
+ void PickScale(int percent)
+ {
+ chosen = percent;
+ ApplyScale(percent);
+ Show();
+ try { store?.Write(UiScaleKey, percent.ToString()); }
+ catch (Exception e) when (e is IOException || e is UnauthorizedAccessException)
+ {
+ Debug.LogWarning($"Settings: could not keep the UI scale ({e.Message}); it holds until the page is closed");
+ }
+ }
+
+ /// <summary>A UI scale's level (1.25 for 125%): the stored values and the buttons' names are whole percents.</summary>
+ static double Level(int percent) => percent / 100.0;
+
+ /// <summary>Whether the scale is verified to fit this window (VerifiedShapes); 100% always is. Before the first
+ /// layout the shape is unknown and a verified scale counts: nothing is drawn yet, and OnGeometry checks again.</summary>
+ bool Fits(int percent)
+ {
+ if (percent == UiScales[0]) return true;
+ if (!VerifiedShapes.TryGetValue(percent, out var shapes)) return false;
+ float shape = root.layout.width / root.layout.height;
+ return !(shape > 0) || (shape >= shapes.narrowest && shape <= shapes.widest);
+ }
+
+ void OnGeometry(GeometryChangedEvent e)
+ {
+ var fit = Fits(chosen) ? chosen : UiScales[0];
+ if (fit != uiScale) ApplyScale(fit);
+ Show();
+ }
+
+ void ApplyScale(int percent)
+ {
+ uiScale = percent;
+ var level = Level(percent);
+ if (panel != null)
+ panel.referenceResolution = new Vector2Int(Mathf.RoundToInt((float)(reference.x / level)), Mathf.RoundToInt((float)(reference.y / level)));
+ }
+
void Show()
{
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"]);
+ foreach (var (b, p, _) in scales)
+ {
+ b.EnableInClassList(SelectedClass, p == uiScale);
+ b.style.display = Fits(p) ? DisplayStyle.Flex : DisplayStyle.None;
+ }
}
}
}
diff --git a/unity/Assets/Tests/EditMode/HebrewUiTests.cs b/unity/Assets/Tests/EditMode/HebrewUiTests.cs
index 82ed92f9d..a5ea59b48 100644
--- a/unity/Assets/Tests/EditMode/HebrewUiTests.cs
+++ b/unity/Assets/Tests/EditMode/HebrewUiTests.cs
@@ -36,6 +36,7 @@ public class HebrewUiTests
{
EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
if (Directory.Exists(saveDir)) Directory.Delete(saveDir, true);
+ SettingsPresenter.VerifiedShapes.Remove(150); // the language switch's stand-in (the game ships none)
}
// --- The flag ---------------------------------------------------------------------------------------------------
@@ -114,6 +115,7 @@ public class HebrewUiTests
game.Store = new SaveStore(saveDir);
var settings = new SettingsStore(Path.Combine(saveDir, "settings"));
game.Settings = settings;
+ SettingsScreenTests.VerifyOnEveryShape(150); // the game verifies no scale above 100% yet (#1011)
game.Begin(Inputs, 0); // no file and no flag: English
Assert.IsFalse(Ui.Q("root").ClassListContains(UiLanguage.HebrewClass));
Assert.IsTrue(Ui.Q<Button>("settings-language-en").ClassListContains(SettingsPresenter.SelectedClass), "English is marked");
@@ -121,6 +123,7 @@ public class HebrewUiTests
Assert.AreEqual("עברית", Ui.Q<Button>("settings-language-he").text, "each language is named in itself");
var session = game.Bridge!.Session;
Assert.IsNull(game.Bridge.Queue(new Statecraft.Sim.SetMobilization(1.0)));
+ UiTestKit.Press(Ui.Q<Button>("settings-uiscale-150")); // the UI scale (#40) must survive the rebuild below
UiTestKit.Press(Ui.Q<Button>("settings-language-he"));
Assert.IsTrue(Ui.Q("root").ClassListContains(UiLanguage.HebrewClass), "Hebrew at once, no reload");
@@ -131,6 +134,8 @@ public class HebrewUiTests
Assert.IsTrue(Ui.Q<Button>("settings-language-he").ClassListContains(SettingsPresenter.SelectedClass), "Hebrew is marked");
Assert.IsFalse(Ui.Q<Button>("settings-language-en").ClassListContains(SettingsPresenter.SelectedClass));
Assert.AreEqual(UiLanguage.Hebrew, settings.Read(SettingsPresenter.LanguageKey), "kept in settings.txt");
+ Assert.AreEqual(new Vector2Int(1280, 720), Object.FindFirstObjectByType<UIDocument>().panelSettings.referenceResolution, "150% survives the switch");
+ Assert.IsTrue(Ui.Q<Button>("settings-uiscale-150").ClassListContains(SettingsPresenter.SelectedClass), "and 150% is marked");
game.Language = null; // a reload: only the file remains
game.Begin(Inputs, 0);
@@ -286,6 +291,7 @@ public class HebrewUiTests
("settings-quality-label", "settings.quality"), ("settings-quality-auto", "settings.quality.auto"),
("settings-quality-high", "settings.quality.high"), ("settings-quality-low", "settings.quality.low"),
("settings-language-label", "settings.language"), ("settings-language-note", "settings.language.note"),
+ ("settings-uiscale-label", "settings.uiscale"),
("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/HudTests.cs b/unity/Assets/Tests/EditMode/HudTests.cs
index d65c8e169..7dadea784 100644
--- a/unity/Assets/Tests/EditMode/HudTests.cs
+++ b/unity/Assets/Tests/EditMode/HudTests.cs
@@ -587,6 +587,7 @@ public class HudTests
("RouteLayer.cs", "CorridorMarginM = 100f", "a clearance in map metres that kit buildings and trees keep from a route (geometry, not a displayed number)"),
("CameraController.cs", "PixelsPerNotch = 100f", "wheel pixels in one mouse notch, to scale the browser's wheel events (input, not a displayed number)"),
("WildlifeLayer.cs", "MinimumCliffElevationM = 100f", "a real elevation in metres an ibex hex must reach (placement, not a displayed number)"),
+ ("SettingsPresenter.cs", "Level(int percent) => percent / 100.0", "the UI scale's stored percents (#40) to the level PlayerText.Percent formats (1.25 for 125%); it never formats text itself"),
};
[Test]
diff --git a/unity/Assets/Tests/EditMode/SettingsScreenTests.cs b/unity/Assets/Tests/EditMode/SettingsScreenTests.cs
index ddfcb87e8..eab450a86 100644
--- a/unity/Assets/Tests/EditMode/SettingsScreenTests.cs
+++ b/unity/Assets/Tests/EditMode/SettingsScreenTests.cs
@@ -1,5 +1,6 @@
#nullable enable
using System.Collections;
+using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
using Statecraft.Game;
@@ -25,6 +26,8 @@ public class SettingsScreenTests
string dir = "";
int level;
float[] scales = new float[0];
+ Vector2Int reference;
+ Dictionary<int, (float, float)> verified = new Dictionary<int, (float, float)>();
static UniversalRenderPipelineAsset Tier(int i) => (UniversalRenderPipelineAsset)QualitySettings.GetRenderPipelineAssetAt(i);
@@ -36,6 +39,8 @@ public class SettingsScreenTests
level = QualitySettings.GetQualityLevel();
scales = new float[QualitySettings.names.Length];
for (int i = 0; i < scales.Length; i++) scales[i] = Tier(i).renderScale;
+ reference = AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel).referenceResolution;
+ verified = new Dictionary<int, (float, float)>(SettingsPresenter.VerifiedShapes);
}
[TearDown]
@@ -46,6 +51,9 @@ public class SettingsScreenTests
GraphicsQuality.Apply(GraphicsQuality.Choice.Auto);
QualitySettings.SetQualityLevel(level, true);
for (int i = 0; i < scales.Length; i++) Tier(i).renderScale = scales[i];
+ AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel).referenceResolution = reference; // the project's panel
+ SettingsPresenter.VerifiedShapes.Clear(); // and the game's table
+ foreach (var kv in verified) SettingsPresenter.VerifiedShapes.Add(kv.Key, kv.Value);
if (Directory.Exists(dir)) Directory.Delete(dir, true);
}
@@ -258,6 +266,187 @@ public class SettingsScreenTests
}
}
+ static readonly (string button, int percent)[] UiScaleButtons =
+ { ("settings-uiscale-100", 100), ("settings-uiscale-125", 125), ("settings-uiscale-150", 150) };
+
+ /// <summary>The owner's UI scale (#40, 18 Oct 2026): 100%, 125% and 150%, default 100%. A choice scales the whole panel
+ /// at once (its reference resolution divided by the scale, so the panel's own ScaleWithScreenSize scale is multiplied by
+ /// it), the set button is marked, the choice is kept in the SettingsStore and comes back after a reload. Closing the
+ /// presenter puts the project's panel back, so a choice made in the editor never stays in the asset.</summary>
+ [Test]
+ public void EachUiScaleTakesEffectAtOnceAndSurvivesAReload([Values(false, true)] bool hebrew)
+ {
+ VerifyOnEveryShape(125, 150); // the mechanism a scale gets once it is verified; the game verifies none yet
+ var text = hebrew ? He : En;
+ using (var ui = new UiTestKit())
+ {
+ var ps = ui.Doc.panelSettings;
+ using (new SettingsPresenter(ui.Root, text, new SettingsStore(dir), panel: ps))
+ {
+ Assert.AreEqual(new Vector2Int(1920, 1080), ps.referenceResolution, "100% by default, with no file");
+ AssertUiScale(ui, 100);
+ foreach (var (name, percent) in UiScaleButtons)
+ Assert.AreEqual(percent + "%", ui.Q<Button>(name).text, "the button says its scale");
+ ui.Press("settings-uiscale-150");
+ Assert.AreEqual(new Vector2Int(1280, 720), ps.referenceResolution, "150% at once");
+ AssertUiScale(ui, 150);
+ Assert.AreEqual("150", new SettingsStore(dir).Read(SettingsPresenter.UiScaleKey));
+ ui.Press("settings-uiscale-125");
+ Assert.AreEqual(new Vector2Int(1536, 864), ps.referenceResolution, "125% at once");
+ AssertUiScale(ui, 125);
+ Assert.AreEqual("125", new SettingsStore(dir).Read(SettingsPresenter.UiScaleKey));
+ }
+ Assert.AreEqual(new Vector2Int(1920, 1080), ps.referenceResolution, "the project's panel is put back");
+ }
+ using (var ui = new UiTestKit()) // the reload: only the file remains
+ using (new SettingsPresenter(ui.Root, text, new SettingsStore(dir), panel: ui.Doc.panelSettings))
+ {
+ Assert.AreEqual(new Vector2Int(1536, 864), ui.Doc.panelSettings.referenceResolution, "125% after the reload");
+ AssertUiScale(ui, 125);
+ ui.Press("settings-uiscale-100");
+ Assert.AreEqual(new Vector2Int(1920, 1080), ui.Doc.panelSettings.referenceResolution, "and back to 100%");
+ Assert.AreEqual("100", new SettingsStore(dir).Read(SettingsPresenter.UiScaleKey));
+ }
+ }
+
+ /// <summary>A stored value the game does not offer is 100%.</summary>
+ [Test]
+ public void AnUnknownUiScaleIs100()
+ {
+ new SettingsStore(dir).Write(SettingsPresenter.UiScaleKey, "300");
+ using var ui = new UiTestKit();
+ using var settings = new SettingsPresenter(ui.Root, En, new SettingsStore(dir), panel: ui.Doc.panelSettings);
+ Assert.AreEqual(new Vector2Int(1920, 1080), ui.Doc.panelSettings.referenceResolution);
+ AssertUiScale(ui, 100);
+ }
+
+ /// <summary>As if the layout suites passed at these scales on every window shape: what a test of the scale's mechanism
+ /// needs now that the game offers only verified scales (SettingsPresenter.VerifiedShapes, empty for now). TearDown puts
+ /// the table back.</summary>
+ public static void VerifyOnEveryShape(params int[] percents)
+ {
+ foreach (var p in percents) SettingsPresenter.VerifiedShapes[p] = (0f, float.PositiveInfinity);
+ }
+
+ /// <summary>The owner's ruling on #1011 (19 Oct 2026), case 1: only the scales verified to fit are offered, 100% always.
+ /// No scale above 100% is verified yet (at 125% and 150% the layout suites fail on every window shape), so on each
+ /// shape the suites cover Settings offers 100% alone, marked. When a scale is verified, this test changes with it.</summary>
+ [UnityTest]
+ public IEnumerator OnlyTheVerifiedUiScalesAreOffered()
+ {
+ Assert.IsEmpty(SettingsPresenter.VerifiedShapes, "no scale above 100% is verified yet");
+ foreach (var (w, h) in new[] { (1920, 1080), (1280, 720), (1024, 768), (960, 1080), (360, 800), (2560, 1080) })
+ {
+ var window = new Window(w, h, dir);
+ try
+ {
+ yield return window.Settle();
+ foreach (var (name, percent) in UiScaleButtons)
+ Assert.AreEqual(percent == 100, window.Root.Q<Button>(name).resolvedStyle.display == DisplayStyle.Flex, $"{w}x{h}: {percent}% offered");
+ Assert.IsTrue(window.Root.Q<Button>("settings-uiscale-100").ClassListContains(SettingsPresenter.SelectedClass), $"{w}x{h}: 100% marked");
+ }
+ finally { window.Dispose(); }
+ }
+ }
+
+ /// <summary>Case 2: a saved 125% or 150% that is not verified to fit comes up as 100% at the next start, marked. The
+ /// file keeps the choice, so it comes back once that scale is verified for the window.</summary>
+ [Test]
+ public void ASavedScaleThatIsNotVerifiedFallsBackTo100OnLoad([Values(125, 150)] int saved)
+ {
+ new SettingsStore(dir).Write(SettingsPresenter.UiScaleKey, saved.ToString());
+ using var ui = new UiTestKit();
+ using var settings = new SettingsPresenter(ui.Root, En, new SettingsStore(dir), panel: ui.Doc.panelSettings);
+ Assert.AreEqual(new Vector2Int(1920, 1080), ui.Doc.panelSettings.referenceResolution, $"a saved {saved}% starts at 100%");
+ AssertUiScale(ui, 100);
+ Assert.AreEqual(saved.ToString(), new SettingsStore(dir).Read(SettingsPresenter.UiScaleKey), "the choice is kept");
+ }
+
+ /// <summary>Case 3: the fit follows the window. With 150% verified only on shapes from 1:2 to 1:1 (a stand-in: the
+ /// game verifies none yet), a saved 150% holds on 960x1080; a resize to 16:9 drops the panel to 100% and stops
+ /// offering 150%; back on 960x1080 the kept choice returns.</summary>
+ [UnityTest]
+ public IEnumerator ResizingOutOfAVerifiedShapeFallsBackTo100()
+ {
+ SettingsPresenter.VerifiedShapes[150] = (0.5f, 1f);
+ new SettingsStore(dir).Write(SettingsPresenter.UiScaleKey, "150");
+ var window = new Window(960, 1080, dir);
+ try
+ {
+ yield return window.Settle();
+ Assert.AreEqual(new Vector2Int(1280, 720), window.Panel.referenceResolution, "150% where it is verified");
+ Assert.IsTrue(window.Root.Q<Button>("settings-uiscale-150").ClassListContains(SettingsPresenter.SelectedClass), "150% is marked");
+ Assert.AreEqual(DisplayStyle.None, window.Root.Q<Button>("settings-uiscale-125").resolvedStyle.display, "125% is not verified");
+ yield return window.Resize(1920, 1080);
+ Assert.AreEqual(new Vector2Int(1920, 1080), window.Panel.referenceResolution, "16:9 is outside 150%'s shapes: 100%");
+ Assert.IsTrue(window.Root.Q<Button>("settings-uiscale-100").ClassListContains(SettingsPresenter.SelectedClass), "100% is marked");
+ Assert.AreEqual(DisplayStyle.None, window.Root.Q<Button>("settings-uiscale-150").resolvedStyle.display, "150% is not offered on 16:9");
+ Assert.AreEqual("150", new SettingsStore(dir).Read(SettingsPresenter.UiScaleKey), "the choice is kept");
+ yield return window.Resize(960, 1080);
+ Assert.AreEqual(new Vector2Int(1280, 720), window.Panel.referenceResolution, "150% again where it is verified");
+ }
+ finally { window.Dispose(); }
+ }
+
+ /// <summary>The real Game.uxml on its own copy of the project's panel at w x h, with the Settings screen's presenter on
+ /// a SettingsStore in dir.</summary>
+ sealed class Window : System.IDisposable
+ {
+ public readonly PanelSettings Panel; readonly GameObject go; readonly SettingsPresenter settings; RenderTexture rt;
+ public VisualElement Root => go.GetComponent<UIDocument>().rootVisualElement;
+
+ public Window(int w, int h, string dir)
+ {
+ rt = new RenderTexture(w, h, 0);
+ Panel = Object.Instantiate(AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel));
+ Panel.targetTexture = rt;
+ go = new GameObject("SettingsScaleTest");
+ go.SetActive(false);
+ var doc = go.AddComponent<UIDocument>();
+ doc.panelSettings = Panel;
+ doc.visualTreeAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(UiPaths.GameUxml);
+ go.SetActive(true);
+ Root.Q("root").RemoveFromClassList("loading");
+ settings = new SettingsPresenter(Root, En, new SettingsStore(dir), panel: Panel);
+ }
+
+ public IEnumerator Settle()
+ {
+ for (int i = 0; i < 30 && !(Root.layout.width > 0); i++) yield return null;
+ for (int i = 0; i < 3; i++) yield return null;
+ }
+
+ /// <summary>A new target texture of w x h, the way a window resize reaches the panel.</summary>
+ public IEnumerator Resize(int w, int h)
+ {
+ var old = rt;
+ rt = new RenderTexture(w, h, 0);
+ Panel.targetTexture = rt;
+ old.Release(); Object.DestroyImmediate(old);
+ for (int i = 0; i < 5; i++) yield return null;
+ }
+
+ public void Dispose()
+ {
+ settings.Dispose();
+ Object.DestroyImmediate(go); Object.DestroyImmediate(Panel); rt.Release(); Object.DestroyImmediate(rt);
+ }
+ }
+
+ /// <summary>The new label; its Hebrew waits for the native reviewer (#564).</summary>
+ [Test]
+ public void TheUiScaleLabelIsInBothLanguages()
+ {
+ Assert.AreEqual("UI scale", En["settings.uiscale"]);
+ Assert.AreEqual("גודל הממשק", He["settings.uiscale"]);
+ }
+
+ static void AssertUiScale(UiTestKit ui, int set)
+ {
+ foreach (var (name, percent) in UiScaleButtons)
+ Assert.AreEqual(percent == set, ui.Q<Button>(name).ClassListContains(SettingsPresenter.SelectedClass), $"{name} marked while {set}% is set");
+ }
+
/// <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]
@@ -284,16 +473,19 @@ public class SettingsScreenTests
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>
+ /// <summary>The open screen at 1280x720 (the issue's size), in English and Hebrew, at each UI scale: 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). 125% and
+ /// 150% run as if verified (VerifyOnEveryShape): the screen itself must hold them once the rest of the UI does.</summary>
[UnityTest]
- public IEnumerator TheOpenScreenFitsAt1280x720InBothLanguages()
+ public IEnumerator TheOpenScreenFitsAt1280x720InBothLanguages([Values(100, 125, 150)] int uiScale)
{
var c = ContentLoader.Load(Paths.Content);
+ VerifyOnEveryShape(125, 150);
+ if (uiScale != 100) new SettingsStore(dir).Write(SettingsPresenter.UiScaleKey, uiScale.ToString());
foreach (var hebrew in new[] { false, true })
{
var text = hebrew ? He : En;
- string at = hebrew ? "he" : "en";
+ string at = (hebrew ? "he" : "en") + " at " + uiScale + "%";
var rt = new RenderTexture(1280, 720, 0);
var ps = Object.Instantiate(AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel));
ps.targetTexture = rt;
@@ -308,18 +500,21 @@ public class SettingsScreenTests
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));
+ var settings = new SettingsPresenter(root, text, new SettingsStore(dir), panel: ps);
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;
+ // 1280x720 is 2/3 of the 1920x1080 reference: the panel's scale is 2/3 times the UI scale.
+ Assert.AreEqual(1920f * 100f / uiScale, root.worldBound.width, 1f, at + ": the panel's logical width");
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",
"settings-quality-label", "settings-quality-auto", "settings-quality-high", "settings-quality-low",
- "settings-language-label", "settings-language-en", "settings-language-he", "settings-language-note" })
+ "settings-language-label", "settings-language-en", "settings-language-he", "settings-language-note",
+ "settings-uiscale-label", "settings-uiscale-100", "settings-uiscale-125", "settings-uiscale-150" })
{
var e = root.Q<TextElement>(name);
Assert.IsFalse(string.IsNullOrWhiteSpace(e.text), $"{at}: {name} has its text");
diff --git a/unity/Assets/UI/Game.uxml b/unity/Assets/UI/Game.uxml
index b6cec91b2..4d515e0f7 100644
--- a/unity/Assets/UI/Game.uxml
+++ b/unity/Assets/UI/Game.uxml
@@ -349,6 +349,15 @@
</ui:VisualElement>
</ui:VisualElement>
<ui:Label name="settings-language-note" text="Event cards are English only for now." class="settings-note muted" />
+ <!-- UI scale (SettingsPresenter.UiScales): three buttons, the one that is set carries .settings-choice-selected. -->
+ <ui:VisualElement class="row settings-row">
+ <ui:Label name="settings-uiscale-label" text="UI scale" class="settings-name" />
+ <ui:VisualElement class="row settings-choices">
+ <ui:Button name="settings-uiscale-100" text="100%" class="settings-switch" />
+ <ui:Button name="settings-uiscale-125" text="125%" class="settings-switch" />
+ <ui:Button name="settings-uiscale-150" text="150%" class="settings-switch" />
+ </ui:VisualElement>
+ </ui:VisualElement>
<Statecraft.Game.UI.UiFrame />
</ui:VisualElement>
<!-- The turn report (#1037, TurnReportPresenter): after End Turn, each top-bar number that changed and the sim's causes.
diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yaml
index 049a764cd..a229ba4c8 100644
--- a/unity/Assets/UI/strings.en.yaml
+++ b/unity/Assets/UI/strings.en.yaml
@@ -75,6 +75,7 @@ settings.quality.low: "Low"
# SettingsPresenter, not here. The note says what is not translated yet (#55).
settings.language: "Language"
settings.language.note: "Event cards are English only for now."
+settings.uiscale: "UI scale"
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.yaml
index 168170f42..d82b1ecc9 100644
--- a/unity/Assets/UI/strings.he.yaml
+++ b/unity/Assets/UI/strings.he.yaml
@@ -69,6 +69,9 @@ settings.quality.low: "נמוכה"
# says that the event cards are not translated yet (#55). For the native reviewer (#564).
settings.language: "שפה"
settings.language.note: "כרטיסי האירועים באנגלית בלבד בינתיים."
+# The UI scale choice (#40): "the size of the interface"; its buttons are numbers (100%, 125%, 150%). For the native
+# reviewer (#564).
+settings.uiscale: "גודל הממשק"
event.draft: "טיוטה"
start.source: "מתוך ההכרזה על הקמת מדינת ישראל (עיתון רשמי מס׳ 1, 14 במאי 1948) ותרגומה הרשמי לאנגלית. הציור נוצר בבינה מלאכותית."
# The recordist's name as the Israel State Archives spells it in its own description of item