diff --git a/OpenRa.Game/Graphics/Animation.cs b/OpenRa.Game/Graphics/Animation.cs index f7c29362ac..34542f3f78 100644 --- a/OpenRa.Game/Graphics/Animation.cs +++ b/OpenRa.Game/Graphics/Animation.cs @@ -46,6 +46,7 @@ namespace OpenRa.Graphics public void PlayThen( string sequenceName, Action after ) { + after = after ?? ( () => { } ); backwards = false; tickAlways = false; CurrentSequence = SequenceProvider.GetSequence( name, sequenceName ); @@ -112,5 +113,10 @@ namespace OpenRa.Graphics ReplaceAnim(CurrentSequence.Name); } } + + public Sequence GetSequence( string sequenceName ) + { + return SequenceProvider.GetSequence( name, sequenceName ); + } } } diff --git a/OpenRa.Game/Traits/Activities/Sell.cs b/OpenRa.Game/Traits/Activities/Sell.cs index c418b5a385..917678ed36 100644 --- a/OpenRa.Game/Traits/Activities/Sell.cs +++ b/OpenRa.Game/Traits/Activities/Sell.cs @@ -11,6 +11,8 @@ namespace OpenRa.Traits.Activities bool started; + int framesRemaining; + void DoSell(Actor self) { var cost = self.Info.Traits.Get().Cost; @@ -21,23 +23,26 @@ namespace OpenRa.Traits.Activities self.Health = 0; foreach (var ns in self.traits.WithInterface()) ns.Sold(self); - Game.world.Remove(self); + Game.world.AddFrameEndTask( _ => Game.world.Remove( self ) ); // todo: give dudes } public IActivity Tick(Actor self) { - if (!started) + if( !started ) { - var rb = self.traits.Get(); - //var rb = self.traits.Get(); - rb.PlayCustomAnimBackwards(self, "make", - () => Game.world.AddFrameEndTask(w => DoSell(self))); + framesRemaining = self.traits.Get().anim.GetSequence( "make" ).Length; + foreach( var ns in self.traits.WithInterface() ) + ns.Selling( self ); - Sound.Play("cashturn.aud"); started = true; } + else if( framesRemaining <= 0 ) + DoSell( self ); + + else + --framesRemaining; return this; } diff --git a/OpenRa.Game/Traits/RenderBuilding.cs b/OpenRa.Game/Traits/RenderBuilding.cs index f795b1d26c..38c2b08f21 100644 --- a/OpenRa.Game/Traits/RenderBuilding.cs +++ b/OpenRa.Game/Traits/RenderBuilding.cs @@ -92,6 +92,12 @@ namespace OpenRa.Traits } } + public void Selling( Actor self ) + { + anim.PlayBackwardsThen( "make", null ); + Sound.Play("cashturn.aud"); + } + public void Sold(Actor self) { DoBib(self, true); } } } diff --git a/OpenRa.Game/Traits/RenderBuildingWarFactory.cs b/OpenRa.Game/Traits/RenderBuildingWarFactory.cs index 8d2a0b62f2..4cabc0f7e9 100644 --- a/OpenRa.Game/Traits/RenderBuildingWarFactory.cs +++ b/OpenRa.Game/Traits/RenderBuildingWarFactory.cs @@ -9,7 +9,7 @@ namespace OpenRa.Traits public object Create(Actor self) { return new RenderWarFactory(self); } } - class RenderWarFactory : INotifyBuildComplete, INotifyDamage, ITick, INotifyProduction + class RenderWarFactory : INotifyBuildComplete, INotifyDamage, ITick, INotifyProduction, INotifySold { public Animation roof; [Sync] @@ -59,5 +59,12 @@ namespace OpenRa.Traits { roof.PlayThen(GetPrefix(self) + "build-top", () => isOpen = true); } + + public void Selling( Actor self ) + { + self.traits.Get().anims.Remove( "roof" ); + } + + public void Sold( Actor self ) { } } } diff --git a/OpenRa.Game/Traits/TraitsInterfaces.cs b/OpenRa.Game/Traits/TraitsInterfaces.cs index 84157ad002..cc7afc4569 100644 --- a/OpenRa.Game/Traits/TraitsInterfaces.cs +++ b/OpenRa.Game/Traits/TraitsInterfaces.cs @@ -17,7 +17,7 @@ namespace OpenRa.Traits public interface IIssueOrder { Order IssueOrder( Actor self, int2 xy, MouseInput mi, Actor underCursor ); } public interface IResolveOrder { void ResolveOrder(Actor self, Order order); } - public interface INotifySold { void Sold(Actor self); } + public interface INotifySold { void Selling( Actor self ); void Sold( Actor self ); } public interface INotifyDamage { void Damaged(Actor self, AttackInfo e); } public interface INotifyBuildComplete { void BuildingComplete(Actor self); } public interface INotifyProduction { void UnitProduced(Actor self, Actor other); }