Replace INotifyBuildComplete in render traits with conditions.
This commit is contained in:
@@ -17,38 +17,40 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Cnc.Traits.Render
|
||||
{
|
||||
[Desc("Building animation to play when ProductionAirdrop is used to deliver units.")]
|
||||
public class WithDeliveryAnimationInfo : ITraitInfo, Requires<WithSpriteBodyInfo>
|
||||
public class WithDeliveryAnimationInfo : ConditionalTraitInfo, Requires<WithSpriteBodyInfo>
|
||||
{
|
||||
[SequenceReference] public readonly string ActiveSequence = "active";
|
||||
|
||||
[SequenceReference] public readonly string IdleSequence = "idle";
|
||||
|
||||
[Desc("Which sprite body to play the animation on.")]
|
||||
public readonly string Body = "body";
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithDeliveryAnimation(init.Self, this); }
|
||||
public override object Create(ActorInitializer init) { return new WithDeliveryAnimation(init.Self, this); }
|
||||
}
|
||||
|
||||
public class WithDeliveryAnimation : INotifyDelivery
|
||||
public class WithDeliveryAnimation : ConditionalTrait<WithDeliveryAnimationInfo>, INotifyDelivery
|
||||
{
|
||||
readonly WithDeliveryAnimationInfo info;
|
||||
readonly WithSpriteBody wsb;
|
||||
|
||||
public WithDeliveryAnimation(Actor self, WithDeliveryAnimationInfo info)
|
||||
: base(info)
|
||||
{
|
||||
wsb = self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == info.Body);
|
||||
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void IncomingDelivery(Actor self)
|
||||
{
|
||||
wsb.PlayCustomAnimationRepeating(self, info.ActiveSequence);
|
||||
if (!IsTraitDisabled)
|
||||
wsb.PlayCustomAnimationRepeating(self, Info.ActiveSequence);
|
||||
}
|
||||
|
||||
public void Delivered(Actor self)
|
||||
{
|
||||
wsb.PlayCustomAnimationRepeating(self, info.IdleSequence);
|
||||
wsb.CancelCustomAnimation(self);
|
||||
}
|
||||
|
||||
protected override void TraitDisabled(Actor self)
|
||||
{
|
||||
wsb.CancelCustomAnimation(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Cnc.Traits.Render
|
||||
{
|
||||
[Desc("Rendered on the refinery when a voxel harvester is docking and undocking.")]
|
||||
public class WithDockingOverlayInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<BodyOrientationInfo>
|
||||
public class WithDockingOverlayInfo : PausableConditionalTraitInfo, Requires<RenderSpritesInfo>, Requires<BodyOrientationInfo>
|
||||
{
|
||||
[Desc("Sequence name to use")]
|
||||
[SequenceReference] public readonly string Sequence = "unload-overlay";
|
||||
@@ -31,29 +31,27 @@ namespace OpenRA.Mods.Cnc.Traits.Render
|
||||
[Desc("Custom palette is a player palette BaseName")]
|
||||
public readonly bool IsPlayerPalette = false;
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithDockingOverlay(init.Self, this); }
|
||||
public override object Create(ActorInitializer init) { return new WithDockingOverlay(init.Self, this); }
|
||||
}
|
||||
|
||||
public class WithDockingOverlay
|
||||
public class WithDockingOverlay : PausableConditionalTrait<WithDockingOverlayInfo>
|
||||
{
|
||||
public readonly WithDockingOverlayInfo Info;
|
||||
public readonly AnimationWithOffset WithOffset;
|
||||
|
||||
public bool Visible;
|
||||
|
||||
public WithDockingOverlay(Actor self, WithDockingOverlayInfo info)
|
||||
: base(info)
|
||||
{
|
||||
Info = info;
|
||||
|
||||
var rs = self.Trait<RenderSprites>();
|
||||
var body = self.Trait<BodyOrientation>();
|
||||
|
||||
var overlay = new Animation(self.World, rs.GetImage(self));
|
||||
var overlay = new Animation(self.World, rs.GetImage(self), () => IsTraitPaused);
|
||||
overlay.Play(info.Sequence);
|
||||
|
||||
WithOffset = new AnimationWithOffset(overlay,
|
||||
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
|
||||
() => !Visible);
|
||||
() => !Visible || IsTraitDisabled);
|
||||
|
||||
rs.Add(WithOffset, info.Palette, info.IsPlayerPalette);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user