Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove GenericSelectTarget #18820

Merged
merged 1 commit into from Feb 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
79 changes: 0 additions & 79 deletions OpenRA.Game/Orders/GenericSelectTarget.cs

This file was deleted.

37 changes: 30 additions & 7 deletions OpenRA.Mods.Common/Orders/GuardOrderGenerator.cs
Expand Up @@ -17,24 +17,39 @@

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)
: base(subjects, order, cursor, button) { }
{
orderName = order;
this.cursor = cursor;
expectedButton = button;
this.subjects = subjects;
}

protected override IEnumerable<Order> OrderInner(World world, CPos xy, MouseInput mi)
public override IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
{
if (mi.Button != ExpectedButton)
yield break;
if (mi.Button != expectedButton)
world.CancelInputMode();

return OrderInner(world, mi);
}

IEnumerable<Order> OrderInner(World world, MouseInput mi)
{
var target = FriendlyGuardableUnits(world, mi).FirstOrDefault();
if (target == null)
yield break;

world.CancelInputMode();

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)
Expand All @@ -54,9 +69,17 @@ public override string GetCursor(World world, CPos cell, int2 worldPixel, MouseI
var canGuard = FriendlyGuardableUnits(world, mi)
.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)
{
return world.ScreenMap.ActorsAtMouse(mi)
Expand Down