extract DrawGrid from DrawBuildingGrid
This commit is contained in:
@@ -53,27 +53,33 @@ namespace OpenRA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void DrawGrid( WorldRenderer wr, Dictionary<int2, bool> cells )
|
||||||
|
{
|
||||||
|
foreach( var c in cells )
|
||||||
|
( c.Value ? buildOk : buildBlocked ).DrawAt( wr, Game.CellSize * c.Key, "terrain" );
|
||||||
|
}
|
||||||
|
|
||||||
public void DrawBuildingGrid( WorldRenderer wr, World world, string name, BuildingInfo bi )
|
public void DrawBuildingGrid( WorldRenderer wr, World world, string name, BuildingInfo bi )
|
||||||
{
|
{
|
||||||
var position = Game.viewport.ViewToWorld(Viewport.LastMousePos).ToInt2();
|
var position = Game.viewport.ViewToWorld(Viewport.LastMousePos).ToInt2();
|
||||||
var topLeft = position - Footprint.AdjustForBuildingSize( bi );
|
var topLeft = position - Footprint.AdjustForBuildingSize( bi );
|
||||||
|
|
||||||
|
var cells = new Dictionary<int2, bool>();
|
||||||
// Linebuild for walls.
|
// Linebuild for walls.
|
||||||
// Assumes a 1x1 footprint; weird things will happen for other footprints
|
// Assumes a 1x1 footprint; weird things will happen for other footprints
|
||||||
if (Rules.Info[name].Traits.Contains<LineBuildInfo>())
|
if (Rules.Info[name].Traits.Contains<LineBuildInfo>())
|
||||||
{
|
{
|
||||||
foreach (var t in LineBuildUtils.GetLineBuildCells(world, topLeft, name, bi))
|
foreach( var t in LineBuildUtils.GetLineBuildCells( world, topLeft, name, bi ) )
|
||||||
(world.IsCloseEnoughToBase(world.LocalPlayer, name, bi, t) ? buildOk : buildBlocked)
|
cells.Add( t, world.IsCloseEnoughToBase( world.LocalPlayer, name, bi, t ) );
|
||||||
.DrawAt(wr, Game.CellSize * t, "terrain");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var res = world.WorldActor.Trait<ResourceLayer>();
|
var res = world.WorldActor.Trait<ResourceLayer>();
|
||||||
var isCloseEnough = world.IsCloseEnoughToBase(world.LocalPlayer, name, bi, topLeft);
|
var isCloseEnough = world.IsCloseEnoughToBase(world.LocalPlayer, name, bi, topLeft);
|
||||||
foreach (var t in Footprint.Tiles(name, bi, topLeft))
|
foreach (var t in Footprint.Tiles(name, bi, topLeft))
|
||||||
((isCloseEnough && world.IsCellBuildable(t, bi.WaterBound) && res.GetResource(t) == null) ? buildOk : buildBlocked)
|
cells.Add( t, isCloseEnough && world.IsCellBuildable(t, bi.WaterBound) && res.GetResource(t) == null );
|
||||||
.DrawAt( wr, Game.CellSize * t, "terrain");
|
|
||||||
}
|
}
|
||||||
|
DrawGrid( wr, cells );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user