A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Map: a confirm step onto a friendly hex or city, and a 30 px drag onset with no catch-up (#1661 rulings 1, 2) (#1808)
Eyal Goland90e2e215635
diff --git a/changelog.d/1661-friendly-confirm-drag.md b/changelog.d/1661-friendly-confirm-drag.mdnew file mode 100644index 000000000..e9598360e--- /dev/null+++ b/changelog.d/1661-friendly-confirm-drag.md@@ -0,0 +1,11 @@+- A confirm step for ordering a unit onto a friendly unit or a city by touch or keyboard (#1661, owner's ruling of+ 26 October 2026). With a unit selected, picking a hex that holds another of your units, or a city, still selects it+ as before, and also offers "Send <unit> to <place>" for the unit you had selected; taking it moves that unit. The+ offer goes away once it is stale: another selection, a new turn, or a screen opening. Mouse right-click ordering is+ unchanged. The Hebrew wording is native-review-pending.++### Changed++- A map drag still starts only past 30 px, and now pans only by the distance beyond it, with no catch-up jump (#1661,+ owner's ruling of 26 October 2026). Each press measures from where it landed, so a quick release and a new press+ between two frames can no longer pan inside the 30 px.diff --git a/changelog.d/1661-left-button-observer.md b/changelog.d/1661-left-button-observer.mdnew file mode 100644index 000000000..35d504690--- /dev/null+++ b/changelog.d/1661-left-button-observer.md@@ -0,0 +1 @@+- Left-button map drags now use the camera's per-press 30 px onset and UI-origin latch, matching right-button drags without replaying held travel (#1661, #998). This builds on Ella Sharakanski's left-drag support in #1791.diff --git a/docs/units.md b/docs/units.mdindex 37e466488..645741804 100644--- a/docs/units.md+++ b/docs/units.md@@ -698,3 +698,15 @@ Brigades, the squadron's bases and the ships: every position, date and coordinatin `content/map/units_1948.yaml`.The photographs are references only: no image file is copied into the repository.++### Friendly destinations and drag onset (#1661, owner rulings 26 October 2026)++Selecting another friendly unit or a city while a movable unit is selected keeps the normal selection and offers+"Send {unit} to {place}" for the previously selected mover. Activating that confirmation gives the existing Move or+go-to command immediately; the confirmation itself also confirms a far route on touch. A new selection, state change+(including a turn or loaded session), or screen opening discards the proposal. Right-click ordering stays immediate.+The English and Hebrew confirmation share the same placeholders; the Hebrew is native-review-pending.++Map drags retain the 30 device-pixel threshold. Each press captures its own origin from input events. On the first+crossing, only the part of that movement segment outside the threshold pans; subsequent motion pans normally, with no+replay of held travel. The tap rule and complete between-frame touch swipes are ruling 3 (#1777).diff --git a/unity/Assets/Scripts/Map/CameraController.cs b/unity/Assets/Scripts/Map/CameraController.csindex 1dccfeabb..553d3b4af 100644--- a/unity/Assets/Scripts/Map/CameraController.cs+++ b/unity/Assets/Scripts/Map/CameraController.cs@@ -81,7 +81,7 @@ namespace Statecraft.Game.Mappublic float GroundTop = ShadowFit.GroundY;/// <summary>True while a mouse press could still be a click: a right click (MapPointer.RightTapCandidate) or,/// since #998, a left one (MapPointer.LeftTapCandidate). Its drag is held, not panned, until the press leaves the- /// click's slop, and then applied at once. A press is a click - an order for the right button (#1654), a selection+ /// click's slop; only travel beyond the slop pans. A press is a click - an order for the right button (#1654), a selection/// for the left - or a pan, never both. Null: the drag pans at once.</summary>public Func<bool>? HoldsMouseDrag;/// <summary>The same for a one-finger drag and a tap (MapPointer.TouchTapCandidate).</summary>@@ -89,11 +89,25 @@ namespace Statecraft.Game.MapCameraRig rig = null!;InputAction? pan, dragPan, zoom, zoomKeys, orbit;+ InputAction? mousePress, mousePosition, touchPress, touchPosition;void Awake() => rig = GetComponent<CameraRig>();void OnEnable(){+ // Camera-owned observers record press origins; they never recognise or enqueue taps.+ mousePress = new InputAction("camera-drag-press", InputActionType.Button, "<Mouse>/rightButton");+ mousePress.AddBinding("<Mouse>/leftButton");+ mousePress.performed += ctx => mouseDrag.Begin(((Mouse)ctx.control.device).position.ReadValue(), IsOverUi);+ mousePress.canceled += _ => mouseDrag.End();+ mousePosition = new InputAction("camera-drag-position", InputActionType.PassThrough, "<Mouse>/position");+ mousePosition.performed += ctx => mouseDrag.Move(ctx.ReadValue<Vector2>());+ touchPress = new InputAction("camera-touch-press", InputActionType.Button, "<Touchscreen>/primaryTouch/press");+ touchPress.performed += ctx => touchDrag.Begin(((Touchscreen)ctx.control.device).primaryTouch.position.ReadValue(), IsOverUi);+ touchPress.canceled += _ => touchDrag.End();+ touchPosition = new InputAction("camera-touch-position", InputActionType.PassThrough, "<Touchscreen>/primaryTouch/position");+ touchPosition.performed += ctx => touchDrag.Move(ctx.ReadValue<Vector2>());+ mousePress.Enable(); mousePosition.Enable(); touchPress.Enable(); touchPosition.Enable();DrainWheel(); // events from while the camera was off (a menu) are not a zoomvar map = InputSystem.actions?.FindActionMap("Camera", throwIfNotFound: true);@@ -103,10 +117,17 @@ namespace Statecraft.Game.Mapmap.Enable();}- void OnDisable() => InputSystem.actions?.FindActionMap("Camera")?.Disable();+ void OnDisable()+ {+ InputSystem.actions?.FindActionMap("Camera")?.Disable();+ mousePress?.Dispose(); mousePress = null; mousePosition?.Dispose(); mousePosition = null;+ touchPress?.Dispose(); touchPress = null; touchPosition?.Dispose(); touchPosition = null;+ mouseDrag.End(); touchDrag.End();+ dragFromUi = dragWasDown = false;+ }bool dragFromUi, dragWasDown;- Vector2 heldDrag; // the drag of a press that may still be a click (HoldsMouseDrag, HoldsTouchDrag)+ readonly PressDrag mouseDrag = new PressDrag(), touchDrag = new PressDrag();void Update() => Tick(Time.unscaledDeltaTime);@@ -117,46 +138,75 @@ namespace Statecraft.Game.Map{if (pan == null || dragPan == null || zoom == null || zoomKeys == null || orbit == null) return;Vector2? pointer = Pointer.current != null ? Pointer.current.position.ReadValue() : (Vector2?)null;- // Either button (#998, owner 22 Oct 2026): DragPan is bound to both, and a press is only a pan once it has- // left the click's slop, so HoldDrag must see that a button is down for the left one as well as the right.+ // Either button (#998): both drag bindings share the press-origin and UI-origin rules.var down = Mouse.current != null && (Mouse.current.rightButton.isPressed || Mouse.current.leftButton.isPressed);- var held = down && HoldsMouseDrag?.Invoke() == true;- var drag = dragPan.ReadValue<Vector2>();+ // A null callback preserves immediate panning for this source alone (N1).+ var mouseGated = HoldsMouseDrag != null;+ var drag = mouseGated ? mouseDrag.Take(HoldsMouseDrag!()) : dragPan.ReadValue<Vector2>();+ var fromUi = down && mouseDrag.FromUi;var zoomRaw = WheelOr(zoom.ReadValue<float>());var ts = Touchscreen.current;if (ts != null){switch (FingersDown(ts, out var a, out var b)){- // one finger drags the map, like the right button: Gather's latch answers whether it started over the UI+ // one finger drags the map; its press observer latches the UI origincase 1:- drag += a.delta.ReadValue();+ drag += HoldsTouchDrag != null ? touchDrag.Take(HoldsTouchDrag()) : a.delta.ReadValue();+ fromUi |= touchDrag.FromUi;down = true;- held |= HoldsTouchDrag?.Invoke() == true;pointer = a.position.ReadValue();break;// a pinch zooms by how far the fingers move; the UI check follows the first fingercase 2:+ touchDrag.Discard();zoomRaw += PinchNotches(a.position.ReadValue(), a.delta.ReadValue(), b.position.ReadValue(), b.delta.ReadValue());pointer = a.position.ReadValue();break;}}- drag = HoldDrag(drag, down, held);var modifier = ModifierHeld(Keyboard.current);- Step(rig, Gather(pan.ReadValue<Vector2>(), drag, zoomRaw, orbit.ReadValue<float>(), down, pointer, zoomKeys.ReadValue<float>(), modifier),- ClampDt(dt), Bounds, Ground, GroundTop);+ var input = Gather(pan.ReadValue<Vector2>(), drag, zoomRaw, orbit.ReadValue<float>(), down, pointer, zoomKeys.ReadValue<float>(), modifier);+ if (down) input.DragFromUi = fromUi; // latched at the actual press, even between camera frames+ Step(rig, input, ClampDt(dt), Bounds, Ground, GroundTop);}- /// <summary>This frame's drag, given whether a drag press is <paramref name="down"/> and still <paramref name="held"/>- /// (it may yet be a click): nothing while held (kept), the kept drag and this frame's once it is not, and the kept- /// drag dropped when the press ends while still held (it was a click).</summary>- internal Vector2 HoldDrag(Vector2 drag, bool down, bool held)+ /// <summary>Position history scoped to one press. Begin resets even if release/repress happens between+ /// camera ticks. Event positions, rather than Mouse/delta, exclude pre-press movement and retain multiple+ /// input updates. Released gestures are not replayed here (Ella owns ruling 3).</summary>+ internal sealed class PressDrag{- if (!down) { heldDrag = Vector2.zero; return drag; }- if (held) { heldDrag += drag; return Vector2.zero; }- drag += heldDrag; heldDrag = Vector2.zero;- return drag;+ Vector2 origin, previous, pending;+ bool down, panning;+ internal bool FromUi { get; private set; }+ internal void Begin(Vector2 at, Func<Vector2, bool>? overUi = null)+ {+ origin = previous = at; pending = Vector2.zero;+ down = true; panning = false; FromUi = overUi?.Invoke(at) == true;+ }+ internal void End() { down = panning = false; pending = Vector2.zero; }+ internal void Discard() { pending = Vector2.zero; }+ internal void Move(Vector2 at)+ {+ if (!down) return;+ var segment = at - previous;+ var start = previous - origin;+ previous = at;+ if (panning) { pending += segment; return; }+ var radius = TapPress.SlopPixels;+ if ((at - origin).sqrMagnitude <= radius * radius || segment.sqrMagnitude == 0f) return;+ panning = true;+ var dot = Vector2.Dot(start, segment);+ var t = (-dot + Mathf.Sqrt(Mathf.Max(0f, dot * dot + segment.sqrMagnitude+ * (radius * radius - start.sqrMagnitude)))) / segment.sqrMagnitude;+ pending += segment * (1f - Mathf.Clamp01(t));+ }+ internal Vector2 Take(bool held)+ {+ // A current click candidate always wins over any prior panning state.+ if (held) { pending = Vector2.zero; panning = false; return Vector2.zero; }+ var result = pending; pending = Vector2.zero; return result;+ }}/// <summary>The first two touches down (2 stands for two or more), or fewer.</summary>diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex bfd9fdaf4..24f59d9d5 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -664,12 +664,17 @@ namespace Statecraft.Game.UIif (info.Selected is (int sq, int sr) && !info.ShowsUnit) map.Select(sq, sr); else map.ClearSelection();return;}+ // A friendly token is drawn where the player tapped (its anchor), which can be a neighbour of its sim hex.+ var friendDrawn = units.Tokens.Any(t => t.Q == q && t.R == r && t.Token.Unit.Side == Statecraft.Game.Map.Units.UnitData.Israel+ && t.Token.Unit.Id != units.Selected);+ var offerMove = info.PrepareFriendlyMove(q, r, friendDrawn);// #1661: a name pill means the city even when another unit stands there. A badge/terrain or keyboard// pick keeps the existing unit-first routing; the event carries intent, not a mutable "last hit" flag.if (cityPill && info.IsCity(q, r)){units.Select(null);info.Show(q, r);+ offerMove?.Invoke();return;}var id = units.UnitToSelectAt(q, r);@@ -677,6 +682,7 @@ namespace Statecraft.Game.UIunits.Select(id);if (id != null) { map.ClearSelection(); info.ShowUnit(); }else info.Show(q, r);+ offerMove?.Invoke();}/// <summary>A right click on the map (MapPointer.HexOrdered; owner, 25 Oct 2026, "Civ: select, then click"): while thediff --git a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs b/unity/Assets/Scripts/UI/InfoPanelPresenter.csindex 4d6c0f066..7973a3365 100644--- a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs+++ b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs@@ -17,6 +17,8 @@ namespace Statecraft.Game.UI/// and Send home after the unit's front signs its armistice (#1309).</summary>public sealed class InfoPanelPresenter : System.IDisposable{+ readonly Button confirmMove;+ (Command command, GameSession session, int turn)? pendingMove;readonly System.Action? clearSelection;readonly EventCallback<NavigationCancelEvent> onCancel;@@ -105,6 +107,12 @@ namespace Statecraft.Game.UI{panel = root.Q<VisualElement>("info-panel"); this.bridge = bridge; this.text = text;orders = panel.Q<VisualElement>("info-orders");+ confirmMove = new Button(ConfirmMove) { name = "info-confirm-move" };+ confirmMove.RegisterCallback<KeyDownEvent>(OnConfirmKey);+ confirmMove.style.whiteSpace = WhiteSpace.Normal;+ panel.Q<Label>("info-title").parent.Insert(2, confirmMove);+ DiscardMove();+ ScreenNav.InfoIntentCovered += OnInfoCovered;this.selectPioneer = selectPioneer;pioneerList = panel.Q<VisualElement>("info-pioneers");pioneerReturn = panel.Q<Button>("info-pioneer-return");@@ -159,7 +167,7 @@ namespace Statecraft.Game.UIreinforceButton = panel.Q<Button>("info-reinforce");onReinforce = () => { if (reinforce is Reinforce r) { bridge.Queue(r); Render(); } };reinforceButton.clicked += onReinforce;- bridge.Changed += Render;+ bridge.Changed += OnStateChanged;panel.parent?.RegisterCallback<GeometryChangedEvent>(OnHudGeometry);Render();}@@ -167,7 +175,7 @@ namespace Statecraft.Game.UIvoid OnHudGeometry(GeometryChangedEvent e) => panel.EnableInClassList(ShortClass, e.newRect.height < ShortBelowPx);/// <summary>Unsubscribes from the bridge and the buttons (the owner calls this when disabled).</summary>- public void Dispose() { pioneerReturn.clicked -= onPioneerReturn; pioneerList.Clear(); panel.UnregisterCallback(onCancel); presses.Dispose(); bridge.Changed -= Render; panel.parent?.UnregisterCallback<GeometryChangedEvent>(OnHudGeometry); campButton.clicked -= onCamp; housingButton.clicked -= onHousing; defenceButton.clicked -= onDefence; moveButton.clicked -= onMove; fortifyButton.clicked -= onFortify; holdButton.clicked -= onHold; attackButton.clicked -= onAttack; sendHomeButton.clicked -= onSendHome; skipButton.clicked -= onSkip; reinforceButton.clicked -= onReinforce; EndPick(); }+ public void Dispose() { pioneerReturn.clicked -= onPioneerReturn; pioneerList.Clear(); panel.UnregisterCallback(onCancel); presses.Dispose(); bridge.Changed -= OnStateChanged; ScreenNav.InfoIntentCovered -= OnInfoCovered; confirmMove.UnregisterCallback<KeyDownEvent>(OnConfirmKey); confirmMove.clicked -= ConfirmMove; confirmMove.RemoveFromHierarchy(); panel.parent?.UnregisterCallback<GeometryChangedEvent>(OnHudGeometry); campButton.clicked -= onCamp; housingButton.clicked -= onHousing; defenceButton.clicked -= onDefence; moveButton.clicked -= onMove; fortifyButton.clicked -= onFortify; holdButton.clicked -= onHold; attackButton.clicked -= onAttack; sendHomeButton.clicked -= onSendHome; skipButton.clicked -= onSkip; reinforceButton.clicked -= onReinforce; EndPick(); }/// <summary>Below this window height (logical px; 1366x657 is about 998) the panel gets ShortClass, and the city's own/// hex folds its projects behind their toggle as on a stacked bar (GddHexPanel.ToggleName): there the full list ran into@@ -213,6 +221,7 @@ namespace Statecraft.Game.UI/// cannot see.</summary>public void Show(int q, int r){+ DiscardMove();if (Covered) return; // covered (#210)if (unitMode || Selected != (q, r)) projects.RemoveFromClassList(GddHexPanel.OpenClass); // a newly chosen hex starts with its city projects foldedEndPick();@@ -223,6 +232,7 @@ namespace Statecraft.Game.UI/// <summary>Shows the selected unit's card (the unit comes from the selectedUnit callback); ignored while covered.</summary>public void ShowUnit(){+ DiscardMove();if (Covered) return;EndPick();pioneer = null; pioneerSession = null; unitMode = true; Selected = null; Render();@@ -231,6 +241,7 @@ namespace Statecraft.Game.UI/// <summary>Shows nothing selected (the hint), as before the first click; ignored while covered.</summary>public void Clear(){+ DiscardMove();if (Covered) return;EndPick();pioneer = null; pioneerSession = null; unitMode = false; Selected = null; Render();@@ -392,6 +403,7 @@ namespace Statecraft.Game.UIvoid EndPick(){+ DiscardMove();if (pick == null) return;pick = null;shownRoute = null;@@ -449,6 +461,72 @@ namespace Statecraft.Game.UI/// even while Move picks (owner, 25 Oct 2026: "Clicking another unit or a city still selects it").</summary>public bool IsCity(int q, int r) => GameRoot.CityAt(bridge.Content, bridge.State, q, r) != null;+ void DiscardMove()+ {+ pendingMove = null;+ confirmMove.style.display = DisplayStyle.None;+ }++ void OnStateChanged() { DiscardMove(); Render(); }++ void OnInfoCovered(VisualElement root)+ {+ if (root == panel || root.Contains(panel)) DiscardMove();+ }++ /// <summary>Captures the original mover before ordinary selection changes the card. The returned action+ /// offers its confirmation after that selection. No command is queued until the button is activated.+ /// <paramref name="friendDrawn"/>: another friendly unit's token is drawn on (q, r) (GameRoot asks the unit layer);+ /// a token stands at its anchor, which need not be its sim hex.</summary>+ internal System.Action? PrepareFriendlyMove(int q, int r, bool friendDrawn = false)+ {+ DiscardMove();+ var c = bridge.Content; var s = bridge.State;+ if (!panel.enabledInHierarchy || panel.parent?.ClassListContains(ScreenNav.ScreenOpenClass) == true+ || pick is not { attack: false } p || p.session != bridge.Session || p.turn != s.Turn+ || MoveTargets() is not { } moves || moves.unit != p.unit || !Takes(p, q, r)) return null;+ // Route allows travel towards a currently full hex; this explicit confirmation must not offer it.+ var moving = s.Units[p.unit];+ var limit = c.RulesAt(s.Date).Mvp!.StackLimit!.Value;+ if (s.Units.Values.Count(u => u.Id != p.unit && u.Side == moving.Side && u.Q == q && u.R == r) >= limit) return null;+ var occupants = s.Units.Values.Where(u => u.Q == q && u.R == r).ToList();+ if (occupants.Any(u => u.Side != "" && u.Side != Movement.PlayerSide)+ || (!IsCity(q, r) && !friendDrawn && !occupants.Any(u => u.Id != p.unit))) return null;+ var token = selectedUnit();+ if (token == null) return null;+ var mover = UnitCard.For(token.Value, s, text, c.IsGdd, c, townNamesHe).Title;+ var target = HexPlaces.Of(string.Format(CultureInfo.InvariantCulture, "{0},{1}", q, r), c, text, townNamesHe);+ Command command = p.hexes.Contains((q, r)) ? new Move(p.unit, q, r) : new UnitOrder(p.unit, Movement.GoTo, q, r);+ return () =>+ {+ if (bridge.Session != p.session || bridge.State.Turn != p.turn || !panel.enabledInHierarchy) return;+ pendingMove = (command, p.session, p.turn);+ confirmMove.text = text.Format("unit.confirm_move", mover, target);+ confirmMove.style.display = DisplayStyle.Flex;+ };+ }++ void OnConfirmKey(KeyDownEvent e)+ {+ if (e.keyCode != UnityEngine.KeyCode.Space) return;+ // Enter arrives as NavigationSubmit; Space needs the same explicit path as the map stop.+ using var submit = NavigationSubmitEvent.GetPooled();+ submit.target = confirmMove; confirmMove.SendEvent(submit);+ e.StopPropagation();+ }++ void ConfirmMove()+ {+ var proposal = pendingMove;+ var keyboard = presses.ByKeyboard;+ DiscardMove(); // a reentrant Changed, or a second activation, cannot repeat the command+ if (proposal is not { } p || p.session != bridge.Session || p.turn != bridge.State.Turn+ || !panel.enabledInHierarchy || Covered || panel.parent?.ClassListContains(ScreenNav.ScreenOpenClass) == true) return;+ bridge.Queue(p.command); // existing bridge/sim validation; the button itself confirms a far route too+ Render();+ if (keyboard) FocusReturn.To(mapFocus);+ }+/// <summary>True while the open pick is a Move's (not an Attack's).</summary>public bool MovePicking => pick is { attack: false };diff --git a/unity/Assets/Scripts/UI/ScreenNav.cs b/unity/Assets/Scripts/UI/ScreenNav.csindex d390f8867..0cfd726bb 100644--- a/unity/Assets/Scripts/UI/ScreenNav.cs+++ b/unity/Assets/Scripts/UI/ScreenNav.cs@@ -12,6 +12,9 @@ namespace Statecraft.Game.UIpublic sealed class ScreenNav : System.IDisposable{public static readonly string[] Screens = { "cabinet", "budget", "defence", "why", "timeline", "how-to-play", "objectives", "settings" };+ // Transient map confirmations expire even for a narrow screen that leaves the info panel visible.+ internal static event System.Action<VisualElement>? InfoIntentCovered;+/// <summary>The class on the open screen's button (Statecraft.uss lights its ring).</summary>public const string OpenClass = "nav-open";/// <summary>The class on the "root" element while a wide screen (class <see cref="WideClass"/>: Cabinet, Defence, Timeline) is@@ -55,6 +58,7 @@ namespace Statecraft.Game.UIr.Q("right-column")?.SetEnabled(!(start || full || modal || outcome || report));bool infoCovered = start || full || modal || outcome || report || r.ClassListContains(WideOpenClass);r.Q("info-panel")?.SetEnabled(!infoCovered);+ if (screen || infoCovered) InfoIntentCovered?.Invoke(r);// the map's keyboard stop (#41 B1b): out of reach exactly when the info panel is, so a pick is never refused (#210)r.Q("map-focus")?.SetEnabled(!infoCovered);var layer = r.Q("event-layer");diff --git a/unity/Assets/Tests/EditMode/CameraInputTests.cs b/unity/Assets/Tests/EditMode/CameraInputTests.csindex c0ed608fa..39298f3fa 100644--- a/unity/Assets/Tests/EditMode/CameraInputTests.cs+++ b/unity/Assets/Tests/EditMode/CameraInputTests.cs@@ -698,4 +698,206 @@ public class CameraZoomKeysThroughTheInputSystemTests : InputTestFixture}finally { Send(c, "OnDisable"); Object.DestroyImmediate(go); }}+ [Test]+ public void DragOnsetDiscardsThirtyPixelsAndNeverCatchesUp()+ {+ var go = new GameObject("DragOnset", typeof(Camera), typeof(CameraRig));+ try+ {+ var c = go.AddComponent<CameraController>();+ c.HoldsMouseDrag = () => true;+ var gesture = new CameraController.PressDrag();+ gesture.Begin(Vector2.zero);+ var position = Vector2.zero;+ Vector2 Drag(Vector2 delta, bool down, bool held)+ {+ if (!down) { gesture.End(); position = Vector2.zero; return Vector2.zero; }+ if (position == Vector2.zero) gesture.Begin(position);+ position += delta; gesture.Move(position); return gesture.Take(held);+ }+ Assert.AreEqual(30f, TapPress.SlopPixels);+ Assert.AreEqual(Vector2.zero, Drag(new Vector2(29, 0), true, true));+ Assert.AreEqual(Vector2.zero, Drag(new Vector2(1, 0), true, true));+ Assert.AreEqual(new Vector2(1, 0), Drag(new Vector2(1, 0), true, false));+ Assert.AreEqual(new Vector2(-5, 2), Drag(new Vector2(-5, 2), true, false), "after onset all motion pans");+ Assert.AreEqual(Vector2.zero, Drag(Vector2.zero, false, false), "no delayed release jump");+ Assert.AreEqual(new Vector2(70, 0), Drag(new Vector2(100, 0), true, false), "one crossing frame");+ Drag(Vector2.zero, false, false);+ var diagonal = Drag(new Vector2(42, 56), true, false);+ Assert.That(diagonal.x, Is.EqualTo(24f).Within(0.0001f));+ Assert.That(diagonal.y, Is.EqualTo(32f).Within(0.0001f));+ }+ finally { Object.DestroyImmediate(go); }+ }++ [Test]+ public void TurningInsideTheSlopOnlyPansTheCrossingSegmentsExcess()+ {+ var go = new GameObject("DragCorner", typeof(Camera), typeof(CameraRig));+ try+ {+ var c = go.AddComponent<CameraController>(); c.HoldsTouchDrag = () => true;+ var gesture = new CameraController.PressDrag();+ var position = Vector2.zero;+ Vector2 Drag(Vector2 delta, bool down, bool held)+ {+ if (!down) { gesture.End(); position = Vector2.zero; return Vector2.zero; }+ if (position == Vector2.zero) gesture.Begin(position);+ position += delta; gesture.Move(position); return gesture.Take(held);+ }+ Drag(new Vector2(0, 24), true, true);+ // The segment reaches the radius-30 circle at (18,24): only its last 12 px pan.+ var excess = Drag(new Vector2(30, 0), true, false);+ Assert.That(excess.x, Is.EqualTo(12f).Within(0.0001f));+ Assert.That(excess.y, Is.EqualTo(0f).Within(0.0001f));+ Drag(Vector2.zero, false, false);+ Drag(new Vector2(10, 0), true, true);+ Assert.AreEqual(Vector2.zero, Drag(Vector2.zero, false, false), "short press drops held travel");+ }+ finally { Object.DestroyImmediate(go); }+ }++}++// #1661 B1/S1/N1: real actions, independent of Ella's pointer fixture.+public class PressOriginCameraInputTests : InputTestFixture+{+ static void Send(Object o, string method) => o.GetType().GetMethod(method,+ System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!.Invoke(o, null);++ sealed class Rig : System.IDisposable+ {+ public readonly SelectThenClickMoveTests.Rig Game = new SelectThenClickMoveTests.Rig();+ public readonly GameObject Go;+ public readonly CameraRig View;+ public readonly CameraController Camera;+ public readonly MapPointer Pointer;+ public readonly System.Collections.Generic.List<Vector2> Orders = new System.Collections.Generic.List<Vector2>();+ public Rig()+ {+ InputSystem.actions = AssetDatabase.LoadAssetAtPath<InputActionAsset>("Assets/InputSystem_Actions.inputactions");+ Go = new GameObject("PressOrigin", typeof(UnityEngine.Camera));+ var lens = Go.GetComponent<UnityEngine.Camera>();+ lens.fieldOfView = 60; lens.aspect = 16f / 9f; lens.rect = new Rect(0, 0, 1, 1);+ View = Go.AddComponent<CameraRig>(); View.TopInset = 0;+ View.Yaw = 0; View.LookAt = new Vector3(500000, 0, 500000); View.Distance = 100000;+ Camera = Go.AddComponent<CameraController>();+ Camera.Bounds = new Rect(0, 0, 1000000, 1000000);+ Pointer = Go.AddComponent<MapPointer>(); Pointer.Map = Game.Map;+ var game = Game;+ var mover = game.Token("golani");+ var target = game.Reach(game.Id(mover)).First(h => game.Layer.UnitToSelectAt(h.q, h.r) == null && !game.Info.IsCity(h.q, h.r));+ game.Select(mover);+ Pointer.PillHex = _ => target;+ Pointer.IsOverUi = p => { Orders.Add(p); return false; };+ Pointer.HexOrdered += (q, r) => Statecraft.Game.UI.GameRoot.OnHexOrdered(game.Map, game.Info, q, r);+ var pointer = Pointer;+ Camera.HoldsMouseDrag = () => pointer.RightTapCandidate;+ Camera.HoldsTouchDrag = () => pointer.TouchTapCandidate;+ Send(Camera, "Awake"); Send(Camera, "OnEnable"); Send(Pointer, "OnEnable");+ }+ public void Frame() { Pointer.Tick(); Camera.Tick(0.016f); }+ public void Dispose() { Send(Pointer, "OnDisable"); Send(Camera, "OnDisable"); Object.DestroyImmediate(Go); Game.Dispose(); }+ }++ [TestCase(10)]+ [TestCase(31)]+ public void AReleaseAndNewPressBeforeTheCameraFrameStartsANewGesture(int travel)+ {+ var mouse = InputSystem.AddDevice<Mouse>();+ using var rig = new Rig();+ Set(mouse.position, new Vector2(400, 400)); Press(mouse.rightButton);+ Move(mouse.position, new Vector2(450, 400), new Vector2(50, 0)); rig.Frame();+ var afterA = rig.View.LookAt;+ Assert.That(afterA.x, Is.EqualTo(500000 - 20 * 120).Within(0.1f), "A has panned");+ Release(mouse.rightButton);+ var b = new Vector2(700, 400);+ Set(mouse.position, b); Press(mouse.rightButton);+ Move(mouse.position, b + new Vector2(travel, 0), new Vector2(travel, 0));+ rig.Frame(); // no camera frame between A's release and B's movement+ Assert.That(rig.View.LookAt.x, Is.EqualTo(afterA.x - (travel > 30 ? 120 : 0)).Within(0.1f));+ Assert.AreEqual(afterA.z, rig.View.LookAt.z);+ Release(mouse.rightButton); rig.Frame();+ if (travel == 10)+ {+ CollectionAssert.AreEqual(new[] { b }, rig.Orders, "one order, at B's press position");+ Assert.AreEqual(1, rig.Game.Bridge.Session.Committed.Count, "one sim command from B");+ Assert.IsInstanceOf<Statecraft.Sim.Move>(rig.Game.Bridge.Session.Committed.Single());+ }+ else { Assert.IsEmpty(rig.Orders); Assert.IsEmpty(rig.Game.Bridge.Session.Committed); }+ }++ [TestCase(30)]+ [TestCase(31)]+ public void OnsetUsesThePressPositionDespitePrePressDeltaAndSeveralInputUpdates(int travel)+ {+ var mouse = InputSystem.AddDevice<Mouse>();+ using var rig = new Rig();+ Set(mouse.position, new Vector2(400, 400)); rig.Frame();+ InputSystem.QueueStateEvent(mouse, new UnityEngine.InputSystem.LowLevel.MouseState+ { position = new Vector2(500, 400), delta = new Vector2(100, 0) });+ InputSystem.QueueStateEvent(mouse, new UnityEngine.InputSystem.LowLevel.MouseState+ { position = new Vector2(500, 400), delta = new Vector2(100, 0) }+ .WithButton(UnityEngine.InputSystem.LowLevel.MouseButton.Right));+ InputSystem.Update(); rig.Frame(); // movement before press, in the same input update+ Move(mouse.position, new Vector2(510, 400), new Vector2(10, 0));+ Move(mouse.position, new Vector2(500 + travel, 400), new Vector2(travel - 10, 0));+ rig.Frame(); // two InputSystem updates, one camera Tick+ Assert.That(rig.View.LookAt.x, Is.EqualTo(500000 - (travel > 30 ? 120 : 0)).Within(0.1f));+ Release(mouse.rightButton); rig.Frame();+ Assert.That(rig.View.LookAt.x, Is.EqualTo(500000 - (travel > 30 ? 120 : 0)).Within(0.1f), "no release catch-up");+ Assert.AreEqual(travel == 30 ? 1 : 0, rig.Game.Bridge.Session.Committed.Count);+ }++ [Test]+ public void AUiOriginRemainsBlockedEvenAfterLeavingItBeforeTheCameraFrame()+ {+ var mouse = InputSystem.AddDevice<Mouse>();+ using var rig = new Rig();+ rig.Camera.IsOverUi = p => p.x < 500;+ Set(mouse.position, new Vector2(400, 400)); Press(mouse.rightButton);+ Move(mouse.position, new Vector2(600, 400), new Vector2(200, 0)); rig.Frame();+ Assert.AreEqual(new Vector3(500000, 0, 500000), rig.View.LookAt);+ Release(mouse.rightButton); rig.Frame();+ Set(mouse.position, new Vector2(600, 400)); Press(mouse.rightButton);+ Move(mouse.position, new Vector2(631, 400), new Vector2(31, 0)); rig.Frame();+ Assert.That(rig.View.LookAt.x, Is.EqualTo(499880).Within(0.1f), "new map press clears the UI latch");+ }++ [TestCase(30)]+ [TestCase(31)]+ public void TouchOnsetAlsoUsesThePressOriginAcrossInputUpdates(int travel)+ {+ InputSystem.AddDevice<Touchscreen>();+ using var rig = new Rig();+ rig.Frame(); // warm the pointer's frame APIs, preserving Ella's still-tap rule+ BeginTouch(1, new Vector2(600, 400)); rig.Frame();+ MoveTouch(1, new Vector2(610, 400));+ MoveTouch(1, new Vector2(600 + travel, 400)); rig.Frame();+ Assert.That(rig.View.LookAt.x, Is.EqualTo(500000 - (travel > 30 ? 120 : 0)).Within(0.1f));+ EndTouch(1, new Vector2(600 + travel, 400)); rig.Frame();+ Assert.That(rig.View.LookAt.x, Is.EqualTo(500000 - (travel > 30 ? 120 : 0)).Within(0.1f), "no release jump");+ }++ [TestCase(false)]+ [TestCase(true)]+ public void ANullCallbackPansThatSourceImmediatelyEvenWhenTheOtherIsGated(bool touch)+ {+ var mouse = InputSystem.AddDevice<Mouse>();+ InputSystem.AddDevice<Touchscreen>();+ using var rig = new Rig();+ if (touch)+ {+ rig.Camera.HoldsTouchDrag = null;+ BeginTouch(1, new Vector2(600, 400)); rig.Frame();+ MoveTouch(1, new Vector2(610, 400)); rig.Frame();+ }+ else+ {+ rig.Camera.HoldsMouseDrag = null;+ Set(mouse.position, new Vector2(600, 400)); Press(mouse.rightButton); rig.Frame();+ Move(mouse.position, new Vector2(610, 400), new Vector2(10, 0)); rig.Frame();+ }+ Assert.That(rig.View.LookAt.x, Is.EqualTo(498800).Within(0.1f), "ungated source pans all ten pixels");+ }}diff --git a/unity/Assets/Tests/EditMode/KeyboardOrdersTests.cs b/unity/Assets/Tests/EditMode/KeyboardOrdersTests.csindex e71b11b7b..8886918e1 100644--- a/unity/Assets/Tests/EditMode/KeyboardOrdersTests.cs+++ b/unity/Assets/Tests/EditMode/KeyboardOrdersTests.cs@@ -175,4 +175,56 @@ public class KeyboardOrdersTests// Event answers correctly stay deferred (spec3.2:89); only the attack must be absent.Assert.IsEmpty(Bridge.Queued.OfType<UnitOrder>().Where(o => o.Order == Combat.Attack), "the attack does not wait for End turn");}++ /// <summary>#1661 ruling 1 with the keyboard alone, in the real game: select Golani, Tab round to the map stop over a+ /// city (Tel Aviv) or over another Israeli unit's token, Enter. That selects as before and offers "Send Golani to+ /// ..."; Tab reaches the offer, and Enter (Submit) or Space takes it: Golani's one order is committed. The offer is+ /// also where a finger lands: the UI pick at its centre is the button, so a tap there is not a map tap.</summary>+ [UnityTest]+ public IEnumerator AFriendlyDestinationIsConfirmedWithTheKeyboardAlone(+ [Values("city", "friendly")] string kind, [Values(KeyCode.Return, KeyCode.Space)] KeyCode key)+ {+ yield return Boot();+ var id = -1;+ yield return SelectGolani(i => id = i);+ var layer = Object.FindFirstObjectByType<UnitLayer>();+ var c = Bridge.Content; var s = Bridge.State;+ (int q, int r) target;+ if (kind == "city")+ {+ var city = c.SettlementHexes.First(x => x.Id == "tel_aviv" && layer.UnitToSelectAt(x.Q, x.R) == null);+ target = (city.Q, city.R);+ }+ else+ {+ var friend = layer.Tokens.First(t => t.Token.Unit.Side == UnitData.Israel && t.Token.Unit.Id != "golani"+ && layer.UnitToSelectAt(t.Q, t.R) == t.Token.Unit.Id+ && Movement.Route(c, s, id, t.Q, t.R, Bridge.Spent).Count > 0);+ target = (friend.Q, friend.R);+ }+ var expected = layer.UnitToSelectAt(target.q, target.r);+ var near = Movement.Reachable(c, s, id, Bridge.Spent).ContainsKey((target.q, target.r));+ yield return EnterOnTheMapAt(target.q, target.r);+ Assert.IsEmpty(Bridge.Session.Committed, "the pick itself gives no order");+ Assert.AreEqual(expected, layer.Selected, "ordinary selection stays");+ var send = ui.Q<Button>("info-confirm-move");+ Assert.IsNotNull(send);+ Assert.AreEqual(DisplayStyle.Flex, send.resolvedStyle.display, "the offer shows");+ yield return Frames(2);+ Assert.AreSame(send, ui.panel.Pick(send.worldBound.center), "a finger on the offer lands on the button, not the map");+ yield return TabTo("info-confirm-move");+ if (key == KeyCode.Return) yield return Enter();+ else+ {+ var at = At;+ using (var k = KeyDownEvent.GetPooled(' ', KeyCode.Space, EventModifiers.None)) { k.target = at; at.SendEvent(k); }+ yield return Frames(3);+ }+ Assert.AreEqual(1, Bridge.Session.Committed.Count, "one order");+ var u = Bridge.State.Units[id];+ if (near) Assert.AreEqual(target, (u.Q, u.R), "in reach: Golani moves there now");+ else Assert.AreEqual(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0},{1}", target.q, target.r),+ u.OrderTarget, "beyond reach: Golani's go-to");+ Assert.AreEqual(DisplayStyle.None, send.resolvedStyle.display, "the offer is used up");+ }}diff --git a/unity/Assets/Tests/EditMode/MapPressTests.cs b/unity/Assets/Tests/EditMode/MapPressTests.csindex c0a8c6260..a60611afe 100644--- a/unity/Assets/Tests/EditMode/MapPressTests.cs+++ b/unity/Assets/Tests/EditMode/MapPressTests.cs@@ -311,4 +311,75 @@ public class RightClickOrPanTests : InputTestFixtureLeftDrag(rig, onMap, onMap + new Vector2(120, 0), onMap + new Vector2(240, 0));Assert.AreNotEqual(start, rig.View.LookAt, "the identical drag begun on the map does pan");}++ // Extends Ella's #1791 left-drag coverage to the camera-owned press observer (#1808).+ [TestCase(30)]+ [TestCase(31)]+ public void ALeftDragUsesThePressOriginAcrossInputUpdates(int travel)+ {+ using var rig = new Rig();+ rig.View.Yaw = 0;+ var start = rig.View.LookAt;+ var from = new Vector2(600, 400);+ Set(mouse.position, from); rig.Frame();+ Press(mouse.leftButton);+ Move(mouse.position, from + new Vector2(10, 0), new Vector2(10, 0));+ Move(mouse.position, from + new Vector2(travel, 0), new Vector2(travel - 10, 0));+ rig.Frame(); // two input updates, no camera frame since the press+ var expected = start.x - (travel > 30 ? 120f : 0f);+ Assert.That(rig.View.LookAt.x, Is.EqualTo(expected).Within(0.1f), "only travel past 30 px pans");+ Assert.AreEqual(start.z, rig.View.LookAt.z);+ rig.Frame();+ Assert.That(rig.View.LookAt.x, Is.EqualTo(expected).Within(0.1f), "travel is consumed once");+ Release(mouse.leftButton); rig.Frame();+ Assert.That(rig.View.LookAt.x, Is.EqualTo(expected).Within(0.1f), "no release catch-up");+ if (travel == 30) CollectionAssert.AreEqual(new[] { from }, rig.Clicks);+ else Assert.IsEmpty(rig.Clicks);+ }++ [TestCase(10)]+ [TestCase(31)]+ public void ALeftReleaseAndRepressBeforeTheCameraFrameStartsANewGesture(int travel)+ {+ using var rig = new Rig();+ rig.View.Yaw = 0;+ var start = rig.View.LookAt;+ var a = new Vector2(400, 400);+ Set(mouse.position, a); rig.Frame();+ Press(mouse.leftButton);+ Move(mouse.position, a + new Vector2(50, 0), new Vector2(50, 0)); rig.Frame();+ Assert.That(rig.View.LookAt.x, Is.EqualTo(start.x - 20 * 120).Within(0.1f), "A pans its excess");+ var afterA = rig.View.LookAt;+ Release(mouse.leftButton);+ var b = new Vector2(700, 400);+ Set(mouse.position, b); Press(mouse.leftButton);+ Move(mouse.position, b + new Vector2(travel, 0), new Vector2(travel, 0)); rig.Frame();+ var expected = afterA.x - (travel > 30 ? 120f : 0f);+ Assert.That(rig.View.LookAt.x, Is.EqualTo(expected).Within(0.1f), "B has its own origin and onset");+ Assert.AreEqual(afterA.z, rig.View.LookAt.z);+ Release(mouse.leftButton); rig.Frame();+ Assert.That(rig.View.LookAt.x, Is.EqualTo(expected).Within(0.1f));+ if (travel == 10) CollectionAssert.AreEqual(new[] { b }, rig.Clicks);+ else Assert.IsEmpty(rig.Clicks);+ }++ [Test]+ public void ALeftUiOriginRemainsBlockedAfterLeavingBeforeTheCameraFrame()+ {+ using var rig = new Rig();+ rig.View.Yaw = 0;+ rig.Controller.IsOverUi = p => p.x < 500;+ var start = rig.View.LookAt;+ Set(mouse.position, new Vector2(400, 400)); rig.Frame();+ Press(mouse.leftButton);+ Move(mouse.position, new Vector2(600, 400), new Vector2(200, 0)); rig.Frame();+ Assert.AreEqual(start, rig.View.LookAt, "the press began on UI, even though the frame ends on the map");+ Release(mouse.leftButton); rig.Frame();+ Press(mouse.leftButton);+ Move(mouse.position, new Vector2(631, 400), new Vector2(31, 0)); rig.Frame();+ Assert.That(rig.View.LookAt.x, Is.EqualTo(start.x - 120f).Within(0.1f), "a new map press clears the latch and pans one pixel");+ Assert.AreEqual(start.z, rig.View.LookAt.z);+ Release(mouse.leftButton); rig.Frame();+ Assert.IsEmpty(rig.Clicks);+ }}diff --git a/unity/Assets/Tests/EditMode/SelectThenClickMoveTests.cs b/unity/Assets/Tests/EditMode/SelectThenClickMoveTests.csindex 9a5c585e7..1dfce7edc 100644--- a/unity/Assets/Tests/EditMode/SelectThenClickMoveTests.cs+++ b/unity/Assets/Tests/EditMode/SelectThenClickMoveTests.cs@@ -12,6 +12,7 @@ using UnityEditor;using UnityEditor.SceneManagement;using UnityEngine;using UnityEngine.UIElements;+using UnityEngine.InputSystem;/// <summary>The owner, playing on 25 October 2026: "i still can't move a fucking unit", "the unit must move when you click on/// the fucking lit hex" and "not wait for the end of the fucking turn"; asked how, "Civ: select, then click (Recommended)".@@ -25,7 +26,7 @@ public class SelectThenClickMoveTestsstatic List<UnitEntry> Units => UnitData.Parse(File.ReadAllText(Path.Combine(Paths.Content, "map", UnitData.DefaultFileName)));static UiText Text => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings).text);- sealed class Rig : System.IDisposable+ internal sealed class Rig : System.IDisposable{public readonly MapScene Map;public readonly UiTestKit Ui;@@ -34,18 +35,18 @@ public class SelectThenClickMoveTestspublic readonly InfoPanelPresenter Info;public readonly List<IReadOnlyCollection<(int q, int r)>> Lit = new List<IReadOnlyCollection<(int q, int r)>>();- public Rig()+ public Rig(UiText? text = null){EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Single);Map = new GameObject("MapScene").AddComponent<MapScene>();Map.Configure(Load("Terrain"), Load("SettlementMarker"), Load("HexSelection"), Load("Sea"), Load("MapFrame"));Map.Build();Ui = new UiTestKit(); // after the new scene, which would take the UI document with it- Bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), Text);+ Bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), text ?? Text);Layer = UnitLayer.Create(Map, Units, C.Hexes, still: true);Layer.Show(Bridge.Content, Bridge.State);var layer = Layer; var map = Map; var lit = Lit;- Info = new InfoPanelPresenter(Ui.Root, Bridge, Text, C.SettlementNames,+ Info = new InfoPanelPresenter(Ui.Root, Bridge, text ?? Text, C.SettlementNames,selectedUnit: () => layer.Selected is string sel ? layer.Tokens.First(p => p.Token.Unit.Id == sel) : (PlacedToken?)null,showReachable: hexes => { lit.Add(hexes.ToList()); map.ShowReachable(hexes); }, showRoute: map.ShowRoute,clearSelection: () => { layer.Select(null); map.ClearSelection(); });@@ -58,6 +59,26 @@ public class SelectThenClickMoveTestspublic void Click(int q, int r, bool touch = false) => GameRoot.OnHexClicked(Map, Layer, Info, q, r, touch);public void Select(PlacedToken t) => Click(t.Q, t.R);+ /// <summary>#1661: another Israeli unit moved onto a city hex Golani has a route to (no game start has one there).+ /// Hands back Golani's token and the city hex; the friend's Move is committed. The friend's token is drawn near the+ /// city, where UnitPlacer finds it a spot, not necessarily on it.</summary>+ public (PlacedToken mover, (int q, int r) city) FriendOnACity()+ {+ var golani = Id(Token("golani"));+ foreach (var t in Layer.Tokens.Where(t => t.Token.Unit.Side == UnitData.Israel && t.Token.Unit.Id != "golani").ToList())+ {+ if (UnitCard.SimUnit(C, Bridge.State, t.Token.Unit) is not int x) continue;+ var city = Reach(x).Cast<(int q, int r)?>().FirstOrDefault(h => Info.IsCity(h!.Value.q, h.Value.r)+ && Layer.UnitToSelectAt(h.Value.q, h.Value.r) == null+ && Movement.Route(C, Bridge.State, golani, h.Value.q, h.Value.r, Bridge.Spent).Count > 0);+ if (city is not (int q, int r)) continue;+ Assert.IsNull(Bridge.Queue(new Move(x, q, r)), "precondition: the friend moves onto the city");+ Layer.Show(C, Bridge.State);+ return (Token("golani"), (q, r));+ }+ throw new AssertionException("no Israeli unit can reach a city Golani has a route to");+ }+public void Dispose(){Info.Dispose();@@ -329,4 +350,344 @@ public class SelectThenClickMoveTestsvar given = rig.Bridge.Session.Committed.OfType<UnitOrder>().Single();Assert.AreEqual((id, Combat.Attack), (given.Unit, given.Order), "the right click gave the attack");}+ // #1661 owner rulings 1 and 2 (the confirm step). Red on main: no offer exists there.+ [TestCase(false)]+ [TestCase(true)]+ public void AFriendlyDestinationOffersTheOriginalMoverExactlyOnce(bool touch)+ {+ using var rig = new Rig();+ var own = rig.Layer.Tokens.Where(t => t.Token.Unit.Side == UnitData.Israel+ && UnitCard.SimUnit(C, rig.Bridge.State, t.Token.Unit) != null).ToList();+ var pair = (from a in own from b in own+ where a.Token.Unit.Id != b.Token.Unit.Id && (a.Q, a.R) != (b.Q, b.R)+ && rig.Layer.UnitToSelectAt(b.Q, b.R) == b.Token.Unit.Id+ && rig.Reach(rig.Id(a)).Contains((b.Q, b.R))+ select (a, b)).First();+ var id = rig.Id(pair.a); var other = rig.Id(pair.b);+ // The tapped hex is where B's token is drawn (its anchor), which can differ from B's sim hex.+ var from = rig.At(id); (int q, int r) target = (pair.b.Q, pair.b.R); var otherAt = rig.At(other);+ rig.Select(pair.a);+ rig.Click(target.q, target.r, touch);+ Assert.IsEmpty(rig.Bridge.Session.Committed, "selection itself gives no order");+ Assert.AreEqual(pair.b.Token.Unit.Id, rig.Layer.Selected, "ordinary selection stays");+ var send = rig.Ui.Root.Q<Button>("info-confirm-move");+ Assert.IsNotNull(send, "a visible confirmation is offered");+ Assert.AreEqual(DisplayStyle.Flex, send.style.display.value);+ StringAssert.Contains(UnitCard.For(pair.a, rig.Bridge.State, Text, C.IsGdd, C).Title, send.text);+ StringAssert.Contains(HexPlaces.Of(string.Format(System.Globalization.CultureInfo.InvariantCulture,+ "{0},{1}", target.q, target.r), C, Text, null), send.text);+ UiTestKit.Press(send);+ Assert.AreEqual(target, rig.At(id), "the retained mover A moves, not selected B");+ Assert.AreEqual(otherAt, rig.At(other), "B stays where it was");+ Assert.AreEqual(1, rig.Bridge.Session.Committed.Count);+ Assert.Greater(rig.Bridge.Spent[id], 0);+ UiTestKit.Press(send);+ Assert.AreEqual(1, rig.Bridge.Session.Committed.Count, "a second activation cannot repeat the move");+ Assert.AreNotEqual(from, rig.At(id));+ }++ [TestCase(false)]+ [TestCase(true)]+ public void ACityOffersAConfirmedGoToWithoutAnExtraTouchTap(bool touch)+ {+ using var rig = new Rig();+ var mover = rig.Token("golani"); var id = rig.Id(mover);+ var city = C.SettlementHexes.First(x => x.Id == "tel_aviv" && rig.Layer.UnitToSelectAt(x.Q, x.R) == null);+ Assert.IsNotEmpty(Movement.Route(C, rig.Bridge.State, id, city.Q, city.R, rig.Bridge.Spent));+ rig.Select(mover);+ rig.Click(city.Q, city.R, touch);+ Assert.IsFalse(rig.Info.ShowsUnit);+ Assert.IsEmpty(rig.Bridge.Session.Committed);+ var send = rig.Ui.Root.Q<Button>("info-confirm-move");+ Assert.IsNotNull(send);+ Assert.AreEqual(DisplayStyle.Flex, send.style.display.value);+ UiTestKit.Press(send);+ Assert.AreEqual(1, rig.Bridge.Session.Committed.Count);+ Assert.AreEqual(Movement.GoTo, rig.Bridge.State.Units[id].Order);+ Assert.AreEqual(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0},{1}", city.Q, city.R),+ rig.Bridge.State.Units[id].OrderTarget);+ }++ [TestCase(false)]+ [TestCase(true)]+ public void AnOccupiedCityPillStillShowsTheCityAndOffersTheOriginalMover(bool pill)+ {+ using var rig = new Rig();+ var (mover, city) = rig.FriendOnACity();+ var baseline = rig.Bridge.Session.Committed.Count;+ var id = rig.Id(mover);+ var near = rig.Reach(id).Contains(city);+ rig.Select(mover);+ var unitFirst = rig.Layer.UnitToSelectAt(city.q, city.r);+ GameRoot.OnHexClicked(rig.Map, rig.Layer, rig.Info, city.q, city.r, true, pill);+ Assert.AreEqual(baseline, rig.Bridge.Session.Committed.Count, "the pick itself gives no order");+ if (pill) Assert.AreEqual(((int, int)?)city, rig.Info.Selected, "a pill means the city");+ else Assert.AreEqual(unitFirst, rig.Layer.Selected, "a badge/terrain or keyboard pick keeps unit-first routing");+ var send = rig.Ui.Root.Q<Button>("info-confirm-move");+ Assert.IsNotNull(send);+ Assert.AreEqual(DisplayStyle.Flex, send.style.display.value, "a city a friend holds offers the retained mover");+ UiTestKit.Press(send);+ if (near) Assert.AreEqual(city, rig.At(id), "a city in reach: the Move");+ else Assert.AreEqual(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0},{1}", city.q, city.r),+ rig.Bridge.State.Units[id].OrderTarget, "a city beyond reach: the go-to");+ Assert.AreEqual(baseline + 1, rig.Bridge.Session.Committed.Count);+ }++ [TestCase("en-US", "en")]+ [TestCase("he-IL", "he")]+ public void ConfirmationUsesLocalizedNamesAndTextUnderEitherCulture(string culture, string language)+ {+ var before = System.Globalization.CultureInfo.CurrentCulture;+ try+ {+ System.Globalization.CultureInfo.CurrentCulture = new System.Globalization.CultureInfo(culture);+ var text = UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>("Assets/UI/strings." + language + ".yaml").text);+ using var rig = new Rig(text);+ var mover = rig.Token("golani");+ var city = C.SettlementHexes.First(x => x.Id == "tel_aviv" && rig.Layer.UnitToSelectAt(x.Q, x.R) == null);+ rig.Select(mover); rig.Click(city.Q, city.R, touch: true);+ var send = rig.Ui.Root.Q<Button>("info-confirm-move");+ Assert.IsNotNull(send);+ Assert.AreEqual(DisplayStyle.Flex, send.style.display.value);+ var place = HexPlaces.Of(string.Format(System.Globalization.CultureInfo.InvariantCulture,+ "{0},{1}", city.Q, city.R), C, text, null);+ Assert.AreEqual(text.Format("unit.confirm_move", UnitCard.For(mover, rig.Bridge.State, text, C.IsGdd, C).Title, place), send.text);+ Assert.IsEmpty(rig.Bridge.Session.Committed);+ }+ finally { System.Globalization.CultureInfo.CurrentCulture = before; }+ }++ [TestCase("selection")]+ [TestCase("turn")]+ [TestCase("screen")]+ [TestCase("escape")]+ [TestCase("session")]+ [TestCase("modal")]+ public void AnOccupiedDestinationConfirmationIsDiscardedWhenStale(string change)+ {+ using var rig = new Rig();+ var mover = rig.Token("golani");+ var city = C.SettlementHexes.First(x => x.Id == "tel_aviv" && rig.Layer.UnitToSelectAt(x.Q, x.R) == null);+ rig.Select(mover); rig.Click(city.Q, city.R, touch: true);+ var send = rig.Ui.Root.Q<Button>("info-confirm-move");+ Assert.IsNotNull(send);+ Assert.AreEqual(DisplayStyle.Flex, send.style.display.value);+ if (change == "selection") rig.Select(mover);+ if (change == "turn") rig.Bridge.EndTurn();+ if (change == "escape") rig.Info.Escape();+ if (change == "session") rig.Bridge.Replace(GameSession.New(C, GoldenRun.Seed, Mode.Historical));+ if (change == "modal")+ {+ var root = rig.Ui.Root.Q("root");+ root.AddToClassList(TurnReportPresenter.OpenClass); ScreenNav.DisableCovered(rig.Ui.Root);+ root.RemoveFromClassList(TurnReportPresenter.OpenClass); ScreenNav.DisableCovered(rig.Ui.Root);+ }+ if (change == "screen")+ {+ // Even a narrow screen that leaves the panel enabled invalidates the proposal.+ using var nav = new ScreenNav(rig.Ui.Root);+ nav.Open("why");+ Assert.IsTrue(rig.Ui.Q<VisualElement>("info-panel").enabledSelf, "narrow screen precondition");+ nav.Open(null);+ }+ var committed = rig.Bridge.Session.Committed.Count;+ Assert.AreEqual(DisplayStyle.None, send.style.display.value);+ UiTestKit.Press(send);+ Assert.AreEqual(committed, rig.Bridge.Session.Committed.Count);+ }++ [Test]+ public void EmptyFarTerrainStillRequiresTwoTouchPicksAndOffersNoFriendlyConfirmation()+ {+ using var rig = new Rig();+ var c = rig.Bridge.Content;+ var mover = rig.Token("golani"); var id = rig.Id(mover);+ var reach = rig.Reach(id).ToHashSet();+ var target = c.Hexes.First(h => h.Land && !reach.Contains((h.Q, h.R))+ && rig.Layer.UnitToSelectAt(h.Q, h.R) == null && !rig.Info.IsCity(h.Q, h.R)+ && Movement.Route(c, rig.Bridge.State, id, h.Q, h.R, rig.Bridge.Spent).Count > 0);+ rig.Select(mover);+ rig.Click(target.Q, target.R, touch: true);+ Assert.IsEmpty(rig.Bridge.Session.Committed, "first tap previews the existing far route");+ Assert.AreEqual(DisplayStyle.None, rig.Ui.Q<Button>("info-confirm-move").style.display.value);+ rig.Click(target.Q, target.R, touch: true);+ Assert.AreEqual(1, rig.Bridge.Session.Committed.Count, "second tap confirms the existing far route");+ Assert.AreEqual(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0},{1}", target.Q, target.R),+ rig.Bridge.State.Units[id].OrderTarget);+ }++ [TestCase("full-friendly")]+ [TestCase("no-points")]+ [TestCase("send-home")]+ [TestCase("game-over")]+ [TestCase("sea")]+ [TestCase("hostile")]+ [TestCase("covered")]+ public void RefusedDestinationsOfferNoConfirmationAndPreserveOrdinarySelection(string reason)+ {+ using var rig = new Rig();+ var c = rig.Bridge.Content; var s = rig.Bridge.State;+ var mover = rig.Token("golani"); var id = rig.Id(mover);+ var city = c.SettlementHexes.First(x => x.Id == "tel_aviv" && rig.Layer.UnitToSelectAt(x.Q, x.R) == null);+ (int q, int r) target = (city.Q, city.R);+ if (reason == "full-friendly")+ {+ var u = s.Units[id];+ var limit = c.RulesAt(s.Date).Mvp!.StackLimit!.Value;+ for (int i = 0; i < limit; i++)+ {+ int clone = s.Units.Keys.Max() + 1;+ s.Units[clone] = new Unit(clone, u.Type, target.q, target.r, u.Service, u.Side,+ u.Strength, "", "", u.HomeCity, u.Full);+ }+ Assert.IsNotEmpty(Movement.Route(c, s, id, target.q, target.r, rig.Bridge.Spent), "route alone permits a full endpoint");+ }+ if (reason == "no-points")+ {+ for (var reach = rig.Reach(id); reach.Count > 0; reach = rig.Reach(id))+ Assert.IsNull(rig.Bridge.Queue(new Move(id, reach.Last().q, reach.Last().r)));+ Assert.AreEqual(0, Movement.PointsLeft(c, rig.Bridge.State, id, rig.Bridge.Spent));+ }+ if (reason == "send-home")+ {+ var u = s.Units[id];+ s.Units[id] = new Unit(u.Id, u.Type, city.Q, city.R, u.Service, u.Side,+ u.Strength, u.Order, u.OrderTarget, u.HomeCity, u.Full);+ Assert.IsNull(rig.Bridge.Queue(new UnitOrder(id, Demobilization.SendHome)), "precondition: home-city Send home");+ Assert.IsTrue(rig.Bridge.GoingHome(id));+ var otherCity = c.SettlementHexes.First(x => (x.Q, x.R) != (city.Q, city.R)+ && Movement.Route(c, rig.Bridge.State, id, x.Q, x.R, rig.Bridge.Spent).Count > 0);+ target = (otherCity.Q, otherCity.R);+ }+ if (reason == "game-over") s.GameOver = GameOverCodes.MvpEnded;+ if (reason == "sea") { var sea = c.Hexes.First(h => !h.Land); target = (sea.Q, sea.R); }+ if (reason == "hostile")+ {+ UnitOrdersTests.EnemyInGolanisReach(s);+ var enemy = s.Units.Values.First(u => u.Side != "" && u.Side != Movement.PlayerSide+ && Combat.Check(c, s, id, u.Q, u.R) == null);+ target = (enemy.Q, enemy.R);+ }+ rig.Layer.Show(c, rig.Bridge.State);+ mover = rig.Token("golani"); rig.Select(mover);+ var selected = rig.Layer.Selected;+ var committed = rig.Bridge.Session.Committed.Count;+ var queued = rig.Bridge.Queued.Count;+ var before = rig.At(id);+ var expectedSelection = rig.Layer.UnitToSelectAt(target.q, target.r);+ if (reason == "covered")+ {+ // A wide screen over the panel (InfoPanelPresenter.Covered, #210), as UnderACoveringScreenNoClickMovesTheUnit.+ rig.Ui.Q<VisualElement>("info-panel").parent.AddToClassList(ScreenNav.WideOpenClass);+ ScreenNav.DisableCovered(rig.Ui.Root);+ }+ rig.Click(target.q, target.r, touch: true);+ var send = rig.Ui.Root.Q<Button>("info-confirm-move");+ Assert.IsNotNull(send);+ Assert.AreEqual(DisplayStyle.None, send.style.display.value, reason);+ UiTestKit.Press(send);+ Assert.AreEqual(committed, rig.Bridge.Session.Committed.Count);+ Assert.AreEqual(queued, rig.Bridge.Queued.Count);+ Assert.AreEqual(before, rig.At(id));+ if (reason == "covered") Assert.AreEqual(selected, rig.Layer.Selected, "coverage preserves the existing selection");+ else+ {+ Assert.AreEqual(expectedSelection, rig.Layer.Selected, "ordinary unit selection stays");+ Assert.AreEqual(expectedSelection != null, rig.Info.ShowsUnit);+ if (expectedSelection == null) Assert.AreEqual(target, rig.Info.Selected, "ordinary hex selection stays");+ }+ }+}+++/// <summary>#1661 ruling 1 by touch: a virtual touchscreen through MapPointer's real frame, so an InputTestFixture.</summary>+public class TouchConfirmTests : InputTestFixture+{+ /// <summary>Touch: a still tap through MapPointer's real frame (a virtual touchscreen) picks the destination, for a+ /// friend's token, a city a friend stands on and an empty city beyond reach; the offer then moves the retained unit once.+ /// Keyboard Tab/Enter/Space and the UI hit test on the offer run in the real game in+ /// KeyboardOrdersTests.AFriendlyDestinationIsConfirmedWithTheKeyboardAlone.</summary>+ [Test]+ public void TouchSelectsAndActivatesTheConfirmation()+ {+ foreach (var kind in new[] { "friendly", "occupied-city", "far-city" })+ TouchOffersAConfirmationForTheRetainedMover(kind);+ }++ void TouchOffersAConfirmationForTheRetainedMover(string kind)+ {+ using var rig = new SelectThenClickMoveTests.Rig();+ var c = rig.Bridge.Content;+ var mover = rig.Token("golani");+ var city = c.SettlementHexes.First(x => x.Id == "tel_aviv" && rig.Layer.UnitToSelectAt(x.Q, x.R) == null);+ (int Q, int R) target = (city.Q, city.R);+ if (kind == "occupied-city")+ {+ var (friendMover, friendCity) = rig.FriendOnACity();+ mover = friendMover; target = (friendCity.q, friendCity.r);+ }+ if (kind == "friendly")+ {+ var own = rig.Layer.Tokens.Where(t => t.Token.Unit.Side == UnitData.Israel+ && UnitCard.SimUnit(c, rig.Bridge.State, t.Token.Unit) != null).ToList();+ var pair = (from a in own from b in own+ where a.Token.Unit.Id != b.Token.Unit.Id && (a.Q, a.R) != (b.Q, b.R)+ && rig.Layer.UnitToSelectAt(b.Q, b.R) == b.Token.Unit.Id+ && rig.Reach(rig.Id(a)).Contains((b.Q, b.R))+ select (a, b)).First();+ mover = pair.a; target = (pair.b.Q, pair.b.R);+ }+ var id = rig.Id(mover);+ var before = rig.At(id);+ var baseline = rig.Bridge.Session.Committed.Count;+ var near = rig.Reach(id).Contains((target.Q, target.R));+ var others = rig.Bridge.State.Units.Values.Where(u => u.Id != id).ToDictionary(u => u.Id, u => (u.Q, u.R));+ Assert.IsNotEmpty(Movement.Route(c, rig.Bridge.State, id, target.Q, target.R, rig.Bridge.Spent));+ var cam = Camera.main;+ var view = cam.GetComponent<CameraRig>() ?? cam.gameObject.AddComponent<CameraRig>();+ var hex = c.HexAt(target.Q, target.R)!;+ var at = rig.Map.Frame.ToWorld(hex.Lon, hex.Lat, 0);+ at.y = rig.Map.Terrain.SampleHeight(at) + rig.Map.Terrain.transform.position.y;+ view.LookAt = at; view.Distance = 30000f; view.Yaw = 0; view.Apply();+ Physics.SyncTransforms();+ var pointer = cam.gameObject.AddComponent<MapPointer>();+ pointer.Map = rig.Map; pointer.IsOverUi = _ => false;+ try+ {+ pointer.HexClicked += (q, r, pill) => GameRoot.OnHexClicked(rig.Map, rig.Layer, rig.Info, q, r, true, pill);+ rig.Select(mover);+ var expectedUnit = rig.Layer.UnitToSelectAt(target.Q, target.R); // before the pick moves the selection+ InputSystem.AddDevice<Touchscreen>();+ pointer.Tick(); // warm frame APIs, as Ella documents; this is a still tap across updates+ var screen = cam.WorldToScreenPoint(at);+ var position = new Vector2(screen.x, screen.y);+ BeginTouch(1, position); pointer.Tick();+ Assert.AreEqual(baseline, rig.Bridge.Session.Committed.Count);+ EndTouch(1, position); pointer.Tick();+ pointer.Tick(); // tap is enqueued after the release frame's drain+ if (expectedUnit == null) Assert.AreEqual(((int, int)?)(target.Q, target.R), rig.Info.Selected, "ordinary hex selection");+ else Assert.AreEqual(expectedUnit, rig.Layer.Selected, "ordinary unit selection");+ Assert.AreEqual(baseline, rig.Bridge.Session.Committed.Count, "the tap itself gives no order");+ var send = rig.Ui.Root.Q<Button>("info-confirm-move");+ Assert.IsNotNull(send);+ Assert.AreEqual(DisplayStyle.Flex, send.style.display.value);+ // The button is taken as the UI takes any button press (Button.clicked); that a finger on it lands on the+ // button and not the map is KeyboardOrdersTests' hit test in the real game.+ UiTestKit.Press(send);+ Assert.AreEqual(baseline + 1, rig.Bridge.Session.Committed.Count);+ Assert.AreNotEqual(before, rig.At(id), "the original mover moves immediately");+ Assert.Greater(rig.Bridge.Spent[id], 0);+ foreach (var other in others) Assert.AreEqual(other.Value, rig.At(other.Key), "other units stay put");+ if (!near)+ {+ Assert.AreEqual(Movement.GoTo, rig.Bridge.State.Units[id].Order);+ Assert.AreEqual(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0},{1}", target.Q, target.R),+ rig.Bridge.State.Units[id].OrderTarget);+ }+ else Assert.AreEqual((target.Q, target.R), rig.At(id));+ UiTestKit.Press(send);+ Assert.AreEqual(baseline + 1, rig.Bridge.Session.Committed.Count, "confirmation consumed exactly once");+ }+ finally { Object.DestroyImmediate(pointer); }+ }}diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yamlindex 46992f4bf..3107027cc 100644--- a/unity/Assets/UI/strings.en.yaml+++ b/unity/Assets/UI/strings.en.yaml@@ -1018,3 +1018,5 @@ why.cause.ending.mvp_ended: "The game has reached its last turn"why.cause.ending.coalition_collapse: "The coalition collapsed"why.cause.ending.defeat_economy: "Money and Food ran out"why.cause.ending.defeat_war: "The enemy holds a city"++unit.confirm_move: "Send {0} to {1}"diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yamlindex 2817ed559..ff80c4302 100644--- a/unity/Assets/UI/strings.he.yaml+++ b/unity/Assets/UI/strings.he.yaml@@ -1121,3 +1121,6 @@ why.cause.ending.mvp_ended: "המשחק הגיע לתור האחרון" # nativewhy.cause.ending.coalition_collapse: "הקואליציה התפרקה" # native-review-pending (#564)why.cause.ending.defeat_economy: "הכסף והמזון אזלו" # native-review-pending (#564)why.cause.ending.defeat_war: "האויב מחזיק בעיר" # native-review-pending (#564)++# native-review-pending: #1661 occupied-destination confirmation+unit.confirm_move: "שליחת {0} אל {1}"