From 875d8bac06a91f8949c90ac084a3940ca5da0af8 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Mon, 8 Jun 2015 01:08:41 +0200 Subject: [PATCH] Move debug target path rendering to SelectionDecorations --- OpenRA.Game/Traits/Selectable.cs | 31 ++----------------- .../Traits/SelectionDecorations.cs | 21 ++++++++++++- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/OpenRA.Game/Traits/Selectable.cs b/OpenRA.Game/Traits/Selectable.cs index fa9fc9be10..2141452889 100644 --- a/OpenRA.Game/Traits/Selectable.cs +++ b/OpenRA.Game/Traits/Selectable.cs @@ -9,9 +9,7 @@ #endregion using System.Collections.Generic; -using System.Drawing; using System.Linq; -using OpenRA.Graphics; namespace OpenRA.Traits { @@ -19,6 +17,7 @@ namespace OpenRA.Traits public class SelectableInfo : ITraitInfo { public readonly int Priority = 10; + [Desc("Bounds for the selectable area.")] public readonly int[] Bounds = null; @@ -29,40 +28,16 @@ namespace OpenRA.Traits public object Create(ActorInitializer init) { return new Selectable(init.Self, this); } } - public class Selectable : IPostRenderSelection + public class Selectable { public readonly string Class = null; - public SelectableInfo Info; - readonly Actor self; + public readonly SelectableInfo Info; public Selectable(Actor self, SelectableInfo info) { - this.self = self; Info = info; Class = string.IsNullOrEmpty(info.Class) ? self.Info.Name : info.Class; } - - IEnumerable ActivityTargetPath() - { - if (!self.IsInWorld || self.IsDead) - yield break; - - var activity = self.GetCurrentActivity(); - if (activity != null) - { - var targets = activity.GetTargets(self); - yield return self.CenterPosition; - - foreach (var t in targets.Where(t => t.Type != TargetType.Invalid)) - yield return t.CenterPosition; - } - } - - public IEnumerable RenderAfterWorld(WorldRenderer wr) - { - if (self.World.LocalPlayer != null && self.World.LocalPlayer.PlayerActor.Trait().PathDebug) - yield return new TargetLineRenderable(ActivityTargetPath(), Color.Green); - } } } diff --git a/OpenRA.Mods.Common/Traits/SelectionDecorations.cs b/OpenRA.Mods.Common/Traits/SelectionDecorations.cs index 9d6c1531f4..d23153a9e7 100644 --- a/OpenRA.Mods.Common/Traits/SelectionDecorations.cs +++ b/OpenRA.Mods.Common/Traits/SelectionDecorations.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits static readonly string[] PipStrings = { "pip-empty", "pip-green", "pip-yellow", "pip-red", "pip-gray", "pip-blue", "pip-ammo", "pip-ammoempty" }; static readonly string[] TagStrings = { "", "tag-fake", "tag-primary" }; - public SelectionDecorationsInfo Info; + public readonly SelectionDecorationsInfo Info; readonly Actor self; public ISelectionDecorationsInfo SelectionDecorationsInfo { get { return Info; } } @@ -49,6 +49,22 @@ namespace OpenRA.Mods.Common.Traits Info = info; } + IEnumerable ActivityTargetPath() + { + if (!self.IsInWorld || self.IsDead) + yield break; + + var activity = self.GetCurrentActivity(); + if (activity != null) + { + var targets = activity.GetTargets(self); + yield return self.CenterPosition; + + foreach (var t in targets.Where(t => t.Type != TargetType.Invalid)) + yield return t.CenterPosition; + } + } + public IEnumerable RenderAfterWorld(WorldRenderer wr) { if (!self.Owner.IsAlliedWith(self.World.RenderPlayer) || self.World.FogObscures(self)) @@ -60,6 +76,9 @@ namespace OpenRA.Mods.Common.Traits if (Info.RenderSelectionBars) yield return new SelectionBarsRenderable(self); + if (self.World.LocalPlayer != null && self.World.LocalPlayer.PlayerActor.Trait().PathDebug) + yield return new TargetLineRenderable(ActivityTargetPath(), Color.Green); + var b = self.VisualBounds; var pos = wr.ScreenPxPosition(self.CenterPosition); var tl = wr.Viewport.WorldToViewPx(pos + new int2(b.Left, b.Top));