diff --git a/OpenRa.Game/Graphics/Animation.cs b/OpenRa.Game/Graphics/Animation.cs index b7fd3d913c..00fa963dc2 100644 --- a/OpenRa.Game/Graphics/Animation.cs +++ b/OpenRa.Game/Graphics/Animation.cs @@ -7,6 +7,7 @@ namespace OpenRa.Game.Graphics readonly string name; Sequence currentSequence; int frame = 0; + bool backwards = false; bool tickAlways; public Animation( string name ) @@ -15,7 +16,16 @@ namespace OpenRa.Game.Graphics Play( "idle" ); } - public Sprite Image { get { return currentSequence.GetSprite( frame ); } } + public Sprite Image + { + get + { + return backwards + ? currentSequence.GetSprite(currentSequence.End - frame - 1) + : currentSequence.GetSprite(frame); + } + } + public float2 Center { get { return 0.25f * new float2(currentSequence.GetSprite(0).bounds.Size); } } public void Play( string sequenceName ) @@ -23,6 +33,11 @@ namespace OpenRa.Game.Graphics PlayThen(sequenceName, () => { }); } + public void PlayBackwards(string sequenceName) + { + PlayBackwardsThen(sequenceName, () => { }); + } + public void PlayRepeating( string sequenceName ) { PlayThen( sequenceName, () => PlayRepeating( sequenceName ) ); @@ -30,6 +45,7 @@ namespace OpenRa.Game.Graphics public void PlayThen( string sequenceName, Action after ) { + backwards = false; tickAlways = false; currentSequence = SequenceProvider.GetSequence( name, sequenceName ); frame = 0; @@ -45,8 +61,15 @@ namespace OpenRa.Game.Graphics }; } + public void PlayBackwardsThen(string sequenceName, Action after) + { + PlayThen(sequenceName, after); + backwards = true; + } + public void PlayFetchIndex( string sequenceName, Func func ) { + backwards = false; tickAlways = true; currentSequence = SequenceProvider.GetSequence( name, sequenceName ); frame = func(); diff --git a/OpenRa.Game/Traits/RenderBuildingWarFactory.cs b/OpenRa.Game/Traits/RenderBuildingWarFactory.cs index ec56359911..c4b13a8a3f 100644 --- a/OpenRa.Game/Traits/RenderBuildingWarFactory.cs +++ b/OpenRa.Game/Traits/RenderBuildingWarFactory.cs @@ -11,6 +11,7 @@ namespace OpenRa.Game.Traits { public Animation roof; bool doneBuilding; + bool isOpen; public readonly Actor self; public RenderWarFactory(Actor self) @@ -37,14 +38,22 @@ namespace OpenRa.Game.Traits { base.Tick(self); roof.Tick(); + + var b = self.Bounds; + if (isOpen && !Game.SelectUnitsInBox( + new float2(b.Left, b.Top), + new float2(b.Right, b.Bottom)).Any(a => a.traits.Contains())) + { + isOpen = false; + roof.PlayBackwardsThen("build-top", () => roof.Play("idle-top")); + } } public void EjectUnit() { /* todo: hold the door open */ - roof.PlayThen("build-top", - () => roof.PlayRepeating("idle-top")); + roof.PlayThen("build-top", () => isOpen = true); } } }