A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Unity: a pioneer card for halutz and veteran groups, with Return (Refs #1549) (#1788)
Eyal Golan3824eb6f5125
diff --git a/changelog.d/1549.md b/changelog.d/1549.mdnew file mode 100644index 000000000..4d2e3fcda--- /dev/null+++ b/changelog.d/1549.md@@ -0,0 +1 @@+- Select pioneer groups from a hex list or project link to see their track, location and work, and return idle groups to civilian life. Existing project and city row actions remain available.diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex d2857f67e..42ba27301 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -381,7 +381,7 @@ namespace Statecraft.Game.UIshowReachable: map.ShowReachable,unitName: id => unitLayer.Tokens.Where(p => UnitCard.SimUnit(bridge.Content, bridge.State, p.Token) == id).Select(p => UnitCard.For(p, bridge.State, text, bridge.Content.IsGdd, bridge.Content, townNamesHe).Title).FirstOrDefault(),- unitDone: FocusNextUnit, showRoute: map.ShowRoute, clearSelection: () => { unitLayer.Select(null); map.ClearSelection(); }));+ unitDone: FocusNextUnit, showRoute: map.ShowRoute, selectPioneer: FocusPioneer, clearSelection: () => { unitLayer.Select(null); map.ClearSelection(); }));toast.Units = unitData; toast.TownNamesHe = townNamesHe; why.TownNamesHe = townNamesHe;report.TownNamesHe = townNamesHe; hudPresenter.TownNamesHe = townNamesHe;// A smoke session never touches the player's save: no autosave, and no New Game (which deletes the autosave).@@ -533,10 +533,13 @@ namespace Statecraft.Game.UIcamRig.Distance = Mathf.Min(camRig.Distance, AdvisorTargets.MoveStepDistanceM);FocusUnit(id);};- // When it closes, the advisor puts back the selection it found (a hex, a unit, or none), unless the player has- // picked something else meanwhile (the HUD stays usable under it).+ // When it closes, the advisor puts back the selection it found (a hex, a unit, a pioneer group's card, or none),+ // unless the player has picked something else meanwhile (the HUD stays usable under it).Func<Action> keepSelection = () =>{+ // A pioneer card has no token (ShowPioneer clears it), so it is a selection of its own, kept with its game+ // (review C288 S1 of #1788): a language switch keeps the session, a load or new game does not.+ var pioneer = info.Pioneer; var pioneerSession = bridge.Session;var hex = info.ShowsUnit ? null : info.Selected;var unit = info.ShowsUnit ? unitLayer.Selected : null;var city = AdvisorTargets.CityHex(bridge.Content, bridge.State);@@ -548,6 +551,11 @@ namespace Statecraft.Game.UIif (this.info is not { } nowInfo || this.units is not { } nowUnits) return;// Under a screen, or the player picked another than the advisor's city or unit: kept.if (nowInfo.Covered || (nowInfo.ShowsUnit ? nowUnits.Selected != shownUnit : nowInfo.Selected != city)) return;+ if (pioneer is int pioneerId && Bridge?.Session == pioneerSession)+ {+ nowInfo.ShowPioneer(pioneerId); // clears the token and the hex outline, as a click on its link does+ if (nowInfo.Pioneer == pioneerId) return;+ }nowUnits.Select(unit);if (nowUnits.Selected != null) { map.ClearSelection(); nowInfo.ShowUnit(); }else if (hex is (int q, int r)) { map.Select(q, r); nowInfo.Show(q, r); }@@ -676,6 +684,12 @@ namespace Statecraft.Game.UIif (info.PickTarget(q, r)) map.ClearSelection();}+ void FocusPioneer(int id)+ {+ // ShowPioneer ends military picks/routes and invokes the same map/token cleanup as Escape.+ info?.ShowPioneer(id);+ }+/// <summary>Selects a drawn unit row, opens its card and centres the camera on its current hex.</summary>internal void FocusUnit(string rowId){diff --git a/unity/Assets/Scripts/UI/GddHexPanel.cs b/unity/Assets/Scripts/UI/GddHexPanel.csindex 6b71be80e..0a3c2a9e2 100644--- a/unity/Assets/Scripts/UI/GddHexPanel.cs+++ b/unity/Assets/Scripts/UI/GddHexPanel.cs@@ -40,7 +40,7 @@ namespace Statecraft.Game.UI/// <summary>Builds the hex's GDD part into <paramref name="host"/> and its city projects into <paramref name="projects"/>/// (each hidden when there is none) and returns the designated site's name in the UI's language when the hex holds one,/// else null. <paramref name="townName"/> names a city in the UI's language (InfoPanelPresenter's town names).</summary>- public static string? Render(VisualElement host, VisualElement projects, SimBridge bridge, UiText text, int q, int r, Func<string, string> townName)+ public static string? Render(VisualElement host, VisualElement projects, SimBridge bridge, UiText text, int q, int r, Func<string, string> townName, Action<int>? selectPioneer = null){host.Clear(); projects.Clear();var c = bridge.Content; var s = bridge.State;@@ -65,7 +65,7 @@ namespace Statecraft.Game.UItitle ??= Name(text, site);var part = new VisualElement { name = "site-part-" + site.Id };host.Add(part);- Site(part, bridge, text, site, Work(site)!.Value);+ Site(part, bridge, text, site, Work(site)!.Value, selectPioneer);}// #792: each corridor segment through the hex (corridors.yaml; a hex where two segments meet is in both). Not on a// city's own hex, whose column is full (InfoPanelLayoutTests): every segment has another hex.@@ -76,7 +76,7 @@ namespace Statecraft.Game.UI{var part = new VisualElement { name = $"corridor-part-{d.Id}-{i + 1}" };host.Add(part);- Segment(part, bridge, text, d, i);+ Segment(part, bridge, text, d, i, selectPioneer);}CityProjects(projects, bridge, text, q, r, townName, cityHere);}@@ -182,16 +182,27 @@ namespace Statecraft.Game.UI}/// <summary>A pioneer group's Return (R-QUAL-003; #1511): the sim's unit order return_civilian, offered where- /// Qualification.CheckReturn takes the group (not one at work). Pioneer groups have no map token and so no unit card:- /// this sits beside the places that list them. A unit order, it takes effect at once (R-TURN-004): the group leaves- /// the lists, and its Build buttons with it.</summary>+ /// Qualification.CheckReturn takes the group (not one at work). It sits beside the places that list the group; the+ /// pioneer card (#1549) offers the same order through <see cref="PioneerReturnOrder"/>. A unit order, it takes+ /// effect at once (R-TURN-004): the group leaves the lists, and its Build buttons with it.</summary>static void PioneerReturn(VisualElement host, SimBridge bridge, UiText text, int unit){- if (Qualification.CheckReturn(bridge.State, unit) != null) return;- // A Build or Stop queued for the group waits for End turn, which the group would no longer be there for.- var working = bridge.Queued.Any(x => (x is PioneerWork w && w.Unit == unit) || (x is StopWork sw && sw.Unit == unit));+ var offer = PioneerReturnOrder(bridge, unit);+ if (!offer.Eligible) return;Button(host, $"pioneer-return-{unit}", text.Format("pioneer.return", Group(text, bridge.State, unit)),- () => bridge.Queue(new UnitOrder(unit, Qualification.ReturnOrder))).SetEnabled(!working);+ () => PioneerReturnOrder(bridge, unit, submit: true)).SetEnabled(!offer.WorkOrdered);+ }++ /// <summary>The one guarded Return for both the rows and the pioneer card (#1549): Eligible when+ /// Qualification.CheckReturn takes the group, WorkOrdered while a Build or Stop is queued for it (that waits for End+ /// turn, which the group would no longer be there for). With <paramref name="submit"/> it queues the order only when+ /// both allow it, so a stale button cannot strand a queued Build or Stop.</summary>+ public static (bool Eligible, bool WorkOrdered) PioneerReturnOrder(SimBridge bridge, int unit, bool submit = false)+ {+ var eligible = Qualification.CheckReturn(bridge.State, unit) == null;+ var working = bridge.Queued.Any(x => (x is PioneerWork w && w.Unit == unit) || (x is StopWork sw && sw.Unit == unit));+ if (submit && eligible && !working) bridge.Queue(new UnitOrder(unit, Qualification.ReturnOrder));+ return (eligible, working);}static void Workers(SimBridge bridge, string city, int current, int count)@@ -213,7 +224,7 @@ namespace Statecraft.Game.UIstatic string Name(UiText text, Statecraft.Sim.Site site) =>text["ui.lang"] == UiLanguage.Hebrew && !string.IsNullOrWhiteSpace(site.NameHe) ? site.NameHe : site.Name;- static void Site(VisualElement host, SimBridge bridge, UiText text, Statecraft.Sim.Site site, (string Action, string Key) kind)+ static void Site(VisualElement host, SimBridge bridge, UiText text, Statecraft.Sim.Site site, (string Action, string Key) kind, Action<int>? selectPioneer){var c = bridge.Content; var s = bridge.State;var (action, key) = kind;@@ -247,6 +258,7 @@ namespace Statecraft.Game.UIelse if (work.BuiltOn == null){var unit = work.Unit!.Value; // a site being built names its unit (SiteWork)+ GroupLink(host, bridge, text, unit, selectPioneer);Line(host, "site-state", text.Format("site.building" + key, Group(text, s, unit), Turns(text, Projects.TurnsToBuild(c, s, unit, site, work.TurnsLeft, work.Progress))));var stopping = bridge.QueuedLike(new StopWork(unit)) is StopWork;Button(host, "site-stop", text[stopping ? "site.ordered" : "site.stop" + key], () => bridge.Queue(new StopWork(unit))).SetEnabled(!stopping);@@ -258,7 +270,7 @@ namespace Statecraft.Game.UI/// kind) with each idle pioneer group, with the kind's cost and the unit's own turns (Projects.Terms,/// Corridors.TurnsToBuild); or its turns left and Stop while it is built; or the day it was built. The order is/// PioneerWork(unit, action, "corridor:N"), SimBridge's corridor key.</summary>- static void Segment(VisualElement host, SimBridge bridge, UiText text, CorridorDef d, int index)+ static void Segment(VisualElement host, SimBridge bridge, UiText text, CorridorDef d, int index, Action<int>? selectPioneer){var c = bridge.Content; var s = bridge.State;var action = d.Kind == Corridors.Rail ? Corridors.BuildRail : Corridors.BuildRoad;@@ -287,6 +299,7 @@ namespace Statecraft.Game.UIelse if (work.BuiltOn == null){var unit = work.Unit!.Value; // a segment being built names its unit (SegmentWork)+ GroupLink(host, bridge, text, unit, selectPioneer);Line(host, "corridor-state", text.Format("site.building", Group(text, s, unit), Turns(text, Corridors.TurnsToBuild(c, s, unit, terms.Turns - work.Progress, work.Carry))));var stopping = bridge.QueuedLike(new StopWork(unit)) is StopWork;Button(host, "corridor-stop", text[stopping ? "site.ordered" : "site.stop"], () => bridge.Queue(new StopWork(unit))).SetEnabled(!stopping);@@ -400,6 +413,17 @@ namespace Statecraft.Game.UI/// <summary>A date in the UI's language, as the event card writes it (EventCardPresenter.ObjectiveLine).</summary>static string Date(UiText t, DateTime d) => t.Format("date.day_month_year", d.Day, t["date.month_" + d.Month], d.Year);+ /// <summary>The worker's link to its pioneer card (#1549) on a site or segment under way; none without a callback, so+ /// existing callers render as before. Idle candidates get none: they open from their own hex's list, and a link per+ /// candidate per segment ran a three-segment hex off a 1024x768 window (InfoPanelLayoutTests).</summary>+ static void GroupLink(VisualElement host, SimBridge bridge, UiText text, int id, Action<int>? select)+ {+ if (select == null) return;+ var b = Button(host, "pioneer-project-" + id.ToString(CultureInfo.InvariantCulture),+ text.Format("pioneer.card.open", Group(text, bridge.State, id)), () => select(id));+ b.AddToClassList("pioneer-link");+ }+static Label Line(VisualElement parent, string name, string value){var l = new Label(value) { name = name };diff --git a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs b/unity/Assets/Scripts/UI/InfoPanelPresenter.csindex 17a8a3f3e..4d6c0f066 100644--- a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs+++ b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs@@ -38,6 +38,12 @@ namespace Statecraft.Game.UIreadonly System.Func<PlacedToken?> selectedUnit;readonly System.Action? unitDone;bool unitMode;+ int? pioneer;+ GameSession? pioneerSession;+ readonly VisualElement pioneerList;+ readonly Button pioneerReturn;+ readonly System.Action onPioneerReturn;+ readonly System.Action<int>? selectPioneer;/// <summary>Lights the hexes the Move or Attack pick offers on the map (none: clears them); null: nothing is drawn.</summary>readonly System.Action<IReadOnlyCollection<(int q, int r)>>? showReachable;/// <summary>Draws a multi-turn go-to route and its arrival-turn numbers; null keeps picking functional without it.</summary>@@ -95,10 +101,15 @@ namespace Statecraft.Game.UISystem.Func<string, (int q, int r)>? townHex = null, IReadOnlyDictionary<string, string>? townNamesHe = null,System.Action<IReadOnlyCollection<(int q, int r)>>? showReachable = null, System.Func<int, string?>? unitName = null,System.Action? unitDone = null,- System.Action<IReadOnlyList<(int q, int r, int turn)>>? showRoute = null, System.Action? clearSelection = null)+ System.Action<IReadOnlyList<(int q, int r, int turn)>>? showRoute = null, System.Action? clearSelection = null, System.Action<int>? selectPioneer = null){panel = root.Q<VisualElement>("info-panel"); this.bridge = bridge; this.text = text;orders = panel.Q<VisualElement>("info-orders");+ this.selectPioneer = selectPioneer;+ pioneerList = panel.Q<VisualElement>("info-pioneers");+ pioneerReturn = panel.Q<Button>("info-pioneer-return");+ onPioneerReturn = ReturnPioneer;+ pioneerReturn.clicked += onPioneerReturn;this.clearSelection = clearSelection;onCancel = e => { if (!e.isPropagationStopped && Escape()) e.StopPropagation(); };panel.RegisterCallback(onCancel);@@ -156,7 +167,7 @@ namespace Statecraft.Game.UIvoid OnHudGeometry(GeometryChangedEvent e) => panel.EnableInClassList(ShortClass, e.newRect.height < ShortBelowPx);/// <summary>Unsubscribes from the bridge and the buttons (the owner calls this when disabled).</summary>- public void Dispose() { panel.UnregisterCallback(onCancel); presses.Dispose(); bridge.Changed -= Render; panel.parent?.UnregisterCallback<GeometryChangedEvent>(OnHudGeometry); campButton.clicked -= onCamp; housingButton.clicked -= onHousing; defenceButton.clicked -= onDefence; moveButton.clicked -= onMove; fortifyButton.clicked -= onFortify; holdButton.clicked -= onHold; attackButton.clicked -= onAttack; sendHomeButton.clicked -= onSendHome; skipButton.clicked -= onSkip; reinforceButton.clicked -= onReinforce; EndPick(); }+ public void Dispose() { pioneerReturn.clicked -= onPioneerReturn; pioneerList.Clear(); panel.UnregisterCallback(onCancel); presses.Dispose(); bridge.Changed -= Render; panel.parent?.UnregisterCallback<GeometryChangedEvent>(OnHudGeometry); campButton.clicked -= onCamp; housingButton.clicked -= onHousing; defenceButton.clicked -= onDefence; moveButton.clicked -= onMove; fortifyButton.clicked -= onFortify; holdButton.clicked -= onHold; attackButton.clicked -= onAttack; sendHomeButton.clicked -= onSendHome; skipButton.clicked -= onSkip; reinforceButton.clicked -= onReinforce; EndPick(); }/// <summary>Below this window height (logical px; 1366x657 is about 998) the panel gets ShortClass, and the city's own/// hex folds its projects behind their toggle as on a stacked bar (GddHexPanel.ToggleName): there the full list ran into@@ -181,7 +192,10 @@ namespace Statecraft.Game.UIpublic (int q, int r)? Selected { get; private set; }/// <summary>True while the panel shows a unit's card.</summary>- public bool ShowsUnit => unitMode && selectedUnit() != null;+ public bool ShowsUnit => pioneer != null || (unitMode && selectedUnit() != null);++ /// <summary>The pioneer group whose card the panel shows, or null (the advisor puts it back, GameRoot's keepSelection).</summary>+ public int? Pioneer => pioneer;/// <summary>True while a screen covers the panel (a wide screen, or any screen in the two-row HUD): a map click/// then changes neither the hex nor the unit shown (#210; units-in-play merge note).</summary>@@ -202,7 +216,7 @@ namespace Statecraft.Game.UIif (Covered) return; // covered (#210)if (unitMode || Selected != (q, r)) projects.RemoveFromClassList(GddHexPanel.OpenClass); // a newly chosen hex starts with its city projects foldedEndPick();- unitMode = false; Selected = (q, r);+ pioneer = null; pioneerSession = null; unitMode = false; Selected = (q, r);Render();}@@ -211,7 +225,7 @@ namespace Statecraft.Game.UI{if (Covered) return;EndPick();- unitMode = true; Selected = null; Render();+ pioneer = null; pioneerSession = null; unitMode = true; Selected = null; Render();}/// <summary>Shows nothing selected (the hint), as before the first click; ignored while covered.</summary>@@ -219,7 +233,54 @@ namespace Statecraft.Game.UI{if (Covered) return;EndPick();- unitMode = false; Selected = null; Render();+ pioneer = null; pioneerSession = null; unitMode = false; Selected = null; Render();+ }++ void RequestPioneer(int id)+ {+ if (Covered || !panel.enabledInHierarchy) return;+ if (selectPioneer != null) selectPioneer(id); else ShowPioneer(id);+ }++ public void ShowPioneer(int id)+ {+ if (Covered || !panel.enabledInHierarchy || !bridge.State.Units.TryGetValue(id, out var u) || !Projects.IsPioneer(u.Type)) return;+ EndPick();+ showReachable?.Invoke(System.Array.Empty<(int q, int r)>());+ showRoute?.Invoke(System.Array.Empty<(int q, int r, int turn)>());+ clearSelection?.Invoke();+ unitMode = false; pioneer = id; pioneerSession = bridge.Session; Selected = (u.Q, u.R);+ projects.RemoveFromClassList(GddHexPanel.OpenClass);+ Render();+ if (presses.ByKeyboard) FocusReturn.ToOrWithin(pioneerReturn, mapFocus);+ }++ bool PioneerWorkOrdered(int id) => GddHexPanel.PioneerReturnOrder(bridge, id).WorkOrdered;++ /// <summary>The card's own checks (the card opened in this session, the game not over, the panel neither disabled+ /// nor covered) around the rows' guarded Return.</summary>+ bool CardCanAct => pioneerSession != null && pioneerSession == bridge.Session && bridge.State.GameOver == null+ && panel.enabledInHierarchy && !Covered;++ bool CanReturnPioneer(int id) => CardCanAct && GddHexPanel.PioneerReturnOrder(bridge, id) is (true, false);++ void ReturnPioneer()+ {+ if (pioneer is int id && CardCanAct) GddHexPanel.PioneerReturnOrder(bridge, id, submit: true);+ }++ void RenderPioneerList(int q, int r)+ {+ var groups = bridge.State.Units.Values.Where(u => Projects.IsPioneer(u.Type) && u.Q == q && u.R == r).OrderBy(u => u.Id).ToList();+ if (groups.Count == 0) return;+ pioneerList.style.display = DisplayStyle.Flex;+ foreach (var u in groups)+ {+ var id = u.Id;+ var b = new Button(() => RequestPioneer(id)) { name = "pioneer-select-" + id.ToString(CultureInfo.InvariantCulture),+ text = text.Format("pioneer.card.open", GddHexPanel.Group(text, bridge.State, id)) };+ b.AddToClassList("pioneer-link"); pioneerList.Add(b);+ }}/// <summary>The shown unit's sim id and the hexes its Move can go to (Movement.Reachable: the sim's answer, spec section@@ -556,8 +617,13 @@ namespace Statecraft.Game.UIpublic void Render(){+ var focused = presses.ByKeyboard ? panel.focusController?.focusedElement as VisualElement : null;+ var keepPioneerFocus = focused != null && (pioneerList.Contains(focused) || focused == pioneerReturn);+ var focusName = keepPioneerFocus ? focused!.name : null;clickThrough = null;RenderLines();+ if (keepPioneerFocus)+ FocusReturn.ToOrWithin(panel.Q(focusName), mapFocus, pioneerList);panel.EnableInClassList(GddClass, gdd.style.display.value == DisplayStyle.Flex);// A fact row shows only when its line has something to say (an empty row would leave a lone sign).foreach (var (row, line) in rows)@@ -567,6 +633,13 @@ namespace Statecraft.Game.UIvoid RenderLines(){var c = bridge.Content; var s = bridge.State;+ pioneerList.Clear(); pioneerList.style.display = DisplayStyle.None;+ pioneerReturn.style.display = DisplayStyle.None;+ if (pioneer is int selected && (pioneerSession != bridge.Session || !s.Units.TryGetValue(selected, out var live) || !Projects.IsPioneer(live.Type)))+ {+ if (pioneerSession != bridge.Session) Selected = null;+ pioneer = null; pioneerSession = null;+ }var camp = campButton; var housing = housingButton;var unit = unitMode ? selectedUnit() : null;// A unit that has left the state (destroyed or surrendered in its own attack) closes its card; a row with no@@ -629,7 +702,24 @@ namespace Statecraft.Game.UI}reinforceButton.style.display = reinforce != null ? DisplayStyle.Flex : DisplayStyle.None;if (reinforce is Reinforce offer) reinforceButton.text = text.Format("unit.order.reinforce", offer.Count);- panel.EnableInClassList(UnitClass, unit != null);+ panel.EnableInClassList(UnitClass, unit != null || pioneer != null);+ if (pioneer is int pid)+ {+ var card = PioneerCard.For(c, s, text, pid, TownName);+ Selected = (s.Units[pid].Q, s.Units[pid].R);+ panel.EnableInClassList("info-empty", false);+ title.text = card.Title; subtitle.text = card.Track;+ settlements.text = card.Location + "\n" + card.Status;+ if (Projects.IsBusy(s, pid)) settlements.text += "\n" + text["pioneer.card.stop_first"];+ region.text = placement.text = "";+ reason.text = PioneerWorkOrdered(pid) ? text["pioneer.card.work_ordered"] : s.GameOver != null ? text["order.game_over"] : "";+ ShowLocalities(""); ShowThumb(null);+ camp.style.display = housing.style.display = DisplayStyle.None;+ pioneerReturn.text = text.Format("pioneer.return", card.Title);+ pioneerReturn.style.display = DisplayStyle.Flex; pioneerReturn.SetEnabled(CanReturnPioneer(pid));+ GddHexPanel.Hide(gdd); GddHexPanel.Hide(projects);+ return;+ }if (unit != null){var card = UnitCard.For(unit.Value, s, text, c.IsGdd, c, townNamesHe);@@ -690,7 +780,8 @@ namespace Statecraft.Game.UIwhile (part != null && !(part.name is { } pn && (pn.StartsWith("site-part-", System.StringComparison.Ordinal) || pn.StartsWith("corridor-part-", System.StringComparison.Ordinal))))part = part.parent;var partName = part?.name;- var siteName = GddHexPanel.Render(gdd, projects, bridge, text, q, r, TownName);+ var siteName = GddHexPanel.Render(gdd, projects, bridge, text, q, r, TownName, RequestPioneer);+ RenderPioneerList(q, r);if (!string.IsNullOrEmpty(keep)){// The rebuilt button of the same name; failing that the nearest control that can take the focus, thediff --git a/unity/Assets/Scripts/UI/PioneerCard.cs b/unity/Assets/Scripts/UI/PioneerCard.csnew file mode 100644index 000000000..fcdc9df6e--- /dev/null+++ b/unity/Assets/Scripts/UI/PioneerCard.cs@@ -0,0 +1,39 @@+#nullable enable+using System;+using System.Linq;+using Statecraft.Sim;++namespace Statecraft.Game.UI+{+ /// <summary>Read-only pioneer facts. Identity, work and location always come from the displayed sim state.</summary>+ public static class PioneerCard+ {+ public static (string Title, string Track, string Location, string Status) For(+ Content c, GameState s, UiText text, int id, Func<string, string> townName)+ {+ var u = s.Units[id];+ string SiteName(Statecraft.Sim.Site site) => text["ui.lang"] == UiLanguage.Hebrew && !string.IsNullOrWhiteSpace(site.NameHe) ? site.NameHe : site.Name;+ var hex = c.HexAt(u.Q, u.R);+ var places = c.SettlementHexes.Where(x => x.Q == u.Q && x.R == u.R).Select(x => townName(x.Id))+ .Concat(c.Sites.Where(x => x.Q == u.Q && x.R == u.R).Select(SiteName)).Distinct();+ // Same player-facing hex convention as InfoPanelPresenter: terrain and elevation, never axial coordinates.+ var terrain = hex == null ? text["info.off_map"] : text.Format("info.hex", text["info.biome." + hex.Biome], hex.ElevM);+ var location = text.Format("pioneer.card.location", string.Join(" · ", places.Concat(new[] { terrain })));+ var status = text["pioneer.card.idle"];+ var siteWork = s.Sites.Values.FirstOrDefault(w => w.BuiltOn == null && w.Unit == id);+ if (siteWork != null)+ {+ var site = c.Sites.First(x => x.Id == siteWork.Site);+ status = text.Format("pioneer.card.working", SiteName(site));+ }+ else if (Corridors.WorkOf(s, id) is var (work, index))+ {+ var d = c.Corridors.First(x => x.Id == work.Id);+ var name = text["ui.lang"] == UiLanguage.Hebrew && !string.IsNullOrWhiteSpace(d.NameHe) ? d.NameHe : d.Name;+ status = text.Format("pioneer.card.working", text.Format("corridor.segment", name, index + 1));+ }+ return (GddHexPanel.Group(text, s, id),+ text.Format("pioneer.card.track", text[u.Type == Projects.VeteranType ? "unit.name.veteran_halutz" : "city.track_halutz"]), location, status);+ }+ }+}diff --git a/unity/Assets/Scripts/UI/PioneerCard.cs.meta b/unity/Assets/Scripts/UI/PioneerCard.cs.metanew file mode 100644index 000000000..26864aa2f--- /dev/null+++ b/unity/Assets/Scripts/UI/PioneerCard.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 1c430caa3cec4ad8902617f821f27779diff --git a/unity/Assets/Tests/EditMode/AdvisorOpeningParityTests.cs b/unity/Assets/Tests/EditMode/AdvisorOpeningParityTests.csindex 71be608c0..49fdfd0bf 100644--- a/unity/Assets/Tests/EditMode/AdvisorOpeningParityTests.cs+++ b/unity/Assets/Tests/EditMode/AdvisorOpeningParityTests.cs@@ -204,6 +204,49 @@ public class AdvisorOpeningParityTestsAssert.AreEqual(hex, game.Info!.Selected, "closing puts back the player's hex");}+ /// <summary>A pioneer group's card is a selection of its own (#1549, review C288 S1): closing the advisor's city step puts+ /// back the pioneer card it found, not an empty panel; a pioneer the player opens meanwhile stays.</summary>+ [Test]+ public void ClosingPutsBackAnOpenPioneerCard()+ {+ var game = OpenScene(new SaveStore(TempDir()), new SettingsStore(TempDir()));+ Begin(game, Inputs, 0, startScreen: true); UiTestKit.Press(Ui.Q<Button>("start-new-game"));+ game.Advisor!.CloseChain();+ var bridge = game.Bridge!; var info = game.Info!; var units = game.Units!;+ var city = AdvisorTargets.CityHex(bridge.Content, bridge.State)!.Value;+ var hex = bridge.Content.Hexes.First(h => h.Land && (h.Q, h.R) != city && units.UnitToSelectAt(h.Q, h.R) == null+ && !bridge.Content.SettlementHexes.Any(x => x.Q == h.Q && x.R == h.R) && !bridge.Content.Sites.Any(x => x.Q == h.Q && x.R == h.R));+ var id = PioneerCardTests.Add(bridge.State, hex.Q, hex.R);+ var other = PioneerCardTests.Add(bridge.State, hex.Q, hex.R);+ void OpenCityStep()+ {+ game.Advisor!.OpenChain();+ for (int i = 0; i < 2; i++) UiTestKit.Press(Ui.Q<Button>("advisor-got-it"));+ Assert.AreEqual(city, info.Selected, "precondition: the city step shows its city");+ Assert.IsNull(info.Pioneer, "precondition: the advisor's city, not the pioneer card");+ }++ if (game.Card!.Shown != null && !game.Card.Collapsed) GameSceneTests.HideTheOpeningCard(Ui); // the card over the HUD+ info.Show(hex.Q, hex.R);+ var link = PioneerCardTests.Link(Ui, id);+ Assert.IsTrue(link != null && link.enabledInHierarchy, "precondition: the hex lists the pioneer group, pressable");+ UiTestKit.Press(link!);+ Assert.AreEqual(id, info.Pioneer, "precondition: the pioneer's card");+ Assert.IsTrue(info.ShowsUnit);+ OpenCityStep();+ UiTestKit.Press(Ui.Q<Button>("advisor-close"));+ Assert.AreEqual(id, info.Pioneer, "closing puts back the pioneer card the advisor found");+ Assert.IsTrue(info.ShowsUnit);+ Assert.AreEqual(GddHexPanel.Group(En, bridge.State, id), Ui.Q<Label>("info-title").text);+ Assert.IsNull(units.Selected, "no military token selected with it");++ OpenCityStep();+ info.Show(hex.Q, hex.R); UiTestKit.Press(PioneerCardTests.Link(Ui, other)!); // the player opens another group meanwhile+ Assert.AreEqual(other, info.Pioneer, "precondition: the player's newer pioneer card");+ UiTestKit.Press(Ui.Q<Button>("advisor-close"));+ Assert.AreEqual(other, info.Pioneer, "a pioneer the player opened meanwhile stays");+ }+// --- Skip, Escape and How to play -------------------------------------------------------------------------------sealed class Rig : IDisposablediff --git a/unity/Assets/Tests/EditMode/GameSceneTests.cs b/unity/Assets/Tests/EditMode/GameSceneTests.csindex eb194c8c3..c3abbe9d2 100644--- a/unity/Assets/Tests/EditMode/GameSceneTests.cs+++ b/unity/Assets/Tests/EditMode/GameSceneTests.cs@@ -1055,4 +1055,30 @@ public class GameSceneTestsif (rt != null) { rt.Release(); Object.DestroyImmediate(rt); }}}+ [Test]+ public void AProjectLinkOpensAPioneerCardThroughTheRealRoot()+ {+ var game = Boot(); HideTheOpeningCard(Ui);+ var b = game.Bridge!; var site = b.Content.Sites.First(x => Projects.IsYishuvSite(x));+ var home = b.Content.SettlementHexes.First(x => x.Id == "tel_aviv");+ var id = PioneerCardTests.Add(b.State, home.Q, home.R);+ b.State.Sites[site.Id] = new SiteWork(site.Id, id, 3, null);+ var map = Object.FindFirstObjectByType<MapScene>();+ // Pick a military unit first: the project link must clear its ring and reach overlay.+ game.FocusUnit("golani");+ // A city/name pill is not needed to open a designated project hex.+ var infoField = typeof(GameRoot).GetField("info", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);+ var info = (InfoPanelPresenter)infoField!.GetValue(game)!;+ info.Show(site.Q, site.R);+ var link = Ui.Q<Button>("pioneer-project-" + id.ToString(System.Globalization.CultureInfo.InvariantCulture));+ Assert.IsNotNull(link); UiTestKit.Press(link);+ Assert.IsTrue(info.ShowsUnit); Assert.IsFalse(info.MovePicking);+ Assert.AreEqual(GddHexPanel.Group(Text, b.State, id), Ui.Q<Label>("info-title").text);+ Assert.IsFalse(Ui.Q<Button>("info-pioneer-return").enabledSelf);+ Assert.IsFalse(map.Terrain.transform.Find(MapScene.ReachableName).GetComponent<MeshRenderer>().enabled);+ var unitsField = typeof(GameRoot).GetField("units", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);+ var units = (Statecraft.Game.Map.Units.UnitLayer)unitsField!.GetValue(game)!;+ Assert.IsNull(units.Selected);+ }+}diff --git a/unity/Assets/Tests/EditMode/InfoPanelLayoutTests.cs b/unity/Assets/Tests/EditMode/InfoPanelLayoutTests.csindex aad91d562..ccf0410e4 100644--- a/unity/Assets/Tests/EditMode/InfoPanelLayoutTests.cs+++ b/unity/Assets/Tests/EditMode/InfoPanelLayoutTests.cs@@ -583,6 +583,157 @@ public class InfoPanelLayoutTests}, text: text, hebrew: hebrew, unit: () => selected);}+ [UnityTest]+ public IEnumerator PioneerListsAndCardsFitTheRequiredWindowsInBothLanguages()+ {+ foreach (var hebrew in new[] { false, true })+ foreach (var (w, h) in new[] { (1024, 768), (1366, 768) })+ foreach (var mode in new[] { "list", "idle", "busy" })+ {+ var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);+ var site = C.Sites.Where(x => Projects.IsYishuvSite(x)).OrderByDescending(x => x.Name.Length + x.NameHe.Length).First();+ var hex = C.Hexes.First(x => x.Land && !C.SettlementHexes.Any(y => y.Q == x.Q && y.R == x.R)+ && !C.Sites.Any(y => y.Q == x.Q && y.R == x.R)+ && !C.Corridors.Any(d => d.Segments.Any(seg => seg.Hexes.Any(hh => hh[0] == x.Q && hh[1] == x.R)))+ && Projects.CitiesFor(C, g.State, x.Q, x.R).Count == 0);+ var id = PioneerCardTests.Add(g.State, hex.Q, hex.R, Projects.VeteranType);+ for (int i = 0; i < 24; i++) PioneerCardTests.Add(g.State, hex.Q, hex.R);+ if (mode == "busy") g.State.Sites[site.Id] = new SiteWork(site.Id, id, 3, null);+ var t = PioneerCardTests.Text(hebrew);+ yield return Rendered(w, h, g, (root, info) => info.Show(hex.Q, hex.R), root =>+ {+ var panel = root.Q("info-panel"); Assert.IsTrue(Inside(panel.worldBound, root.worldBound));+ if (mode == "list")+ {+ var list = root.Q<ScrollView>("info-pioneers");+ Assert.IsTrue(Inside(list.worldBound, panel.worldBound));+ Assert.AreEqual(25, list.Query<Button>().ToList().Count);+ var last = list.Query<Button>().ToList().Last();+ Assert.IsTrue(Inside(last.worldBound, list.contentViewport.worldBound), "last entry is reachable after scrolling");+ Assert.IsTrue(TextFits(last), last.text);+ }+ else+ {+ var back = root.Q<Button>("info-pioneer-return");+ Assert.AreEqual(mode == "idle", back.enabledSelf);+ foreach (var line in panel.Query<TextElement>().ToList().Where(x => Shown(x) && !string.IsNullOrEmpty(x.text)))+ {+ Assert.IsTrue(Inside(line.worldBound, panel.worldBound), line.name);+ Assert.IsTrue(TextFits(line), line.text);+ }+ }+ }, t, hebrew, root =>+ {+ // The new game's opening card is modal and disables the panel: hide it, as a player does, then press once+ // the HUD has its tier, as the other presses here.+ GameSceneTests.HideTheOpeningCard(root);+ var link = PioneerCardTests.Link(root, id); Assert.IsNotNull(link);+ if (mode != "list") { UiTestKit.Press(link); return; }+ var list = root.Q<ScrollView>("info-pioneers");+ list.ScrollTo(list.Query<Button>().ToList().Last());+ });+ }+ }++ [UnityTest]+ public IEnumerator PioneerLinksCoexistWithCityAndLongNamedProjects()+ {+ var problems = new List<string>();+ foreach (var hebrew in new[] { false, true })+ foreach (var (w, h) in new[] { (1024, 768), (1366, 768) })+ foreach (var mode in new[] { "city", "site-idle", "site-busy", "corridor-idle", "corridor-busy" })+ {+ var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);+ // Isolate the three candidate links; retain the rest of the real scenario and UI.+ foreach (var id in g.State.Units.Values.Where(u => Projects.IsPioneer(u.Type)).Select(u => u.Id).ToList())+ g.State.Units.Remove(id);+ g.State.Sites.Clear(); g.State.Corridors.Clear();+ var city = C.SettlementHexes.Single(x => x.Id == "tel_aviv");+ var site = C.Sites.Where(x => Projects.IsYishuvSite(x))+ .OrderByDescending(x => (hebrew ? x.NameHe : x.Name).Length).First();+ // Pick a longest-name corridor with a non-city hex in its first segment.+ var d = C.Corridors.Where(x => x.Segments[0].Hexes.Any(hh => !C.SettlementHexes.Any(c => c.Q == hh[0] && c.R == hh[1])))+ .OrderByDescending(x => (hebrew ? x.NameHe : x.Name).Length).First();+ var segmentHex = d.Segments[0].Hexes.First(hh => !C.SettlementHexes.Any(c => c.Q == hh[0] && c.R == hh[1]));+ var q = mode == "city" ? city.Q : mode.StartsWith("site", System.StringComparison.Ordinal) ? site.Q : segmentHex[0];+ var r = mode == "city" ? city.R : mode.StartsWith("site", System.StringComparison.Ordinal) ? site.R : segmentHex[1];+ var ids = Enumerable.Range(0, 3).Select(_ => PioneerCardTests.Add(g.State, city.Q, city.R)).ToArray();+ if (mode == "city")+ {+ var x = g.State.Cities[city.Id];+ g.State.Cities[city.Id] = x.WithCraftsmen(2).WithQualified(new Qualified(1, 1, new[] { 3, 5 }));+ g.State.Policies[MapActions.MaabarotPolicy] = 1;+ }+ if (mode == "site-busy") g.State.Sites[site.Id] = new SiteWork(site.Id, ids[0], 3, null);+ if (mode == "corridor-busy") g.State.Corridors[d.Id] = new CorridorWork(d.Id,+ d.Segments.Select((_, i) => i == 0 ? new SegmentWork(ids[0], 0, null) : null).ToArray());+ var t = PioneerCardTests.Text(hebrew);+ var at = $"{(hebrew ? "he" : "en")} {w}x{h} {mode}";+ void Expect(bool ok, string what) { if (!ok) problems.Add($"{at}: {what}"); }+ yield return Rendered(w, h, g, (root, info) => info.Show(q, r), root =>+ {+ var panel = root.Q("info-panel"); var host = root.Q(GddHexPanel.HostName);+ Expect(Inside(panel.worldBound, root.worldBound), $"the panel {panel.worldBound} leaves the window {root.worldBound}");+ Assert.IsTrue(Shown(host), mode);+ Assert.AreEqual(DisplayStyle.None, root.Q<Button>("info-pioneer-return").resolvedStyle.display,+ "measure project links before opening any card");+ if (mode == "city")+ {+ Assert.IsNotNull(host.Q<Button>("city-reassign-halutz"));+ Assert.IsNotNull(host.Q<Button>("city-workers-more"));+ var projects = root.Q(GddHexPanel.ProjectsHostName);+ Assert.IsTrue(Shown(projects));+ Assert.IsNotNull(projects.Q<Button>("city-project-" + C.ProjectKinds[0].Id));+ var list = root.Q<ScrollView>("info-pioneers");+ Assert.IsTrue(Inside(list.worldBound, panel.worldBound));+ var links = list.Query<Button>().ToList(); Assert.AreEqual(3, links.Count);+ Assert.Greater(list.contentContainer.worldBound.height, list.contentViewport.worldBound.height,+ "crowded city list needs scrolling");+ Assert.IsTrue(Inside(links.Last().worldBound, list.contentViewport.worldBound), "last city link reachable after scrolling");+ foreach (var link in links) Assert.IsTrue(TextFits(link), link.text);+ }+ else+ {+ var part = mode.StartsWith("site", System.StringComparison.Ordinal)+ ? host.Q("site-part-" + site.Id) : host.Q("corridor-part-" + d.Id + "-1");+ Assert.IsNotNull(part);+ var links = part.Query<Button>().ToList().Where(b => b.name.StartsWith("pioneer-project-", System.StringComparison.Ordinal)).ToList();+ var busy = mode.EndsWith("busy", System.StringComparison.Ordinal);+ // The worker's row links to its card; idle candidates keep #1540's rows unchanged (they open from+ // their own hex's list): three extra links per segment ran a three-segment hex off the window.+ Assert.AreEqual(busy ? 1 : 0, links.Count, "only the worker's row links to its card");+ var action = part.Q<Button>(busy ? (mode.StartsWith("site", System.StringComparison.Ordinal) ? "site-stop" : "corridor-stop")+ : (mode.StartsWith("site", System.StringComparison.Ordinal) ? "site-build-" : "corridor-build-") + ids[0].ToString(System.Globalization.CultureInfo.InvariantCulture));+ Assert.IsNotNull(action);+ Expect(action.enabledInHierarchy && Shown(action), $"{action.name} '{action.text}' enabled {action.enabledInHierarchy} shown {Shown(action)}");+ Expect(Inside(action.worldBound, panel.worldBound), $"{action.name} {action.worldBound} leaves the panel {panel.worldBound}");+ foreach (var link in links)+ {+ Expect(link.enabledInHierarchy && Shown(link), $"{link.name} enabled {link.enabledInHierarchy} shown {Shown(link)}");+ Expect(Inside(link.worldBound, panel.worldBound), $"{link.name} {link.worldBound} leaves the panel {panel.worldBound}"); Expect(TextFits(link), $"'{link.text}' does not fit");+ }+ }+ // city-jobs: 'Jobs: 106 of 106 filled' already overflows its box at en 1024x768 on main with this city state+ // (measured on b56011ba, before this change); not this test's subject.+ foreach (var line in panel.Query<TextElement>().ToList().Where(x => Shown(x) && !string.IsNullOrEmpty(x.text)+ && x.name != "city-jobs" && !root.Q<ScrollView>("info-pioneers").Contains(x)))+ {+ Expect(Inside(line.worldBound, panel.worldBound), $"'{line.text}' {line.worldBound} leaves the panel {panel.worldBound} ({line.name})");+ Expect(TextFits(line), $"'{line.text}' does not fit its box {line.contentRect} ({line.name})");+ }+ }, t, hebrew, root =>+ {+ GameSceneTests.HideTheOpeningCard(root); // the modal opening card disables the panel's links+ if (mode == "city")+ {+ var list = root.Q<ScrollView>("info-pioneers");+ list.ScrollTo(list.Query<Button>().ToList().Last());+ }+ });+ }+ Assert.IsEmpty(problems, string.Join("\n", problems));+ }+// R-MOVE-001 (#1708): both locales display the same effective allowance used by sim reachability.[UnityTest]public IEnumerator Gdd03UnitCardUsesEffectivePointsDenominator([Values(false, true)] bool hebrew)diff --git a/unity/Assets/Tests/EditMode/PioneerCardTests.cs b/unity/Assets/Tests/EditMode/PioneerCardTests.csnew file mode 100644index 000000000..8084c9989--- /dev/null+++ b/unity/Assets/Tests/EditMode/PioneerCardTests.cs@@ -0,0 +1,253 @@+#nullable enable+using System.Collections.Generic;+using System.Globalization;+using System.Linq;+using NUnit.Framework;+using Statecraft.Game;+using Statecraft.Game.UI;+using Statecraft.Sim;+using UnityEditor;+using UnityEngine;+using UnityEngine.UIElements;++// R-QUAL-003, R-TURN-004: presentation asks the sim and uses its existing immediate unit-order path.+public class PioneerCardTests+{+ public static readonly Content C = ContentLoader.Load(Paths.Content);+ public static UiText Text(bool he) => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(he ? UiPaths.StringsHebrew : UiPaths.Strings).text);+ public static int Add(GameState s, int q, int r, string type = "halutz")+ {+ var id = s.NextId++;+ s.Units.Add(id, new Unit(id, type, q, r));+ return id;+ }+ public static InfoPanelPresenter Panel(UiTestKit ui, SimBridge b, UiText t) =>+ new InfoPanelPresenter(ui.Root, b, t, C.SettlementHexes.ToDictionary(x => x.Id, x => x.Id));+ public static Button Link(VisualElement root, int id) => root.Q<Button>("pioneer-select-" + id.ToString(CultureInfo.InvariantCulture));+ static void Open(UiTestKit ui, InfoPanelPresenter p, int id, int q, int r)+ {+ p.Show(q, r);+ var link = Link(ui.Root, id);+ Assert.IsNotNull(link, "RED on base: a pioneer on ordinary land has no selection control");+ UiTestKit.Press(link);+ }++ [TestCase(false, "halutz")] [TestCase(true, "halutz")]+ [TestCase(false, "veteran_halutz")] [TestCase(true, "veteran_halutz")]+ public void ATokenFreeListOpensALiveCardAndReturnsExactlyOnce(bool he, string type)+ {+ using var ui = new UiTestKit(); var t = Text(he);+ var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);+ var hex = C.Hexes.First(h => h.Land && !C.SettlementHexes.Any(x => x.Q == h.Q && x.R == h.R) && !C.Sites.Any(x => x.Q == h.Q && x.R == h.R));+ var id = Add(g.State, hex.Q, hex.R, type); var other = Add(g.State, hex.Q, hex.R);+ var b = new SimBridge(g, t); using var p = Panel(ui, b, t);+ Open(ui, p, id, hex.Q, hex.R);+ Assert.IsTrue(p.ShowsUnit);+ Assert.AreEqual(GddHexPanel.Group(t, b.State, id), ui.Q<Label>("info-title").text);+ Assert.That(ui.Q<Label>("info-settlements").text, Does.Contain(t["pioneer.card.idle"]));+ Assert.That(ui.Q<Label>("info-subtitle").text, Does.Contain(t[type == Projects.VeteranType ? "unit.name.veteran_halutz" : "city.track_halutz"]));+ Assert.That(ui.Q<Label>("info-settlements").text, Does.Contain(t.Format("info.hex", t["info.biome." + hex.Biome], hex.ElevM)));+ foreach (var name in new[] { "info-defence", "info-move", "info-fortify", "info-hold", "info-attack", "info-send-home", "info-reinforce", "info-skip" })+ Assert.AreEqual(DisplayStyle.None, ui.Q<Button>(name).style.display.value, name);+ var back = ui.Q<Button>("info-pioneer-return"); Assert.IsTrue(back.enabledSelf);+ UiTestKit.Press(back); UiTestKit.Press(back);+ var order = b.Session.Committed.OfType<UnitOrder>().Single();+ Assert.AreEqual((id, Qualification.ReturnOrder), (order.Unit, order.Order));+ Assert.IsNull(order.Q); Assert.IsNull(order.R); Assert.IsEmpty(b.Queued);+ Assert.IsFalse(b.State.Units.ContainsKey(id)); Assert.IsTrue(b.State.Units.ContainsKey(other));+ Assert.IsFalse(p.ShowsUnit); Assert.AreEqual((hex.Q, hex.R), p.Selected);+ Assert.IsNotNull(Link(ui.Root, other)); Assert.IsNull(Link(ui.Root, id));+ }++ [TestCase(false, false, "halutz")] [TestCase(false, true, "halutz")]+ [TestCase(true, false, "halutz")] [TestCase(true, true, "halutz")]+ [TestCase(false, false, "veteran_halutz")] [TestCase(false, true, "veteran_halutz")]+ [TestCase(true, false, "veteran_halutz")] [TestCase(true, true, "veteran_halutz")]+ public void BusySiteAndCorridorLinksOpenTheWorkersCard(bool corridor, bool he, string type)+ {+ using var ui = new UiTestKit(); var t = Text(he);+ var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);+ var home = C.SettlementHexes.First(x => x.Id == "tel_aviv");+ var id = Add(g.State, home.Q, home.R, type);+ int q, r; string target;+ if (corridor)+ {+ var d = C.Corridors.First(x => x.Segments[0].Hexes.Any(h => !C.SettlementHexes.Any(city => city.Q == h[0] && city.R == h[1]))); var h = d.Segments[0].Hexes.First(h => !C.SettlementHexes.Any(city => city.Q == h[0] && city.R == h[1])); q = h[0]; r = h[1];+ target = t.Format("corridor.segment", he && !string.IsNullOrWhiteSpace(d.NameHe) ? d.NameHe : d.Name, 1);+ g.State.Corridors[d.Id] = new CorridorWork(d.Id, d.Segments.Select((_, i) => i == 0 ? new SegmentWork(id, 0, null) : null).ToArray());+ }+ else+ {+ var site = C.Sites.First(x => Projects.IsYishuvSite(x)); q = site.Q; r = site.R;+ target = he && !string.IsNullOrWhiteSpace(site.NameHe) ? site.NameHe : site.Name;+ g.State.Sites[site.Id] = new SiteWork(site.Id, id, 3, null);+ }+ var b = new SimBridge(g, t); using var p = Panel(ui, b, t);+ p.Show(q, r);+ var link = ui.Root.Q<Button>("pioneer-project-" + id.ToString(CultureInfo.InvariantCulture));+ Assert.IsNotNull(link, "RED on base: project worker has no card link"); UiTestKit.Press(link);+ Assert.IsFalse(ui.Q<Button>("info-pioneer-return").enabledSelf);+ Assert.That(ui.Q<Label>("info-settlements").text, Does.Contain(t["pioneer.card.stop_first"]));+ Assert.That(ui.Q<Label>("info-settlements").text, Does.Contain(t.Format("pioneer.card.working", target)));+ Assert.That(ui.Q<Label>("info-settlements").text, Does.Contain("tel_aviv"), "test town-name resolver identifies the current hex separately from the work target");+ Assert.AreEqual(0, b.Session.Committed.Count);+ }++ [TestCase(false)] [TestCase(true)]+ public void CardRefusesQueuedBuildAndStopWithoutWithdrawingEither(bool stop)+ {+ using var ui = new UiTestKit(); var t = Text(false);+ var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);+ var home = C.SettlementHexes.First(x => x.Id == "tel_aviv"); var id = Add(g.State, home.Q, home.R);+ var b = new SimBridge(g, t); using var p = Panel(ui, b, t);+ Open(ui, p, id, home.Q, home.R);+ Command work = stop ? (Command)new StopWork(id) : new PioneerWork(id, Projects.BuildYishuv, C.Sites.First(x => Projects.IsYishuvSite(x)).Id);+ Assert.IsNull(b.Queue(work)); Assert.IsFalse(ui.Q<Button>("info-pioneer-return").enabledSelf);+ // Force a stale enabled control to exercise the dispatch guard as well as disabled presentation.+ ui.Q<Button>("info-pioneer-return").SetEnabled(true);+ UiTestKit.Press(ui.Q<Button>("info-pioneer-return")); Assert.IsEmpty(b.Session.Committed);+ Assert.AreSame(work, b.Queued.Single()); Assert.IsTrue(b.State.Units.ContainsKey(id));+ b.Withdraw(work); b.State.GameOver = GameOverCodes.MvpEnded; p.Render();+ Assert.IsFalse(ui.Q<Button>("info-pioneer-return").enabledSelf);+ }++ [Test]+ public void ReplacingTheSessionCannotReturnAReusedId()+ {+ using var ui = new UiTestKit(); var t = Text(false);+ var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical); var h = C.SettlementHexes.First();+ var id = Add(g.State, h.Q, h.R); var b = new SimBridge(g, t); using var p = Panel(ui, b, t);+ Open(ui, p, id, h.Q, h.R);+ var next = GameSession.New(C, GoldenRun.Seed, Mode.Historical); Add(next.State, h.Q, h.R);+ b.Replace(next); Assert.IsFalse(p.ShowsUnit);+ UiTestKit.Press(ui.Q<Button>("info-pioneer-return")); Assert.IsEmpty(next.Committed);+ }++ [TestCase("en-US")] [TestCase("he-IL")]+ public void HebrewElevationAndGroupNumbersKeepTheirDirection(string culture)+ {+ var before = CultureInfo.CurrentCulture;+ try+ {+ CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo(culture);+ var t = Text(true); var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);+ var h = C.Hexes.First(x => x.Land && x.ElevM < 0); var id = Add(g.State, h.Q, h.R);+ using var ui = new UiTestKit(); using var p = Panel(ui, new SimBridge(g, t), t);+ Open(ui, p, id, h.Q, h.R);+ var value = h.ElevM.ToString("N0", CultureInfo.InvariantCulture);+ Assert.That(ui.Q<Label>("info-settlements").text, Does.Contain("\u200e" + value + "\u200e"));+ Assert.That(ui.Q<Label>("info-title").text, Does.Contain("\u200e"));+ }+ finally { CultureInfo.CurrentCulture = before; }+ }+ [TestCase(false)] [TestCase(true)]+ public void CompletedWorkReadsIdleAndPromotionRefreshesTheTrack(bool corridor)+ {+ using var ui = new UiTestKit(); var t = Text(false);+ var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical); var h = C.SettlementHexes.First();+ var id = Add(g.State, h.Q, h.R);+ if (corridor)+ {+ var d = C.Corridors.First();+ g.State.Corridors[d.Id] = new CorridorWork(d.Id, d.Segments.Select((_, i) => i == 0 ? new SegmentWork(null, Projects.Terms(C.RulesAt(g.State.Date).Mvp!, d.Kind == Corridors.Rail ? Corridors.BuildRail : Corridors.BuildRoad).Turns, g.State.Date) : null).ToArray());+ }+ else+ {+ var site = C.Sites.First(); g.State.Sites[site.Id] = SiteWork.Built(site.Id, g.State.Date);+ }+ // Both completed records have no worker: arrangement can now reach the card assertions.+ Assert.IsFalse(Projects.IsBusy(g.State, id));+ var b = new SimBridge(g, t); using var p = Panel(ui, b, t); Open(ui, p, id, h.Q, h.R);+ Assert.That(ui.Q<Label>("info-settlements").text, Does.Contain(t["pioneer.card.idle"]));+ Assert.IsTrue(ui.Q<Button>("info-pioneer-return").enabledSelf);+ g.State.Units[id] = new Unit(id, Projects.VeteranType, h.Q, h.R); p.Render();+ Assert.That(ui.Q<Label>("info-subtitle").text, Does.Contain(t["unit.name.veteran_halutz"]));+ g.State.Units.Remove(id); p.Render(); Assert.IsFalse(p.ShowsUnit);+ UiTestKit.Press(ui.Q<Button>("info-pioneer-return")); Assert.IsEmpty(b.Session.Committed);+ }++ [Test]+ public void HiddenDisabledAndCoveredCardsCannotDispatchAndDisposeUnhooksReturn()+ {+ using var ui = new UiTestKit(); var t = Text(false);+ var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical); var h = C.SettlementHexes.First();+ var id = Add(g.State, h.Q, h.R); var b = new SimBridge(g, t); var p = Panel(ui, b, t);+ Open(ui, p, id, h.Q, h.R); var back = ui.Q<Button>("info-pioneer-return");+ ui.Q<VisualElement>("info-panel").SetEnabled(false); UiTestKit.Press(back); Assert.IsEmpty(b.Session.Committed);+ ui.Q<VisualElement>("info-panel").SetEnabled(true);+ var hud = ui.Q<VisualElement>("info-panel").parent;+ hud.AddToClassList(ScreenNav.WideOpenClass); UiTestKit.Press(back); Assert.IsEmpty(b.Session.Committed);+ hud.RemoveFromClassList(ScreenNav.WideOpenClass);+ p.Show(h.Q, h.R); UiTestKit.Press(back); Assert.IsEmpty(b.Session.Committed);+ Open(ui, p, id, h.Q, h.R); p.Dispose(); UiTestKit.Press(back); Assert.IsEmpty(b.Session.Committed);+ using var again = Panel(ui, b, t); Open(ui, again, id, h.Q, h.R); UiTestKit.Press(back);+ Assert.AreEqual(1, b.Session.Committed.Count);+ }++ [Test]+ public void OptionalProjectCallbackLeavesExistingRenderCallersUnchanged()+ {+ var t = Text(false); var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);+ var site = C.Sites.First(x => Projects.IsYishuvSite(x)); var id = Add(g.State, site.Q, site.R);+ g.State.Sites[site.Id] = new SiteWork(site.Id, id, 3, null); // the worker's row is the one that links to its card+ using var ui = new UiTestKit();+ var b = new SimBridge(g, t);+ var host = ui.Q<VisualElement>(GddHexPanel.HostName);+ var projects = ui.Q<VisualElement>(GddHexPanel.ProjectsHostName);+ GddHexPanel.Render(host, projects, b, t, site.Q, site.R, x => x);+ var actions = host.Query<Button>().ToList().Select(x => (x.name, x.text, x.enabledSelf)).ToList();+ Assert.IsNull(host.Q<Button>("pioneer-project-" + id.ToString(CultureInfo.InvariantCulture)));+ int? picked = null; int calls = 0;+ var render = typeof(GddHexPanel).GetMethod("Render");+ Assert.AreEqual(8, render!.GetParameters().Length, "optional navigation callback is absent on base");+ render.Invoke(null, new object[] { host, projects, b, t, site.Q, site.R,+ (System.Func<string, string>)(x => x), (System.Action<int>)(x => { picked = x; calls++; }) });+ CollectionAssert.AreEqual(actions, host.Query<Button>().ToList().Where(x => !x.name.StartsWith("pioneer-project-", System.StringComparison.Ordinal))+ .Select(x => (x.name, x.text, x.enabledSelf)).ToList());+ var link = host.Q<Button>("pioneer-project-" + id.ToString(CultureInfo.InvariantCulture));+ Assert.IsNotNull(link.panel, "UiTestKit hosts attach generated links to the runtime panel");+ UiTestKit.Press(link); Assert.AreEqual(id, picked); Assert.AreEqual(1, calls);+ }++ [TestCase(false)] [TestCase(true)]+ public void CardRefusesWhenCheckReturnFailsBeforeTheNextRender(bool corridor)+ {+ using var ui = new UiTestKit(); var t = Text(false);+ var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical); var h = C.SettlementHexes.First();+ var id = Add(g.State, h.Q, h.R); var b = new SimBridge(g, t); using var p = Panel(ui, b, t);+ Open(ui, p, id, h.Q, h.R); var back = ui.Q<Button>("info-pioneer-return");+ Assert.IsTrue(back.enabledSelf);+ var site = C.Sites.First(x => Projects.IsYishuvSite(x));+ if (corridor)+ {+ var d = C.Corridors.First();+ b.State.Corridors[d.Id] = new CorridorWork(d.Id, d.Segments.Select((_, i) => i == 0 ? new SegmentWork(id, 0, null) : null).ToArray());+ }+ else b.State.Sites[site.Id] = new SiteWork(site.Id, id, 3, null);+ Assert.IsNotNull(Qualification.CheckReturn(b.State, id), "the sim, not the card, refuses committed work");+ var refused = 0; b.Refused += _ => refused++;+ UiTestKit.Press(back); Assert.IsEmpty(b.Session.Committed); Assert.IsTrue(b.State.Units.ContainsKey(id));+ Assert.AreEqual(0, refused, "the shared guard asks CheckReturn first: the order never reaches the sim to be refused");+ }++ [TestCase(false)] [TestCase(true)]+ public void BusyToCompletedWorkRefreshesTheSameCard(bool corridor)+ {+ using var ui = new UiTestKit(); var t = Text(false);+ var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical); var home = C.SettlementHexes.First();+ var id = Add(g.State, home.Q, home.R);+ var site = C.Sites.First(x => Projects.IsYishuvSite(x)); var d = C.Corridors.First();+ var turns = Projects.Terms(C.RulesAt(g.State.Date).Mvp!, d.Kind == Corridors.Rail ? Corridors.BuildRail : Corridors.BuildRoad).Turns;+ if (corridor) g.State.Corridors[d.Id] = new CorridorWork(d.Id, d.Segments.Select((_, i) => i == 0 ? new SegmentWork(id, 0, null) : null).ToArray());+ else g.State.Sites[site.Id] = new SiteWork(site.Id, id, 1, null);+ var b = new SimBridge(g, t); using var p = Panel(ui, b, t); Open(ui, p, id, home.Q, home.R);+ Assert.IsFalse(ui.Q<Button>("info-pioneer-return").enabledSelf);+ if (corridor) g.State.Corridors[d.Id] = new CorridorWork(d.Id, d.Segments.Select((_, i) => i == 0 ? new SegmentWork(null, turns, g.State.Date) : null).ToArray());+ else g.State.Sites[site.Id] = SiteWork.Built(site.Id, g.State.Date);+ p.Render();+ Assert.IsTrue(p.ShowsUnit);+ Assert.That(ui.Q<Label>("info-settlements").text, Does.Contain(t["pioneer.card.idle"]));+ Assert.IsTrue(ui.Q<Button>("info-pioneer-return").enabledSelf);+ }++}diff --git a/unity/Assets/Tests/EditMode/PioneerCardTests.cs.meta b/unity/Assets/Tests/EditMode/PioneerCardTests.cs.metanew file mode 100644index 000000000..e01119eaa--- /dev/null+++ b/unity/Assets/Tests/EditMode/PioneerCardTests.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 12ef857bae1a482381296f67a8619bc1diff --git a/unity/Assets/Tests/EditMode/UnitOrdersTests.cs b/unity/Assets/Tests/EditMode/UnitOrdersTests.csindex b108d18fd..ec66f5327 100644--- a/unity/Assets/Tests/EditMode/UnitOrdersTests.cs+++ b/unity/Assets/Tests/EditMode/UnitOrdersTests.cs@@ -903,4 +903,24 @@ public class UnitOrdersTestsAssert.IsEmpty(bridge.Queued, "closing selection does not alter the turn's orders");}+ [Test]+ public void PioneerSelectionClearsMilitaryPicksAndEscapeGivesNoOrder()+ {+ using var ui = new UiTestKit(); var t = Text;+ var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);+ var token = UnitRoster.FromState(Units, C, g.State, _ => true, (row, a, q, r) => a).Single(x => x.Unit.Id == "golani");+ PlacedToken? shown = new PlacedToken(token, new AnchorSpot(0, 0, 0, 0, false));+ var golani = g.State.Units[UnitCard.SimUnit(C, g.State, token.Unit)!.Value];+ var id = PioneerCardTests.Add(g.State, golani.Q, golani.R);+ var b = new SimBridge(g, t); IReadOnlyCollection<(int q, int r)>? reach = null;+ using var p = new InfoPanelPresenter(ui.Root, b, t, C.SettlementHexes.ToDictionary(x => x.Id, x => x.Id), selectedUnit: () => shown,+ showReachable: x => reach = x, clearSelection: () => shown = null);+ p.ShowUnit(); Assert.IsNotEmpty(reach!);+ var select = typeof(InfoPanelPresenter).GetMethod("ShowPioneer");+ Assert.IsNotNull(select, "a pioneer selection transition is absent on base");+ select!.Invoke(p, new object[] { id }); Assert.IsNull(shown); Assert.IsEmpty(reach!); Assert.IsFalse(p.MovePicking);+ Assert.IsTrue(p.ShowsUnit); Assert.IsTrue(p.Escape()); Assert.IsFalse(p.ShowsUnit);+ Assert.IsNull(p.Selected); Assert.IsEmpty(b.Session.Committed); Assert.IsEmpty(b.Queued);+ }+}diff --git a/unity/Assets/UI/Game.uxml b/unity/Assets/UI/Game.uxmlindex b51f3be6d..cd8ebfaa0 100644--- a/unity/Assets/UI/Game.uxml+++ b/unity/Assets/UI/Game.uxml@@ -150,6 +150,7 @@<ui:Button name="build-camp" /><ui:Button name="build-housing" /><ui:Button name="info-defence" />+ <ui:Button name="info-pioneer-return" style="display: none;" /><!-- Keep the three primary orders together when the laptop panel has room; the group still wraps on phones. --><ui:VisualElement name="info-primary-orders" class="row info-primary-orders"><!-- The unit card's Move order (GDD loop, #754): shown only when the sim has a hex the unit can reach. -->@@ -171,6 +172,7 @@</ui:VisualElement><ui:Label name="info-reason" class="reason" /><!-- The hex's city projects (GddHexPanel, #1122): here, not in the GDD column, which a city's own hex fills. -->+ <ui:ScrollView name="info-pioneers" class="pioneer-list" mode="Vertical" style="display: none;" /><ui:VisualElement name="info-projects" class="info-projects" /></ui:VisualElement><!-- The GDD loop's city counts and orders, or the designated site's state and Build/Stop (GddHexPanel, #381): adiff --git a/unity/Assets/UI/Statecraft.uss b/unity/Assets/UI/Statecraft.ussindex 473ed2680..f521c5078 100644--- a/unity/Assets/UI/Statecraft.uss+++ b/unity/Assets/UI/Statecraft.uss@@ -420,6 +420,10 @@ Button:disabled { color: var(--ink-dim); border-color: rgba(120, 120, 120, 0.4);.info-row-sign { width: 22px; height: 22px; flex-shrink: 0; margin: 3px 10px 0 0; }.info-row-text { flex-grow: 1; flex-shrink: 1; min-width: 0; }.info-unit .info-row-sign { display: none; }+/* Token-free selection stays scrollable on crowded hexes; project links use the same wrapping copy. */+.pioneer-list { max-height: 64px; flex-shrink: 1; }+.pioneer-link { white-space: normal; font-size: 16px; flex-shrink: 0; margin: 1px 0; }+#info-pioneer-return { white-space: normal; flex-shrink: 1; }/* The border layer's label, beside the minimap's lower left: what the outlines are (MapRegions.Label). Out of the column'sflex flow (absolute), so it takes no height from the event card at any HUD tier (armistice review I-4). */.map-layer { display: none; position: absolute; right: 230px; bottom: 0; max-width: 250px; padding: 5px 8px; font-size: 15px; white-space: normal; -unity-text-align: middle-center; color: var(--ink); background-color: rgba(9, 14, 26, 0.9); border-radius: 3px; }diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yamlindex 3db75ee76..4bb365928 100644--- a/unity/Assets/UI/strings.en.yaml+++ b/unity/Assets/UI/strings.en.yaml@@ -677,6 +677,15 @@ city.reassign_halutz: "Reassign halutzim: 1 of {0}"city.reassign_veteran_halutz: "Reassign veteran pioneers: 1 of {0}"# A pioneer group's Return (R-QUAL-003); {0}: its name, site.group.pioneer.return: "Return {0} to civilian life"++# Pioneer card (#1549).+pioneer.card.open: "Open {0}"+pioneer.card.location: "Hex: {0}"+pioneer.card.track: "Track: {0}"+pioneer.card.idle: "Idle"+pioneer.card.working: "Working at {0}"+pioneer.card.stop_first: "Stop the work on its project row before returning to civilian life."+pioneer.card.work_ordered: "Build or Stop is ordered for this group. Remove that order before returning to civilian life."# City projects on the chosen hex (#1122): the city that builds it, Build for each content kind (its name, then cost and# turns from content), the order, and a project under way or finished. Refusals the map actions share use their# info.map_action_reason.* strings; these are the city projects' own.diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yamlindex 69e25532f..093c8b105 100644--- a/unity/Assets/UI/strings.he.yaml+++ b/unity/Assets/UI/strings.he.yaml@@ -737,6 +737,15 @@ city.reassign_craftsmen: "שיבוץ מחדש של בעלי מלאכה: 1 מתוcity.reassign_halutz: "שיבוץ מחדש של חלוצים: 1 מתוך {0}"city.reassign_veteran_halutz: "שיבוץ מחדש של חלוצים ותיקים: 1 מתוך {0}"pioneer.return: "החזרת {0} לחיים אזרחיים"++# Pioneer card (#1549). All new Hebrew keys below: native-review-pending (#564).+pioneer.card.open: "פתיחת {0}"+pioneer.card.location: "משבצת: {0}"+pioneer.card.track: "מסלול: {0}"+pioneer.card.idle: "ללא עבודה"+pioneer.card.working: "בעבודה ב{0}"+pioneer.card.stop_first: "כדי לחזור לחיים אזרחיים, הפסיקו את העבודה בשורת המיזם."+pioneer.card.work_ordered: "לקבוצה זו ניתנה הוראת בנייה או הפסקת עבודה. הסירו את ההוראה כדי לחזור לחיים אזרחיים."# City projects on the chosen hex (#1122). The kind names come from content/projects.yaml name_he, nouns ("מעברה"), so# every sentence takes them as nouns; "הקמת" keeps the order line's gender neutral. The resource id in no_resource has no# Hebrew name yet (no content kind requires one). For the native reviewer (#564).