Unhardcode the capture cursors.

This commit is contained in:
Matthias Mailänder
2016-07-23 23:50:02 +02:00
parent 40754e3ddb
commit da509d6394
2 changed files with 17 additions and 6 deletions

View File

@@ -35,6 +35,10 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Stance that the structure's previous owner needs to have for the capturing player to receive Experience.")] [Desc("Stance that the structure's previous owner needs to have for the capturing player to receive Experience.")]
public readonly Stance PlayerExperienceStances = Stance.Enemy; public readonly Stance PlayerExperienceStances = Stance.Enemy;
public readonly string SabotageCursor = "capture";
public readonly string EnterCursor = "enter";
public readonly string EnterBlockedCursor = "enter-blocked";
[VoiceReference] public readonly string Voice = "Action"; [VoiceReference] public readonly string Voice = "Action";
public object Create(ActorInitializer init) { return new Captures(init.Self, this); } public object Create(ActorInitializer init) { return new Captures(init.Self, this); }
@@ -101,10 +105,11 @@ namespace OpenRA.Mods.Common.Traits
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor) public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
{ {
var capturesInfo = self.Trait<Captures>().Info;
var c = target.Info.TraitInfoOrDefault<CapturableInfo>(); var c = target.Info.TraitInfoOrDefault<CapturableInfo>();
if (c == null || !c.CanBeTargetedBy(self, target.Owner)) if (c == null || !c.CanBeTargetedBy(self, target.Owner))
{ {
cursor = "enter-blocked"; cursor = capturesInfo.EnterBlockedCursor;
return false; return false;
} }
@@ -112,16 +117,17 @@ namespace OpenRA.Mods.Common.Traits
var lowEnoughHealth = health.HP <= c.CaptureThreshold * health.MaxHP / 100; var lowEnoughHealth = health.HP <= c.CaptureThreshold * health.MaxHP / 100;
cursor = !sabotage || lowEnoughHealth || target.Owner.NonCombatant cursor = !sabotage || lowEnoughHealth || target.Owner.NonCombatant
? "enter" : "capture"; ? capturesInfo.EnterCursor : capturesInfo.SabotageCursor;
return true; return true;
} }
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor) public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{ {
var capturesInfo = self.Trait<Captures>().Info;
var c = target.Info.TraitInfoOrDefault<CapturableInfo>(); var c = target.Info.TraitInfoOrDefault<CapturableInfo>();
if (c == null || !c.CanBeTargetedBy(self, target.Owner)) if (c == null || !c.CanBeTargetedBy(self, target.Owner))
{ {
cursor = "enter-blocked"; cursor = capturesInfo.EnterCursor;
return false; return false;
} }
@@ -129,7 +135,7 @@ namespace OpenRA.Mods.Common.Traits
var lowEnoughHealth = target.HP <= c.CaptureThreshold * health.HP / 100; var lowEnoughHealth = target.HP <= c.CaptureThreshold * health.HP / 100;
cursor = !sabotage || lowEnoughHealth || target.Owner.NonCombatant cursor = !sabotage || lowEnoughHealth || target.Owner.NonCombatant
? "enter" : "capture"; ? capturesInfo.EnterCursor : capturesInfo.SabotageCursor;
return true; return true;
} }

View File

@@ -34,6 +34,9 @@ namespace OpenRA.Mods.Common.Traits
[VoiceReference] public readonly string Voice = "Action"; [VoiceReference] public readonly string Voice = "Action";
public readonly string CaptureCursor = "ability";
public readonly string CaptureBlockedCursor = "move-blocked";
public object Create(ActorInitializer init) { return new ExternalCaptures(init.Self, this); } public object Create(ActorInitializer init) { return new ExternalCaptures(init.Self, this); }
} }
@@ -122,7 +125,8 @@ namespace OpenRA.Mods.Common.Traits
var c = target.TraitOrDefault<ExternalCapturable>(); var c = target.TraitOrDefault<ExternalCapturable>();
var canTargetActor = c != null && !c.CaptureInProgress && c.Info.CanBeTargetedBy(self, target.Owner); var canTargetActor = c != null && !c.CaptureInProgress && c.Info.CanBeTargetedBy(self, target.Owner);
cursor = canTargetActor ? "ability" : "move-blocked"; var capturesInfo = self.Trait<ExternalCaptures>().Info;
cursor = canTargetActor ? capturesInfo.CaptureCursor : capturesInfo.CaptureBlockedCursor;
return canTargetActor; return canTargetActor;
} }
@@ -131,7 +135,8 @@ namespace OpenRA.Mods.Common.Traits
var c = target.Info.TraitInfoOrDefault<ExternalCapturableInfo>(); var c = target.Info.TraitInfoOrDefault<ExternalCapturableInfo>();
var canTargetActor = c != null && c.CanBeTargetedBy(self, target.Owner); var canTargetActor = c != null && c.CanBeTargetedBy(self, target.Owner);
cursor = canTargetActor ? "ability" : "move-blocked"; var capturesInfo = self.Trait<ExternalCaptures>().Info;
cursor = canTargetActor ? capturesInfo.CaptureCursor : capturesInfo.CaptureBlockedCursor;
return canTargetActor; return canTargetActor;
} }
} }