Remove GenericSelectTarget
This commit is contained in:
@@ -1,79 +0,0 @@
|
|||||||
#region Copyright & License Information
|
|
||||||
/*
|
|
||||||
* Copyright 2007-2020 The OpenRA Developers (see AUTHORS)
|
|
||||||
* This file is part of OpenRA, which is free software. It is made
|
|
||||||
* available to you under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation, either version 3 of
|
|
||||||
* the License, or (at your option) any later version. For more
|
|
||||||
* information, see COPYING.
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using OpenRA.Traits;
|
|
||||||
|
|
||||||
namespace OpenRA.Orders
|
|
||||||
{
|
|
||||||
public class GenericSelectTarget : UnitOrderGenerator
|
|
||||||
{
|
|
||||||
public readonly string OrderName;
|
|
||||||
protected readonly string Cursor;
|
|
||||||
protected readonly MouseButton ExpectedButton;
|
|
||||||
|
|
||||||
protected IEnumerable<Actor> subjects;
|
|
||||||
|
|
||||||
public GenericSelectTarget(IEnumerable<Actor> subjects, string order, string cursor, MouseButton button)
|
|
||||||
{
|
|
||||||
this.subjects = subjects;
|
|
||||||
OrderName = order;
|
|
||||||
Cursor = cursor;
|
|
||||||
ExpectedButton = button;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GenericSelectTarget(IEnumerable<Actor> subjects, string order, string cursor)
|
|
||||||
: this(subjects, order, cursor, MouseButton.Left) { }
|
|
||||||
|
|
||||||
public GenericSelectTarget(Actor subject, string order, string cursor)
|
|
||||||
: this(new Actor[] { subject }, order, cursor) { }
|
|
||||||
|
|
||||||
public GenericSelectTarget(Actor subject, string order, string cursor, MouseButton button)
|
|
||||||
: this(new Actor[] { subject }, order, cursor, button) { }
|
|
||||||
|
|
||||||
public override IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
|
||||||
{
|
|
||||||
if (mi.Button != ExpectedButton)
|
|
||||||
world.CancelInputMode();
|
|
||||||
return OrderInner(world, cell, mi);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual IEnumerable<Order> OrderInner(World world, CPos cell, MouseInput mi)
|
|
||||||
{
|
|
||||||
if (mi.Button == ExpectedButton && world.Map.Contains(cell))
|
|
||||||
{
|
|
||||||
world.CancelInputMode();
|
|
||||||
|
|
||||||
var queued = mi.Modifiers.HasModifier(Modifiers.Shift);
|
|
||||||
yield return new Order(OrderName, null, Target.FromCell(world, cell), queued, null, subjects.ToArray());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
|
||||||
{
|
|
||||||
return world.Map.Contains(cell) ? Cursor : "generic-blocked";
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool InputOverridesSelection(World world, int2 xy, MouseInput mi)
|
|
||||||
{
|
|
||||||
// Custom order generators always override selection
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void SelectionChanged(World world, IEnumerable<Actor> selected)
|
|
||||||
{
|
|
||||||
subjects = selected;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool ClearSelectionOnLeftClick { get { return false; } }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,16 +17,31 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Orders
|
namespace OpenRA.Mods.Common.Orders
|
||||||
{
|
{
|
||||||
public class GuardOrderGenerator : GenericSelectTarget
|
public class GuardOrderGenerator : UnitOrderGenerator
|
||||||
{
|
{
|
||||||
|
readonly string orderName;
|
||||||
|
readonly string cursor;
|
||||||
|
readonly MouseButton expectedButton;
|
||||||
|
IEnumerable<Actor> subjects;
|
||||||
|
|
||||||
public GuardOrderGenerator(IEnumerable<Actor> subjects, string order, string cursor, MouseButton button)
|
public GuardOrderGenerator(IEnumerable<Actor> subjects, string order, string cursor, MouseButton button)
|
||||||
: base(subjects, order, cursor, button) { }
|
|
||||||
|
|
||||||
protected override IEnumerable<Order> OrderInner(World world, CPos xy, MouseInput mi)
|
|
||||||
{
|
{
|
||||||
if (mi.Button != ExpectedButton)
|
orderName = order;
|
||||||
yield break;
|
this.cursor = cursor;
|
||||||
|
expectedButton = button;
|
||||||
|
this.subjects = subjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||||
|
{
|
||||||
|
if (mi.Button != expectedButton)
|
||||||
|
world.CancelInputMode();
|
||||||
|
|
||||||
|
return OrderInner(world, mi);
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerable<Order> OrderInner(World world, MouseInput mi)
|
||||||
|
{
|
||||||
var target = FriendlyGuardableUnits(world, mi).FirstOrDefault();
|
var target = FriendlyGuardableUnits(world, mi).FirstOrDefault();
|
||||||
if (target == null)
|
if (target == null)
|
||||||
yield break;
|
yield break;
|
||||||
@@ -34,7 +49,7 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
world.CancelInputMode();
|
world.CancelInputMode();
|
||||||
|
|
||||||
var queued = mi.Modifiers.HasModifier(Modifiers.Shift);
|
var queued = mi.Modifiers.HasModifier(Modifiers.Shift);
|
||||||
yield return new Order(OrderName, null, Target.FromActor(target), queued, null, subjects.Where(s => s != target).ToArray());
|
yield return new Order(orderName, null, Target.FromActor(target), queued, null, subjects.Where(s => s != target).ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SelectionChanged(World world, IEnumerable<Actor> selected)
|
public override void SelectionChanged(World world, IEnumerable<Actor> selected)
|
||||||
@@ -54,9 +69,17 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
var canGuard = FriendlyGuardableUnits(world, mi)
|
var canGuard = FriendlyGuardableUnits(world, mi)
|
||||||
.Any(a => multiple || a != subjects.First());
|
.Any(a => multiple || a != subjects.First());
|
||||||
|
|
||||||
return canGuard ? Cursor : "move-blocked";
|
return canGuard ? cursor : "move-blocked";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool InputOverridesSelection(World world, int2 xy, MouseInput mi)
|
||||||
|
{
|
||||||
|
// Custom order generators always override selection
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool ClearSelectionOnLeftClick { get { return false; } }
|
||||||
|
|
||||||
static IEnumerable<Actor> FriendlyGuardableUnits(World world, MouseInput mi)
|
static IEnumerable<Actor> FriendlyGuardableUnits(World world, MouseInput mi)
|
||||||
{
|
{
|
||||||
return world.ScreenMap.ActorsAtMouse(mi)
|
return world.ScreenMap.ActorsAtMouse(mi)
|
||||||
|
|||||||
Reference in New Issue
Block a user