Replace INotifyBuildComplete in render traits with conditions.

This commit is contained in:
Paul Chote
2018-10-05 20:16:36 +00:00
committed by abcdefg30
parent 26b0a06a17
commit 14607f55c5
28 changed files with 152 additions and 407 deletions

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits.Render
}
}
public class WithSpriteTurret : ConditionalTrait<WithSpriteTurretInfo>, INotifyBuildComplete, INotifySold, INotifyTransform, INotifyDamageStateChanged
public class WithSpriteTurret : ConditionalTrait<WithSpriteTurretInfo>, INotifyDamageStateChanged
{
public readonly Animation DefaultAnimation;
readonly RenderSprites rs;
@@ -78,9 +78,6 @@ namespace OpenRA.Mods.Common.Traits.Render
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)
{
@@ -90,13 +87,12 @@ namespace OpenRA.Mods.Common.Traits.Render
.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 || !buildComplete,
() => IsTraitDisabled,
p => RenderUtils.ZOffsetFromCenter(self, p, 1)), info.Palette, info.IsPlayerPalette);
// Restrict turret facings to match the sprite
@@ -144,12 +140,5 @@ namespace OpenRA.Mods.Common.Traits.Render
{
DefaultAnimation.PlayRepeating(NormalizeSequence(self, Info.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) { }
}
}