Move debug target path rendering to SelectionDecorations
This commit is contained in:
@@ -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<WPos> 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<IRenderable> RenderAfterWorld(WorldRenderer wr)
|
||||
{
|
||||
if (self.World.LocalPlayer != null && self.World.LocalPlayer.PlayerActor.Trait<DeveloperMode>().PathDebug)
|
||||
yield return new TargetLineRenderable(ActivityTargetPath(), Color.Green);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<WPos> 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<IRenderable> 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<DeveloperMode>().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));
|
||||
|
||||
Reference in New Issue
Block a user