diff --git a/OpenRA.Game/Graphics/Animation.cs b/OpenRA.Game/Graphics/Animation.cs index d851c20094..25b97440eb 100644 --- a/OpenRA.Game/Graphics/Animation.cs +++ b/OpenRA.Game/Graphics/Animation.cs @@ -69,12 +69,6 @@ namespace OpenRA.Graphics return Render(pos, WVec.Zero, 0, palette, 1f); } - public void Initialize(string sequenceName) - { - CurrentSequence = sequenceProvider.GetSequence(name, sequenceName); - tickAlways = true; - } - public void Play(string sequenceName) { PlayThen(sequenceName, null); diff --git a/OpenRA.Game/Traits/Render/RenderSimple.cs b/OpenRA.Game/Traits/Render/RenderSimple.cs index a1dae7459f..032eb4edd5 100755 --- a/OpenRA.Game/Traits/Render/RenderSimple.cs +++ b/OpenRA.Game/Traits/Render/RenderSimple.cs @@ -41,7 +41,7 @@ namespace OpenRA.Traits public RenderSimple(Actor self) : this(self, MakeFacingFunc(self)) { - DefaultAnimation.PlayRepeating("idle"); + DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle")); self.Trait().SetAutodetectedFacings(DefaultAnimation.CurrentSequence.Facings); } diff --git a/OpenRA.Mods.RA/Buildings/Building.cs b/OpenRA.Mods.RA/Buildings/Building.cs index a467b7c288..839fad50f0 100644 --- a/OpenRA.Mods.RA/Buildings/Building.cs +++ b/OpenRA.Mods.RA/Buildings/Building.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Primitives; using OpenRA.Traits; +using OpenRA.Mods.RA.Render; namespace OpenRA.Mods.RA.Buildings { @@ -100,12 +101,13 @@ namespace OpenRA.Mods.RA.Buildings } } - public class Building : INotifyDamage, IOccupySpace, INotifyCapture, INotifyBuildComplete, INotifySold, INotifyTransform, ISync, ITechTreePrerequisite, INotifyAddedToWorld, INotifyRemovedFromWorld + public class Building : INotifyDamage, IOccupySpace, INotifyCapture, ITick, INotifySold, INotifyTransform, ISync, ITechTreePrerequisite, INotifyAddedToWorld, INotifyRemovedFromWorld { public readonly BuildingInfo Info; public bool BuildComplete { get; private set; } [Sync] readonly CPos topLeft; readonly Actor self; + readonly bool skipMakeAnimation; PowerManager PlayerPower; @@ -139,7 +141,7 @@ namespace OpenRA.Mods.RA.Buildings .Select(c => Pair.New(c, SubCell.FullCell)).ToArray(); CenterPosition = init.world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(init.world, Info); - BuildComplete = init.Contains(); + skipMakeAnimation = init.Contains(); } public int GetPowerUsage() @@ -180,10 +182,22 @@ namespace OpenRA.Mods.RA.Buildings self.World.ScreenMap.Remove(self); } - public void BuildingComplete(Actor self) + public void Tick(Actor self) { + if (!BuildComplete && (skipMakeAnimation || !self.HasTrait())) + NotifyBuildingComplete(self); + } + + public void NotifyBuildingComplete(Actor self) + { + if (BuildComplete) + return; + BuildComplete = true; Locked = false; + + foreach (var notify in self.TraitsImplementing()) + notify.BuildingComplete(self); } public void Selling(Actor self) @@ -193,6 +207,7 @@ namespace OpenRA.Mods.RA.Buildings BuildComplete = false; } + public void Sold(Actor self) { } public void BeforeTransform(Actor self) diff --git a/OpenRA.Mods.RA/Render/RenderBuilding.cs b/OpenRA.Mods.RA/Render/RenderBuilding.cs index e8a49ef6c0..e1f6f02998 100755 --- a/OpenRA.Mods.RA/Render/RenderBuilding.cs +++ b/OpenRA.Mods.RA/Render/RenderBuilding.cs @@ -36,8 +36,6 @@ namespace OpenRA.Mods.RA.Render public class RenderBuilding : RenderSimple, INotifyDamageStateChanged, INotifyBuildComplete { RenderBuildingInfo info; - bool buildComplete; - bool skipMakeAnimation; public RenderBuilding(ActorInitializer init, RenderBuildingInfo info) : this(init, info, () => 0) { } @@ -47,26 +45,12 @@ namespace OpenRA.Mods.RA.Render { var self = init.self; this.info = info; - skipMakeAnimation = init.Contains(); - DefaultAnimation.Initialize(NormalizeSequence(self, "idle")); + DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle")); self.Trait().SetAutodetectedFacings(DefaultAnimation.CurrentSequence.Facings); } - public override void Tick(Actor self) - { - base.Tick(self); - - if (buildComplete) - return; - - buildComplete = true; - if (!self.HasTrait() || skipMakeAnimation) - foreach (var notify in self.TraitsImplementing()) - notify.BuildingComplete(self); - } - public virtual void BuildingComplete(Actor self) { DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle")); diff --git a/OpenRA.Mods.RA/Render/WithMakeAnimation.cs b/OpenRA.Mods.RA/Render/WithMakeAnimation.cs index a9bd04a7ba..d53d1ca9a4 100644 --- a/OpenRA.Mods.RA/Render/WithMakeAnimation.cs +++ b/OpenRA.Mods.RA/Render/WithMakeAnimation.cs @@ -18,7 +18,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA.Render { - public class WithMakeAnimationInfo : ITraitInfo, Requires + public class WithMakeAnimationInfo : ITraitInfo, Requires, Requires { [Desc("Sequence name to use")] public readonly string Sequence = "make"; @@ -26,37 +26,35 @@ namespace OpenRA.Mods.RA.Render public object Create(ActorInitializer init) { return new WithMakeAnimation(init, this); } } - public class WithMakeAnimation : ITick + public class WithMakeAnimation { - WithMakeAnimationInfo info; - RenderBuilding building; - bool buildComplete; + readonly WithMakeAnimationInfo info; + readonly RenderBuilding renderBuilding; public WithMakeAnimation(ActorInitializer init, WithMakeAnimationInfo info) { - building = init.self.Trait(); this.info = info; - buildComplete = init.Contains(); - } + var self = init.self; + renderBuilding = self.Trait(); - public void Tick(Actor self) - { - if (self.IsDead() || buildComplete) - return; - - buildComplete = true; - - building.PlayCustomAnimThen(self, info.Sequence, () => + var building = self.Trait(); + if (!init.Contains()) { - foreach (var notify in self.TraitsImplementing()) - notify.BuildingComplete(self); - }); + renderBuilding.PlayCustomAnimThen(self, info.Sequence, () => + { + building.NotifyBuildingComplete(self); + }); + } + else + building.NotifyBuildingComplete(self); } public void Reverse(Actor self, Activity activity) { - building.PlayCustomAnimBackwards(self, info.Sequence, () => { - building.PlayCustomAnim(self, info.Sequence); // avoids visual glitches as we wait for the actor to get destroyed + renderBuilding.PlayCustomAnimBackwards(self, info.Sequence, () => + { + // avoids visual glitches as we wait for the actor to get destroyed + renderBuilding.DefaultAnimation.PlayFetchIndex(info.Sequence, () => 0); self.QueueActivity(activity); }); }