New types for cell and pixel coordinate position/vectors.
This commit is contained in:
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
|
||||
var mi = new MouseInput
|
||||
{
|
||||
Location = loc,
|
||||
Location = loc.ToInt2(),
|
||||
Button = MouseButton.Right,
|
||||
Modifiers = Game.GetModifierKeys()
|
||||
};
|
||||
@@ -95,7 +95,7 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
|
||||
var loc = MinimapPixelToCell(mi.Location);
|
||||
if ((mi.Event == MouseInputEvent.Down || mi.Event == MouseInputEvent.Move) && mi.Button == MouseButton.Left)
|
||||
Game.viewport.Center(loc);
|
||||
Game.viewport.Center(loc.ToFloat2());
|
||||
|
||||
if (mi.Event == MouseInputEvent.Down && mi.Button == MouseButton.Right)
|
||||
{
|
||||
@@ -105,7 +105,7 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
Event = MouseInputEvent.Down,
|
||||
Button = MouseButton.Right,
|
||||
Modifiers = mi.Modifiers,
|
||||
Location = (loc * Game.CellSize - Game.viewport.Location).ToInt2()
|
||||
Location = (loc.ToPPos().ToFloat2() - Game.viewport.Location).ToInt2()
|
||||
};
|
||||
|
||||
if (WorldInteractionController != null)
|
||||
@@ -141,9 +141,9 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
if (hasRadar && !animating)
|
||||
{
|
||||
var wr = Game.viewport.WorldRect;
|
||||
var wro = new int2(wr.X, wr.Y);
|
||||
var wro = new CPos(wr.X, wr.Y);
|
||||
var tl = CellToMinimapPixel(wro);
|
||||
var br = CellToMinimapPixel(wro + new int2(wr.Width, wr.Height));
|
||||
var br = CellToMinimapPixel(wro + new CVec(wr.Width, wr.Height));
|
||||
|
||||
Game.Renderer.EnableScissor((int)mapRect.Left, (int)mapRect.Top, (int)mapRect.Width, (int)mapRect.Height);
|
||||
Game.Renderer.LineRenderer.DrawRect(tl, br, Color.White);
|
||||
@@ -197,20 +197,20 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
animating = false;
|
||||
}
|
||||
|
||||
int2 CellToMinimapPixel(int2 p)
|
||||
int2 CellToMinimapPixel(CPos p)
|
||||
{
|
||||
var viewOrigin = new float2(mapRect.X, mapRect.Y);
|
||||
var mapOrigin = new float2(world.Map.Bounds.Left, world.Map.Bounds.Top);
|
||||
var mapOrigin = new CPos(world.Map.Bounds.Left, world.Map.Bounds.Top);
|
||||
|
||||
return (viewOrigin + previewScale * (p - mapOrigin)).ToInt2();
|
||||
return (viewOrigin + previewScale * (p - mapOrigin).ToFloat2()).ToInt2();
|
||||
}
|
||||
|
||||
int2 MinimapPixelToCell(int2 p)
|
||||
CPos MinimapPixelToCell(int2 p)
|
||||
{
|
||||
var viewOrigin = new float2(mapRect.X, mapRect.Y);
|
||||
var mapOrigin = new float2(world.Map.Bounds.Left, world.Map.Bounds.Top);
|
||||
var mapOrigin = new CPos(world.Map.Bounds.Left, world.Map.Bounds.Top);
|
||||
|
||||
return (mapOrigin + (1/previewScale) * (p - viewOrigin)).ToInt2();
|
||||
return (CPos)(mapOrigin.ToFloat2() + (1f / previewScale) * (p - viewOrigin)).ToInt2();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user