diff --git a/OpenRA.Game/Orders/IOrderGenerator.cs b/OpenRA.Game/Orders/IOrderGenerator.cs index 627833915a..9fad38b603 100644 --- a/OpenRA.Game/Orders/IOrderGenerator.cs +++ b/OpenRA.Game/Orders/IOrderGenerator.cs @@ -21,5 +21,6 @@ namespace OpenRA IEnumerable Render(WorldRenderer wr, World world); IEnumerable RenderAboveShroud(WorldRenderer wr, World world); string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi); + void Deactivate(); } } diff --git a/OpenRA.Game/Orders/UnitOrderGenerator.cs b/OpenRA.Game/Orders/UnitOrderGenerator.cs index 706280df6e..f141f47c40 100644 --- a/OpenRA.Game/Orders/UnitOrderGenerator.cs +++ b/OpenRA.Game/Orders/UnitOrderGenerator.cs @@ -84,6 +84,8 @@ namespace OpenRA.Orders return cursorOrder != null ? cursorOrder.Cursor : (useSelect ? "select" : "default"); } + public void Deactivate() { } + // Used for classic mouse orders, determines whether or not action at xy is move or select public virtual bool InputOverridesSelection(WorldRenderer wr, World world, int2 xy, MouseInput mi) { diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index f6c0669d74..f56054cd77 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -148,6 +148,9 @@ namespace OpenRA set { Sync.AssertUnsynced("The current order generator may not be changed from synced code"); + if (orderGenerator != null) + orderGenerator.Deactivate(); + orderGenerator = value; } } @@ -544,6 +547,9 @@ namespace OpenRA { Disposing = true; + if (OrderGenerator != null) + OrderGenerator.Deactivate(); + frameEndActions.Clear(); Game.Sound.StopAudio(); diff --git a/OpenRA.Mods.Common/Orders/OrderGenerator.cs b/OpenRA.Mods.Common/Orders/OrderGenerator.cs index 2bcd56ff76..af90a40b2a 100644 --- a/OpenRA.Mods.Common/Orders/OrderGenerator.cs +++ b/OpenRA.Mods.Common/Orders/OrderGenerator.cs @@ -29,6 +29,7 @@ namespace OpenRA.Mods.Common.Orders IEnumerable IOrderGenerator.Render(WorldRenderer wr, World world) { return Render(wr, world); } IEnumerable IOrderGenerator.RenderAboveShroud(WorldRenderer wr, World world) { return RenderAboveShroud(wr, world); } string IOrderGenerator.GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { return GetCursor(world, cell, worldPixel, mi); } + void IOrderGenerator.Deactivate() { } protected abstract void Tick(World world); protected abstract IEnumerable Render(WorldRenderer wr, World world); diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs index c05c0e3541..98e5df3c5f 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits [Desc("Enables the player directional targeting")] public readonly bool UseDirectionalTarget = false; - [Desc("Placeholder cursor animation for the target cursor when the real cursor is invisible.")] + [Desc("Placeholder cursor animation for the target cursor when using directional targeting.")] public readonly string TargetPlaceholderCursorAnimation = null; [Desc("Palette for placeholder cursor animation.")] diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/ParatroopersPower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/ParatroopersPower.cs index 29e377d3a0..6a91befe4b 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/ParatroopersPower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/ParatroopersPower.cs @@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Traits [Desc("Enables the player directional targeting")] public readonly bool UseDirectionalTarget = false; - [Desc("Placeholder cursor animation for the target cursor when the real cursor is invisible.")] + [Desc("Placeholder cursor animation for the target cursor when using directional targeting.")] public readonly string TargetPlaceholderCursorAnimation = null; [Desc("Palette for placeholder cursor animation.")] diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/SelectDirectionalTarget.cs b/OpenRA.Mods.Common/Traits/SupportPowers/SelectDirectionalTarget.cs index 3d4bb71cda..59b3ef98b8 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/SelectDirectionalTarget.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/SelectDirectionalTarget.cs @@ -30,10 +30,11 @@ namespace OpenRA.Mods.Common.Traits readonly Arrow[] directionArrows; CPos targetCell; - int2 location; + int2 targetLocation; int2 dragLocation; bool activated; bool dragStarted; + bool hideMouse = true; Arrow currentArrow; public SelectDirectionalTarget(World world, string order, SupportPowerManager manager, string cursor, string targetPlaceholderCursorAnimation, @@ -67,7 +68,7 @@ namespace OpenRA.Mods.Common.Traits if (!activated) { targetCell = cell; - location = mi.Location; + targetLocation = mi.Location; activated = true; } @@ -80,11 +81,10 @@ namespace OpenRA.Mods.Common.Traits if (mi.Event == MouseInputEvent.Move) { dragLocation = mi.Location; - var angle = AngleBetween(location, dragLocation); + + var angle = AngleBetween(targetLocation, dragLocation); currentArrow = GetArrow(angle); dragStarted = true; - - yield break; } if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Up) @@ -110,7 +110,7 @@ namespace OpenRA.Mods.Common.Traits bool IsOutsideDragZone { - get { return dragStarted && (dragLocation - location).Length > 20; } + get { return dragStarted && (dragLocation - targetLocation).Length > 20; } } IEnumerable IOrderGenerator.Render(WorldRenderer wr, World world) { yield break; } @@ -121,6 +121,8 @@ namespace OpenRA.Mods.Common.Traits return Enumerable.Empty(); var targetPalette = wr.Palette(targetPlaceholderCursorPalette); + + var location = activated ? targetLocation : Viewport.LastMousePos; var worldPx = wr.Viewport.ViewToWorldPx(location); var worldPos = wr.ProjectedPosition(worldPx); var renderables = new List(targetCursor.Render(worldPos, WVec.Zero, -511, targetPalette, 1 / wr.Viewport.Zoom)); @@ -131,10 +133,22 @@ namespace OpenRA.Mods.Common.Traits renderables.Add(new SpriteRenderable(currentArrow.Sprite, worldPos, WVec.Zero, -511, directionPalette, 1 / wr.Viewport.Zoom, true)); } + if (hideMouse) + { + hideMouse = false; + Game.RunAfterTick(() => Game.HideCursor = true); + } + return renderables; } - string IOrderGenerator.GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { return activated ? "invisible" : cursor; } + string IOrderGenerator.GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { return cursor; } + + void IOrderGenerator.Deactivate() + { + if (activated) + Game.HideCursor = false; + } // Starting at (0, -1) and rotating in CCW static double AngleBetween(int2 p1, int2 p2) diff --git a/mods/cnc/cursors.yaml b/mods/cnc/cursors.yaml index 985826d2e3..7c28d0924e 100644 --- a/mods/cnc/cursors.yaml +++ b/mods/cnc/cursors.yaml @@ -136,8 +136,6 @@ Cursors: sell-vehicle: Start: 154 Length: 24 - invisible: - Start: 28 mouse3.shp: cursor default: Start: 0 diff --git a/mods/ra/cursors.yaml b/mods/ra/cursors.yaml index 865ae30e91..83734569e6 100644 --- a/mods/ra/cursors.yaml +++ b/mods/ra/cursors.yaml @@ -200,8 +200,6 @@ Cursors: sell2: Start: 148 Length: 12 - invisible: - Start: 34 nopower.shp: cursor powerdown-blocked: Start: 0