From ee1fb0f1e0f91c04701e1b23663c87ebc8c20085 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 24 Nov 2015 22:44:54 +0000 Subject: [PATCH] Add SelectionDecoration flag to WithDecoration. --- .../Traits/Render/WithDecoration.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Render/WithDecoration.cs b/OpenRA.Mods.Common/Traits/Render/WithDecoration.cs index 799508f887..23b41d285a 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithDecoration.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithDecoration.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using OpenRA.Graphics; using OpenRA.Traits; @@ -59,19 +60,24 @@ namespace OpenRA.Mods.Common.Traits [Desc("Should this be visible to enemy players?")] public readonly bool ShowToEnemies = false; + [Desc("Should this be visible only when selected?")] + public readonly bool SelectionDecoration = false; + public override object Create(ActorInitializer init) { return new WithDecoration(init.Self, this); } } - public class WithDecoration : UpgradableTrait, IRender + public class WithDecoration : UpgradableTrait, IRender, IPostRenderSelection { readonly WithDecorationInfo info; readonly string image; readonly Animation anim; + readonly Actor self; public WithDecoration(Actor self, WithDecorationInfo info) : base(info) { this.info = info; + this.self = self; image = info.Image ?? self.Info.Name; anim = new Animation(self.World, image); anim.Paused = () => self.World.Paused; @@ -86,6 +92,16 @@ namespace OpenRA.Mods.Common.Traits public virtual bool ShouldRender(Actor self) { return true; } public IEnumerable Render(Actor self, WorldRenderer wr) + { + return !info.SelectionDecoration ? RenderInner(self, wr, self.Bounds) : Enumerable.Empty(); + } + + public IEnumerable RenderAfterWorld(WorldRenderer wr) + { + return info.SelectionDecoration ? RenderInner(self, wr, self.VisualBounds) : Enumerable.Empty(); + } + + IEnumerable RenderInner(Actor self, WorldRenderer wr, Rectangle actorBounds) { if (IsTraitDisabled) return Enumerable.Empty(); @@ -111,7 +127,6 @@ namespace OpenRA.Mods.Common.Traits return Enumerable.Empty(); var pxPos = wr.ScreenPxPosition(self.CenterPosition); - var actorBounds = self.Bounds; actorBounds.Offset(pxPos.X, pxPos.Y); var img = anim.Image;