Hide cursor and render the placeholder directly

This commit is contained in:
teinarss
2019-04-14 20:23:09 +02:00
committed by reaperrr
parent 09f4b69aef
commit e801537d96
9 changed files with 33 additions and 13 deletions

View File

@@ -21,5 +21,6 @@ namespace OpenRA
IEnumerable<IRenderable> Render(WorldRenderer wr, World world);
IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world);
string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi);
void Deactivate();
}
}

View File

@@ -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)
{

View File

@@ -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();

View File

@@ -29,6 +29,7 @@ namespace OpenRA.Mods.Common.Orders
IEnumerable<IRenderable> IOrderGenerator.Render(WorldRenderer wr, World world) { return Render(wr, world); }
IEnumerable<IRenderable> 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<IRenderable> Render(WorldRenderer wr, World world);

View File

@@ -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.")]

View File

@@ -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.")]

View File

@@ -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<IRenderable> IOrderGenerator.Render(WorldRenderer wr, World world) { yield break; }
@@ -121,6 +121,8 @@ namespace OpenRA.Mods.Common.Traits
return Enumerable.Empty<IRenderable>();
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<IRenderable>(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)

View File

@@ -136,8 +136,6 @@ Cursors:
sell-vehicle:
Start: 154
Length: 24
invisible:
Start: 28
mouse3.shp: cursor
default:
Start: 0

View File

@@ -200,8 +200,6 @@ Cursors:
sell2:
Start: 148
Length: 12
invisible:
Start: 34
nopower.shp: cursor
powerdown-blocked:
Start: 0