Restructuring orders.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
using System.Drawing;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using IjwFramework.Types;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using IjwFramework.Types;
|
||||
using System.Collections.Generic;
|
||||
using OpenRa.Game.Traits;
|
||||
|
||||
namespace OpenRa.Game.Graphics
|
||||
@@ -12,13 +12,13 @@ namespace OpenRa.Game.Graphics
|
||||
public readonly SpriteRenderer spriteRenderer;
|
||||
public readonly LineRenderer lineRenderer;
|
||||
public readonly Region region;
|
||||
public readonly UiOverlay uiOverlay;
|
||||
|
||||
public readonly UiOverlay uiOverlay;
|
||||
|
||||
public static bool ShowUnitPaths = false;
|
||||
|
||||
public WorldRenderer(Renderer renderer)
|
||||
{
|
||||
// TODO: this is layout policy. it belongs at a higher level than this.
|
||||
// TODO: this is layout policy. it belongs at a higher level than this.
|
||||
region = Region.Create(Game.viewport, DockStyle.Left,
|
||||
Game.viewport.Width - 128, Draw,
|
||||
Game.controller.HandleMouseInput);
|
||||
@@ -28,41 +28,41 @@ namespace OpenRa.Game.Graphics
|
||||
spriteRenderer = new SpriteRenderer(renderer, true);
|
||||
lineRenderer = new LineRenderer(renderer);
|
||||
uiOverlay = new UiOverlay(spriteRenderer);
|
||||
}
|
||||
|
||||
void DrawSpriteList(Player owner, RectangleF rect,
|
||||
IEnumerable<Pair<Sprite, float2>> images)
|
||||
{
|
||||
foreach (var image in images)
|
||||
{
|
||||
var loc = image.Second;
|
||||
|
||||
if (loc.X > rect.Right || loc.X < rect.Left
|
||||
- image.First.bounds.Width)
|
||||
continue;
|
||||
if (loc.Y > rect.Bottom || loc.Y < rect.Top
|
||||
- image.First.bounds.Height)
|
||||
continue;
|
||||
|
||||
spriteRenderer.DrawSprite(image.First, loc,
|
||||
(owner != null) ? owner.Palette : 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DrawSpriteList(Player owner, RectangleF rect,
|
||||
IEnumerable<Pair<Sprite, float2>> images)
|
||||
{
|
||||
foreach (var image in images)
|
||||
{
|
||||
var loc = image.Second;
|
||||
|
||||
if (loc.X > rect.Right || loc.X < rect.Left
|
||||
- image.First.bounds.Width)
|
||||
continue;
|
||||
if (loc.Y > rect.Bottom || loc.Y < rect.Top
|
||||
- image.First.bounds.Height)
|
||||
continue;
|
||||
|
||||
spriteRenderer.DrawSprite(image.First, loc,
|
||||
(owner != null) ? owner.Palette : 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
var rect = new RectangleF((region.Position + Game.viewport.Location).ToPointF(),
|
||||
region.Size.ToSizeF());
|
||||
|
||||
foreach (Actor a in Game.world.Actors.OrderBy( u => u.CenterLocation.Y ))
|
||||
DrawSpriteList(a.Owner, rect, a.Render());
|
||||
|
||||
foreach (var a in Game.world.Actors
|
||||
.Where(u => u.traits.Contains<Traits.RenderWarFactory>())
|
||||
.Select(u => u.traits.Get<Traits.RenderWarFactory>()))
|
||||
DrawSpriteList(a.self.Owner, rect, a.RenderRoof(a.self)); /* RUDE HACK */
|
||||
|
||||
foreach (IEffect e in Game.world.Effects)
|
||||
DrawSpriteList(a.Owner, rect, a.Render());
|
||||
|
||||
foreach (var a in Game.world.Actors
|
||||
.Where(u => u.traits.Contains<Traits.RenderWarFactory>())
|
||||
.Select(u => u.traits.Get<Traits.RenderWarFactory>()))
|
||||
DrawSpriteList(a.self.Owner, rect, a.RenderRoof(a.self)); /* RUDE HACK */
|
||||
|
||||
foreach (IEffect e in Game.world.Effects)
|
||||
DrawSpriteList(e.Owner, rect, e.Render());
|
||||
|
||||
uiOverlay.Draw();
|
||||
@@ -93,7 +93,7 @@ namespace OpenRa.Game.Graphics
|
||||
lineRenderer.Flush();
|
||||
}
|
||||
|
||||
const float conditionYellow = 0.5f; /* todo: get these from gamerules */
|
||||
const float conditionYellow = 0.5f; /* todo: get these from gamerules */
|
||||
const float conditionRed = 0.25f;
|
||||
|
||||
void DrawSelectionBox(Actor selectedUnit, Color c, bool drawHealthBar)
|
||||
@@ -114,60 +114,60 @@ namespace OpenRa.Game.Graphics
|
||||
lineRenderer.DrawLine(xY, xY + new float2(4, 0), c, c);
|
||||
lineRenderer.DrawLine(xY, xY + new float2(0, -4), c, c);
|
||||
lineRenderer.DrawLine(XY, XY + new float2(-4, 0), c, c);
|
||||
lineRenderer.DrawLine(XY, XY + new float2(0, -4), c, c);
|
||||
|
||||
if (drawHealthBar)
|
||||
{
|
||||
c = Color.Gray;
|
||||
lineRenderer.DrawLine(xy + new float2(0, -2), xy + new float2(0, -4), c, c);
|
||||
lineRenderer.DrawLine(Xy + new float2(0, -2), Xy + new float2(0, -4), c, c);
|
||||
|
||||
var healthAmount = (float)selectedUnit.Health / selectedUnit.unitInfo.Strength;
|
||||
var healthColor = (healthAmount < conditionRed) ? Color.Red
|
||||
: (healthAmount < conditionYellow) ? Color.Yellow
|
||||
: Color.LimeGreen;
|
||||
|
||||
var healthColor2 = Color.FromArgb(
|
||||
255,
|
||||
healthColor.R / 2,
|
||||
healthColor.G / 2,
|
||||
healthColor.B / 2);
|
||||
|
||||
var z = float2.Lerp(xy, Xy, healthAmount);
|
||||
|
||||
lineRenderer.DrawLine(z + new float2(0, -4), Xy + new float2(0,-4), c, c);
|
||||
lineRenderer.DrawLine(z + new float2(0, -2), Xy + new float2(0, -2), c, c);
|
||||
|
||||
lineRenderer.DrawLine(xy + new float2(0, -3),
|
||||
z + new float2(0, -3),
|
||||
healthColor, healthColor);
|
||||
|
||||
lineRenderer.DrawLine(xy + new float2(0, -2),
|
||||
z + new float2(0, -2),
|
||||
healthColor2, healthColor2);
|
||||
|
||||
lineRenderer.DrawLine(xy + new float2(0, -4),
|
||||
z + new float2(0, -4),
|
||||
healthColor2, healthColor2);
|
||||
}
|
||||
|
||||
if (ShowUnitPaths)
|
||||
{
|
||||
var mobile = selectedUnit.traits.GetOrDefault<Mobile>();
|
||||
if (mobile != null)
|
||||
{
|
||||
var path = mobile.GetCurrentPath();
|
||||
var start = selectedUnit.Location;
|
||||
|
||||
foreach (var step in path)
|
||||
{
|
||||
lineRenderer.DrawLine(
|
||||
Game.CellSize * start + new float2(12, 12),
|
||||
Game.CellSize * step + new float2(12, 12),
|
||||
Color.Red, Color.Red);
|
||||
start = step;
|
||||
}
|
||||
}
|
||||
lineRenderer.DrawLine(XY, XY + new float2(0, -4), c, c);
|
||||
|
||||
if (drawHealthBar)
|
||||
{
|
||||
c = Color.Gray;
|
||||
lineRenderer.DrawLine(xy + new float2(0, -2), xy + new float2(0, -4), c, c);
|
||||
lineRenderer.DrawLine(Xy + new float2(0, -2), Xy + new float2(0, -4), c, c);
|
||||
|
||||
var healthAmount = (float)selectedUnit.Health / selectedUnit.unitInfo.Strength;
|
||||
var healthColor = (healthAmount < conditionRed) ? Color.Red
|
||||
: (healthAmount < conditionYellow) ? Color.Yellow
|
||||
: Color.LimeGreen;
|
||||
|
||||
var healthColor2 = Color.FromArgb(
|
||||
255,
|
||||
healthColor.R / 2,
|
||||
healthColor.G / 2,
|
||||
healthColor.B / 2);
|
||||
|
||||
var z = float2.Lerp(xy, Xy, healthAmount);
|
||||
|
||||
lineRenderer.DrawLine(z + new float2(0, -4), Xy + new float2(0,-4), c, c);
|
||||
lineRenderer.DrawLine(z + new float2(0, -2), Xy + new float2(0, -2), c, c);
|
||||
|
||||
lineRenderer.DrawLine(xy + new float2(0, -3),
|
||||
z + new float2(0, -3),
|
||||
healthColor, healthColor);
|
||||
|
||||
lineRenderer.DrawLine(xy + new float2(0, -2),
|
||||
z + new float2(0, -2),
|
||||
healthColor2, healthColor2);
|
||||
|
||||
lineRenderer.DrawLine(xy + new float2(0, -4),
|
||||
z + new float2(0, -4),
|
||||
healthColor2, healthColor2);
|
||||
}
|
||||
|
||||
if (ShowUnitPaths)
|
||||
{
|
||||
var mobile = selectedUnit.traits.GetOrDefault<Mobile>();
|
||||
if (mobile != null)
|
||||
{
|
||||
var path = mobile.GetCurrentPath();
|
||||
var start = selectedUnit.Location;
|
||||
|
||||
foreach (var step in path)
|
||||
{
|
||||
lineRenderer.DrawLine(
|
||||
Game.CellSize * start + new float2(12, 12),
|
||||
Game.CellSize * step + new float2(12, 12),
|
||||
Color.Red, Color.Red);
|
||||
start = step;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user