diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index 77fa4f53e0..cfd4760341 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -191,14 +191,16 @@ namespace OpenRa.Game if (producer == null) throw new InvalidOperationException("BuildUnit without suitable production structure!"); - var unit = new Actor(name, (1/24f * producer.CenterLocation).ToInt2(), player); - var mobile = unit.traits.Get(); - mobile.facing = 128; + var unit = new Actor(name, (1/24f * producer.CenterLocation).ToInt2(), player); + var mobile = unit.traits.Get(); + mobile.facing = 128; mobile.QueueAction( new Traits.Mobile.MoveTo( unit.Location + new int2( 0, 3 ) ) ); world.AddFrameEndTask(_ => world.Add(unit)); // todo: make the producing building play `build` + if (producer.traits.Contains()) + producer.traits.Get().EjectUnit(); } } } 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/Graphics/WorldRenderer.cs b/OpenRa.Game/Graphics/WorldRenderer.cs index 0bc924cc22..abbc26f950 100644 --- a/OpenRa.Game/Graphics/WorldRenderer.cs +++ b/OpenRa.Game/Graphics/WorldRenderer.cs @@ -44,8 +44,8 @@ namespace OpenRa.Game.Graphics spriteRenderer.DrawSprite(image.First, loc, (owner != null) ? owner.Palette : 0); } - } - + } + public void Draw() { var rect = new RectangleF((region.Position + Game.viewport.Location).ToPointF(), @@ -54,6 +54,11 @@ namespace OpenRa.Game.Graphics foreach (Actor a in Game.world.Actors.OrderBy( u => u.CenterLocation.Y )) DrawSpriteList(a.Owner, rect, a.Render()); + foreach (var a in Game.world.Actors + .Where(u => u.traits.Contains()) + .Select(u => u.traits.Get())) + DrawSpriteList(a.self.Owner, rect, a.RenderRoof(a.self)); /* RUDE HACK */ + foreach (IEffect e in Game.world.Effects) DrawSpriteList(e.Owner, rect, e.Render()); diff --git a/OpenRa.Game/Traits/RenderBuildingWarFactory.cs b/OpenRa.Game/Traits/RenderBuildingWarFactory.cs index e68a2ddc17..c4b13a8a3f 100644 --- a/OpenRa.Game/Traits/RenderBuildingWarFactory.cs +++ b/OpenRa.Game/Traits/RenderBuildingWarFactory.cs @@ -11,10 +11,14 @@ namespace OpenRa.Game.Traits { public Animation roof; bool doneBuilding; + bool isOpen; + public readonly Actor self; public RenderWarFactory(Actor self) : base(self) { + this.self = self; + roof = new Animation(self.unitInfo.Image ?? self.unitInfo.Name); anim.PlayThen("make", () => { @@ -24,19 +28,32 @@ namespace OpenRa.Game.Traits }); } - public override IEnumerable> Render(Actor self) + public IEnumerable> RenderRoof(Actor self) { if (doneBuilding) - return base.Render(self).Concat( - new[] { Pair.New(roof.Image, 24f * (float2)self.Location) }); - else - return base.Render(self); + yield return Pair.New(roof.Image, 24f * (float2)self.Location); } public override void Tick(Actor self) { 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", () => isOpen = true); } } }