From 96c455464429eebb845bf60bff8ce04e07a1617e Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Mon, 9 Nov 2020 13:58:13 +0100 Subject: [PATCH] Remove GenericSelectTarget --- OpenRA.Game/Orders/GenericSelectTarget.cs | 79 ------------------- .../Orders/GuardOrderGenerator.cs | 39 +++++++-- 2 files changed, 31 insertions(+), 87 deletions(-) delete mode 100644 OpenRA.Game/Orders/GenericSelectTarget.cs diff --git a/OpenRA.Game/Orders/GenericSelectTarget.cs b/OpenRA.Game/Orders/GenericSelectTarget.cs deleted file mode 100644 index cf8049ed9e..0000000000 --- a/OpenRA.Game/Orders/GenericSelectTarget.cs +++ /dev/null @@ -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 subjects; - - public GenericSelectTarget(IEnumerable subjects, string order, string cursor, MouseButton button) - { - this.subjects = subjects; - OrderName = order; - Cursor = cursor; - ExpectedButton = button; - } - - public GenericSelectTarget(IEnumerable 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(World world, CPos cell, int2 worldPixel, MouseInput mi) - { - if (mi.Button != ExpectedButton) - world.CancelInputMode(); - return OrderInner(world, cell, mi); - } - - protected virtual IEnumerable 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 selected) - { - subjects = selected; - } - - public override bool ClearSelectionOnLeftClick { get { return false; } } - } -} diff --git a/OpenRA.Mods.Common/Orders/GuardOrderGenerator.cs b/OpenRA.Mods.Common/Orders/GuardOrderGenerator.cs index bcb7b978f7..86a20f6a24 100644 --- a/OpenRA.Mods.Common/Orders/GuardOrderGenerator.cs +++ b/OpenRA.Mods.Common/Orders/GuardOrderGenerator.cs @@ -17,16 +17,31 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Orders { - public class GuardOrderGenerator : GenericSelectTarget + public class GuardOrderGenerator : UnitOrderGenerator { + readonly string orderName; + readonly string cursor; + readonly MouseButton expectedButton; + IEnumerable subjects; + public GuardOrderGenerator(IEnumerable subjects, string order, string cursor, MouseButton button) - : base(subjects, order, cursor, button) { } - - protected override IEnumerable OrderInner(World world, CPos xy, MouseInput mi) { - if (mi.Button != ExpectedButton) - yield break; + orderName = order; + this.cursor = cursor; + expectedButton = button; + this.subjects = subjects; + } + public override IEnumerable Order(World world, CPos cell, int2 worldPixel, MouseInput mi) + { + if (mi.Button != expectedButton) + world.CancelInputMode(); + + return OrderInner(world, mi); + } + + IEnumerable OrderInner(World world, MouseInput mi) + { var target = FriendlyGuardableUnits(world, mi).FirstOrDefault(); if (target == null) yield break; @@ -34,7 +49,7 @@ namespace OpenRA.Mods.Common.Orders 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 selected) @@ -54,9 +69,17 @@ namespace OpenRA.Mods.Common.Orders 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 FriendlyGuardableUnits(World world, MouseInput mi) { return world.ScreenMap.ActorsAtMouse(mi)