Using the building footprint, the placement overlay is offset from the cursor so the cursor is in the approximate middle of the overlay (not precisely due to overlay snapping to tiles). The tile size (24) was used as a magic number in a lot of places, they have been replaced with Game.CellSize.
63 lines
1.3 KiB
C#
63 lines
1.3 KiB
C#
using System.Drawing;
|
|
using OpenRa.Game.Graphics;
|
|
using System;
|
|
using OpenRa.Game.GameRules;
|
|
|
|
namespace OpenRa.Game
|
|
{
|
|
class UiOverlay
|
|
{
|
|
SpriteRenderer spriteRenderer;
|
|
Sprite buildOk;
|
|
Sprite buildBlocked;
|
|
Game game;
|
|
|
|
public UiOverlay(SpriteRenderer spriteRenderer, Game game)
|
|
{
|
|
this.spriteRenderer = spriteRenderer;
|
|
this.game = game;
|
|
|
|
buildOk = SynthesizeTile(0x80);
|
|
buildBlocked = SynthesizeTile(0xe6);
|
|
}
|
|
|
|
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 (!hasOverlay)
|
|
return;
|
|
|
|
foreach (var t in Footprint.Tiles(name,position))
|
|
spriteRenderer.DrawSprite(game.IsCellBuildable(t) ? buildOk : buildBlocked, Game.CellSize * t, 0);
|
|
|
|
spriteRenderer.Flush();
|
|
}
|
|
|
|
bool hasOverlay;
|
|
int2 position;
|
|
string name;
|
|
|
|
public void KillOverlay()
|
|
{
|
|
hasOverlay = false;
|
|
}
|
|
|
|
public void SetCurrentOverlay(int2 cell, string name)
|
|
{
|
|
hasOverlay = true;
|
|
position = cell;
|
|
this.name = name;
|
|
}
|
|
}
|
|
}
|