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: narrow windows wrap the top bar into two rows

eyalgolan6cf4031cbf1b
diff --git a/unity/Assets/Scripts/UI/HudPresenter.cs b/unity/Assets/Scripts/UI/HudPresenter.cs
index 7f1032a9b..29c60df36 100644
--- a/unity/Assets/Scripts/UI/HudPresenter.cs
+++ b/unity/Assets/Scripts/UI/HudPresenter.cs
@@ -21,6 +21,12 @@ namespace Statecraft.Game.UI
/// .EveryWindowShapeFitsTheBarAfterATurn), so the two tiers share the threshold.</summary>
public const float NarrowBelowPx = CompactBelowPx;
public const string NarrowClass = "hud-narrow";
+ /// <summary>Below this width (windows narrower than about square, e.g. a browser snapped to half a 1080p screen, about
+ /// 1360 logical px) one row cannot hold the badge, six meters, the screen buttons and End Turn: the root also gets
+ /// TwoRowClass, and the bar wraps into two rows, the date and the meters above, the screen buttons and End Turn
+ /// below (Statecraft.uss .hud-two-row).</summary>
+ public const float TwoRowBelowPx = 1500f;
+ public const string TwoRowClass = "hud-two-row";
public HudPresenter(VisualElement root, SimBridge bridge, UiText text)
{
@@ -42,7 +48,7 @@ namespace Statecraft.Game.UI
{
bridge.Changed -= Render; endTurn.clicked -= onEndTurn; endTurn.generateVisualContent -= PaintHourglass;
bar.UnregisterCallback<GeometryChangedEvent>(OnBarGeometry);
- bar.RemoveFromClassList(CompactClass); hudRoot.RemoveFromClassList(NarrowClass);
+ bar.RemoveFromClassList(CompactClass); hudRoot.RemoveFromClassList(NarrowClass); hudRoot.RemoveFromClassList(TwoRowClass);
}
// The bar's width does not depend on the class, so this settles in one pass.
@@ -53,6 +59,7 @@ namespace Statecraft.Game.UI
if (!(width > 0)) return; // NaN before layout: wait for it
bar.EnableInClassList(CompactClass, width < CompactBelowPx);
hudRoot.EnableInClassList(NarrowClass, width < NarrowBelowPx);
+ hudRoot.EnableInClassList(TwoRowClass, width < TwoRowBelowPx);
}
/// <summary>End Turn's hourglass, in the button's left padding (Statecraft.uss .end-turn), painted into the button so it
diff --git a/unity/Assets/Tests/EditMode/PromoHudTests.cs b/unity/Assets/Tests/EditMode/PromoHudTests.cs
index 6ca1a9a1a..ba9d04546 100644
--- a/unity/Assets/Tests/EditMode/PromoHudTests.cs
+++ b/unity/Assets/Tests/EditMode/PromoHudTests.cs
@@ -130,16 +130,18 @@ public class PromoHudTests
/// <summary>The bar at every window shape, after a turn has played and with the widest realistic changes and date:
/// 16:9 (1920 logical px) keeps the icons; 16:10 (~1821), 5:4, 4:3 and windows narrower than about square (1280x1024 ~1585,
/// 1024x768 ~1662, 1024x1024 ~1440, a browser snapped to half a 1080p screen ~1358, 800x1000 ~1288) get the compact,
- /// narrow HUD: no icons, and a taller bar whose meters stack the change under the value. Everywhere: every meter label stays inside its meter and the bar, no two meters'
+ /// narrow HUD: no icons, and a taller bar whose meters stack the change under the value. Below about 1500 logical px
+ /// (1024x1024, 960x1080, 800x1000) the bar also wraps into two rows. Everywhere: every meter label stays inside its meter and the bar, no two meters'
/// labels overlap, the meters end before the screen buttons, the date badge holds its widest line inside its trim at a
/// fixed width, and the panels start below the bar (review N2, N3 and the narrow-window follow-up).</summary>
[UnityTest]
public IEnumerator EveryWindowShapeFitsTheBarAfterATurn()
{
- foreach (var (w, h, compact, narrow) in new[] { (1920, 1080, false, false), (1280, 720, false, false), (1366, 768, false, false),
- (1920, 1200, true, true), (1440, 900, true, true),
- (1280, 1024, true, true), (1024, 768, true, true), (1024, 1024, true, true),
- (960, 1080, true, true), (800, 1000, true, true) })
+ foreach (var (w, h, compact, narrow, twoRow) in new[] { (1920, 1080, false, false, false), (1280, 720, false, false, false),
+ (1366, 768, false, false, false), (1920, 1200, true, true, false),
+ (1440, 900, true, true, false), (1280, 1024, true, true, false),
+ (1024, 768, true, true, false), (1024, 1024, true, true, true),
+ (960, 1080, true, true, true), (800, 1000, true, true, true) })
{
var rt = new RenderTexture(w, h, 0);
var ps = Object.Instantiate(AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel));
@@ -171,6 +173,7 @@ public class PromoHudTests
var where = $"{w}x{h} (bar {barRect.width:0} px)";
Assert.AreEqual(compact, bar.ClassListContains(HudPresenter.CompactClass), where + ": compact");
Assert.AreEqual(narrow, root.Q("root").ClassListContains(HudPresenter.NarrowClass), where + ": narrow");
+ Assert.AreEqual(twoRow, root.Q("root").ClassListContains(HudPresenter.TwoRowClass), where + ": two rows");
foreach (var icon in root.Q("meters").Query<UiIcon>().ToList())
Assert.AreEqual(compact ? DisplayStyle.None : DisplayStyle.Flex, icon.resolvedStyle.display, $"{where}: {icon.Glyph}");
var badge = root.Q(className: "date-box");
@@ -191,7 +194,22 @@ public class PromoHudTests
foreach (var b in labels)
if (a.meter != b.meter && a.label.worldBound.Overlaps(b.label.worldBound))
Assert.Fail($"{where}: '{a.label.text}' ({a.meter}) overlaps '{b.label.text}' ({b.meter})");
- Assert.LessOrEqual(root.Q("meters").worldBound.xMax, root.Q("nav").worldBound.xMin + 0.5f, where + ": the meters run into the screen buttons");
+ // The meters never reach the screen buttons or End Turn (beside them on one row, above them on two), with a
+ // margin for the browser's text measuring a little wider than the editor's.
+ foreach (var other in new[] { root.Q("nav").worldBound, root.Q(className: "turn-box").worldBound, badge.worldBound })
+ foreach (var (meter, l) in labels)
+ {
+ var r = l.worldBound; r.xMax += 12f;
+ Assert.IsFalse(r.Overlaps(other), $"{where}: '{l.text}' ({meter}) {r} is within 12 px of {other}");
+ }
+ // The meters are not squeezed: they take their natural widths with at least 5% to spare before the screen
+ // buttons (or the bar's end, on two rows), room for the browser's text measuring a little wider than the editor's.
+ var meters = root.Q("meters").Children().ToList();
+ var used = meters[meters.Count - 1].worldBound.xMax - meters[0].worldBound.xMin;
+ var limit = twoRow ? barRect.xMax - 14f : root.Q("nav").worldBound.xMin;
+ Assert.GreaterOrEqual(limit - meters[meters.Count - 1].worldBound.xMax, 0.05f * used, $"{where}: the meters use {used:0} of {limit - meters[0].worldBound.xMin:0} px");
+ foreach (var e in new[] { root.Q("nav"), root.Q(className: "turn-box"), badge })
+ Assert.LessOrEqual(e.worldBound.yMax, barRect.yMax + 0.5f, $"{where}: {e.name}{string.Join(".", e.GetClasses())} leaves the bar");
Assert.GreaterOrEqual(root.Q("right-column").worldBound.yMin, barRect.yMax, where + ": the event column starts under the bar");
var screen = root.Q("screen-why");
screen.style.display = DisplayStyle.Flex; // opened, as ScreenNav does
diff --git a/unity/Assets/UI/Statecraft.uss b/unity/Assets/UI/Statecraft.uss
index 7675476f5..08d9af1b7 100644
--- a/unity/Assets/UI/Statecraft.uss
+++ b/unity/Assets/UI/Statecraft.uss
@@ -89,26 +89,26 @@ Button:disabled { color: var(--ink-dim); border-color: rgba(120, 120, 120, 0.4);
.year { -unity-font-definition: url("project://database/Assets/UI/Fonts/EBGaramond-SemiBold.ttf"); font-size: 32px; color: var(--ink); }
.meters { flex-direction: row; flex-grow: 1; align-items: center; }
.meter {
- flex-direction: row; align-items: center; min-width: 130px; flex-shrink: 1; padding: 0 10px 0 8px;
+ flex-direction: row; align-items: center; min-width: 130px; flex-shrink: 1; padding: 0 8px 0 7px;
border-right-width: 1px; border-color: rgba(196, 160, 92, 0.25);
}
/* The icon gives way first in a narrow window (down to 26px), so the caption keeps its line. */
-.meter-icon { width: 38px; height: 38px; flex-shrink: 1; min-width: 26px; margin-right: 7px; }
+.meter-icon { width: 32px; height: 32px; flex-shrink: 1; min-width: 24px; margin-right: 6px; }
.meter-body { flex-shrink: 1; flex-grow: 1; min-width: 0; }
-.meter-name { font-size: 16px; color: var(--ink); white-space: normal; } /* wraps in a narrow meter */
+.meter-name { font-size: 16px; color: var(--ink); white-space: normal; max-width: 120px; } /* a long caption wraps rather than widen its meter */
#security-level { font-size: 14px; color: var(--ink-dim); }
.meter-row { flex-direction: row; align-items: flex-end; }
.meter-value { font-size: 24px; color: var(--ink); }
-.meter-delta { font-size: 17px; margin-left: 8px; }
+.meter-delta { font-size: 16px; margin-left: 7px; }
/* The screen buttons: a round, gold-rimmed icon with its name under it (the name keeps them legible without tooltips). */
.nav { flex-direction: row; flex-shrink: 0; align-items: center; }
.nav-button {
- width: 68px; height: 86px; margin: 0 2px; padding: 56px 0 0 0;
+ width: 64px; height: 86px; margin: 0 1px; padding: 56px 0 0 0;
background-color: rgba(0, 0, 0, 0); border-width: 0;
font-size: 14px; color: var(--ink-dim); -unity-text-align: upper-center; white-space: nowrap;
}
.nav-disc {
- position: absolute; top: 2px; left: 9px; width: 50px; height: 50px; padding: 11px;
+ position: absolute; top: 2px; left: 7px; width: 50px; height: 50px; padding: 11px;
border-radius: 25px; border-width: 1.5px; border-color: var(--gold-dim); background-color: var(--navy-deep);
}
.nav-button:hover { background-color: rgba(0, 0, 0, 0); color: var(--ink); }
@@ -135,7 +135,12 @@ Button:disabled { color: var(--ink-dim); border-color: rgba(120, 120, 120, 0.4);
.hud-narrow .meter-row { flex-direction: column; align-items: flex-start; }
.hud-narrow .meter-value { font-size: 22px; }
.hud-narrow .meter-delta { margin-left: 0; font-size: 15px; }
-.turn-box { width: 190px; flex-shrink: 1; min-width: 150px; align-items: flex-end; }
+/* Narrower than about square (HudPresenter adds hud-two-row): the bar wraps into two rows, the date badge and the meters
+ (78% of the bar, so they always take the first row) above, the screen buttons and End Turn below; the panels move down. */
+.hud-two-row .top-bar { height: 216px; padding-top: 6px; padding-bottom: 4px; flex-wrap: wrap; justify-content: space-between; align-content: space-around; }
+.hud-two-row .meters { width: 78%; flex-grow: 1; }
+.hud-two-row .right-column, .hud-two-row .screen, .hud-two-row .toast { top: 232px; }
+.turn-box { width: 156px; flex-shrink: 1; min-width: 150px; align-items: flex-end; }
#attention { font-size: 16px; }
.end-turn {
-unity-font-definition: url("project://database/Assets/UI/Fonts/EBGaramond-SemiBold.ttf"); font-size: 22px;