diff --git a/OpenRA.Game/Controller.cs b/OpenRA.Game/Controller.cs index f1c8ac60c1..2816a62cd4 100644 --- a/OpenRA.Game/Controller.cs +++ b/OpenRA.Game/Controller.cs @@ -70,11 +70,5 @@ namespace OpenRA return Pair.New(Game.CellSize * dragStart, Game.CellSize * dragEnd); } } - - public float2 MousePosition { get { return dragEnd; } } - Modifiers modifiers; - - public void SetModifiers(Modifiers mods) { modifiers = mods; } - public Modifiers GetModifiers() { return modifiers; } } } diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 6b76243d02..11fd8fd5fc 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -456,10 +456,9 @@ namespace OpenRA throw new InvalidOperationException("Desync in OnKeyPress"); } - public static void HandleModifierKeys(Modifiers mods) - { - controller.SetModifiers(mods); - } + static Modifiers modifiers; + public static Modifiers GetModifierKeys() { return modifiers; } + public static void HandleModifierKeys(Modifiers mods) { modifiers = mods; } static Size GetResolution(Settings settings, WindowMode windowmode) { diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index 014d2d28cf..e6ef9c7947 100644 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -78,9 +78,13 @@ namespace OpenRA.Graphics cursorFrame += 0.5f; } + public float2 ViewToWorld(int2 loc) + { + return (1f / Game.CellSize) * (loc.ToFloat2() + Location); + } public float2 ViewToWorld(MouseInput mi) { - return (1f / Game.CellSize) * (new float2(mi.Location.X, mi.Location.Y) + Location); + return ViewToWorld(mi.Location); } public void Center(int2 loc) diff --git a/OpenRA.Game/UiOverlay.cs b/OpenRA.Game/UiOverlay.cs index 796a6eaff9..1c3b65f96b 100644 --- a/OpenRA.Game/UiOverlay.cs +++ b/OpenRA.Game/UiOverlay.cs @@ -14,6 +14,7 @@ using System.Linq; using OpenRA.GameRules; using OpenRA.Graphics; using OpenRA.Traits; +using OpenRA.Widgets; namespace OpenRA { @@ -54,7 +55,7 @@ namespace OpenRA public void DrawBuildingGrid( World world, string name, BuildingInfo bi ) { - var position = Game.controller.MousePosition.ToInt2(); + var position = Game.viewport.ViewToWorld(Widget.LastMousePos).ToInt2(); var topLeft = position - Footprint.AdjustForBuildingSize( bi ); // Linebuild for walls. diff --git a/OpenRA.Game/Widgets/BuildPaletteWidget.cs b/OpenRA.Game/Widgets/BuildPaletteWidget.cs index 26c883e248..442e5d4145 100644 --- a/OpenRA.Game/Widgets/BuildPaletteWidget.cs +++ b/OpenRA.Game/Widgets/BuildPaletteWidget.cs @@ -387,7 +387,7 @@ namespace OpenRA.Widgets Sound.Play(unit.Traits.Contains() ? eva.BuildingSelectAudio : eva.UnitSelectAudio); Game.IssueOrder(Order.StartProduction(world.LocalPlayer, item, - Game.controller.GetModifiers().HasModifier(Modifiers.Shift) ? 5 : 1)); + Game.GetModifierKeys().HasModifier(Modifiers.Shift) ? 5 : 1)); } static Dictionary CategoryNameRemaps = new Dictionary diff --git a/OpenRA.Game/Widgets/DefaultInputControllerWidget.cs b/OpenRA.Game/Widgets/DefaultInputControllerWidget.cs index 6b5ee831a7..e300401204 100644 --- a/OpenRA.Game/Widgets/DefaultInputControllerWidget.cs +++ b/OpenRA.Game/Widgets/DefaultInputControllerWidget.cs @@ -82,7 +82,7 @@ namespace OpenRA.Widgets { Location = pos, Button = MouseButton.Right, - Modifiers = Game.controller.GetModifiers() + Modifiers = Game.GetModifierKeys() }; return Game.controller.orderGenerator.GetCursor( world, Game.viewport.ViewToWorld(mi).ToInt2(), mi ); diff --git a/OpenRA.Game/Widgets/RadarBinWidget.cs b/OpenRA.Game/Widgets/RadarBinWidget.cs index eccdcc56d4..e10a6b514e 100644 --- a/OpenRA.Game/Widgets/RadarBinWidget.cs +++ b/OpenRA.Game/Widgets/RadarBinWidget.cs @@ -71,7 +71,7 @@ namespace OpenRA.Widgets { Location = loc, Button = MouseButton.Right, - Modifiers = Game.controller.GetModifiers() + Modifiers = Game.GetModifierKeys() }; var cursor = Game.controller.orderGenerator.GetCursor( world, loc, mi );