A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
fix(map): frame the map below the top bar (playtest 1, item 3)
eyalgolan1049bee86807
diff --git a/unity/Assets/Scripts/Map/CameraRig.cs b/unity/Assets/Scripts/Map/CameraRig.csindex f718ab7d7..3d7ee771a 100644--- a/unity/Assets/Scripts/Map/CameraRig.cs+++ b/unity/Assets/Scripts/Map/CameraRig.cs@@ -11,6 +11,8 @@ namespace Statecraft.Game.Map{public const float Pitch = 50f, Fov = 35f;public Vector3 LookAt; public float Distance = 120000f; public float Yaw;+ /// <summary>Share of the screen height (0..1) the UI covers at the top. The view is shifted so LookAt sits in the+ /// middle of the map area below it (an off-centre frustum: picking rays and WorldToScreenPoint follow it).</summary>public float TopInset;DepthOfField _dof;@@ -39,6 +41,20 @@ namespace Statecraft.Game.Maptransform.rotation = Quaternion.Euler(Pitch, Yaw, 0);transform.position = LookAt - transform.forward * Distance;if (_dof != null) { _dof.gaussianStart.Override(Distance * 1.05f); _dof.gaussianEnd.Override(Distance * 1.8f); }+ ApplyProjection();+ }++ /// <summary>Sets the camera's projection for <see cref="TopInset"/> only (the transform is left alone). Apply calls it+ /// every frame, so a new window aspect is picked up too.</summary>+ public void ApplyProjection()+ {+ var cam = GetComponent<Camera>();+ if (cam == null) return;+ cam.ResetProjectionMatrix(); // follows the aspect and FOV again+ if (TopInset <= 0f) return;+ // NDC y = (m11 y + m12 z) / -z, so m12 = s moves every point down by s: the centre of the area below the bar+ // (NDC y from -1 to 1 - 2 TopInset) is at -TopInset.+ var p = cam.projectionMatrix; p[1, 2] = Mathf.Clamp(TopInset, 0f, 0.5f); cam.projectionMatrix = p;}}}diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex 89d8654a5..b70f9597c 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -148,6 +148,7 @@ namespace Statecraft.Game.UIAction<int, int> onHex = info.Show;pointer.HexClicked += onHex;var camRig = rig = cameraController.GetComponent<CameraRig>();+ Own(new TopBarInset(root, camRig)); // the map is framed below the top barvar mini = minimap = Own(new MinimapPresenter(root, map.Hexes));mini.Clicked += (lon, lat) => { camRig.LookAt = map.Frame.ToWorld(lon, lat, 0); camRig.Apply(); SyncMinimap(); };Action onChanged = RenderPlacementsIfChanged;diff --git a/unity/Assets/Scripts/UI/TopBarInset.cs b/unity/Assets/Scripts/UI/TopBarInset.csindex e4ee73a11..f07530373 100644--- a/unity/Assets/Scripts/UI/TopBarInset.cs+++ b/unity/Assets/Scripts/UI/TopBarInset.cs@@ -1,12 +1,45 @@#nullable enableusing Statecraft.Game.Map;+using UnityEngine;using UnityEngine.UIElements;namespace Statecraft.Game.UI{+ /// <summary>Tells the camera what share of the window the top bar covers (CameraRig.TopInset), so the map is framed in+ /// the area below the bar and labels near the top of the view are not hidden under it (playtest 1, item 3). Follows+ /// the bar and the window as they change size; disposing gives the camera the whole screen back.</summary>public sealed class TopBarInset : System.IDisposable{- public TopBarInset(VisualElement root, CameraRig rig) { }- public void Dispose() { }+ readonly VisualElement root, bar; readonly CameraRig rig;++ public TopBarInset(VisualElement root, CameraRig rig)+ {+ this.root = root; this.rig = rig;+ bar = root.Q<VisualElement>("top-bar");+ bar.RegisterCallback<GeometryChangedEvent>(OnGeometry);+ root.RegisterCallback<GeometryChangedEvent>(OnGeometry);+ Update();+ }++ void OnGeometry(GeometryChangedEvent e) => Update();++ /// <summary>Sets the inset from the current layout (0 until the panel has one).</summary>+ public void Update()+ {+ if (rig == null) return; // the camera went first (scene teardown)+ var window = root.panel?.visualTree.worldBound.height ?? float.NaN;+ var height = bar.worldBound.height;+ rig.TopInset = window > 0 && !float.IsNaN(height) && height > 0 ? Mathf.Clamp01(height / window) : 0f;+ rig.ApplyProjection();+ }++ public void Dispose()+ {+ bar.UnregisterCallback<GeometryChangedEvent>(OnGeometry);+ root.UnregisterCallback<GeometryChangedEvent>(OnGeometry);+ if (rig == null) return;+ rig.TopInset = 0f;+ rig.ApplyProjection();+ }}}diff --git a/unity/Assets/Tests/EditMode/GameSceneTests.cs b/unity/Assets/Tests/EditMode/GameSceneTests.csindex 2febf09cf..e844e256d 100644--- a/unity/Assets/Tests/EditMode/GameSceneTests.cs+++ b/unity/Assets/Tests/EditMode/GameSceneTests.cs@@ -182,7 +182,7 @@ public class GameSceneTestsAssert.AreEqual(ground.z, b.center.z, 100f);}- /// <summary>Points the main camera straight down at Tel Aviv and returns the screen centre.</summary>+ /// <summary>Points the main camera straight down at Tel Aviv and returns Tel Aviv's screen position.</summary>static Vector2 AimAtTelAviv(){var map = Object.FindFirstObjectByType<MapScene>();@@ -193,7 +193,9 @@ public class GameSceneTestsvar cam = Camera.main!;cam.transform.position = new Vector3(ground.x, 50_000f, ground.z);cam.transform.rotation = Quaternion.Euler(90, 0, 0);- return new Vector2(cam.pixelWidth / 2f, cam.pixelHeight / 2f);+ Ui.panel?.Pick(Vector2.zero); // settle the layout first: the top bar's height sets the camera's inset (TopBarInset)+ var p = cam.WorldToScreenPoint(new Vector3(ground.x, map.Terrain.SampleHeight(ground), ground.z));+ return new Vector2(p.x, p.y); // projected, not the screen centre: the frame below the top bar is off-centre (TopBarInset)}// One label each presenter writes on every change: HUD, toast, info panel, Why, Budget, Defence, Cabinet, event card