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.

fix(ui): 4:3 top bar, per-file strings error, button theme test

eyalgolancd8b60eac06f
diff --git a/unity/Assets/Scripts/UI/UiText.cs b/unity/Assets/Scripts/UI/UiText.cs
index 3cd83649b..826c065f6 100644
--- a/unity/Assets/Scripts/UI/UiText.cs
+++ b/unity/Assets/Scripts/UI/UiText.cs
@@ -10,7 +10,8 @@ namespace Statecraft.Game.UI
public sealed class UiText
{
readonly Dictionary<string, string> map;
- UiText(Dictionary<string, string> map) { this.map = map; }
+ readonly string file;
+ UiText(Dictionary<string, string> map, string file) { this.map = map; this.file = file; }
/// <summary>Parses the strings file. Throws InvalidOperationException naming the file when it is empty or not a map.</summary>
public static UiText Parse(string yaml, string file = "strings.en.yaml")
@@ -19,11 +20,11 @@ namespace Statecraft.Game.UI
try { m = new DeserializerBuilder().WithDuplicateKeyChecking().Build().Deserialize<Dictionary<string, string>>(yaml ?? ""); }
catch (YamlDotNet.Core.YamlException e) { throw new InvalidOperationException($"{file}: {e.Message}", e); }
if (m == null || m.Count == 0) throw new InvalidOperationException($"{file}: no strings");
- return new UiText(m);
+ return new UiText(m, file);
}
public string this[string key] =>
- map.TryGetValue(key, out var v) ? v : throw new KeyNotFoundException($"strings.en.yaml has no key '{key}'");
+ map.TryGetValue(key, out var v) ? v : throw new KeyNotFoundException($"{file} has no key '{key}'");
public string Format(string key, params object[] args) => string.Format(CultureInfo.InvariantCulture, this[key], args);
}
diff --git a/unity/Assets/Tests/EditMode/UiFoundationTests.cs b/unity/Assets/Tests/EditMode/UiFoundationTests.cs
index 3a8d2f299..3ef453f86 100644
--- a/unity/Assets/Tests/EditMode/UiFoundationTests.cs
+++ b/unity/Assets/Tests/EditMode/UiFoundationTests.cs
@@ -77,4 +77,29 @@ public class UiFoundationTests
// Input System screen positions are y-up; ToPanel flips y before RuntimePanelUtils.ScreenToPanel (which does not).
Assert.AreEqual(RuntimePanelUtils.ScreenToPanel(panel, new Vector2(10, 20)), UiPointer.ToPanel(panel, new Vector2(10, 1060), 1080f));
}
+
+ [UnityTest]
+ public IEnumerator ButtonsUseTheStatecraftTheme()
+ {
+ using var ui = new UiTestKit();
+ var navy = new Color(9 / 255f, 14 / 255f, 26 / 255f, 1f);
+ var goldDim = new Color(196 / 255f, 160 / 255f, 92 / 255f, 0.45f);
+ var gold = new Color(196 / 255f, 160 / 255f, 92 / 255f, 1f);
+ var nav = ui.Q<Button>("nav-cabinet");
+ for (int i = 0; i < 10 && nav.resolvedStyle.backgroundColor.a < 0.5f; i++) yield return null;
+ void Near(Color e, Color a, string what) => Assert.That(Mathf.Abs(e.r - a.r) + Mathf.Abs(e.g - a.g) + Mathf.Abs(e.b - a.b) + Mathf.Abs(e.a - a.a), Is.LessThan(0.02f), $"{what}: expected {e} got {a}");
+ Near(navy, nav.resolvedStyle.backgroundColor, "nav background");
+ Near(goldDim, nav.resolvedStyle.borderTopColor, "nav border");
+ var end = ui.Q<Button>("end-turn");
+ Near(navy, end.resolvedStyle.backgroundColor, "end-turn background");
+ Near(gold, end.resolvedStyle.borderTopColor, "end-turn border");
+ }
+
+ [Test]
+ public void AMissingKeyNamesTheFileGivenToParse()
+ {
+ var text = UiText.Parse("a: b", "other.yaml");
+ var e = Assert.Throws<System.Collections.Generic.KeyNotFoundException>(() => { var _ = text["x"]; });
+ StringAssert.Contains("other.yaml", e.Message);
+ }
}
diff --git a/unity/Assets/Tests/EditMode/UiLayoutTests.cs b/unity/Assets/Tests/EditMode/UiLayoutTests.cs
index 683ac5625..28ca04733 100644
--- a/unity/Assets/Tests/EditMode/UiLayoutTests.cs
+++ b/unity/Assets/Tests/EditMode/UiLayoutTests.cs
@@ -17,7 +17,7 @@ public class UiLayoutTests
[UnityTest]
public IEnumerator NothingOverlapsAt1080pAnd720p()
{
- foreach (var (w, h) in new[] { (1920, 1080), (1280, 720) })
+ foreach (var (w, h) in new[] { (1920, 1080), (1280, 720), (1280, 1024) })
{
var rt = new RenderTexture(w, h, 0);
var ps = Object.Instantiate(AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel));
@@ -40,6 +40,21 @@ public class UiLayoutTests
foreach (var f in Fixed)
Assert.IsFalse(R(s).Overlaps(R(f)), $"{w}x{h}: {s} {R(s)} overlaps {f} {R(f)}");
Assert.LessOrEqual(R("meters").xMax, R("nav").xMin + 0.5f, $"{w}x{h}: the meters run into the screen buttons");
+ Assert.LessOrEqual(R("top-bar").xMin, root.Q(className: "date-box").worldBound.xMin, $"{w}x{h}: date box starts outside the top bar");
+ Assert.LessOrEqual(root.Q(className: "date-box").worldBound.xMax, R("meters").xMin + 0.5f, $"{w}x{h}: date box runs into the meters");
+ Assert.LessOrEqual(R("nav").xMax, root.Q(className: "turn-box").worldBound.xMin + 0.5f, $"{w}x{h}: the screen buttons run into the End Turn box");
+ Assert.LessOrEqual(root.Q(className: "turn-box").worldBound.xMax, R("top-bar").xMax + 0.5f, $"{w}x{h}: End Turn box overflows the top bar");
+ foreach (var m in root.Q("meters").Children()) // text may wrap in a narrow meter but must stay inside it and inside the bar
+ {
+ Assert.LessOrEqual(m.worldBound.yMax, R("top-bar").yMax + 0.5f, $"{w}x{h}: {m.name} overflows the top bar vertically");
+ foreach (var l in m.Query<Label>().ToList())
+ {
+ Assert.GreaterOrEqual(l.worldBound.xMin + 0.5f, m.worldBound.xMin, $"{w}x{h}: '{l.text}' leaves {m.name} on the left");
+ Assert.LessOrEqual(l.worldBound.xMax, m.worldBound.xMax + 0.5f, $"{w}x{h}: '{l.text}' leaves {m.name} on the right");
+ if (l.ClassListContains("meter-name") && !string.IsNullOrEmpty(l.text))
+ Assert.GreaterOrEqual(l.worldBound.height + 0.5f, l.resolvedStyle.fontSize, $"{w}x{h}: '{l.text}' collapsed");
+ }
+ }
foreach (var m in root.Q("meters").Children())
Assert.GreaterOrEqual(m.worldBound.width, 128.5f, $"{w}x{h}: {m.name} is squeezed below its minimum width"); // 130 less pixel rounding at 2/3 scale
}
diff --git a/unity/Assets/UI/Statecraft.uss b/unity/Assets/UI/Statecraft.uss
index 1e4b24937..4440f8f6f 100644
--- a/unity/Assets/UI/Statecraft.uss
+++ b/unity/Assets/UI/Statecraft.uss
@@ -56,17 +56,17 @@ Button:disabled { color: var(--ink-dim); border-color: rgba(120, 120, 120, 0.4);
flex-direction: row; align-items: center;
border-width: 0 0 1px 0; border-radius: 0; padding: 0 16px;
}
-.date-box { width: 190px; border-right-width: 1px; border-color: var(--gold-dim); padding-right: 12px; }
+.date-box { width: 190px; flex-shrink: 1; min-width: 150px; border-right-width: 1px; border-color: var(--gold-dim); padding-right: 12px; }
.year { -unity-font-definition: url("project://database/Assets/UI/Fonts/EBGaramond-SemiBold.ttf"); font-size: 36px; }
.meters { flex-direction: row; flex-grow: 1; }
-.meter { min-width: 130px; flex-shrink: 1; padding: 0 12px; border-right-width: 1px; border-color: var(--gold-dim); }
-.meter-name { font-size: 18px; color: var(--ink-dim); }
+.meter { min-width: 130px; flex-shrink: 1; padding: 0 8px; border-right-width: 1px; border-color: var(--gold-dim); }
+.meter-name { font-size: 18px; color: var(--ink-dim); white-space: normal; } /* wraps in a narrow meter */
.meter-row { flex-direction: row; align-items: flex-end; }
.meter-value { font-size: 26px; }
.meter-delta { font-size: 18px; margin-left: 8px; }
-.nav { flex-direction: row; }
+.nav { flex-direction: row; flex-shrink: 0; }
.nav Button { margin: 0 4px; -unity-text-align: middle-center; }
-.turn-box { width: 190px; align-items: flex-end; }
+.turn-box { width: 190px; flex-shrink: 1; min-width: 150px; align-items: flex-end; }
.end-turn { -unity-font-definition: url("project://database/Assets/UI/Fonts/EBGaramond-SemiBold.ttf"); font-size: 22px; border-color: var(--gold); }
/* Event card at the right, info panel at the bottom-left, minimap at the bottom-right. */