diff --git a/OpenRA.Mods.Common/Traits/Render/SelectionDecorations.cs b/OpenRA.Mods.Common/Traits/Render/SelectionDecorations.cs index a291aa224a..9524e8cc33 100644 --- a/OpenRA.Mods.Common/Traits/Render/SelectionDecorations.cs +++ b/OpenRA.Mods.Common/Traits/Render/SelectionDecorations.cs @@ -34,23 +34,32 @@ namespace OpenRA.Mods.Common.Traits.Render public readonly Color SelectionBoxColor = Color.White; + public readonly string Image = "pips"; + + [Desc("Sprite sequence used to render the control group 0-9 numbers.")] + [SequenceReference("Image")] public readonly string GroupSequence = "groups"; + public object Create(ActorInitializer init) { return new SelectionDecorations(init.Self, this); } public int[] SelectionBoxBounds { get { return VisualBounds; } } } - public class SelectionDecorations : IPostRenderSelection + public class SelectionDecorations : IPostRenderSelection, 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" }; public readonly SelectionDecorationsInfo Info; + readonly Actor self; + readonly Animation pipImages; public SelectionDecorations(Actor self, SelectionDecorationsInfo info) { this.self = self; Info = info; + + pipImages = new Animation(self.World, Info.Image); } IEnumerable ActivityTargetPath() @@ -90,42 +99,38 @@ namespace OpenRA.Mods.Common.Traits.Render var pos = wr.ScreenPxPosition(self.CenterPosition); var tl = wr.Viewport.WorldToViewPx(pos + new int2(b.Left, b.Top)); var bl = wr.Viewport.WorldToViewPx(pos + new int2(b.Left, b.Bottom)); + var pal = wr.Palette(Info.Palette); - foreach (var r in DrawControlGroup(wr, self, tl)) + foreach (var r in DrawControlGroup(wr, self, tl, pal)) yield return r; - foreach (var r in DrawPips(wr, self, bl)) + foreach (var r in DrawPips(wr, self, bl, pal)) yield return r; } - IEnumerable DrawControlGroup(WorldRenderer wr, Actor self, int2 basePosition) + IEnumerable DrawControlGroup(WorldRenderer wr, Actor self, int2 basePosition, PaletteReference palette) { var group = self.World.Selection.GetControlGroupForActor(self); if (group == null) yield break; - var pipImages = new Animation(self.World, "pips"); - var pal = wr.Palette(Info.Palette); - pipImages.PlayFetchIndex("groups", () => (int)group); - pipImages.Tick(); + pipImages.PlayFetchIndex(Info.GroupSequence, () => (int)group); var pos = basePosition - (0.5f * pipImages.Image.Size.XY).ToInt2() + new int2(9, 5); - yield return new UISpriteRenderable(pipImages.Image, self.CenterPosition, pos, 0, pal, 1f); + yield return new UISpriteRenderable(pipImages.Image, self.CenterPosition, pos, 0, palette, 1f); } - IEnumerable DrawPips(WorldRenderer wr, Actor self, int2 basePosition) + IEnumerable DrawPips(WorldRenderer wr, Actor self, int2 basePosition, PaletteReference palette) { var pipSources = self.TraitsImplementing(); if (!pipSources.Any()) yield break; - var pipImages = new Animation(self.World, "pips"); pipImages.PlayRepeating(PipStrings[0]); var pipSize = pipImages.Image.Size.XY.ToInt2(); var pipxyBase = basePosition + new int2(1 - pipSize.X / 2, -(3 + pipSize.Y / 2)); var pipxyOffset = new int2(0, 0); - var pal = wr.Palette(Info.Palette); var width = self.VisualBounds.Width; foreach (var pips in pipSources) @@ -142,12 +147,17 @@ namespace OpenRA.Mods.Common.Traits.Render pipImages.PlayRepeating(PipStrings[(int)pip]); pipxyOffset += new int2(pipSize.X, 0); - yield return new UISpriteRenderable(pipImages.Image, self.CenterPosition, pipxyBase + pipxyOffset, 0, pal, 1f); + yield return new UISpriteRenderable(pipImages.Image, self.CenterPosition, pipxyBase + pipxyOffset, 0, palette, 1f); } // Increment row pipxyOffset = new int2(0, pipxyOffset.Y - (pipSize.Y + 1)); } } + + void ITick.Tick(Actor self) + { + pipImages.Tick(); + } } }