From 1dd90a1d7bc2e8a62bfcfd041f800c4a046059e9 Mon Sep 17 00:00:00 2001 From: teinarss Date: Sat, 30 Mar 2019 20:07:11 +0100 Subject: [PATCH] Pushed down the MouseInput handling to the OrderGenerators and made a base class for handling the basic logic --- OpenRA.Mods.Cnc/Traits/Minelayer.cs | 12 +++--- OpenRA.Mods.Cnc/Traits/PortableChrono.cs | 12 +++--- .../Traits/SupportPowers/AttackOrderPower.cs | 13 ++++--- .../Traits/SupportPowers/ChronoshiftPower.cs | 25 ++++++------ OpenRA.Mods.Common/OpenRA.Mods.Common.csproj | 1 + .../Orders/BeaconOrderGenerator.cs | 12 +++--- .../Orders/GlobalButtonOrderGenerator.cs | 16 ++++---- OpenRA.Mods.Common/Orders/OrderGenerator.cs | 39 +++++++++++++++++++ .../Orders/PlaceBuildingOrderGenerator.cs | 12 +++--- .../Orders/RepairOrderGenerator.cs | 12 +++--- .../GrantExternalConditionPower.cs | 13 ++++--- .../SupportPowers/SupportPowerManager.cs | 13 ++++--- .../WorldInteractionControllerWidget.cs | 17 ++++---- 13 files changed, 120 insertions(+), 77 deletions(-) create mode 100644 OpenRA.Mods.Common/Orders/OrderGenerator.cs diff --git a/OpenRA.Mods.Cnc/Traits/Minelayer.cs b/OpenRA.Mods.Cnc/Traits/Minelayer.cs index 5650328bf9..d6d77fc6ca 100644 --- a/OpenRA.Mods.Cnc/Traits/Minelayer.cs +++ b/OpenRA.Mods.Cnc/Traits/Minelayer.cs @@ -155,7 +155,7 @@ namespace OpenRA.Mods.Cnc.Traits bool IRenderAboveShroudWhenSelected.SpatiallyPartitionable { get { return false; } } - class MinefieldOrderGenerator : IOrderGenerator + class MinefieldOrderGenerator : OrderGenerator { readonly List minelayers; readonly Sprite tileOk; @@ -179,7 +179,7 @@ namespace OpenRA.Mods.Cnc.Traits minelayers.Add(a); } - public IEnumerable Order(World world, CPos cell, int2 worldPixel, MouseInput mi) + protected override IEnumerable OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi) { if (mi.Button == Game.Settings.Game.MouseButtonPreference.Cancel) { @@ -201,15 +201,15 @@ namespace OpenRA.Mods.Cnc.Traits } } - public void Tick(World world) + protected override void Tick(World world) { minelayers.RemoveAll(minelayer => !minelayer.IsInWorld || minelayer.IsDead); if (!minelayers.Any()) world.CancelInputMode(); } - public IEnumerable Render(WorldRenderer wr, World world) { yield break; } - public IEnumerable RenderAboveShroud(WorldRenderer wr, World world) + protected override IEnumerable Render(WorldRenderer wr, World world) { yield break; } + protected override IEnumerable RenderAboveShroud(WorldRenderer wr, World world) { var minelayer = minelayers.FirstOrDefault(m => m.IsInWorld && !m.IsDead); if (minelayer == null) @@ -230,7 +230,7 @@ namespace OpenRA.Mods.Cnc.Traits } } - public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) + protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { return "ability"; } diff --git a/OpenRA.Mods.Cnc/Traits/PortableChrono.cs b/OpenRA.Mods.Cnc/Traits/PortableChrono.cs index 02441da3cf..e201b6cf31 100644 --- a/OpenRA.Mods.Cnc/Traits/PortableChrono.cs +++ b/OpenRA.Mods.Cnc/Traits/PortableChrono.cs @@ -180,7 +180,7 @@ namespace OpenRA.Mods.Cnc.Traits } } - class PortableChronoOrderGenerator : IOrderGenerator + class PortableChronoOrderGenerator : OrderGenerator { readonly Actor self; readonly PortableChronoInfo info; @@ -191,7 +191,7 @@ namespace OpenRA.Mods.Cnc.Traits this.info = info; } - public IEnumerable Order(World world, CPos cell, int2 worldPixel, MouseInput mi) + protected override IEnumerable OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi) { if (mi.Button == Game.Settings.Game.MouseButtonPreference.Cancel) { @@ -207,18 +207,18 @@ namespace OpenRA.Mods.Cnc.Traits } } - public void Tick(World world) + protected override void Tick(World world) { if (!self.IsInWorld || self.IsDead) world.CancelInputMode(); } - public IEnumerable Render(WorldRenderer wr, World world) + protected override IEnumerable Render(WorldRenderer wr, World world) { yield break; } - public IEnumerable RenderAboveShroud(WorldRenderer wr, World world) + protected override IEnumerable RenderAboveShroud(WorldRenderer wr, World world) { if (!self.IsInWorld || self.Owner != self.World.LocalPlayer) yield break; @@ -234,7 +234,7 @@ namespace OpenRA.Mods.Cnc.Traits Color.FromArgb(96, Color.Black)); } - public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) + protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { if (self.IsInWorld && self.Location != cell && self.Trait().CanTeleport && self.Owner.Shroud.IsExplored(cell)) diff --git a/OpenRA.Mods.Cnc/Traits/SupportPowers/AttackOrderPower.cs b/OpenRA.Mods.Cnc/Traits/SupportPowers/AttackOrderPower.cs index 12e5a759f1..65e5575892 100644 --- a/OpenRA.Mods.Cnc/Traits/SupportPowers/AttackOrderPower.cs +++ b/OpenRA.Mods.Cnc/Traits/SupportPowers/AttackOrderPower.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Graphics; +using OpenRA.Mods.Common.Orders; using OpenRA.Mods.Common.Traits; using OpenRA.Primitives; using OpenRA.Traits; @@ -61,7 +62,7 @@ namespace OpenRA.Mods.Cnc.Traits } } - public class SelectAttackPowerTarget : IOrderGenerator + public class SelectAttackPowerTarget : OrderGenerator { readonly SupportPowerManager manager; readonly SupportPowerInstance instance; @@ -94,7 +95,7 @@ namespace OpenRA.Mods.Cnc.Traits return world.Map.Contains(cell) && instance.Instances.Any(a => !a.IsTraitPaused && (a.Self.CenterPosition - pos).HorizontalLengthSquared < range); } - IEnumerable IOrderGenerator.Order(World world, CPos cell, int2 worldPixel, MouseInput mi) + protected override IEnumerable OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi) { world.CancelInputMode(); if (mi.Button == expectedButton && IsValidTarget(world, cell)) @@ -104,16 +105,16 @@ namespace OpenRA.Mods.Cnc.Traits }; } - void IOrderGenerator.Tick(World world) + protected override void Tick(World world) { // Cancel the OG if we can't use the power if (!manager.Powers.ContainsKey(order)) world.CancelInputMode(); } - IEnumerable IOrderGenerator.Render(WorldRenderer wr, World world) { yield break; } + protected override IEnumerable Render(WorldRenderer wr, World world) { yield break; } - IEnumerable IOrderGenerator.RenderAboveShroud(WorldRenderer wr, World world) + protected override IEnumerable RenderAboveShroud(WorldRenderer wr, World world) { foreach (var a in instance.Instances.Where(i => !i.IsTraitPaused)) { @@ -133,7 +134,7 @@ namespace OpenRA.Mods.Cnc.Traits } } - string IOrderGenerator.GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) + protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { return IsValidTarget(world, cell) ? cursor : cursorBlocked; } diff --git a/OpenRA.Mods.Cnc/Traits/SupportPowers/ChronoshiftPower.cs b/OpenRA.Mods.Cnc/Traits/SupportPowers/ChronoshiftPower.cs index 68b5825856..3b3aa9c25b 100644 --- a/OpenRA.Mods.Cnc/Traits/SupportPowers/ChronoshiftPower.cs +++ b/OpenRA.Mods.Cnc/Traits/SupportPowers/ChronoshiftPower.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Graphics; +using OpenRA.Mods.Common.Orders; using OpenRA.Mods.Common.Traits; using OpenRA.Primitives; using OpenRA.Traits; @@ -120,7 +121,7 @@ namespace OpenRA.Mods.Cnc.Traits return true; } - class SelectChronoshiftTarget : IOrderGenerator + class SelectChronoshiftTarget : OrderGenerator { readonly ChronoshiftPower power; readonly int range; @@ -143,7 +144,7 @@ namespace OpenRA.Mods.Cnc.Traits tile = world.Map.Rules.Sequences.GetSequence(info.OverlaySpriteGroup, info.SourceTileSequence).GetSprite(0); } - public IEnumerable Order(World world, CPos cell, int2 worldPixel, MouseInput mi) + protected override IEnumerable OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi) { world.CancelInputMode(); if (mi.Button == MouseButton.Left) @@ -152,14 +153,14 @@ namespace OpenRA.Mods.Cnc.Traits yield break; } - public void Tick(World world) + protected override void Tick(World world) { // Cancel the OG if we can't use the power if (!manager.Powers.ContainsKey(order)) world.CancelInputMode(); } - public IEnumerable RenderAboveShroud(WorldRenderer wr, World world) + protected override IEnumerable RenderAboveShroud(WorldRenderer wr, World world) { var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos); var targetUnits = power.UnitsInRange(xy).Where(a => !world.FogObscures(a)); @@ -174,7 +175,7 @@ namespace OpenRA.Mods.Cnc.Traits } } - public IEnumerable Render(WorldRenderer wr, World world) + protected override IEnumerable Render(WorldRenderer wr, World world) { var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos); var tiles = world.Map.FindTilesInCircle(xy, range); @@ -183,13 +184,13 @@ namespace OpenRA.Mods.Cnc.Traits yield return new SpriteRenderable(tile, wr.World.Map.CenterOfCell(t), WVec.Zero, -511, palette, 1f, true); } - public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) + protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { return ((ChronoshiftPowerInfo)power.Info).SelectionCursor; } } - class SelectDestination : IOrderGenerator + class SelectDestination : OrderGenerator { readonly ChronoshiftPower power; readonly CPos sourceLocation; @@ -214,7 +215,7 @@ namespace OpenRA.Mods.Cnc.Traits sourceTile = world.Map.Rules.Sequences.GetSequence(info.OverlaySpriteGroup, info.SourceTileSequence).GetSprite(0); } - public IEnumerable Order(World world, CPos cell, int2 worldPixel, MouseInput mi) + protected override IEnumerable OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi) { if (mi.Button == MouseButton.Right) { @@ -241,14 +242,14 @@ namespace OpenRA.Mods.Cnc.Traits }; } - public void Tick(World world) + protected override void Tick(World world) { // Cancel the OG if we can't use the power if (!manager.Powers.ContainsKey(order)) world.CancelInputMode(); } - public IEnumerable RenderAboveShroud(WorldRenderer wr, World world) + protected override IEnumerable RenderAboveShroud(WorldRenderer wr, World world) { var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos); var palette = wr.Palette(power.Info.IconPalette); @@ -289,7 +290,7 @@ namespace OpenRA.Mods.Cnc.Traits } } - public IEnumerable Render(WorldRenderer wr, World world) + protected override IEnumerable Render(WorldRenderer wr, World world) { var palette = wr.Palette(power.Info.IconPalette); @@ -322,7 +323,7 @@ namespace OpenRA.Mods.Cnc.Traits return canTeleport; } - public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) + protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { var powerInfo = (ChronoshiftPowerInfo)power.Info; return IsValidTarget(cell) ? powerInfo.TargetCursor : powerInfo.TargetBlockedCursor; diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 7a2daf08fb..ec202ae64f 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -117,6 +117,7 @@ + diff --git a/OpenRA.Mods.Common/Orders/BeaconOrderGenerator.cs b/OpenRA.Mods.Common/Orders/BeaconOrderGenerator.cs index 25165d8c42..85308ac153 100644 --- a/OpenRA.Mods.Common/Orders/BeaconOrderGenerator.cs +++ b/OpenRA.Mods.Common/Orders/BeaconOrderGenerator.cs @@ -15,9 +15,9 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Orders { - public class BeaconOrderGenerator : IOrderGenerator + public class BeaconOrderGenerator : OrderGenerator { - public IEnumerable Order(World world, CPos cell, int2 worldPixel, MouseInput mi) + protected override IEnumerable OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi) { world.CancelInputMode(); @@ -25,10 +25,10 @@ namespace OpenRA.Mods.Common.Orders yield return new Order("PlaceBeacon", world.LocalPlayer.PlayerActor, Target.FromCell(world, cell), false) { SuppressVisualFeedback = true }; } - public virtual void Tick(World world) { } - public IEnumerable Render(WorldRenderer wr, World world) { yield break; } - public IEnumerable RenderAboveShroud(WorldRenderer wr, World world) { yield break; } - public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) + protected override void Tick(World world) { } + protected override IEnumerable Render(WorldRenderer wr, World world) { yield break; } + protected override IEnumerable RenderAboveShroud(WorldRenderer wr, World world) { yield break; } + protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { return "ability"; } diff --git a/OpenRA.Mods.Common/Orders/GlobalButtonOrderGenerator.cs b/OpenRA.Mods.Common/Orders/GlobalButtonOrderGenerator.cs index 84493eea7a..9ca9612665 100644 --- a/OpenRA.Mods.Common/Orders/GlobalButtonOrderGenerator.cs +++ b/OpenRA.Mods.Common/Orders/GlobalButtonOrderGenerator.cs @@ -16,7 +16,7 @@ using OpenRA.Mods.Common.Traits; namespace OpenRA.Mods.Common.Orders { - public abstract class GlobalButtonOrderGenerator : IOrderGenerator + public abstract class GlobalButtonOrderGenerator : OrderGenerator { string order; @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Orders this.order = order; } - public IEnumerable Order(World world, CPos cell, int2 worldPixel, MouseInput mi) + protected override IEnumerable OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi) { if (mi.Button == MouseButton.Right) world.CancelInputMode(); @@ -54,17 +54,17 @@ namespace OpenRA.Mods.Common.Orders } } - public void Tick(World world) + protected override void Tick(World world) { if (world.LocalPlayer != null && world.LocalPlayer.WinState != WinState.Undefined) world.CancelInputMode(); } - public IEnumerable Render(WorldRenderer wr, World world) { yield break; } - public IEnumerable RenderAboveShroud(WorldRenderer wr, World world) { yield break; } + protected override IEnumerable Render(WorldRenderer wr, World world) { yield break; } + protected override IEnumerable RenderAboveShroud(WorldRenderer wr, World world) { yield break; } - public abstract string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi); + protected abstract override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi); } public class PowerDownOrderGenerator : GlobalButtonOrderGenerator @@ -76,7 +76,7 @@ namespace OpenRA.Mods.Common.Orders return !t.IsTraitDisabled && !t.IsTraitPaused; } - public override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) + protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { mi.Button = MouseButton.Left; return OrderInner(world, mi).Any() ? "powerdown" : "powerdown-blocked"; @@ -87,7 +87,7 @@ namespace OpenRA.Mods.Common.Orders { public SellOrderGenerator() : base("Sell") { } - public override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) + protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { mi.Button = MouseButton.Left; diff --git a/OpenRA.Mods.Common/Orders/OrderGenerator.cs b/OpenRA.Mods.Common/Orders/OrderGenerator.cs new file mode 100644 index 0000000000..2bcd56ff76 --- /dev/null +++ b/OpenRA.Mods.Common/Orders/OrderGenerator.cs @@ -0,0 +1,39 @@ +#region Copyright & License Information +/* + * Copyright 2007-2019 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.Graphics; + +namespace OpenRA.Mods.Common.Orders +{ + public abstract class OrderGenerator : IOrderGenerator + { + public IEnumerable Order(World world, CPos cell, int2 worldPixel, MouseInput mi) + { + if ((mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Down) || (mi.Button == MouseButton.Right && mi.Event == MouseInputEvent.Up)) + return OrderInner(world, cell, worldPixel, mi); + + return Enumerable.Empty(); + } + + void IOrderGenerator.Tick(World world) { Tick(world); } + IEnumerable IOrderGenerator.Render(WorldRenderer wr, World world) { return Render(wr, world); } + IEnumerable IOrderGenerator.RenderAboveShroud(WorldRenderer wr, World world) { return RenderAboveShroud(wr, world); } + string IOrderGenerator.GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { return GetCursor(world, cell, worldPixel, mi); } + + protected abstract void Tick(World world); + protected abstract IEnumerable Render(WorldRenderer wr, World world); + protected abstract IEnumerable RenderAboveShroud(WorldRenderer wr, World world); + protected abstract string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi); + protected abstract IEnumerable OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi); + } +} diff --git a/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs index a17f69be30..8ff57e379e 100644 --- a/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs @@ -20,7 +20,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Orders { - public class PlaceBuildingOrderGenerator : IOrderGenerator + public class PlaceBuildingOrderGenerator : OrderGenerator { [Flags] enum CellType { Valid = 0, Invalid = 1, LineBuild = 2 } @@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Orders return cell; } - public IEnumerable Order(World world, CPos cell, int2 worldPixel, MouseInput mi) + protected override IEnumerable OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi) { if (mi.Button == MouseButton.Right) world.CancelInputMode(); @@ -147,7 +147,7 @@ namespace OpenRA.Mods.Common.Orders } } - public void Tick(World world) + protected override void Tick(World world) { if (queue.AllQueued().All(i => !i.Done || i.Item != actorInfo.Name)) world.CancelInputMode(); @@ -169,8 +169,8 @@ namespace OpenRA.Mods.Common.Orders return host.TraitsImplementing().Any(p => location + p.Info.Offset == cell && p.AcceptsPlug(host, plug.Type)); } - public IEnumerable Render(WorldRenderer wr, World world) { yield break; } - public IEnumerable RenderAboveShroud(WorldRenderer wr, World world) + protected override IEnumerable Render(WorldRenderer wr, World world) { yield break; } + protected override IEnumerable RenderAboveShroud(WorldRenderer wr, World world) { var topLeft = viewport.ViewToWorld(Viewport.LastMousePos + topLeftScreenOffset); var centerPosition = world.Map.CenterOfCell(topLeft) + centerOffset; @@ -250,7 +250,7 @@ namespace OpenRA.Mods.Common.Orders } } - public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { return "default"; } + protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { return "default"; } IEnumerable ClearBlockersOrders(World world, CPos topLeft) { diff --git a/OpenRA.Mods.Common/Orders/RepairOrderGenerator.cs b/OpenRA.Mods.Common/Orders/RepairOrderGenerator.cs index 2c5551947f..47e5b34641 100644 --- a/OpenRA.Mods.Common/Orders/RepairOrderGenerator.cs +++ b/OpenRA.Mods.Common/Orders/RepairOrderGenerator.cs @@ -17,9 +17,9 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Orders { - public class RepairOrderGenerator : IOrderGenerator + public class RepairOrderGenerator : OrderGenerator { - public IEnumerable Order(World world, CPos cell, int2 worldPixel, MouseInput mi) + protected override IEnumerable OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi) { if (mi.Button == MouseButton.Right) world.CancelInputMode(); @@ -73,17 +73,17 @@ namespace OpenRA.Mods.Common.Orders yield return new Order(orderId, underCursor, Target.FromActor(repairBuilding), false) { VisualFeedbackTarget = Target.FromActor(underCursor) }; } - public void Tick(World world) + protected override void Tick(World world) { if (world.LocalPlayer != null && world.LocalPlayer.WinState != WinState.Undefined) world.CancelInputMode(); } - public IEnumerable Render(WorldRenderer wr, World world) { yield break; } - public IEnumerable RenderAboveShroud(WorldRenderer wr, World world) { yield break; } + protected override IEnumerable Render(WorldRenderer wr, World world) { yield break; } + protected override IEnumerable RenderAboveShroud(WorldRenderer wr, World world) { yield break; } - public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) + protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { mi.Button = MouseButton.Left; return OrderInner(world, mi).Any() diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/GrantExternalConditionPower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/GrantExternalConditionPower.cs index cda229847d..818e88b614 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/GrantExternalConditionPower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/GrantExternalConditionPower.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Graphics; +using OpenRA.Mods.Common.Orders; using OpenRA.Mods.Common.Traits.Render; using OpenRA.Primitives; using OpenRA.Traits; @@ -101,7 +102,7 @@ namespace OpenRA.Mods.Common.Traits }); } - class SelectConditionTarget : IOrderGenerator + class SelectConditionTarget : OrderGenerator { readonly GrantExternalConditionPower power; readonly int range; @@ -122,21 +123,21 @@ namespace OpenRA.Mods.Common.Traits tile = world.Map.Rules.Sequences.GetSequence("overlay", "target-select").GetSprite(0); } - public IEnumerable Order(World world, CPos cell, int2 worldPixel, MouseInput mi) + protected override IEnumerable OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi) { world.CancelInputMode(); if (mi.Button == MouseButton.Left && power.UnitsInRange(cell).Any()) yield return new Order(order, manager.Self, Target.FromCell(world, cell), false) { SuppressVisualFeedback = true }; } - public void Tick(World world) + protected override void Tick(World world) { // Cancel the OG if we can't use the power if (!manager.Powers.ContainsKey(order)) world.CancelInputMode(); } - public IEnumerable RenderAboveShroud(WorldRenderer wr, World world) + protected override IEnumerable RenderAboveShroud(WorldRenderer wr, World world) { var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos); foreach (var unit in power.UnitsInRange(xy)) @@ -146,7 +147,7 @@ namespace OpenRA.Mods.Common.Traits } } - public IEnumerable Render(WorldRenderer wr, World world) + protected override IEnumerable Render(WorldRenderer wr, World world) { var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos); var pal = wr.Palette(TileSet.TerrainPaletteInternalName); @@ -155,7 +156,7 @@ 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 cell, int2 worldPixel, MouseInput mi) + protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { return power.UnitsInRange(cell).Any() ? power.info.Cursor : power.info.BlockedCursor; } diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs index de1f81752f..87d596b9a7 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs @@ -13,6 +13,7 @@ using System; using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; +using OpenRA.Mods.Common.Orders; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -258,7 +259,7 @@ namespace OpenRA.Mods.Common.Traits } } - public class SelectGenericPowerTarget : IOrderGenerator + public class SelectGenericPowerTarget : OrderGenerator { readonly SupportPowerManager manager; readonly string order; @@ -279,23 +280,23 @@ namespace OpenRA.Mods.Common.Traits expectedButton = button; } - public IEnumerable Order(World world, CPos cell, int2 worldPixel, MouseInput mi) + protected override IEnumerable OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi) { world.CancelInputMode(); if (mi.Button == expectedButton && world.Map.Contains(cell)) yield return new Order(order, manager.Self, Target.FromCell(world, cell), false) { SuppressVisualFeedback = true }; } - public virtual void Tick(World world) + protected override void Tick(World world) { // Cancel the OG if we can't use the power if (!manager.Powers.ContainsKey(order)) world.CancelInputMode(); } - public IEnumerable Render(WorldRenderer wr, World world) { yield break; } - public IEnumerable RenderAboveShroud(WorldRenderer wr, World world) { yield break; } - public string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) + protected override IEnumerable Render(WorldRenderer wr, World world) { yield break; } + protected override IEnumerable RenderAboveShroud(WorldRenderer wr, World world) { yield break; } + protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { return world.Map.Contains(cell) ? cursor : "generic-blocked"; } diff --git a/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs index dc1b526282..dbc43b4a0a 100644 --- a/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs @@ -82,6 +82,14 @@ namespace OpenRA.Mods.Common.Widgets var multiClick = mi.MultiTapCount >= 2; + if (!(World.OrderGenerator is UnitOrderGenerator)) + { + ApplyOrders(World, mi); + isDragging = false; + YieldMouseFocus(mi); + return true; + } + if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Down) { if (!TakeMouseFocus(mi)) @@ -89,15 +97,6 @@ namespace OpenRA.Mods.Common.Widgets dragStart = mousePos; isDragging = true; - - // Place buildings, use support powers, and other non-unit things - if (!(World.OrderGenerator is UnitOrderGenerator)) - { - ApplyOrders(World, mi); - isDragging = false; - YieldMouseFocus(mi); - return true; - } } if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Up)