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;
}
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()
{
palette.ApplyModifiers(world.WorldActor.TraitsImplementing<IPaletteModifier>());

View File

@@ -60,27 +60,17 @@ namespace OpenRA.Traits
return;
var from = wr.ScreenPxPosition(self.CenterPosition);
var wlr = Game.Renderer.WorldLineRenderer;
foreach (var target in targets)
{
if (target.Type == TargetType.Invalid)
continue;
var to = wr.ScreenPxPosition(target.CenterPosition);
wlr.DrawLine(from, to, c, c);
DrawTargetMarker(wlr, from);
DrawTargetMarker(wlr, to);
Game.Renderer.WorldLineRenderer.DrawLine(from, to, c, c);
wr.DrawTargetMarker(c, from);
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
@@ -89,12 +79,7 @@ namespace OpenRA.Traits
{
var line = self.TraitOrDefault<DrawLineToTarget>();
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)

View File

@@ -154,7 +154,8 @@ namespace OpenRA.Traits
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();
if (activity != null)
@@ -163,15 +164,10 @@ namespace OpenRA.Traits
var start = wr.ScreenPxPosition(self.CenterPosition);
var c = Color.Green;
var wlr = Game.Renderer.WorldLineRenderer;
foreach (var stp in targets.Where(t => t.Type != TargetType.Invalid).Select(p => wr.ScreenPxPosition(p.CenterPosition)))
foreach (var stp in targets.Where(t => t.Type != TargetType.Invalid).Select(pos => wr.ScreenPxPosition(pos.CenterPosition)))
{
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(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);
Game.Renderer.WorldLineRenderer.DrawLine(start, stp, c, c);
wr.DrawTargetMarker(c, stp);
start = stp;
}
}

View File

@@ -52,6 +52,7 @@ namespace OpenRA.Mods.RA
var c = Color.White;
foreach (var a in armaments.Value)
{
foreach (var b in a.Barrels)
{
var muzzle = self.CenterPosition + a.MuzzleOffset(self, b);
@@ -60,10 +61,8 @@ namespace OpenRA.Mods.RA
var sm = wr.ScreenPosition(muzzle);
var sd = wr.ScreenPosition(muzzle + dirOffset);
wlr.DrawLine(sm, sd, 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);
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);
wr.DrawTargetMarker(c, sm);
}
}
}
}