diff --git a/OpenRa.Game/Effects/RepairIndicator.cs b/OpenRa.Game/Effects/RepairIndicator.cs new file mode 100644 index 0000000000..bbc94dd799 --- /dev/null +++ b/OpenRa.Game/Effects/RepairIndicator.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; +using OpenRa.Game.Graphics; +using OpenRa.Game.Traits; + +namespace OpenRa.Game.Effects +{ + class RepairIndicator : IEffect + { + int framesLeft = (int)(Rules.General.RepairRate * 25 * 60 / 2); + Actor a; + Animation anim = new Animation("select"); + + public RepairIndicator(Actor a) { this.a = a; anim.PlayRepeating("repair"); } + + public void Tick() + { + if (--framesLeft == 0 || a.IsDead) + Game.world.AddFrameEndTask(w => w.Remove(this)); + } + + public IEnumerable Render() + { + yield return new Renderable(anim.Image, + a.CenterLocation - .5f * anim.Image.size, PaletteType.Chrome); + } + } +} diff --git a/OpenRa.Game/Graphics/WorldRenderer.cs b/OpenRa.Game/Graphics/WorldRenderer.cs index 9df8b1ea24..14bbff4afe 100644 --- a/OpenRa.Game/Graphics/WorldRenderer.cs +++ b/OpenRa.Game/Graphics/WorldRenderer.cs @@ -82,18 +82,7 @@ namespace OpenRa.Game.Graphics spriteRenderer.Flush(); - DrawBandBox(); - - - foreach(var a in Game.world.Actors.Where(b => b.Owner == Game.LocalPlayer && b.traits.Contains() && b.traits.Get().IsRepairing())) - { - var bounds = a.GetBounds(true); - - var repairImages = new Animation("select"); - repairImages.PlayRepeating("repair"); - spriteRenderer.DrawSprite(repairImages.Image, new float2(.5f * (bounds.Left + bounds.Right)-12, .5f * (bounds.Top + bounds.Bottom)-11), PaletteType.Chrome); - } - + DrawBandBox(); if (Game.controller.orderGenerator != null) Game.controller.orderGenerator.Render(); diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index 53863fbbc8..c34482273f 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -83,6 +83,7 @@ + diff --git a/OpenRa.Game/Traits/Building.cs b/OpenRa.Game/Traits/Building.cs index 2b2d95a571..5beea8d05f 100644 --- a/OpenRa.Game/Traits/Building.cs +++ b/OpenRa.Game/Traits/Building.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using OpenRa.Game.Effects; namespace OpenRa.Game.Traits { @@ -43,10 +44,6 @@ namespace OpenRa.Game.Traits isRepairing = !isRepairing; } } - - public bool IsRepairing(){ - return isRepairing; - } int remainingTicks; @@ -62,8 +59,10 @@ namespace OpenRa.Game.Traits if (!self.Owner.TakeCash(cost)) { remainingTicks = 1; + return; } + Game.world.AddFrameEndTask(w => w.Add(new RepairIndicator(self))); self.InflictDamage(self, -hpToRepair, Rules.WarheadInfo["Super"]); if (self.Health == self.Info.Strength) {