New types for cell and pixel coordinate position/vectors.

This commit is contained in:
James Dunne
2012-06-20 23:22:27 -05:00
parent 0b98a8ce5e
commit 9c49143534
162 changed files with 1291 additions and 865 deletions

View File

@@ -141,8 +141,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
if (p.World.LobbyInfo.GlobalSettings.LockTeams)
return; // team changes are banned
// NOTE(jsd): Abuse of the type system here with `CPos`
world.IssueOrder(new Order("SetStance", world.LocalPlayer.PlayerActor, false)
{ TargetLocation = new int2((int)ss, 0), TargetString = p.InternalName });
{ TargetLocation = new CPos((int)ss, 0), TargetString = p.InternalName });
bw.Text = ss.ToString();
}

View File

@@ -77,7 +77,7 @@ namespace OpenRA.Mods.RA.Widgets
var mi = new MouseInput
{
Location = loc,
Location = loc.ToInt2(),
Button = MouseButton.Right,
Modifiers = Game.GetModifierKeys()
};
@@ -98,7 +98,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)
{
@@ -108,7 +108,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)
@@ -154,9 +154,9 @@ namespace OpenRA.Mods.RA.Widgets
if (radarAnimationFrame == radarSlideAnimationLength + radarActivateAnimationLength)
{
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);
@@ -220,14 +220,14 @@ namespace OpenRA.Mods.RA.Widgets
radarAnimating = false;
}
int2 CellToMinimapPixel(int2 p)
int2 CellToMinimapPixel(CPos p)
{
return new int2((int)(mapRect.X +previewScale*(p.X - world.Map.Bounds.Left)), (int)(mapRect.Y + previewScale*(p.Y - world.Map.Bounds.Top)));
}
int2 MinimapPixelToCell(int2 p)
CPos MinimapPixelToCell(int2 p)
{
return new int2(world.Map.Bounds.Left + (int)((p.X - mapRect.X)/previewScale), world.Map.Bounds.Top + (int)((p.Y - mapRect.Y)/previewScale));
return new CPos(world.Map.Bounds.Left + (int)((p.X - mapRect.X) / previewScale), world.Map.Bounds.Top + (int)((p.Y - mapRect.Y) / previewScale));
}
}
}

View File

@@ -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();
}
}
}

View File

@@ -140,7 +140,8 @@ namespace OpenRA.Mods.RA.Widgets
{
var at = a.TraitOrDefault<AutoTarget>();
if (at != null) at.predictedStance = nextStance;
return new Order("SetUnitStance", a, false) { TargetLocation = new int2((int)nextStance, 0) };
// NOTE(jsd): Abuse of the type system here with `CPos`
return new Order("SetUnitStance", a, false) { TargetLocation = new CPos((int)nextStance, 0) };
});
Game.Debug( "Unit stance set to: {0}".F(nextStance) );
@@ -180,7 +181,7 @@ namespace OpenRA.Mods.RA.Widgets
if (eventNotifier.lastAttackTime < 0)
return true;
Game.viewport.Center(eventNotifier.lastAttackLocation);
Game.viewport.Center(eventNotifier.lastAttackLocation.ToFloat2());
return true;
}
}

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Widgets
if (Viewport.TicksSinceLastMove < TooltipDelay || world == null)
return;
var cell = Game.viewport.ViewToWorld(Viewport.LastMousePos).ToInt2();
var cell = Game.viewport.ViewToWorld(Viewport.LastMousePos);
if (!world.Map.IsInMap(cell)) return;
if (world.LocalPlayer != null && !world.LocalPlayer.Shroud.IsExplored(cell))