Add a lint check for cursor definitions.

This commit is contained in:
Matthias Mailänder
2021-03-14 16:01:33 +01:00
committed by reaperrr
parent cefb2e7cc6
commit bbbed49f82
40 changed files with 211 additions and 28 deletions

View File

@@ -88,6 +88,7 @@ namespace OpenRA.Mods.Cnc.Traits
"A dictionary of [actor id]: [condition].")]
public readonly Dictionary<string, string> DisguisedAsConditions = new Dictionary<string, string>();
[CursorReference]
[Desc("Cursor to display when hovering over a valid actor to disguise as.")]
public readonly string Cursor = "ability";

View File

@@ -44,6 +44,7 @@ namespace OpenRA.Mods.Cnc.Traits
[Desc("Experience to grant to the infiltrating player.")]
public readonly int PlayerExperience = 0;
[CursorReference]
[Desc("Cursor to display when able to infiltrate the target actor.")]
public readonly string EnterCursor = "enter";

View File

@@ -61,7 +61,15 @@ namespace OpenRA.Mods.Cnc.Traits
[Desc("Types of damage that this trait causes to self while self-destructing. Leave empty for no damage types.")]
public readonly BitSet<DamageType> DamageTypes = default(BitSet<DamageType>);
public override object Create(ActorInitializer init) { return new MadTank(init.Self, this); }
[CursorReference]
[Desc("Cursor to display when targetting.")]
public readonly string AttackCursor = "attack";
[CursorReference]
[Desc("Cursor to display when able to set up the detonation sequence.")]
public readonly string DeployCursor = "deploy";
public override object Create(ActorInitializer init) { return new MadTank(this); }
public void RulesetLoaded(Ruleset rules, ActorInfo ai)
{
@@ -83,7 +91,9 @@ namespace OpenRA.Mods.Cnc.Traits
{
readonly MadTankInfo info;
public MadTank(Actor self, MadTankInfo info)
bool initiated;
public MadTank(MadTankInfo info)
{
this.info = info;
}
@@ -92,8 +102,10 @@ namespace OpenRA.Mods.Cnc.Traits
{
get
{
yield return new TargetTypeOrderTargeter(new BitSet<TargetableType>("DetonateAttack"), "DetonateAttack", 5, "attack", true, false) { ForceAttack = false };
yield return new DeployOrderTargeter("Detonate", 5);
yield return new TargetTypeOrderTargeter(new BitSet<TargetableType>("DetonateAttack"), "DetonateAttack", 5, info.AttackCursor, true, false) { ForceAttack = false };
if (!initiated)
yield return new DeployOrderTargeter("Detonate", 5, () => info.DeployCursor);
}
}
@@ -140,7 +152,6 @@ namespace OpenRA.Mods.Cnc.Traits
readonly bool assignTargetOnFirstRun;
int ticks;
bool initiated;
Target target;
public DetonationSequence(Actor self, MadTank mad)
@@ -176,7 +187,7 @@ namespace OpenRA.Mods.Cnc.Traits
return false;
}
if (!initiated)
if (!mad.initiated)
{
// If the target has died while we were moving, we should abort detonation.
if (target.Type == TargetType.Invalid)
@@ -189,7 +200,7 @@ namespace OpenRA.Mods.Cnc.Traits
wfsb.PlayCustomAnimationRepeating(self, mad.info.ThumpSequence);
IsInterruptible = false;
initiated = true;
mad.initiated = true;
}
if (++ticks % mad.info.ThumpInterval == 0)
@@ -209,7 +220,7 @@ namespace OpenRA.Mods.Cnc.Traits
protected override void OnLastRun(Actor self)
{
if (!initiated)
if (!mad.initiated)
return;
Game.Sound.Play(SoundType.World, mad.info.DetonationSound, self.CenterPosition);

View File

@@ -50,12 +50,18 @@ namespace OpenRA.Mods.Cnc.Traits
[Desc("Only allow laying mines on listed terrain types. Leave empty to allow all terrain types.")]
public readonly HashSet<string> TerrainTypes = new HashSet<string>();
[CursorReference]
[Desc("Cursor to display when able to lay a mine.")]
public readonly string DeployCursor = "deploy";
[CursorReference]
[Desc("Cursor to display when unable to lay a mine.")]
public readonly string DeployBlockedCursor = "deploy-blocked";
[CursorReference]
[Desc("Cursor to display when able to lay a mine.")]
public readonly string AbilityCursor = "ability";
public override object Create(ActorInitializer init) { return new Minelayer(init.Self, this); }
}
@@ -85,7 +91,7 @@ namespace OpenRA.Mods.Cnc.Traits
{
get
{
yield return new BeginMinefieldOrderTargeter();
yield return new BeginMinefieldOrderTargeter(Info.AbilityCursor);
yield return new DeployOrderTargeter("PlaceMine", 5, () => IsCellAcceptable(self, self.Location) ? Info.DeployCursor : Info.DeployBlockedCursor);
}
}
@@ -97,7 +103,7 @@ namespace OpenRA.Mods.Cnc.Traits
case "BeginMinefield":
var start = self.World.Map.CellContaining(target.CenterPosition);
if (self.World.OrderGenerator is MinefieldOrderGenerator)
((MinefieldOrderGenerator)self.World.OrderGenerator).AddMinelayer(self, start);
((MinefieldOrderGenerator)self.World.OrderGenerator).AddMinelayer(self);
else
self.World.OrderGenerator = new MinefieldOrderGenerator(self, start, queued);
@@ -204,6 +210,7 @@ namespace OpenRA.Mods.Cnc.Traits
readonly float validAlpha, unknownAlpha, blockedAlpha;
readonly CPos minefieldStart;
readonly bool queued;
readonly string cursor;
public MinefieldOrderGenerator(Actor a, CPos xy, bool queued)
{
@@ -251,9 +258,11 @@ namespace OpenRA.Mods.Cnc.Traits
blockedTile = blockedSequence.GetSprite(0);
blockedAlpha = blockedSequence.GetAlpha(0);
}
cursor = minelayer.Info.AbilityCursor;
}
public void AddMinelayer(Actor a, CPos xy)
public void AddMinelayer(Actor a)
{
minelayers.Add(a);
}
@@ -331,7 +340,7 @@ namespace OpenRA.Mods.Cnc.Traits
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
{
return "ability";
return cursor;
}
}
@@ -339,6 +348,14 @@ namespace OpenRA.Mods.Cnc.Traits
{
public string OrderID => "BeginMinefield";
public int OrderPriority => 5;
readonly string cursor;
public BeginMinefieldOrderTargeter(string cursor)
{
this.cursor = cursor;
}
public bool TargetOverridesSelection(Actor self, in Target target, List<Actor> actorsAt, CPos xy, TargetModifiers modifiers) { return true; }
public bool CanTarget(Actor self, in Target target, List<Actor> othersAtTarget, ref TargetModifiers modifiers, ref string cursor)
@@ -350,7 +367,8 @@ namespace OpenRA.Mods.Cnc.Traits
if (!self.World.Map.Contains(location))
return false;
cursor = "ability";
cursor = this.cursor;
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
return modifiers.HasModifier(TargetModifiers.ForceAttack);

View File

@@ -35,15 +35,19 @@ namespace OpenRA.Mods.Cnc.Traits
[Desc("Sound to play when teleporting.")]
public readonly string ChronoshiftSound = "chrotnk1.aud";
[CursorReference]
[Desc("Cursor to display when able to deploy the actor.")]
public readonly string DeployCursor = "deploy";
[CursorReference]
[Desc("Cursor to display when unable to deploy the actor.")]
public readonly string DeployBlockedCursor = "deploy-blocked";
[CursorReference]
[Desc("Cursor to display when targeting a teleport location.")]
public readonly string TargetCursor = "chrono-target";
[CursorReference]
[Desc("Cursor to display when the targeted location is blocked.")]
public readonly string TargetBlockedCursor = "move-blocked";

View File

@@ -48,12 +48,15 @@ namespace OpenRA.Mods.Cnc.Traits
public readonly bool KillCargo = true;
[CursorReference]
[Desc("Cursor to display when selecting targets for the chronoshift.")]
public readonly string SelectionCursor = "chrono-select";
[CursorReference]
[Desc("Cursor to display when targeting an area for the chronoshift.")]
public readonly string TargetCursor = "chrono-target";
[CursorReference]
[Desc("Cursor to display when the targeted area is blocked.")]
public readonly string TargetBlockedCursor = "move-blocked";