Now coloring A* cells by owning player color. Added checkbox to cheats menu.
This commit is contained in:
@@ -120,7 +120,8 @@ namespace OpenRA.Mods.RA.Move
|
||||
|
||||
public List<CPos> FindBidiPath( /* searches from both ends toward each other */
|
||||
PathSearch fromSrc,
|
||||
PathSearch fromDest)
|
||||
PathSearch fromDest,
|
||||
Player onBehalfOf)
|
||||
{
|
||||
using (new PerfSample("Pathfinder"))
|
||||
{
|
||||
@@ -155,8 +156,8 @@ namespace OpenRA.Mods.RA.Move
|
||||
var dbg = world.WorldActor.TraitOrDefault<DebugOverlay>();
|
||||
if (dbg != null)
|
||||
{
|
||||
dbg.AddLayer(fromSrc.considered.Select(p => new Pair<CPos, int>(p, fromSrc.cellInfo[p.X, p.Y].MinCost)), fromSrc.maxCost);
|
||||
dbg.AddLayer(fromDest.considered.Select(p => new Pair<CPos, int>(p, fromDest.cellInfo[p.X, p.Y].MinCost)), fromDest.maxCost);
|
||||
dbg.AddLayer(fromSrc.considered.Select(p => new Pair<CPos, int>(p, fromSrc.cellInfo[p.X, p.Y].MinCost)), fromSrc.maxCost, onBehalfOf);
|
||||
dbg.AddLayer(fromDest.considered.Select(p => new Pair<CPos, int>(p, fromDest.cellInfo[p.X, p.Y].MinCost)), fromDest.maxCost, onBehalfOf);
|
||||
}
|
||||
|
||||
if (path != null)
|
||||
|
||||
@@ -59,6 +59,11 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
widget.Get<ButtonWidget>("RESET_EXPLORATION").OnClick = () =>
|
||||
world.IssueOrder(new Order("DevResetExploration", world.LocalPlayer.PlayerActor, false));
|
||||
|
||||
var dbgOverlay = world.WorldActor.TraitOrDefault<DebugOverlay>();
|
||||
var showAstarCostCheckbox = widget.Get<CheckboxWidget>("SHOW_ASTAR");
|
||||
showAstarCostCheckbox.IsChecked = () => dbgOverlay != null ? dbgOverlay.Visible : false;
|
||||
showAstarCostCheckbox.OnClick = () => { if (dbgOverlay != null) dbgOverlay.Visible ^= true; };
|
||||
|
||||
widget.Get<ButtonWidget>("CLOSE").OnClick = () => { Ui.CloseWindow(); onExit(); };
|
||||
}
|
||||
|
||||
|
||||
@@ -15,46 +15,61 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
class DebugOverlay : IRenderOverlay, IWorldLoaded
|
||||
{
|
||||
int[,] layer;
|
||||
Dictionary<Player, int[,]> layers;
|
||||
int refreshTick;
|
||||
World world;
|
||||
public bool Visible;
|
||||
|
||||
public void WorldLoaded(World w)
|
||||
{
|
||||
this.world = w;
|
||||
this.layer = new int[w.Map.MapSize.X, w.Map.MapSize.Y];
|
||||
this.refreshTick = 0;
|
||||
this.layers = new Dictionary<Player, int[,]>(8);
|
||||
// Enabled via Cheats menu
|
||||
this.Visible = false;
|
||||
}
|
||||
|
||||
public void AddLayer(IEnumerable<Pair<CPos, int>> cellWeights, int maxWeight)
|
||||
public void AddLayer(IEnumerable<Pair<CPos, int>> cellWeights, int maxWeight, Player pl)
|
||||
{
|
||||
if (maxWeight == 0) return;
|
||||
|
||||
int[,] layer;
|
||||
if (!layers.TryGetValue(pl, out layer))
|
||||
{
|
||||
layer = new int[world.Map.MapSize.X, world.Map.MapSize.Y];
|
||||
layers.Add(pl, layer);
|
||||
}
|
||||
|
||||
foreach (var p in cellWeights)
|
||||
layer[p.First.X, p.First.Y] = layer[p.First.X, p.First.Y] / 2 + (p.Second * 128 / maxWeight);
|
||||
layer[p.First.X, p.First.Y] = Math.Min(128, (layer[p.First.X, p.First.Y] / 2) + ((maxWeight - p.Second) * 64 / maxWeight));
|
||||
}
|
||||
|
||||
public void Render(WorldRenderer wr)
|
||||
{
|
||||
if (!Visible) return;
|
||||
|
||||
var qr = Game.Renderer.WorldQuadRenderer;
|
||||
bool doSwap = refreshTick - world.FrameNumber <= 0;
|
||||
if (doSwap) refreshTick = world.FrameNumber + 20;
|
||||
bool doDim = refreshTick - world.FrameNumber <= 0;
|
||||
if (doDim) refreshTick = world.FrameNumber + 15;
|
||||
|
||||
for (int j = world.Map.Bounds.Top; j <= world.Map.Bounds.Bottom; ++j)
|
||||
for (int i = world.Map.Bounds.Left; i <= world.Map.Bounds.Right; ++i)
|
||||
{
|
||||
if (!world.Map.IsInMap(i, j)) continue;
|
||||
foreach (var pair in layers)
|
||||
{
|
||||
Color c = (pair.Key != null) ? pair.Key.ColorRamp.GetColor(0f) : Color.PaleTurquoise;
|
||||
var layer = pair.Value;
|
||||
|
||||
var cell = new CPos(i, j);
|
||||
var pix = cell.ToPPos();
|
||||
|
||||
var w = Math.Max(0, Math.Min(layer[i, j], 224));
|
||||
if (doSwap)
|
||||
for (int j = world.Map.Bounds.Top; j <= world.Map.Bounds.Bottom; ++j)
|
||||
for (int i = world.Map.Bounds.Left; i <= world.Map.Bounds.Right; ++i)
|
||||
{
|
||||
layer[i, j] = layer[i, j] * 4 / 5;
|
||||
var ploc = new CPos(i, j).ToPPos();
|
||||
|
||||
var w = Math.Max(0, Math.Min(layer[i, j], 128));
|
||||
if (doDim)
|
||||
{
|
||||
layer[i, j] = layer[i, j] * 4 / 5;
|
||||
}
|
||||
qr.FillRect(new RectangleF(ploc.X, ploc.Y, Game.CellSize, Game.CellSize), Color.FromArgb(w, c));
|
||||
}
|
||||
qr.FillRect(new RectangleF(pix.X, pix.Y, Game.CellSize, Game.CellSize), Color.FromArgb(w, Color.White));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ Background@CHEATS_PANEL:
|
||||
X:(WINDOW_RIGHT - WIDTH)/2
|
||||
Y:(WINDOW_BOTTOM - HEIGHT)/2
|
||||
Width:350
|
||||
Height:420
|
||||
Height:450
|
||||
Visible:true
|
||||
Children:
|
||||
Label@LABEL_TITLE:
|
||||
@@ -75,6 +75,12 @@ Background@CHEATS_PANEL:
|
||||
Width:PARENT_RIGHT - 30
|
||||
Height:20
|
||||
Text:Build Anywhere
|
||||
Checkbox@SHOW_ASTAR:
|
||||
X:30
|
||||
Y:320
|
||||
Width:PARENT_RIGHT - 30
|
||||
Height:20
|
||||
Text:Show A* Cost
|
||||
Button@CLOSE:
|
||||
X:30
|
||||
Y:360
|
||||
|
||||
Reference in New Issue
Block a user