Files
OpenRA/OpenRA.Mods.Common/Traits/Render/WithTurretAimAnimation.cs
reaperrr fd83cbf60f Fix WithTurretAimAnimation disabled handling
The old sequence was not recovering when this trait lost its required
condition while the aim anim was running.

Now it doesn't unconditionally return, but instead checks what the
current sequence is and resets to base turret sequence if AimAnim is
disabled.
2018-03-10 00:13:42 +01:00

80 lines
2.6 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2018 The OpenRA Developers (see AUTHORS)
* 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.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
public class WithTurretAimAnimationInfo : ConditionalTraitInfo, Requires<WithSpriteTurretInfo>, Requires<ArmamentInfo>, Requires<AttackBaseInfo>
{
[Desc("Armament name")]
public readonly string Armament = "primary";
[Desc("Turret name")]
public readonly string Turret = "primary";
[Desc("Displayed while targeting.")]
[SequenceReference] public readonly string Sequence = null;
[Desc("Shown while reloading.")]
[SequenceReference(null, true)] public readonly string ReloadPrefix = null;
public override object Create(ActorInitializer init) { return new WithTurretAimAnimation(init, this); }
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
{
var turretAttackAnim = ai.TraitInfos<WithTurretAttackAnimationInfo>().Any(t => t.Turret == Turret);
if (turretAttackAnim)
throw new YamlException("WithTurretAimAnimation is currently not compatible with WithTurretAttackAnimation. Don't use them on the same turret.");
base.RulesetLoaded(rules, ai);
}
}
public class WithTurretAimAnimation : ConditionalTrait<WithTurretAimAnimationInfo>, ITick
{
readonly AttackBase attack;
readonly Armament armament;
readonly WithSpriteTurret wst;
string sequence;
public WithTurretAimAnimation(ActorInitializer init, WithTurretAimAnimationInfo info)
: base(info)
{
attack = init.Self.Trait<AttackBase>();
armament = init.Self.TraitsImplementing<Armament>()
.Single(a => a.Info.Name == info.Armament);
wst = init.Self.TraitsImplementing<WithSpriteTurret>()
.Single(st => st.Info.Turret == info.Turret);
sequence = wst.Info.Sequence;
}
void ITick.Tick(Actor self)
{
if (IsTraitDisabled && sequence == wst.Info.Sequence)
return;
sequence = wst.Info.Sequence;
if (!IsTraitDisabled && !string.IsNullOrEmpty(Info.Sequence) && attack.IsAiming)
sequence = Info.Sequence;
var prefix = (armament.IsReloading && !string.IsNullOrEmpty(Info.ReloadPrefix)) ? Info.ReloadPrefix : "";
if (!IsTraitDisabled && !string.IsNullOrEmpty(prefix) && sequence != (prefix + sequence))
sequence = prefix + sequence;
wst.DefaultAnimation.ReplaceAnim(sequence);
}
}
}