Make With(Turret)AimAnimation support multiple AttackBase traits
This commit is contained in:
committed by
Matthias Mailänder
parent
ee3c54b572
commit
f2eb42a4b2
@@ -41,25 +41,35 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
|
|
||||||
public class WithAimAnimation : ConditionalTrait<WithAimAnimationInfo>, INotifyAiming
|
public class WithAimAnimation : ConditionalTrait<WithAimAnimationInfo>, INotifyAiming
|
||||||
{
|
{
|
||||||
readonly AttackBase attack;
|
readonly AttackBase[] attackBases;
|
||||||
readonly WithSpriteBody wsb;
|
readonly WithSpriteBody wsb;
|
||||||
|
|
||||||
public WithAimAnimation(ActorInitializer init, WithAimAnimationInfo info)
|
public WithAimAnimation(ActorInitializer init, WithAimAnimationInfo info)
|
||||||
: base(info)
|
: base(info)
|
||||||
{
|
{
|
||||||
attack = init.Self.Trait<AttackBase>();
|
attackBases = init.Self.TraitsImplementing<AttackBase>().ToArray();
|
||||||
wsb = init.Self.TraitsImplementing<WithSpriteBody>().First(w => w.Info.Name == Info.Body);
|
wsb = init.Self.TraitsImplementing<WithSpriteBody>().First(w => w.Info.Name == Info.Body);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void UpdateSequence()
|
void UpdateSequence(bool isAiming)
|
||||||
{
|
{
|
||||||
var seq = !IsTraitDisabled && attack.IsAiming ? Info.Sequence : wsb.Info.Sequence;
|
var seq = !IsTraitDisabled && isAiming ? Info.Sequence : wsb.Info.Sequence;
|
||||||
wsb.DefaultAnimation.ReplaceAnim(seq);
|
wsb.DefaultAnimation.ReplaceAnim(seq);
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyAiming.StartedAiming(Actor self, AttackBase ab) { UpdateSequence(); }
|
void INotifyAiming.StartedAiming(Actor self, AttackBase ab)
|
||||||
void INotifyAiming.StoppedAiming(Actor self, AttackBase ab) { UpdateSequence(); }
|
{
|
||||||
protected override void TraitEnabled(Actor self) { UpdateSequence(); }
|
// We know that at least one AttackBase is aiming
|
||||||
protected override void TraitDisabled(Actor self) { UpdateSequence(); }
|
UpdateSequence(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void INotifyAiming.StoppedAiming(Actor self, AttackBase ab) { UpdateSequence(attackBases.Any(a => a.IsAiming)); }
|
||||||
|
protected override void TraitEnabled(Actor self) { UpdateSequence(attackBases.Any(a => a.IsAiming)); }
|
||||||
|
|
||||||
|
protected override void TraitDisabled(Actor self)
|
||||||
|
{
|
||||||
|
// Stop regardless of any aiming AttackBases
|
||||||
|
UpdateSequence(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,26 +41,35 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
|
|
||||||
public class WithTurretAimAnimation : ConditionalTrait<WithTurretAimAnimationInfo>, INotifyAiming
|
public class WithTurretAimAnimation : ConditionalTrait<WithTurretAimAnimationInfo>, INotifyAiming
|
||||||
{
|
{
|
||||||
readonly AttackBase attack;
|
readonly AttackBase[] attackBases;
|
||||||
readonly WithSpriteTurret wst;
|
readonly WithSpriteTurret wst;
|
||||||
|
|
||||||
public WithTurretAimAnimation(ActorInitializer init, WithTurretAimAnimationInfo info)
|
public WithTurretAimAnimation(ActorInitializer init, WithTurretAimAnimationInfo info)
|
||||||
: base(info)
|
: base(info)
|
||||||
{
|
{
|
||||||
attack = init.Self.Trait<AttackBase>();
|
attackBases = init.Self.TraitsImplementing<AttackBase>().ToArray();
|
||||||
wst = init.Self.TraitsImplementing<WithSpriteTurret>()
|
wst = init.Self.TraitsImplementing<WithSpriteTurret>().Single(st => st.Info.Turret == info.Turret);
|
||||||
.Single(st => st.Info.Turret == info.Turret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void UpdateSequence()
|
void UpdateSequence(bool isAiming)
|
||||||
{
|
{
|
||||||
var seq = !IsTraitDisabled && attack.IsAiming ? Info.Sequence : wst.Info.Sequence;
|
var seq = !IsTraitDisabled && isAiming ? Info.Sequence : wst.Info.Sequence;
|
||||||
wst.DefaultAnimation.ReplaceAnim(seq);
|
wst.DefaultAnimation.ReplaceAnim(seq);
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyAiming.StartedAiming(Actor self, AttackBase ab) { UpdateSequence(); }
|
void INotifyAiming.StartedAiming(Actor self, AttackBase ab)
|
||||||
void INotifyAiming.StoppedAiming(Actor self, AttackBase ab) { UpdateSequence(); }
|
{
|
||||||
protected override void TraitEnabled(Actor self) { UpdateSequence(); }
|
// We know that at least one AttackBase is aiming
|
||||||
protected override void TraitDisabled(Actor self) { UpdateSequence(); }
|
UpdateSequence(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void INotifyAiming.StoppedAiming(Actor self, AttackBase ab) { UpdateSequence(attackBases.Any(a => a.IsAiming)); }
|
||||||
|
protected override void TraitEnabled(Actor self) { UpdateSequence(attackBases.Any(a => a.IsAiming)); }
|
||||||
|
|
||||||
|
protected override void TraitDisabled(Actor self)
|
||||||
|
{
|
||||||
|
// Stop regardless of any aiming AttackBases
|
||||||
|
UpdateSequence(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user