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

@@ -26,33 +26,25 @@ namespace OpenRA.Mods.Common.Traits.Render
public override object Create(ActorInitializer init) { return new WithNukeLaunchAnimation(init.Self, this); }
}
public class WithNukeLaunchAnimation : ConditionalTrait<WithNukeLaunchAnimationInfo>, INotifyNuke, INotifyBuildComplete, INotifySold
public class WithNukeLaunchAnimation : ConditionalTrait<WithNukeLaunchAnimationInfo>, INotifyNuke
{
readonly WithSpriteBody spriteBody;
bool buildComplete;
readonly WithSpriteBody wsb;
public WithNukeLaunchAnimation(Actor self, WithNukeLaunchAnimationInfo info)
: base(info)
{
spriteBody = self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == Info.Body);
wsb = self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == Info.Body);
}
void INotifyNuke.Launching(Actor self)
{
if (buildComplete && !IsTraitDisabled)
spriteBody.PlayCustomAnimation(self, Info.Sequence, () => spriteBody.CancelCustomAnimation(self));
if (!IsTraitDisabled)
wsb.PlayCustomAnimation(self, Info.Sequence, () => wsb.CancelCustomAnimation(self));
}
void INotifyBuildComplete.BuildingComplete(Actor self)
protected override void TraitDisabled(Actor self)
{
buildComplete = true;
wsb.CancelCustomAnimation(self);
}
void INotifySold.Selling(Actor self)
{
buildComplete = false;
}
void INotifySold.Sold(Actor self) { }
}
}