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: unit lines name a place, not hex coordinates; one movement point; larger route turn numbers (Refs #1527) (#1633)

Eyal Golan1f0e03d77417
diff --git a/changelog.d/1527-toast-polish.md b/changelog.d/1527-toast-polish.md
new file mode 100644
index 000000000..9962a561d
--- /dev/null
+++ b/changelog.d/1527-toast-polish.md
@@ -0,0 +1,4 @@
+### Fixed
+- A unit's lines in the toast and on the Why screen name a place, never a hex's coordinates: a town's hex by the
+ town's name, any other hex from the nearest town ("a hex 10 km east of Haifa"). A one-point move says
+ "1 movement point". A go-to route's turn numbers are drawn at a city name's size.
diff --git a/unity/Assets/Scripts/UI/HexPlaces.cs b/unity/Assets/Scripts/UI/HexPlaces.cs
new file mode 100644
index 000000000..e7b3e1a18
--- /dev/null
+++ b/unity/Assets/Scripts/UI/HexPlaces.cs
@@ -0,0 +1,41 @@
+#nullable enable
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using Statecraft.Sim;
+
+namespace Statecraft.Game.UI
+{
+ /// <summary>A hex as the unit lines name it (#1527's follow-up): never its coordinates (no debug coordinates in player
+ /// text, playtest 2, P2-6). A settlement's hex is the settlement's name; any other hex is said from the nearest
+ /// settlement (map/settlement_hexes.yaml, the first in file order on a tie), how far and which way, so a hex far out in
+ /// the Negev is not "near" anything.</summary>
+ public static class HexPlaces
+ {
+ /// <summary>The sim's "q,r" (Movement.HexText and the like) as a place; any other value unchanged.</summary>
+ public static string Of(string value, Content c, UiText text, IReadOnlyDictionary<string, string>? namesHe)
+ {
+ var parts = value.Split(',');
+ if (parts.Length != 2 || !int.TryParse(parts[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out var q)
+ || !int.TryParse(parts[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out var r)) return value;
+ SettlementHex? nearest = null; var best = int.MaxValue;
+ foreach (var s in c.SettlementHexes)
+ {
+ var d = MapActions.Distance(q, r, s.Q, s.R);
+ if (d < best) { best = d; nearest = s; }
+ }
+ if (nearest == null || !(c.HexAt(q, r) is MapHex to) || !(c.HexAt(nearest.Q, nearest.R) is MapHex from)) return value;
+ var name = ContentNames.Settlement(text, c, nearest.Id, namesHe);
+ if (best == 0) return name;
+ // Between the two hexes' centres, on a local flat projection (a few dozen km at most), to the nearest 5 km.
+ var east = (to.Lon - from.Lon) * Math.Cos((to.Lat + from.Lat) / 2 * Math.PI / 180) * 111.32;
+ var north = (to.Lat - from.Lat) * 110.57;
+ var km = Math.Max(5, (int)Math.Round(Math.Sqrt(east * east + north * north) / 5, MidpointRounding.AwayFromZero) * 5);
+ var way = Directions[(int)Math.Round((Math.Atan2(east, north) * 180 / Math.PI + 360) % 360 / 45) % 8];
+ return text.Format("why.hex.away", km, text["why.hex." + way], name);
+ }
+
+ /// <summary>The eight compass points, clockwise from north (why.hex.&lt;point&gt;).</summary>
+ static readonly string[] Directions = { "north", "north_east", "east", "south_east", "south", "south_west", "west", "north_west" };
+ }
+}
diff --git a/unity/Assets/Scripts/UI/HexPlaces.cs.meta b/unity/Assets/Scripts/UI/HexPlaces.cs.meta
new file mode 100644
index 000000000..2daeade35
--- /dev/null
+++ b/unity/Assets/Scripts/UI/HexPlaces.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: f165c1397641d418081c152736b17256
\ No newline at end of file
diff --git a/unity/Assets/Scripts/UI/UnitNames.cs b/unity/Assets/Scripts/UI/UnitNames.cs
index a25047337..bd079e94c 100644
--- a/unity/Assets/Scripts/UI/UnitNames.cs
+++ b/unity/Assets/Scripts/UI/UnitNames.cs
@@ -43,7 +43,7 @@ namespace Statecraft.Game.UI
return text.Format("why.line." + cause.Key,
string.Join(", ", cause.Units.Take(attackers).Select(u => Of(u, c, rows, text, namesHe))),
string.Join(", ", cause.Units.Skip(attackers).Select(u => Of(u, c, rows, text, namesHe))),
- cause.Args[0], Number(cause.Args[1]), Number(cause.Args[2]), Number(cause.Args[3]));
+ HexPlaces.Of(cause.Args[0], c, text, namesHe), Number(cause.Args[1]), Number(cause.Args[2]), Number(cause.Args[3]));
}
var args = cause.Args.ToArray();
@@ -52,8 +52,10 @@ namespace Statecraft.Game.UI
else if (cause.Key == WhyKeys.Withdrew && args.Length > 0)
args[0] = ContentNames.Settlement(text, c, args[0], namesHe);
var values = cause.Units.Select(u => (object)Of(u, c, rows, text, namesHe))
- .Concat(args.Select(Number)).ToArray();
- return text.Format("why.line." + cause.Key, values);
+ .Concat(args.Select(a => Number(HexPlaces.Of(a, c, text, namesHe)))).ToArray();
+ // A one-point move says "point" (why.line.unit_moved_one).
+ var one = cause.Key == WhyKeys.UnitMoved && args.Length > 1 && args[1] == "1" ? "_one" : "";
+ return text.Format("why.line." + cause.Key + one, values);
}
static object Number(string value) => int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var n) ? n : value;
diff --git a/unity/Assets/Tests/EditMode/MapLabelTests.cs b/unity/Assets/Tests/EditMode/MapLabelTests.cs
index 274572d5a..0cf153b15 100644
--- a/unity/Assets/Tests/EditMode/MapLabelTests.cs
+++ b/unity/Assets/Tests/EditMode/MapLabelTests.cs
@@ -425,6 +425,29 @@ public class MapLabelTests
finally { labels.Dispose(); hd.Dispose(); }
}
+ /// <summary>#1527's follow-up: a go-to route's turn numbers are drawn at a city name's size (they were smaller than a
+ /// town's), and the disc holds a two-digit turn.</summary>
+ [UnityTest]
+ public IEnumerator RouteTurnNumbersReadAtACitysNameSize()
+ {
+ var hd = new HdPanel(cam);
+ var labels = new MapLabelsPresenter(hd.Root, map, cam);
+ try
+ {
+ var hexes = map.Hexes.hexes.Where(h => h.land).Take(12).ToList();
+ map.ShowRoute(hexes.Select((h, i) => (h.q, h.r, i + 1)).ToList());
+ labels.Refresh(force: true);
+ yield return Settle(labels);
+ var city = labels.Labels.Single(l => l.name == "label-tel_aviv");
+ var turn = hd.Root.Query<Label>(className: MapLabelsPresenter.RouteTurnClass).ToList().Single(l => l.text == "12");
+ Assert.GreaterOrEqual(turn.resolvedStyle.fontSize, city.resolvedStyle.fontSize, "a turn number reads like a city's name");
+ var two = turn.MeasureTextSize("12", 0, VisualElement.MeasureMode.Undefined, 0, VisualElement.MeasureMode.Undefined);
+ Assert.GreaterOrEqual(turn.resolvedStyle.width - turn.resolvedStyle.borderLeftWidth - turn.resolvedStyle.borderRightWidth, two.x,
+ "two digits fit the disc");
+ }
+ finally { map.ShowRoute(System.Array.Empty<(int, int, int)>()); labels.Dispose(); hd.Dispose(); }
+ }
+
static IEnumerator Settle(MapLabelsPresenter labels)
{
for (int i = 0; i < 20 && labels.Labels.Concat(labels.LocalityLabels).Any(l => float.IsNaN(l.resolvedStyle.width) || l.resolvedStyle.width <= 0); i++) yield return null;
diff --git a/unity/Assets/Tests/EditMode/UnitOrdersTests.cs b/unity/Assets/Tests/EditMode/UnitOrdersTests.cs
index e3e683a66..1bacc46d6 100644
--- a/unity/Assets/Tests/EditMode/UnitOrdersTests.cs
+++ b/unity/Assets/Tests/EditMode/UnitOrdersTests.cs
@@ -531,7 +531,7 @@ public class UnitOrdersTests
Assert.IsNull(bridge.Queue(new UnitOrder(0, Combat.Attack, syrian.Q, syrian.R)));
Assert.AreEqual(arms - 1, bridge.State.Arms, "paid at once (arms_per_attack 1)");
var line = ui.Q<Label>("toast").text;
- StringAssert.StartsWith("The attack on hex", line);
+ StringAssert.StartsWith("The attack on Degania Alef (", line); // the place, not the hex's coordinates
StringAssert.DoesNotContain("unit 0", line);
StringAssert.Contains(golani.Unit.Name, line);
info.ShowUnit();
diff --git a/unity/Assets/Tests/EditMode/WhyHexPlacesTests.cs b/unity/Assets/Tests/EditMode/WhyHexPlacesTests.cs
new file mode 100644
index 000000000..111eff935
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/WhyHexPlacesTests.cs
@@ -0,0 +1,80 @@
+#nullable enable
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text.RegularExpressions;
+using NUnit.Framework;
+using Statecraft.Game;
+using Statecraft.Game.Map.Units;
+using Statecraft.Game.UI;
+using Statecraft.Sim;
+using UnityEditor;
+using UnityEngine;
+
+/// <summary>#1527's follow-up: the unit lines (toast and Why) name a place, never a hex's coordinates; a one-point move
+/// says "point".</summary>
+public class WhyHexPlacesTests
+{
+ static readonly Content C = ContentLoader.Load(Paths.Content);
+ static List<UnitEntry> Rows => UnitData.Parse(File.ReadAllText(Path.Combine(Paths.Content, "map", UnitData.DefaultFileName)));
+ static UiText En => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings).text);
+ static UiText He => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.StringsHebrew).text, "strings.he.yaml");
+ static readonly Dictionary<string, string> NamesHe = new Dictionary<string, string> { ["haifa"] = "חיפה", ["tel_aviv"] = "תל אביב" };
+ static readonly Regex Coordinates = new Regex(@"\d+\s*,\s*-?\d+");
+
+ static UnitRef Golani => new UnitRef(Simulation.NewGame(C, GoldenRun.Seed, Mode.Historical).Units[0]);
+ static string GolaniName(UiText text) => UnitNames.Of(Golani, C, Rows, text);
+
+ static Cause Moved(string hex, int cost) => new Cause("map", "0", cost, "", key: WhyKeys.UnitMoved, units: new[] { Golani },
+ args: new[] { hex, cost.ToString(System.Globalization.CultureInfo.InvariantCulture) });
+
+ [Test]
+ public void AMoveOntoATownsHexNamesTheTownAndOnePointIsSingular()
+ {
+ Assert.AreEqual(GolaniName(En) + " moved to Haifa for 1 movement point", UnitNames.Line(Moved("5,8", 1), C, Rows, En));
+ var he = UnitNames.Line(Moved("5,8", 1), C, Rows, He, NamesHe);
+ StringAssert.Contains("משושה חיפה", he);
+ StringAssert.Contains("נקודת תנועה אחת", he);
+ StringAssert.DoesNotContain("1 נקודות", he);
+ }
+
+ [Test]
+ public void AMoveElsewhereSaysHowFarAndWhichWayFromTheNearestTown()
+ {
+ // (6,8) is the hex east of Haifa's (5,8): 8.5 km between the centres, said to the nearest 5 km.
+ Assert.AreEqual(GolaniName(En) + " moved to a hex 10 km east of Haifa for 2 movement points", UnitNames.Line(Moved("6,8", 2), C, Rows, En));
+ StringAssert.Contains("משושה 10 ק״מ מזרחית ל־חיפה", UnitNames.Line(Moved("6,8", 2), C, Rows, He, NamesHe));
+ // (-3,20) is one hex from Tel Aviv, Lod and Rishon LeZion alike: the first in settlement_hexes.yaml's order wins.
+ StringAssert.Contains("a hex 10 km south-east of Tel Aviv", UnitNames.Line(Moved("-3,20", 2), C, Rows, En));
+ }
+
+ /// <summary>Every unit line, in both languages, with a hex of negative q (the Hebrew bidi case: "-3,20" showed as
+ /// "3,20-"): no coordinates remain.</summary>
+ [Test]
+ public void NoUnitLineShowsCoordinatesInEitherLanguage()
+ {
+ const string hex = "-3,20";
+ var args = new Dictionary<string, string[]>
+ {
+ [WhyKeys.UnitMoved] = new[] { hex, "2" },
+ [WhyKeys.AttackCalledOff] = new[] { hex, "3", "1" },
+ [WhyKeys.Engagement] = new[] { hex, "120", "10", "20", "1" },
+ [WhyKeys.Destroyed] = new string[0],
+ [WhyKeys.SurrenderedPrisoners] = new[] { "500" },
+ [WhyKeys.SurrenderedHeld] = new[] { "500" },
+ [WhyKeys.SentHome] = new[] { "500", "tel_aviv" },
+ [WhyKeys.Withdrew] = new[] { "jaffa", hex },
+ };
+ foreach (var key in WhyKeys.All)
+ {
+ var units = key == WhyKeys.Engagement ? new[] { Golani, Golani } : new[] { Golani };
+ var cause = new Cause("map", "0", 0, "", key: key, units: units, args: args.TryGetValue(key, out var a) ? a : new[] { hex });
+ foreach (var (text, names) in new[] { (En, (Dictionary<string, string>?)null), (He, NamesHe) })
+ {
+ var line = UnitNames.Line(cause, C, Rows, text, names);
+ Assert.IsFalse(Coordinates.IsMatch(line), $"{key}: {line}");
+ StringAssert.DoesNotContain("hex -", line, key);
+ }
+ }
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/WhyHexPlacesTests.cs.meta b/unity/Assets/Tests/EditMode/WhyHexPlacesTests.cs.meta
new file mode 100644
index 000000000..38970a125
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/WhyHexPlacesTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 5af9c13d1a23049c1906f966a06e5131
\ No newline at end of file
diff --git a/unity/Assets/UI/Statecraft.uss b/unity/Assets/UI/Statecraft.uss
index 19f133ca2..19b6d8c6e 100644
--- a/unity/Assets/UI/Statecraft.uss
+++ b/unity/Assets/UI/Statecraft.uss
@@ -819,14 +819,15 @@ Button.settings-choice-selected { -unity-font-definition: url("project://databas
-unity-text-align: middle-center;
white-space: nowrap;
}
-/* The last hex of each turn in a multi-turn go-to: a compact number centred on the route, not a settlement name. */
+/* The last hex of each turn in a multi-turn go-to: a number centred on the route, not a settlement name, at a city name's
+ size (.map-label-city) so it reads at the default zoom; the disc holds two digits. */
.map-route-turn {
- width: 26px;
- height: 26px;
+ width: 36px;
+ height: 36px;
translate: -50% -50%;
padding: 0;
- border-radius: 13px;
- font-size: 17px;
+ border-radius: 18px;
+ font-size: 23px;
background-color: rgba(14, 22, 38, 0.92);
}
.map-label-city { font-size: 23px; color: rgb(250, 242, 224); }
diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yaml
index 015fd43b4..70b85b39e 100644
--- a/unity/Assets/UI/strings.en.yaml
+++ b/unity/Assets/UI/strings.en.yaml
@@ -293,26 +293,38 @@ why.situations: "Situations"
why.other: "Other"
why.nothing: "Nothing notable happened this turn."
# Structured Why lines that name units (#1399).
-why.line.unit_moved: "{0} moved to hex {1} for {2} movement points"
-why.line.fortify_lost: "{0} left hex {1} and is no longer fortified"
-why.line.fortifying: "{0} is fortifying hex {1}; it is fortified from the end of the turn"
-why.line.holds: "{0} holds hex {1}"
-why.line.attack_ended_truce: "{0}'s attack on hex {1} ends: a truce is on"
-why.line.attack_ordered: "{0} will attack hex {1}"
-why.line.attack_ended: "{0}'s attack on hex {1} ends: no enemy unit is there"
-why.line.holds_fire: "{0} holds its fire: no attack on hex {1} to support"
-why.line.attack_called_off: "{0}'s attack on hex {1} is called off: it needs {2} Arms and the stock has {3}"
-why.line.engagement: "The attack on hex {2} ({0} against {1}, strength ratio {3}%): the attackers lost {4:N0} people and the defenders lost {5:N0} people"
+why.line.unit_moved: "{0} moved to {1} for {2} movement points"
+why.line.unit_moved_one: "{0} moved to {1} for 1 movement point"
+why.line.fortify_lost: "{0} left {1} and is no longer fortified"
+why.line.fortifying: "{0} is fortifying {1}; it is fortified from the end of the turn"
+why.line.holds: "{0} holds {1}"
+why.line.attack_ended_truce: "{0}'s attack on {1} ends: a truce is on"
+why.line.attack_ordered: "{0} will attack {1}"
+why.line.attack_ended: "{0}'s attack on {1} ends: no enemy unit is there"
+why.line.holds_fire: "{0} holds its fire: no attack on {1} to support"
+why.line.attack_called_off: "{0}'s attack on {1} is called off: it needs {2} Arms and the stock has {3}"
+why.line.engagement: "The attack on {2} ({0} against {1}, strength ratio {3}%): the attackers lost {4:N0} people and the defenders lost {5:N0} people"
why.line.destroyed: "{0} was destroyed"
-why.line.retreated: "{0} retreated to hex {1}"
+why.line.retreated: "{0} retreated to {1}"
why.line.surrendered_prisoners: "{0} surrendered with {1:N0} people: it had no hex to retreat to. They are held as prisoners"
why.line.surrendered_held: "{0} surrendered with {1:N0} people: it had no hex to retreat to. They are held by the enemy"
why.line.sent_home: "{0} is sent home: its {1:N0} people are civilians in {2} now"
-why.line.withdrew: "{0} withdrew from {1} to hex {2}"
-why.line.on_its_way: "{0} is on its way to hex {1}"
-why.line.stopped_no_route: "{0} stopped: no route reaches hex {1}"
-why.line.stopped_full: "{0} stopped: hex {1} is full"
-why.line.arrived: "{0} arrived at hex {1}"
+why.line.withdrew: "{0} withdrew from {1} to {2}"
+why.line.on_its_way: "{0} is on its way to {1}"
+why.line.stopped_no_route: "{0} stopped: no route reaches {1}"
+why.line.stopped_full: "{0} stopped: {1} is full"
+why.line.arrived: "{0} arrived at {1}"
+# A hex in the unit lines (HexPlaces): a settlement's hex is its name alone; any other hex is said from the nearest
+# settlement, {0} the km between the centres (to the nearest 5), {1} the compass point (why.hex.<point>), {2} the settlement.
+why.hex.away: "a hex {0} km {1} of {2}"
+why.hex.north: "north"
+why.hex.north_east: "north-east"
+why.hex.east: "east"
+why.hex.south_east: "south-east"
+why.hex.south: "south"
+why.hex.south_west: "south-west"
+why.hex.west: "west"
+why.hex.north_west: "north-west"
# The turn report (#1037, TurnReportPresenter): a line is a top-bar caption and the change the bar shows.
report.title: "What happened this turn"
report.intro: "What changed in the top bar, and the main causes:"
diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yaml
index 02ccdeff5..f120af9f6 100644
--- a/unity/Assets/UI/strings.he.yaml
+++ b/unity/Assets/UI/strings.he.yaml
@@ -310,6 +310,7 @@ why.other: "אחר"
why.nothing: "לא קרה דבר ראוי לציון בתור הזה."
# Hebrew drafts for the structured unit Why lines (#1399); native review pending (#564).
why.line.unit_moved: "{0} נעה למשושה {1} תמורת {2} נקודות תנועה"
+why.line.unit_moved_one: "{0} נעה למשושה {1} תמורת נקודת תנועה אחת"
why.line.fortify_lost: "{0} עזבה את משושה {1} ואינה מבוצרת עוד"
why.line.fortifying: "{0} מתבצרת במשושה {1}; היא תהיה מבוצרת מסוף התור"
why.line.holds: "{0} מחזיקה במשושה {1}"
@@ -329,6 +330,18 @@ why.line.on_its_way: "{0} בדרך למשושה {1}"
why.line.stopped_no_route: "{0} נעצרה: אין מסלול שמגיע למשושה {1}"
why.line.stopped_full: "{0} נעצרה: משושה {1} מלא"
why.line.arrived: "{0} הגיעה למשושה {1}"
+# A hex in the unit lines (HexPlaces), after the lines' "משושה": a settlement's hex is its name alone ("משושה חיפה"); any
+# other hex is said from the nearest settlement, {0} the km (to the nearest 5), {1} the compass point, {2} the settlement,
+# with a maqaf after the prefix as in why.line.sent_home. Agent-drafted Hebrew; native review pending (#564).
+why.hex.away: "{0} ק״מ {1} ל־{2}"
+why.hex.north: "צפונית"
+why.hex.north_east: "צפון־מזרחית"
+why.hex.east: "מזרחית"
+why.hex.south_east: "דרום־מזרחית"
+why.hex.south: "דרומית"
+why.hex.south_west: "דרום־מערבית"
+why.hex.west: "מערבית"
+why.hex.north_west: "צפון־מערבית"
# The turn report (#1037, TurnReportPresenter): a line is a top-bar caption and the change the bar shows.
report.title: "מה קרה בתור הזה"
report.intro: "מה השתנה בסרגל העליון, ומה הסיבות העיקריות:"