Unhardcode support power blocked cursor.

This commit is contained in:
Matthias Mailänder
2024-04-14 13:27:46 +02:00
committed by Gustas
parent fc4ebf332d
commit 69d9bbb400
11 changed files with 53 additions and 14 deletions

View File

@@ -47,10 +47,6 @@ namespace OpenRA.Mods.Common.Traits
"This requires the actor to have the WithSpriteBody trait or one of its derivatives.")] "This requires the actor to have the WithSpriteBody trait or one of its derivatives.")]
public readonly string Sequence = "active"; public readonly string Sequence = "active";
[CursorReference]
[Desc("Cursor to display when there are no units to apply the condition in range.")]
public readonly string BlockedCursor = "move-blocked";
public readonly string FootprintImage = "overlay"; public readonly string FootprintImage = "overlay";
[SequenceReference(nameof(FootprintImage))] [SequenceReference(nameof(FootprintImage))]

View File

@@ -219,7 +219,7 @@ namespace OpenRA.Mods.Common.Traits
readonly NukePowerInfo info; readonly NukePowerInfo info;
public SelectNukePowerTarget(string order, SupportPowerManager manager, NukePowerInfo info, MouseButton button) public SelectNukePowerTarget(string order, SupportPowerManager manager, NukePowerInfo info, MouseButton button)
: base(order, manager, info.Cursor, button) : base(order, manager, info, button)
{ {
this.info = info; this.info = info;
} }

View File

@@ -116,7 +116,7 @@ namespace OpenRA.Mods.Common.Traits
string IOrderGenerator.GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) string IOrderGenerator.GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
{ {
return world.Map.Contains(cell) ? cursor : "generic-blocked"; return world.Map.Contains(cell) ? info.Cursor : info.BlockedCursor;
} }
bool IOrderGenerator.HandleKeyPress(KeyInput e) { return false; } bool IOrderGenerator.HandleKeyPress(KeyInput e) { return false; }

View File

@@ -46,9 +46,6 @@ namespace OpenRA.Mods.Common.Traits
[PaletteReference] [PaletteReference]
public readonly string EffectPalette = null; public readonly string EffectPalette = null;
[Desc("Cursor to display when the location is unsuitable.")]
public readonly string BlockedCursor = "move-blocked";
public override object Create(ActorInitializer init) { return new SpawnActorPower(init.Self, this); } public override object Create(ActorInitializer init) { return new SpawnActorPower(init.Self, this); }
} }

View File

@@ -46,6 +46,10 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Cursor to display for using this support power.")] [Desc("Cursor to display for using this support power.")]
public readonly string Cursor = "ability"; public readonly string Cursor = "ability";
[CursorReference]
[Desc("Cursor when unable to activate on this position. ")]
public readonly string BlockedCursor = "generic-blocked";
[Desc("If set to true, the support power will be fully charged when it becomes available. " + [Desc("If set to true, the support power will be fully charged when it becomes available. " +
"Normal rules apply for subsequent charges.")] "Normal rules apply for subsequent charges.")]
public readonly bool StartFullyCharged = false; public readonly bool StartFullyCharged = false;
@@ -209,7 +213,7 @@ namespace OpenRA.Mods.Common.Traits
public virtual void SelectTarget(Actor self, string order, SupportPowerManager manager) public virtual void SelectTarget(Actor self, string order, SupportPowerManager manager)
{ {
self.World.OrderGenerator = new SelectGenericPowerTarget(order, manager, info.Cursor, MouseButton.Left); self.World.OrderGenerator = new SelectGenericPowerTarget(order, manager, info, MouseButton.Left);
} }
public virtual void Activate(Actor self, Order order, SupportPowerManager manager) public virtual void Activate(Actor self, Order order, SupportPowerManager manager)

View File

@@ -283,12 +283,12 @@ namespace OpenRA.Mods.Common.Traits
public class SelectGenericPowerTarget : OrderGenerator public class SelectGenericPowerTarget : OrderGenerator
{ {
readonly SupportPowerManager manager; readonly SupportPowerManager manager;
readonly string cursor; readonly SupportPowerInfo info;
readonly MouseButton expectedButton; readonly MouseButton expectedButton;
public string OrderKey { get; } public string OrderKey { get; }
public SelectGenericPowerTarget(string order, SupportPowerManager manager, string cursor, MouseButton button) public SelectGenericPowerTarget(string order, SupportPowerManager manager, SupportPowerInfo info, MouseButton button)
{ {
// Clear selection if using Left-Click Orders // Clear selection if using Left-Click Orders
if (Game.Settings.Game.UseClassicMouseStyle) if (Game.Settings.Game.UseClassicMouseStyle)
@@ -296,7 +296,7 @@ namespace OpenRA.Mods.Common.Traits
this.manager = manager; this.manager = manager;
OrderKey = order; OrderKey = order;
this.cursor = cursor; this.info = info;
expectedButton = button; expectedButton = button;
} }
@@ -319,7 +319,7 @@ namespace OpenRA.Mods.Common.Traits
protected override IEnumerable<IRenderable> RenderAnnotations(WorldRenderer wr, World world) { yield break; } protected override IEnumerable<IRenderable> RenderAnnotations(WorldRenderer wr, World world) { yield break; }
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
{ {
return world.Map.Contains(cell) ? cursor : "generic-blocked"; return world.Map.Contains(cell) ? info.Cursor : info.BlockedCursor;
} }
} }
} }

View File

@@ -0,0 +1,38 @@
#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 System.Collections.Generic;
namespace OpenRA.Mods.Common.UpdateRules.Rules
{
public class AddSupportPowerBlockedCursor : UpdateRule
{
public override string Name => "Add SpawnActorPower/GrantExternalConditionPower BlockedCursor.";
public override string Description =>
"SpawnActorPower and GrantExternalConditionPower field BlockedCursor changed its default value.";
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNodeBuilder actorNode)
{
foreach (var power in new List<string> { "SpawnActorPower", "GrantExternalConditionPower" })
{
foreach (var spawnActorPower in actorNode.ChildrenMatching(power))
{
var cursor = spawnActorPower.LastChildMatching("BlockedCursor");
if (cursor != null && !cursor.IsRemoval())
yield break;
var blockedCursorNode = new MiniYamlNodeBuilder("BlockedCursor", new MiniYamlBuilder("move-blocked"));
spawnActorPower.AddNode(blockedCursorNode);
}
}
}
}
}

View File

@@ -87,6 +87,7 @@ namespace OpenRA.Mods.Common.UpdateRules
new RemoveConyardChronoReturnAnimation(), new RemoveConyardChronoReturnAnimation(),
new RemoveEditorSelectionLayerProperties(), new RemoveEditorSelectionLayerProperties(),
new AddMarkerLayerOverlay(), new AddMarkerLayerOverlay(),
new AddSupportPowerBlockedCursor(),
// Execute these rules last to avoid premature yaml merge crashes. // Execute these rules last to avoid premature yaml merge crashes.
new ReplaceCloakPalette(), new ReplaceCloakPalette(),

View File

@@ -110,6 +110,7 @@ Player:
OnFireSound: ironcur9.aud OnFireSound: ironcur9.aud
Dimensions: 3, 3 Dimensions: 3, 3
Footprint: _x_ xxx _x_ Footprint: _x_ xxx _x_
BlockedCursor: move-blocked
Production: Production:
Produces: Building Produces: Building
LobbyPrerequisiteCheckbox@GLOBALBOUNTY: LobbyPrerequisiteCheckbox@GLOBALBOUNTY:

View File

@@ -382,6 +382,7 @@ powerproxy.sonarpulse:
EffectPalette: moveflash EffectPalette: moveflash
SupportPowerPaletteOrder: 80 SupportPowerPaletteOrder: 80
EffectSequence: idle EffectSequence: idle
BlockedCursor: move-blocked
powerproxy.paratroopers: powerproxy.paratroopers:
AlwaysVisible: AlwaysVisible:

View File

@@ -450,6 +450,7 @@ IRON:
SupportPowerPaletteOrder: 10 SupportPowerPaletteOrder: 10
Dimensions: 3, 3 Dimensions: 3, 3
Footprint: _x_ xxx _x_ Footprint: _x_ xxx _x_
BlockedCursor: move-blocked
SupportPowerChargeBar: SupportPowerChargeBar:
InfiltrateForSupportPowerReset: InfiltrateForSupportPowerReset:
Types: SpyInfiltrate Types: SpyInfiltrate