From fc4ebf332dbb43696f44328c42d681eec2bca16f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 14 Apr 2024 12:58:11 +0200 Subject: [PATCH] Deduplicate directional support powers. --- .../Traits/SupportPowers/AirstrikePower.cs | 21 +------- .../SupportPowers/DirectionalSupportPower.cs | 50 +++++++++++++++++++ .../Traits/SupportPowers/ParatroopersPower.cs | 21 +------- .../SupportPowers/SelectDirectionalTarget.cs | 17 +++---- 4 files changed, 60 insertions(+), 49 deletions(-) create mode 100644 OpenRA.Mods.Common/Traits/SupportPowers/DirectionalSupportPower.cs diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs index 0a8c23192e..38530a1001 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs @@ -19,7 +19,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { - public class AirstrikePowerInfo : SupportPowerInfo + public class AirstrikePowerInfo : DirectionalSupportPowerInfo { [ActorReference(typeof(AircraftInfo))] public readonly string UnitType = "badr.bomber"; @@ -36,22 +36,13 @@ namespace OpenRA.Mods.Common.Traits [Desc("Amount of time to keep the camera alive after the aircraft have finished attacking")] public readonly int CameraRemoveDelay = 25; - [Desc("Enables the player directional targeting")] - public readonly bool UseDirectionalTarget = false; - - [Desc("Animation used to render the direction arrows.")] - public readonly string DirectionArrowAnimation = null; - - [Desc("Palette for direction cursor animation.")] - public readonly string DirectionArrowPalette = "chrome"; - [Desc("Weapon range offset to apply during the beacon clock calculation")] public readonly WDist BeaconDistanceOffset = WDist.FromCells(6); public override object Create(ActorInitializer init) { return new AirstrikePower(init.Self, this); } } - public class AirstrikePower : SupportPower + public class AirstrikePower : DirectionalSupportPower { readonly AirstrikePowerInfo info; @@ -61,14 +52,6 @@ namespace OpenRA.Mods.Common.Traits this.info = info; } - public override void SelectTarget(Actor self, string order, SupportPowerManager manager) - { - if (info.UseDirectionalTarget) - self.World.OrderGenerator = new SelectDirectionalTarget(self.World, order, manager, Info.Cursor, info.DirectionArrowAnimation, info.DirectionArrowPalette); - else - base.SelectTarget(self, order, manager); - } - public override void Activate(Actor self, Order order, SupportPowerManager manager) { base.Activate(self, order, manager); diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/DirectionalSupportPower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/DirectionalSupportPower.cs new file mode 100644 index 0000000000..27986a510c --- /dev/null +++ b/OpenRA.Mods.Common/Traits/SupportPowers/DirectionalSupportPower.cs @@ -0,0 +1,50 @@ +#region Copyright & License Information +/* + * Copyright (c) The OpenRA Developers and Contributors + * 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 OpenRA.Traits; + +namespace OpenRA.Mods.Common.Traits +{ + public abstract class DirectionalSupportPowerInfo : SupportPowerInfo + { + [Desc("Enables the player directional targeting")] + public readonly bool UseDirectionalTarget = false; + + [SequenceReference(nameof(DirectionArrowAnimation), allowNullImage: true)] + public readonly string[] Arrows = { "arrow-t", "arrow-tl", "arrow-l", "arrow-bl", "arrow-b", "arrow-br", "arrow-r", "arrow-tr" }; + + [Desc("Animation used to render the direction arrows.")] + public readonly string DirectionArrowAnimation = null; + + [PaletteReference] + [Desc("Palette for direction cursor animation.")] + public readonly string DirectionArrowPalette = "chrome"; + } + + public class DirectionalSupportPower : SupportPower + { + readonly DirectionalSupportPowerInfo info; + + public DirectionalSupportPower(Actor self, DirectionalSupportPowerInfo info) + : base(self, info) + { + this.info = info; + } + + public override void SelectTarget(Actor self, string order, SupportPowerManager manager) + { + if (info.UseDirectionalTarget) + self.World.OrderGenerator = new SelectDirectionalTarget(self.World, order, manager, info); + else + base.SelectTarget(self, order, manager); + } + } +} diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/ParatroopersPower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/ParatroopersPower.cs index e50d6f07a0..81c3481803 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/ParatroopersPower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/ParatroopersPower.cs @@ -19,7 +19,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { - public class ParatroopersPowerInfo : SupportPowerInfo + public class ParatroopersPowerInfo : DirectionalSupportPowerInfo { [ActorReference(typeof(AircraftInfo))] public readonly string UnitType = "badr"; @@ -54,22 +54,13 @@ namespace OpenRA.Mods.Common.Traits [Desc("Amount of time (in ticks) to keep the camera alive while the passengers drop.")] public readonly int CameraRemoveDelay = 85; - [Desc("Enables the player directional targeting")] - public readonly bool UseDirectionalTarget = false; - - [Desc("Animation used to render the direction arrows.")] - public readonly string DirectionArrowAnimation = null; - - [Desc("Palette for direction cursor animation.")] - public readonly string DirectionArrowPalette = "chrome"; - [Desc("Weapon range offset to apply during the beacon clock calculation.")] public readonly WDist BeaconDistanceOffset = WDist.FromCells(4); public override object Create(ActorInitializer init) { return new ParatroopersPower(init.Self, this); } } - public class ParatroopersPower : SupportPower + public class ParatroopersPower : DirectionalSupportPower { readonly ParatroopersPowerInfo info; @@ -79,14 +70,6 @@ namespace OpenRA.Mods.Common.Traits this.info = info; } - public override void SelectTarget(Actor self, string order, SupportPowerManager manager) - { - if (info.UseDirectionalTarget) - self.World.OrderGenerator = new SelectDirectionalTarget(self.World, order, manager, Info.Cursor, info.DirectionArrowAnimation, info.DirectionArrowPalette); - else - base.SelectTarget(self, order, manager); - } - public override void Activate(Actor self, Order order, SupportPowerManager manager) { base.Activate(self, order, manager); diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/SelectDirectionalTarget.cs b/OpenRA.Mods.Common/Traits/SupportPowers/SelectDirectionalTarget.cs index d68f8881dd..6aca3ec2cd 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/SelectDirectionalTarget.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/SelectDirectionalTarget.cs @@ -26,10 +26,7 @@ namespace OpenRA.Mods.Common.Traits readonly string order; readonly SupportPowerManager manager; - readonly string cursor; - readonly string directionArrowPalette; - readonly string[] arrows = { "arrow-t", "arrow-tl", "arrow-l", "arrow-bl", "arrow-b", "arrow-br", "arrow-r", "arrow-tr" }; readonly Arrow[] directionArrows; CPos targetCell; @@ -39,17 +36,15 @@ namespace OpenRA.Mods.Common.Traits bool dragStarted; Arrow currentArrow; readonly MouseAttachmentWidget mouseAttachment; + readonly DirectionalSupportPowerInfo info; - public SelectDirectionalTarget(World world, string order, SupportPowerManager manager, string cursor, - string directionArrowAnimation, string directionArrowPalette) + public SelectDirectionalTarget(World world, string order, SupportPowerManager manager, DirectionalSupportPowerInfo info) { this.order = order; this.manager = manager; - this.cursor = cursor; + this.info = info; - this.directionArrowPalette = directionArrowPalette; - - directionArrows = LoadArrows(directionArrowAnimation, world, arrows.Length); + directionArrows = LoadArrows(info.DirectionArrowAnimation, world, info.Arrows.Length); mouseAttachment = Ui.Root.Get("MOUSE_ATTATCHMENT"); } @@ -87,7 +82,7 @@ namespace OpenRA.Mods.Common.Traits currentArrow = GetArrow(angle); - mouseAttachment.SetAttachment(targetLocation, currentArrow.Sprite, directionArrowPalette); + mouseAttachment.SetAttachment(targetLocation, currentArrow.Sprite, info.DirectionArrowPalette); dragStarted = true; } @@ -163,7 +158,7 @@ namespace OpenRA.Mods.Common.Traits for (var i = 0; i < noOfDividingPoints; i++) { - var sprite = world.Map.Sequences.GetSequence(cursorAnimation, arrows[i]).GetSprite(0); + var sprite = world.Map.Sequences.GetSequence(cursorAnimation, info.Arrows[i]).GetSprite(0); var angle = i * partAngle; var direction = WAngle.FromDegrees(angle);