diff --git a/OpenRA.Mods.Common/Traits/Render/SelectionDecorations.cs b/OpenRA.Mods.Common/Traits/Render/SelectionDecorations.cs index 443d58a400..95ae0da122 100644 --- a/OpenRA.Mods.Common/Traits/Render/SelectionDecorations.cs +++ b/OpenRA.Mods.Common/Traits/Render/SelectionDecorations.cs @@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Traits.Render public int[] SelectionBoxBounds { get { return VisualBounds; } } } - public class SelectionDecorations : IRenderAboveShroud, ITick + public class SelectionDecorations : IRenderAboveShroud, INotifyCreated, ITick { // depends on the order of pips in TraitsInterfaces.cs! static readonly string[] PipStrings = { "pip-empty", "pip-green", "pip-yellow", "pip-red", "pip-gray", "pip-blue", "pip-ammo", "pip-ammoempty" }; @@ -49,6 +49,7 @@ namespace OpenRA.Mods.Common.Traits.Render public readonly SelectionDecorationsInfo Info; readonly Animation pipImages; + IPips[] pipSources; public SelectionDecorations(Actor self, SelectionDecorationsInfo info) { @@ -57,6 +58,11 @@ namespace OpenRA.Mods.Common.Traits.Render pipImages = new Animation(self.World, Info.Image); } + void INotifyCreated.Created(Actor self) + { + pipSources = self.TraitsImplementing().ToArray(); + } + IEnumerable ActivityTargetPath(Actor self) { if (!self.IsInWorld || self.IsDead) @@ -76,8 +82,13 @@ namespace OpenRA.Mods.Common.Traits.Render IEnumerable IRenderAboveShroud.RenderAboveShroud(Actor self, WorldRenderer wr) { if (self.World.FogObscures(self)) - yield break; + return Enumerable.Empty(); + return DrawDecorations(self, wr); + } + + IEnumerable DrawDecorations(Actor self, WorldRenderer wr) + { var selected = self.World.Selection.Contains(self); var regularWorld = self.World.Type == WorldType.Regular; var statusBars = Game.Settings.Game.StatusBars; @@ -108,21 +119,25 @@ namespace OpenRA.Mods.Common.Traits.Render if (self.World.LocalPlayer != null && self.World.LocalPlayer.PlayerActor.Trait().PathDebug) yield return new TargetLineRenderable(ActivityTargetPath(self), Color.Green); + foreach (var r in DrawPips(self, wr)) + yield return r; + } + + IEnumerable DrawPips(Actor self, WorldRenderer wr) + { + if (pipSources.Length == 0) + return Enumerable.Empty(); + var b = self.VisualBounds; var pos = wr.ScreenPxPosition(self.CenterPosition); var bl = wr.Viewport.WorldToViewPx(pos + new int2(b.Left, b.Bottom)); var pal = wr.Palette(Info.Palette); - foreach (var r in DrawPips(self, wr, bl, pal)) - yield return r; + return DrawPips(self, bl, pal); } - IEnumerable DrawPips(Actor self, WorldRenderer wr, int2 basePosition, PaletteReference palette) + IEnumerable DrawPips(Actor self, int2 basePosition, PaletteReference palette) { - var pipSources = self.TraitsImplementing(); - if (!pipSources.Any()) - yield break; - pipImages.PlayRepeating(PipStrings[0]); var pipSize = pipImages.Image.Size.XY.ToInt2();