A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Unity: lit hexes get a translucent edge fill over the models, and a hover marker during Move/Attack picks (Fixes #2201) (#2213)
Berid8972693f4df
diff --git a/changelog.d/2201.md b/changelog.d/2201.mdnew file mode 100644index 000000000..05eec1b1e--- /dev/null+++ b/changelog.d/2201.md@@ -0,0 +1,5 @@+### Changed++- Lit hexes are easier to see over towns and trees: each one now has a translucent ivory tint along its edge, fading+ towards the middle, drawn over the buildings and trees. While a Move or Attack pick is open, the hex under the pointer+ has a gold band with navy edges (#2201).diff --git a/unity/Assets/Resources/Map/HexHover.mat b/unity/Assets/Resources/Map/HexHover.matnew file mode 100644index 000000000..388bc1469--- /dev/null+++ b/unity/Assets/Resources/Map/HexHover.mat@@ -0,0 +1,30 @@+%YAML 1.1+%TAG !u! tag:unity3d.com,2011:+--- !u!21 &2100000+Material:+ serializedVersion: 8+ m_ObjectHideFlags: 0+ m_CorrespondingSourceObject: {fileID: 0}+ m_PrefabInstance: {fileID: 0}+ m_PrefabAsset: {fileID: 0}+ m_Name: HexHover+ m_Shader: {fileID: 4800000, guid: baee1e43fd4846b996674af906b2e1c5, type: 3}+ m_Parent: {fileID: 0}+ m_ModifiedSerializedProperties: 0+ m_ValidKeywords: []+ m_InvalidKeywords: []+ m_LightmapFlags: 4+ m_EnableInstancingVariants: 0+ m_DoubleSidedGI: 0+ m_CustomRenderQueue: 3045+ stringTagMap: {}+ disabledShaderPasses: []+ m_LockedProperties:+ m_SavedProperties:+ serializedVersion: 3+ m_TexEnvs: []+ m_Ints: []+ m_Floats: []+ m_Colors: []+ m_BuildTextureStacks: []+ m_AllowLocking: 1diff --git a/unity/Assets/Resources/Map/HexHover.mat.meta b/unity/Assets/Resources/Map/HexHover.mat.metanew file mode 100644index 000000000..8555d8446--- /dev/null+++ b/unity/Assets/Resources/Map/HexHover.mat.meta@@ -0,0 +1,8 @@+fileFormatVersion: 2+guid: a7d44e5082aa4de8a4fca51cd358a544+NativeFormatImporter:+ externalObjects: {}+ mainObjectFileID: 2100000+ userData:+ assetBundleName:+ assetBundleVariant:diff --git a/unity/Assets/Resources/Map/HexOverlay.mat b/unity/Assets/Resources/Map/HexOverlay.matnew file mode 100644index 000000000..be8fff51a--- /dev/null+++ b/unity/Assets/Resources/Map/HexOverlay.mat@@ -0,0 +1,30 @@+%YAML 1.1+%TAG !u! tag:unity3d.com,2011:+--- !u!21 &2100000+Material:+ serializedVersion: 8+ m_ObjectHideFlags: 0+ m_CorrespondingSourceObject: {fileID: 0}+ m_PrefabInstance: {fileID: 0}+ m_PrefabAsset: {fileID: 0}+ m_Name: HexOverlay+ m_Shader: {fileID: 4800000, guid: baee1e43fd4846b996674af906b2e1c5, type: 3}+ m_Parent: {fileID: 0}+ m_ModifiedSerializedProperties: 0+ m_ValidKeywords: []+ m_InvalidKeywords: []+ m_LightmapFlags: 4+ m_EnableInstancingVariants: 0+ m_DoubleSidedGI: 0+ m_CustomRenderQueue: -1+ stringTagMap: {}+ disabledShaderPasses: []+ m_LockedProperties:+ m_SavedProperties:+ serializedVersion: 3+ m_TexEnvs: []+ m_Ints: []+ m_Floats: []+ m_Colors: []+ m_BuildTextureStacks: []+ m_AllowLocking: 1diff --git a/unity/Assets/Resources/Map/HexOverlay.mat.meta b/unity/Assets/Resources/Map/HexOverlay.mat.metanew file mode 100644index 000000000..1a5262c24--- /dev/null+++ b/unity/Assets/Resources/Map/HexOverlay.mat.meta@@ -0,0 +1,8 @@+fileFormatVersion: 2+guid: 664120026cff45b4bf78a1b33b623e3e+NativeFormatImporter:+ externalObjects: {}+ mainObjectFileID: 2100000+ userData:+ assetBundleName:+ assetBundleVariant:diff --git a/unity/Assets/Scripts/Map/MapScene.cs b/unity/Assets/Scripts/Map/MapScene.csindex bcc94308f..a3c7f9d4f 100644--- a/unity/Assets/Scripts/Map/MapScene.cs+++ b/unity/Assets/Scripts/Map/MapScene.cs@@ -169,7 +169,8 @@ namespace Statecraft.Game.Map/// <summary>Outlines every hex in <paramref name="hexes"/> (Movement.Reachable's, from InfoPanelPresenter) with a thin/// band in one mesh, drawn and draped as <see cref="Select"/>'s outline and with its material; nothing to light (none,/// or only hexes off the map) hides it. Display only: which hexes are lit is the sim's answer, never computed here.- /// A unit has at most 5 movement points (unit_types.yaml), so the mesh stays far under 16-bit indices.</summary>+ /// A unit has at most 5 movement points (unit_types.yaml), so the mesh stays far under 16-bit indices. Each lit hex also+ /// gets a translucent fill over the models (<see cref="ReachableFillName"/>, #2201).</summary>public void ShowReachable(IEnumerable<(int q, int r)> hexes){if (Terrain == null || Hexes == null) return;@@ -190,6 +191,8 @@ namespace Statecraft.Game.Mapfloat size = Hexes.hex_size_km * 1000f;int n = MapBuilder.RingVertices;var verts = new List<Vector3>(); var tris = new List<int>();+ var fill = new List<Vector3>(); var fillColours = new List<Color>(); var fillTris = new List<int>(); var inner = new List<Vector3>(n);+ var clear = FillColour.linear; clear.a = 0f;var ring = new List<Vector3>(2 * n); var middle = new List<Vector3>(n);foreach (var at in hexes){@@ -212,12 +215,141 @@ namespace Statecraft.Game.Mapint a = b0 + j, b = b0 + (j + 1) % n, ai = b0 + n + j, bi = b0 + n + (j + 1) % n;tris.AddRange(new[] { a, ai, b, b, ai, bi }); // the shader draws both faces (Cull Off)}+ // The fill (#2201): a strip from the band's outer ring, in the fill's colour, to a ring FillDepth further in,+ // clear, so the tint fades towards the middle of the hex.+ inner.Clear();+ MapBuilder.DrapedRing(Frame, Terrain.terrainData, centre, size * (1f - FillDepth), SelectionClearanceM, inner);+ int f0 = fill.Count;+ for (int j = 0; j < n; j++) { fill.Add(ring[j]); fillColours.Add(FillColour.linear); }+ for (int j = 0; j < n; j++) { fill.Add(inner[j]); fillColours.Add(clear); }+ for (int j = 0; j < n; j++)+ {+ int a = f0 + j, b = f0 + (j + 1) % n, ai = f0 + n + j, bi = f0 + n + (j + 1) % n;+ fillTris.AddRange(new[] { a, ai, b, b, ai, bi });+ }}var m = go.GetComponent<MeshFilter>().sharedMesh;m.Clear();m.SetVertices(verts); m.SetTriangles(tris, 0);m.RecalculateBounds();go.GetComponent<MeshRenderer>().enabled = verts.Count > 0;+ SetOverlayMesh(OverlayChild(ReachableFillName), fill, fillColours, fillTris, fadeClose: true);+ }++ /// <summary>The lit hexes' translucent fill (#2201), beside <see cref="ReachableName"/> under the terrain.</summary>+ public const string ReachableFillName = "ReachableFill";+ /// <summary>The hover marker on the hex under the pointer while a pick is open (#2201), under the terrain.</summary>+ public const string HoverName = "HexHover";+ /// <summary>The fill's material (Statecraft/HexOverlay: vertex colours, drawn over the models), in Resources so a player+ /// keeps it and its shader.</summary>+ public const string OverlayMaterialResource = "Map/HexOverlay";+ /// <summary>The hover marker's material: the same shader, queued at Transparent+45, between the fill (+40) and the move+ /// arrow (+50, #2184), so the band draws over the fill and under the arrow. A queue, not a sortingOrder: URP sorts by order+ /// in layer before the queue, so an order of 1 would draw the band over the arrow's tip on the hovered hex.</summary>+ public const string HoverMaterialResource = "Map/HexHover";+ /// <summary>The lit hexes' fill at their edge: the selection's ivory at 40%, so a lit hex reads over a town or a wood and the+ /// ground still shows through.</summary>+ public static readonly Color FillColour = new Color(SelectionColour.r, SelectionColour.g, SelectionColour.b, 0.4f);+ /// <summary>How far in from the edge the fill fades to clear, as a fraction of the hex circumradius, so the middle of a lit+ /// hex is untinted. The shader also thins the fill as the camera comes close (the closest zoom, 6 km, shows about one+ /// hex, and a full tint washed the whole view).</summary>+ public const float FillDepth = 0.45f;+ /// <summary>The hover band's core and edges: the move arrow's gold and navy ink (#2134), so the band reads on pale+ /// towns and dry grass (the navy) and on dark woods (the gold).</summary>+ public static readonly Color HoverColour = new Color(1f, 0.82f, 0.25f), HoverInk = new Color(0.06f, 0.08f, 0.14f, 0.9f);++ /// <summary>A child of the terrain drawn with the overlay material, made on first use (a rebuild destroys it).</summary>+ GameObject OverlayChild(string name, string material = OverlayMaterialResource)+ {+ var found = Terrain.transform.Find(name);+ if (found != null) return found.gameObject;+ var go = new GameObject(name);+ go.transform.SetParent(Terrain.transform, false);+ go.AddComponent<MeshFilter>().sharedMesh = Terrain.GetComponent<MapRuntimeAssets>().Own(new Mesh { name = name });+ var renderer = go.AddComponent<MeshRenderer>();+ renderer.sharedMaterial = Resources.Load<Material>(material);+ renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;+ return go;+ }++ /// <summary><paramref name="fadeClose"/>: uv.x 1, so Statecraft/HexOverlay fades the mesh as the camera comes close.</summary>+ static void SetOverlayMesh(GameObject go, List<Vector3> verts, List<Color> colours, List<int> tris, bool fadeClose)+ {+ var m = go.GetComponent<MeshFilter>().sharedMesh;+ m.Clear();+ var uvs = new List<Vector2>(verts.Count);+ for (int i = 0; i < verts.Count; i++) uvs.Add(new Vector2(fadeClose ? 1f : 0f, 0f));+ m.SetVertices(verts); m.SetColors(colours); m.SetUVs(0, uvs); m.SetTriangles(tris, 0);+ m.RecalculateBounds();+ go.GetComponent<MeshRenderer>().enabled = verts.Count > 0;+ }++ /// <summary>Within this camera distance the hover band thins to the lit-hex outline's <see cref="ReachableWidth"/>: the+ /// overlay shader's CloseM (Statecraft/HexOverlay), inside which the fill fades too. At the closest zoom (6 km) one hex+ /// fills the view and the selection's 0.12 band hid the buildings on it (owner ruling, #2213).</summary>+ public const float HoverCloseM = 8000f;++ MeshRenderer hoverRenderer;+ (int q, int r)? hovered;+ float hoverWidth;+ // Kept between calls: the pointer moves to a new hex many times a second, and fresh lists each time made steady garbage.+ readonly List<Vector3> hoverVerts = new List<Vector3>();+ readonly List<Color> hoverColours = new List<Color>();+ readonly List<int> hoverTris = new List<int>();+ readonly List<Vector3>[] hoverRings = { new List<Vector3>(), new List<Vector3>(), new List<Vector3>(), new List<Vector3>() };+ // The strip edges as shares of the band: a navy edge either side, 0.2 of the band each (about 2 px at the opening zoom,+ // not a heavy bar at 6 km), the gold between.+ static readonly float[] HoverShares = { 0f, 0.2f, 0.8f, 1f };++ /// <summary>Marks hex (q, r) with a band of the selection's width in three strips, navy edge, gold core, navy edge,+ /// draped as <see cref="Select"/>'s, thinned to the lit-hex outline's width with the camera within <see cref="HoverCloseM"/>+ /// (<paramref name="cameraDistanceM"/>, the camera rig's distance); null or a hex off the map hides it. GameRoot asks every+ /// frame: the same hex at the same width again returns at once.</summary>+ public void ShowHover((int q, int r)? hex, float cameraDistanceM = float.PositiveInfinity)+ {+ if (Terrain == null || Hexes == null) return;+ float width = cameraDistanceM <= HoverCloseM ? ReachableWidth : SelectionWidth;+ if (hoverRenderer != null && hovered == hex && hoverWidth == width) return;+ hovered = hex; hoverWidth = width;+ var go = OverlayChild(HoverName, HoverMaterialResource);+ hoverRenderer = go.GetComponent<MeshRenderer>();+ HexJson at = null;+ if (hex is (int q, int r)) foreach (var h in Hexes.hexes) if (h.q == q && h.r == r) { at = h; break; }+ var verts = hoverVerts; var colours = hoverColours; var tris = hoverTris;+ verts.Clear(); colours.Clear(); tris.Clear();+ if (at != null)+ {+ var c = Frame.ToWorld(at.lon, at.lat, 0);+ var centre = new Vector2(c.x, c.z);+ float size = Hexes.hex_size_km * 1000f;+ int n = MapBuilder.RingVertices;+ var shares = HoverShares;+ var rings = hoverRings;+ for (int i = 0; i < shares.Length; i++)+ {+ rings[i].Clear();+ MapBuilder.DrapedRing(Frame, Terrain.terrainData, centre, size * (1f - width * shares[i]), SelectionClearanceM, rings[i]);+ }+ for (int j = 0; j < n; j++) // each index at the highest of its rings, as Select's band+ {+ float y = float.MinValue;+ foreach (var ring in rings) y = Mathf.Max(y, ring[j].y);+ foreach (var ring in rings) ring[j] = new Vector3(ring[j].x, y, ring[j].z);+ }+ for (int i = 0; i < 3; i++)+ {+ var colour = (i == 1 ? HoverColour : HoverInk).linear;+ int b0 = verts.Count;+ verts.AddRange(rings[i]); verts.AddRange(rings[i + 1]);+ for (int j = 0; j < 2 * n; j++) colours.Add(colour);+ for (int j = 0; j < n; j++)+ {+ int a = b0 + j, b = b0 + (j + 1) % n, ai = b0 + n + j, bi = b0 + n + (j + 1) % n;+ tris.Add(a); tris.Add(ai); tris.Add(b); tris.Add(b); tris.Add(ai); tris.Add(bi); // the shader draws both faces (Cull Off)+ }+ }+ }+ SetOverlayMesh(go, verts, colours, tris, fadeClose: false);}/// <summary>Shows the sim's multi-turn route as thin hex bands. Each item carries its arrival turn;diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex 0053d406f..ff303d013 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -808,6 +808,13 @@ namespace Statecraft.Game.UIofferMove?.Invoke();}+ /// <summary>Marks the hex under the pointer (<paramref name="under"/>; null: off the map) only where a click would give the+ /// open Move or Attack pick's order (PickTakes), else nothing (#2201: a player could not tell which hex a click would+ /// take). A hex the pick does not take, such as water, stays unmarked: a click there ends the pick. The camera distance+ /// thins the band up close (MapScene.HoverCloseM).</summary>+ internal static void MarkHover(MapScene map, InfoPanelPresenter? info, (int q, int r)? under, float cameraDistanceM = float.PositiveInfinity) =>+ map.ShowHover(under is (int q, int r) && info != null && info.PickTakesHovered(q, r) ? under : null, cameraDistanceM);+/// <summary>A right click on the map (MapPointer.HexOrdered; owner, 25 Oct 2026, "Civ: select, then click"): while the/// shown unit's pick takes (q, r), the order a left click there gives (PickTarget), even on another unit's hex./// Otherwise nothing: no unit shown, a hex it cannot reach, or a screen over the panel (#210).</summary>@@ -1058,8 +1065,10 @@ namespace Statecraft.Game.UIvar hover = MapLabelsPresenter.HoverPosition(UnityEngine.InputSystem.Pointer.current);labels.Hover(hover);HoverCity(hover);- if (hover is Vector2 at && pointer.HexAt(at) is (int q, int r)) info?.ShowRouteTo(q, r);+ var under = hover is Vector2 at ? pointer.HexAt(at) : null;+ if (under is (int q, int r)) info?.ShowRouteTo(q, r);else if (UnityEngine.InputSystem.Pointer.current is UnityEngine.InputSystem.Mouse) info?.HideRoute();+ MarkHover(map, info, under, rig != null ? rig.Distance : float.PositiveInfinity);var touch = UnityEngine.InputSystem.Touchscreen.current;if (touch != null && touch.primaryTouch.press.wasPressedThisFrame) labels.Tap(touch.primaryTouch.position.ReadValue());}diff --git a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs b/unity/Assets/Scripts/UI/InfoPanelPresenter.csindex 700d39311..7115c896f 100644--- a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs+++ b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs@@ -579,11 +579,29 @@ namespace Statecraft.Game.UI/// <summary>True while the open pick is a Move's (not an Attack's).</summary>public bool MovePicking => pick is { attack: false };+ /// <summary>True while a Move or an Attack pick is open (GameRoot marks the hovered hex then, #2201).</summary>+ public bool Picking => pick != null;/// <summary>True when a pick is open and PickTarget would give an order for (q, r): a lit hex, or, for Move, an unlit/// hex with a go-to route. A right click (GameRoot.OnHexOrdered) gives one only then.</summary>public bool PickTakes(int q, int r) => pick is { } p && Takes(p, q, r);+ (int q, int r, HashSet<(int q, int r)> hexes, PreviewResult now, bool takes)? hoverTakes;++ /// <summary>PickTakes for the hex under the pointer, which GameRoot.MarkHover asks every frame. PickTakes runs RouteTo, a+ /// search of the whole map, so the answer is kept and worked out again only when the hex, the pick (each pick opens with+ /// its own lit set) or the session's preview changes.</summary>+ public bool PickTakesHovered(int q, int r)+ {+ if (!(pick is { } p)) return false;+ var now = bridge.Session.Now;+ if (hoverTakes is { } m && m.q == q && m.r == r && ReferenceEquals(m.hexes, p.hexes) && ReferenceEquals(m.now, now))+ return m.takes;+ var takes = Takes(p, q, r);+ hoverTakes = (q, r, p.hexes, now, takes);+ return takes;+ }+bool Takes((int unit, HashSet<(int q, int r)> hexes, GameSession session, int turn, bool attack, (int q, int r)? touchRoute) p,int q, int r) => p.hexes.Contains((q, r)) || RouteTo(p, q, r).Count > 0; // RouteTo: PickTarget's go-to rulediff --git a/unity/Assets/Shaders/HexOverlay.shader b/unity/Assets/Shaders/HexOverlay.shadernew file mode 100644index 000000000..a0cbfb0c6--- /dev/null+++ b/unity/Assets/Shaders/HexOverlay.shader@@ -0,0 +1,43 @@+// The lit hexes' fill and the hover marker (#2201, MapScene.ShowReachable and ShowHover). Unlit; each vertex carries its+// colour (the fill's translucent ivory, the hover band's gold core and navy edges), so one shader draws both. Drawn over+// the ground, the tokens and the town and tree models (ZTest Always), as the move arrow is (#2134): a lit hex in a dense+// town or a wood was a thin outline the models stood over. Queued just under the arrow's Transparent+50, so the arrow stays+// on top of both: the fill at this shader's +40, the hover band at +45 (HexHover.mat's own queue, over the fill). No motion. A+// vertex with uv.x 1 (the fill) fades to CloseShare of its alpha as the camera comes within CloseM of it: at the closest+// zoom one hex fills the screen and the full tint washed the whole view. uv.x 0 (the hover band) keeps its strength at+// every zoom.+Shader "Statecraft/HexOverlay"+{+ SubShader+ {+ Tags { "RenderType" = "Transparent" "Queue" = "Transparent+40" "RenderPipeline" = "UniversalPipeline" "IgnoreProjector" = "True" }+ Pass+ {+ Name "Unlit"+ Tags { "LightMode" = "UniversalForward" }+ Cull Off+ ZWrite Off+ ZTest Always+ Blend SrcAlpha OneMinusSrcAlpha+ HLSLPROGRAM+ #pragma vertex Vert+ #pragma fragment Frag+ #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"+ static const float CloseM = 8000.0, FarM = 40000.0, CloseShare = 0.3;+ struct Attributes { float4 positionOS : POSITION; half4 colour : COLOR; float2 uv : TEXCOORD0; };+ struct Varyings { float4 positionCS : SV_POSITION; half4 colour : COLOR; };+ Varyings Vert(Attributes input)+ {+ Varyings o;+ float3 world = TransformObjectToWorld(input.positionOS.xyz);+ o.positionCS = TransformWorldToHClip(world);+ float far = saturate((distance(GetCameraPositionWS(), world) - CloseM) / (FarM - CloseM));+ o.colour = input.colour;+ o.colour.a *= lerp(1.0, lerp(CloseShare, 1.0, far), input.uv.x);+ return o;+ }+ half4 Frag(Varyings input) : SV_Target { return input.colour; }+ ENDHLSL+ }+ }+}diff --git a/unity/Assets/Shaders/HexOverlay.shader.meta b/unity/Assets/Shaders/HexOverlay.shader.metanew file mode 100644index 000000000..45020d3d6--- /dev/null+++ b/unity/Assets/Shaders/HexOverlay.shader.meta@@ -0,0 +1,9 @@+fileFormatVersion: 2+guid: baee1e43fd4846b996674af906b2e1c5+ShaderImporter:+ externalObjects: {}+ defaultTextures: []+ nonModifiableTextures: []+ userData:+ assetBundleName:+ assetBundleVariant:diff --git a/unity/Assets/Tests/EditMode/HexHighlightTests.cs b/unity/Assets/Tests/EditMode/HexHighlightTests.csnew file mode 100644index 000000000..cf293799e--- /dev/null+++ b/unity/Assets/Tests/EditMode/HexHighlightTests.cs@@ -0,0 +1,255 @@+#nullable enable+using System.Linq;+using NUnit.Framework;+using Statecraft.Game;+using Statecraft.Game.Map;+using Statecraft.Game.UI;+using Statecraft.Sim;+using UnityEditor;+using UnityEditor.SceneManagement;+using UnityEngine;+using UnityEngine.UIElements;++/// <summary>#2201 (a player's report, relayed by the owner on 1 Nov 2026): lit hexes were a thin ivory outline with no fill,+/// hard to see over towns and trees, and nothing marked the hex under the pointer. Now a lit hex also has a translucent fill+/// and, while a Move or Attack pick is open, the hex under the pointer has a gold band with navy edges. Both are drawn over the+/// models (Statecraft/HexOverlay, ZTest Always).</summary>+public class HexHighlightTests+{+ static readonly Content C = ContentLoader.Load(Paths.Content);++ static MapScene BuildMap()+ {+ EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Single);+ var map = new GameObject("MapScene").AddComponent<MapScene>();+ map.Configure(Load("Terrain"), Load("SettlementMarker"), Load("HexSelection"), Load("Sea"), Load("MapFrame"));+ map.Build();+ return map;+ }++ static Material Load(string name) => AssetDatabase.LoadAssetAtPath<Material>($"Assets/Materials/{name}.mat");++ static bool Near(Color a, Color b) => Mathf.Abs(a.r - b.r) < 0.01f && Mathf.Abs(a.g - b.g) < 0.01f+ && Mathf.Abs(a.b - b.b) < 0.01f && Mathf.Abs(a.a - b.a) < 0.01f; // vertex colours come back as 8-bit++ static bool Shows(MapScene map, string name) => map.Terrain.transform.Find(name)?.GetComponent<MeshRenderer>().enabled == true;++ /// <summary>Each lit hex gets a fill in the selection's ivory, drawn with the overlay material: a strip from the hex's edge,+ /// translucent so the ground and the models read through it, to a ring FillDepth further in, clear, so the middle of the+ /// hex stays clear at the closest zoom. The outline band stays as before. Nothing to+ /// light (none, or only hexes off the map) hides the fill with the band.</summary>+ [Test]+ public void LitHexesAreFilledWithATranslucentIvory()+ {+ var map = BuildMap();+ try+ {+ var hexes = C.Hexes.Where(h => h.Land).Take(3).Select(h => (h.Q, h.R)).ToList();+ map.ShowReachable(hexes);+ var fill = map.Terrain.transform.Find(MapScene.ReachableFillName);+ Assert.IsNotNull(fill, "the lit hexes have a fill");+ Assert.IsTrue(fill.GetComponent<MeshRenderer>().enabled);+ Assert.AreEqual(Resources.Load<Material>(MapScene.OverlayMaterialResource), fill.GetComponent<MeshRenderer>().sharedMaterial);+ var mesh = fill.GetComponent<MeshFilter>().sharedMesh;+ int n = MapBuilder.RingVertices;+ Assert.AreEqual(3 * 2 * n, mesh.vertexCount, "one strip of two rings per hex");+ var clear = MapScene.FillColour.linear; clear.a = 0f;+ var colours = mesh.colors;+ for (int i = 0; i < colours.Length; i++)+ Assert.IsTrue(Near(colours[i], i % (2 * n) < n ? MapScene.FillColour.linear : clear), $"vertex {i}: the edge tinted, the inner ring clear");+ var uvs = new System.Collections.Generic.List<Vector2>(); mesh.GetUVs(0, uvs);+ Assert.IsTrue(uvs.Count == mesh.vertexCount && uvs.All(uv => uv.x == 1f), "the fill fades as the camera comes close (uv.x 1)");+ Assert.AreEqual(MapScene.SelectionColour, new Color(MapScene.FillColour.r, MapScene.FillColour.g, MapScene.FillColour.b), "the selection's ivory");+ Assert.That(MapScene.FillColour.a, Is.InRange(0.15f, 0.5f), "translucent: the ground reads through");+ Assert.AreEqual(3 * 2 * MapBuilder.RingVertices, map.Terrain.transform.Find(MapScene.ReachableName).GetComponent<MeshFilter>().sharedMesh.vertexCount,+ "the outline band is unchanged");+ map.ShowReachable(new[] { (9999, 9999) });+ Assert.IsFalse(Shows(map, MapScene.ReachableFillName), "off the map: nothing to fill");+ map.ShowReachable(hexes);+ map.ShowReachable(new (int, int)[0]);+ Assert.IsFalse(Shows(map, MapScene.ReachableFillName));+ }+ finally { Object.DestroyImmediate(map.gameObject); }+ }++ /// <summary>ShowHover marks one hex with a band in three strips (navy edge, gold core, navy edge) centred on it, follows the+ /// hex it is given, hides with none or a hex off the map, and asking again for the same hex allocates nothing (GameRoot+ /// asks every frame).</summary>+ [Test]+ public void TheHoverMarkerFollowsItsHexAndHides()+ {+ var map = BuildMap();+ try+ {+ var land = C.Hexes.Where(h => h.Land).ToList();+ var a = land[land.Count / 2]; var b = land[land.Count / 2 + 40]; // inland: a ring at the map's edge is clamped to it+ map.ShowHover((a.Q, a.R));+ var hover = map.Terrain.transform.Find(MapScene.HoverName);+ Assert.IsNotNull(hover, "the hovered hex is marked");+ var renderer = hover.GetComponent<MeshRenderer>();+ Assert.IsTrue(renderer.enabled);+ Assert.AreEqual(Resources.Load<Material>(MapScene.HoverMaterialResource), renderer.sharedMaterial);+ var mesh = hover.GetComponent<MeshFilter>().sharedMesh;+ Assert.AreEqual(3 * 2 * MapBuilder.RingVertices, mesh.vertexCount, "three strips of two rings");+ int n = MapBuilder.RingVertices;+ var colours = mesh.colors;+ for (int i = 0; i < colours.Length; i++) // strip k is vertices 2kn..2(k+1)n-1: navy, gold, navy from the edge in+ Assert.IsTrue(Near(colours[i], i / (2 * n) == 1 ? MapScene.HoverColour.linear : MapScene.HoverInk.linear),+ $"vertex {i}: navy outer strip, gold core, navy inner strip");+ var uvs = new System.Collections.Generic.List<Vector2>(); mesh.GetUVs(0, uvs);+ Assert.IsTrue(uvs.All(uv => uv.x == 0f), "the hover band keeps its strength at every zoom (uv.x 0)");+ Vector2 At(HexJson h) { var w = map.Frame.ToWorld(h.lon, h.lat, 0); return new Vector2(w.x, w.z); }+ HexJson Json(MapHex h) => map.Hexes.hexes.Single(j => j.q == h.Q && j.r == h.R);+ float size = map.Hexes.hex_size_km * 1000f;+ Vector2 Centre() => new Vector2(renderer.bounds.center.x, renderer.bounds.center.z);+ Assert.Less(Vector2.Distance(Centre(), At(Json(a))), 0.1f * size, "centred on the hex");+ map.ShowHover((b.Q, b.R));+ Assert.Less(Vector2.Distance(Centre(), At(Json(b))), 0.1f * size, "follows the hex it is given");+ map.ShowHover((b.Q, b.R));+ long before = System.GC.GetAllocatedBytesForCurrentThread();+ for (int i = 0; i < 100; i++) map.ShowHover((b.Q, b.R));+ Assert.AreEqual(0, System.GC.GetAllocatedBytesForCurrentThread() - before, "the same hex again allocates nothing");+ map.ShowHover(null);+ Assert.IsFalse(renderer.enabled, "none: hidden");+ map.ShowHover((a.Q, a.R));+ map.ShowHover((9999, 9999));+ Assert.IsFalse(renderer.enabled, "off the map: hidden");+ }+ finally { Object.DestroyImmediate(map.gameObject); }+ }++ /// <summary>The hover band is the lit-hex outline's 0.06 of the radius with the camera within the overlay's close distance+ /// (the 6 km zoom shows about one hex, and the 0.12 band hid the buildings there), and the selection's 0.12 farther out.+ /// Measured on the mesh: the inner ring's distance from the hex centre against the outer ring's, vertex by vertex.</summary>+ [Test]+ public void TheHoverBandThinsUpClose()+ {+ var map = BuildMap();+ try+ {+ var land = C.Hexes.Where(h => h.Land).ToList();+ var a = land[land.Count / 2];+ var json = map.Hexes.hexes.Single(j => j.q == a.Q && j.r == a.R);+ var w = map.Frame.ToWorld(json.lon, json.lat, 0);+ var centre = new Vector2(w.x, w.z);+ int n = MapBuilder.RingVertices;+ float Width()+ {+ var v = map.Terrain.transform.Find(MapScene.HoverName).GetComponent<MeshFilter>().sharedMesh.vertices;+ float most = 0f;+ for (int j = 0; j < n; j++) // vertex j is the outer ring, 5n + j the innermost (strip 2's inner ring)+ {+ float outer = Vector2.Distance(new Vector2(v[j].x, v[j].z), centre);+ float inner = Vector2.Distance(new Vector2(v[5 * n + j].x, v[5 * n + j].z), centre);+ most = Mathf.Max(most, 1f - inner / outer);+ }+ return most;+ }+ map.ShowHover((a.Q, a.R), CameraController.MinDistance);+ Assert.AreEqual(0.06f, Width(), 0.003f, "the closest zoom (6 km): the lit-hex outline's width");+ Assert.AreEqual(MapScene.ReachableWidth, 0.06f, 1e-6f);+ map.ShowHover((a.Q, a.R), 20000f);+ Assert.AreEqual(0.12f, Width(), 0.003f, "farther out: the selection's width");+ map.ShowHover((a.Q, a.R), MapScene.HoverCloseM);+ Assert.AreEqual(0.06f, Width(), 0.003f, "thin up to the overlay's close distance");+ map.ShowHover((a.Q, a.R), MapScene.HoverCloseM + 1f);+ Assert.AreEqual(0.12f, Width(), 0.003f, "just past it: the selection's width");+ Assert.AreEqual(8000f, MapScene.HoverCloseM, "Statecraft/HexOverlay's CloseM, where the fill fades");+ map.ShowHover((a.Q, a.R), CameraController.MinDistance);+ Assert.AreEqual(0.06f, Width(), 0.003f, "the same hex rebuilds when the camera comes close again");+ map.ShowHover((a.Q, a.R));+ Assert.AreEqual(0.12f, Width(), 0.003f, "no camera distance: the far width");+ }+ finally { Object.DestroyImmediate(map.gameObject); }+ }++ /// <summary>The overlay shader compiles for WebGL 2, and its material draws in the transparent queue just under the move+ /// arrow's (Transparent+50, #2134), so an arrow is never covered by a fill or the hover band. Its pass ignores depth (ZTest+ /// Always): the fix for #2201 rests on that line, with ZTest LEqual the towns and trees stand over the fill and the hover+ /// band again. The pass state is fixed in the source, not a material property, so the test reads the source.</summary>+ [Test]+ public void TheOverlayRunsOnWebGL2UnderTheMoveArrow()+ {+ var mat = Resources.Load<Material>(MapScene.OverlayMaterialResource);+ Assert.IsNotNull(mat);+ Assert.AreEqual("Statecraft/HexOverlay", mat.shader.name);+ CollectionAssert.IsEmpty(ShaderChecks.Gles3Errors(mat.shader));+ Assert.AreEqual((int)UnityEngine.Rendering.RenderQueue.Transparent + 40, mat.renderQueue);+ var source = System.IO.File.ReadAllText(AssetDatabase.GetAssetPath(mat.shader));+ StringAssert.IsMatch(@"(?m)^\s*ZTest\s+Always\s*$", source, "drawn over the models, not hidden behind them");+ StringAssert.IsMatch(@"(?m)^\s*ZWrite\s+Off\s*$", source, "writes no depth");+ StringAssert.IsMatch(@"(?m)^\s*Blend\s+SrcAlpha\s+OneMinusSrcAlpha\s*$", source, "alpha-blended: the fill is translucent");+ }++ /// <summary>The hover band draws over the lit hexes' fill and under the move arrow (#2184: queue Transparent+50, the default+ /// sorting layer, order in layer 0), so the arrow's tip on the hovered hex stays on top. URP sorts transparent renderers by+ /// sorting layer and order in layer before the queue, so the band keeps the arrow's layer and order and sits under it by+ /// queue alone: an order of 1 would draw it after the arrow whatever the queue. Same shader as the fill (ZTest Always).</summary>+ [Test]+ public void TheHoverBandDrawsOverTheFillAndUnderTheMoveArrow()+ {+ var map = BuildMap();+ try+ {+ var lit = C.Hexes.Where(h => h.Land).Select(h => (h.Q, h.R)).First();+ map.ShowReachable(new[] { lit });+ map.ShowHover(lit);+ var fill = map.Terrain.transform.Find(MapScene.ReachableFillName).GetComponent<MeshRenderer>();+ var hover = map.Terrain.transform.Find(MapScene.HoverName).GetComponent<MeshRenderer>();+ Assert.AreEqual(0, hover.sortingLayerID, "the arrow's sorting layer, the default");+ Assert.AreEqual(0, hover.sortingOrder, "the arrow's order in layer: a higher one draws the band over the arrow");+ Assert.AreEqual(0, fill.sortingLayerID);+ Assert.AreEqual(0, fill.sortingOrder);+ const int arrow = (int)UnityEngine.Rendering.RenderQueue.Transparent + 50;+ Assert.That(hover.sharedMaterial.renderQueue, Is.GreaterThan(fill.sharedMaterial.renderQueue).And.LessThan(arrow),+ "queued after the fill and before the arrow");+ Assert.AreEqual(fill.sharedMaterial.shader, hover.sharedMaterial.shader, "drawn over the models as the fill is");+ }+ finally { Object.DestroyImmediate(map.gameObject); }+ }++ /// <summary>GameRoot marks the hex under the pointer only where a click would give the pick's order (PickTakes), during the+ /// Move pick and the Attack pick: a lit hex, and not water or an unlit land hex the pick does not take (here the unit's own+ /// hex), where a click ends the pick. Nothing before a unit is selected, off the map, or once the pick ends.</summary>+ [Test]+ public void TheHoverMarksOnlyHexesAClickWouldTake()+ {+ using var rig = new SelectThenClickMoveTests.Rig();+ var s = rig.Bridge.State;+ var id = UnitOrdersTests.EnemyInGolanisReach(s);+ rig.Layer.Show(rig.Bridge.Content, s);+ var water = C.Hexes.First(h => !h.Land);+ var sea = (water.Q, water.R);+ var home = rig.At(id);+ GameRoot.MarkHover(rig.Map, rig.Info, rig.Reach(id).First());+ Assert.IsFalse(Shows(rig.Map, MapScene.HoverName), "no pick: no marker");+ void MarksOnlyWhatAClickTakes(string pick)+ {+ var lit = rig.Lit.Last();+ Assert.IsNotEmpty(lit, $"precondition: the {pick} pick lights hexes");+ Assert.IsFalse(lit.Contains(home) || rig.Info.PickTakes(home.q, home.r), $"precondition: the {pick} pick does not take the unit's own hex");+ Assert.IsFalse(rig.Info.PickTakes(sea.Q, sea.R), $"precondition: the {pick} pick does not take water");+ GameRoot.MarkHover(rig.Map, rig.Info, lit.First());+ Assert.IsTrue(Shows(rig.Map, MapScene.HoverName), $"the {pick} pick marks a lit hex");+ GameRoot.MarkHover(rig.Map, rig.Info, sea);+ Assert.IsFalse(Shows(rig.Map, MapScene.HoverName), $"the {pick} pick: no marker on water, a click there ends the pick");+ GameRoot.MarkHover(rig.Map, rig.Info, home);+ Assert.IsFalse(Shows(rig.Map, MapScene.HoverName), $"the {pick} pick: no marker on an unlit land hex it does not take");+ GameRoot.MarkHover(rig.Map, rig.Info, lit.First());+ GameRoot.MarkHover(rig.Map, rig.Info, null);+ Assert.IsFalse(Shows(rig.Map, MapScene.HoverName), "off the map: no marker");+ }+ rig.Select(rig.Token("golani"));+ Assert.IsTrue(rig.Info.MovePicking, "precondition: the Move pick is open");+ MarksOnlyWhatAClickTakes("Move");+ UiTestKit.Press(rig.Ui.Q<Button>("info-attack"));+ Assert.IsFalse(rig.Info.MovePicking, "precondition: the Attack pick is open");+ Assert.IsTrue(rig.Info.Picking);+ MarksOnlyWhatAClickTakes("Attack");+ var target = rig.Lit.Last().First();+ rig.Click(sea.Q, sea.R); // a hex with no target ends the pick+ Assert.IsFalse(rig.Info.Picking, "precondition: the pick ended");+ GameRoot.MarkHover(rig.Map, rig.Info, target);+ Assert.IsFalse(Shows(rig.Map, MapScene.HoverName), "the pick ended: no marker");+ }+}diff --git a/unity/Assets/Tests/EditMode/HexHighlightTests.cs.meta b/unity/Assets/Tests/EditMode/HexHighlightTests.cs.metanew file mode 100644index 000000000..d9a6999f2--- /dev/null+++ b/unity/Assets/Tests/EditMode/HexHighlightTests.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 4d4388b380bf4039b3cc21f688473ac7