IOrderGenerator now renders itself (Removed various cast and is fails.). - Fixed silly bug in prev.
This commit is contained in:
@@ -1,40 +1,40 @@
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using IjwFramework.Types;
|
using IjwFramework.Types;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenRa.Game.Traits;
|
using OpenRa.Game.Traits;
|
||||||
using OpenRa.Game.Support;
|
using OpenRa.Game.Support;
|
||||||
|
|
||||||
namespace OpenRa.Game.Graphics
|
namespace OpenRa.Game.Graphics
|
||||||
{
|
{
|
||||||
class WorldRenderer
|
class WorldRenderer
|
||||||
{
|
{
|
||||||
public readonly TerrainRenderer terrainRenderer;
|
public readonly TerrainRenderer terrainRenderer;
|
||||||
public readonly SpriteRenderer spriteRenderer;
|
public readonly SpriteRenderer spriteRenderer;
|
||||||
public readonly LineRenderer lineRenderer;
|
public readonly LineRenderer lineRenderer;
|
||||||
public readonly Region region;
|
public readonly Region region;
|
||||||
public readonly UiOverlay uiOverlay;
|
public readonly UiOverlay uiOverlay;
|
||||||
readonly Renderer renderer;
|
readonly Renderer renderer;
|
||||||
|
|
||||||
public static bool ShowUnitPaths = false;
|
public static bool ShowUnitPaths = false;
|
||||||
|
|
||||||
public WorldRenderer(Renderer renderer)
|
public WorldRenderer(Renderer renderer)
|
||||||
{
|
{
|
||||||
terrainRenderer = new TerrainRenderer( renderer, Game.map );
|
terrainRenderer = new TerrainRenderer( renderer, Game.map );
|
||||||
|
|
||||||
// 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,
|
region = Region.Create(Game.viewport, DockStyle.Left,
|
||||||
Game.viewport.Width - 128, Draw,
|
Game.viewport.Width - 128, Draw,
|
||||||
Game.controller.HandleMouseInput);
|
Game.controller.HandleMouseInput);
|
||||||
|
|
||||||
Game.viewport.AddRegion(region);
|
Game.viewport.AddRegion(region);
|
||||||
|
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
spriteRenderer = new SpriteRenderer(renderer, true);
|
spriteRenderer = new SpriteRenderer(renderer, true);
|
||||||
lineRenderer = new LineRenderer(renderer);
|
lineRenderer = new LineRenderer(renderer);
|
||||||
uiOverlay = new UiOverlay(spriteRenderer);
|
uiOverlay = new UiOverlay(spriteRenderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawSpriteList(RectangleF rect,
|
void DrawSpriteList(RectangleF rect,
|
||||||
IEnumerable<Tuple<Sprite, float2, int>> images)
|
IEnumerable<Tuple<Sprite, float2, int>> images)
|
||||||
@@ -92,10 +92,8 @@ namespace OpenRa.Game.Graphics
|
|||||||
DrawSelectionBox(u, Color.Yellow, false);
|
DrawSelectionBox(u, Color.Yellow, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
var uog = Game.controller.orderGenerator as UnitOrderGenerator;
|
if( Game.controller.orderGenerator != null )
|
||||||
if (uog != null)
|
Game.controller.orderGenerator.Render();
|
||||||
foreach (var a in uog.selection)
|
|
||||||
DrawSelectionBox(a, Color.White, true);
|
|
||||||
|
|
||||||
lineRenderer.Flush();
|
lineRenderer.Flush();
|
||||||
|
|
||||||
@@ -109,81 +107,81 @@ namespace OpenRa.Game.Graphics
|
|||||||
), new int2(5, 5), Color.White);
|
), new int2(5, 5), Color.White);
|
||||||
|
|
||||||
PerfHistory.Render(renderer, lineRenderer);
|
PerfHistory.Render(renderer, lineRenderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawSelectionBox(Actor selectedUnit, Color c, bool drawHealthBar)
|
public void DrawSelectionBox(Actor selectedUnit, Color c, bool drawHealthBar)
|
||||||
{
|
{
|
||||||
var center = selectedUnit.CenterLocation;
|
var center = selectedUnit.CenterLocation;
|
||||||
var size = selectedUnit.SelectedSize;
|
var size = selectedUnit.SelectedSize;
|
||||||
|
|
||||||
var xy = center - 0.5f * size;
|
var xy = center - 0.5f * size;
|
||||||
var XY = center + 0.5f * size;
|
var XY = center + 0.5f * size;
|
||||||
var Xy = new float2(XY.X, xy.Y);
|
var Xy = new float2(XY.X, xy.Y);
|
||||||
var xY = new float2(xy.X, XY.Y);
|
var xY = new float2(xy.X, XY.Y);
|
||||||
|
|
||||||
lineRenderer.DrawLine(xy, xy + new float2(4, 0), c, c);
|
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(0, 4), c, c);
|
||||||
lineRenderer.DrawLine(Xy, Xy + new float2(-4, 0), c, c);
|
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(0, 4), c, c);
|
||||||
|
|
||||||
lineRenderer.DrawLine(xY, xY + new float2(4, 0), c, c);
|
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(0, -4), c, c);
|
||||||
lineRenderer.DrawLine(XY, XY + new float2(-4, 0), c, c);
|
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(0, -4), c, c);
|
||||||
|
|
||||||
if (drawHealthBar)
|
if (drawHealthBar)
|
||||||
{
|
{
|
||||||
c = Color.Gray;
|
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);
|
||||||
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 healthAmount = (float)selectedUnit.Health / selectedUnit.unitInfo.Strength;
|
||||||
var healthColor = (healthAmount < Rules.General.ConditionRed) ? Color.Red
|
var healthColor = (healthAmount < Rules.General.ConditionRed) ? Color.Red
|
||||||
: (healthAmount < Rules.General.ConditionYellow) ? Color.Yellow
|
: (healthAmount < Rules.General.ConditionYellow) ? Color.Yellow
|
||||||
: Color.LimeGreen;
|
: Color.LimeGreen;
|
||||||
|
|
||||||
var healthColor2 = Color.FromArgb(
|
var healthColor2 = Color.FromArgb(
|
||||||
255,
|
255,
|
||||||
healthColor.R / 2,
|
healthColor.R / 2,
|
||||||
healthColor.G / 2,
|
healthColor.G / 2,
|
||||||
healthColor.B / 2);
|
healthColor.B / 2);
|
||||||
|
|
||||||
var z = float2.Lerp(xy, Xy, healthAmount);
|
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, -4), Xy + new float2(0,-4), c, c);
|
||||||
lineRenderer.DrawLine(z + new float2(0, -2), Xy + new float2(0, -2), c, c);
|
lineRenderer.DrawLine(z + new float2(0, -2), Xy + new float2(0, -2), c, c);
|
||||||
|
|
||||||
lineRenderer.DrawLine(xy + new float2(0, -3),
|
lineRenderer.DrawLine(xy + new float2(0, -3),
|
||||||
z + new float2(0, -3),
|
z + new float2(0, -3),
|
||||||
healthColor, healthColor);
|
healthColor, healthColor);
|
||||||
|
|
||||||
lineRenderer.DrawLine(xy + new float2(0, -2),
|
lineRenderer.DrawLine(xy + new float2(0, -2),
|
||||||
z + new float2(0, -2),
|
z + new float2(0, -2),
|
||||||
healthColor2, healthColor2);
|
healthColor2, healthColor2);
|
||||||
|
|
||||||
lineRenderer.DrawLine(xy + new float2(0, -4),
|
lineRenderer.DrawLine(xy + new float2(0, -4),
|
||||||
z + new float2(0, -4),
|
z + new float2(0, -4),
|
||||||
healthColor2, healthColor2);
|
healthColor2, healthColor2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ShowUnitPaths)
|
if (ShowUnitPaths)
|
||||||
{
|
{
|
||||||
var mobile = selectedUnit.traits.GetOrDefault<Mobile>();
|
var mobile = selectedUnit.traits.GetOrDefault<Mobile>();
|
||||||
if (mobile != null)
|
if (mobile != null)
|
||||||
{
|
{
|
||||||
var path = mobile.GetCurrentPath();
|
var path = mobile.GetCurrentPath();
|
||||||
var start = selectedUnit.Location;
|
var start = selectedUnit.Location;
|
||||||
|
|
||||||
foreach (var step in path)
|
foreach (var step in path)
|
||||||
{
|
{
|
||||||
lineRenderer.DrawLine(
|
lineRenderer.DrawLine(
|
||||||
Game.CellSize * start + new float2(12, 12),
|
Game.CellSize * start + new float2(12, 12),
|
||||||
Game.CellSize * step + new float2(12, 12),
|
Game.CellSize * step + new float2(12, 12),
|
||||||
Color.Red, Color.Red);
|
Color.Red, Color.Red);
|
||||||
start = step;
|
start = step;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,5 +8,6 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
IEnumerable<Order> Order( int2 xy, bool lmb );
|
IEnumerable<Order> Order( int2 xy, bool lmb );
|
||||||
void Tick();
|
void Tick();
|
||||||
|
void Render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,5 +43,10 @@ namespace OpenRa.Game
|
|||||||
if( producing == null || producing.Item != Building.Name || producing.RemainingTime != 0 )
|
if( producing == null || producing.Item != Building.Name || producing.RemainingTime != 0 )
|
||||||
Game.world.AddFrameEndTask( _ => { Game.controller.orderGenerator = null; } );
|
Game.world.AddFrameEndTask( _ => { Game.controller.orderGenerator = null; } );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Render()
|
||||||
|
{
|
||||||
|
Game.worldRenderer.uiOverlay.DrawBuildingGrid( Building );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ namespace OpenRa.Game.Traits.Activities
|
|||||||
umt = mobile.GetMovementType(),
|
umt = mobile.GetMovementType(),
|
||||||
checkForBlocked = false,
|
checkForBlocked = false,
|
||||||
};
|
};
|
||||||
var refineries = Game.world.Actors.Where( x => x.unitInfo.Name == "proc" ).ToList();
|
var refineries = Game.world.Actors.Where( x => x.unitInfo != null && x.unitInfo.Name == "proc" ).ToList();
|
||||||
if( refinery != null )
|
if( refinery != null )
|
||||||
search.AddInitialCell( refinery.Location + refineryDeliverOffset );
|
search.AddInitialCell( refinery.Location + refineryDeliverOffset );
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -41,30 +41,28 @@ namespace OpenRa.Game
|
|||||||
for (var i = 0; i < 128; i++)
|
for (var i = 0; i < 128; i++)
|
||||||
if (Game.UnitInfluence.GetUnitAt(new int2(i, j)) != null)
|
if (Game.UnitInfluence.GetUnitAt(new int2(i, j)) != null)
|
||||||
spriteRenderer.DrawSprite(unitDebug, Game.CellSize * new float2(i, j), 0);
|
spriteRenderer.DrawSprite(unitDebug, Game.CellSize * new float2(i, j), 0);
|
||||||
|
}
|
||||||
|
|
||||||
var placeBuilding = Game.controller.orderGenerator as PlaceBuilding;
|
public void DrawBuildingGrid( UnitInfo.BuildingInfo bi )
|
||||||
if (placeBuilding == null) return;
|
{
|
||||||
|
|
||||||
var position = Game.controller.MousePosition.ToInt2();
|
var position = Game.controller.MousePosition.ToInt2();
|
||||||
|
|
||||||
var bi = placeBuilding.Building;
|
|
||||||
|
|
||||||
var maxDistance = bi.Adjacent + 2; /* real-ra is weird. this is 1 GAP. */
|
var maxDistance = bi.Adjacent + 2; /* real-ra is weird. this is 1 GAP. */
|
||||||
|
|
||||||
if (ShowBuildDebug)
|
if( ShowBuildDebug )
|
||||||
for (var j = 0; j < 128; j++)
|
for( var j = 0 ; j < 128 ; j++ )
|
||||||
for (var i = 0; i < 128; i++)
|
for( var i = 0 ; i < 128 ; i++ )
|
||||||
if (Game.GetDistanceToBase(new int2(i, j), Game.LocalPlayer) < maxDistance)
|
if( Game.GetDistanceToBase( new int2( i, j ), Game.LocalPlayer ) < maxDistance )
|
||||||
if (Game.IsCellBuildable(new int2(i, j), bi.WaterBound ? UnitMovementType.Float : UnitMovementType.Wheel))
|
if( Game.IsCellBuildable( new int2( i, j ), bi.WaterBound ? UnitMovementType.Float : UnitMovementType.Wheel ) )
|
||||||
if (!Game.map.ContainsResource(new int2(i,j)))
|
if( !Game.map.ContainsResource( new int2( i, j ) ) )
|
||||||
spriteRenderer.DrawSprite(unitDebug, Game.CellSize * new float2(i, j), 0);
|
spriteRenderer.DrawSprite( unitDebug, Game.CellSize * new float2( i, j ), 0 );
|
||||||
|
|
||||||
var tooFarFromBase = !Footprint.Tiles(bi, position).Any(
|
var tooFarFromBase = !Footprint.Tiles( bi, position ).Any(
|
||||||
t => Game.GetDistanceToBase(t, Game.LocalPlayer) < maxDistance);
|
t => Game.GetDistanceToBase( t, Game.LocalPlayer ) < maxDistance );
|
||||||
|
|
||||||
foreach( var t in Footprint.Tiles( bi, position ) )
|
foreach( var t in Footprint.Tiles( bi, position ) )
|
||||||
spriteRenderer.DrawSprite( (!tooFarFromBase && Game.IsCellBuildable( t, bi.WaterBound
|
spriteRenderer.DrawSprite( ( !tooFarFromBase && Game.IsCellBuildable( t, bi.WaterBound
|
||||||
? UnitMovementType.Float : UnitMovementType.Wheel ) && !Game.map.ContainsResource(t))
|
? UnitMovementType.Float : UnitMovementType.Wheel ) && !Game.map.ContainsResource( t ) )
|
||||||
? buildOk : buildBlocked, Game.CellSize * t, 0 );
|
? buildOk : buildBlocked, Game.CellSize * t, 0 );
|
||||||
|
|
||||||
spriteRenderer.Flush();
|
spriteRenderer.Flush();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace OpenRa.Game
|
namespace OpenRa.Game
|
||||||
{
|
{
|
||||||
@@ -28,5 +28,11 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
selection.RemoveAll(a => a.IsDead);
|
selection.RemoveAll(a => a.IsDead);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Render()
|
||||||
|
{
|
||||||
|
foreach( var a in selection )
|
||||||
|
Game.worldRenderer.DrawSelectionBox( a, Color.White, true );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user