Fix radar pixel <-> cell conversions.

Fixes #8869.
This commit is contained in:
Paul Chote
2015-08-01 20:18:28 +01:00
parent 583b4f92b6
commit 3a8a18499e

View File

@@ -427,7 +427,7 @@ namespace OpenRA.Mods.Common.Widgets
var dy = (int)(previewScale * (uv.V - world.Map.Bounds.Top)); var dy = (int)(previewScale * (uv.V - world.Map.Bounds.Top));
// Odd rows are shifted right by 1px // Odd rows are shifted right by 1px
if ((uv.V & 1) == 1) if (isDiamond && (uv.V & 1) == 1)
dx += 1; dx += 1;
return new int2(mapRect.X + dx, mapRect.Y + dy); return new int2(mapRect.X + dx, mapRect.Y + dy);
@@ -435,10 +435,9 @@ namespace OpenRA.Mods.Common.Widgets
CPos MinimapPixelToCell(int2 p) CPos MinimapPixelToCell(int2 p)
{ {
var viewOrigin = new float2(mapRect.X, mapRect.Y); var u = (int)((p.X - mapRect.X) / (previewScale * cellWidth)) + world.Map.Bounds.Left;
var mapOrigin = new float2(world.Map.Bounds.Left, world.Map.Bounds.Top); var v = (int)((p.Y - mapRect.Y) / previewScale) + world.Map.Bounds.Top;
var fcell = mapOrigin + (1f / previewScale) * (p - viewOrigin); return new MPos(u, v).ToCPos(world.Map);
return new MPos((int)fcell.X / 2, (int)fcell.Y).ToCPos(world.Map);
} }
} }
} }