Extract DrawTargetMarker to WorldRenderer.

This commit is contained in:
Paul Chote
2013-10-14 23:31:17 +13:00
parent 839419635d
commit 483120ea20
4 changed files with 26 additions and 32 deletions

View File

@@ -200,6 +200,20 @@ namespace OpenRA.Graphics
wlr.LineWidth = oldWidth; wlr.LineWidth = oldWidth;
} }
public void DrawTargetMarker(Color c, float2 location)
{
var tl = new float2(-1, -1);
var br = new float2(1, 1);
var bl = new float2(tl.X, br.Y);
var tr = new float2(br.X, tl.Y);
var wlr = Game.Renderer.WorldLineRenderer;
wlr.DrawLine(location + tl, location + tr, c, c);
wlr.DrawLine(location + tr, location + br, c, c);
wlr.DrawLine(location + br, location + bl, c, c);
wlr.DrawLine(location + bl, location + tl, c, c);
}
public void RefreshPalette() public void RefreshPalette()
{ {
palette.ApplyModifiers(world.WorldActor.TraitsImplementing<IPaletteModifier>()); palette.ApplyModifiers(world.WorldActor.TraitsImplementing<IPaletteModifier>());

View File

@@ -60,27 +60,17 @@ namespace OpenRA.Traits
return; return;
var from = wr.ScreenPxPosition(self.CenterPosition); var from = wr.ScreenPxPosition(self.CenterPosition);
var wlr = Game.Renderer.WorldLineRenderer;
foreach (var target in targets) foreach (var target in targets)
{ {
if (target.Type == TargetType.Invalid) if (target.Type == TargetType.Invalid)
continue; continue;
var to = wr.ScreenPxPosition(target.CenterPosition); var to = wr.ScreenPxPosition(target.CenterPosition);
wlr.DrawLine(from, to, c, c); Game.Renderer.WorldLineRenderer.DrawLine(from, to, c, c);
DrawTargetMarker(wlr, from); wr.DrawTargetMarker(c, from);
DrawTargetMarker(wlr, to); wr.DrawTargetMarker(c, to);
} }
} }
void DrawTargetMarker(LineRenderer wlr, float2 p)
{
wlr.DrawLine(p + new float2(-1, -1), p + new float2(-1, 1), c, c);
wlr.DrawLine(p + new float2(-1, 1), p + new float2(1, 1), c, c);
wlr.DrawLine(p + new float2(1, 1), p + new float2(1, -1), c, c);
wlr.DrawLine(p + new float2(1, -1), p + new float2(-1, -1), c, c);
}
} }
public static class LineTargetExts public static class LineTargetExts
@@ -89,12 +79,7 @@ namespace OpenRA.Traits
{ {
var line = self.TraitOrDefault<DrawLineToTarget>(); var line = self.TraitOrDefault<DrawLineToTarget>();
if (line != null) if (line != null)
{ self.World.AddFrameEndTask(w => line.SetTargets(self, targets, color, false));
self.World.AddFrameEndTask(w =>
{
line.SetTargets(self, targets, color, false);
});
}
} }
public static void SetTargetLine(this Actor self, Target target, Color color) public static void SetTargetLine(this Actor self, Target target, Color color)

View File

@@ -154,7 +154,8 @@ namespace OpenRA.Traits
void DrawUnitPath(WorldRenderer wr, Actor self) void DrawUnitPath(WorldRenderer wr, Actor self)
{ {
if (self.World.LocalPlayer == null ||!self.World.LocalPlayer.PlayerActor.Trait<DeveloperMode>().PathDebug) return; if (self.World.LocalPlayer == null || !self.World.LocalPlayer.PlayerActor.Trait<DeveloperMode>().PathDebug)
return;
var activity = self.GetCurrentActivity(); var activity = self.GetCurrentActivity();
if (activity != null) if (activity != null)
@@ -163,15 +164,10 @@ namespace OpenRA.Traits
var start = wr.ScreenPxPosition(self.CenterPosition); var start = wr.ScreenPxPosition(self.CenterPosition);
var c = Color.Green; var c = Color.Green;
foreach (var stp in targets.Where(t => t.Type != TargetType.Invalid).Select(pos => wr.ScreenPxPosition(pos.CenterPosition)))
var wlr = Game.Renderer.WorldLineRenderer;
foreach (var stp in targets.Where(t => t.Type != TargetType.Invalid).Select(p => wr.ScreenPxPosition(p.CenterPosition)))
{ {
wlr.DrawLine(stp + new float2(-1, -1), stp + new float2(-1, 1), c, c); Game.Renderer.WorldLineRenderer.DrawLine(start, stp, c, c);
wlr.DrawLine(stp + new float2(-1, 1), stp + new float2(1, 1), c, c); wr.DrawTargetMarker(c, stp);
wlr.DrawLine(stp + new float2(1, 1), stp + new float2(1, -1), c, c);
wlr.DrawLine(stp + new float2(1, -1), stp + new float2(-1, -1), c, c);
wlr.DrawLine(start, stp, c, c);
start = stp; start = stp;
} }
} }

View File

@@ -52,6 +52,7 @@ namespace OpenRA.Mods.RA
var c = Color.White; var c = Color.White;
foreach (var a in armaments.Value) foreach (var a in armaments.Value)
{
foreach (var b in a.Barrels) foreach (var b in a.Barrels)
{ {
var muzzle = self.CenterPosition + a.MuzzleOffset(self, b); var muzzle = self.CenterPosition + a.MuzzleOffset(self, b);
@@ -60,11 +61,9 @@ namespace OpenRA.Mods.RA
var sm = wr.ScreenPosition(muzzle); var sm = wr.ScreenPosition(muzzle);
var sd = wr.ScreenPosition(muzzle + dirOffset); var sd = wr.ScreenPosition(muzzle + dirOffset);
wlr.DrawLine(sm, sd, c, c); wlr.DrawLine(sm, sd, c, c);
wlr.DrawLine(sm + new float2(-1, -1), sm + new float2(-1, 1), c, c); wr.DrawTargetMarker(c, sm);
wlr.DrawLine(sm + new float2(-1, 1), sm + new float2(1, 1), c, c);
wlr.DrawLine(sm + new float2(1, 1), sm + new float2(1, -1), c, c);
wlr.DrawLine(sm + new float2(1, -1), sm + new float2(-1, -1), c, c);
} }
}
} }
} }
} }