Fix map preview bounds calculation.

This commit is contained in:
Paul Chote
2021-08-20 18:41:57 +01:00
committed by abcdefg30
parent 7f94d67d39
commit 3551eb3128
2 changed files with 30 additions and 7 deletions

View File

@@ -713,11 +713,34 @@ namespace OpenRA
var isRectangularIsometric = Grid.Type == MapGridType.RectangularIsometric;
// Fudge the heightmap offset by adding as much extra as we need / can.
// This tries to correct for our incorrect assumption that MPos == PPos
var heightOffset = Math.Min(Grid.MaximumTerrainHeight, MapSize.Y - Bounds.Bottom);
var top = int.MaxValue;
var bottom = int.MinValue;
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 height = Bounds.Height + heightOffset;
var height = bottom - top;
var bitmapWidth = width;
if (isRectangularIsometric)
@@ -726,13 +749,13 @@ namespace OpenRA
var stride = bitmapWidth * 4;
var pxStride = 4;
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 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
var actorColor = positions.FirstOrDefault(ap => ap.Position == uv).Color;