Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

fix: the guide's Move step centres the camera on its unit (Fixes #1392) (#1394)

Eyal Golande78253e4c14
diff --git a/changelog.d/1392.md b/changelog.d/1392.md
new file mode 100644
index 000000000..cc918f636
--- /dev/null
+++ b/changelog.d/1392.md
@@ -0,0 +1,5 @@
+### Fixed
+
+- The first-turn guide's "Moving a unit" step centres the camera on the unit it selects, 40 km out at most, so the unit
+ and its lit destination hexes are on screen and clear of the info panel. Before, its unit (the Negev Brigade at Nir
+ Am) was off screen at the start's camera, and Move seemed to do nothing (#1392).
diff --git a/unity/Assets/Scripts/UI/FirstTurnGuidePresenter.cs b/unity/Assets/Scripts/UI/FirstTurnGuidePresenter.cs
index e91da5f26..c429d9e9f 100644
--- a/unity/Assets/Scripts/UI/FirstTurnGuidePresenter.cs
+++ b/unity/Assets/Scripts/UI/FirstTurnGuidePresenter.cs
@@ -37,6 +37,10 @@ namespace Statecraft.Game.UI
public static readonly string[] Steps = { "attention", "city", "training", "move", "event", "objectives" };
/// <summary>The event card's step (the card shows on it and is hidden on the others).</summary>
public const int EventStep = 4;
+ /// <summary>The camera's farthest distance on the move step, which centres it on <see cref="UnitToShow"/>'s hex (GameRoot;
+ /// a nearer camera stays as near). At the start's 90 km, the view's fit to the map's edge (CameraController.Settle) left
+ /// a unit near the edge, the Negev Brigade at Nir Am, under the info panel (#1392).</summary>
+ public const float MoveStepDistanceM = 40000f;
/// <summary>The ring's gap round its target, in panel px. Under Attention (step 1) End Turn's border is kept clear of
/// it by Statecraft.uss (.guide-open #attention), not by this gap: the two sit 3 px apart in the bar.</summary>
const float RingGap = 4f;
diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.cs
index 771af5174..70c0980dc 100644
--- a/unity/Assets/Scripts/UI/GameRoot.cs
+++ b/unity/Assets/Scripts/UI/GameRoot.cs
@@ -470,7 +470,7 @@ namespace Statecraft.Game.UI
// 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; step 4 shows a unit
- // that can move, its ring and its card, as a click on it would (OnHexClicked).
+ // that can move, its ring and its card, as a click on it would (OnHexClicked), and centres the camera on its hex.
Action showCity = () =>
{
if (FirstTurnGuidePresenter.CityHex(bridge.Content, bridge.State) is not (int q, int r)) return;
@@ -480,7 +480,15 @@ namespace Statecraft.Game.UI
{
if (FirstTurnGuidePresenter.UnitToShow(bridge.Content, bridge.State, unitLayer.Tokens.Select(t => t.Token.Unit)) is not string id) return;
unitLayer.Select(id);
- if (unitLayer.Selected != null) { map.ClearSelection(); info.ShowUnit(); }
+ if (unitLayer.Selected != null)
+ {
+ map.ClearSelection(); info.ShowUnit();
+ var token = unitLayer.Tokens.First(t => t.Token.Unit.Id == id);
+ var hex = bridge.Content.HexAt(token.Q, token.R)!;
+ camRig.LookAt = map.Frame.ToWorld(hex.Lon, hex.Lat, 0);
+ camRig.Distance = Mathf.Min(camRig.Distance, FirstTurnGuidePresenter.MoveStepDistanceM);
+ cameraController.Settle(); SyncMinimap(); labels?.Refresh();
+ }
};
// When it closes, the guide 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).
diff --git a/unity/Assets/Tests/EditMode/FirstTurnGuideTests.cs b/unity/Assets/Tests/EditMode/FirstTurnGuideTests.cs
index 73aaa48a1..e100f03c1 100644
--- a/unity/Assets/Tests/EditMode/FirstTurnGuideTests.cs
+++ b/unity/Assets/Tests/EditMode/FirstTurnGuideTests.cs
@@ -379,6 +379,80 @@ public class FirstTurnGuideTests
Assert.IsNull(info.Selected, "and no hex");
}
+ /// <summary>Issue #1392: the move step brings UnitToShow's hex into the map view, clear of the info panel and the guide's
+ /// card, with at least one of Movement.Reachable's lit destinations visible too. The real scene, camera projection and HUD
+ /// layout are used at the guide's supported desktop, itch embed and phone sizes, in both UI directions.</summary>
+ [UnityTest]
+ public IEnumerator TheMoveStepShowsTheUnitAndAReachableHexOnTheMap()
+ {
+ var problems = new List<string>();
+ foreach (var hebrew in new[] { false, true })
+ foreach (var (w, h) in new[] { (1920, 1080), (1280, 720), (390, 844) })
+ {
+ // The scene first: opening it in Single mode destroys textures made before it.
+ var game = OpenScene(new SaveStore(TempDir()), new SettingsStore(TempDir()));
+ var rt = new RenderTexture(w, h, 0);
+ var camRt = new RenderTexture(w, h, 24);
+ var ps = Object.Instantiate(AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel));
+ ps.targetTexture = rt;
+ var camera = Camera.main;
+ try
+ {
+ game.Language = hebrew ? UiLanguage.Hebrew : UiLanguage.English;
+ Object.FindFirstObjectByType<UIDocument>().panelSettings = ps;
+ camera.targetTexture = camRt;
+ game.Begin(Inputs, 0, startScreen: true);
+ UiTestKit.Press(Ui.Q<Button>("start-new-game"));
+ var guide = game.Guide!; var bridge = game.Bridge!; var units = game.Units!;
+ var map = Object.FindFirstObjectByType<MapScene>();
+ var move = Array.IndexOf(FirstTurnGuidePresenter.Steps, "move");
+ for (int step = 0; step < move; step++) UiTestKit.Press(Ui.Q<Button>("guide-next"));
+ Assert.AreEqual(move, guide.Step, "precondition: the guide is on its move step");
+ for (int frame = 0; frame < 5; frame++) yield return null;
+
+ var id = FirstTurnGuidePresenter.UnitToShow(bridge.Content, bridge.State, units.Tokens.Select(t => t.Token.Unit));
+ Assert.IsNotNull(id, "precondition: a drawn unit can move");
+ var token = units.Tokens.Single(t => t.Token.Unit.Id == id);
+ var simUnit = UnitCard.SimUnit(bridge.Content, bridge.State, token.Token.Unit);
+ Assert.IsNotNull(simUnit, "precondition: the guide's token has a sim unit");
+ var reachable = Movement.Reachable(bridge.Content, bridge.State, simUnit!.Value).Keys.ToList();
+ Assert.IsNotEmpty(reachable, "precondition: the guide's unit has a destination");
+ UiTestKit.Press(Ui.Q<Button>("info-move"));
+ Assert.IsTrue(map.Terrain.transform.Find(MapScene.ReachableName)?.GetComponent<MeshRenderer>().enabled == true,
+ "precondition: Move lit the reachable hexes");
+
+ var root = Ui;
+ var info = root.Q("info-panel").worldBound;
+ var card = root.Q("guide-panel").worldBound; // the guide's own card is opaque too
+ string at = $"{(hebrew ? "he" : "en")} {w}x{h}";
+ (bool visible, bool clear, Vector3 viewport, Vector2 panel) Project(int q, int r)
+ {
+ var hex = bridge.Content.HexAt(q, r)!;
+ var ground = map.Frame.ToWorld(hex.Lon, hex.Lat, 0);
+ ground.y = map.Terrain.SampleHeight(ground) + map.Terrain.transform.position.y;
+ var viewport = camera.WorldToViewportPoint(ground);
+ var panel = MapLabelsPresenter.ToPanel(viewport, camera.rect, root.panel.visualTree.layout.size, Vector2.zero);
+ return (viewport.z > 0f && viewport.x >= 0f && viewport.x <= 1f && viewport.y >= 0f && viewport.y <= 1f,
+ !info.Contains(panel) && !card.Contains(panel), viewport, panel);
+ }
+
+ var unit = Project(token.Q, token.R);
+ if (!unit.visible) problems.Add($"{at}: unit ({token.Q},{token.R}) is outside the viewport at {unit.viewport}");
+ else if (!unit.clear) problems.Add($"{at}: unit ({token.Q},{token.R}) at {unit.panel} is under the info panel {info} or the guide {card}");
+ if (!reachable.Select(p => (at: p, projection: Project(p.Q, p.R))).Any(p => p.projection.visible && p.projection.clear))
+ problems.Add($"{at}: no reachable hex is visible and clear of the info panel and the guide");
+ }
+ finally
+ {
+ camera.targetTexture = null;
+ Object.FindFirstObjectByType<UIDocument>().panelSettings = AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel);
+ Object.DestroyImmediate(ps); rt.Release(); Object.DestroyImmediate(rt); camRt.Release(); Object.DestroyImmediate(camRt);
+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
+ }
+ }
+ Assert.IsEmpty(problems, string.Join("\n", problems));
+ }
+
// --- Each step with what it explains (owner's report on v0.1.4) ---------------------------------------------------
/// <summary>The first card's first option, pressed as a click would.</summary>