Easier actor selection in game by actor bounds center

This commit is contained in:
atlimit8
2015-11-15 11:30:40 -06:00
parent 387d0d0e3f
commit b07cd683e8
17 changed files with 100 additions and 75 deletions

View File

@@ -15,20 +15,23 @@ namespace OpenRA.Mods.Common.Orders
{
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)
world.CancelInputMode();
else if (!world.ShroudObscures(xy))
else if (!world.ShroudObscures(cell))
{
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 IEnumerable<IRenderable> Render(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";
}
}
}

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Orders
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)
world.CancelInputMode();
@@ -64,7 +64,7 @@ namespace OpenRA.Mods.Common.Orders
public IEnumerable<IRenderable> Render(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;
return cursor + (OrderInner(world, mi).Any() ? "" : "-blocked");

View File

@@ -62,12 +62,12 @@ namespace OpenRA.Mods.Common.Orders
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)
world.CancelInputMode();
var ret = InnerOrder(world, xy, mi).ToArray();
var ret = InnerOrder(world, cell, mi).ToArray();
// If there was a successful placement order
if (ret.Any(o => o.OrderString == "PlaceBuilding"
@@ -78,7 +78,7 @@ namespace OpenRA.Mods.Common.Orders
return ret;
}
IEnumerable<Order> InnerOrder(World world, CPos xy, MouseInput mi)
IEnumerable<Order> InnerOrder(World world, CPos cell, MouseInput mi)
{
if (world.Paused)
yield break;
@@ -86,7 +86,7 @@ namespace OpenRA.Mods.Common.Orders
if (mi.Button == MouseButton.Left)
{
var orderType = "PlaceBuilding";
var topLeft = xy - FootprintUtils.AdjustForBuildingSize(buildingInfo);
var topLeft = cell - FootprintUtils.AdjustForBuildingSize(buildingInfo);
var plugInfo = world.Map.Rules.Actors[building].TraitInfoOrDefault<PlugInfo>();
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)
{

View File

@@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Orders
{
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)
world.CancelInputMode();
@@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.Orders
public IEnumerable<IRenderable> Render(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;
return OrderInner(world, mi).Any()

View File

@@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Traits
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())
return null;

View File

@@ -125,11 +125,11 @@ namespace OpenRA.Mods.Common.Traits
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();
if (mi.Button == MouseButton.Left && power.UnitsInRange(xy).Any())
yield return new Order(order, manager.Self, false) { TargetLocation = xy, SuppressVisualFeedback = true };
if (mi.Button == MouseButton.Left && power.UnitsInRange(cell).Any())
yield return new Order(order, manager.Self, false) { TargetLocation = cell, SuppressVisualFeedback = true };
}
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);
}
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";
}
}
}

View File

@@ -267,11 +267,11 @@ namespace OpenRA.Mods.Common.Traits
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();
if (mi.Button == expectedButton && world.Map.Contains(xy))
yield return new Order(order, manager.Self, false) { TargetLocation = xy, SuppressVisualFeedback = true };
if (mi.Button == expectedButton && world.Map.Contains(cell))
yield return new Order(order, manager.Self, false) { TargetLocation = cell, SuppressVisualFeedback = true };
}
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> 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";
}
}
}

View File

@@ -219,7 +219,8 @@ namespace OpenRA.Mods.Common.Widgets
return null;
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
{
@@ -228,7 +229,7 @@ namespace OpenRA.Mods.Common.Widgets
Modifiers = Game.GetModifierKeys()
};
var cursor = world.OrderGenerator.GetCursor(world, cell, mi);
var cursor = world.OrderGenerator.GetCursor(world, cell, worldPixel, mi);
if (cursor == null)
return "default";

View File

@@ -128,9 +128,10 @@ namespace OpenRA.Mods.Common.Widgets
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>())
.WithHighestSelectionPriority();
.WithHighestSelectionPriority(worldPixel);
if (underCursor != null)
{
@@ -140,9 +141,9 @@ namespace OpenRA.Mods.Common.Widgets
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)
.WithHighestSelectionPriority();
.WithHighestSelectionPriority(worldPixel);
if (frozen != null)
{