Deduplicate directional support powers.

This commit is contained in:
Matthias Mailänder
2024-04-14 12:58:11 +02:00
committed by Gustas
parent 1a3d3cd31e
commit fc4ebf332d
4 changed files with 60 additions and 49 deletions

View File

@@ -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);

View File

@@ -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);
}
}
}

View File

@@ -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);

View File

@@ -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<MouseAttachmentWidget>("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);