Skip to content

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

Map: a left drag pans the map (#998) (#1791)

EllaSharakanskib0808484477e
diff --git a/changelog.d/998-left-drag-pan.md b/changelog.d/998-left-drag-pan.md
new file mode 100644
index 000000000..da55f517c
--- /dev/null
+++ b/changelog.d/998-left-drag-pan.md
@@ -0,0 +1,7 @@
+### Added
+
+- Dragging the map with the left mouse button pans it, the way map apps do (#998; owner's ruling of 22 October 2026).
+ A plain left click still selects the hex and gives its orders. The pan starts only once the press leaves the click's
+ 30 px slop, so a click never nudges the map, and a drag selects nothing. The click is decided on the release rather
+ than the press — a press cannot be known to be a drag until it moves — and is still queued once per physical press,
+ so each click acts exactly once. Right-drag, the touch gestures and the keyboard are unchanged.
diff --git a/unity/Assets/InputSystem_Actions.inputactions b/unity/Assets/InputSystem_Actions.inputactions
index 06fcaffc4..9e4fc33ec 100644
--- a/unity/Assets/InputSystem_Actions.inputactions
+++ b/unity/Assets/InputSystem_Actions.inputactions
@@ -1086,6 +1086,39 @@
"isComposite": false,
"isPartOfComposite": true
},
+ {
+ "name": "LeftDrag",
+ "id": "b0c4f952-045c-4207-8dfe-fc874867a8e8",
+ "path": "OneModifier",
+ "interactions": "",
+ "processors": "",
+ "groups": "",
+ "action": "DragPan",
+ "isComposite": true,
+ "isPartOfComposite": false
+ },
+ {
+ "name": "modifier",
+ "id": "98b00b14-6638-46ea-b3a4-62f8e04b4aef",
+ "path": "<Mouse>/leftButton",
+ "interactions": "",
+ "processors": "",
+ "groups": ";Keyboard&Mouse",
+ "action": "DragPan",
+ "isComposite": false,
+ "isPartOfComposite": true
+ },
+ {
+ "name": "binding",
+ "id": "58344891-672f-450f-bebd-d95d6a1b39aa",
+ "path": "<Mouse>/delta",
+ "interactions": "",
+ "processors": "",
+ "groups": ";Keyboard&Mouse",
+ "action": "DragPan",
+ "isComposite": false,
+ "isPartOfComposite": true
+ },
{
"name": "",
"id": "5b1f0c3e-7a8d-4c51-9e2b-3a6d4f8e1c30",
diff --git a/unity/Assets/Scripts/Map/CameraController.cs b/unity/Assets/Scripts/Map/CameraController.cs
index dce9e8677..1dccfeabb 100644
--- a/unity/Assets/Scripts/Map/CameraController.cs
+++ b/unity/Assets/Scripts/Map/CameraController.cs
@@ -6,7 +6,7 @@ using UnityEngine.InputSystem;
namespace Statecraft.Game.Map
{
/// <summary>One frame of camera input, in the units the actions give: Pan in [-1, 1] per axis (keys), DragPan in
- /// screen pixels (right-button drag), Zoom in wheel notches (positive = in), Orbit in [-1, 1] (Q/E).</summary>
+ /// screen pixels (a left- or right-button drag, #998), Zoom in wheel notches (positive = in), Orbit in [-1, 1] (Q/E).</summary>
public struct CameraInput
{
public Vector2 Pan, DragPan; public float Zoom, Orbit;
@@ -15,7 +15,9 @@ namespace Statecraft.Game.Map
public float KeyZoom;
/// <summary>True while the pointer is over the UI: the camera then ignores pointer input (wheel zoom, drag).</summary>
public bool OverUi;
- /// <summary>True when the current right-button drag started over the UI (latched on button-down): that drag never pans the map.</summary>
+ /// <summary>True when the current mouse drag, with either button, started over the UI (latched on button-down):
+ /// that drag never pans the map. Since #998 a left drag pans too, so this latch is what keeps dragging a panel's
+ /// scrollbar from moving the map (ALeftDragStartingOverTheUiNeverPans).</summary>
public bool DragFromUi;
}
@@ -77,9 +79,10 @@ namespace Statecraft.Game.Map
/// <summary>The highest the ground (and the frame round the map, which stays below it) reaches in world y: with it,
/// ViewFootprint bounds the near side of the view tightly. ShadowFit.GroundY (the default) means flat ground.</summary>
public float GroundTop = ShadowFit.GroundY;
- /// <summary>True while the right button's press could still be a right click (MapPointer.RightTapCandidate): its drag
- /// is held, not panned, until the press leaves the click's slop, and then applied at once. A press is a right click
- /// (an order, #1654) or a pan, never both. Null: the drag pans at once.</summary>
+ /// <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
+ /// 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>
public Func<bool>? HoldsTouchDrag;
@@ -114,7 +117,9 @@ 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;
- var down = Mouse.current != null && Mouse.current.rightButton.isPressed;
+ // 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.
+ var down = Mouse.current != null && (Mouse.current.rightButton.isPressed || Mouse.current.leftButton.isPressed);
var held = down && HoldsMouseDrag?.Invoke() == true;
var drag = dragPan.ReadValue<Vector2>();
var zoomRaw = WheelOr(zoom.ReadValue<float>());
diff --git a/unity/Assets/Scripts/Map/MapPointer.cs b/unity/Assets/Scripts/Map/MapPointer.cs
index 173cf82c0..08f5ee35a 100644
--- a/unity/Assets/Scripts/Map/MapPointer.cs
+++ b/unity/Assets/Scripts/Map/MapPointer.cs
@@ -40,9 +40,11 @@ namespace Statecraft.Game.Map
/// <summary>Left click on the map (not on the UI) selects the hex under the pointer: a ray from the camera hits the
/// terrain's collider, the hit becomes lon/lat (GeoFrame) and then a hex (HexPicker). On a touchscreen a tap (press and
/// release inside TapPress.SlopPixels, with no second finger down) does the same, so a one-finger drag pans and a pinch zooms without selecting.
- /// A right click (press and release inside the same slop) raises HexOrdered instead, selecting nothing. One TapPress per
- /// gesture decides both a click and the camera's pan (RightTapCandidate, TouchTapCandidate): the camera pans only once
- /// the press has left the slop, so a press is a click or a pan, never both (#1654 review).</summary>
+ /// A right click (press and release inside the same slop) raises HexOrdered instead, selecting nothing. Since #998 a
+ /// left press behaves the same way: inside the slop it selects on release, and past it the camera pans and nothing is
+ /// selected. One TapPress per gesture decides both a click and the camera's pan (RightTapCandidate, LeftTapCandidate,
+ /// TouchTapCandidate): the camera pans only once the press has left the slop, so a press is a click or a pan, never
+ /// both (#1654 review).</summary>
/// <remarks>Runs before <see cref="CameraController"/> (#1661 item 5). The camera asks this pointer whether a press
/// may still be a tap. For a finger that answer is <see cref="TouchTapCandidate"/>, which only this component's own
/// frame moves; <see cref="RightTapCandidate"/> is moved by the right button's action callbacks
@@ -71,21 +73,28 @@ namespace Statecraft.Game.Map
// Right clicks, as presses are: the right button's press, every pointer move while it is held and its release are
// each stepped at their own event's position, so a drag out and back inside one slow frame is still a drag.
readonly Queue<Vector2> rightClicks = new Queue<Vector2>();
- InputAction? press, rightPress, rightMove;
+ InputAction? press, leftMove, rightPress, rightMove;
- TapPress tap, rightTap;
+ TapPress tap, rightTap, leftTap;
/// <summary>True while the right button's press could still end as a right click (TapPress.TapCandidate): the
/// camera holds its right-drag pan until it is false.</summary>
public bool RightTapCandidate => rightTap.TapCandidate;
/// <summary>True while the primary finger's press could still end as a tap: the camera holds its one-finger pan.</summary>
public bool TouchTapCandidate => tap.TapCandidate;
+ /// <summary>True while the left button's press could still end as a click (#998): the camera holds its drag
+ /// until the press leaves the slop, so a click never nudges the map and a drag past it pans.</summary>
+ public bool LeftTapCandidate => leftTap.TapCandidate;
void OnEnable()
{
press = new InputAction("map-press", InputActionType.Button, "<Mouse>/leftButton");
press.performed += OnPressed;
+ press.canceled += OnReleased;
press.Enable();
+ leftMove = new InputAction("map-left-move", InputActionType.PassThrough, "<Mouse>/position");
+ leftMove.performed += OnLeftMoved;
+ leftMove.Enable();
rightPress = new InputAction("map-right-press", InputActionType.Button, "<Mouse>/rightButton");
rightPress.performed += OnRightPressed;
rightPress.canceled += OnRightReleased;
@@ -97,11 +106,12 @@ namespace Statecraft.Game.Map
void OnDisable()
{
- if (press != null) { press.performed -= OnPressed; press.Dispose(); press = null; }
+ if (press != null) { press.performed -= OnPressed; press.canceled -= OnReleased; press.Dispose(); press = null; }
+ if (leftMove != null) { leftMove.performed -= OnLeftMoved; leftMove.Dispose(); leftMove = null; }
if (rightPress != null) { rightPress.performed -= OnRightPressed; rightPress.canceled -= OnRightReleased; rightPress.Dispose(); rightPress = null; }
if (rightMove != null) { rightMove.performed -= OnRightMoved; rightMove.Dispose(); rightMove = null; }
presses.Clear(); rightClicks.Clear();
- rightTap = default;
+ rightTap = default; leftTap = default;
}
void OnRightPressed(InputAction.CallbackContext ctx)
@@ -118,7 +128,24 @@ namespace Statecraft.Game.Map
void OnPressed(InputAction.CallbackContext ctx)
{
- if (ctx.control.device is Pointer p) OnPress(p.position.ReadValue()); // read during the event: its own position
+ if (ctx.control.device is Pointer p) LeftStep(true, false, p.position.ReadValue()); // read during the event: its own position
+ }
+
+ void OnLeftMoved(InputAction.CallbackContext ctx) => LeftStep(false, false, ctx.ReadValue<Vector2>());
+
+ void OnReleased(InputAction.CallbackContext ctx)
+ {
+ if (ctx.control.device is Pointer p) LeftStep(false, true, p.position.ReadValue());
+ }
+
+ /// <summary>One step of the left button's press (#998, owner's ruling of 22 October 2026: a left drag pans the
+ /// map). The click is decided like the right button's: it is queued on the release, at the position the press
+ /// went down, and only while it never left the slop. Queuing on the release and not the press is what lets a
+ /// drag pan without selecting — a press cannot be known to be a drag until it moves — and the queue still holds
+ /// one entry per physical press, so each click acts exactly once (docs/m3-rulings.md, #1617).</summary>
+ internal void LeftStep(bool pressed, bool released, Vector2 position)
+ {
+ if (leftTap.Step(pressed, released, position, false) is Vector2 at) OnPress(at);
}
/// <summary>Queues a press at <paramref name="at"/> (screen pixels, y up).</summary>
diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.cs
index f48a15183..bfd9fdaf4 100644
--- a/unity/Assets/Scripts/UI/GameRoot.cs
+++ b/unity/Assets/Scripts/UI/GameRoot.cs
@@ -416,7 +416,10 @@ namespace Statecraft.Game.UI
|| (UiPointer.PickAt(root.panel, p, Screen.height) is { } picked && !info.TakesClickThrough(picked, () => pointer.HexUnder(p)));
pointer.IsOverUi = pointerOverUi;
// #1654 review: the pointer's tap rule decides both a click and the camera's drag, so a press is never both.
- Func<bool> holdsMouseDrag = () => pointer.RightTapCandidate, holdsTouchDrag = () => pointer.TouchTapCandidate;
+ // Either button (#998): whichever is down holds the drag while it could still be a click, so a click never
+ // nudges the map and a drag past the slop pans.
+ Func<bool> holdsMouseDrag = () => pointer.RightTapCandidate || pointer.LeftTapCandidate,
+ holdsTouchDrag = () => pointer.TouchTapCandidate;
cameraController.HoldsMouseDrag = holdsMouseDrag; cameraController.HoldsTouchDrag = holdsTouchDrag;
Action<int, int, bool> onHex = (q, r, cityPill) =>
{
diff --git a/unity/Assets/Tests/EditMode/CameraInputTests.cs b/unity/Assets/Tests/EditMode/CameraInputTests.cs
index 2af052997..c0ed608fa 100644
--- a/unity/Assets/Tests/EditMode/CameraInputTests.cs
+++ b/unity/Assets/Tests/EditMode/CameraInputTests.cs
@@ -29,7 +29,13 @@ public class CameraInputTests
var map = asset.FindActionMap("Camera", true);
foreach (var name in new[] { "Pan", "DragPan", "Zoom", "ZoomKeys", "Orbit" }) Assert.IsNotNull(map.FindAction(name), name);
Assert.AreEqual(8, map.FindAction("Pan").bindings.Count(b => b.isPartOfComposite && b.path.StartsWith("<Keyboard>/")));
- Assert.AreEqual(3, map.FindAction("DragPan").bindings.Count);
+ // Two OneModifier composites since #998: the right button and the left one, each over <Mouse>/delta. Naming the
+ // modifiers says more than the count, and catches a composite losing its button rather than only its arity.
+ Assert.AreEqual(6, map.FindAction("DragPan").bindings.Count);
+ CollectionAssert.AreEquivalent(new[] { "<Mouse>/rightButton", "<Mouse>/leftButton" },
+ map.FindAction("DragPan").bindings.Where(b => b.name == "modifier").Select(b => b.path).ToArray());
+ CollectionAssert.AreEquivalent(new[] { "<Mouse>/delta", "<Mouse>/delta" },
+ map.FindAction("DragPan").bindings.Where(b => b.name == "binding").Select(b => b.path).ToArray());
Assert.AreEqual(1, map.FindAction("Zoom").bindings.Count);
// a11y B1a: = and -, and the numpad's + and -, as two 1D composites; the wheel's Zoom keeps its one binding.
CollectionAssert.AreEquivalent(new[] { "<Keyboard>/equals", "<Keyboard>/minus", "<Keyboard>/numpadPlus", "<Keyboard>/numpadMinus" },
diff --git a/unity/Assets/Tests/EditMode/MapPointerTickTests.cs b/unity/Assets/Tests/EditMode/MapPointerTickTests.cs
index d8fb05f60..dbfb630ee 100644
--- a/unity/Assets/Tests/EditMode/MapPointerTickTests.cs
+++ b/unity/Assets/Tests/EditMode/MapPointerTickTests.cs
@@ -37,7 +37,7 @@ public class MapPointerTickTests : InputTestFixture
var asked = Asked;
Pointer.IsOverUi = p => { asked.Add(p); return true; }; // true: the decision is recorded, no map needed
var pointer = Pointer;
- Controller.HoldsMouseDrag = () => pointer.RightTapCandidate; // as GameRoot wires them
+ Controller.HoldsMouseDrag = () => pointer.RightTapCandidate || pointer.LeftTapCandidate; // as GameRoot wires them
Controller.HoldsTouchDrag = () => pointer.TouchTapCandidate;
Send(Controller, "Awake"); Send(Controller, "OnEnable"); Send(Pointer, "OnEnable");
}
diff --git a/unity/Assets/Tests/EditMode/MapPressTests.cs b/unity/Assets/Tests/EditMode/MapPressTests.cs
index b1aa04a54..a94839694 100644
--- a/unity/Assets/Tests/EditMode/MapPressTests.cs
+++ b/unity/Assets/Tests/EditMode/MapPressTests.cs
@@ -70,11 +70,13 @@ public class MapPressTests
}
}
-/// <summary>#1654 review (blocker): a right press is a right click (an order) or the camera's drag pan, never both. Real
-/// mouse events go through the Input System test fixture into MapPointer (its own right-button actions) and the project's
-/// Camera actions into CameraController.Tick, wired as GameRoot wires them (HoldsMouseDrag = RightTapCandidate). The UI
-/// recorder stands in for the map: HandleRightClick asks it once per right click. Edit mode sends no OnEnable, so the
-/// test sends it.</summary>
+/// <summary>#1654 review (blocker): a mouse press is a click or the camera's drag pan, never both. That was first
+/// settled for the right button (a click is an order); since #998 the left button drags the same way, and its tests live
+/// here beside the right ones rather than in a class of their own. Real mouse events go through the Input System test
+/// fixture into MapPointer (its own left- and right-button actions) and the project's Camera actions into
+/// CameraController.Tick, wired as GameRoot wires them (HoldsMouseDrag = RightTapCandidate || LeftTapCandidate). The UI
+/// recorder stands in for the map: it is asked once per click or order. Edit mode sends no OnEnable, so the test sends
+/// it.</summary>
public class RightClickOrPanTests : InputTestFixture
{
static void Send(Object o, string message) =>
@@ -98,7 +100,7 @@ public class RightClickOrPanTests : InputTestFixture
var clicks = Clicks;
Pointer.IsOverUi = p => { clicks.Add(p); return true; }; // asked once per right click; true: no map needed
var pointer = Pointer;
- Controller.HoldsMouseDrag = () => pointer.RightTapCandidate; // as GameRoot wires it
+ Controller.HoldsMouseDrag = () => pointer.RightTapCandidate || pointer.LeftTapCandidate; // as GameRoot wires it
Send(Controller, "Awake"); Send(Controller, "OnEnable"); Send(Pointer, "OnEnable");
}
public void Frame() { Controller.Tick(0.016f); Pointer.ProcessPresses(); }
@@ -182,4 +184,108 @@ public class RightClickOrPanTests : InputTestFixture
rig.Frame();
Assert.IsEmpty(rig.Clicks, "each event is stepped at its own position: the excursion makes it a drag");
}
+
+ /// <summary>Drags the left button, the same shape as <see cref="Drag"/> does the right one.</summary>
+ Vector3 LeftDrag(Rig rig, Vector2 from, params Vector2[] path)
+ {
+ Set(mouse.position, from);
+ rig.Frame();
+ Press(mouse.leftButton);
+ rig.Frame();
+ var at = from;
+ foreach (var p in path) { Move(mouse.position, p, p - at); at = p; rig.Frame(); }
+ var held = rig.View.LookAt;
+ Release(mouse.leftButton);
+ rig.Frame();
+ return held;
+ }
+
+ /// <summary>#998, owner's ruling of 22 October 2026: dragging the map with the left button pans it once the
+ /// pointer has moved more than a few pixels, and the drag selects nothing. Today the left button selects on its
+ /// press, so a drag both selects the hex it started on and leaves the map still.</summary>
+ [Test]
+ public void ALeftDragPastTheSlopPansAndSelectsNothing()
+ {
+ using var rig = new Rig();
+ var start = rig.View.LookAt;
+ var from = new Vector2(600, 400);
+ LeftDrag(rig, from, from + new Vector2(120, 0), from + new Vector2(240, 0));
+ Assert.IsEmpty(rig.Clicks, "a left drag selects nothing");
+ Assert.AreNotEqual(start, rig.View.LookAt, "and the map pans with it");
+ }
+
+ /// <summary>The other half of the same ruling: a plain left click still selects, and does not nudge the map. It
+ /// selects on the release now rather than the press, because a press cannot be known to be a drag until it moves;
+ /// the click is still queued per press, so each physical click acts exactly once (docs/m3-rulings.md, #1617).</summary>
+ [Test]
+ public void ALeftClickInsideTheSlopStillSelectsAndDoesNotPan()
+ {
+ using var rig = new Rig();
+ var start = rig.View.LookAt;
+ var at = new Vector2(600, 400);
+ LeftDrag(rig, at, at + new Vector2(4, -3));
+ CollectionAssert.AreEqual(new[] { at }, rig.Clicks, "a click inside the slop selects where it went down");
+ Assert.AreEqual(start, rig.View.LookAt, "and the map does not move");
+ }
+
+ /// <summary>#1791 review: docs/m3-rulings.md:74's per-press guarantee, restated on the new code path. Two physical
+ /// left clicks inside one frame - press, release, press, release before a single <c>Frame()</c> - are two clicks,
+ /// each at its own position. The left click is queued from the release callback now, so the guarantee rests on the
+ /// queue rather than on one sampled position per frame.</summary>
+ [Test]
+ public void TwoLeftClicksInsideOneFrameAreTwoClicksAtTheirOwnPositions()
+ {
+ using var rig = new Rig();
+ var first = new Vector2(600, 400);
+ var second = new Vector2(300, 200);
+ Set(mouse.position, first);
+ rig.Frame();
+ Press(mouse.leftButton);
+ Release(mouse.leftButton);
+ Move(mouse.position, second);
+ Press(mouse.leftButton);
+ Release(mouse.leftButton);
+ rig.Frame();
+ CollectionAssert.AreEqual(new[] { first, second }, rig.Clicks,
+ "each physical click acts exactly once, at its own position (docs/m3-rulings.md:74)");
+ }
+
+ /// <summary>The left twin of <see cref="ARightDragOutAndBackInsideOneFrameIsNoClick"/>: a press that goes out past
+ /// the slop and comes back inside one frame is a drag, not a click, because every move is stepped at its own
+ /// position rather than only the last one being sampled.</summary>
+ [Test]
+ public void ALeftDragOutAndBackInsideOneFrameIsNoClick()
+ {
+ using var rig = new Rig();
+ var from = new Vector2(700, 400);
+ Set(mouse.position, from);
+ rig.Frame();
+ // one slow frame: press, out past the slop, back and release, all before the next frame
+ Press(mouse.leftButton);
+ Move(mouse.position, from + new Vector2(200, 0));
+ Move(mouse.position, from);
+ Release(mouse.leftButton);
+ rig.Frame();
+ Assert.IsEmpty(rig.Clicks, "each event is stepped at its own position: the excursion makes it a drag");
+ }
+
+ /// <summary>#1791 review: until #998 a left drag could never pan, so dragging a panel's scrollbar was safe by
+ /// construction. Now it relies on the <c>dragFromUi</c> latch (<c>Gather</c>, which answers the UI question once on
+ /// the button's way down, and <c>Step</c>, which zeroes the drag when it is set), and nothing pinned that for the
+ /// left button.
+ /// <para>The second half is what keeps this from passing vacuously: the identical drag begun on the map does pan,
+ /// so the first half is the latch holding, not the left button failing to pan at all.</para></summary>
+ [Test]
+ public void ALeftDragStartingOverTheUiNeverPans()
+ {
+ using var rig = new Rig();
+ rig.Controller.IsOverUi = p => p.y > 1000; // the top of the screen is a panel
+ var start = rig.View.LookAt;
+ var onUi = new Vector2(600, 1200);
+ LeftDrag(rig, onUi, onUi + new Vector2(120, 0), onUi + new Vector2(240, 0));
+ Assert.AreEqual(start, rig.View.LookAt, "a left drag that began on a panel does not pan the map");
+ var onMap = new Vector2(600, 400);
+ LeftDrag(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");
+ }
}