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.

feat(ui): settlement labels as decluttered EB Garamond pills in UI Toolkit, crisp above the tilt-shift; TextMesh labels removed

eyalgolan81a89db6b218
diff --git a/docs/visual-v1.md b/docs/visual-v1.md
index 4c4928f1e..04d729210 100644
--- a/docs/visual-v1.md
+++ b/docs/visual-v1.md
@@ -69,3 +69,34 @@ Notes:
| Task | Name | Images | Owner verdict |
|---|---|---|---|
| 1 | t01-before | captures/visual/t01-before/*-compare*.png | (owner) |
+| 9 | t09-labels | captures/visual/t09-labels/*-compare*.png | (owner) |
+
+## Task 9: labels
+
+Settlement names are UI Toolkit pills (`MapLabelsPresenter`, EB Garamond SemiBold on navy with a gold edge) in the
+click-through `map-labels` layer, placed in `GameRoot.LateUpdate` with an inline pixel `translate` and hidden while the
+game loads. The world-space `TextMesh` labels are gone.
+
+Frame time, headless, DPR 1, `res=1920x1080 scale=0.80` (`?vprofile`, `machine_lock.py --exclusive --wait-unity`):
+
+| Pose | all | -labels | none | all - (-labels) | budget |
+|---|---|---|---|---|---|
+| gameplay03 | 2.30 (spread 0.15) | 2.36 (0.06) | 2.34 (0.04) | -0.06 ms | <= 1 + 0.15 ms: within |
+| diorama02 | 6.82 (0.06) | 6.55 (0.02) | 6.61 (0.14) | +0.27 ms | <= 1 + 0.06 ms: within |
+
+The profile holds the camera still, so after the first frames `Refresh` returns early (unchanged view-projection,
+panel size and zoom); the cost measured is the drawing of the pills, not the per-frame placement while the camera moves.
+
+Deviations from the plan text, each forced by a test:
+- Projection: `RuntimePanelUtils.CameraTransformWorldToPanel` flips y with `Screen.height`, which is wrong when the camera
+ draws to a texture of another size (edit-mode tests: 600 px off). The presenter maps the camera's viewport point
+ through `camera.rect` onto the panel's own size instead.
+- Declutter at the overview: the Tel Aviv - Lod cluster's markers sit 10-60 px apart there, and a town's pill could not
+ avoid a neighbour's marker with any anchor (Rishon LeZion's pill ended 10 px under Jaffa's marker). A pill other than
+ a city's is now also hidden when it comes within `NeighbourClearPx` (2 x LiftPx + MarginPx = 16 px) of another
+ settlement's marker top. At 90 km this hides nothing (11 of 25 shown, as before); at the overview 10 of 25 are shown.
+- City pills: 20 px text and 8 px side padding (plan: 22 px and 10 px), so Tel Aviv's centred pill ends clear of Petah
+ Tikva's marker at the overview.
+- `ThePillIsEbGaramondOnNavyWithAGoldEdgeAndHiddenWhileLoading` uses a 1920x1080 panel instead of `UiTestKit`'s: the
+ batch-mode screen gives that panel about 0.39 px per point, and UI Toolkit rounds the 1 px border up to one physical
+ pixel (2.57 points).
diff --git a/unity/Assets/Scripts/Map/MapScene.cs b/unity/Assets/Scripts/Map/MapScene.cs
index 1631b46b0..ee4a5a2df 100644
--- a/unity/Assets/Scripts/Map/MapScene.cs
+++ b/unity/Assets/Scripts/Map/MapScene.cs
@@ -18,6 +18,8 @@ namespace Statecraft.Game.Map
public HexFile Hexes { get; private set; }
public Terrain Terrain { get; private set; }
public Material MarkerMaterial => markerMaterial;
+ /// <summary>The settlements the last Build placed (settlements_1948.yaml), for the UI's map labels.</summary>
+ public IReadOnlyList<Settlement> Settlements { get; private set; } = new List<Settlement>();
/// <summary>The selected hex's outline: a child of the terrain (so a rebuild destroys it).</summary>
public const string SelectionName = "HexSelection";
@@ -116,6 +118,7 @@ namespace Statecraft.Game.Map
DiagLog.BootPhase("border skirt");
Frame = new GeoFrame(meta.lon0, meta.lon1, meta.lat0, meta.lat1, size.x, size.z);
var list = SettlementPlacer.Parse(inputs.SettlementsYaml, (meta.lon0, meta.lon1, meta.lat0, meta.lat1), SettlementsPath);
+ Settlements = list;
SettlementPlacer.Place(list, Frame, Terrain, markerMaterial).transform.SetParent(transform, true);
DiagLog.BootPhase("settlements placed");
diff --git a/unity/Assets/Scripts/Map/SettlementPlacer.cs b/unity/Assets/Scripts/Map/SettlementPlacer.cs
index 1df7e9b5f..b570a41b2 100644
--- a/unity/Assets/Scripts/Map/SettlementPlacer.cs
+++ b/unity/Assets/Scripts/Map/SettlementPlacer.cs
@@ -26,32 +26,16 @@ namespace Statecraft.Game.Map
{
public const string DefaultFileName = "settlements_1948.yaml";
- // Marker colour and box edge (m); label cap height (m). Cap heights give >= 18 / 14 / 11 px at the top (farthest
- // edge, ~128 km) of a 1080p flythrough frame at the rig's 90 km distance and 35-degree FOV (K1).
- static readonly Dictionary<string, (Color c, float h, float cap)> Marker = new Dictionary<string, (Color, float, float)>
+ // Marker colour and box edge (m) per type: placeholder art until the settlement art track.
+ static readonly Dictionary<string, (Color c, float h)> Marker = new Dictionary<string, (Color, float)>
{
- ["city"] = (new Color(0.93f, 0.92f, 0.88f), 1800f, 1500f), ["town"] = (new Color(0.88f, 0.84f, 0.76f), 1100f, 1150f),
- ["kibbutz"] = (new Color(0.80f, 0.35f, 0.25f), 600f, 900f), ["moshav"] = (new Color(0.78f, 0.45f, 0.30f), 600f, 900f),
- ["arab_town"] = (new Color(0.82f, 0.74f, 0.58f), 1100f, 1150f), ["village"] = (new Color(0.76f, 0.68f, 0.52f), 600f, 900f),
+ ["city"] = (new Color(0.93f, 0.92f, 0.88f), 1800f), ["town"] = (new Color(0.88f, 0.84f, 0.76f), 1100f),
+ ["kibbutz"] = (new Color(0.80f, 0.35f, 0.25f), 600f), ["moshav"] = (new Color(0.78f, 0.45f, 0.30f), 600f),
+ ["arab_town"] = (new Color(0.82f, 0.74f, 0.58f), 1100f), ["village"] = (new Color(0.76f, 0.68f, 0.52f), 600f),
};
- // Labels in the dense Tel Aviv - Lod cluster (and Safed / Rosh Pinna, 4 km apart) extend away from their neighbours
- // instead of centring on the marker.
- static readonly Dictionary<string, TextAnchor> LabelAnchor = new Dictionary<string, TextAnchor>
- {
- ["jaffa"] = TextAnchor.LowerRight, ["rishon_lezion"] = TextAnchor.LowerRight,
- ["lod"] = TextAnchor.LowerLeft, ["petah_tikva"] = TextAnchor.LowerLeft,
- ["safed"] = TextAnchor.LowerRight, ["rosh_pinna"] = TextAnchor.LowerLeft,
- };
-
- // East offset (m) of a label from its marker. Ramla sits between Rishon LeZion (west) and Lod (north-east): centred
- // and nudged west, its label stays over its own marker and clear of both neighbours' boxes.
- static readonly Dictionary<string, float> LabelOffsetEastM = new Dictionary<string, float> { ["ramla"] = -1500f };
-
- public const int LabelFontSize = 64; // glyph raster size; characterSize scales it to world metres
- public const float CapHeightPerUnit = 4.5f; // cap height (m) per unit of characterSize at LabelFontSize
- public const float LabelLift = 0.75f; // label base above the marker top, in box edges: clears the box's far top edge at the rig pitch
- static readonly Color LabelColour = new Color(0.98f, 0.97f, 0.93f), ShadowColour = new Color(0.06f, 0.05f, 0.04f, 0.9f);
+ /// <summary>The marker box's edge (m) for a settlement type; the UI's label sits on its top.</summary>
+ public static float MarkerHeightM(string type) => Marker[type].h;
static readonly int BaseColor = Shader.PropertyToID("_BaseColor");
@@ -136,47 +120,26 @@ namespace Statecraft.Game.Map
throw new InvalidDataException($"{at} {field} {v} outside the heightmap bounds {min.Value}..{max.Value}");
}
- /// <summary>Placeholder markers (real per-era prefabs come in M3/M4): a box sized by type plus a name label, under a
- /// returned "Settlements" root. The box is a plain MeshFilter + MeshRenderer (no collider) using the editor-made
+ /// <summary>Placeholder markers (per-era art comes with the settlement art track): a box sized by type, under a returned
+ /// "Settlements" root. The box is a plain MeshFilter + MeshRenderer (no collider) using the editor-made
/// <paramref name="markerMaterial"/> (no runtime Shader.Find, M0 correction 1); the per-type colour goes through a
- /// MaterialPropertyBlock. The label is light text with a dark drop shadow, above the box, facing the rig's pitch.</summary>
+ /// MaterialPropertyBlock. Names are drawn by the UI (MapLabelsPresenter), not here.</summary>
public static GameObject Place(List<Settlement> list, GeoFrame frame, Terrain terrain, Material markerMaterial)
{
var root = new GameObject("Settlements"); var parent = root.transform;
- var font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
var cube = Resources.GetBuiltinResource<Mesh>("Cube.fbx");
var block = new MaterialPropertyBlock();
foreach (var s in list)
{
var p = frame.ToWorld(s.Lon, s.Lat, 0); p.y = terrain.SampleHeight(p) + terrain.transform.position.y;
- var (c, h, cap) = Marker[s.Type];
+ var (c, h) = Marker[s.Type];
var box = new GameObject(s.Id); box.transform.SetParent(parent);
box.AddComponent<MeshFilter>().sharedMesh = cube;
var r = box.AddComponent<MeshRenderer>(); r.sharedMaterial = markerMaterial;
block.SetColor(BaseColor, c); r.SetPropertyBlock(block);
box.transform.position = p + Vector3.up * h / 2; box.transform.localScale = new Vector3(h, h, h);
-
- var anchor = LabelAnchor.TryGetValue(s.Id, out var a) ? a : TextAnchor.LowerCenter;
- var label = MakeText(s.Id + "_label", s.Name, font, cap, anchor, LabelColour);
- var east = LabelOffsetEastM.TryGetValue(s.Id, out var dx) ? dx : 0f;
- label.transform.SetPositionAndRotation(p + Vector3.up * h * (1f + LabelLift) + Vector3.right * east,
- Quaternion.Euler(CameraRig.Pitch, 0, 0));
- label.transform.SetParent(parent, true);
- var shadow = MakeText("shadow", s.Name, font, cap, anchor, ShadowColour);
- shadow.transform.SetParent(label.transform, false);
- shadow.transform.localPosition = new Vector3(cap * 0.07f, -cap * 0.07f, cap * 0.05f); // down-right, behind
}
return root;
}
-
- static GameObject MakeText(string name, string text, Font font, float capM, TextAnchor anchor, Color colour)
- {
- var go = new GameObject(name);
- go.AddComponent<MeshRenderer>().sharedMaterial = font.material;
- var t = go.AddComponent<TextMesh>();
- t.font = font; t.fontSize = LabelFontSize; t.characterSize = capM / CapHeightPerUnit;
- t.text = text; t.anchor = anchor; t.color = colour;
- return go;
- }
}
}
diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.cs
index c53dc3682..003e4548f 100644
--- a/unity/Assets/Scripts/UI/GameRoot.cs
+++ b/unity/Assets/Scripts/UI/GameRoot.cs
@@ -40,6 +40,7 @@ namespace Statecraft.Game.UI
/// <summary>Everything Begin created that must be undone, disposed in reverse order.</summary>
readonly List<IDisposable> owned = new List<IDisposable>();
MinimapPresenter? minimap;
+ MapLabelsPresenter? labels;
CameraRig? rig;
List<(string, int, int, DateTime)>? drawn;
@@ -161,6 +162,7 @@ namespace Statecraft.Game.UI
var camRig = rig = cameraController.GetComponent<CameraRig>();
Own(new TopBarInset(root, camRig)); // the map is framed below the top bar
var mini = minimap = Own(new MinimapPresenter(root, map.Hexes));
+ labels = Own(new MapLabelsPresenter(root, map, cameraController.GetComponent<Camera>()));
mini.Clicked += (lon, lat) => { camRig.LookAt = map.Frame.ToWorld(lon, lat, 0); camRig.Apply(); SyncMinimap(); };
Action onChanged = RenderPlacementsIfChanged;
bridge.Changed += onChanged;
@@ -208,7 +210,7 @@ namespace Statecraft.Game.UI
StopAllCoroutines();
for (int i = owned.Count - 1; i >= 0; i--) owned[i].Dispose();
owned.Clear();
- minimap = null; rig = null; drawn = null; logCamera = false;
+ minimap = null; labels = null; rig = null; drawn = null; logCamera = false;
// A ?profile run cut short (a stopped coroutine never reaches its restore line) must not leave the terrain at the
// profile's pixel error (Task 24 review M1). Nothing else changes it, so restoring is always right.
if (map != null && map.Terrain != null) map.Terrain.heightmapPixelError = MapBuilder.TerrainPixelError;
@@ -244,6 +246,9 @@ namespace Statecraft.Game.UI
internal static string CameraLine(float distance, float yaw) => FormattableString.Invariant($"CAMERA distance={distance:0} yaw={yaw:0.0}");
+ /// <summary>After every Update (CameraController moves the camera in its Update), so the pills never trail the camera.</summary>
+ void LateUpdate() => labels?.Refresh();
+
void Update()
{
SyncMinimap();
diff --git a/unity/Assets/Scripts/UI/MapLabelsPresenter.cs b/unity/Assets/Scripts/UI/MapLabelsPresenter.cs
new file mode 100644
index 000000000..743663a1f
--- /dev/null
+++ b/unity/Assets/Scripts/UI/MapLabelsPresenter.cs
@@ -0,0 +1,172 @@
+#nullable enable
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Statecraft.Game.Map;
+using UnityEngine;
+using UnityEngine.UIElements;
+
+namespace Statecraft.Game.UI
+{
+ /// <summary>Settlement names as UI Toolkit pills (EB Garamond SemiBold on navy with a gold edge, Statecraft.uss
+ /// ".map-label") in the click-through "map-labels" layer under the panels. Each pill sits in a zero-size absolute slot;
+ /// Refresh (GameRoot.LateUpdate, after the camera has moved) moves each slot with an inline pixel translate to its
+ /// marker's top as the camera sees it, LiftPx above it, so no layout pass runs per frame, and returns early when the
+ /// camera's view-projection, the panel size and the zoom are unchanged. Pills are placed in priority order (city, then
+ /// town and Arab town, then the rest, each in file order); a pill behind the camera or off screen, a minor place
+ /// (village, kibbutz, moshav) beyond DeclutterDistanceM, or a pill that would overlap an already placed one (its last
+ /// laid-out size plus MarginPx) is hidden with visibility, so it keeps its size and the choice does not flicker. A pill
+ /// other than a city's is also hidden when it would come within NeighbourClearPx of another settlement's marker top, so
+ /// no shown name reads as a neighbour's (the dense Tel Aviv - Lod cluster at the overview); cities always keep theirs.
+ /// Screen-space, so the tilt-shift never blurs them. The dense Tel Aviv - Lod cluster keeps M2's anchors and Ramla's
+ /// nudge west. The anchors are read once, when the presenter is created (a later MapScene.Build needs a new presenter;
+ /// GameRoot makes one per Begin).</summary>
+ public sealed class MapLabelsPresenter : IDisposable
+ {
+ public const string ContainerName = "map-labels", SlotClass = "map-label-slot", LabelClass = "map-label";
+ public const float LiftPx = 6f, MarginPx = 4f, DeclutterDistanceM = 150000f;
+ /// <summary>A pill's least gap to any other marker's top: twice its own gap (LiftPx) plus MarginPx.</summary>
+ public const float NeighbourClearPx = 2f * LiftPx + MarginPx;
+
+ static readonly HashSet<string> MinorTypes = new HashSet<string> { "village", "kibbutz", "moshav" };
+ static readonly Dictionary<string, string> AnchorClass = new Dictionary<string, string>
+ {
+ ["jaffa"] = "anchor-lower-right", ["rishon_lezion"] = "anchor-lower-right", ["lod"] = "anchor-lower-left",
+ ["petah_tikva"] = "anchor-lower-left", ["safed"] = "anchor-lower-right", ["rosh_pinna"] = "anchor-lower-left",
+ };
+ static readonly Dictionary<string, float> OffsetEastM = new Dictionary<string, float> { ["ramla"] = -1500f };
+
+ sealed class Item
+ {
+ public Settlement Settlement = null!; public Vector3 Anchor, MarkerTop; public VisualElement Slot = null!; public Label Label = null!;
+ public string AnchorClass = ""; public bool TopOnScreen; public Vector2 TopPanel;
+ }
+
+ readonly VisualElement container;
+ readonly Camera camera;
+ readonly Func<float> zoom;
+ readonly List<Item> items = new List<Item>(); // in placing (priority) order
+ Matrix4x4 lastViewProjection; Vector2 lastPanelSize; float lastZoom = float.NaN; bool sizesKnown;
+
+ public IReadOnlyList<Label> Labels { get; }
+ public IReadOnlyList<VisualElement> Slots { get; }
+
+ public MapLabelsPresenter(VisualElement root, MapScene map, Camera camera, Func<float>? zoomDistance = null)
+ {
+ container = root.Q<VisualElement>(ContainerName) ?? throw new InvalidOperationException($"Game.uxml has no '{ContainerName}' element");
+ this.camera = camera;
+ zoom = zoomDistance ?? (() => camera.TryGetComponent(out CameraRig rig) ? rig.Distance : 0f);
+ container.Clear();
+ var labels = new List<Label>(); var slots = new List<VisualElement>();
+ foreach (var s in map.Settlements)
+ {
+ var slot = new VisualElement { name = "slot-" + s.Id, pickingMode = PickingMode.Ignore };
+ slot.AddToClassList(SlotClass);
+ var anchorClass = AnchorClass.TryGetValue(s.Id, out var a) ? a : "anchor-lower-centre";
+ var label = new Label(s.Name) { name = "label-" + s.Id, pickingMode = PickingMode.Ignore };
+ label.AddToClassList(LabelClass);
+ label.AddToClassList("map-label-" + s.Type);
+ label.AddToClassList(anchorClass);
+ slot.Add(label);
+ container.Add(slot);
+ labels.Add(label); slots.Add(slot);
+ var anchor = Anchor(map, s); var top = map.Frame.ToWorld(s.Lon, s.Lat, 0); top.y = anchor.y;
+ items.Add(new Item { Settlement = s, Anchor = anchor, MarkerTop = top, Slot = slot, Label = label, AnchorClass = anchorClass });
+ }
+ // Stable sort: priority, then file order.
+ var ordered = items.Select((it, i) => (it, i)).OrderBy(x => Priority(x.it.Settlement.Type)).ThenBy(x => x.i).Select(x => x.it).ToList();
+ items.Clear(); items.AddRange(ordered);
+ Labels = labels; Slots = slots;
+ removeToggle?.Invoke();
+ removeToggle = VisualToggles.Register("labels", on => container.style.display = on ? DisplayStyle.Flex : DisplayStyle.None);
+ Refresh(force: true);
+ }
+
+ /// <summary>The world point a settlement's label hangs from: its marker's top, nudged east or west for a few crowded names.</summary>
+ public static Vector3 Anchor(MapScene map, Settlement s)
+ {
+ var p = map.Frame.ToWorld(s.Lon, s.Lat, 0);
+ p.x += OffsetEastM.TryGetValue(s.Id, out var dx) ? dx : 0f;
+ p.y = map.Terrain.SampleHeight(p) + map.Terrain.transform.position.y + SettlementPlacer.MarkerHeightM(s.Type);
+ return p;
+ }
+
+ /// <summary>Placing order: lower first. Cities, then towns and Arab towns, then villages, kibbutzim and moshavim.</summary>
+ public static int Priority(string type) => type == "city" ? 0 : type == "town" || type == "arab_town" ? 1 : 2;
+
+ public static bool HiddenByZoom(string type, float distance) => MinorTypes.Contains(type) && distance > DeclutterDistanceM;
+
+ /// <summary>The pill's panel rectangle when its anchor point is <paramref name="at"/> (the anchor class says which corner
+ /// of the pill sits there, USS translate).</summary>
+ public static Rect PillRect(Vector2 at, Vector2 size, string anchorClass) => anchorClass switch
+ {
+ "anchor-lower-left" => new Rect(at.x, at.y - size.y, size.x, size.y),
+ "anchor-lower-right" => new Rect(at.x - size.x, at.y - size.y, size.x, size.y),
+ _ => new Rect(at.x - size.x / 2f, at.y - size.y, size.x, size.y),
+ };
+
+ public void Refresh(bool force = false)
+ {
+ var panel = container.panel;
+ if (panel == null || camera == null) return;
+ var viewProjection = camera.projectionMatrix * camera.worldToCameraMatrix;
+ var panelSize = container.layout.size;
+ float distance = zoom();
+ if (!force && sizesKnown && viewProjection == lastViewProjection && panelSize == lastPanelSize && distance == lastZoom) return;
+ lastViewProjection = viewProjection; lastPanelSize = panelSize; lastZoom = distance;
+ sizesKnown = true;
+ var screen = panel.visualTree.layout.size; // the whole panel, which the camera's view fills
+ var origin = container.worldBound.position; // slots translate from the layer's top-left
+ bool laidOut = !(float.IsNaN(screen.x) || screen.x <= 0f || float.IsNaN(origin.x) || float.IsNaN(origin.y));
+ if (!laidOut) { sizesKnown = false; origin = Vector2.zero; } // before the first layout: cull by view only, place later
+ var r0 = camera.rect;
+ Vector2 ToPanel(Vector3 v) => new Vector2((r0.x + v.x * r0.width) * screen.x, (1f - (r0.y + v.y * r0.height)) * screen.y) - origin;
+ foreach (var it in items)
+ {
+ var t = camera.WorldToViewportPoint(it.MarkerTop);
+ it.TopOnScreen = t.z > 0f && t.x > -0.05f && t.x < 1.05f && t.y > -0.05f && t.y < 1.05f;
+ it.TopPanel = ToPanel(t);
+ }
+ var placed = new List<Rect>();
+ foreach (var it in items)
+ {
+ var v = camera.WorldToViewportPoint(it.Anchor);
+ bool shown = v.z > 0f && v.x > -0.05f && v.x < 1.05f && v.y > -0.05f && v.y < 1.05f && !HiddenByZoom(it.Settlement.Type, distance);
+ var at = Vector2.zero;
+ if (shown)
+ {
+ // Viewport to panel through the camera's own rect, not RuntimePanelUtils.CameraTransformWorldToPanel: that
+ // flips y with Screen.height, which is wrong whenever the camera draws to a texture (edit-mode tests,
+ // captures) and the screen is a different size.
+ at = ToPanel(v);
+ at.y -= LiftPx;
+ var size = new Vector2(it.Label.resolvedStyle.width, it.Label.resolvedStyle.height);
+ if (!laidOut || float.IsNaN(size.x) || size.x <= 0f) sizesKnown = false; // not laid out yet: show it, cull on a later refresh
+ else
+ {
+ var r = PillRect(at, size, it.AnchorClass);
+ var grown = new Rect(r.x - MarginPx, r.y - MarginPx, r.width + 2f * MarginPx, r.height + 2f * MarginPx);
+ if (placed.Any(p => p.Overlaps(grown)) || it.Settlement.Type != "city" && CrowdsANeighbour(it, r)) shown = false;
+ else placed.Add(r);
+ }
+ }
+ it.Slot.style.visibility = shown ? Visibility.Visible : Visibility.Hidden;
+ if (shown && laidOut) it.Slot.style.translate = new Translate(at.x, at.y);
+ }
+ }
+
+ bool CrowdsANeighbour(Item it, Rect r)
+ {
+ foreach (var other in items)
+ if (other != it && other.TopOnScreen && Gap(r, other.TopPanel) <= NeighbourClearPx) return true;
+ return false;
+ }
+
+ static float Gap(Rect r, Vector2 p) =>
+ new Vector2(Mathf.Max(0f, Mathf.Max(r.xMin - p.x, p.x - r.xMax)), Mathf.Max(0f, Mathf.Max(r.yMin - p.y, p.y - r.yMax))).magnitude;
+
+ Action? removeToggle; // the labels switch's removal token (VisualToggles.Register): a disposed presenter never removes a newer one
+
+ public void Dispose() { removeToggle?.Invoke(); removeToggle = null; container.Clear(); items.Clear(); }
+ }
+}
diff --git a/unity/Assets/Scripts/UI/MapLabelsPresenter.cs.meta b/unity/Assets/Scripts/UI/MapLabelsPresenter.cs.meta
new file mode 100644
index 000000000..6517dc1ba
--- /dev/null
+++ b/unity/Assets/Scripts/UI/MapLabelsPresenter.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 1c63cf887242b4796b2ea29a20a3c9c3
\ No newline at end of file
diff --git a/unity/Assets/Tests/EditMode/MapLabelTests.cs b/unity/Assets/Tests/EditMode/MapLabelTests.cs
new file mode 100644
index 000000000..de95ed7bb
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/MapLabelTests.cs
@@ -0,0 +1,247 @@
+#nullable enable
+using System.Collections;
+using System.IO;
+using System.Linq;
+using NUnit.Framework;
+using Statecraft.Game.Map;
+using Statecraft.Game.UI;
+using UnityEditor;
+using UnityEditor.SceneManagement;
+using UnityEngine;
+using UnityEngine.TestTools;
+using UnityEngine.UIElements;
+
+/// <summary>Plan Task 9: settlement labels as UI Toolkit pills in EB Garamond, decluttered and on their markers.</summary>
+public class MapLabelTests
+{
+ MapScene map = null!;
+ Camera cam = null!;
+ CameraRig rig = null!;
+
+ [SetUp]
+ public void Open()
+ {
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ map = Object.FindFirstObjectByType<MapScene>(); map.Build();
+ cam = Camera.main; rig = cam.GetComponent<CameraRig>();
+ Pose(34.85, 32.0, 90000f);
+ }
+
+ [TearDown]
+ public void Close() { cam.targetTexture = null; EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); VisualToggles.Clear(); }
+
+ void Pose(double lon, double lat, float distance)
+ {
+ rig.LookAt = map.Frame.ToWorld(lon, lat, 0); rig.Distance = distance; rig.Yaw = 0; rig.TopInset = 0; rig.Apply();
+ }
+
+ static bool Shown(VisualElement slot) => slot.style.visibility.value == Visibility.Visible;
+
+ [Test]
+ public void EverySettlementHasOneGaramondPillThatIgnoresThePointer()
+ {
+ using var ui = new UiTestKit();
+ using var labels = new MapLabelsPresenter(ui.Root, map, cam);
+ var names = map.Settlements.Select(s => s.Name).ToArray();
+ CollectionAssert.AreEqual(names, labels.Labels.Select(l => l.text).ToArray());
+ var container = ui.Q<VisualElement>(MapLabelsPresenter.ContainerName);
+ Assert.AreEqual(names.Length, container.childCount);
+ foreach (var slot in labels.Slots) Assert.AreEqual(PickingMode.Ignore, slot.pickingMode);
+ foreach (var l in labels.Labels)
+ {
+ Assert.IsTrue(l.ClassListContains(MapLabelsPresenter.LabelClass), l.text);
+ Assert.AreEqual(PickingMode.Ignore, l.pickingMode, l.text + " must not catch map clicks");
+ }
+ Assert.AreEqual(PickingMode.Ignore, container.pickingMode);
+ VisualToggles.Set("labels", false);
+ Assert.AreEqual(DisplayStyle.None, container.style.display.value, "the labels toggle hides the layer");
+ VisualToggles.Set("labels", true);
+ Assert.AreEqual(DisplayStyle.Flex, container.style.display.value);
+ }
+
+ [Test]
+ public void LabelsOffScreenAreHiddenAndComeBack()
+ {
+ using var ui = new UiTestKit();
+ using var labels = new MapLabelsPresenter(ui.Root, map, cam);
+ var tlv = labels.Slots.Single(s => s.name == "slot-tel_aviv");
+ Pose(35.5, 33.2, CameraController.MinDistance); // the far north, close up
+ labels.Refresh(force: true);
+ Assert.IsFalse(Shown(tlv), "Tel Aviv is off screen");
+ Pose(34.85, 32.0, 90000f);
+ labels.Refresh(force: true);
+ Assert.IsTrue(Shown(tlv));
+ }
+
+ [Test]
+ public void TheDenseClusterKeepsItsAnchorsAndMinorPlacesGiveWayAtTheOverview()
+ {
+ using var ui = new UiTestKit();
+ using var labels = new MapLabelsPresenter(ui.Root, map, cam);
+ string AnchorOf(string id) => labels.Labels.Single(l => l.name == "label-" + id).GetClasses().Single(c => c.StartsWith("anchor-"));
+ Assert.AreEqual("anchor-lower-right", AnchorOf("jaffa")); Assert.AreEqual("anchor-lower-right", AnchorOf("rishon_lezion"));
+ Assert.AreEqual("anchor-lower-left", AnchorOf("lod")); Assert.AreEqual("anchor-lower-left", AnchorOf("petah_tikva"));
+ Assert.AreEqual("anchor-lower-centre", AnchorOf("tel_aviv"));
+ var ramla = map.Settlements.Single(s => s.Id == "ramla");
+ Assert.AreEqual(map.Frame.ToWorld(ramla.Lon, ramla.Lat, 0).x - 1500f, MapLabelsPresenter.Anchor(map, ramla).x, 1f, "Ramla's label nudged west");
+ Assert.Less(MapLabelsPresenter.Priority("city"), MapLabelsPresenter.Priority("town"));
+ Assert.AreEqual(MapLabelsPresenter.Priority("town"), MapLabelsPresenter.Priority("arab_town"));
+ Assert.Less(MapLabelsPresenter.Priority("arab_town"), MapLabelsPresenter.Priority("kibbutz"));
+ foreach (var minor in new[] { "village", "kibbutz", "moshav" })
+ {
+ Assert.IsFalse(MapLabelsPresenter.HiddenByZoom(minor, 90000f), minor + " at 90 km");
+ Assert.IsTrue(MapLabelsPresenter.HiddenByZoom(minor, CameraController.MaxDistance), minor + " at the overview");
+ }
+ Assert.IsFalse(MapLabelsPresenter.HiddenByZoom("town", CameraController.MaxDistance));
+ Assert.AreEqual(new Rect(90, 70, 20, 10), MapLabelsPresenter.PillRect(new Vector2(100, 80), new Vector2(20, 10), "anchor-lower-centre"));
+ Assert.AreEqual(new Rect(100, 70, 20, 10), MapLabelsPresenter.PillRect(new Vector2(100, 80), new Vector2(20, 10), "anchor-lower-left"));
+ Assert.AreEqual(new Rect(80, 70, 20, 10), MapLabelsPresenter.PillRect(new Vector2(100, 80), new Vector2(20, 10), "anchor-lower-right"));
+ }
+
+ [Test]
+ public void RebuildingKeepsOneLabelPerSettlement()
+ {
+ using var ui = new UiTestKit();
+ var first = new MapLabelsPresenter(ui.Root, map, cam);
+ first.Dispose();
+ Assert.AreEqual(0, ui.Q<VisualElement>(MapLabelsPresenter.ContainerName).childCount, "dispose clears");
+ map.Build();
+ using var second = new MapLabelsPresenter(ui.Root, map, cam);
+ using var third = new MapLabelsPresenter(ui.Root, map, cam);
+ Assert.AreEqual(map.Settlements.Count, ui.Q<VisualElement>(MapLabelsPresenter.ContainerName).childCount);
+ }
+
+ /// <summary>Behavioural, not text (review N4/N6): with the real theme, a laid-out pill resolves to EB Garamond SemiBold on
+ /// the navy fill with the gold edge, and the whole layer is display:none while the root carries "loading" (the slots'
+ /// inline visibility cannot override that), and back once it is removed.</summary>
+ [UnityTest]
+ public IEnumerator ThePillIsEbGaramondOnNavyWithAGoldEdgeAndHiddenWhileLoading()
+ {
+ // A 1920x1080 panel (scale 1), as in the game: UiTestKit's panel follows the batch-mode screen (about 0.39 points per
+ // pixel there), and UI Toolkit rounds a 1 px border up to one physical pixel, 2.57 points.
+ var rt = new RenderTexture(1920, 1080, 0);
+ var ps = Object.Instantiate(AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel)); ps.targetTexture = rt;
+ var go = new GameObject("LabelPanel"); go.SetActive(false);
+ var doc = go.AddComponent<UIDocument>(); doc.panelSettings = ps; doc.visualTreeAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(UiPaths.GameUxml);
+ go.SetActive(true);
+ var labels = new MapLabelsPresenter(doc.rootVisualElement, map, cam);
+ try
+ {
+ var root = doc.rootVisualElement.Q<VisualElement>("root");
+ var container = doc.rootVisualElement.Q<VisualElement>(MapLabelsPresenter.ContainerName);
+ Assert.IsTrue(root.ClassListContains("loading"), "Game.uxml starts loading");
+ for (int i = 0; i < 10; i++) yield return null;
+ Assert.AreEqual(DisplayStyle.None, container.resolvedStyle.display, "hidden while the game loads");
+ root.RemoveFromClassList("loading");
+ for (int i = 0; i < 10; i++) yield return null;
+ Assert.AreEqual(DisplayStyle.Flex, container.resolvedStyle.display, "shown once ready");
+ var pill = labels.Labels.Single(l => l.name == "label-tel_aviv");
+ var font = pill.resolvedStyle.unityFontDefinition;
+ var fontName = font.font != null ? font.font.name : font.fontAsset != null ? font.fontAsset.name : "";
+ StringAssert.Contains("EBGaramond-SemiBold", fontName);
+ var bg = pill.resolvedStyle.backgroundColor;
+ Assert.AreEqual(14f / 255f, bg.r, 0.01f); Assert.AreEqual(22f / 255f, bg.g, 0.01f); Assert.AreEqual(38f / 255f, bg.b, 0.01f);
+ Assert.AreEqual(0.82f, bg.a, 0.01f);
+ var gold = pill.resolvedStyle.borderTopColor;
+ Assert.AreEqual(196f / 255f, gold.r, 0.01f); Assert.AreEqual(160f / 255f, gold.g, 0.01f); Assert.AreEqual(92f / 255f, gold.b, 0.01f);
+ Assert.AreEqual(1f, pill.resolvedStyle.borderTopWidth, 0.01f);
+ Assert.IsNull(GameObject.Find("tel_aviv_label"), "no world-space TextMesh labels remain");
+ }
+ finally { labels.Dispose(); Object.DestroyImmediate(go); Object.DestroyImmediate(ps); rt.Release(); Object.DestroyImmediate(rt); }
+ }
+
+ static IEnumerator Settle(MapLabelsPresenter labels)
+ {
+ for (int i = 0; i < 20 && labels.Labels.Any(l => float.IsNaN(l.resolvedStyle.width) || l.resolvedStyle.width <= 0); i++) yield return null;
+ labels.Refresh(force: true); yield return null; // the first refresh with sizes declutters
+ labels.Refresh(force: true); yield return null;
+ }
+
+ /// <summary>Independent of the presenter's own projection call: the Tel Aviv pill's bottom centre is within 2 px of its
+ /// marker box's top, projected with Camera.WorldToScreenPoint and the panel's scale, LiftPx above it.</summary>
+ [UnityTest]
+ public IEnumerator APillSitsJustAboveItsMarkerTop()
+ {
+ var rt = new RenderTexture(1920, 1080, 0); var camRt = new RenderTexture(1920, 1080, 24);
+ var ps = Object.Instantiate(AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel)); ps.targetTexture = rt;
+ var go = new GameObject("LabelPanel"); go.SetActive(false);
+ var doc = go.AddComponent<UIDocument>(); doc.panelSettings = ps; doc.visualTreeAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(UiPaths.GameUxml);
+ go.SetActive(true);
+ cam.targetTexture = camRt;
+ var root = doc.rootVisualElement; root.Q("root")?.RemoveFromClassList("loading");
+ var labels = new MapLabelsPresenter(root, map, cam);
+ try
+ {
+ yield return Settle(labels);
+ var box = GameObject.Find("Settlements").transform.Find("tel_aviv");
+ var top = box.position + Vector3.up * box.lossyScale.y / 2;
+ var p = cam.WorldToScreenPoint(top); // pixels of the 1920x1080 camera target, y up
+ float scale = root.worldBound.width / 1920f;
+ var expected = new Vector2(p.x * scale, (1080f - p.y) * scale - MapLabelsPresenter.LiftPx);
+ var wb = labels.Labels.Single(l => l.name == "label-tel_aviv").worldBound;
+ TestContext.WriteLine($"Tel Aviv pill {wb}, expected bottom centre {expected}");
+ Assert.AreEqual(expected.x, wb.center.x, 2f, "centred on the marker");
+ Assert.AreEqual(expected.y, wb.yMax, 2f, "LiftPx above the marker's top");
+ }
+ finally
+ {
+ labels.Dispose(); Object.DestroyImmediate(go); Object.DestroyImmediate(ps); rt.Release(); Object.DestroyImmediate(rt);
+ cam.targetTexture = null; camRt.Release(); Object.DestroyImmediate(camRt);
+ }
+ }
+
+ static readonly string[] TelAvivCluster = { "tel_aviv", "jaffa", "petah_tikva", "rishon_lezion", "lod", "ramla", "rehovot" };
+
+ static float Gap(Rect r, Vector2 p) => new Vector2(Mathf.Max(0, Mathf.Max(r.xMin - p.x, p.x - r.xMax)), Mathf.Max(0, Mathf.Max(r.yMin - p.y, p.y - r.yMax))).magnitude;
+
+ /// <summary>M2's cluster test, on layout bounds (review I5): at 90 km (the flythrough's frame 120) and at the overview,
+ /// no two shown pills overlap, Tel Aviv is always shown, and every shown pill of the Tel Aviv - Lod cluster is at most
+ /// half as far from its own marker top as from any other cluster marker's top, so none reads as a neighbour's.</summary>
+ [UnityTest]
+ public IEnumerator ShownPillsNeverOverlapAndEachReadsAsItsOwn()
+ {
+ var rt = new RenderTexture(1920, 1080, 0); var camRt = new RenderTexture(1920, 1080, 24);
+ var ps = Object.Instantiate(AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel)); ps.targetTexture = rt;
+ var go = new GameObject("LabelPanel"); go.SetActive(false);
+ var doc = go.AddComponent<UIDocument>(); doc.panelSettings = ps; doc.visualTreeAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(UiPaths.GameUxml);
+ go.SetActive(true);
+ cam.targetTexture = camRt;
+ var root = doc.rootVisualElement; root.Q("root")?.RemoveFromClassList("loading");
+ var labels = new MapLabelsPresenter(root, map, cam);
+ try
+ {
+ foreach (var (name, lon, lat, distance) in new[] { ("90 km", 34.95, 31.3 + (32.9 - 31.3) * 120 / 239.0, 90000f), ("overview", PromoPose.Diorama02.Lon, PromoPose.Diorama02.Lat, CameraController.MaxDistance) })
+ {
+ Pose(lon, lat, distance);
+ yield return Settle(labels);
+ float scale = root.worldBound.width / 1920f;
+ Vector2 MarkerTop(string id)
+ {
+ var box = GameObject.Find("Settlements").transform.Find(id);
+ var p = cam.WorldToScreenPoint(box.position + Vector3.up * box.lossyScale.y / 2);
+ return new Vector2(p.x * scale, (1080f - p.y) * scale);
+ }
+ var shown = labels.Slots.Where(Shown).Select(s => (id: s.name.Substring("slot-".Length), rect: s.Q<Label>().worldBound)).ToList();
+ TestContext.WriteLine($"{name}: {shown.Count} of {labels.Slots.Count} pills shown");
+ Assert.IsTrue(shown.Any(s => s.id == "tel_aviv"), $"{name}: Tel Aviv is shown");
+ for (int i = 0; i < shown.Count; i++)
+ for (int j = i + 1; j < shown.Count; j++)
+ Assert.IsFalse(shown[i].rect.Overlaps(shown[j].rect), $"{name}: {shown[i].id} {shown[i].rect} overlaps {shown[j].id} {shown[j].rect}");
+ foreach (var (id, rect) in shown.Where(s => TelAvivCluster.Contains(s.id)))
+ {
+ float own = Gap(rect, MarkerTop(id));
+ foreach (var other in TelAvivCluster.Where(o => o != id))
+ Assert.Greater(Gap(rect, MarkerTop(other)), 2f * own + 4f, $"{name}: {id} pill is {own:F0} px from its marker but closer to {other}'s");
+ }
+ if (distance > MapLabelsPresenter.DeclutterDistanceM)
+ foreach (var s in map.Settlements.Where(s => MapLabelsPresenter.HiddenByZoom(s.Type, distance)))
+ Assert.IsFalse(Shown(labels.Slots.Single(x => x.name == "slot-" + s.Id)), $"{name}: {s.Id} ({s.Type}) is decluttered");
+ }
+ }
+ finally
+ {
+ labels.Dispose(); Object.DestroyImmediate(go); Object.DestroyImmediate(ps); rt.Release(); Object.DestroyImmediate(rt);
+ cam.targetTexture = null; camRt.Release(); Object.DestroyImmediate(camRt);
+ }
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/MapLabelTests.cs.meta b/unity/Assets/Tests/EditMode/MapLabelTests.cs.meta
new file mode 100644
index 000000000..0844ac6d2
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/MapLabelTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 366c4c55033aa4e29a642668334edab3
\ No newline at end of file
diff --git a/unity/Assets/Tests/EditMode/SettlementTests.cs b/unity/Assets/Tests/EditMode/SettlementTests.cs
index 470e9ed0f..2f8aede14 100644
--- a/unity/Assets/Tests/EditMode/SettlementTests.cs
+++ b/unity/Assets/Tests/EditMode/SettlementTests.cs
@@ -574,29 +574,6 @@ public class MapSceneTests
Assert.Greater(haifa.z, telAviv.z, "Haifa north of Tel Aviv"); Assert.Greater(haifa.z, jerusalem.z, "Haifa north of Jerusalem");
}
- [Test]
- public void LabelsAreLightWithADarkShadowAboveTheMarkerFacingTheRig()
- {
- var map = NewMap(); map.Build();
- var root = GameObject.Find("Settlements").transform;
- var cam = Camera.main.transform;
- foreach (var s in SettlementPlacer.Parse(File.ReadAllText(RealYamlPath), Bounds))
- {
- var box = root.Find(s.Id); var label = root.Find(s.Id + "_label"); Assert.IsNotNull(label, s.Id + " label");
- var text = label.GetComponent<TextMesh>(); Assert.AreEqual(s.Name, text.text);
- Assert.Greater(Mathf.Min(text.color.r, text.color.g, text.color.b), 0.85f, s.Id + " label is light");
- Assert.AreEqual(CameraRig.Pitch, label.eulerAngles.x, 0.01f, s.Id + " label pitch");
- // The whole label sits above the marker's top in screen terms: its base is above every point of the box.
- var top = box.position + Vector3.up * box.lossyScale.y / 2;
- var farTopEdge = top + Vector3.forward * box.lossyScale.z / 2;
- Assert.Greater(Vector3.Dot(label.position - farTopEdge, cam.up), 0f, s.Id + " label base above the box's far top edge");
- var shadow = label.Find("shadow"); Assert.IsNotNull(shadow, s.Id + " shadow");
- var st = shadow.GetComponent<TextMesh>(); Assert.AreEqual(s.Name, st.text);
- Assert.Less(Mathf.Max(st.color.r, st.color.g, st.color.b), 0.2f, s.Id + " shadow is dark");
- Assert.Greater(Vector3.Dot(shadow.position - label.position, cam.forward), 0f, s.Id + " shadow behind the label");
- }
- }
-
[Test]
public void CaptureOfASceneWithoutMapSceneNamesTheSceneAndTheFix()
{
@@ -609,48 +586,4 @@ public class MapSceneTests
StringAssert.Contains("Assets/Map.unity", ex.InnerException.Message);
StringAssert.Contains("MakeScene", ex.InnerException.Message);
}
-
- static readonly string[] TelAvivCluster = { "tel_aviv", "jaffa", "petah_tikva", "rishon_lezion", "lod", "ramla", "rehovot" };
-
- static Rect ScreenRect(Camera cam, Bounds b)
- {
- float x0 = float.MaxValue, y0 = float.MaxValue, x1 = float.MinValue, y1 = float.MinValue;
- for (int i = 0; i < 8; i++)
- {
- var c = b.center + Vector3.Scale(b.extents, new Vector3((i & 1) == 0 ? -1 : 1, (i & 2) == 0 ? -1 : 1, (i & 4) == 0 ? -1 : 1));
- var p = cam.WorldToScreenPoint(c);
- x0 = Mathf.Min(x0, p.x); y0 = Mathf.Min(y0, p.y); x1 = Mathf.Max(x1, p.x); y1 = Mathf.Max(y1, p.y);
- }
- return Rect.MinMaxRect(x0, y0, x1, y1);
- }
-
- static float Gap(Rect a, Rect b) =>
- new Vector2(Mathf.Max(0, Mathf.Max(a.xMin - b.xMax, b.xMin - a.xMax)), Mathf.Max(0, Mathf.Max(a.yMin - b.yMax, b.yMin - a.yMax))).magnitude;
-
- [Test]
- public void EveryTelAvivClusterLabelIsUnambiguouslyClosestToItsOwnMarker()
- {
- // At flythrough frame 120 (1080p), each label's screen box must be at most half as far from its own marker as from
- // any other marker of the cluster, so no label reads as a neighbour's.
- var map = NewMap(); map.Build();
- var cam = Camera.main; var rig = cam.GetComponent<CameraRig>();
- var rt = new RenderTexture(1920, 1080, 24); cam.targetTexture = rt;
- try
- {
- rig.LookAt = map.Frame.ToWorld(34.95, 31.3 + (32.9 - 31.3) * 120 / 239.0, 0); rig.Distance = 90000f; rig.Apply();
- var root = GameObject.Find("Settlements").transform;
- foreach (var id in TelAvivCluster)
- {
- var label = ScreenRect(cam, root.Find(id + "_label").GetComponent<MeshRenderer>().bounds);
- float own = Gap(label, ScreenRect(cam, root.Find(id).GetComponent<MeshRenderer>().bounds));
- foreach (var other in TelAvivCluster)
- {
- if (other == id) continue;
- float gap = Gap(label, ScreenRect(cam, root.Find(other).GetComponent<MeshRenderer>().bounds));
- Assert.Greater(gap, 2f * own + 4f, $"{id} label is {own:F0} px from its marker but {gap:F0} px from {other}'s");
- }
- }
- }
- finally { cam.targetTexture = null; Object.DestroyImmediate(rt); }
- }
}
diff --git a/unity/Assets/UI/Game.uxml b/unity/Assets/UI/Game.uxml
index cd821d6d3..1e565e4ae 100644
--- a/unity/Assets/UI/Game.uxml
+++ b/unity/Assets/UI/Game.uxml
@@ -3,6 +3,8 @@
<!-- "loading" until GameRoot has started the game: only the loading line shows (playtest 2, P2-1). -->
<ui:VisualElement name="root" class="root loading" picking-mode="Ignore">
<ui:Label name="loading" text="Loading the map of 1948…" class="loading-line" picking-mode="Ignore" />
+ <!-- Settlement names, positioned by MapLabelsPresenter under every panel; clicks pass through to the map. -->
+ <ui:VisualElement name="map-labels" class="map-labels" picking-mode="Ignore" />
<ui:VisualElement name="top-bar" class="panel top-bar">
<ui:VisualElement class="date-box">
<ui:Label name="year" class="year" />
diff --git a/unity/Assets/UI/Statecraft.uss b/unity/Assets/UI/Statecraft.uss
index 60fd510a7..9abed170e 100644
--- a/unity/Assets/UI/Statecraft.uss
+++ b/unity/Assets/UI/Statecraft.uss
@@ -133,3 +133,31 @@ Button:disabled { color: var(--ink-dim); border-color: rgba(120, 120, 120, 0.4);
.loading .loading-line { display: flex; }
.root.loading { background-color: var(--navy-solid); } /* the template's navy, not the default sky (final review M1) */
.loading .date-box, .loading .meters, .loading .nav, .loading .turn-box, .loading .info-panel, .loading .right-column { visibility: hidden; }
+
+/* Map labels (visual v1 Task 9): the promo's dark pill with a thin gold edge, in EB Garamond SemiBold. Each pill sits in a
+ zero-size slot that MapLabelsPresenter moves with an inline translate; the anchor class says which corner of the pill sits
+ on the marker's top. Hidden while the game loads. */
+.map-labels { position: absolute; left: 0; top: 0; right: 0; bottom: 0; }
+.loading .map-labels { display: none; }
+.map-label-slot { position: absolute; left: 0; top: 0; width: 0; height: 0; overflow: visible; }
+.map-label {
+ position: absolute;
+ -unity-font-definition: url("project://database/Assets/UI/Fonts/EBGaramond-SemiBold.ttf");
+ font-size: 18px;
+ color: rgb(243, 234, 216);
+ background-color: rgba(14, 22, 38, 0.82);
+ border-width: 1px;
+ border-color: var(--gold);
+ border-radius: 12px;
+ padding: 1px 8px 2px 8px;
+ margin: 0;
+ -unity-text-align: middle-center;
+ white-space: nowrap;
+}
+/* Tel Aviv's pill, centred on its marker, must end clear of Petah Tikva's marker 10 km east at the overview (about 61 px
+ apart there; MapLabelTests.ShownPillsNeverOverlapAndEachReadsAsItsOwn): 20 px and 8 px side padding, not 22 and 10. */
+.map-label-city { font-size: 20px; }
+.map-label-town, .map-label-arab_town { font-size: 19px; }
+.anchor-lower-centre { translate: -50% -100%; }
+.anchor-lower-left { translate: 0 -100%; }
+.anchor-lower-right { translate: -100% -100%; }