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.

Accessibility: top bar rises and falls carry an up or down mark (L1) (Refs #2340) (#2504)

Berife007b186012
diff --git a/changelog.d/2340-top-bar-change-marks.md b/changelog.d/2340-top-bar-change-marks.md
new file mode 100644
index 000000000..0e738e556
--- /dev/null
+++ b/changelog.d/2340-top-bar-change-marks.md
@@ -0,0 +1,4 @@
+### Fixed
+
+- Every rise and fall in the top bar has a small up or down triangle before the signed number, so the change no longer
+ relies on green and red alone, in English and Hebrew (#2340).
diff --git a/unity/Assets/Scripts/UI/HudPresenter.cs b/unity/Assets/Scripts/UI/HudPresenter.cs
index 680e57376..9ef7c7c6b 100644
--- a/unity/Assets/Scripts/UI/HudPresenter.cs
+++ b/unity/Assets/Scripts/UI/HudPresenter.cs
@@ -144,6 +144,9 @@ namespace Statecraft.Game.UI
readonly Label? exhaustedLine;
public const float ExhaustedPx = 13f;
float exhaustedSize = ExhaustedPx;
+ /// <summary>The room before a change that its up or down mark takes (Statecraft.uss .meter-delta.delta-up, 9 px).</summary>
+ public const float ChangeMarkPadPx = 9f;
+ readonly List<Label> deltas = new List<Label>();
/// <summary>The plate's padding while the floor raises its text (the stylesheet's is 2 px top and bottom, 10-12 at the
/// sides): PlateSidePx at both sides keeps every line at least 0 px from the 18 px corner zones (TopBarTests), each the
/// corner scrolls' reach (about 14 px in) plus 4, and PlateEdgePx at the top and bottom keeps it inside the frame's
@@ -232,6 +235,7 @@ namespace Statecraft.Game.UI
var meter = root.Q<VisualElement>("meter-" + id); var caption = text["hud.caption." + id];
meter.Q<Label>(className: "meter-name").text = caption; // the bar shows the words its tooltip says
said[id] = (meter, caption);
+ var delta = root.Q<Label>(id + "-delta"); delta.generateVisualContent += PaintChange; deltas.Add(delta);
}
if (root.Q(MeterTip.TipName) != null) meterTip = new MeterTip(root, bridge, text, said.Values.Select(x => x.element));
// The text floor: checked now and twice a second, since a window resized at the same shape changes the panel's
@@ -274,6 +278,7 @@ namespace Statecraft.Game.UI
if (exhaustedLine != null) { exhaustedLine.style.fontSize = StyleKeyword.Null; exhaustedLine.style.whiteSpace = StyleKeyword.Null; }
if (dateRow != null) { dateRow.style.flexDirection = StyleKeyword.Null; if (dateRow.parent != null) PadPlate(dateRow.parent, false); }
bridge.Changed -= Render; endTurn.clicked -= onEndTurn; endTurn.generateVisualContent -= PaintHourglass;
+ foreach (var d in deltas) d.generateVisualContent -= PaintChange;
bar.UnregisterCallback<GeometryChangedEvent>(OnBarGeometry);
hudRoot.UnregisterCallback(onRootGeometry);
root.Q(className: "hemicycle-box")?.UnregisterCallback<GeometryChangedEvent>(OnCabinetGeometry);
@@ -708,6 +713,25 @@ namespace Statecraft.Game.UI
(m.visualElement.layout.height - 22f) / 2f, 22f, 22f), UiIcon.IsFocused(m.visualElement)); // the right side in Hebrew (#193)
}
+ /// <summary>L1 (#2340): a change's direction is not told by green and red alone, which deuteranopia cannot tell apart. A
+ /// small triangle in the change's own colour points up for a rise and down for a fall, in the room the stylesheet keeps
+ /// before the change (ChangeMarkPadPx; the right side in the mirrored Hebrew bar). Painted, as the hourglass is, because
+ /// the Hebrew face (Frank Ruhl Libre) has no arrow glyph. Owner ruling Q27, 4 Nov 2026:
+ /// https://github.com/eyalgolan/statecraft-israel/issues/2340#issuecomment-6623136558</summary>
+ static void PaintChange(MeshGenerationContext m)
+ {
+ var e = m.visualElement; bool up = e.ClassListContains("delta-up");
+ if (!up && !e.ClassListContains("delta-down")) return;
+ float w = UnityEngine.Mathf.Min(ChangeMarkPadPx - 2f, e.resolvedStyle.fontSize * 0.55f), h = w * 0.9f;
+ float cx = UiLanguage.Within(e) ? e.layout.width - 1f - w / 2f : 1f + w / 2f, cy = e.layout.height / 2f, tip = up ? -h / 2f : h / 2f;
+ var p = m.painter2D; // tip: the point's offset from the middle line, up (negative) for a rise; the base is opposite
+ p.fillColor = e.resolvedStyle.color;
+ p.BeginPath();
+ p.MoveTo(new UnityEngine.Vector2(cx - w / 2f, cy - tip)); p.LineTo(new UnityEngine.Vector2(cx + w / 2f, cy - tip)); p.LineTo(new UnityEngine.Vector2(cx, cy + tip));
+ p.ClosePath();
+ p.Fill();
+ }
+
void Set(string name, string value) => root.Q<Label>(name).text = value;
void Set(string meter, Meter m)
diff --git a/unity/Assets/Tests/EditMode/TopBarTests.cs b/unity/Assets/Tests/EditMode/TopBarTests.cs
index 3442e225b..b0e4a29b0 100644
--- a/unity/Assets/Tests/EditMode/TopBarTests.cs
+++ b/unity/Assets/Tests/EditMode/TopBarTests.cs
@@ -98,7 +98,11 @@ public class TopBarTests
{
foreach (var (name, delta) in new[] { ("treasury", PlayerText.MoneyChange(C, "treasury", -12.4)), ("immigration", text.Format("hud.delta_people", 12345.0)),
("security", "-10%"), ("support", "-10%"), ("cohesion", "-10%"), ("standing", "+10%"), ("fx", PlayerText.MoneyChange(C, "fx_reserves", 12.5)) })
- root.Q<Label>(name + "-delta").text = delta;
+ {
+ var label = root.Q<Label>(name + "-delta"); label.text = delta;
+ // The classes its sign gives (HudPresenter.Set), so the up or down mark's room is in the fit too (L1, #2340).
+ label.EnableInClassList("delta-up", delta.Contains("+")); label.EnableInClassList("delta-down", delta.Contains("-"));
+ }
foreach (var (name, value) in new[] { ("treasury", PlayerText.Money(C, "treasury", -123.4)), ("immigration", text.Format("hud.people", 123456.0)),
("fx", PlayerText.Money(C, "fx_reserves", 123.4)), ("security", "100%"), ("support", "100%"), ("cohesion", "100%"), ("standing", "100%") })
root.Q<Label>(name + "-value").text = value;
@@ -135,6 +139,53 @@ public class TopBarTests
}
+ /// <summary>L1 (#2340): every rise and fall in the bar carries a mark besides its green or red, which deuteranopia cannot
+ /// tell apart. In the room before the change (HudPresenter.ChangeMarkPadPx; its right side in the mirrored Hebrew bar) the
+ /// rendered bar has ink in the change's colour whose bottom row is at least twice as wide as its top row for a rise (a
+ /// triangle pointing up, its base below), and the other way round for a fall. With the widest values, which rise and
+ /// fall, at 1920x1080 and 1280x720.</summary>
+ [UnityTest]
+ public IEnumerator EveryRiseAndFallCarriesAnUpOrDownMark([Values(false, true)] bool hebrew, [Values(1920, 1280)] int w)
+ {
+ var problems = new List<string>(); int ups = 0, downs = 0;
+ yield return Rendered(w, w * 9 / 16, hebrew, (root, text) =>
+ {
+ var rt = ((IRuntimePanel)root.panel).panelSettings.targetTexture;
+ var tex = new Texture2D(rt.width, rt.height, TextureFormat.RGBA32, false);
+ RenderTexture.active = rt; tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0); tex.Apply(); RenderTexture.active = null;
+ try
+ {
+ float k = rt.width / root.panel.visualTree.layout.width; // texture pixels per panel pixel
+ foreach (var id in HudModel.MeterIds)
+ {
+ var d = root.Q<Label>(id + "-delta");
+ bool up = d.ClassListContains("delta-up"), down = d.ClassListContains("delta-down");
+ if (root.Q("meter-" + id).resolvedStyle.display == DisplayStyle.None || !up && !down) continue;
+ if (up) ups++; else downs++;
+ var b = d.worldBound; float x0 = hebrew ? b.xMax - HudPresenter.ChangeMarkPadPx : b.xMin;
+ var rows = new List<int>(); // texture rows from the top, one entry per ink pixel
+ for (int x = Mathf.FloorToInt(x0 * k); x < Mathf.CeilToInt((x0 + HudPresenter.ChangeMarkPadPx) * k); x++)
+ for (int y = Mathf.FloorToInt(b.yMin * k); y < Mathf.CeilToInt(b.yMax * k); y++)
+ {
+ var c = tex.GetPixel(x, rt.height - 1 - y); // ReadPixels row 0 is the bottom
+ bool ink = up ? c.g - c.r > 0.15f && c.g - c.b > 0.15f : c.r - c.g > 0.25f && c.r - c.b > 0.25f; // --up, --down
+ if (ink) rows.Add(y);
+ }
+ // A triangle is widest at its base and one point at its tip: compare the ink in its first and last rows.
+ int top = rows.Count == 0 ? 0 : rows.Min(), bottom = rows.Count == 0 ? 0 : rows.Max();
+ int first = rows.Count(r => r == top), last = rows.Count(r => r == bottom);
+ int toward = up ? last : first, away = up ? first : last; // the base's row, the tip's row
+ if (rows.Count < 8 || toward < 2 || toward < 2 * away)
+ problems.Add($"{w} {(hebrew ? "he" : "en")} {id} ({(up ? "rise" : "fall")} \"{d.text}\"): {rows.Count} ink px, {first} in the top row, {last} in the bottom row");
+ }
+ }
+ finally { Object.DestroyImmediate(tex); }
+ });
+ Assert.That(ups, Is.GreaterThan(0), "precondition: a rise is shown");
+ Assert.That(downs, Is.GreaterThan(0), "precondition: a fall is shown");
+ Assert.IsEmpty(problems, string.Join("\n", problems));
+ }
+
[UnityTest]
public IEnumerator LandscapeSafeInsetsKeepCaptionInkDisjoint()
{
diff --git a/unity/Assets/UI/Statecraft.uss b/unity/Assets/UI/Statecraft.uss
index 3de53ccb0..5e5a3e077 100644
--- a/unity/Assets/UI/Statecraft.uss
+++ b/unity/Assets/UI/Statecraft.uss
@@ -119,6 +119,9 @@ Button:disabled { color: var(--ink-dim); border-color: rgba(120, 120, 120, 0.4);
.meter-row { flex-direction: row; align-items: flex-end; }
.meter-value { font-size: 21px; color: var(--ink); }
.meter-delta { font-size: 16px; margin-left: 7px; }
+/* Room before a rise or a fall for its up or down mark, so the change is not told by colour alone (L1, #2340; painted by
+ HudPresenter.PaintChange, 9 px = its ChangeMarkPadPx). */
+.meter-delta.delta-up, .meter-delta.delta-down { padding-left: 9px; }
/* 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 {
@@ -1020,6 +1023,7 @@ Button.settings-choice-selected { -unity-font-definition: url("project://databas
.lang-he .meter-icon { margin-right: 0; margin-left: 5px; }
.lang-he .meter-delta { margin-left: 0; margin-right: 7px; }
.lang-he.hud-narrow .meter-delta { margin-right: 0; }
+.lang-he .meter-delta.delta-up, .lang-he .meter-delta.delta-down { padding-left: 0; padding-right: 9px; }
.lang-he .event-hide { margin: 2px 12px 0 0; }
.lang-he .event-image { margin-right: 0; margin-left: 12px; }
.lang-he .info-thumb { margin-right: 0; margin-left: 14px; }