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: today's name of a 1948 locality by tap and in the info panel (refs #245) (#305)

Guy Shohamfb6244222566
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 951d563b4..6b2cef2cf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,10 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
## [Unreleased]
### Added
+- Map: today's name of a 1948 locality by tap and in the info panel. A tap on a locality pill toggles its tooltip, a tap
+ elsewhere hides it, and a mouse still hovers as before. The info panel lists the selected hex's 1948 localities with
+ today's name where a living place carries on, by the same rule as the tooltip. Keyboard players reach the panel list
+ once a hex can be selected from the keyboard (#41) (refs #245).
- Budget lines owned by office and date (`budget_owners` in `rules.yaml`, issue #108): the Immigration line (its id stays
`prime_minister`) belongs to the Minister of Immigration until 7 October 1951 and to the Prime Minister from 8 October
1951. A line scales effects through the owner of the day, and the Budget screen names that office. An office with
diff --git a/unity/Assets/Scripts/Map/Kits/Localities.cs b/unity/Assets/Scripts/Map/Kits/Localities.cs
index d14911f5f..302a97a46 100644
--- a/unity/Assets/Scripts/Map/Kits/Localities.cs
+++ b/unity/Assets/Scripts/Map/Kits/Localities.cs
@@ -39,6 +39,35 @@ namespace Statecraft.Game.Map.Kits
public int Sources;
}
+ /// <summary>The one "living place carries on" rule (owner ruling 2026-10-12), shared by the label tooltip and the info
+ /// panel: the name to show as today's name, in Hebrew when asked and one is recorded; null when no living place carries
+ /// on (<see cref="Place.Today"/> is null) or when today's name is the 1948 name itself (Nablus is Nablus). It shows
+ /// only what the file records.</summary>
+ public static string? TodayName(Place p, bool hebrew)
+ {
+ if (p.Today == null || SameName(p.Today, p.Settlement.Name)) return null;
+ return hebrew && !string.IsNullOrEmpty(p.TodayHe) ? p.TodayHe : p.Today;
+ }
+
+ static bool SameName(string a, string b)
+ {
+ static string Norm(string x) { var sb = new System.Text.StringBuilder(); foreach (var c in x) if (char.IsLetterOrDigit(c)) sb.Append(char.ToLowerInvariant(c)); return sb.ToString(); }
+ return Norm(a) == Norm(b);
+ }
+
+ /// <summary>The places by the hex they lie in (<paramref name="hexOf"/> maps a place to its hex), in the places' order.</summary>
+ public static Dictionary<(int q, int r), List<Place>> ByHex(IEnumerable<Place> places, System.Func<Place, (int q, int r)> hexOf)
+ {
+ var by = new Dictionary<(int q, int r), List<Place>>();
+ foreach (var p in places)
+ {
+ var h = hexOf(p);
+ if (!by.TryGetValue(h, out var list)) by[h] = list = new List<Place>();
+ list.Add(p);
+ }
+ return by;
+ }
+
public sealed class Area
{
public string Subdistrict = "";
diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.cs
index 1f730b3be..35ac1285b 100644
--- a/unity/Assets/Scripts/UI/GameRoot.cs
+++ b/unity/Assets/Scripts/UI/GameRoot.cs
@@ -180,9 +180,10 @@ namespace Statecraft.Game.UI
bridge.Changed += showUnits;
owned.Add(new Undo(() => bridge.Changed -= showUnits));
showUnits();
+ var localitiesAt = LocalitiesAt(map);
var info = Own(new InfoPanelPresenter(root, bridge, text, names, nav: nav,
selectedUnit: () => unitLayer.Selected is string id ? unitLayer.Tokens.First(p => p.Token.Unit.Id == id) : (Statecraft.Game.Map.Units.PlacedToken?)null,
- regions: regions));
+ regions: regions, localitiesAt: localitiesAt));
// A smoke session never touches the player's save: no autosave, and no New Game (which deletes the autosave).
// Leaving New Game out is safer than handing it a throwaway store: no file is ever deleted, no path has to be
// right on every platform, and the scripted run never presses it.
@@ -211,7 +212,7 @@ namespace Statecraft.Game.UI
var mini = minimap = Own(new MinimapPresenter(root, map.Hexes));
bool hebrew = text["ui.lang"] == "he"; // today's name in the UI's language (review M6)
labels = Own(new MapLabelsPresenter(root, map, cameraController.GetComponent<Camera>(), null,
- p => MapLabelsPresenter.TipOf(p, n => text.Format("map.today", hebrew && p.TodayHe != null ? p.TodayHe : n), text["map.mixed"])));
+ p => MapLabelsPresenter.TipOf(p, n => text.Format("map.today", n), text["map.mixed"], hebrew)));
mini.Clicked += (lon, lat) => { camRig.LookAt = map.Frame.ToWorld(lon, lat, 0); cameraController.Settle(); SyncMinimap(); labels?.Refresh(); }; // the click may come after LateUpdate (review M6)
Action onChanged = RenderPlacementsIfChanged;
bridge.Changed += onChanged;
@@ -267,6 +268,14 @@ namespace Statecraft.Game.UI
else if (Application.isPlaying && VisualShots.Requested()) StartCoroutine(VisualShots.Run(camRig, map.Frame, Debug.Log));
}
+ /// <summary>The 1948 localities in a hex (by the hex their point lies in, as the map picks hexes), for the info panel.</summary>
+ internal static Func<int, int, IReadOnlyList<Statecraft.Game.Map.Kits.Localities.Place>> LocalitiesAt(MapScene map)
+ {
+ var byHex = Statecraft.Game.Map.Kits.Localities.ByHex(map.Localities, p => HexPicker.FromLonLat(p.Settlement.Lon, p.Settlement.Lat, map.Hexes.bounds, map.Hexes.hex_size_km));
+ IReadOnlyList<Statecraft.Game.Map.Kits.Localities.Place> none = Array.Empty<Statecraft.Game.Map.Kits.Localities.Place>();
+ return (q, r) => byHex.TryGetValue((q, r), out var l) ? l : none;
+ }
+
T Own<T>(T d) where T : IDisposable { owned.Add(d); return d; }
/// <summary>A map click: on a unit's hex it selects the unit (the ring and its card; the hex outline is cleared, so
@@ -335,9 +344,11 @@ namespace Statecraft.Game.UI
{
if (labels == null) return;
labels.Refresh();
- // Today's name under a 1948 locality's pill while the pointer is over it (owner ruling 2026-10-11).
- var pointer = UnityEngine.InputSystem.Pointer.current;
- labels.Hover(pointer != null ? pointer.position.ReadValue() : (Vector2?)null);
+ // Today's name under a 1948 locality's pill: while a mouse (or pen) is over it (owner ruling 2026-10-11), or after a
+ // tap on it (#245). A touchscreen has no hover: its last touch position stays after the finger lifts.
+ labels.Hover(MapLabelsPresenter.HoverPosition(UnityEngine.InputSystem.Pointer.current));
+ var touch = UnityEngine.InputSystem.Touchscreen.current;
+ if (touch != null && touch.primaryTouch.press.wasPressedThisFrame) labels.Tap(touch.primaryTouch.position.ReadValue());
}
void Update()
diff --git a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
index 3fa699118..a6d460bd8 100644
--- a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
+++ b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
@@ -19,11 +19,14 @@ namespace Statecraft.Game.UI
readonly Button campButton, housingButton, defenceButton; readonly System.Action onCamp, onHousing, onDefence;
readonly System.Func<PlacedToken?> selectedUnit;
bool unitMode;
- readonly Label title, subtitle, region, settlements, placement, reason;
+ readonly Label title, subtitle, region, settlements, localitiesLabel, placement, reason;
+ readonly System.Func<int, int, IReadOnlyList<Statecraft.Game.Map.Kits.Localities.Place>>? localitiesAt;
readonly UiIcon thumb;
readonly IReadOnlyDictionary<string, string> settlementNames;
readonly MapRegions? regions;
+ /// <param name="localitiesAt">The 1948 localities that lie in a hex (null: the panel lists none); they are listed under the
+ /// settlements with today's name where the shared rule (Localities.TodayName) allows (#245).</param>
/// <param name="nav">Opens the Defence screen from a unit's card (null: the button does nothing).</param>
/// <param name="selectedUnit">The selected unit's token now (null: none), read at every render so the card follows
/// the state.</param>
@@ -31,11 +34,13 @@ namespace Statecraft.Game.UI
/// panel names the selected hex's sub-district or armistice zone, and any armistice line through it, with its
/// agreement (null: no region line).</param>
public InfoPanelPresenter(VisualElement root, SimBridge bridge, UiText text, IReadOnlyDictionary<string, string> settlementNames,
- ScreenNav? nav = null, System.Func<PlacedToken?>? selectedUnit = null, MapRegions? regions = null)
+ ScreenNav? nav = null, System.Func<PlacedToken?>? selectedUnit = null, MapRegions? regions = null,
+ System.Func<int, int, IReadOnlyList<Statecraft.Game.Map.Kits.Localities.Place>>? localitiesAt = null)
{
panel = root.Q<VisualElement>("info-panel"); this.bridge = bridge; this.text = text;
- this.settlementNames = settlementNames; this.regions = regions;
+ this.settlementNames = settlementNames; this.regions = regions; this.localitiesAt = localitiesAt;
title = panel.Q<Label>("info-title"); subtitle = panel.Q<Label>("info-subtitle"); region = panel.Q<Label>("info-region"); settlements = panel.Q<Label>("info-settlements");
+ localitiesLabel = panel.Q<Label>("info-localities");
placement = panel.Q<Label>("info-placement"); reason = panel.Q<Label>("info-reason");
thumb = panel.Q<UiIcon>("info-thumb");
campButton = panel.Q<Button>("build-camp"); housingButton = panel.Q<Button>("build-housing");
@@ -116,6 +121,23 @@ namespace Statecraft.Game.UI
return string.Join("\n", parts);
}
+ /// <summary>The "1948 localities" line for a hex: each place's 1948 name, with today's name where Localities.TodayName
+ /// allows ("Beisan (today: Beit She'an)"); empty for a hex with none.</summary>
+ public static string LocalitiesText(UiText text, IReadOnlyList<Statecraft.Game.Map.Kits.Localities.Place> places)
+ {
+ if (places.Count == 0) return "";
+ bool hebrew = text["ui.lang"] == "he";
+ var names = places.Select(p => Statecraft.Game.Map.Kits.Localities.TodayName(p, hebrew) is string today
+ ? text.Format("info.locality_today", p.Settlement.Name, today) : p.Settlement.Name);
+ return text.Format("info.localities", string.Join(", ", names));
+ }
+
+ void ShowLocalities(string line)
+ {
+ localitiesLabel.text = line;
+ localitiesLabel.style.display = line.Length == 0 ? DisplayStyle.None : DisplayStyle.Flex;
+ }
+
public void Render()
{
var c = bridge.Content; var s = bridge.State;
@@ -127,6 +149,7 @@ namespace Statecraft.Game.UI
var card = UnitCard.For(unit.Value, s, text);
panel.EnableInClassList("info-empty", false);
title.text = card.Title; subtitle.text = card.Subtitle; settlements.text = card.Body;
+ ShowLocalities("");
region.text = ""; // a unit's card names no sub-district (the last hex's would stay under it)
placement.text = card.Footer; reason.text = card.Note;
camp.style.display = DisplayStyle.None; housing.style.display = DisplayStyle.None;
@@ -138,6 +161,7 @@ namespace Statecraft.Game.UI
{
title.text = text["info.hint"];
subtitle.text = region.text = settlements.text = placement.text = reason.text = "";
+ ShowLocalities("");
camp.style.display = DisplayStyle.None; housing.style.display = DisplayStyle.None;
ShowThumb(null);
return;
@@ -152,6 +176,7 @@ namespace Statecraft.Game.UI
// hex, each with its agreement (true lines drawn to the nearest hex edge: the owner's ruling).
region.text = regions == null ? "" : RegionText(regions, text, q, r, s.Date);
settlements.text = owned.Count > 0 ? text.Format("info.owned", string.Join(", ", owned)) : "";
+ ShowLocalities(localitiesAt == null ? "" : LocalitiesText(text, localitiesAt(q, r)));
var here = MapActions.At(s, q, r);
var queued = bridge.QueuedLike(new MapAction(MapActions.Housing, q, r)) as MapAction;
placement.text = queued != null ? text.Format("info.queued", PlayerText.Capitalised(PlayerText.MapAction(c, queued.Action)))
diff --git a/unity/Assets/Scripts/UI/MapLabelsPresenter.cs b/unity/Assets/Scripts/UI/MapLabelsPresenter.cs
index 1fcd0db81..c8d66b016 100644
--- a/unity/Assets/Scripts/UI/MapLabelsPresenter.cs
+++ b/unity/Assets/Scripts/UI/MapLabelsPresenter.cs
@@ -53,6 +53,8 @@ namespace Statecraft.Game.UI
public const string LocalityClass = "map-label-locality", TooltipClass = "map-label-tooltip", TooltipName = "map-label-tooltip";
/// <summary>Extra room a pill hidden in the last refresh needs before it is shown again (review M7).</summary>
public const float HysteresisPx = 2f;
+ /// <summary>How far outside a pill a tap still counts as on it (a fingertip is wider than a mouse pointer).</summary>
+ public const float TapSlopPx = 8f;
/// <summary>The most of a kit's screen rectangle a pill may cover (issue #214): its own kit's, and any other
/// visible kit's.</summary>
public const float MaxKitCover = 0.1f;
@@ -106,28 +108,23 @@ namespace Statecraft.Game.UI
/// ("Today: Beit She'an" under "Beisan"; owner ruling 2026-10-12: none for a place that did not), "Mixed locality" for
/// Nesher; hidden otherwise, and never for a pill with nothing to say. Ignores the pointer, like the pills.</summary>
public Label Tooltip { get; }
- Item? hovered;
+ Item? tapped, shownFor; // the pill a tap opened; the pill the tooltip shows now
/// <summary>The default tooltip text (tests; GameRoot passes the UI strings): null when there is nothing to say.</summary>
public static string? DefaultTip(Statecraft.Game.Map.Kits.Localities.Place p) =>
TipOf(p, n => "Today: " + n, "Mixed locality");
- /// <summary>A locality's tooltip: "Mixed locality" for a mixed one, then today's name where one carries on and it is not
- /// the 1948 name itself (Nablus is Nablus); null when neither.</summary>
- public static string? TipOf(Statecraft.Game.Map.Kits.Localities.Place p, Func<string, string> today, string mixed)
+ /// <summary>A locality's tooltip: "Mixed locality" for a mixed one, then today's name where a living place carries on
+ /// (Localities.TodayName, the rule the info panel shares); null when neither.</summary>
+ public static string? TipOf(Statecraft.Game.Map.Kits.Localities.Place p, Func<string, string> today, string mixed, bool hebrew = false)
{
var lines = new List<string>();
if (p.Mixed) lines.Add(mixed);
- if (p.Today != null && !SameName(p.Today, p.Settlement.Name)) lines.Add(today(p.Today));
+ var name = Statecraft.Game.Map.Kits.Localities.TodayName(p, hebrew);
+ if (name != null) lines.Add(today(name));
return lines.Count == 0 ? null : string.Join("\n", lines);
}
- static bool SameName(string a, string b)
- {
- static string Norm(string x) { var sb = new System.Text.StringBuilder(); foreach (var c in x) if (char.IsLetterOrDigit(c)) sb.Append(char.ToLowerInvariant(c)); return sb.ToString(); }
- return Norm(a) == Norm(b);
- }
-
public MapLabelsPresenter(VisualElement root, MapScene map, Camera camera, Func<float>? zoomDistance = null, Func<Statecraft.Game.Map.Kits.Localities.Place, string?>? tipText = null)
{
var tip = tipText ?? DefaultTip;
@@ -386,16 +383,51 @@ namespace Statecraft.Game.UI
return true;
}
+ /// <summary>The pointer position the hover tooltip may follow, or null: a touchscreen has no hover (the Input System
+ /// keeps its last touch position after the finger lifts, which would leave a tooltip up), so a touch is answered by
+ /// <see cref="Tap"/> instead. A mouse, a pen or any other pointer hovers. Decided by the device type, not guessed.</summary>
+ public static Vector2? HoverPosition(UnityEngine.InputSystem.Pointer? pointer) =>
+ pointer == null || pointer is UnityEngine.InputSystem.Touchscreen ? (Vector2?)null : pointer.position.ReadValue();
+
/// <summary>Shows today's name under the locality pill at <paramref name="screenYUp"/> (an Input System pointer position,
- /// y up), or hides it (null: no pointer). Called after Refresh each frame (GameRoot.LateUpdate); allocates only when
- /// the hovered pill changes.</summary>
+ /// y up), or hides the hover tooltip (null: no hovering pointer, see <see cref="HoverPosition"/>). A position means a
+ /// mouse is in use, so a tooltip a tap left up goes. Called after Refresh each frame (GameRoot.LateUpdate); it also
+ /// keeps a tapped tooltip under its pill as the camera moves; allocates only when the shown pill changes.</summary>
public void Hover(Vector2? screenYUp)
{
var panel = container.panel;
- if (!screenYUp.HasValue || panel == null) { HoverItem(null); return; }
- HoverAt(UiPointer.ToPanel(panel, screenYUp.Value, Screen.height) - container.worldBound.position);
+ if (screenYUp.HasValue && panel != null)
+ {
+ tapped = null;
+ HoverAt(UiPointer.ToPanel(panel, screenYUp.Value, Screen.height) - container.worldBound.position);
+ return;
+ }
+ ShowTooltipFor(tapped);
+ }
+
+ /// <summary>A touch at <paramref name="screenYUp"/> (a Touchscreen position, y up): on a locality pill it toggles that
+ /// pill's tooltip (a second tap on it hides it); anywhere else it hides the tooltip.</summary>
+ public void Tap(Vector2 screenYUp)
+ {
+ var panel = container.panel;
+ if (panel == null) { TapAt(new Vector2(float.NaN, float.NaN)); return; }
+ TapAt(UiPointer.ToPanel(panel, screenYUp, Screen.height) - container.worldBound.position);
}
+ /// <summary>The hit test under Tap, at a point in the labels layer's coordinates. The pill is grown by TapSlopPx,
+ /// as a fingertip is wider than a mouse pointer.</summary>
+ public void TapAt(Vector2 layerPoint)
+ {
+ Item? hit = null;
+ for (int i = 0; i < items.Count && hit == null; i++)
+ if (Hittable(items[i]) && Grow(items[i].Placed, TapSlopPx).Contains(layerPoint)) hit = items[i];
+ tapped = hit != null && hit != tapped ? hit : null;
+ ShowTooltipFor(tapped);
+ }
+
+ static Rect Grow(Rect r, float by) => new Rect(r.x - by, r.y - by, r.width + 2f * by, r.height + 2f * by);
+ static bool Hittable(Item it) => it.IsLocality && it.Tip != null && it.ShownLast;
+
/// <summary>The hit test under Hover, at a point in the labels layer's coordinates: the shown locality pill (with
/// something to say) that contains it, or none.</summary>
public void HoverAt(Vector2 layerPoint)
@@ -404,23 +436,24 @@ namespace Statecraft.Game.UI
for (int i = 0; i < items.Count && over == null; i++)
{
var it = items[i];
- if (it.IsLocality && it.Tip != null && it.ShownLast && it.Placed.Contains(layerPoint)) over = it;
+ if (Hittable(it) && it.Placed.Contains(layerPoint)) over = it;
}
- HoverItem(over);
+ ShowTooltipFor(over);
}
/// <summary>Hover by locality id (tests): shows its tooltip when its pill is shown.</summary>
public void HoverLocality(string? id)
{
Item? over = null;
- foreach (var it in items) if (it.IsLocality && it.Tip != null && it.ShownLast && it.Settlement.Id == id) over = it;
- HoverItem(over);
+ foreach (var it in items) if (Hittable(it) && it.Settlement.Id == id) over = it;
+ ShowTooltipFor(over);
}
- void HoverItem(Item? over)
+ void ShowTooltipFor(Item? over)
{
- if (over == null) { if (hovered != null) { Tooltip.style.visibility = Visibility.Hidden; hovered = null; } return; }
- if (over != hovered) { Tooltip.text = over.Tip; hovered = over; }
+ if (over != null && !Hittable(over)) { over = null; if (tapped != null && !Hittable(tapped)) tapped = null; } // its pill went (zoom, a panel)
+ if (over == null) { if (shownFor != null) { Tooltip.style.visibility = Visibility.Hidden; shownFor = null; } return; }
+ if (over != shownFor) { Tooltip.text = over.Tip; shownFor = over; }
// left/top, not an inline translate: that would replace the USS translate (-50%) that centres it under the pill.
Tooltip.style.left = over.Placed.center.x; Tooltip.style.top = over.Placed.yMax + 2f;
Tooltip.style.visibility = Visibility.Visible;
diff --git a/unity/Assets/Tests/EditMode/LocalityNameTests.cs b/unity/Assets/Tests/EditMode/LocalityNameTests.cs
new file mode 100644
index 000000000..58cb22bab
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/LocalityNameTests.cs
@@ -0,0 +1,155 @@
+#nullable enable
+using System.Collections;
+using System.Linq;
+using NUnit.Framework;
+using Statecraft.Game;
+using Statecraft.Game.Map;
+using Statecraft.Game.Map.Kits;
+using Statecraft.Game.UI;
+using Statecraft.Sim;
+using UnityEditor;
+using UnityEditor.SceneManagement;
+using UnityEngine;
+using UnityEngine.TestTools;
+using UnityEngine.UIElements;
+
+/// <summary>Issue #245: the info panel lists a hex's 1948 localities, with today's name by the same rule as the map tooltip
+/// (Localities.TodayName: a living place carries on, owner ruling 2026-10-12).</summary>
+public class LocalityNameTests
+{
+ static readonly Content C = ContentLoader.Load(Paths.Content);
+ MapScene map = null!;
+ static UiText En => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings).text);
+ static UiText He => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings.Replace("strings.en.yaml", "strings.he.yaml")).text, "strings.he.yaml");
+
+ [SetUp]
+ public void Open() { EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single); map = Object.FindFirstObjectByType<MapScene>(); map.Build(); }
+
+ [TearDown]
+ public void Close() => EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
+
+ InfoPanelPresenter Panel(UiTestKit ui, UiText text)
+ {
+ var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
+ return new InfoPanelPresenter(ui.Root, new SimBridge(g, text), text, C.SettlementHexes.ToDictionary(x => x.Id, x => x.Id), localitiesAt: GameRoot.LocalitiesAt(map));
+ }
+
+ [Test]
+ public void TheRuleIsOneFunctionForTheTooltipAndThePanel()
+ {
+ var by = map.Localities.ToDictionary(p => p.Settlement.Id);
+ Assert.AreEqual("Beit She'an", Localities.TodayName(by["beit_shean"], false));
+ Assert.IsNull(Localities.TodayName(by["isdud"], false), "a place that did not carry on");
+ Assert.IsNull(Localities.TodayName(by["nablus"], false), "Nablus is Nablus");
+ foreach (var p in map.Localities)
+ {
+ var tip = MapLabelsPresenter.TipOf(p, n => "T:" + n, "M");
+ var today = Localities.TodayName(p, false);
+ Assert.AreEqual(today != null, tip != null && tip.Contains("T:" + today), p.Settlement.Id + ": tooltip and rule agree");
+ }
+ }
+
+ [Test]
+ public void TheInfoPanelListsTheHexsLocalitiesWithTodaysNameOnlyWhereTheRuleAllows()
+ {
+ var at = GameRoot.LocalitiesAt(map);
+ var withToday = map.Localities.Where(p => Localities.TodayName(p, false) != null).ToList();
+ var without = map.Localities.Where(p => Localities.TodayName(p, false) == null).ToList();
+ Assert.IsNotEmpty(withToday); Assert.IsNotEmpty(without);
+ using var ui = new UiTestKit();
+ var info = Panel(ui, En);
+ var label = ui.Q<Label>("info-localities");
+
+ var p1 = withToday[0];
+ var (q, r) = HexPicker.FromLonLat(p1.Settlement.Lon, p1.Settlement.Lat, map.Hexes.bounds, map.Hexes.hex_size_km);
+ info.Show(q, r);
+ Assert.AreEqual(DisplayStyle.Flex, label.style.display.value);
+ StringAssert.StartsWith("1948 localities: ", label.text);
+ StringAssert.Contains($"{p1.Settlement.Name} (today: {Localities.TodayName(p1, false)})", label.text);
+ foreach (var p in at(q, r))
+ {
+ StringAssert.Contains(p.Settlement.Name, label.text, "every locality of the hex is listed");
+ if (Localities.TodayName(p, false) == null) StringAssert.DoesNotContain(p.Settlement.Name + " (", label.text, p.Settlement.Id + " has no today name");
+ }
+
+ var p2 = without[0];
+ var (q2, r2) = HexPicker.FromLonLat(p2.Settlement.Lon, p2.Settlement.Lat, map.Hexes.bounds, map.Hexes.hex_size_km);
+ info.Show(q2, r2);
+ StringAssert.Contains(p2.Settlement.Name, label.text);
+ StringAssert.DoesNotContain(p2.Settlement.Name + " (", label.text, "a place that did not carry on shows no today name");
+ }
+
+ [Test]
+ public void AHexWithNoLocalitiesShowsNoSection()
+ {
+ var at = GameRoot.LocalitiesAt(map);
+ var hex = C.SettlementHexes.Select(h => (h.Q, h.R)).First(h => at(h.Q, h.R).Count == 0);
+ using var ui = new UiTestKit();
+ var info = Panel(ui, En);
+ var label = ui.Q<Label>("info-localities");
+ info.Show(hex.Q, hex.R);
+ Assert.AreEqual(DisplayStyle.None, label.style.display.value);
+ Assert.AreEqual("", label.text);
+ var p = map.Localities[0];
+ var (q, r) = HexPicker.FromLonLat(p.Settlement.Lon, p.Settlement.Lat, map.Hexes.bounds, map.Hexes.hex_size_km);
+ info.Show(q, r);
+ Assert.AreEqual(DisplayStyle.Flex, label.style.display.value);
+ info.Show(hex.Q, hex.R);
+ Assert.AreEqual(DisplayStyle.None, label.style.display.value, "the section goes when the next hex has none");
+ }
+
+ [Test]
+ public void TheHebrewPanelUsesHebrewTodayNames()
+ {
+ var p = map.Localities.First(x => Localities.TodayName(x, true) != null && !string.IsNullOrEmpty(x.TodayHe));
+ var text = InfoPanelPresenter.LocalitiesText(He, new[] { p });
+ StringAssert.Contains(p.TodayHe!, text);
+ Assert.AreEqual("", InfoPanelPresenter.LocalitiesText(He, new Localities.Place[0]));
+ }
+
+ /// <summary>The list wraps inside the info panel: the hex with the most localities (seven around Tel Aviv) at a desktop,
+ /// a laptop and a phone size, on the real Game.uxml and PanelSettings. Unwrapped, the line ran far past the panel.</summary>
+ [UnityTest]
+ public IEnumerator TheLongestListWrapsInsideThePanel()
+ {
+ var at = GameRoot.LocalitiesAt(map);
+ var hex = map.Localities.Select(p => HexPicker.FromLonLat(p.Settlement.Lon, p.Settlement.Lat, map.Hexes.bounds, map.Hexes.hex_size_km))
+ .OrderByDescending(h => at(h.q, h.r).Count).First();
+ Assert.GreaterOrEqual(at(hex.q, hex.r).Count, 5);
+ foreach (var (w, h) in new[] { (1920, 1080), (960, 600), (390, 844) })
+ {
+ var rt = new RenderTexture(w, h, 0);
+ var ps = Object.Instantiate(AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel));
+ ps.targetTexture = rt;
+ var go = new GameObject("LocalityLayoutTest");
+ 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 info = new InfoPanelPresenter(root, new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), En), En,
+ C.SettlementHexes.ToDictionary(x => x.Id, x => x.Id), localitiesAt: at);
+ try
+ {
+ info.Show(hex.q, hex.r);
+ var label = root.Q<Label>("info-localities");
+ for (int i = 0; i < 20 && !(label.contentRect.width > 0); i++) yield return null;
+ yield return null; // one more pass, so text measured after the first layout settles
+ var box = label.contentRect;
+ var natural = label.MeasureTextSize(label.text, 0, VisualElement.MeasureMode.Undefined, 0, VisualElement.MeasureMode.Undefined);
+ Assert.Greater(natural.x, box.width, $"{w}x{h}: the test needs a line longer than the panel");
+ Assert.AreEqual(WhiteSpace.Normal, label.resolvedStyle.whiteSpace, $"{w}x{h}: the list wraps");
+ var wrapped = label.MeasureTextSize(label.text, box.width, VisualElement.MeasureMode.Exactly, 0, VisualElement.MeasureMode.Undefined);
+ Assert.LessOrEqual(wrapped.y, box.height + 1f, $"{w}x{h}: the wrapped list fits its box {box}");
+ var panel = root.Q("info-panel").worldBound;
+ Assert.LessOrEqual(label.worldBound.xMax, panel.xMax + 0.5f, $"{w}x{h}: inside the panel {panel}");
+ }
+ finally
+ {
+ info.Dispose();
+ Object.DestroyImmediate(go); Object.DestroyImmediate(ps); rt.Release(); Object.DestroyImmediate(rt);
+ }
+ }
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/LocalityNameTests.cs.meta b/unity/Assets/Tests/EditMode/LocalityNameTests.cs.meta
new file mode 100644
index 000000000..c3c29b578
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/LocalityNameTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 655d1cfb7bdf04ec1947480f3411068f
\ No newline at end of file
diff --git a/unity/Assets/Tests/EditMode/MapLabelTests.cs b/unity/Assets/Tests/EditMode/MapLabelTests.cs
index 223682465..dcac8acf2 100644
--- a/unity/Assets/Tests/EditMode/MapLabelTests.cs
+++ b/unity/Assets/Tests/EditMode/MapLabelTests.cs
@@ -386,6 +386,75 @@ public class MapLabelTests
finally { labels.Dispose(); hd.Dispose(); }
}
+ /// <summary>Issue #245: on a touchscreen a tap on a locality pill toggles its tooltip (a second tap hides it), and a tap
+ /// elsewhere, or on a pill with nothing to say, hides it. The touch's own Hover(null) each frame leaves a tapped
+ /// tooltip up. A mouse hover still shows and hides it as before, and a mouse in use takes a tapped tooltip away.</summary>
+ [UnityTest]
+ public IEnumerator ATapTogglesTheTooltipAndATapElsewhereHidesIt()
+ {
+ var hd = new HdPanel(cam);
+ var labels = new MapLabelsPresenter(hd.Root, map, cam);
+ try
+ {
+ Pose(35.50, 32.49, 30000f);
+ yield return Settle(labels);
+ var container = hd.Root.Q<VisualElement>(MapLabelsPresenter.ContainerName).worldBound.position;
+ Vector2 Centre(string id) => labels.LocalitySlots.Single(x => x.name == "slot-" + id).Q<Label>().worldBound.center - container;
+ bool Up() => labels.Tooltip.style.visibility.value == Visibility.Visible;
+ Assert.IsTrue(Shown(labels.LocalitySlots.Single(x => x.name == "slot-beit_shean")));
+
+ labels.TapAt(Centre("beit_shean"));
+ Assert.IsTrue(Up(), "a tap on Beisan's pill shows its tooltip");
+ Assert.AreEqual("Today: Beit She'an", labels.Tooltip.text);
+ labels.Hover(null); // the frames after the tap: a touchscreen has no hover position
+ Assert.IsTrue(Up(), "and it stays up across frames");
+ labels.TapAt(Centre("beit_shean"));
+ Assert.IsFalse(Up(), "a second tap on the pill hides it");
+ labels.TapAt(Centre("beit_shean"));
+ labels.TapAt(new Vector2(-50f, -50f));
+ Assert.IsFalse(Up(), "a tap elsewhere hides it");
+
+ labels.HoverAt(Centre("beit_shean"));
+ Assert.IsTrue(Up(), "a mouse hover still shows it");
+ Assert.AreEqual("Today: Beit She'an", labels.Tooltip.text);
+ labels.HoverAt(new Vector2(-50f, -50f));
+ Assert.IsFalse(Up(), "and off the pill hides it");
+
+ labels.TapAt(Centre("beit_shean"));
+ Assert.IsTrue(Up());
+ labels.Hover(new Vector2(-500f, -500f)); // a mouse position well off every pill
+ Assert.IsFalse(Up(), "a mouse in use takes a tapped tooltip away");
+
+ labels.TapAt(Centre("beit_shean"));
+ Pose(PromoPose.Gameplay03.Lon, PromoPose.Gameplay03.Lat, PromoPose.Gameplay03.Distance);
+ yield return Settle(labels);
+ labels.Hover(null);
+ Assert.IsFalse(Up(), "zooming out hides the pill and the tooltip with it");
+ }
+ finally { labels.Dispose(); hd.Dispose(); }
+ }
+
+ /// <summary>Issue #245: the device type decides. A touchscreen has no hover position (the Input System keeps its last
+ /// touch after the finger lifts); a mouse and a pen do.</summary>
+ [Test]
+ public void OnlyANonTouchPointerHovers()
+ {
+ Assert.IsNull(MapLabelsPresenter.HoverPosition(null));
+ var touch = UnityEngine.InputSystem.InputSystem.AddDevice<UnityEngine.InputSystem.Touchscreen>();
+ var mouse = UnityEngine.InputSystem.InputSystem.AddDevice<UnityEngine.InputSystem.Mouse>();
+ var pen = UnityEngine.InputSystem.InputSystem.AddDevice<UnityEngine.InputSystem.Pen>();
+ try
+ {
+ Assert.IsNull(MapLabelsPresenter.HoverPosition(touch), "a touchscreen does not hover");
+ Assert.IsNotNull(MapLabelsPresenter.HoverPosition(mouse), "a mouse hovers");
+ Assert.IsNotNull(MapLabelsPresenter.HoverPosition(pen), "a pen hovers");
+ }
+ finally
+ {
+ UnityEngine.InputSystem.InputSystem.RemoveDevice(touch); UnityEngine.InputSystem.InputSystem.RemoveDevice(mouse); UnityEngine.InputSystem.InputSystem.RemoveDevice(pen);
+ }
+ }
+
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;
static float RectGap(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;
diff --git a/unity/Assets/UI/Game.uxml b/unity/Assets/UI/Game.uxml
index 4f6875fe1..89b8c2dd8 100644
--- a/unity/Assets/UI/Game.uxml
+++ b/unity/Assets/UI/Game.uxml
@@ -117,6 +117,7 @@
<ui:Label name="info-region" class="muted" />
<ui:VisualElement class="gold-rule" />
<ui:Label name="info-settlements" />
+ <ui:Label name="info-localities" class="muted wrap" />
<ui:Label name="info-placement" class="muted" />
<ui:VisualElement class="row">
<ui:Button name="build-camp" />
diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yaml
index 631e54131..faab9fef6 100644
--- a/unity/Assets/UI/strings.en.yaml
+++ b/unity/Assets/UI/strings.en.yaml
@@ -101,6 +101,8 @@ map.layer_front_no_data: " · {0}: Mandate sub-districts, no armistice line data
map.layer_front_low: "{0} (low accuracy)"
map.layer_front_note: "{0} (and the {1})"
info.owned: "Settlements: {0}"
+info.localities: "1948 localities: {0}"
+info.locality_today: "{0} (today: {1})"
map.today: "Today: {0}"
map.mixed: "Mixed locality"
ui.lang: "en"
diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yaml
index 9a603ddf6..5d5573295 100644
--- a/unity/Assets/UI/strings.he.yaml
+++ b/unity/Assets/UI/strings.he.yaml
@@ -96,6 +96,8 @@ map.layer_front_no_data: " · {0}: נפות המנדט, אין נתוני קו
map.layer_front_low: "{0} (דיוק נמוך)"
map.layer_front_note: "{0} (וגם {1})"
info.owned: "יישובים: {0}"
+info.localities: "יישובים ב-1948: {0}"
+info.locality_today: "{0} (היום: {1})"
map.today: "היום: {0}"
map.mixed: "יישוב מעורב"
ui.lang: "he"