Disable WithSpriteTurret until build/transform complete

This commit is contained in:
reaperrr
2015-12-14 15:27:52 +01:00
parent bee590a057
commit 0d60ee5fe0

View File

@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
public class WithSpriteTurret : UpgradableTrait<WithSpriteTurretInfo>, ITick, INotifyDamageStateChanged
public class WithSpriteTurret : UpgradableTrait<WithSpriteTurretInfo>, INotifyBuildComplete, INotifySold, INotifyTransform, ITick, INotifyDamageStateChanged
{
public readonly Animation DefaultAnimation;
protected readonly AttackBase Attack;
@@ -65,6 +65,9 @@ namespace OpenRA.Mods.Common.Traits
readonly Turreted t;
readonly Armament[] arms;
// TODO: This should go away once https://github.com/OpenRA/OpenRA/issues/7035 is implemented
bool buildComplete;
public WithSpriteTurret(Actor self, WithSpriteTurretInfo info)
: base(info)
{
@@ -75,11 +78,14 @@ namespace OpenRA.Mods.Common.Traits
.First(tt => tt.Name == info.Turret);
arms = self.TraitsImplementing<Armament>()
.Where(w => w.Info.Turret == info.Turret).ToArray();
buildComplete = !self.Info.HasTraitInfo<BuildingInfo>(); // always render instantly for units
DefaultAnimation = new Animation(self.World, rs.GetImage(self), () => t.TurretFacing);
DefaultAnimation.PlayRepeating(NormalizeSequence(self, info.Sequence));
rs.Add(new AnimationWithOffset(
DefaultAnimation, () => TurretOffset(self), () => IsTraitDisabled, p => RenderUtils.ZOffsetFromCenter(self, p, 1)));
rs.Add(new AnimationWithOffset(DefaultAnimation,
() => TurretOffset(self),
() => IsTraitDisabled || !buildComplete,
p => RenderUtils.ZOffsetFromCenter(self, p, 1)));
// Restrict turret facings to match the sprite
t.QuantizedFacings = DefaultAnimation.CurrentSequence.Facings;
@@ -116,5 +122,12 @@ namespace OpenRA.Mods.Common.Traits
var sequence = Attack.IsAttacking ? Info.AimSequence : Info.Sequence;
DefaultAnimation.ReplaceAnim(sequence);
}
void INotifyBuildComplete.BuildingComplete(Actor self) { buildComplete = true; }
void INotifySold.Selling(Actor self) { buildComplete = false; }
void INotifySold.Sold(Actor self) { }
void INotifyTransform.BeforeTransform(Actor self) { buildComplete = false; }
void INotifyTransform.OnTransform(Actor self) { }
void INotifyTransform.AfterTransform(Actor toActor) { }
}
}