diff --git a/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs b/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs index 7b5140d034..e3689bfdca 100644 --- a/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs +++ b/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs @@ -8,15 +8,17 @@ */ #endregion +using System.Collections.Generic; using System.Linq; using OpenRA.Effects; +using OpenRA.Graphics; using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { [Desc("Allows the player to execute build orders.", " Attach this to the player actor.")] - public class PlaceBuildingInfo : ITraitInfo + public class PlaceBuildingInfo : ITraitInfo, IPlaceBuildingDecoration { [Desc("Palette to use for rendering the placement sprite.")] [PaletteReference] public readonly string Palette = "terrain"; @@ -28,6 +30,16 @@ namespace OpenRA.Mods.Common.Traits public readonly string NewOptionsNotification = "NewOptions"; public object Create(ActorInitializer init) { return new PlaceBuilding(this); } + + public IEnumerable Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition) + { + if (!ai.Traits.Get().RequiresBaseProvider) + yield break; + + foreach (var a in w.ActorsWithTrait()) + foreach (var r in a.Trait.RenderAfterWorld(wr)) + yield return r; + } } public class PlaceBuilding : IResolveOrder diff --git a/OpenRA.Mods.Common/Traits/Render/RenderBuilding.cs b/OpenRA.Mods.Common/Traits/Render/RenderBuilding.cs index 15612e5588..c8333623b5 100644 --- a/OpenRA.Mods.Common/Traits/Render/RenderBuilding.cs +++ b/OpenRA.Mods.Common/Traits/Render/RenderBuilding.cs @@ -17,21 +17,11 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { [Desc("Render trait for stationary objects that can be placed from the build palette.")] - public class RenderBuildingInfo : RenderSimpleInfo, Requires, IPlaceBuildingDecoration + public class RenderBuildingInfo : RenderSimpleInfo, Requires { public readonly bool PauseOnLowPower = false; public override object Create(ActorInitializer init) { return new RenderBuilding(init, this); } - - public IEnumerable Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition) - { - if (!ai.Traits.Get().RequiresBaseProvider) - yield break; - - foreach (var a in w.ActorsWithTrait()) - foreach (var r in a.Trait.RenderAfterWorld(wr)) - yield return r; - } } public class RenderBuilding : RenderSimple, INotifyDamageStateChanged, INotifyBuildComplete diff --git a/OpenRA.Mods.Common/Traits/Render/WithSpriteBody.cs b/OpenRA.Mods.Common/Traits/Render/WithSpriteBody.cs index c4861111ce..dbb82faed1 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithSpriteBody.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithSpriteBody.cs @@ -25,6 +25,9 @@ namespace OpenRA.Mods.Common.Traits [Desc("Animation to play when the actor is idle.")] [SequenceReference] public readonly string Sequence = "idle"; + [Desc("Pause animation when actor is disabled.")] + public readonly bool PauseAnimationWhenDisabled = false; + public override object Create(ActorInitializer init) { return new WithSpriteBody(init, this); } public virtual IEnumerable RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p) @@ -36,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits } } - public class WithSpriteBody : UpgradableTrait, ISpriteBody, INotifyDamageStateChanged + public class WithSpriteBody : UpgradableTrait, ISpriteBody, INotifyDamageStateChanged, INotifyBuildComplete { public readonly Animation DefaultAnimation; @@ -63,6 +66,16 @@ namespace OpenRA.Mods.Common.Traits return RenderSprites.NormalizeSequence(DefaultAnimation, self.GetDamageState(), sequence); } + // TODO: Get rid of INotifyBuildComplete in favor of using the upgrade system + public virtual void BuildingComplete(Actor self) + { + DefaultAnimation.PlayRepeating(NormalizeSequence(self, Info.Sequence)); + + if (Info.PauseAnimationWhenDisabled) + DefaultAnimation.Paused = () => + self.IsDisabled() && DefaultAnimation.CurrentSequence.Name == NormalizeSequence(self, Info.Sequence); + } + public void PlayCustomAnimation(Actor self, string name, Action after = null) { DefaultAnimation.PlayThen(NormalizeSequence(self, name), () =>