Introduce IDecorationBounds to replace Actor.SelectionOverlayBounds.
This commit is contained in:
@@ -21,19 +21,21 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
readonly Actor actor;
|
||||
readonly bool displayHealth;
|
||||
readonly bool displayExtra;
|
||||
readonly Rectangle decorationBounds;
|
||||
|
||||
public SelectionBarsRenderable(Actor actor, bool displayHealth, bool displayExtra)
|
||||
: this(actor.CenterPosition, actor)
|
||||
public SelectionBarsRenderable(Actor actor, Rectangle decorationBounds, bool displayHealth, bool displayExtra)
|
||||
: this(actor.CenterPosition, actor, decorationBounds)
|
||||
{
|
||||
this.displayHealth = displayHealth;
|
||||
this.displayExtra = displayExtra;
|
||||
}
|
||||
|
||||
public SelectionBarsRenderable(WPos pos, Actor actor)
|
||||
public SelectionBarsRenderable(WPos pos, Actor actor, Rectangle decorationBounds)
|
||||
: this()
|
||||
{
|
||||
this.pos = pos;
|
||||
this.actor = actor;
|
||||
this.decorationBounds = decorationBounds;
|
||||
}
|
||||
|
||||
public WPos Pos { get { return pos; } }
|
||||
@@ -46,7 +48,7 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
|
||||
public IRenderable WithPalette(PaletteReference newPalette) { return this; }
|
||||
public IRenderable WithZOffset(int newOffset) { return this; }
|
||||
public IRenderable OffsetBy(WVec vec) { return new SelectionBarsRenderable(pos + vec, actor); }
|
||||
public IRenderable OffsetBy(WVec vec) { return new SelectionBarsRenderable(pos + vec, actor, decorationBounds); }
|
||||
public IRenderable AsDecoration() { return this; }
|
||||
|
||||
void DrawExtraBars(WorldRenderer wr, float3 start, float3 end)
|
||||
@@ -150,11 +152,8 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
var health = actor.TraitOrDefault<IHealth>();
|
||||
|
||||
var screenPos = wr.Screen3DPxPosition(pos);
|
||||
var bounds = actor.SelectionOverlayBounds;
|
||||
bounds.Offset((int)screenPos.X, (int)screenPos.Y);
|
||||
|
||||
var start = new float3(bounds.Left + 1, bounds.Top, screenPos.Z);
|
||||
var end = new float3(bounds.Right - 1, bounds.Top, screenPos.Z);
|
||||
var start = new float3(decorationBounds.Left + 1, decorationBounds.Top, screenPos.Z);
|
||||
var end = new float3(decorationBounds.Right - 1, decorationBounds.Top, screenPos.Z);
|
||||
|
||||
if (DisplayHealth)
|
||||
DrawHealthBar(wr, health, start, end);
|
||||
|
||||
@@ -17,16 +17,16 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
public struct SelectionBoxRenderable : IRenderable, IFinalizedRenderable
|
||||
{
|
||||
readonly WPos pos;
|
||||
readonly Rectangle visualBounds;
|
||||
readonly Rectangle decorationBounds;
|
||||
readonly Color color;
|
||||
|
||||
public SelectionBoxRenderable(Actor actor, Color color)
|
||||
: this(actor.CenterPosition, actor.SelectionOverlayBounds, color) { }
|
||||
public SelectionBoxRenderable(Actor actor, Rectangle decorationBounds, Color color)
|
||||
: this(actor.CenterPosition, decorationBounds, color) { }
|
||||
|
||||
public SelectionBoxRenderable(WPos pos, Rectangle visualBounds, Color color)
|
||||
public SelectionBoxRenderable(WPos pos, Rectangle decorationBounds, Color color)
|
||||
{
|
||||
this.pos = pos;
|
||||
this.visualBounds = visualBounds;
|
||||
this.decorationBounds = decorationBounds;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@@ -38,18 +38,18 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
|
||||
public IRenderable WithPalette(PaletteReference newPalette) { return this; }
|
||||
public IRenderable WithZOffset(int newOffset) { return this; }
|
||||
public IRenderable OffsetBy(WVec vec) { return new SelectionBoxRenderable(pos + vec, visualBounds, color); }
|
||||
public IRenderable OffsetBy(WVec vec) { return new SelectionBoxRenderable(pos + vec, decorationBounds, color); }
|
||||
public IRenderable AsDecoration() { return this; }
|
||||
|
||||
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }
|
||||
public void Render(WorldRenderer wr)
|
||||
{
|
||||
var iz = 1 / wr.Viewport.Zoom;
|
||||
var screenPos = wr.Screen3DPxPosition(pos);
|
||||
var tl = screenPos + new float2(visualBounds.Left, visualBounds.Top);
|
||||
var br = screenPos + new float2(visualBounds.Right, visualBounds.Bottom);
|
||||
var tr = new float3(br.X, tl.Y, screenPos.Z);
|
||||
var bl = new float3(tl.X, br.Y, screenPos.Z);
|
||||
var screenDepth = wr.Screen3DPxPosition(pos).Z;
|
||||
var tl = new float2(decorationBounds.Left, decorationBounds.Top);
|
||||
var br = new float2(decorationBounds.Right, decorationBounds.Bottom);
|
||||
var tr = new float3(br.X, tl.Y, screenDepth);
|
||||
var bl = new float3(tl.X, br.Y, screenDepth);
|
||||
var u = new float2(4 * iz, 0);
|
||||
var v = new float2(0, 4 * iz);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user