Introduce RangeCircleRenderable.

This commit is contained in:
Paul Chote
2014-07-22 17:06:28 +12:00
parent 48bbac5c6f
commit c4bcf0af46
9 changed files with 91 additions and 27 deletions

View File

@@ -199,17 +199,6 @@ namespace OpenRA.Graphics
}
}
public void DrawRangeCircleWithContrast(WPos pos, WRange range, Color fg, Color bg)
{
var wlr = Game.Renderer.WorldLineRenderer;
var oldWidth = wlr.LineWidth;
wlr.LineWidth = 3;
DrawRangeCircle(pos, range, bg);
wlr.LineWidth = 1;
DrawRangeCircle(pos, range, fg);
wlr.LineWidth = oldWidth;
}
public void DrawTargetMarker(Color c, float2 location)
{
var tl = new float2(-1 / Viewport.Zoom, -1 / Viewport.Zoom);

View File

@@ -10,6 +10,7 @@
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.Mods.RA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Buildings
@@ -68,12 +69,13 @@ namespace OpenRA.Mods.RA.Buildings
if (!ValidRenderPlayer())
return;
wr.DrawRangeCircleWithContrast(
new RangeCircleRenderable(
self.CenterPosition,
WRange.FromCells(Info.Range),
0,
Color.FromArgb(128, Ready() ? Color.White : Color.Red),
Color.FromArgb(96, Color.Black)
);
).Render(wr);
}
// Selection bar

View File

@@ -0,0 +1,59 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Drawing;
using OpenRA.Graphics;
namespace OpenRA.Mods.RA.Graphics
{
public struct RangeCircleRenderable : IRenderable
{
readonly WPos centerPosition;
readonly WRange radius;
readonly int zOffset;
readonly Color color;
readonly Color contrastColor;
public RangeCircleRenderable(WPos centerPosition, WRange radius, int zOffset, Color color, Color contrastColor)
{
this.centerPosition = centerPosition;
this.radius = radius;
this.zOffset = zOffset;
this.color = color;
this.contrastColor = contrastColor;
}
public WPos Pos { get { return centerPosition; } }
public float Scale { get { return 1f; } }
public PaletteReference Palette { get { return null; } }
public int ZOffset { get { return zOffset; } }
public bool IsDecoration { get { return true; } }
public IRenderable WithScale(float newScale) { return new RangeCircleRenderable(centerPosition, radius, zOffset, color, contrastColor); }
public IRenderable WithPalette(PaletteReference newPalette) { return new RangeCircleRenderable(centerPosition, radius, zOffset, color, contrastColor); }
public IRenderable WithZOffset(int newOffset) { return new RangeCircleRenderable(centerPosition, radius, newOffset, color, contrastColor); }
public IRenderable OffsetBy(WVec vec) { return new RangeCircleRenderable(centerPosition + vec, radius, zOffset, color, contrastColor); }
public IRenderable AsDecoration() { return this; }
public void BeforeRender(WorldRenderer wr) {}
public void Render(WorldRenderer wr)
{
var wlr = Game.Renderer.WorldLineRenderer;
var oldWidth = wlr.LineWidth;
wlr.LineWidth = 3;
wr.DrawRangeCircle(centerPosition, radius, contrastColor);
wlr.LineWidth = 1;
wr.DrawRangeCircle(centerPosition, radius, color);
wlr.LineWidth = oldWidth;
}
public void RenderDebugGeometry(WorldRenderer wr) {}
}
}

View File

@@ -530,6 +530,7 @@
<Compile Include="Air\FlyAwayOnIdle.cs" />
<Compile Include="Buildings\ClonesProducedUnits.cs" />
<Compile Include="Cloneable.cs" />
<Compile Include="Graphics\RangeCircleRenderable.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">

View File

@@ -12,6 +12,7 @@ using System.Collections.Generic;
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Graphics;
using OpenRA.Mods.RA.Orders;
using OpenRA.Traits;
@@ -180,12 +181,13 @@ namespace OpenRA.Mods.RA
if (!self.Trait<PortableChrono>().Info.HasDistanceLimit)
return;
wr.DrawRangeCircleWithContrast(
new RangeCircleRenderable(
self.CenterPosition,
WRange.FromCells(self.Trait<PortableChrono>().Info.MaxDistance),
0,
Color.FromArgb(128, Color.LawnGreen),
Color.FromArgb(96, Color.Black)
);
).Render(wr);
}
public string GetCursor(World world, CPos xy, MouseInput mi)

View File

@@ -10,6 +10,7 @@
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.Mods.RA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
@@ -30,11 +31,13 @@ namespace OpenRA.Mods.RA
if (self.Owner != self.World.LocalPlayer)
return;
wr.DrawRangeCircleWithContrast(
new RangeCircleRenderable(
self.CenterPosition,
WRange.FromCells(self.Info.Traits.Get<DetectCloakedInfo>().Range),
0,
Color.FromArgb(128, Color.LimeGreen),
Color.FromArgb(96, Color.Black));
Color.FromArgb(96, Color.Black)
).Render(wr);
}
}
}

View File

@@ -10,6 +10,7 @@
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.Mods.RA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
@@ -57,12 +58,13 @@ namespace OpenRA.Mods.RA
public static void DrawRangeCircle(WorldRenderer wr, WPos pos, int range, Color color)
{
wr.DrawRangeCircleWithContrast(
new RangeCircleRenderable(
pos,
WRange.FromCells(range),
0,
Color.FromArgb(128, color),
Color.FromArgb(96, Color.Black)
);
).Render(wr);
}
}
}

View File

@@ -11,6 +11,7 @@
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.RA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
@@ -39,12 +40,13 @@ namespace OpenRA.Mods.RA
if (range == WRange.Zero)
return;
wr.DrawRangeCircleWithContrast(
new RangeCircleRenderable(
centerPosition,
range,
0,
Color.FromArgb(128, Color.Yellow),
Color.FromArgb(96, Color.Black)
);
).Render(wr);
foreach (var a in w.ActorsWithTrait<RenderRangeCircle>())
if (a.Actor.Owner == a.Actor.World.LocalPlayer)
@@ -71,12 +73,13 @@ namespace OpenRA.Mods.RA
if (self.Owner != self.World.LocalPlayer)
return;
wr.DrawRangeCircleWithContrast(
new RangeCircleRenderable(
self.CenterPosition,
attack.GetMaximumRange(),
0,
Color.FromArgb(128, Color.Yellow),
Color.FromArgb(96, Color.Black)
);
).Render(wr);
}
}
}

View File

@@ -10,6 +10,7 @@
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.Mods.RA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
@@ -18,12 +19,13 @@ namespace OpenRA.Mods.RA
{
public void Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition)
{
wr.DrawRangeCircleWithContrast(
new RangeCircleRenderable(
centerPosition,
ai.Traits.Get<CreatesShroudInfo>().Range,
0,
Color.FromArgb(128, Color.Cyan),
Color.FromArgb(96, Color.Black)
);
).Render(wr);
foreach (var a in w.ActorsWithTrait<RenderShroudCircle>())
if (a.Actor.Owner == a.Actor.World.LocalPlayer)
@@ -44,12 +46,13 @@ namespace OpenRA.Mods.RA
if (self.Owner != self.World.LocalPlayer)
return;
wr.DrawRangeCircleWithContrast(
new RangeCircleRenderable(
self.CenterPosition,
self.Info.Traits.Get<CreatesShroudInfo>().Range,
0,
Color.FromArgb(128, Color.Cyan),
Color.FromArgb(96, Color.Black)
);
).Render(wr);
}
}
}