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.

Map labels: each pill nearer its own marker than any neighbour's (refs #599) (#623)

Eyal Golanc649d1a94e45
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 480249e3c..884d87675 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -620,6 +620,12 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
It decodes to the same bytes, so the terrain is unchanged (#44).
### Fixed
+- Map labels (refs #599): close over Jaffa's harbour the "Tel Aviv" and "Jaffa" pills no longer read swapped. Every pill
+ is now nearer its own settlement's marker than any other visible marker (by more than 4 px), in every placing pass,
+ since two sprawling kits' screen rectangles overlap and a spot against one's edge could sit by the other town. A city
+ keeps its name: when every spot round its sprawl fails it may hang just under its marker point, its last pass ignores
+ the 1948 localities' markers (Silwan is 1.5 km from Jerusalem), and a kit reaching behind the camera at the closest
+ zoom places its pill round the marker box instead of hiding it.
- Screenshot runs (`?shot`, `-shot`; `tools/art_checkpoint.sh`) show the map again: since the GDD cutover (#600) the
opening card, One Army, covered it in every capture. The card, its scrim and "Decision waiting" now stay hidden in a
screenshot run, as the units do (`EventCardPresenter.HiddenInCaptures`); normal play and the smoke run still show it.
diff --git a/unity/Assets/Scripts/UI/MapLabelsPresenter.cs b/unity/Assets/Scripts/UI/MapLabelsPresenter.cs
index dc66fac62..fe2441365 100644
--- a/unity/Assets/Scripts/UI/MapLabelsPresenter.cs
+++ b/unity/Assets/Scripts/UI/MapLabelsPresenter.cs
@@ -21,8 +21,9 @@ namespace Statecraft.Game.UI
/// box when there is no kit, or while the "kits" toggle is off and the boxes are drawn) to a screen rectangle, and
/// every spot a pill may take is placed against that rectangle: above it (centred, or to the left or right of its
/// centre), then beside it on the right or the left, then below it. Only when none of those fits may a pill sit over
- /// its kit, its bottom centre LiftPx above the settlement's point, and only if it covers at most MaxKitCover of the
- /// kit's rectangle (a big city's name over its own streets, never a kibbutz's roofs under a pill).
+ /// its kit, its bottom centre LiftPx above the settlement's point (or, a city failing that, its top centre LiftPx
+ /// below it), and only if it covers at most MaxKitCover of the kit's rectangle (a big city's name over its own
+ /// streets, never a kibbutz's roofs under a pill).
///
/// Declutter: pills are placed in priority order (city, then town and Arab town, then the rest, each in file order). A
/// pill is hidden (visibility, so it keeps its size and the choice does not flicker) when its marker is behind the
@@ -33,10 +34,14 @@ namespace Statecraft.Game.UI
/// (OccluderNames: the top bar, the left icon column, the info panel, the minimap and its map-layer caption, the event card), does not
/// overlap an already placed pill (its last laid-out size plus MarginPx), covers at most MaxKitCover of its own kit's
/// rectangle and of every other visible kit's, and is more than twice as far from every other visible marker's top as
- /// from its own kit (the kit alone, not the tokens on it), plus MarginPx, so no name reads as a neighbour's. A city
- /// that finds no such spot never loses its name: it takes, in this order, the first spot round its kit alone that
- /// still reads as its own (over a unit token if need be), then the first clear of panels, pills, tokens and its own
- /// kit, then the first clear of panels, pills and its own kit. A pill hidden in the last refresh needs HysteresisPx more
+ /// from its own kit (the kit alone, not the tokens on it), plus MarginPx, so no name reads as a neighbour's. Whatever
+ /// the spot, a pill is also nearer its own marker's top than any other visible marker's, by more than MarginPx
+ /// (issue #599: two sprawling kits' rectangles overlap and each holds the other's marker, so a spot against one's
+ /// edge can sit by the other's town). A city that finds no such spot keeps its name if it can: it takes, in this
+ /// order, the first spot round its kit alone that still reads as its own (over a unit token if need be), then the
+ /// first clear of panels, pills, tokens and its own kit, then the first clear of panels, pills and its own kit, each
+ /// still nearer its own marker than any other; last, the same with only the game settlements' markers counted, so a
+ /// 1948 locality's marker never takes a city's name. A pill hidden in the last refresh needs HysteresisPx more
/// room to come back, so it does not blink at a threshold. Refresh allocates nothing. The dense Tel Aviv - Lod cluster
/// keeps M2's anchor classes. The kits' bounds are read once, when the presenter is created (a later MapScene.Build
/// needs a new presenter; GameRoot makes one per Begin).
@@ -75,8 +80,10 @@ namespace Statecraft.Game.UI
const string Centre = "anchor-lower-centre", Left = "anchor-lower-left", Right = "anchor-lower-right";
/// <summary>Where a pill sits against its kit's screen rectangle: above it (centred on it, starting at its centre,
- /// or ending at it), beside it, below it, or over it (its bottom centre above the settlement's point).</summary>
- public enum Spot { AboveCentre, AboveLeft, AboveRight, BesideRight, BesideLeft, Below, Over }
+ /// or ending at it), beside it, below it, or over it (its bottom centre above the settlement's point), or, for a
+ /// city only and last in each of its passes, under the point (its top centre below it: issue #599, where the spots
+ /// round a sprawl are all by a neighbour and the point is too near the top bar for Over).</summary>
+ public enum Spot { AboveCentre, AboveLeft, AboveRight, BesideRight, BesideLeft, Below, Over, Under }
static readonly Spot[] Fallbacks = { Spot.AboveRight, Spot.AboveLeft, Spot.AboveCentre, Spot.BesideRight, Spot.BesideLeft, Spot.Below, Spot.Over };
static readonly HashSet<string> MinorTypes = new HashSet<string> { "village", "kibbutz", "moshav" };
static readonly Dictionary<string, string> AnchorClass = new Dictionary<string, string>
@@ -237,7 +244,7 @@ namespace Statecraft.Game.UI
}
/// <summary>The pill's rectangle at <paramref name="spot"/> against the kit's screen rectangle <paramref name="kit"/>
- /// (LiftPx clear of it); Over hangs it LiftPx above <paramref name="point"/> instead.</summary>
+ /// (LiftPx clear of it); Over hangs it LiftPx above <paramref name="point"/> instead, Under LiftPx below it.</summary>
public static Rect SpotRect(Spot spot, Rect kit, Vector2 point, Vector2 size)
{
float above = kit.yMin - LiftPx - size.y, cx = kit.center.x, cy = kit.center.y;
@@ -249,6 +256,7 @@ namespace Statecraft.Game.UI
Spot.BesideRight => new Rect(kit.xMax + LiftPx, cy - size.y / 2f, size.x, size.y),
Spot.BesideLeft => new Rect(kit.xMin - LiftPx - size.x, cy - size.y / 2f, size.x, size.y),
Spot.Below => new Rect(cx - size.x / 2f, kit.yMax + LiftPx, size.x, size.y),
+ Spot.Under => new Rect(point.x - size.x / 2f, point.y + LiftPx, size.x, size.y),
_ => new Rect(point.x - size.x / 2f, point.y - LiftPx - size.y, size.x, size.y),
};
}
@@ -339,6 +347,9 @@ namespace Statecraft.Game.UI
it.TopPanel = ToPanel(t, cameraRect, screen, origin);
it.TopVisible = t.z > 0f && t.x >= 0f && t.x <= 1f && t.y >= 0f && t.y <= 1f && !UnderAPanel(it.TopPanel); // a marker under a panel is no one's neighbour
it.KitInFront = ProjectBoxes(kitsShown ? it.Kit : it.Marker, viewProjection, cameraRect, screen, origin, out it.KitPanel);
+ // A kit reaching behind the camera at the closest zoom has no screen rectangle: any settlement's pill is then
+ // placed round its marker box, as with the kits off, rather than hidden (second review of #599: Tel Aviv at 6 km).
+ if (!it.KitInFront && kitsShown) it.KitInFront = ProjectBoxes(it.Marker, viewProjection, cameraRect, screen, origin, out it.KitPanel);
it.Around = it.KitPanel; // the kit, and every token that stands on it: the spots are placed round both
for (int k = 0; k < keepClearRects.Count; k++)
if (keepClearRects[k].Overlaps(it.KitPanel)) it.Around = Rect.MinMaxRect(Mathf.Min(it.Around.xMin, keepClearRects[k].xMin),
@@ -369,13 +380,17 @@ namespace Statecraft.Game.UI
for (int k = 0; !found && k < Fallbacks.Length; k++)
if (Fallbacks[k] != it.First) found = TryPlace(it, size, home, Fallbacks[k], extra, true, true, ref shift);
// A city keeps its name (review of #518): next round its kit alone, still reading as its own but
- // over a token if need be; then clear of the tokens but not of its neighbours; last, neither.
- for (int pass = 0; !found && it.IsCity && pass < 3; pass++)
+ // over a token if need be; then clear of the tokens but not of its neighbours; then neither; last
+ // (second review of #599), nearer its own marker than any other game settlement's, the 1948
+ // localities' markers aside (they are placed after it and keep clear of its pill). Each pass ends
+ // with Under, which only a city takes.
+ for (int pass = 0; !found && it.IsCity && pass < 4; pass++)
{
- bool neighbours = pass == 0, avoidTokens = pass == 1;
- found = TryPlace(it, size, home, it.First, extra, neighbours, avoidTokens, ref shift);
+ bool neighbours = pass == 0, avoidTokens = pass == 1, countLocalities = pass < 3;
+ found = TryPlace(it, size, home, it.First, extra, neighbours, avoidTokens, ref shift, countLocalities);
for (int k = 0; !found && k < Fallbacks.Length; k++)
- if (Fallbacks[k] != it.First) found = TryPlace(it, size, home, Fallbacks[k], extra, neighbours, avoidTokens, ref shift);
+ if (Fallbacks[k] != it.First) found = TryPlace(it, size, home, Fallbacks[k], extra, neighbours, avoidTokens, ref shift, countLocalities);
+ if (!found) found = TryPlace(it, size, home, Spot.Under, extra, neighbours, avoidTokens, ref shift, countLocalities);
}
shown = found;
}
@@ -388,8 +403,11 @@ namespace Statecraft.Game.UI
/// <summary>Whether the pill fits at <paramref name="spot"/>; if so records it as placed and sets the shift from
/// its USS anchor's rectangle <paramref name="home"/>. With <paramref name="clearOfTokens"/> the spot is placed
- /// round the kit and the tokens on it and keeps clear of every token; without, round the kit alone.</summary>
- bool TryPlace(Item it, Vector2 size, Rect home, Spot spot, float extra, bool clearOfNeighbours, bool clearOfTokens, ref Vector2 shift)
+ /// round the kit and the tokens on it and keeps clear of every token; without, round the kit alone. Without
+ /// <paramref name="localitiesCount"/> the 1948 localities' markers do not count as others for the own-marker rule
+ /// (a city's last pass).</summary>
+ bool TryPlace(Item it, Vector2 size, Rect home, Spot spot, float extra, bool clearOfNeighbours, bool clearOfTokens, ref Vector2 shift,
+ bool localitiesCount = true)
{
var r = SpotRect(spot, clearOfTokens ? it.Around : it.KitPanel, it.TopPanel, size);
float m = MarginPx + extra;
@@ -399,15 +417,18 @@ namespace Statecraft.Game.UI
if (clearOfTokens) for (int i = 0; i < keepClearRects.Count; i++) if (keepClearRects[i].Overlaps(grown)) return false;
for (int i = 0; i < placed.Count; i++) if (placed[i].Overlaps(grown)) return false;
if (Cover(r, it.KitPanel) > MaxKitCover) return false;
- if (clearOfNeighbours)
+ // Issue #599: in every pass the pill is nearer its own marker than any other visible marker, by more than
+ // MarginPx. Two sprawling kits' rectangles overlap and hold each other's markers, so a spot against one's
+ // edge can sit by the other's town.
+ float mine = Gap(r, it.TopPanel) + MarginPx + extra;
+ float need = 2f * Gap(r, it.KitPanel) + MarginPx + extra; // owned by the town itself, never by the tokens on it
+ for (int i = 0; i < items.Count; i++)
{
- float need = 2f * Gap(r, it.KitPanel) + MarginPx + extra; // owned by the town itself, never by the tokens on it
- for (int i = 0; i < items.Count; i++)
- {
- var other = items[i];
- if (other == it || !other.TopVisible) continue;
- if (Gap(r, other.TopPanel) <= need || (other.KitInFront && Cover(r, other.KitPanel) > MaxKitCover)) return false;
- }
+ var other = items[i];
+ if (other == it || !other.TopVisible) continue;
+ float gap = Gap(r, other.TopPanel);
+ if (gap <= mine && (localitiesCount || !other.IsLocality)) return false;
+ if (clearOfNeighbours && (gap <= need || (other.KitInFront && Cover(r, other.KitPanel) > MaxKitCover))) return false;
}
placed.Add(r);
it.Placed = r;
diff --git a/unity/Assets/Tests/EditMode/MapLabelTests.cs b/unity/Assets/Tests/EditMode/MapLabelTests.cs
index 15188aadf..e5f3bd514 100644
--- a/unity/Assets/Tests/EditMode/MapLabelTests.cs
+++ b/unity/Assets/Tests/EditMode/MapLabelTests.cs
@@ -175,6 +175,7 @@ public class MapLabelTests
Assert.AreEqual(new Rect(115, 215 - lift - 10, 30, 10), over);
Assert.AreEqual(30f * 9f / (60f * 40f), MapLabelsPresenter.Cover(over, kit), 1e-4f, "over the kit: its bottom 9 rows, 270 of its 2400 px");
Assert.AreEqual(0f, MapLabelsPresenter.Cover(over, new Rect(0, 0, 0, 0)), "an empty kit is never covered");
+ Assert.AreEqual(new Rect(115, 215 + lift, 30, 10), MapLabelsPresenter.SpotRect(MapLabelsPresenter.Spot.Under, kit, point, size), "under the point (#599)");
}
[Test]
public void EverySettlementHasOneGaramondPillThatIgnoresThePointer()
@@ -676,6 +677,118 @@ public class MapLabelTests
finally { labels.Dispose(); hd.Dispose(); }
}
+ /// <summary>Issue #599: close over Jaffa's harbour (gameplay03's yaw at 30, 40 and 50% of its distance, with the game's
+ /// top-bar inset), Tel Aviv's and Jaffa's kit rectangles are hundreds of pixels across and overlap, and each holds or
+ /// touches the other's marker. Every shown pill must still be nearer its own settlement's marker than any other
+ /// visible marker, so "Tel Aviv" never hangs by Jaffa's harbour and "Jaffa" never sits on the pier by Tel Aviv. The
+ /// markers are measured independently of the presenter. Jaffa is named at every pose, and Tel Aviv wherever its
+ /// marker is visible (a city keeps its name). gameplay03 itself is checked the same way.</summary>
+ [UnityTest]
+ public IEnumerator EachPillIsNearerItsOwnMarkerByJaffasHarbour() => NearerOwnMarker(false);
+
+ /// <summary>The same with the units in play (#518's keep-clear moves the spots round the Kiryati Brigade).</summary>
+ [UnityTest]
+ public IEnumerator EachPillIsNearerItsOwnMarkerByJaffasHarbourWithTheUnits() => NearerOwnMarker(true);
+
+ IEnumerator NearerOwnMarker(bool units)
+ {
+ var hd = new HdPanel(cam);
+ var labels = Labels(hd, units);
+ var inset = new TopBarInset(hd.Root, rig);
+ try
+ {
+ var g03 = PromoPose.Gameplay03;
+ foreach (var pose in new[] { g03, new PromoPose("jaffa30", 34.76, 32.05, 0.3f * g03.Distance, g03.Yaw),
+ new PromoPose("jaffa40", 34.76, 32.05, 0.4f * g03.Distance, g03.Yaw), new PromoPose("jaffa50", 34.76, 32.05, 0.5f * g03.Distance, g03.Yaw) })
+ {
+ pose.Apply(rig, map.Frame);
+ yield return null;
+ inset.Update();
+ yield return Settle(labels);
+ var tops = VisibleMarkerTops(hd, map);
+ var shown = labels.Slots.Where(Shown).Select(s => (id: s.name.Substring("slot-".Length), rect: s.Q<Label>().worldBound)).ToList();
+ foreach (var id in new[] { "tel_aviv", "jaffa" })
+ {
+ var p = shown.FirstOrDefault(x => x.id == id);
+ string Gaps() => string.Join(" ", new[] { "tel_aviv", "jaffa" }.Where(tops.ContainsKey).Select(o => $"{o} {Gap(p.rect, tops[o]):F0}"));
+ TestContext.WriteLine($"{pose.Name} units={units}: {id} marker {(tops.TryGetValue(id, out var t) ? t.ToString() : "not visible")} " +
+ (p.id == null ? "hidden" : $"pill {p.rect}, gap to {Gaps()}"));
+ }
+ Assert.IsTrue(shown.Any(x => x.id == "jaffa"), $"{pose.Name}: Jaffa is named");
+ if (tops.ContainsKey("tel_aviv")) Assert.IsTrue(shown.Any(x => x.id == "tel_aviv"), $"{pose.Name}: Tel Aviv's marker is visible, so it is named");
+ foreach (var (id, rect) in shown)
+ {
+ Assert.IsTrue(tops.ContainsKey(id), $"{pose.Name}: {id} is shown but its marker is not visible");
+ float own = Gap(rect, tops[id]);
+ foreach (var other in tops.Where(o => o.Key != id))
+ Assert.Less(own, Gap(rect, other.Value), $"{pose.Name}: the {id} pill {rect} is {own:F0} px from its own marker but {Gap(rect, other.Value):F0} px from {other.Key}'s");
+ }
+ }
+ }
+ finally { inset.Dispose(); labels.Dispose(); hd.Dispose(); }
+ }
+
+ /// <summary>Second review of #599: a city keeps its name. At gameplay03, at jaffa30, and over each city
+ /// (from the closest zoom out to 40 km, at five yaws, with the top-bar inset), every city whose marker is visible is named, with the units off and on, and
+ /// its pill is nearer its own marker than any other visible settlement's. Within LocalityDistanceM the 1948 localities'
+ /// markers are on the map too (Silwan is 1.5 km from Jerusalem), and they must not take a city's name away. The towns
+ /// the review named are logged (a town may give way, as before). No other settlement's pill hangs under its marker:
+ /// Spot.Under is a city's last resort.</summary>
+ [UnityTest]
+ public IEnumerator EveryCityKeepsItsNameCloseUp() => CitiesKeepTheirNames(false);
+
+ [UnityTest]
+ public IEnumerator EveryCityKeepsItsNameCloseUpWithTheUnits() => CitiesKeepTheirNames(true);
+
+ IEnumerator CitiesKeepTheirNames(bool units)
+ {
+ var hd = new HdPanel(cam);
+ var labels = Labels(hd, units);
+ var inset = new TopBarInset(hd.Root, rig);
+ try
+ {
+ var g03 = PromoPose.Gameplay03;
+ var cities = map.Settlements.Where(s => s.Type == "city").ToList();
+ Assert.GreaterOrEqual(cities.Count, 3, "Jerusalem, Tel Aviv and Haifa");
+ var poses = new System.Collections.Generic.List<(PromoPose pose, string? over)> { (g03, null), (new PromoPose("jaffa30", 34.76, 32.05, 0.3f * g03.Distance, g03.Yaw), null) };
+ foreach (var c in cities)
+ foreach (var d in new[] { CameraController.MinDistance, 10000f, 14000f, 18000f, 24000f, 30000f, 40000f })
+ foreach (var yaw in new[] { 0f, g03.Yaw, 90f, 180f, 270f })
+ poses.Add((new PromoPose($"{c.Id}{d / 1000f:F0}y{yaw:F0}", c.Lon, c.Lat, d, yaw), c.Id));
+ string[] towns = { "acre", "rosh_pinna", "rishon_lezion", "petah_tikva" };
+ foreach (var (pose, over) in poses)
+ {
+ pose.Apply(rig, map.Frame);
+ if (over != null) // over a city the look point is on the ground, as the game's pan keeps it (CameraController)
+ {
+ var at = rig.LookAt; at.y = map.Terrain.SampleHeight(at) + map.Terrain.transform.position.y;
+ rig.LookAt = at; rig.Apply();
+ }
+ yield return null;
+ inset.Update();
+ yield return Settle(labels);
+ var tops = VisibleMarkerTops(hd, map);
+ var shown = labels.Slots.Where(Shown).Select(s => (id: s.name.Substring("slot-".Length), rect: s.Q<Label>().worldBound)).ToList();
+ if (over != null) Assert.IsTrue(tops.ContainsKey(over), $"{pose.Name}: {over}'s marker is on screen, so this pose checks it");
+ TestContext.WriteLine($"{pose.Name} units={units}: " + string.Join(" ", cities.Select(c => c.Id).Concat(towns).Where(tops.ContainsKey)
+ .Select(id => $"{id}={(shown.Any(x => x.id == id) ? "named" : "HIDDEN")}")));
+ // Only a city hangs its pill under its marker (Spot.Under: top LiftPx below the marker top, centred on it).
+ foreach (var (id, rect) in shown.Where(x => tops.ContainsKey(x.id) && map.Settlements.First(s => s.Id == x.id).Type != "city"))
+ Assert.IsFalse(Mathf.Abs(rect.yMin - (tops[id].y + MapLabelsPresenter.LiftPx)) < 1f && Mathf.Abs(rect.center.x - tops[id].x) < 1f,
+ $"{pose.Name}: {id} is no city but its pill {rect} hangs under its marker {tops[id]}");
+ foreach (var c in cities.Where(c => tops.ContainsKey(c.Id)))
+ {
+ var p = shown.FirstOrDefault(x => x.id == c.Id);
+ Assert.IsNotNull(p.id, $"{pose.Name}: {c.Id}'s marker {tops[c.Id]} is visible, so it is named");
+ float own = Gap(p.rect, tops[c.Id]);
+ foreach (var other in tops.Where(o => o.Key != c.Id))
+ Assert.Less(own, Gap(p.rect, other.Value), $"{pose.Name}: the {c.Id} pill {p.rect} is {own:F0} px from its own marker but {Gap(p.rect, other.Value):F0} px from {other.Key}'s");
+ }
+ }
+ }
+ finally { inset.Dispose(); labels.Dispose(); hd.Dispose(); }
+ }
+
/// <summary>Re-review N1: a panel that appears (the event card) hides the pill it covers when its layout lands, from the
/// geometry event itself, with no other refresh (in the game that is before the frame is drawn, not one frame later).</summary>
[UnityTest]