Easier actor selection in game by actor bounds center
This commit is contained in:
@@ -37,23 +37,26 @@ namespace OpenRA.Orders
|
|||||||
public GenericSelectTarget(Actor subject, string order, string cursor, MouseButton button)
|
public GenericSelectTarget(Actor subject, string order, string cursor, MouseButton button)
|
||||||
: this(new Actor[] { subject }, order, cursor, button) { }
|
: this(new Actor[] { subject }, order, cursor, button) { }
|
||||||
|
|
||||||
public override IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
|
public override IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button != ExpectedButton)
|
if (mi.Button != ExpectedButton)
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
return OrderInner(world, xy, mi);
|
return OrderInner(world, cell, mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual IEnumerable<Order> OrderInner(World world, CPos xy, MouseInput mi)
|
protected virtual IEnumerable<Order> OrderInner(World world, CPos cell, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == ExpectedButton && world.Map.Contains(xy))
|
if (mi.Button == ExpectedButton && world.Map.Contains(cell))
|
||||||
{
|
{
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
foreach (var subject in Subjects)
|
foreach (var subject in Subjects)
|
||||||
yield return new Order(OrderName, subject, false) { TargetLocation = xy };
|
yield return new Order(OrderName, subject, false) { TargetLocation = cell };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string GetCursor(World world, CPos xy, MouseInput mi) { return world.Map.Contains(xy) ? Cursor : "generic-blocked"; }
|
public override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
|
{
|
||||||
|
return world.Map.Contains(cell) ? Cursor : "generic-blocked";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
public interface IOrderGenerator
|
public interface IOrderGenerator
|
||||||
{
|
{
|
||||||
IEnumerable<Order> Order(World world, CPos xy, MouseInput mi);
|
IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi);
|
||||||
void Tick(World world);
|
void Tick(World world);
|
||||||
IEnumerable<IRenderable> Render(WorldRenderer wr, World world);
|
IEnumerable<IRenderable> Render(WorldRenderer wr, World world);
|
||||||
IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr, World world);
|
IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr, World world);
|
||||||
string GetCursor(World world, CPos xy, MouseInput mi);
|
string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,31 +17,31 @@ namespace OpenRA.Orders
|
|||||||
{
|
{
|
||||||
public class UnitOrderGenerator : IOrderGenerator
|
public class UnitOrderGenerator : IOrderGenerator
|
||||||
{
|
{
|
||||||
static Target TargetForInput(World world, CPos xy, MouseInput mi)
|
static Target TargetForInput(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
var actor = world.ScreenMap.ActorsAt(mi)
|
var actor = world.ScreenMap.ActorsAt(mi)
|
||||||
.Where(a => !world.FogObscures(a) && a.Info.HasTraitInfo<ITargetableInfo>())
|
.Where(a => !world.FogObscures(a) && a.Info.HasTraitInfo<ITargetableInfo>())
|
||||||
.WithHighestSelectionPriority();
|
.WithHighestSelectionPriority(worldPixel);
|
||||||
|
|
||||||
if (actor != null)
|
if (actor != null)
|
||||||
return Target.FromActor(actor);
|
return Target.FromActor(actor);
|
||||||
|
|
||||||
var frozen = world.ScreenMap.FrozenActorsAt(world.RenderPlayer, mi)
|
var frozen = world.ScreenMap.FrozenActorsAt(world.RenderPlayer, mi)
|
||||||
.Where(a => a.Info.HasTraitInfo<ITargetableInfo>() && a.Visible && a.HasRenderables)
|
.Where(a => a.Info.HasTraitInfo<ITargetableInfo>() && a.Visible && a.HasRenderables)
|
||||||
.WithHighestSelectionPriority();
|
.WithHighestSelectionPriority(worldPixel);
|
||||||
|
|
||||||
if (frozen != null)
|
if (frozen != null)
|
||||||
return Target.FromFrozenActor(frozen);
|
return Target.FromFrozenActor(frozen);
|
||||||
|
|
||||||
return Target.FromCell(world, xy);
|
return Target.FromCell(world, cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
|
public virtual IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
var target = TargetForInput(world, xy, mi);
|
var target = TargetForInput(world, cell, worldPixel, mi);
|
||||||
var actorsAt = world.ActorMap.GetActorsAt(xy).ToList();
|
var actorsAt = world.ActorMap.GetActorsAt(cell).ToList();
|
||||||
var orders = world.Selection.Actors
|
var orders = world.Selection.Actors
|
||||||
.Select(a => OrderForUnit(a, target, actorsAt, xy, mi))
|
.Select(a => OrderForUnit(a, target, actorsAt, cell, mi))
|
||||||
.Where(o => o != null)
|
.Where(o => o != null)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
@@ -62,18 +62,18 @@ namespace OpenRA.Orders
|
|||||||
public virtual IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
public virtual IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||||
public virtual IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr, World world) { yield break; }
|
public virtual IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr, World world) { yield break; }
|
||||||
|
|
||||||
public virtual string GetCursor(World world, CPos xy, MouseInput mi)
|
public virtual string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
var useSelect = false;
|
var useSelect = false;
|
||||||
var target = TargetForInput(world, xy, mi);
|
var target = TargetForInput(world, cell, worldPixel, mi);
|
||||||
var actorsAt = world.ActorMap.GetActorsAt(xy).ToList();
|
var actorsAt = world.ActorMap.GetActorsAt(cell).ToList();
|
||||||
|
|
||||||
if (target.Type == TargetType.Actor && target.Actor.Info.HasTraitInfo<SelectableInfo>() &&
|
if (target.Type == TargetType.Actor && target.Actor.Info.HasTraitInfo<SelectableInfo>() &&
|
||||||
(mi.Modifiers.HasModifier(Modifiers.Shift) || !world.Selection.Actors.Any()))
|
(mi.Modifiers.HasModifier(Modifiers.Shift) || !world.Selection.Actors.Any()))
|
||||||
useSelect = true;
|
useSelect = true;
|
||||||
|
|
||||||
var ordersWithCursor = world.Selection.Actors
|
var ordersWithCursor = world.Selection.Actors
|
||||||
.Select(a => OrderForUnit(a, target, actorsAt, xy, mi))
|
.Select(a => OrderForUnit(a, target, actorsAt, cell, mi))
|
||||||
.Where(o => o != null && o.Cursor != null);
|
.Where(o => o != null && o.Cursor != null);
|
||||||
|
|
||||||
var cursorOrder = ordersWithCursor.MaxByOrDefault(o => o.Order.OrderPriority);
|
var cursorOrder = ordersWithCursor.MaxByOrDefault(o => o.Order.OrderPriority);
|
||||||
@@ -84,14 +84,14 @@ namespace OpenRA.Orders
|
|||||||
// Used for classic mouse orders, determines whether or not action at xy is move or select
|
// Used for classic mouse orders, determines whether or not action at xy is move or select
|
||||||
public static bool InputOverridesSelection(World world, int2 xy, MouseInput mi)
|
public static bool InputOverridesSelection(World world, int2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
var actor = world.ScreenMap.ActorsAt(xy).WithHighestSelectionPriority();
|
var actor = world.ScreenMap.ActorsAt(xy).WithHighestSelectionPriority(xy);
|
||||||
if (actor == null)
|
if (actor == null)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
var target = Target.FromActor(actor);
|
var target = Target.FromActor(actor);
|
||||||
var cell = world.Map.CellContaining(target.CenterPosition);
|
var cell = world.Map.CellContaining(target.CenterPosition);
|
||||||
var actorsAt = world.ActorMap.GetActorsAt(cell).ToList();
|
var actorsAt = world.ActorMap.GetActorsAt(cell).ToList();
|
||||||
var underCursor = world.Selection.Actors.WithHighestSelectionPriority();
|
var underCursor = world.Selection.Actors.WithHighestSelectionPriority(xy);
|
||||||
|
|
||||||
var o = OrderForUnit(underCursor, target, actorsAt, cell, mi);
|
var o = OrderForUnit(underCursor, target, actorsAt, cell, mi);
|
||||||
if (o != null && o.Order.OverrideSelection)
|
if (o != null && o.Order.OverrideSelection)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace OpenRA.Traits
|
namespace OpenRA.Traits
|
||||||
@@ -43,14 +44,22 @@ namespace OpenRA.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Actor WithHighestSelectionPriority(this IEnumerable<Actor> actors)
|
public static Actor WithHighestSelectionPriority(this IEnumerable<Actor> actors, int2 selectionPixel)
|
||||||
{
|
{
|
||||||
return actors.MaxByOrDefault(a => a.Info.SelectionPriority());
|
return actors.MaxByOrDefault(a => CalculateActorSelectionPriority(a.Info, a.Bounds, selectionPixel));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FrozenActor WithHighestSelectionPriority(this IEnumerable<FrozenActor> actors)
|
public static FrozenActor WithHighestSelectionPriority(this IEnumerable<FrozenActor> actors, int2 selectionPixel)
|
||||||
{
|
{
|
||||||
return actors.MaxByOrDefault(a => a.Info.SelectionPriority());
|
return actors.MaxByOrDefault(a => CalculateActorSelectionPriority(a.Info, a.Bounds, selectionPixel));
|
||||||
|
}
|
||||||
|
|
||||||
|
static long CalculateActorSelectionPriority(ActorInfo info, Rectangle bounds, int2 selectionPixel)
|
||||||
|
{
|
||||||
|
var centerPixel = new int2(bounds.X, bounds.Y);
|
||||||
|
var pixelDistance = (centerPixel - selectionPixel).Length;
|
||||||
|
|
||||||
|
return ((long)-pixelDistance << 32) + info.SelectionPriority();
|
||||||
}
|
}
|
||||||
|
|
||||||
static readonly Actor[] NoActors = { };
|
static readonly Actor[] NoActors = { };
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ namespace OpenRA.Widgets
|
|||||||
if (multiClick)
|
if (multiClick)
|
||||||
{
|
{
|
||||||
var unit = World.ScreenMap.ActorsAt(xy)
|
var unit = World.ScreenMap.ActorsAt(xy)
|
||||||
.WithHighestSelectionPriority();
|
.WithHighestSelectionPriority(xy);
|
||||||
|
|
||||||
if (unit != null && unit.Owner == (World.RenderPlayer ?? World.LocalPlayer))
|
if (unit != null && unit.Owner == (World.RenderPlayer ?? World.LocalPlayer))
|
||||||
{
|
{
|
||||||
@@ -193,7 +193,8 @@ namespace OpenRA.Widgets
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var cell = worldRenderer.Viewport.ViewToWorld(mi.Location);
|
var cell = worldRenderer.Viewport.ViewToWorld(mi.Location);
|
||||||
var orders = world.OrderGenerator.Order(world, cell, mi).ToArray();
|
var worldPixel = worldRenderer.Viewport.ViewToWorldPx(mi.Location);
|
||||||
|
var orders = world.OrderGenerator.Order(world, cell, worldPixel, mi).ToArray();
|
||||||
world.PlayVoiceForOrders(orders);
|
world.PlayVoiceForOrders(orders);
|
||||||
|
|
||||||
var flashed = false;
|
var flashed = false;
|
||||||
@@ -231,6 +232,7 @@ namespace OpenRA.Widgets
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
var cell = worldRenderer.Viewport.ViewToWorld(screenPos);
|
var cell = worldRenderer.Viewport.ViewToWorld(screenPos);
|
||||||
|
var worldPixel = worldRenderer.Viewport.ViewToWorldPx(screenPos);
|
||||||
|
|
||||||
var mi = new MouseInput
|
var mi = new MouseInput
|
||||||
{
|
{
|
||||||
@@ -239,7 +241,7 @@ namespace OpenRA.Widgets
|
|||||||
Modifiers = Game.GetModifierKeys()
|
Modifiers = Game.GetModifierKeys()
|
||||||
};
|
};
|
||||||
|
|
||||||
return World.OrderGenerator.GetCursor(World, cell, mi);
|
return World.OrderGenerator.GetCursor(World, cell, worldPixel, mi);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,20 +15,23 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
{
|
{
|
||||||
public class BeaconOrderGenerator : IOrderGenerator
|
public class BeaconOrderGenerator : IOrderGenerator
|
||||||
{
|
{
|
||||||
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
|
public IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button != MouseButton.Left)
|
if (mi.Button != MouseButton.Left)
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
else if (!world.ShroudObscures(xy))
|
else if (!world.ShroudObscures(cell))
|
||||||
{
|
{
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
yield return new Order("PlaceBeacon", world.LocalPlayer.PlayerActor, false) { TargetLocation = xy, SuppressVisualFeedback = true };
|
yield return new Order("PlaceBeacon", world.LocalPlayer.PlayerActor, false) { TargetLocation = cell, SuppressVisualFeedback = true };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Tick(World world) { }
|
public virtual void Tick(World world) { }
|
||||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||||
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr, World world) { yield break; }
|
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr, World world) { yield break; }
|
||||||
public string GetCursor(World world, CPos xy, MouseInput mi) { return !world.ShroudObscures(xy) ? "ability" : "generic-blocked"; }
|
public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
|
{
|
||||||
|
return !world.ShroudObscures(cell) ? "ability" : "generic-blocked";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
this.order = order;
|
this.order = order;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
|
public IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Right)
|
if (mi.Button == MouseButton.Right)
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
@@ -64,7 +64,7 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||||
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr, World world) { yield break; }
|
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr, World world) { yield break; }
|
||||||
|
|
||||||
public string GetCursor(World world, CPos xy, MouseInput mi)
|
public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
mi.Button = MouseButton.Left;
|
mi.Button = MouseButton.Left;
|
||||||
return cursor + (OrderInner(world, mi).Any() ? "" : "-blocked");
|
return cursor + (OrderInner(world, mi).Any() ? "" : "-blocked");
|
||||||
|
|||||||
@@ -62,12 +62,12 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
buildingInfluence = producer.World.WorldActor.Trait<BuildingInfluence>();
|
buildingInfluence = producer.World.WorldActor.Trait<BuildingInfluence>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
|
public IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Right)
|
if (mi.Button == MouseButton.Right)
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
|
|
||||||
var ret = InnerOrder(world, xy, mi).ToArray();
|
var ret = InnerOrder(world, cell, mi).ToArray();
|
||||||
|
|
||||||
// If there was a successful placement order
|
// If there was a successful placement order
|
||||||
if (ret.Any(o => o.OrderString == "PlaceBuilding"
|
if (ret.Any(o => o.OrderString == "PlaceBuilding"
|
||||||
@@ -78,7 +78,7 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<Order> InnerOrder(World world, CPos xy, MouseInput mi)
|
IEnumerable<Order> InnerOrder(World world, CPos cell, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (world.Paused)
|
if (world.Paused)
|
||||||
yield break;
|
yield break;
|
||||||
@@ -86,7 +86,7 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
if (mi.Button == MouseButton.Left)
|
if (mi.Button == MouseButton.Left)
|
||||||
{
|
{
|
||||||
var orderType = "PlaceBuilding";
|
var orderType = "PlaceBuilding";
|
||||||
var topLeft = xy - FootprintUtils.AdjustForBuildingSize(buildingInfo);
|
var topLeft = cell - FootprintUtils.AdjustForBuildingSize(buildingInfo);
|
||||||
|
|
||||||
var plugInfo = world.Map.Rules.Actors[building].TraitInfoOrDefault<PlugInfo>();
|
var plugInfo = world.Map.Rules.Actors[building].TraitInfoOrDefault<PlugInfo>();
|
||||||
if (plugInfo != null)
|
if (plugInfo != null)
|
||||||
@@ -219,7 +219,7 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetCursor(World world, CPos xy, MouseInput mi) { return "default"; }
|
public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { return "default"; }
|
||||||
|
|
||||||
IEnumerable<Order> ClearBlockersOrders(World world, CPos topLeft)
|
IEnumerable<Order> ClearBlockersOrders(World world, CPos topLeft)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
{
|
{
|
||||||
public class RepairOrderGenerator : IOrderGenerator
|
public class RepairOrderGenerator : IOrderGenerator
|
||||||
{
|
{
|
||||||
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
|
public IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Right)
|
if (mi.Button == MouseButton.Right)
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
@@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||||
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr, World world) { yield break; }
|
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr, World world) { yield break; }
|
||||||
|
|
||||||
public string GetCursor(World world, CPos xy, MouseInput mi)
|
public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
mi.Button = MouseButton.Left;
|
mi.Button = MouseButton.Left;
|
||||||
return OrderInner(world, mi).Any()
|
return OrderInner(world, mi).Any()
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string GetCursor(World world, CPos xy, MouseInput mi)
|
public override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (!Subjects.Any())
|
if (!Subjects.Any())
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -125,11 +125,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
tile = world.Map.SequenceProvider.GetSequence("overlay", "target-select").GetSprite(0);
|
tile = world.Map.SequenceProvider.GetSequence("overlay", "target-select").GetSprite(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
|
public IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
if (mi.Button == MouseButton.Left && power.UnitsInRange(xy).Any())
|
if (mi.Button == MouseButton.Left && power.UnitsInRange(cell).Any())
|
||||||
yield return new Order(order, manager.Self, false) { TargetLocation = xy, SuppressVisualFeedback = true };
|
yield return new Order(order, manager.Self, false) { TargetLocation = cell, SuppressVisualFeedback = true };
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(World world)
|
public void Tick(World world)
|
||||||
@@ -155,9 +155,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
yield return new SpriteRenderable(tile, wr.World.Map.CenterOfCell(t), WVec.Zero, -511, pal, 1f, true);
|
yield return new SpriteRenderable(tile, wr.World.Map.CenterOfCell(t), WVec.Zero, -511, pal, 1f, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetCursor(World world, CPos xy, MouseInput mi)
|
public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
return power.UnitsInRange(xy).Any() ? "ability" : "move-blocked";
|
return power.UnitsInRange(cell).Any() ? "ability" : "move-blocked";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -267,11 +267,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
expectedButton = button;
|
expectedButton = button;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
|
public IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
if (mi.Button == expectedButton && world.Map.Contains(xy))
|
if (mi.Button == expectedButton && world.Map.Contains(cell))
|
||||||
yield return new Order(order, manager.Self, false) { TargetLocation = xy, SuppressVisualFeedback = true };
|
yield return new Order(order, manager.Self, false) { TargetLocation = cell, SuppressVisualFeedback = true };
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Tick(World world)
|
public virtual void Tick(World world)
|
||||||
@@ -283,6 +283,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||||
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr, World world) { yield break; }
|
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr, World world) { yield break; }
|
||||||
public string GetCursor(World world, CPos xy, MouseInput mi) { return world.Map.Contains(xy) ? cursor : "generic-blocked"; }
|
public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
|
{
|
||||||
|
return world.Map.Contains(cell) ? cursor : "generic-blocked";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -219,7 +219,8 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
var cell = MinimapPixelToCell(pos);
|
var cell = MinimapPixelToCell(pos);
|
||||||
var location = worldRenderer.Viewport.WorldToViewPx(worldRenderer.ScreenPxPosition(world.Map.CenterOfCell(cell)));
|
var worldPixel = worldRenderer.ScreenPxPosition(world.Map.CenterOfCell(cell));
|
||||||
|
var location = worldRenderer.Viewport.WorldToViewPx(worldPixel);
|
||||||
|
|
||||||
var mi = new MouseInput
|
var mi = new MouseInput
|
||||||
{
|
{
|
||||||
@@ -228,7 +229,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
Modifiers = Game.GetModifierKeys()
|
Modifiers = Game.GetModifierKeys()
|
||||||
};
|
};
|
||||||
|
|
||||||
var cursor = world.OrderGenerator.GetCursor(world, cell, mi);
|
var cursor = world.OrderGenerator.GetCursor(world, cell, worldPixel, mi);
|
||||||
if (cursor == null)
|
if (cursor == null)
|
||||||
return "default";
|
return "default";
|
||||||
|
|
||||||
|
|||||||
@@ -128,9 +128,10 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var underCursor = world.ScreenMap.ActorsAt(worldRenderer.Viewport.ViewToWorldPx(Viewport.LastMousePos))
|
var worldPixel = worldRenderer.Viewport.ViewToWorldPx(Viewport.LastMousePos);
|
||||||
|
var underCursor = world.ScreenMap.ActorsAt(worldPixel)
|
||||||
.Where(a => !world.FogObscures(a) && a.Info.HasTraitInfo<ITooltipInfo>())
|
.Where(a => !world.FogObscures(a) && a.Info.HasTraitInfo<ITooltipInfo>())
|
||||||
.WithHighestSelectionPriority();
|
.WithHighestSelectionPriority(worldPixel);
|
||||||
|
|
||||||
if (underCursor != null)
|
if (underCursor != null)
|
||||||
{
|
{
|
||||||
@@ -140,9 +141,9 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var frozen = world.ScreenMap.FrozenActorsAt(world.RenderPlayer, worldRenderer.Viewport.ViewToWorldPx(Viewport.LastMousePos))
|
var frozen = world.ScreenMap.FrozenActorsAt(world.RenderPlayer, worldPixel)
|
||||||
.Where(a => a.TooltipInfo != null && a.IsValid)
|
.Where(a => a.TooltipInfo != null && a.IsValid)
|
||||||
.WithHighestSelectionPriority();
|
.WithHighestSelectionPriority(worldPixel);
|
||||||
|
|
||||||
if (frozen != null)
|
if (frozen != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ namespace OpenRA.Mods.RA.Traits
|
|||||||
tileBlocked = self.World.Map.SequenceProvider.GetSequence("overlay", "build-invalid").GetSprite(0);
|
tileBlocked = self.World.Map.SequenceProvider.GetSequence("overlay", "build-invalid").GetSprite(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
|
public IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == Game.Settings.Game.MouseButtonPreference.Cancel)
|
if (mi.Button == Game.Settings.Game.MouseButtonPreference.Cancel)
|
||||||
{
|
{
|
||||||
@@ -160,7 +160,7 @@ namespace OpenRA.Mods.RA.Traits
|
|||||||
if (mi.Button == Game.Settings.Game.MouseButtonPreference.Action && underCursor == null)
|
if (mi.Button == Game.Settings.Game.MouseButtonPreference.Action && underCursor == null)
|
||||||
{
|
{
|
||||||
minelayer.World.CancelInputMode();
|
minelayer.World.CancelInputMode();
|
||||||
yield return new Order("PlaceMinefield", minelayer, false) { TargetLocation = xy };
|
yield return new Order("PlaceMinefield", minelayer, false) { TargetLocation = cell };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +190,10 @@ namespace OpenRA.Mods.RA.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetCursor(World world, CPos xy, MouseInput mi) { lastMousePos = xy; return "ability"; } /* TODO */
|
public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
|
{
|
||||||
|
lastMousePos = cell; return "ability"; /* TODO */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BeginMinefieldOrderTargeter : IOrderTargeter
|
class BeginMinefieldOrderTargeter : IOrderTargeter
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ namespace OpenRA.Mods.RA.Traits
|
|||||||
this.self = self;
|
this.self = self;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
|
public IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == Game.Settings.Game.MouseButtonPreference.Cancel)
|
if (mi.Button == Game.Settings.Game.MouseButtonPreference.Cancel)
|
||||||
{
|
{
|
||||||
@@ -159,11 +159,11 @@ namespace OpenRA.Mods.RA.Traits
|
|||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.IsInWorld && self.Location != xy
|
if (self.IsInWorld && self.Location != cell
|
||||||
&& self.Trait<PortableChrono>().CanTeleport && self.Owner.Shroud.IsExplored(xy))
|
&& self.Trait<PortableChrono>().CanTeleport && self.Owner.Shroud.IsExplored(cell))
|
||||||
{
|
{
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
yield return new Order("PortableChronoTeleport", self, mi.Modifiers.HasModifier(Modifiers.Shift)) { TargetLocation = xy };
|
yield return new Order("PortableChronoTeleport", self, mi.Modifiers.HasModifier(Modifiers.Shift)) { TargetLocation = cell };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,10 +194,10 @@ namespace OpenRA.Mods.RA.Traits
|
|||||||
Color.FromArgb(96, Color.Black));
|
Color.FromArgb(96, Color.Black));
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetCursor(World world, CPos xy, MouseInput mi)
|
public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (self.IsInWorld && self.Location != xy
|
if (self.IsInWorld && self.Location != cell
|
||||||
&& self.Trait<PortableChrono>().CanTeleport && self.Owner.Shroud.IsExplored(xy))
|
&& self.Trait<PortableChrono>().CanTeleport && self.Owner.Shroud.IsExplored(cell))
|
||||||
return "chrono-target";
|
return "chrono-target";
|
||||||
else
|
else
|
||||||
return "move-blocked";
|
return "move-blocked";
|
||||||
|
|||||||
@@ -115,11 +115,11 @@ namespace OpenRA.Mods.RA.Traits
|
|||||||
tile = world.Map.SequenceProvider.GetSequence("overlay", "target-select").GetSprite(0);
|
tile = world.Map.SequenceProvider.GetSequence("overlay", "target-select").GetSprite(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
|
public IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
if (mi.Button == MouseButton.Left)
|
if (mi.Button == MouseButton.Left)
|
||||||
world.OrderGenerator = new SelectDestination(world, order, manager, power, xy);
|
world.OrderGenerator = new SelectDestination(world, order, manager, power, cell);
|
||||||
|
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
@@ -150,7 +150,7 @@ namespace OpenRA.Mods.RA.Traits
|
|||||||
yield return new SpriteRenderable(tile, wr.World.Map.CenterOfCell(t), WVec.Zero, -511, pal, 1f, true);
|
yield return new SpriteRenderable(tile, wr.World.Map.CenterOfCell(t), WVec.Zero, -511, pal, 1f, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetCursor(World world, CPos xy, MouseInput mi)
|
public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
return "chrono-select";
|
return "chrono-select";
|
||||||
}
|
}
|
||||||
@@ -179,7 +179,7 @@ namespace OpenRA.Mods.RA.Traits
|
|||||||
sourceTile = world.Map.SequenceProvider.GetSequence("overlay", "target-select").GetSprite(0);
|
sourceTile = world.Map.SequenceProvider.GetSequence("overlay", "target-select").GetSprite(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
|
public IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Right)
|
if (mi.Button == MouseButton.Right)
|
||||||
{
|
{
|
||||||
@@ -187,7 +187,7 @@ namespace OpenRA.Mods.RA.Traits
|
|||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var ret = OrderInner(xy).FirstOrDefault();
|
var ret = OrderInner(cell).FirstOrDefault();
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
@@ -281,9 +281,9 @@ namespace OpenRA.Mods.RA.Traits
|
|||||||
return canTeleport;
|
return canTeleport;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetCursor(World world, CPos xy, MouseInput mi)
|
public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
{
|
{
|
||||||
return IsValidTarget(xy) ? "chrono-target" : "move-blocked";
|
return IsValidTarget(cell) ? "chrono-target" : "move-blocked";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user