A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
UI: a five-step first-turn guide, skippable and re-openable (Fixes #42) (#1209)
Eyal Golanab8ee0a5d947
diff --git a/changelog.d/first-turn-guide-42.md b/changelog.d/first-turn-guide-42.mdnew file mode 100644index 000000000..5192fbfcb--- /dev/null+++ b/changelog.d/first-turn-guide-42.md@@ -0,0 +1,3 @@+- A first-turn guide (#42): five short steps (Attention, a city's housing and jobs, training, an event card, the+ objectives), each with a gold ring round its part of the screen. It shows once, on your first new game, can be+ skipped at any step, and opens again from How to play. In English and Hebrew; it never changes the game or the save.diff --git a/unity/Assets/Scripts/UI/EventCardPresenter.cs b/unity/Assets/Scripts/UI/EventCardPresenter.csindex 3014d1a2e..d1fde0273 100644--- a/unity/Assets/Scripts/UI/EventCardPresenter.cs+++ b/unity/Assets/Scripts/UI/EventCardPresenter.cs@@ -162,11 +162,16 @@ namespace Statecraft.Game.UIpublic bool Collapsed => Shown != null && collapsedFor == Shown.Id;/// <summary>Hide: the card gives the map back and waits behind the "Decision waiting" button, which takes the focus.</summary>- public void Collapse()+ public void Collapse() => Collapse(takeFocus: true);++ /// <summary>Hide; with <paramref name="takeFocus"/> false "Decision waiting" leaves the focus where it is (the+ /// first-turn guide hides the card while its own panel has the focus, FirstTurnGuidePresenter).</summary>+ public void Collapse(bool takeFocus){if (Shown == null) return;collapsedFor = Shown.Id;Render();+ if (!takeFocus) return;if (hideByPointer) { hideByPointer = false; return; }reopen.Focus();// Tried again once styles resolve: the button was hidden a moment ago and may not take it yet.diff --git a/unity/Assets/Scripts/UI/FirstTurnGuidePresenter.cs b/unity/Assets/Scripts/UI/FirstTurnGuidePresenter.csnew file mode 100644index 000000000..47cefed88--- /dev/null+++ b/unity/Assets/Scripts/UI/FirstTurnGuidePresenter.cs@@ -0,0 +1,243 @@+#nullable enable+using System;+using System.Collections.Generic;+using System.Linq;+using Statecraft.Sim;+using UnityEngine;+using UnityEngine.UIElements;++namespace Statecraft.Game.UI+{+ /// <summary>The first-turn guide (#42; Q-ONB-1, owner, 17 October 2026, #784; in v0.1.3 by the owner's ruling of+ /// 20 October 2026): five short panels, Attention, a city's housing and jobs, training, an event card and the objectives,+ /// each with a gold ring round its part of the HUD as it is today (<see cref="Targets"/>).+ /// <para>It shows by itself once, on the first new game (<see cref="NewGame"/>): never on a Continue, and never without a+ /// settings file to remember that it was seen (automated runs and EditMode tests have none). It can be skipped at any+ /// step (Skip, Escape) and opened again from the How to play screen.</para>+ /// <para>Presentation only: it reads the state and changes the UI alone (the card's Hide, the hex the info panel shows,+ /// the "seen" line in the settings file, SettingsStore), never the sim, the queued orders or the save. Steps 2 and 3+ /// show a city with a training facility (<see cref="CityHex"/>) in the info panel; the decision card is hidden+ /// ("Decision waiting") except on step 4 and put back as it was when the guide closes. The guide takes no pointer+ /// outside its panel, so the HUD stays usable under it (the browser checks press End Turn with it open).</para></summary>+ public sealed class FirstTurnGuidePresenter : IDisposable+ {+ /// <summary>On the "root" element while the guide shows (Statecraft.uss shows its layer).</summary>+ public const string OpenClass = "guide-open";+ /// <summary>On the dock while the panel sits at the top of the window (the step's target is in the lower half).</summary>+ public const string TopClass = "guide-dock-top";+ /// <summary>The settings file's line (SettingsStore) once the guide has shown by itself.</summary>+ public const string SeenKey = "first_turn_guide";+ /// <summary>The steps' string keys, in order (guide.<key>.title, guide.<key>.text).</summary>+ public static readonly string[] Steps = { "attention", "city", "training", "event", "objectives" };+ /// <summary>The event card's step (the card shows on it and is hidden on the others).</summary>+ public const int EventStep = 3;+ /// <summary>The ring's gap round its target, in panel px.</summary>+ const float RingGap = 4f;++ readonly VisualElement hudRoot, layer, ring, dock;+ readonly Label count, title, words;+ readonly Button next, skip, reopenButton;+ readonly UiText text;+ readonly SettingsStore? store;+ readonly EventCardPresenter? card;+ readonly Action? showCity, closeScreens;+ readonly Action onNext, onSkip, onReopen;+ readonly IVisualElementScheduledItem follow;+ bool disposed;+ /// <summary>The card was open (not hidden) when the guide opened: it is put back so when the guide closes.</summary>+ bool cardWasOpen;++ /// <param name="store">The settings file, where the guide notes that it has shown (null: it never shows by itself).</param>+ /// <param name="card">The decision card, hidden except on the event step (null: none).</param>+ /// <param name="showCity">Shows <see cref="CityHex"/>'s city in the info panel, as a click on it would (null: nothing).</param>+ /// <param name="closeScreens">Closes an open side-menu screen when the guide opens (null: nothing).</param>+ public FirstTurnGuidePresenter(VisualElement root, UiText text, SettingsStore? store, EventCardPresenter? card = null,+ Action? showCity = null, Action? closeScreens = null)+ {+ this.text = text; this.store = store; this.card = card; this.showCity = showCity; this.closeScreens = closeScreens;+ hudRoot = root.Q("root") ?? root;+ layer = root.Q<VisualElement>("first-turn-guide");+ ring = layer.Q<VisualElement>("guide-ring");+ dock = layer.Q<VisualElement>("guide-dock");+ count = layer.Q<Label>("guide-count"); title = layer.Q<Label>("guide-title"); words = layer.Q<Label>("guide-text");+ next = layer.Q<Button>("guide-next"); skip = layer.Q<Button>("guide-skip");+ skip.text = text["guide.skip"];+ reopenButton = root.Q<Button>("how-to-play-guide");+ reopenButton.text = text["how_to_play.guide"];+ onNext = Next; onSkip = Close; onReopen = Open;+ next.clicked += onNext; skip.clicked += onSkip; reopenButton.clicked += onReopen;+ // The targets move with the layout (a window resized, the info panel re-rendered after an order), so the ring+ // follows them while the guide shows.+ follow = layer.schedule.Execute(Place).Every(100);+ follow.Pause();+ hudRoot.RemoveFromClassList(OpenClass);+ }++ public bool IsOpen => hudRoot.ClassListContains(OpenClass);++ /// <summary>The step shown (0 to 4), or -1 when the guide is closed.</summary>+ public int Step { get; private set; } = -1;++ /// <summary>Whether the guide has shown by itself before (the settings file's line); true with no file to read, so it+ /// never shows by itself there.</summary>+ public bool Seen => store == null || store.Read(SeenKey) == "seen";++ /// <summary>A new game has begun: the guide opens if it has never shown by itself, and notes that it has. Not under+ /// the start screen: GameRoot calls this again when the screen closes on a new game.</summary>+ public void NewGame()+ {+ if (disposed || IsOpen || Seen || hudRoot.ClassListContains(StartScreenPresenter.OpenClass)) return;+ try { store!.Write(SeenKey, "seen"); }+ catch (Exception e) { Debug.LogWarning("The first-turn guide could not note that it was seen: " + e.Message); }+ Open();+ }++ /// <summary>Opens the guide at its first step (How to play's button; NewGame). An open side-menu screen closes.</summary>+ public void Open()+ {+ if (disposed) return;+ closeScreens?.Invoke();+ if (!IsOpen) cardWasOpen = card?.Shown != null && !card.Collapsed;+ hudRoot.AddToClassList(OpenClass);+ follow.Resume();+ Show(0);+ }++ /// <summary>Next, or Done on the last step.</summary>+ public void Next()+ {+ if (!IsOpen) return;+ if (Step + 1 >= Steps.Length) Close(); else Show(Step + 1);+ }++ /// <summary>Escape: skips the guide. True when it was open.</summary>+ public bool Escape()+ {+ if (!IsOpen) return false;+ Close();+ return true;+ }++ /// <summary>Closes the guide (Skip, Done, Escape) and puts the decision card back as it was when the guide opened.</summary>+ public void Close()+ {+ if (!IsOpen) return;+ Step = -1;+ follow.Pause();+ hudRoot.RemoveFromClassList(OpenClass);+ var focused = layer.focusController?.focusedElement as VisualElement;+ bool hadFocus = focused != null && layer.Contains(focused);+ if (hadFocus) focused!.Blur();+ if (card?.Shown != null)+ {+ if (cardWasOpen && card.Collapsed) card.Reopen(); // the card takes the focus itself+ else if (!cardWasOpen && !card.Collapsed) card.Collapse(takeFocus: false);+ }+ // From the keyboard, the next Tab carries on from End Turn (#41 M1), unless the card is open and took the focus.+ if (hadFocus && (card?.Shown == null || card.Collapsed)) FocusReturn.To(hudRoot.Q<Button>("end-turn"));+ }++ void Show(int step)+ {+ Step = step;+ var key = Steps[step];+ count.text = text.Format("guide.step", step + 1, Steps.Length);+ title.text = text["guide." + key + ".title"];+ words.text = text["guide." + key + ".text"];+ next.text = text[step + 1 == Steps.Length ? "guide.done" : "guide.next"];+ // The card shows only on its own step: elsewhere its backdrop would dim the parts the other steps point at.+ if (card?.Shown != null)+ {+ if (step == EventStep && card.Collapsed) card.Reopen();+ else if (step != EventStep && !card.Collapsed) card.Collapse(takeFocus: false);+ }+ if (key == "city" || key == "training") showCity?.Invoke();+ Place();+ FocusReturn.To(next); // Enter goes on to the next step; again once styles resolve, as the layer may only now show+ }++ /// <summary>The elements a step points at, as the HUD has them now (the ring goes round the shown ones): Attention in+ /// the top bar; the city's housing, jobs and workers rows in the info panel (GddHexPanel); its training rows; the+ /// card's options, or "Decision waiting" while it is hidden; and the side menu's Objectives button (#1189).</summary>+ public IReadOnlyList<VisualElement> Targets(int step)+ {+ var found = new List<VisualElement?>();+ switch (Steps[step])+ {+ case "attention": found.Add(hudRoot.Q("attention")); break;+ case "city":+ var gdd = hudRoot.Q(GddHexPanel.HostName);+ foreach (var name in new[] { "city-housing", "city-jobs-row", "city-workers-row" }) found.Add(gdd?.Q(name));+ break;+ case "training":+ var host = hudRoot.Q(GddHexPanel.HostName);+ if (host != null) found.AddRange(host.Query<VisualElement>().Where(e => e.name.StartsWith("city-train-", StringComparison.Ordinal) && e.name.EndsWith("-row", StringComparison.Ordinal)).ToList());+ break;+ case "event":+ found.Add(card?.Shown != null && card.Collapsed ? hudRoot.Q("event-reopen") : hudRoot.Q("event-options"));+ break;+ case "objectives": found.Add(hudRoot.Q("nav-objectives")); break;+ }+ return found.Where(e => e != null && Shown(e)).Select(e => e!).ToList();+ }++ /// <summary>The window area the ring surrounds (the union of the step's shown targets), or null when none shows.</summary>+ public Rect? TargetArea()+ {+ if (Step < 0) return null;+ Rect? area = null;+ foreach (var e in Targets(Step))+ {+ var r = e.worldBound;+ area = area is Rect a ? Rect.MinMaxRect(Mathf.Min(a.xMin, r.xMin), Mathf.Min(a.yMin, r.yMin), Mathf.Max(a.xMax, r.xMax), Mathf.Max(a.yMax, r.yMax)) : r;+ }+ return area;+ }++ /// <summary>Puts the ring round the step's targets, and the panel in the other half of the window, so it never covers+ /// them. With no target shown (a card already answered, a city panel the player closed), no ring and the panel at the+ /// bottom.</summary>+ internal void Place()+ {+ if (!IsOpen) return;+ var area = TargetArea();+ ring.style.display = area == null ? DisplayStyle.None : DisplayStyle.Flex;+ if (area is not Rect a) { dock.RemoveFromClassList(TopClass); return; }+ var topLeft = layer.WorldToLocal(new Vector2(a.xMin, a.yMin));+ ring.style.left = topLeft.x - RingGap; ring.style.top = topLeft.y - RingGap;+ ring.style.width = a.width + 2 * RingGap; ring.style.height = a.height + 2 * RingGap;+ dock.EnableInClassList(TopClass, a.center.y > layer.worldBound.center.y);+ }++ /// <summary>Shown on the panel: laid out with a size, and neither it nor any parent hidden.</summary>+ static bool Shown(VisualElement e)+ {+ if (e.panel == null || !(e.worldBound.width > 0 && e.worldBound.height > 0)) return false;+ for (var v = e; v != null; v = v.parent)+ if (v.resolvedStyle.display == DisplayStyle.None || v.resolvedStyle.visibility == Visibility.Hidden) return false;+ return true;+ }++ /// <summary>The city the guide shows in the info panel: the first city (cities.yaml order) with a training facility at+ /// the start (Training.HasFacility, the sim's helper), else the first city; its settlement hex, or null with none.</summary>+ public static (int q, int r)? CityHex(Content c, GameState s)+ {+ var cities = c.Cities.Where(x => s.Cities.ContainsKey(x.Id)).ToList();+ var city = cities.FirstOrDefault(x => c.UnitTypes.Any(t => t.Facility != "" && Training.HasFacility(c, s, x.Id, t.Facility)))+ ?? cities.FirstOrDefault();+ if (city == null) return null;+ foreach (var h in c.SettlementHexes) if (h.Id == city.Id) return (h.Q, h.R);+ return null;+ }++ public void Dispose()+ {+ if (disposed) return;+ disposed = true;+ follow.Pause();+ Step = -1;+ hudRoot.RemoveFromClassList(OpenClass);+ next.clicked -= onNext; skip.clicked -= onSkip; reopenButton.clicked -= onReopen;+ }+ }+}diff --git a/unity/Assets/Scripts/UI/FirstTurnGuidePresenter.cs.meta b/unity/Assets/Scripts/UI/FirstTurnGuidePresenter.cs.metanew file mode 100644index 000000000..878da39db--- /dev/null+++ b/unity/Assets/Scripts/UI/FirstTurnGuidePresenter.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 2c3af2641513f49489a34b93390d7a23\ No newline at end of filediff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex 1a41adb31..3f78ddb94 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -61,6 +61,9 @@ namespace Statecraft.Game.UIstring? hoveredCity; // the city HoverCity lit (#1063)OutcomePresenter? outcomes;TurnReportPresenter? report;+ FirstTurnGuidePresenter? guide;+ /// <summary>Tests: the first-turn guide of the last Begin.</summary>+ internal FirstTurnGuidePresenter? Guide => guide;CameraRig? rig;List<(string, int, int, DateTime)>? drawn;/// <summary>The designated sites on the map (#381), made on first use beside the placements; and their states as drawn.</summary>@@ -405,15 +408,33 @@ namespace Statecraft.Game.UIdrawn = null; drawnSites = null;RenderPlacementsIfChanged();SyncMinimap();+ // The first-turn guide (#42) opens when the start screen closes on a new game (not on Continue). It is made after+ // the screen, so Shutdown disposes it first and the screen's closing then opens nothing.+ FirstTurnGuidePresenter? firstTurn = null;// The start screen goes up in the same frame the loading state ends, so the HUD never flashes before it. While it// shows, the camera keys are off (keyboard pan would otherwise move the hidden map; plan amendment A4).if (showsStart) // newGame is made above whenever smoke == 0{var cam = cameraController;var recording = Own(new DeclarationRecording(root, text, toast.Show)); // never built in automated runs (Skipped)- start = Own(new StartScreenPresenter(root, newGame!, resumed, shown => { if (cam != null) cam.enabled = !shown; }, recording, text));+ start = Own(new StartScreenPresenter(root, newGame!, resumed, shown =>+ {+ if (cam != null) cam.enabled = !shown;+ if (!shown && start?.Resumed == false) firstTurn?.NewGame();+ }, recording, text));start.Show();}+ // It shows by itself only where the start screen does (never in the automated runs, nor under ?firstcard, which+ // times the first card) and a settings file remembers that it has; How to play opens it again anywhere. Steps 2+ // and 3 show its city as a click there would, without selecting a unit on the city's hex.+ Action showCity = () =>+ {+ if (FirstTurnGuidePresenter.CityHex(bridge.Content, bridge.State) is not (int q, int r)) return;+ unitLayer.Select(null); map.Select(q, r); info.Show(q, r);+ };+ guide = firstTurn = Own(new FirstTurnGuidePresenter(root, text, showsStart && !FirstCardCheckRequested() ? SettingsFile() : null,+ card, showCity, () => nav?.Close()));+ if (newGame != null) newGame.Started += firstTurn.NewGame; // New Game in the top bar too; both die with this Beginif (hebrew) Own(new UiDirection(root, bridge));root.Q("root")?.RemoveFromClassList("loading"); // ready: the bar, panels and screens may show (P2-1)DiagLog.BootPhase("screens ready");@@ -523,7 +544,7 @@ namespace Statecraft.Game.UIfor (int i = owned.Count - 1; i >= 0; i--) owned[i].Dispose();owned.Clear();if (hoveredCity != null) { hoveredCity = null; HandCursor(false); } // the next Begin's pills start unlit- minimap = null; labels = null; nav = null; start = null; card = null; outcomes = null; report = null; rig = null; drawn = null; drawnSites = null; units = null; Regions = null; logCamera = false;+ minimap = null; labels = null; nav = null; start = null; card = null; outcomes = null; report = null; guide = null; rig = null; drawn = null; drawnSites = null; units = null; Regions = null; logCamera = false;// A ?profile run cut short (a stopped coroutine never reaches its restore line) must not leave the terrain at the// profile's pixel error (Task 24 review M1). Nothing else changes it, so restoring is always right.if (map != null && map.Terrain != null) map.Terrain.heightmapPixelError = MapBuilder.TerrainPixelError;@@ -653,9 +674,10 @@ namespace Statecraft.Game.UI// Escape closes the open screen even when no element has the keyboard focus (ScreenNav also takes the UI// Cancel event from a focused element; closing twice is harmless). On the start screen it withdraws an open New// Game request (StartScreenPresenter.Escape; idempotent too).+ // With no screen to close, Escape skips the first-turn guide (FirstTurnGuidePresenter.Escape).// With nothing else to close, Escape on the open decision card is Hide (EventCardPresenter.Escape; the card itself// takes the Cancel event when it has the focus).- if (UnityEngine.InputSystem.Keyboard.current?.escapeKey.wasPressedThisFrame == true) { bool done = outcomes?.SkipAll() == true || outcomes?.ClosedThisFrame == true; if (!done) done = report?.Close() == true || report?.ClosedThisFrame == true; done |= start?.Escape() == true; done |= nav?.Close() == true; if (!done && document.rootVisualElement.focusController?.focusedElement == null) card?.Escape(); }+ if (UnityEngine.InputSystem.Keyboard.current?.escapeKey.wasPressedThisFrame == true) { bool done = outcomes?.SkipAll() == true || outcomes?.ClosedThisFrame == true; if (!done) done = report?.Close() == true || report?.ClosedThisFrame == true; done |= start?.Escape() == true; done |= nav?.Close() == true; if (!done) done = guide?.Escape() == true; if (!done && document.rootVisualElement.focusController?.focusedElement == null) card?.Escape(); }// PageUp, PageDown, Home and End, with no modifier, scroll the open screen or the open card's text, with or without// focus (KeyScroll; accessibility audit H3), but not under an End Turn outcome clip, which covers them. The arrows// stay with the camera (NavigationGuard, B6).diff --git a/unity/Assets/Tests/EditMode/FirstTurnGuideTests.cs b/unity/Assets/Tests/EditMode/FirstTurnGuideTests.csnew file mode 100644index 000000000..ea32bf56d--- /dev/null+++ b/unity/Assets/Tests/EditMode/FirstTurnGuideTests.cs@@ -0,0 +1,317 @@+#nullable enable+using System;+using System.Collections;+using System.Collections.Generic;+using System.IO;+using System.Linq;+using NUnit.Framework;+using Statecraft.Game;+using Statecraft.Game.Boot;+using Statecraft.Game.Map;+using Statecraft.Game.UI;+using Statecraft.Sim;+using UnityEditor;+using UnityEditor.SceneManagement;+using UnityEngine;+using UnityEngine.TestTools;+using UnityEngine.UIElements;+using Object = UnityEngine.Object;++/// <summary>The first-turn guide (#42; Q-ONB-1, owner, 17 October 2026, #784): it shows by itself on the first new game only,+/// never on a Continue or a second game; it can be skipped and opened again from How to play; every step's target is on+/// screen at 1280x720 and 390x844 in English and Hebrew, with the panel clear of it; and it changes neither the sim nor the+/// save.</summary>+public class FirstTurnGuideTests+{+ static readonly Content C = ContentLoader.Load(Paths.Content);+ 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");+ /// <summary>The settlements' names for the info panel's title (InfoPanelLayoutTests' list).</summary>+ static Dictionary<string, string> Names() => SettlementPlacer.Parse(File.ReadAllText(Path.Combine(Paths.Content, "map", SettlementPlacer.DefaultFileName)))+ .ToDictionary(t => t.Id, t => t.Name);++ readonly List<string> temp = new List<string>();+ string TempDir()+ {+ var dir = Path.Combine(Path.GetTempPath(), "statecraft-guide-" + Guid.NewGuid().ToString("N"));+ temp.Add(dir);+ return dir;+ }++ [TearDown]+ public void Clean()+ {+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); // after the scene tests+ foreach (var d in temp) { try { if (Directory.Exists(d)) Directory.Delete(d, true); } catch (Exception) { } }+ temp.Clear();+ }++ // --- When it shows ----------------------------------------------------------------------------------------------++ static GameInputs? inputs;+ static GameInputs Inputs => inputs ??= GameInputs.FromDisk(Paths.Content, Paths.StreamingMap);+ static VisualElement Ui => Object.FindFirstObjectByType<UIDocument>().rootVisualElement;++ static GameRoot OpenScene(SaveStore store, SettingsStore settings)+ {+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);+ Object.FindFirstObjectByType<MapScene>().Build(Inputs.Map);+ var root = Object.FindFirstObjectByType<GameRoot>();+ root.Store = store; root.Settings = settings;+ return root;+ }++ /// <summary>Map.unity as a player boots it: the guide waits for the start screen, opens when New Game closes it (at its+ /// first step, the card hidden behind "Decision waiting") and notes in the settings file that it has shown; the next new+ /// game, from the start screen or the top bar, does not show it again.</summary>+ [Test]+ public void ShowsOnTheFirstNewGameOnly()+ {+ var settings = new SettingsStore(TempDir());+ var game = OpenScene(new SaveStore(TempDir()), settings);+ game.Begin(Inputs, 0, startScreen: true); // a fresh profile: no save+ Assert.IsFalse(game.Guide!.IsOpen, "not under the start screen");+ UiTestKit.Press(Ui.Q<Button>("start-new-game"));+ Assert.IsTrue(game.Guide!.IsOpen, "New Game closes the screen and the guide opens");+ Assert.AreEqual(0, game.Guide.Step);+ Assert.IsTrue(game.Card!.Shown != null && game.Card.Collapsed, "the opening card waits behind Decision waiting");+ Assert.AreEqual("seen", settings.Read(FirstTurnGuidePresenter.SeenKey));+ UiTestKit.Press(Ui.Q<Button>("guide-skip"));+ Assert.IsFalse(game.Guide.IsOpen);+ Assert.IsFalse(game.Card.Collapsed, "skipping puts the card back");++ game.Begin(Inputs, 0, startScreen: true); // a reload with no save: a new game again+ UiTestKit.Press(Ui.Q<Button>("start-new-game"));+ Assert.IsFalse(game.Guide!.IsOpen, "a second new game: not again");+ UiTestKit.Press(Ui.Q<Button>("new-game")); UiTestKit.Press(Ui.Q<Button>("new-game"));+ Assert.IsFalse(game.Guide!.IsOpen, "nor from the top bar's New Game");+ }++ /// <summary>A Continue (a loaded save) never shows it, even before it was ever seen; a new game from the top bar then+ /// does. Automated runs never show it: no start screen (Begin(inputs, n)) or no settings file.</summary>+ [Test]+ public void NeverShowsOnAContinueOrAnAutomatedRun()+ {+ var settings = new SettingsStore(TempDir());+ var store = new SaveStore(TempDir());+ var played = new SimBridge(GameSession.New(C, 9, Mode.Historical), En);+ played.EndTurn(); played.EndTurn();+ store.WriteAutosave(played.Session.Save.Write());+ var game = OpenScene(store, settings);+ game.Begin(Inputs, 0, startScreen: true);+ UiTestKit.Press(Ui.Q<Button>("start-continue"));+ Assert.IsFalse(game.Guide!.IsOpen, "Continue");+ Assert.IsNull(settings.Read(FirstTurnGuidePresenter.SeenKey), "and still unseen");++ game.Begin(Inputs, 0); // the tests' and tools' Begin: no start screen+ UiTestKit.Press(Ui.Q<Button>("new-game")); UiTestKit.Press(Ui.Q<Button>("new-game"));+ Assert.IsFalse(game.Guide!.IsOpen, "an automated run");+ game.Settings = null; // EditMode with no settings file+ game.Begin(Inputs, 0, startScreen: true);+ UiTestKit.Press(Ui.Q<Button>("start-new-game"));+ Assert.IsFalse(game.Guide!.IsOpen, "nowhere to remember it: never by itself");++ game.Settings = settings;+ game.Begin(Inputs, 0, startScreen: true);+ UiTestKit.Press(Ui.Q<Button>("start-new-game"));+ Assert.IsTrue(game.Guide!.IsOpen, "the first new game in this profile");+ }++ // --- Skip, Escape and How to play -------------------------------------------------------------------------------++ sealed class Rig : IDisposable+ {+ public readonly UiTestKit Ui = new UiTestKit();+ public readonly SimBridge Bridge;+ public readonly ScreenNav Nav;+ public readonly EventCardPresenter Card;+ public readonly FirstTurnGuidePresenter Guide;+ readonly List<IDisposable> owned = new List<IDisposable>();++ public Rig(UiText text, SettingsStore? settings = null)+ {+ Ui.Root.Q("root").RemoveFromClassList("loading");+ Bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), text);+ owned.Add(new HudPresenter(Ui.Root, Bridge, text));+ Nav = Own(new ScreenNav(Ui.Root));+ Card = Own(new EventCardPresenter(Ui.Root, Bridge, text, null));+ var info = Own(new InfoPanelPresenter(Ui.Root, Bridge, text, Names()));+ Own(new HowToPlayPresenter(Ui.Root, text));+ Guide = Own(new FirstTurnGuidePresenter(Ui.Root, text, settings, Card,+ () => { if (FirstTurnGuidePresenter.CityHex(Bridge.Content, Bridge.State) is (int q, int r)) info.Show(q, r); }, () => Nav.Close()));+ }++ T Own<T>(T d) where T : IDisposable { owned.Add(d); return d; }++ public void Dispose()+ {+ for (int i = owned.Count - 1; i >= 0; i--) owned[i].Dispose();+ Ui.Dispose();+ }+ }++ /// <summary>Skip at any step closes it; Next walks the five steps and Done closes it; Escape skips; How to play's button+ /// opens it again at its first step, closing that screen; each step shows its own strings.</summary>+ [Test]+ public void CanBeSkippedAtAnyStepAndReopened([Values(false, true)] bool hebrew)+ {+ var text = hebrew ? He : En;+ using var rig = new Rig(text, new SettingsStore(TempDir()));+ rig.Guide.NewGame();+ Assert.IsTrue(rig.Guide.IsOpen);+ for (int step = 0; step < FirstTurnGuidePresenter.Steps.Length; step++)+ {+ var key = FirstTurnGuidePresenter.Steps[step];+ Assert.AreEqual(step, rig.Guide.Step);+ Assert.AreEqual(text.Format("guide.step", step + 1, 5), rig.Ui.Q<Label>("guide-count").text);+ Assert.AreEqual(text["guide." + key + ".title"], rig.Ui.Q<Label>("guide-title").text);+ Assert.AreEqual(text["guide." + key + ".text"], rig.Ui.Q<Label>("guide-text").text);+ Assert.AreEqual(text[step == 4 ? "guide.done" : "guide.next"], rig.Ui.Q<Button>("guide-next").text);+ Assert.AreEqual(step != FirstTurnGuidePresenter.EventStep, rig.Card.Collapsed, $"step {step + 1}: the card shows on its own step only");+ rig.Ui.Press("guide-next");+ }+ Assert.IsFalse(rig.Guide.IsOpen, "Done closes it");+ Assert.IsFalse(rig.Card.Collapsed, "and the card is as it was");++ for (int at = 0; at < FirstTurnGuidePresenter.Steps.Length; at++)+ {+ rig.Ui.Press("nav-how-to-play");+ Assert.AreEqual("how-to-play", rig.Nav.Current);+ Assert.AreEqual(text["how_to_play.guide"], rig.Ui.Q<Button>("how-to-play-guide").text);+ rig.Ui.Press("how-to-play-guide");+ Assert.IsTrue(rig.Guide.IsOpen, "How to play opens it again");+ Assert.IsNull(rig.Nav.Current, "and closes itself");+ Assert.AreEqual(0, rig.Guide.Step);+ for (int i = 0; i < at; i++) rig.Ui.Press("guide-next");+ rig.Ui.Press("guide-skip");+ Assert.IsFalse(rig.Guide.IsOpen, $"Skip at step {at + 1}");+ Assert.IsFalse(rig.Card.Collapsed, $"the card is back after a Skip at step {at + 1}");+ }++ rig.Guide.Open();+ Assert.IsTrue(rig.Guide.Escape(), "Escape skips it");+ Assert.IsFalse(rig.Guide.IsOpen);+ Assert.IsFalse(rig.Guide.Escape(), "and does nothing when it is closed");++ rig.Card.Collapse(); // the player hid the card before opening the guide+ rig.Guide.Open();+ for (int i = 0; i < FirstTurnGuidePresenter.EventStep; i++) rig.Ui.Press("guide-next");+ Assert.IsFalse(rig.Card.Collapsed, "the event step shows the card");+ rig.Ui.Press("guide-skip");+ Assert.IsTrue(rig.Card.Collapsed, "and Skip hides it again, as the player left it");+ }++ // --- Presentation only ------------------------------------------------------------------------------------------++ /// <summary>The whole guide, by itself, through How to play, through every step, Skip and Escape: the state hash, the+ /// session, the queued orders and the save file are what they were.</summary>+ [Test]+ public void ChangesNeitherTheSimNorTheSave()+ {+ var store = new SaveStore(TempDir());+ var settings = new SettingsStore(TempDir());+ var game = OpenScene(store, settings);+ game.Begin(Inputs, 0, startScreen: true);+ UiTestKit.Press(Ui.Q<Button>("start-new-game"));+ Assert.IsTrue(game.Guide!.IsOpen);+ var bridge = game.Bridge!;+ bridge.EndTurn(); // a turn played, so there is a save to compare+ if (Ui.Q("root").ClassListContains(TurnReportPresenter.OpenClass)) UiTestKit.Press(Ui.Q<Button>("turn-report-close"));+ var session = bridge.Session;+ var hash = bridge.State.Hash();+ var save = store.ReadAutosave();+ Assert.IsNotNull(save, "precondition: the turn was saved");+ var queued = bridge.Queued.Count;++ void Next(int times) { for (int i = 0; i < times; i++) UiTestKit.Press(Ui.Q<Button>("guide-next")); }+ void FromHowToPlay() { UiTestKit.Press(Ui.Q<Button>("nav-how-to-play")); UiTestKit.Press(Ui.Q<Button>("how-to-play-guide")); }+ Next(FirstTurnGuidePresenter.Steps.Length); // the guide that opened by itself, to Done+ Assert.IsFalse(game.Guide.IsOpen);+ FromHowToPlay(); Next(2); UiTestKit.Press(Ui.Q<Button>("guide-skip"));+ FromHowToPlay(); Next(3); Assert.IsTrue(game.Guide.Escape());+ Assert.IsFalse(game.Guide.IsOpen);+ Assert.AreSame(session, bridge.Session, "the same game");+ Assert.AreEqual(hash, bridge.State.Hash(), "the state hash");+ Assert.AreEqual(queued, bridge.Queued.Count, "no order queued");+ Assert.AreEqual(save, store.ReadAutosave(), "the save file");+ }++ // --- Where each step points --------------------------------------------------------------------------------------++ /// <summary>Every step's target is on screen, in the window, with the gold ring round it and the panel inside the window+ /// and clear of it, at 1280x720 and 390x844 (the phone the three-row bar is tuned for), in English and Hebrew, on a new+ /// game's first turn (the opening card open).</summary>+ [UnityTest]+ public IEnumerator EveryStepPointsAtAVisibleElement()+ {+ var problems = new List<string>();+ foreach (var hebrew in new[] { false, true })+ foreach (var (w, h) in new[] { (1280, 720), (390, 844) })+ yield return EachStep(w, h, hebrew, (root, guide, step) =>+ {+ string at = $"{(hebrew ? "he" : "en")} {w}x{h} step {step + 1} ({FirstTurnGuidePresenter.Steps[step]})";+ var window = root.worldBound;+ var targets = guide.Targets(step);+ if (targets.Count == 0) { problems.Add($"{at}: no target shows"); return; }+ var area = guide.TargetArea()!.Value;+ if (!Inside(area, window)) problems.Add($"{at}: the target {area} leaves the window {window}");+ var ring = root.Q("guide-ring");+ if (ring.resolvedStyle.display != DisplayStyle.Flex) problems.Add($"{at}: no ring");+ else if (!Inside(area, ring.worldBound)) problems.Add($"{at}: the ring {ring.worldBound} is not round the target {area}");+ var panel = root.Q("guide-panel").worldBound;+ if (!(panel.width > 0) || !Inside(panel, window)) problems.Add($"{at}: the panel {panel} leaves the window {window}");+ if (panel.Overlaps(area)) problems.Add($"{at}: the panel {panel} covers the target {area}");+ foreach (var name in new[] { "guide-title", "guide-text", "guide-skip", "guide-next" })+ if (!Inside(root.Q(name).worldBound, panel)) problems.Add($"{at}: {name} {root.Q(name).worldBound} leaves the panel {panel}");+ });+ Assert.IsEmpty(problems, string.Join("\n", problems));+ }++ static bool Inside(Rect inner, Rect outer) =>+ inner.xMin >= outer.xMin - 0.5f && inner.xMax <= outer.xMax + 0.5f && inner.yMin >= outer.yMin - 0.5f && inner.yMax <= outer.yMax + 0.5f;++ /// <summary>The real Game.uxml on the real PanelSettings at w x h with the HUD, the opening card and the info panel on a+ /// new game; the guide opened, and <paramref name="check"/> run at each step once the layout has settled.</summary>+ static IEnumerator EachStep(int w, int h, bool hebrew, Action<VisualElement, FirstTurnGuidePresenter, int> check)+ {+ var text = hebrew ? He : En;+ var rt = new RenderTexture(w, h, 0);+ var ps = Object.Instantiate(AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel));+ ps.targetTexture = rt;+ var go = new GameObject("FirstTurnGuideTest");+ 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;+ root.Q("root").RemoveFromClassList("loading");+ if (hebrew) root.Q("root").AddToClassList(UiLanguage.HebrewClass);+ var bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), text);+ var hud = new HudPresenter(root, bridge, text);+ var nav = new ScreenNav(root);+ var card = new EventCardPresenter(root, bridge, text, null);+ var info = new InfoPanelPresenter(root, bridge, text, Names());+ var guide = new FirstTurnGuidePresenter(root, text, null, card,+ () => { if (FirstTurnGuidePresenter.CityHex(bridge.Content, bridge.State) is (int q, int r)) info.Show(q, r); }, () => nav.Close());+ try+ {+ Assert.IsNotNull(card.Shown, "precondition: a new game opens on a card");+ guide.Open();+ for (int step = 0; step < FirstTurnGuidePresenter.Steps.Length; step++)+ {+ if (step > 0) guide.Next();+ for (int i = 0; i < 20 && guide.Targets(step).Count == 0; i++) yield return null;+ for (int i = 0; i < 3; i++) yield return null; // the layout settles+ guide.Place();+ for (int i = 0; i < 2; i++) yield return null; // the panel's dock follows the ring's side+ check(root, guide, step);+ }+ }+ finally+ {+ guide.Dispose(); info.Dispose(); card.Dispose(); nav.Dispose(); hud.Dispose();+ Object.DestroyImmediate(go); Object.DestroyImmediate(ps); rt.Release(); Object.DestroyImmediate(rt);+ }+ }+}diff --git a/unity/Assets/Tests/EditMode/FirstTurnGuideTests.cs.meta b/unity/Assets/Tests/EditMode/FirstTurnGuideTests.cs.metanew file mode 100644index 000000000..1817eec0c--- /dev/null+++ b/unity/Assets/Tests/EditMode/FirstTurnGuideTests.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: ff2faa371b4a844dfb95fd48c2f89012\ No newline at end of filediff --git a/unity/Assets/UI/Game.uxml b/unity/Assets/UI/Game.uxmlindex 311ee0d04..f360e0f7d 100644--- a/unity/Assets/UI/Game.uxml+++ b/unity/Assets/UI/Game.uxml@@ -322,6 +322,8 @@<ui:Label name="how-to-play-end-turn" class="how-to-play-line" /><ui:Label name="how-to-play-why" class="how-to-play-line" /></ui:ScrollView>+ <!-- Opens the first-turn guide again (#42, FirstTurnGuidePresenter), which closes this screen. -->+ <ui:Button name="how-to-play-guide" class="how-to-play-guide" /><Statecraft.Game.UI.UiFrame /></ui:VisualElement><!-- The objectives (#1189, ObjectivesPresenter): one row per objective, its status and both dates, no score. -->@@ -381,6 +383,24 @@</ui:VisualElement><Statecraft.Game.UI.UiFrame /></ui:VisualElement>+ <!-- The first-turn guide (#42, FirstTurnGuidePresenter): a gold ring round the step's part of the HUD and a short panel+ in the other half of the window. It takes no pointer outside the panel, so the HUD stays usable under it. Over the+ screens and the decision layer, under the turn report, the outcome clips and the start screen. -->+ <ui:VisualElement name="first-turn-guide" class="guide-layer" picking-mode="Ignore">+ <ui:VisualElement name="guide-ring" class="guide-ring" picking-mode="Ignore" />+ <ui:VisualElement name="guide-dock" class="guide-dock" picking-mode="Ignore">+ <ui:VisualElement name="guide-panel" class="panel guide-panel">+ <ui:Label name="guide-count" class="muted guide-count" />+ <ui:Label name="guide-title" class="title guide-title" />+ <ui:Label name="guide-text" class="guide-text" />+ <ui:VisualElement class="row guide-actions">+ <ui:Button name="guide-skip" />+ <ui:Button name="guide-next" class="guide-next" />+ </ui:VisualElement>+ <Statecraft.Game.UI.UiFrame filigree="true" />+ </ui:VisualElement>+ </ui:VisualElement>+ </ui:VisualElement><!-- The turn report (#1037, TurnReportPresenter): after End Turn, each top-bar number that changed and the sim's causes.A backdrop over the HUD (ScreenNav.DisableCovered disables what it covers), under the outcome clips' layer. --><ui:VisualElement name="turn-report" class="turn-report">diff --git a/unity/Assets/UI/Statecraft.uss b/unity/Assets/UI/Statecraft.ussindex 9586568c2..c32d304f9 100644--- a/unity/Assets/UI/Statecraft.uss+++ b/unity/Assets/UI/Statecraft.uss@@ -496,6 +496,24 @@ Button.settings-choice-selected { -unity-font-definition: url("project://databas.turn-report-causes { white-space: normal; padding-left: 12px; }.turn-report-actions { justify-content: flex-end; margin-top: 8px; flex-shrink: 0; }.turn-report-actions > Button { margin-left: 8px; }+/* The first-turn guide (#42, FirstTurnGuidePresenter): shown while the root has guide-open. The layer and the ring take no+ pointer; the ring goes round the step's targets (placed in code), the dock holds the panel at the bottom of the window,+ or at the top (guide-dock-top) when the targets are in the lower half. */+.guide-layer { display: none; position: absolute; left: 0; top: 0; right: 0; bottom: 0; }+.guide-open .guide-layer { display: flex; }+.guide-ring { position: absolute; border-width: 3px; border-color: var(--gold-light); border-radius: 6px; }+.guide-dock { position: absolute; left: 0; right: 0; bottom: 16px; flex-direction: row; justify-content: center; padding: 0 16px; }+.guide-dock.guide-dock-top { bottom: auto; top: 16px; }+.guide-panel { flex-grow: 1; flex-shrink: 1; max-width: 560px; padding: 14px 18px; background-color: var(--navy-solid); border-color: var(--gold); }+.guide-count { font-size: 16px; }+.guide-title { color: var(--gold-light); font-size: 26px; white-space: normal; }+.guide-text { white-space: normal; font-size: 19px; margin: 4px 0 8px 0; }+.guide-actions { justify-content: space-between; }+.guide-actions > Button { min-height: 44px; }+.guide-next, .lang-he .guide-next { min-width: 120px; -unity-text-align: middle-center; }+/* How to play's button that opens the guide again: under the lines, never squeezed by them. */+.how-to-play-guide { flex-shrink: 0; align-self: flex-start; min-height: 44px; margin-top: 8px; }+.lang-he .how-to-play-guide { align-self: flex-end; }/* A top-bar number's explanation (MeterTip, #1037): under the bar, wrapped, kept inside the window by MeterTip. */.meter-tip {display: none; position: absolute; max-width: 420px; padding: 6px 10px;diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yamlindex 2bb553061..afe2f28b6 100644--- a/unity/Assets/UI/strings.en.yaml+++ b/unity/Assets/UI/strings.en.yaml@@ -71,6 +71,25 @@ objectives.done: "Completed on {0}; historically {1}"objectives.open: "Not completed yet; historically {0}"objectives.name.first_new_yishuv: "First new yishuv"objectives.name.absorb_immigrants: "Absorb the immigrants"+# How to play's button that opens the first-turn guide again (#42).+how_to_play.guide: "Show the first-turn guide"+# The first-turn guide (#42; Q-ONB-1, owner, 17 October 2026, #784): five steps, each pointing at its part of the HUD+# (FirstTurnGuidePresenter). Like the How to play lines, they describe the sim without balance values. {0} the step, {1} the+# number of steps.+guide.step: "Step {0} of {1}"+guide.next: "Next"+guide.done: "Done"+guide.skip: "Skip the guide"+guide.attention.title: "Attention"+guide.attention.text: "Most orders cost Attention. This shows how much you have left this turn. It refills at the start of each turn, and Attention you leave unspent does not carry over."+guide.city.title: "A city's housing and jobs"+guide.city.text: "Select a city on the map to see its housing and jobs here. The + and − buttons set how many of its civilians are in work."+guide.training.title: "Training"+guide.training.text: "In a city with a military camp or a Hakhshara, you can train civilians who have no work as recruits or halutzim. Each button shows what the training costs and how many turns it takes."+guide.event.title: "An event card"+guide.event.text: "An event card asks for a decision. Answering it costs Attention, and your choice takes effect when you end the turn. A card you leave unanswered goes to the responsible minister."+guide.objectives.title: "Objectives"+guide.objectives.text: "Objectives lists the game's goals, such as the first new yishuv, with the date you completed each beside the historical one. Completing one also brings its card."# The Settings screen (#40): its title, the tilt-shift option and the button that says what is set.settings.title: "Settings"settings.tiltshift: "Blur at the top and bottom of the map"diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yamlindex bc4016987..9e932ebe4 100644--- a/unity/Assets/UI/strings.he.yaml+++ b/unity/Assets/UI/strings.he.yaml@@ -62,6 +62,24 @@ objectives.done: "הושלם ב־{0}; בהיסטוריה ב־{1}"objectives.open: "טרם הושלם; בהיסטוריה ב־{0}"objectives.name.first_new_yishuv: "יישוב חדש ראשון"objectives.name.absorb_immigrants: "קליטת העולים"+# How to play's button that opens the first-turn guide again (#42). For the native reviewer (#564).+how_to_play.guide: "הצגת המדריך לתור הראשון"+# The first-turn guide (#42): agent-drafted Hebrew, the How to play screen's terms (#1041) and the city panel's (city.*).+# For the native reviewer (#564).+guide.step: "שלב {0} מתוך {1}"+guide.next: "הבא"+guide.done: "סיום"+guide.skip: "דילוג על המדריך"+guide.attention.title: "תשומת לב"+guide.attention.text: "רוב ההוראות עולות תשומת לב. כאן מוצג כמה נשאר לכם בתור הזה. היא מתמלאת מחדש בתחילת כל תור, ותשומת לב שלא ניצלתם אינה עוברת לתור הבא."+guide.city.title: "דיור ומשרות בעיר"+guide.city.text: "בחרו עיר במפה כדי לראות כאן את הדיור ואת המשרות בה. הכפתורים + ו־− קובעים כמה מאזרחיה עובדים."+guide.training.title: "אימון והכשרה"+guide.training.text: "בעיר שיש בה מחנה צבאי או מחנה הכשרה אפשר לאמן אזרחים ללא עבודה כמגויסים או להכשיר אותם כחלוצים. כל כפתור מראה כמה עולה האימון וכמה תורות הוא נמשך."+guide.event.title: "כרטיס אירוע"+guide.event.text: "כרטיס אירוע מבקש מכם החלטה. מענה עליו עולה תשומת לב, והבחירה שלכם נכנסת לתוקף בסיום התור. כרטיס שלא עניתם עליו עובר לשר האחראי."+guide.objectives.title: "יעדים"+guide.objectives.text: "במסך היעדים מופיעים יעדי המשחק, כמו היישוב החדש הראשון, ולצד כל אחד התאריך שבו השלמתם אותו לעומת התאריך ההיסטורי. השלמת יעד מביאה גם את הכרטיס שלו."# The Settings screen (#40). "On" / "Off" as a switch's state, not a command. For the native reviewer (#564).settings.title: "הגדרות"settings.tiltshift: "טשטוש בחלק העליון ובחלק התחתון של המפה"