72 lines
2.4 KiB
C#
72 lines
2.4 KiB
C#
using System.Drawing;
|
|
using OpenRa.Game.Graphics;
|
|
using System;
|
|
using OpenRa.Game.GameRules;
|
|
using System.Linq;
|
|
|
|
namespace OpenRa.Game
|
|
{
|
|
class UiOverlay
|
|
{
|
|
SpriteRenderer spriteRenderer;
|
|
Sprite buildOk, buildBlocked, unitDebug;
|
|
|
|
public static bool ShowUnitDebug = false;
|
|
public static bool ShowBuildDebug = false;
|
|
|
|
public UiOverlay(SpriteRenderer spriteRenderer)
|
|
{
|
|
this.spriteRenderer = spriteRenderer;
|
|
|
|
buildOk = SynthesizeTile(0x80);
|
|
buildBlocked = SynthesizeTile(0xe6);
|
|
unitDebug = SynthesizeTile(0x7c);
|
|
}
|
|
|
|
static Sprite SynthesizeTile(byte paletteIndex)
|
|
{
|
|
byte[] data = new byte[Game.CellSize * Game.CellSize];
|
|
|
|
for (int i = 0; i < Game.CellSize; i++)
|
|
for (int j = 0; j < Game.CellSize; j++)
|
|
data[i * Game.CellSize + j] = ((i + j) % 4 < 2) ? (byte)0 : paletteIndex;
|
|
|
|
return SheetBuilder.Add( data, new Size(Game.CellSize,Game.CellSize) );
|
|
}
|
|
|
|
public void Draw()
|
|
{
|
|
if (ShowUnitDebug)
|
|
for (var j = 0; j < 128; j++)
|
|
for (var i = 0; i < 128; i++)
|
|
if (Game.UnitInfluence.GetUnitAt(new int2(i, j)) != null)
|
|
spriteRenderer.DrawSprite(unitDebug, Game.CellSize * new float2(i, j), 0);
|
|
}
|
|
|
|
public void DrawBuildingGrid( UnitInfo.BuildingInfo bi )
|
|
{
|
|
var position = Game.controller.MousePosition.ToInt2();
|
|
|
|
var maxDistance = bi.Adjacent + 2; /* real-ra is weird. this is 1 GAP. */
|
|
|
|
//if( ShowBuildDebug )
|
|
// for( var j = 0 ; j < 128 ; j++ )
|
|
// for( var i = 0 ; i < 128 ; i++ )
|
|
// 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.map.ContainsResource( new int2( i, j ) ) )
|
|
// spriteRenderer.DrawSprite( unitDebug, Game.CellSize * new float2( i, j ), 0 );
|
|
|
|
var tooFarFromBase = !Footprint.Tiles( bi, position ).Any(
|
|
t => Game.GetDistanceToBase( t, Game.LocalPlayer ) < maxDistance );
|
|
|
|
foreach( var t in Footprint.Tiles( bi, position ) )
|
|
spriteRenderer.DrawSprite( ( !tooFarFromBase && Game.IsCellBuildable( t, bi.WaterBound
|
|
? UnitMovementType.Float : UnitMovementType.Wheel ) && !Game.map.ContainsResource( t ) )
|
|
? buildOk : buildBlocked, Game.CellSize * t, 0 );
|
|
|
|
spriteRenderer.Flush();
|
|
}
|
|
}
|
|
}
|