Fix map preview bounds calculation.
This commit is contained in:
@@ -713,11 +713,34 @@ namespace OpenRA
|
|||||||
|
|
||||||
var isRectangularIsometric = Grid.Type == MapGridType.RectangularIsometric;
|
var isRectangularIsometric = Grid.Type == MapGridType.RectangularIsometric;
|
||||||
|
|
||||||
// Fudge the heightmap offset by adding as much extra as we need / can.
|
var top = int.MaxValue;
|
||||||
// This tries to correct for our incorrect assumption that MPos == PPos
|
var bottom = int.MinValue;
|
||||||
var heightOffset = Math.Min(Grid.MaximumTerrainHeight, MapSize.Y - Bounds.Bottom);
|
|
||||||
|
if (Grid.MaximumTerrainHeight > 0)
|
||||||
|
{
|
||||||
|
// The minimap is drawn in cell space, so we need to
|
||||||
|
// unproject the PPos bounds to find the MPos boundaries.
|
||||||
|
// This matches the calculation in RadarWidget that is used ingame
|
||||||
|
for (var x = Bounds.Left; x < Bounds.Right; x++)
|
||||||
|
{
|
||||||
|
var allTop = Unproject(new PPos(x, Bounds.Top));
|
||||||
|
var allBottom = Unproject(new PPos(x, Bounds.Bottom));
|
||||||
|
if (allTop.Any())
|
||||||
|
top = Math.Min(top, allTop.MinBy(uv => uv.V).V);
|
||||||
|
|
||||||
|
if (allBottom.Any())
|
||||||
|
bottom = Math.Max(bottom, allBottom.MaxBy(uv => uv.V).V);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// If the mod uses flat maps, MPos == PPos and we can take the bounds rect directly
|
||||||
|
top = Bounds.Top;
|
||||||
|
bottom = Bounds.Bottom;
|
||||||
|
}
|
||||||
|
|
||||||
var width = Bounds.Width;
|
var width = Bounds.Width;
|
||||||
var height = Bounds.Height + heightOffset;
|
var height = bottom - top;
|
||||||
|
|
||||||
var bitmapWidth = width;
|
var bitmapWidth = width;
|
||||||
if (isRectangularIsometric)
|
if (isRectangularIsometric)
|
||||||
@@ -726,13 +749,13 @@ namespace OpenRA
|
|||||||
var stride = bitmapWidth * 4;
|
var stride = bitmapWidth * 4;
|
||||||
var pxStride = 4;
|
var pxStride = 4;
|
||||||
var minimapData = new byte[stride * height];
|
var minimapData = new byte[stride * height];
|
||||||
(Color Left, Color Right) terrainColor = default((Color, Color));
|
(Color Left, Color Right) terrainColor = default;
|
||||||
|
|
||||||
for (var y = 0; y < height; y++)
|
for (var y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
for (var x = 0; x < width; x++)
|
for (var x = 0; x < width; x++)
|
||||||
{
|
{
|
||||||
var uv = new MPos(x + Bounds.Left, y + Bounds.Top);
|
var uv = new MPos(x + Bounds.Left, y + top);
|
||||||
|
|
||||||
// FirstOrDefault will return a (MPos.Zero, Color.Transparent) if positions is empty
|
// FirstOrDefault will return a (MPos.Zero, Color.Transparent) if positions is empty
|
||||||
var actorColor = positions.FirstOrDefault(ap => ap.Position == uv).Color;
|
var actorColor = positions.FirstOrDefault(ap => ap.Position == uv).Color;
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
top = Math.Min(top, allTop.MinBy(uv => uv.V).V);
|
top = Math.Min(top, allTop.MinBy(uv => uv.V).V);
|
||||||
|
|
||||||
if (allBottom.Any())
|
if (allBottom.Any())
|
||||||
bottom = Math.Max(bottom, allBottom.MinBy(uv => uv.V).V);
|
bottom = Math.Max(bottom, allBottom.MaxBy(uv => uv.V).V);
|
||||||
}
|
}
|
||||||
|
|
||||||
var b = Rectangle.FromLTRB(left, top, right, bottom);
|
var b = Rectangle.FromLTRB(left, top, right, bottom);
|
||||||
|
|||||||
Reference in New Issue
Block a user