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): the top bar fits its 96px and screen lists scroll inside their screen
eyalgolan6a990da62767
diff --git a/unity/Assets/Tests/EditMode/UiLayoutTests.cs b/unity/Assets/Tests/EditMode/UiLayoutTests.csindex 28ca04733..012cd1285 100644--- a/unity/Assets/Tests/EditMode/UiLayoutTests.cs+++ b/unity/Assets/Tests/EditMode/UiLayoutTests.cs@@ -1,6 +1,10 @@using System.Collections;+using System.Collections.Generic;+using System.Linq;using NUnit.Framework;+using Statecraft.Game;using Statecraft.Game.UI;+using Statecraft.Sim;using UnityEditor;using UnityEngine;using UnityEngine.TestTools;@@ -61,4 +65,67 @@ public class UiLayoutTestsfinally { Object.DestroyImmediate(go); Object.DestroyImmediate(ps); rt.Release(); Object.DestroyImmediate(rt); }}}++ // Task 24, seen in headed Chrome: the top bar's labels were taller than the bar and, centred, ran off the top of the+ // screen at every size; the Cabinet list grew out of its screen over the top bar. Checked with every screen filled by+ // its presenter (an event open on the card), at 16:9 and at the wider viewports a browser window leaves.+ [UnityTest]+ public IEnumerator FilledScreensStayInsideTheirPanelsAndTheTopBarFits()+ {+ var c = ContentLoader.Load(Paths.Content);+ var text = UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings).text);+ var g = GameSession.New(c, GoldenRun.Seed, Mode.Historical);+ while (!g.State.PendingEvents.Contains("armistice_egypt")) g.Step(new Command[0]);+ g.Step(new Command[0]); // a Why report to show+ while (g.State.PendingEvents.Count == 0) g.Step(new Command[0]);+ var problems = new List<string>();+ foreach (var (w, h) in new[] { (1920, 1080), (1280, 720), (1920, 960), (1600, 757), (1366, 657) })+ {+ var rt = new RenderTexture(w, h, 0);+ var ps = Object.Instantiate(AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel));+ ps.targetTexture = rt;+ var go = new GameObject("LayoutTest");+ 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;+ var bridge = new SimBridge(g, text);+ var disposables = new List<System.IDisposable>+ {+ new HudPresenter(root, bridge, text), new EventCardPresenter(root, bridge, text, null),+ new CabinetPresenter(root, bridge, text, null), new BudgetPresenter(root, bridge, text),+ new DefencePresenter(root, bridge, text), new WhyPresenter(root, bridge, text),+ };+ var nav = new ScreenNav(root);+ try+ {+ for (int i = 0; i < 20 && float.IsNaN(root.Q("minimap").worldBound.width); i++) yield return null;+ yield return null;+ Rect R(VisualElement e) => e.worldBound;+ 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;+ var bar = root.Q("top-bar");+ foreach (var l in bar.Query<VisualElement>().ToList().Where(e => e != bar && e.resolvedStyle.display == DisplayStyle.Flex))+ if (!Inside(R(l), R(bar))) problems.Add($"{w}x{h}: top bar child {l.name}/{(l as Label)?.text ?? l.GetClasses().FirstOrDefault()} {R(l)} leaves the bar {R(bar)}");+ var card = root.Q("event-card");+ if (R(card).Overlaps(R(root.Q("minimap")))) problems.Add($"{w}x{h}: event card {R(card)} overlaps the minimap {R(root.Q("minimap"))}");+ foreach (var s in ScreenNav.Screens)+ {+ nav.Open(s);+ for (int i = 0; i < 3; i++) yield return null;+ var screen = root.Q("screen-" + s);+ foreach (var e in screen.Children().Concat(screen.Query<ScrollView>().ToList()).Where(e => e.resolvedStyle.display == DisplayStyle.Flex))+ if (!Inside(R(e), R(screen))) problems.Add($"{w}x{h}: {s} child {e.name}/{e.GetClasses().FirstOrDefault()} {R(e)} leaves the screen {R(screen)}");+ }+ nav.Open(null);+ }+ finally+ {+ nav.Dispose(); foreach (var d in disposables) d.Dispose();+ Object.DestroyImmediate(go); Object.DestroyImmediate(ps); rt.Release(); Object.DestroyImmediate(rt);+ }+ }+ Assert.IsEmpty(problems, string.Join("\n", problems));+ }}diff --git a/unity/Assets/UI/Game.uxml b/unity/Assets/UI/Game.uxmlindex a2f55d7f2..f81fb7615 100644--- a/unity/Assets/UI/Game.uxml+++ b/unity/Assets/UI/Game.uxml@@ -4,8 +4,10 @@<ui:VisualElement name="top-bar" class="panel top-bar"><ui:VisualElement class="date-box"><ui:Label name="year" class="year" />- <ui:Label name="turn" class="muted" />- <ui:Label name="date" class="muted" />+ <ui:VisualElement class="date-row">+ <ui:Label name="turn" class="muted" />+ <ui:Label name="date" class="muted" />+ </ui:VisualElement></ui:VisualElement><ui:VisualElement name="meters" class="meters"><ui:VisualElement name="meter-treasury" class="meter">diff --git a/unity/Assets/UI/Statecraft.uss b/unity/Assets/UI/Statecraft.ussindex 6dd50f90e..a24d64b82 100644--- a/unity/Assets/UI/Statecraft.uss+++ b/unity/Assets/UI/Statecraft.uss@@ -56,14 +56,19 @@ 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;}+/* Everything in the bar must fit its 96px (EB Garamond lines are about 1.55 x the font size): labels lose their default+ vertical padding and margin, the year is 32px, and turn and date share one line. */+.top-bar Label { padding-top: 0; padding-bottom: 0; margin-top: 0; margin-bottom: 0; }.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; }+.date-row { flex-direction: row; }+.date-row Label { font-size: 17px; margin-right: 8px; }+.year { -unity-font-definition: url("project://database/Assets/UI/Fonts/EBGaramond-SemiBold.ttf"); font-size: 32px; }.meters { flex-direction: row; flex-grow: 1; }.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-name { font-size: 16px; 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; }+.meter-value { font-size: 24px; }+.meter-delta { font-size: 16px; margin-left: 8px; }.nav { flex-direction: row; flex-shrink: 0; }.nav Button { margin: 0 4px; -unity-text-align: middle-center; }.turn-box { width: 190px; flex-shrink: 1; min-width: 150px; align-items: flex-end; }@@ -87,6 +92,10 @@ Button:disabled { color: var(--ink-dim); border-color: rgba(120, 120, 120, 0.4);.rung { flex-direction: row; padding: 4px 8px; border-left-width: 3px; border-color: rgba(0, 0, 0, 0); }.rung-current { border-color: var(--gold); background-color: rgba(196, 160, 92, 0.15); }.grow { flex-grow: 1; }+/* A growing row inside a screen (the Cabinet's seats and candidates) takes the height that is left and stretches its+ 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; }.toast { position: absolute; left: 30%; right: 30%; top: 112px; -unity-text-align: middle-center; white-space: normal; }