From 36d59d6b1db3cdfbce02ea4015a10056298abbe8 Mon Sep 17 00:00:00 2001 From: Bynnar18 Date: Tue, 10 Feb 2015 19:48:41 -0600 Subject: [PATCH 1/3] Restored faulty left-click logic for now. --- OpenRA.Game/Game.cs | 2 + OpenRA.Game/Input/InputHandler.cs | 21 +++++ OpenRA.Game/Orders/UnitOrderGenerator.cs | 2 +- OpenRA.Game/Settings.cs | 1 + .../WorldInteractionControllerWidget.cs | 31 ++++++- OpenRA.Mods.Common/Traits/Guard.cs | 2 +- .../Widgets/Logic/SettingsLogic.cs | 2 + .../Widgets/WorldCommandWidget.cs | 2 +- OpenRA.Mods.RA/Traits/Minelayer.cs | 4 +- OpenRA.Mods.RA/Traits/PortableChrono.cs | 2 +- mods/cnc/chrome/settings.yaml | 91 ++++++++++--------- mods/ra/chrome/settings.yaml | 91 ++++++++++--------- 12 files changed, 156 insertions(+), 95 deletions(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index b0e86e3d11..7828e1181d 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -27,6 +27,8 @@ namespace OpenRA { public static class Game { + public static MouseButtonPreference mouseButtonPreference = new MouseButtonPreference(); + public const int NetTickScale = 3; // 120 ms net tick for 40 ms local tick public const int Timestep = 40; public const int TimestepJankThreshold = 250; // Don't catch up for delays larger than 250ms diff --git a/OpenRA.Game/Input/InputHandler.cs b/OpenRA.Game/Input/InputHandler.cs index 79fb87f130..68b5e92cd1 100755 --- a/OpenRA.Game/Input/InputHandler.cs +++ b/OpenRA.Game/Input/InputHandler.cs @@ -49,4 +49,25 @@ namespace OpenRA Sync.CheckSyncUnchanged(world, () => Ui.HandleInput(input)); } } + + public class MouseButtonPreference + { + + public MouseButton Action + { + get + { + return Game.Settings.Game.UseClassicMouseStyle ? MouseButton.Left : MouseButton.Right; + } + } + + + public MouseButton Cancel + { + get + { + return Game.Settings.Game.UseClassicMouseStyle ? MouseButton.Right : MouseButton.Left; + } + } + } } diff --git a/OpenRA.Game/Orders/UnitOrderGenerator.cs b/OpenRA.Game/Orders/UnitOrderGenerator.cs index fe54431119..2515ebce99 100644 --- a/OpenRA.Game/Orders/UnitOrderGenerator.cs +++ b/OpenRA.Game/Orders/UnitOrderGenerator.cs @@ -96,7 +96,7 @@ namespace OpenRA.Orders if (self.Destroyed || !target.IsValidFor(self)) return null; - if (mi.Button == MouseButton.Right) + if (mi.Button == Game.mouseButtonPreference.Action) { foreach (var o in self.TraitsImplementing() .SelectMany(trait => trait.Orders diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index 265166385c..875a64ef5b 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -130,6 +130,7 @@ namespace OpenRA public float ViewportEdgeScrollStep = 10f; public float UIScrollSpeed = 50f; + public bool UseClassicMouseStyle = false; public bool AlwaysShowStatusBars = false; public bool TeamHealthColors = false; diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs index cdf82eab71..d9b7c9d002 100644 --- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs @@ -55,6 +55,9 @@ namespace OpenRA.Widgets public override bool HandleMouseInput(MouseInput mi) { var xy = worldRenderer.Viewport.ViewToWorldPx(mi.Location); + + var useClassicMouseStyle = Game.Settings.Game.UseClassicMouseStyle; + var hasBox = SelectionBox != null; var multiClick = mi.MultiTapCount >= 2; @@ -66,7 +69,8 @@ namespace OpenRA.Widgets dragStart = xy; // place buildings - ApplyOrders(World, xy, mi); + if(!useClassicMouseStyle) + ApplyOrders(World, xy, mi); } if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Move && dragStart.HasValue) @@ -74,6 +78,18 @@ namespace OpenRA.Widgets if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Up) { + if (useClassicMouseStyle && HasMouseFocus) + { + // order units around + if (!hasBox && World.Selection.Actors.Any() && !multiClick) + { + ApplyOrders(World, xy, mi); + YieldMouseFocus(mi); + return true; + } + } + + if (World.OrderGenerator is UnitOrderGenerator) { if (multiClick) @@ -97,9 +113,14 @@ namespace OpenRA.Widgets YieldMouseFocus(mi); } - // don't issue orders while selecting - if (mi.Button == MouseButton.Right && mi.Event == MouseInputEvent.Down && !hasBox) - ApplyOrders(World, xy, mi); + if (mi.Button == MouseButton.Right && mi.Event == MouseInputEvent.Down) + { + if (useClassicMouseStyle) + World.Selection.Clear(); + + if (!hasBox) // don't issue orders while selecting + ApplyOrders(World, xy, mi); + } lastMousePosition = xy; @@ -172,7 +193,7 @@ namespace OpenRA.Widgets var mi = new MouseInput { Location = screenPos, - Button = MouseButton.Right, + Button = Game.mouseButtonPreference.Action, Modifiers = Game.GetModifierKeys() }; diff --git a/OpenRA.Mods.Common/Traits/Guard.cs b/OpenRA.Mods.Common/Traits/Guard.cs index 2e0c4a30f3..b17be9ee3e 100644 --- a/OpenRA.Mods.Common/Traits/Guard.cs +++ b/OpenRA.Mods.Common/Traits/Guard.cs @@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits public IEnumerable Order(World world, CPos xy, MouseInput mi) { - if (mi.Button == MouseButton.Left) + if (mi.Button == Game.mouseButtonPreference.Cancel) { world.CancelInputMode(); yield break; diff --git a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs index 30d15c34e7..9934948cb2 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs @@ -312,6 +312,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var gs = Game.Settings.Game; var ks = Game.Settings.Keys; + BindCheckboxPref(panel, "CLASSICORDERS_CHECKBOX", gs, "UseClassicMouseStyle"); BindCheckboxPref(panel, "EDGESCROLL_CHECKBOX", gs, "ViewportEdgeScroll"); BindCheckboxPref(panel, "LOCKMOUSE_CHECKBOX", gs, "LockMouseWindow"); BindSliderPref(panel, "SCROLLSPEED_SLIDER", gs, "ViewportEdgeScrollStep"); @@ -472,6 +473,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic return () => { + gs.UseClassicMouseStyle = dgs.UseClassicMouseStyle; gs.MouseScroll = dgs.MouseScroll; gs.LockMouseWindow = dgs.LockMouseWindow; gs.ViewportEdgeScroll = dgs.ViewportEdgeScroll; diff --git a/OpenRA.Mods.Common/Widgets/WorldCommandWidget.cs b/OpenRA.Mods.Common/Widgets/WorldCommandWidget.cs index fd9a392925..c1f7fbb2fb 100644 --- a/OpenRA.Mods.Common/Widgets/WorldCommandWidget.cs +++ b/OpenRA.Mods.Common/Widgets/WorldCommandWidget.cs @@ -98,7 +98,7 @@ namespace OpenRA.Mods.Common.Widgets if (actors.Any()) world.OrderGenerator = new GenericSelectTarget(actors, - "AttackMove", "attackmove", MouseButton.Right); + "AttackMove", "attackmove", Game.mouseButtonPreference.Action); return true; } diff --git a/OpenRA.Mods.RA/Traits/Minelayer.cs b/OpenRA.Mods.RA/Traits/Minelayer.cs index 721540a673..a1020e2f7f 100644 --- a/OpenRA.Mods.RA/Traits/Minelayer.cs +++ b/OpenRA.Mods.RA/Traits/Minelayer.cs @@ -146,7 +146,7 @@ namespace OpenRA.Mods.RA.Traits public IEnumerable Order(World world, CPos xy, MouseInput mi) { - if (mi.Button == MouseButton.Left) + if (mi.Button == Game.mouseButtonPreference.Cancel) { world.CancelInputMode(); yield break; @@ -157,7 +157,7 @@ namespace OpenRA.Mods.RA.Traits .MaxByOrDefault(a => a.Info.Traits.Contains() ? a.Info.Traits.Get().Priority : int.MinValue); - if (mi.Button == MouseButton.Right && underCursor == null) + if (mi.Button == Game.mouseButtonPreference.Action && underCursor == null) { minelayer.World.CancelInputMode(); yield return new Order("PlaceMinefield", minelayer, false) { TargetLocation = xy }; diff --git a/OpenRA.Mods.RA/Traits/PortableChrono.cs b/OpenRA.Mods.RA/Traits/PortableChrono.cs index 9d72c6e854..ee845a03d7 100644 --- a/OpenRA.Mods.RA/Traits/PortableChrono.cs +++ b/OpenRA.Mods.RA/Traits/PortableChrono.cs @@ -153,7 +153,7 @@ namespace OpenRA.Mods.RA.Traits public IEnumerable Order(World world, CPos xy, MouseInput mi) { - if (mi.Button == MouseButton.Left) + if (mi.Button == Game.mouseButtonPreference.Cancel) { world.CancelInputMode(); yield break; diff --git a/mods/cnc/chrome/settings.yaml b/mods/cnc/chrome/settings.yaml index 7760764ece..e20b0219f5 100644 --- a/mods/cnc/chrome/settings.yaml +++ b/mods/cnc/chrome/settings.yaml @@ -320,53 +320,16 @@ Container@SETTINGS_PANEL: Font: Bold Text: Input Align: Center - Checkbox@EDGESCROLL_CHECKBOX: + Checkbox@CLASSICORDERS_CHECKBOX: X: 15 Y: 40 - Width: 130 - Height: 20 - Font: Regular - Text: Edge Scrolling - Checkbox@LOCKMOUSE_CHECKBOX: - X: 15 - Y: 70 - Width: 130 - Height: 20 - Font: Regular - Text: Lock mouse to window - Label@SCROLL_SPEED_LABEL: - X: PARENT_RIGHT - WIDTH - 270 - Y: 37 - Width: 95 - Height: 25 - Text: Scroll Speed: - Align: Right - Slider@SCROLLSPEED_SLIDER: - X: PARENT_RIGHT - WIDTH - 15 - Y: 43 Width: 250 Height: 20 - Ticks: 5 - MinimumValue: 10 - MaximumValue: 50 - Label@UI_SCROLL_SPEED_LABEL: - X: PARENT_RIGHT - WIDTH - 270 - Y: 67 - Width: 95 - Height: 25 - Text: UI Scroll Speed: - Align: Right - Slider@UI_SCROLLSPEED_SLIDER: - X: PARENT_RIGHT - WIDTH - 15 - Y: 73 - Width: 250 - Height: 20 - Ticks: 5 - MinimumValue: 1 - MaximumValue: 100 + Font: Regular + Text: Left-Click Orders Label@MOUSE_SCROLL_LABEL: X: PARENT_RIGHT - WIDTH - 120 - Y: 99 + Y: 39 Width: 160 Height: 20 Font: Regular @@ -374,11 +337,55 @@ Container@SETTINGS_PANEL: Align: Right DropDownButton@MOUSE_SCROLL: X: PARENT_RIGHT - WIDTH - 15 - Y: 98 + Y: 38 Width: 100 Height: 25 Font: Regular Text: Enabled + Checkbox@EDGESCROLL_CHECKBOX: + X: 15 + Y: 70 + Width: 130 + Height: 20 + Font: Regular + Text: Edge Scrolling + Checkbox@LOCKMOUSE_CHECKBOX: + X: 15 + Y: 100 + Width: 130 + Height: 20 + Font: Regular + Text: Lock mouse to window + Label@SCROLL_SPEED_LABEL: + X: PARENT_RIGHT - WIDTH - 270 + Y: 67 + Width: 95 + Height: 25 + Text: Scroll Speed: + Align: Right + Slider@SCROLLSPEED_SLIDER: + X: PARENT_RIGHT - WIDTH - 15 + Y: 73 + Width: 250 + Height: 20 + Ticks: 5 + MinimumValue: 10 + MaximumValue: 50 + Label@UI_SCROLL_SPEED_LABEL: + X: PARENT_RIGHT - WIDTH - 270 + Y: 97 + Width: 95 + Height: 25 + Text: UI Scroll Speed: + Align: Right + Slider@UI_SCROLLSPEED_SLIDER: + X: PARENT_RIGHT - WIDTH - 15 + Y: 103 + Width: 250 + Height: 20 + Ticks: 5 + MinimumValue: 1 + MaximumValue: 100 Label@HOTKEYS_TITLE: Y: 135 Width: PARENT_RIGHT diff --git a/mods/ra/chrome/settings.yaml b/mods/ra/chrome/settings.yaml index bc60296a97..846da5cf86 100644 --- a/mods/ra/chrome/settings.yaml +++ b/mods/ra/chrome/settings.yaml @@ -324,53 +324,16 @@ Background@SETTINGS_PANEL: Width: PARENT_RIGHT - 10 Height: PARENT_BOTTOM Children: - Checkbox@EDGESCROLL_CHECKBOX: + Checkbox@CLASSICORDERS_CHECKBOX: X: 15 Y: 40 - Width: 130 - Height: 20 - Font: Regular - Text: Edge Scrolling - Checkbox@LOCKMOUSE_CHECKBOX: - X: 15 - Y: 70 - Width: 130 - Height: 20 - Font: Regular - Text: Lock mouse to window - Label@SCROLL_SPEED_LABEL: - X: PARENT_RIGHT - WIDTH - 270 - Y: 37 - Width: 95 - Height: 25 - Text: Scroll Speed: - Align: Right - Slider@SCROLLSPEED_SLIDER: - X: PARENT_RIGHT - WIDTH - 15 - Y: 43 Width: 250 Height: 20 - Ticks: 5 - MinimumValue: 10 - MaximumValue: 50 - Label@UI_SCROLL_SPEED_LABEL: - X: PARENT_RIGHT - WIDTH - 270 - Y: 67 - Width: 95 - Height: 25 - Text: UI Scroll Speed: - Align: Right - Slider@UI_SCROLLSPEED_SLIDER: - X: PARENT_RIGHT - WIDTH - 15 - Y: 73 - Width: 250 - Height: 20 - Ticks: 5 - MinimumValue: 1 - MaximumValue: 100 + Font: Regular + Text: Left-Click Orders Label@MOUSE_SCROLL_LABEL: X: PARENT_RIGHT - WIDTH - 120 - Y: 99 + Y: 39 Width: 160 Height: 20 Font: Regular @@ -378,11 +341,55 @@ Background@SETTINGS_PANEL: Align: Right DropDownButton@MOUSE_SCROLL: X: PARENT_RIGHT - WIDTH - 15 - Y: 98 + Y: 38 Width: 100 Height: 25 Font: Regular Text: Enabled + Checkbox@EDGESCROLL_CHECKBOX: + X: 15 + Y: 70 + Width: 130 + Height: 20 + Font: Regular + Text: Edge Scrolling + Checkbox@LOCKMOUSE_CHECKBOX: + X: 15 + Y: 100 + Width: 130 + Height: 20 + Font: Regular + Text: Lock mouse to window + Label@SCROLL_SPEED_LABEL: + X: PARENT_RIGHT - WIDTH - 270 + Y: 67 + Width: 95 + Height: 25 + Text: Scroll Speed: + Align: Right + Slider@SCROLLSPEED_SLIDER: + X: PARENT_RIGHT - WIDTH - 15 + Y: 73 + Width: 250 + Height: 20 + Ticks: 5 + MinimumValue: 10 + MaximumValue: 50 + Label@UI_SCROLL_SPEED_LABEL: + X: PARENT_RIGHT - WIDTH - 270 + Y: 97 + Width: 95 + Height: 25 + Text: UI Scroll Speed: + Align: Right + Slider@UI_SCROLLSPEED_SLIDER: + X: PARENT_RIGHT - WIDTH - 15 + Y: 103 + Width: 250 + Height: 20 + Ticks: 5 + MinimumValue: 1 + MaximumValue: 100 Label@HOTKEYS_TITLE: Y: 135 Width: PARENT_RIGHT From 7b46b763294df3f222f5ebcb31de74c5263e3cba Mon Sep 17 00:00:00 2001 From: Bynnar18 Date: Wed, 25 Feb 2015 19:28:32 -0600 Subject: [PATCH 2/3] Fixed left-click orders and implemented a selection deadzone. --- OpenRA.Game/Game.cs | 2 - OpenRA.Game/Input/InputHandler.cs | 2 - OpenRA.Game/Orders/UnitOrderGenerator.cs | 16 ++++- OpenRA.Game/Settings.cs | 2 + .../WorldInteractionControllerWidget.cs | 63 ++++++++++++------- OpenRA.Mods.Common/Traits/Guard.cs | 2 +- .../Widgets/WorldCommandWidget.cs | 2 +- OpenRA.Mods.RA/Traits/Minelayer.cs | 4 +- OpenRA.Mods.RA/Traits/PortableChrono.cs | 2 +- 9 files changed, 63 insertions(+), 32 deletions(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 7828e1181d..b0e86e3d11 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -27,8 +27,6 @@ namespace OpenRA { public static class Game { - public static MouseButtonPreference mouseButtonPreference = new MouseButtonPreference(); - public const int NetTickScale = 3; // 120 ms net tick for 40 ms local tick public const int Timestep = 40; public const int TimestepJankThreshold = 250; // Don't catch up for delays larger than 250ms diff --git a/OpenRA.Game/Input/InputHandler.cs b/OpenRA.Game/Input/InputHandler.cs index 68b5e92cd1..7923978688 100755 --- a/OpenRA.Game/Input/InputHandler.cs +++ b/OpenRA.Game/Input/InputHandler.cs @@ -52,7 +52,6 @@ namespace OpenRA public class MouseButtonPreference { - public MouseButton Action { get @@ -61,7 +60,6 @@ namespace OpenRA } } - public MouseButton Cancel { get diff --git a/OpenRA.Game/Orders/UnitOrderGenerator.cs b/OpenRA.Game/Orders/UnitOrderGenerator.cs index 2515ebce99..0a94727ec0 100644 --- a/OpenRA.Game/Orders/UnitOrderGenerator.cs +++ b/OpenRA.Game/Orders/UnitOrderGenerator.cs @@ -88,6 +88,20 @@ namespace OpenRA.Orders return cursorOrder != null ? cursorOrder.Cursor : (useSelect ? "select" : "default"); } + // Used for classic mouse orders, determines whether or not action at xy is move or select + public static bool InputOverridesSelection(World world, int2 xy, MouseInput mi) + { + var target = Target.FromActor(world.ScreenMap.ActorsAt(xy).WithHighestSelectionPriority()); + var underCursor = world.Selection.Actors.WithHighestSelectionPriority(); + + var o = OrderForUnit(underCursor, target, mi); + + if (o == null || o.Trait is IMove) + return true; + + return false; + } + static UnitOrderResult OrderForUnit(Actor self, Target target, MouseInput mi) { if (self.Owner != self.World.LocalPlayer) @@ -96,7 +110,7 @@ namespace OpenRA.Orders if (self.Destroyed || !target.IsValidFor(self)) return null; - if (mi.Button == Game.mouseButtonPreference.Action) + if (mi.Button == Game.Settings.Game.MouseButtonPreference.Action) { foreach (var o in self.TraitsImplementing() .SelectMany(trait => trait.Orders diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index 875a64ef5b..8e29368030 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -127,8 +127,10 @@ namespace OpenRA public bool ViewportEdgeScroll = true; public bool LockMouseWindow = false; public MouseScrollType MouseScroll = MouseScrollType.Standard; + public MouseButtonPreference MouseButtonPreference = new MouseButtonPreference(); public float ViewportEdgeScrollStep = 10f; public float UIScrollSpeed = 50f; + public int SelectionDeadzone = 24; public bool UseClassicMouseStyle = false; public bool AlwaysShowStatusBars = false; diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs index d9b7c9d002..bd9f61814c 100644 --- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs @@ -40,7 +40,7 @@ namespace OpenRA.Widgets { if (!IsDragging) { - foreach (var u in SelectActorsInBox(World, lastMousePosition, lastMousePosition, _ => true)) + foreach (var u in SelectActorsInBoxWithDeadzone(World, lastMousePosition, lastMousePosition, _ => true)) worldRenderer.DrawRollover(u); return; @@ -48,7 +48,7 @@ namespace OpenRA.Widgets var selbox = SelectionBox; Game.Renderer.WorldLineRenderer.DrawRect(selbox.Value.First.ToFloat2(), selbox.Value.Second.ToFloat2(), Color.White); - foreach (var u in SelectActorsInBox(World, selbox.Value.First, selbox.Value.Second, _ => true)) + foreach (var u in SelectActorsInBoxWithDeadzone(World, selbox.Value.First, selbox.Value.Second, _ => true)) worldRenderer.DrawRollover(u); } @@ -68,8 +68,8 @@ namespace OpenRA.Widgets dragStart = xy; - // place buildings - if(!useClassicMouseStyle) + // Place buildings + if (!useClassicMouseStyle || !World.Selection.Actors.Any()) ApplyOrders(World, xy, mi); } @@ -78,20 +78,26 @@ namespace OpenRA.Widgets if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Up) { - if (useClassicMouseStyle && HasMouseFocus) - { - // order units around - if (!hasBox && World.Selection.Actors.Any() && !multiClick) - { - ApplyOrders(World, xy, mi); - YieldMouseFocus(mi); - return true; - } - } - - if (World.OrderGenerator is UnitOrderGenerator) { + if (useClassicMouseStyle && HasMouseFocus) + { + if (!hasBox && World.Selection.Actors.Any() && !multiClick) + { + if (!(World.ScreenMap.ActorsAt(xy).Where(x => x.HasTrait() && x.Trait().Info.Selectable && + (x.Owner.IsAlliedWith(World.RenderPlayer) || !World.FogObscures(x))).Any() && !mi.Modifiers.HasModifier(Modifiers.Ctrl) && + !mi.Modifiers.HasModifier(Modifiers.Alt) && UnitOrderGenerator.InputOverridesSelection(World, xy, mi))) + { + // Order units instead of selecting + ApplyOrders(World, xy, mi); + dragStart = dragEnd = null; + YieldMouseFocus(mi); + lastMousePosition = xy; + return true; + } + } + } + if (multiClick) { var unit = World.ScreenMap.ActorsAt(xy) @@ -104,10 +110,12 @@ namespace OpenRA.Widgets } else if (dragStart.HasValue) { - var newSelection = SelectActorsInBox(World, dragStart.Value, xy, _ => true); + var newSelection = SelectActorsInBoxWithDeadzone(World, dragStart.Value, xy, _ => true); World.Selection.Combine(World, newSelection, mi.Modifiers.HasModifier(Modifiers.Shift), dragStart == xy); } } + else if (useClassicMouseStyle) + ApplyOrders(World, xy, mi); dragStart = dragEnd = null; YieldMouseFocus(mi); @@ -115,11 +123,14 @@ namespace OpenRA.Widgets if (mi.Button == MouseButton.Right && mi.Event == MouseInputEvent.Down) { - if (useClassicMouseStyle) - World.Selection.Clear(); + // Don't do anything while selecting + if (!hasBox) + { + if (useClassicMouseStyle) + World.Selection.Clear(); - if (!hasBox) // don't issue orders while selecting ApplyOrders(World, xy, mi); + } } lastMousePosition = xy; @@ -131,7 +142,7 @@ namespace OpenRA.Widgets { get { - return dragStart.HasValue && dragEnd.HasValue; + return dragStart.HasValue && dragEnd.HasValue && (dragStart.Value - dragEnd.Value).Length > Game.Settings.Game.SelectionDeadzone; } } @@ -193,7 +204,7 @@ namespace OpenRA.Widgets var mi = new MouseInput { Location = screenPos, - Button = Game.mouseButtonPreference.Action, + Button = Game.Settings.Game.MouseButtonPreference.Action, Modifiers = Game.GetModifierKeys() }; @@ -245,6 +256,14 @@ namespace OpenRA.Widgets return false; } + static IEnumerable SelectActorsInBoxWithDeadzone(World world, int2 a, int2 b, Func cond) + { + if (a == b || (a - b).Length > Game.Settings.Game.SelectionDeadzone) + return SelectActorsInBox(world, a, b, cond); + else + return SelectActorsInBox(world, b, b, cond); + } + static IEnumerable SelectActorsInBox(World world, int2 a, int2 b, Func cond) { return world.ScreenMap.ActorsInBox(a, b) diff --git a/OpenRA.Mods.Common/Traits/Guard.cs b/OpenRA.Mods.Common/Traits/Guard.cs index b17be9ee3e..0c856daec6 100644 --- a/OpenRA.Mods.Common/Traits/Guard.cs +++ b/OpenRA.Mods.Common/Traits/Guard.cs @@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits public IEnumerable Order(World world, CPos xy, MouseInput mi) { - if (mi.Button == Game.mouseButtonPreference.Cancel) + if (mi.Button == Game.Settings.Game.MouseButtonPreference.Cancel) { world.CancelInputMode(); yield break; diff --git a/OpenRA.Mods.Common/Widgets/WorldCommandWidget.cs b/OpenRA.Mods.Common/Widgets/WorldCommandWidget.cs index c1f7fbb2fb..b40633b46f 100644 --- a/OpenRA.Mods.Common/Widgets/WorldCommandWidget.cs +++ b/OpenRA.Mods.Common/Widgets/WorldCommandWidget.cs @@ -98,7 +98,7 @@ namespace OpenRA.Mods.Common.Widgets if (actors.Any()) world.OrderGenerator = new GenericSelectTarget(actors, - "AttackMove", "attackmove", Game.mouseButtonPreference.Action); + "AttackMove", "attackmove", Game.Settings.Game.MouseButtonPreference.Action); return true; } diff --git a/OpenRA.Mods.RA/Traits/Minelayer.cs b/OpenRA.Mods.RA/Traits/Minelayer.cs index a1020e2f7f..706cebe9cc 100644 --- a/OpenRA.Mods.RA/Traits/Minelayer.cs +++ b/OpenRA.Mods.RA/Traits/Minelayer.cs @@ -146,7 +146,7 @@ namespace OpenRA.Mods.RA.Traits public IEnumerable Order(World world, CPos xy, MouseInput mi) { - if (mi.Button == Game.mouseButtonPreference.Cancel) + if (mi.Button == Game.Settings.Game.MouseButtonPreference.Cancel) { world.CancelInputMode(); yield break; @@ -157,7 +157,7 @@ namespace OpenRA.Mods.RA.Traits .MaxByOrDefault(a => a.Info.Traits.Contains() ? a.Info.Traits.Get().Priority : int.MinValue); - if (mi.Button == Game.mouseButtonPreference.Action && underCursor == null) + if (mi.Button == Game.Settings.Game.MouseButtonPreference.Action && underCursor == null) { minelayer.World.CancelInputMode(); yield return new Order("PlaceMinefield", minelayer, false) { TargetLocation = xy }; diff --git a/OpenRA.Mods.RA/Traits/PortableChrono.cs b/OpenRA.Mods.RA/Traits/PortableChrono.cs index ee845a03d7..510d74f8d5 100644 --- a/OpenRA.Mods.RA/Traits/PortableChrono.cs +++ b/OpenRA.Mods.RA/Traits/PortableChrono.cs @@ -153,7 +153,7 @@ namespace OpenRA.Mods.RA.Traits public IEnumerable Order(World world, CPos xy, MouseInput mi) { - if (mi.Button == Game.mouseButtonPreference.Cancel) + if (mi.Button == Game.Settings.Game.MouseButtonPreference.Cancel) { world.CancelInputMode(); yield break; From 0abe8f9b2b0d10a6cabe9b6e9bbb3939f7029461 Mon Sep 17 00:00:00 2001 From: Bynnar18 Date: Sat, 28 Feb 2015 15:49:15 -0600 Subject: [PATCH 3/3] Fixes issues with support powers and adds property to all IOrderGenerator classes to determine priority over selection in the left-click order scheme. --- OpenRA.Game/Orders/UnitOrderGenerator.cs | 6 +++--- OpenRA.Game/Traits/TraitsInterfaces.cs | 1 + .../Widgets/WorldInteractionControllerWidget.cs | 12 ++++++++---- .../Traits/SupportPowers/IonCannonPower.cs | 4 ++++ OpenRA.Mods.Common/Orders/DeployOrderTargeter.cs | 1 + .../Orders/PlaceBuildingOrderGenerator.cs | 4 ++++ OpenRA.Mods.Common/Orders/UnitOrderTargeter.cs | 1 + OpenRA.Mods.Common/Traits/Air/Aircraft.cs | 1 + OpenRA.Mods.Common/Traits/Attack/AttackBase.cs | 1 + OpenRA.Mods.Common/Traits/Buildings/RallyPoint.cs | 1 + OpenRA.Mods.Common/Traits/Harvester.cs | 1 + OpenRA.Mods.Common/Traits/Mobile.cs | 1 + .../Traits/SupportPowers/GrantUpgradePower.cs | 4 ++++ .../Traits/SupportPowers/SupportPowerManager.cs | 4 ++++ OpenRA.Mods.RA/Traits/Minelayer.cs | 1 + OpenRA.Mods.RA/Traits/PortableChrono.cs | 1 + .../Traits/SupportPowers/ChronoshiftPower.cs | 4 ++++ 17 files changed, 41 insertions(+), 7 deletions(-) diff --git a/OpenRA.Game/Orders/UnitOrderGenerator.cs b/OpenRA.Game/Orders/UnitOrderGenerator.cs index 0a94727ec0..6095444fec 100644 --- a/OpenRA.Game/Orders/UnitOrderGenerator.cs +++ b/OpenRA.Game/Orders/UnitOrderGenerator.cs @@ -96,10 +96,10 @@ namespace OpenRA.Orders var o = OrderForUnit(underCursor, target, mi); - if (o == null || o.Trait is IMove) - return true; + if (o != null && o.Order.OverrideSelection) + return false; - return false; + return true; } static UnitOrderResult OrderForUnit(Actor self, Target target, MouseInput mi) diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index fd0091d7ba..9edb9b8932 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -79,6 +79,7 @@ namespace OpenRA.Traits int OrderPriority { get; } bool CanTarget(Actor self, Target target, List othersAtTarget, TargetModifiers modifiers, ref string cursor); bool IsQueued { get; } + bool OverrideSelection { get; } } public interface IResolveOrder { void ResolveOrder(Actor self, Order order); } diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs index bd9f61814c..c6ec62f6fc 100644 --- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs @@ -68,9 +68,15 @@ namespace OpenRA.Widgets dragStart = xy; - // Place buildings - if (!useClassicMouseStyle || !World.Selection.Actors.Any()) + // Place buildings, use support powers, and other non-unit things + if (!(World.OrderGenerator is UnitOrderGenerator)) + { ApplyOrders(World, xy, mi); + dragStart = dragEnd = null; + YieldMouseFocus(mi); + lastMousePosition = xy; + return true; + } } if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Move && dragStart.HasValue) @@ -114,8 +120,6 @@ namespace OpenRA.Widgets World.Selection.Combine(World, newSelection, mi.Modifiers.HasModifier(Modifiers.Shift), dragStart == xy); } } - else if (useClassicMouseStyle) - ApplyOrders(World, xy, mi); dragStart = dragEnd = null; YieldMouseFocus(mi); diff --git a/OpenRA.Mods.Cnc/Traits/SupportPowers/IonCannonPower.cs b/OpenRA.Mods.Cnc/Traits/SupportPowers/IonCannonPower.cs index 567f41baeb..b7c9af5e59 100644 --- a/OpenRA.Mods.Cnc/Traits/SupportPowers/IonCannonPower.cs +++ b/OpenRA.Mods.Cnc/Traits/SupportPowers/IonCannonPower.cs @@ -45,6 +45,10 @@ namespace OpenRA.Mods.Cnc.Traits public override IOrderGenerator OrderGenerator(string order, SupportPowerManager manager) { + // Clear selection if using Left-Click Orders + if (Game.Settings.Game.UseClassicMouseStyle) + manager.Self.World.Selection.Clear(); + Sound.PlayToPlayer(manager.Self.Owner, Info.SelectTargetSound); var info = Info as IonCannonPowerInfo; return new SelectGenericPowerTarget(order, manager, info.Cursor, MouseButton.Left); diff --git a/OpenRA.Mods.Common/Orders/DeployOrderTargeter.cs b/OpenRA.Mods.Common/Orders/DeployOrderTargeter.cs index 605c017ee8..5450883ed4 100644 --- a/OpenRA.Mods.Common/Orders/DeployOrderTargeter.cs +++ b/OpenRA.Mods.Common/Orders/DeployOrderTargeter.cs @@ -32,6 +32,7 @@ namespace OpenRA.Mods.Common.Orders public string OrderID { get; private set; } public int OrderPriority { get; private set; } + public bool OverrideSelection { get { return true; } } public bool CanTarget(Actor self, Target target, List othersAtTarget, TargetModifiers modifiers, ref string cursor) { diff --git a/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs index 606a00accd..b4571b498e 100644 --- a/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs @@ -34,6 +34,10 @@ namespace OpenRA.Mods.Common.Orders producer = queue.Actor; building = name; + // Clear selection if using Left-Click Orders + if (Game.Settings.Game.UseClassicMouseStyle) + producer.World.Selection.Clear(); + var map = producer.World.Map; var tileset = producer.World.TileSet.Id.ToLowerInvariant(); buildingInfo = map.Rules.Actors[building].Traits.Get(); diff --git a/OpenRA.Mods.Common/Orders/UnitOrderTargeter.cs b/OpenRA.Mods.Common/Orders/UnitOrderTargeter.cs index 02bcb33995..13ac615446 100644 --- a/OpenRA.Mods.Common/Orders/UnitOrderTargeter.cs +++ b/OpenRA.Mods.Common/Orders/UnitOrderTargeter.cs @@ -31,6 +31,7 @@ namespace OpenRA.Mods.Common.Orders public string OrderID { get; private set; } public int OrderPriority { get; private set; } public bool? ForceAttack = null; + public bool OverrideSelection { get { return true; } } public abstract bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor); public abstract bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor); diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index 9adb07ed5e..bf679bed0e 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -302,6 +302,7 @@ namespace OpenRA.Mods.Common.Traits { public string OrderID { get { return "Move"; } } public int OrderPriority { get { return 4; } } + public bool OverrideSelection { get { return false; } } readonly AircraftInfo info; diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs index 6f53c583ad..d91c486af3 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs @@ -194,6 +194,7 @@ namespace OpenRA.Mods.Common.Traits public string OrderID { get; private set; } public int OrderPriority { get; private set; } + public bool OverrideSelection { get { return true; } } bool CanTargetActor(Actor self, Target target, TargetModifiers modifiers, ref string cursor) { diff --git a/OpenRA.Mods.Common/Traits/Buildings/RallyPoint.cs b/OpenRA.Mods.Common/Traits/Buildings/RallyPoint.cs index 40bb681cc0..98e65ccea0 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/RallyPoint.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/RallyPoint.cs @@ -56,6 +56,7 @@ namespace OpenRA.Mods.Common.Traits { public string OrderID { get { return "SetRallyPoint"; } } public int OrderPriority { get { return 0; } } + public bool OverrideSelection { get { return true; } } public bool CanTarget(Actor self, Target target, List othersAtTarget, TargetModifiers modifiers, ref string cursor) { diff --git a/OpenRA.Mods.Common/Traits/Harvester.cs b/OpenRA.Mods.Common/Traits/Harvester.cs index 568d36e1c0..42e672e4ea 100644 --- a/OpenRA.Mods.Common/Traits/Harvester.cs +++ b/OpenRA.Mods.Common/Traits/Harvester.cs @@ -445,6 +445,7 @@ namespace OpenRA.Mods.Common.Traits public string OrderID { get { return "Harvest"; } } public int OrderPriority { get { return 10; } } public bool IsQueued { get; protected set; } + public bool OverrideSelection { get { return true; } } public bool CanTarget(Actor self, Target target, List othersAtTarget, TargetModifiers modifiers, ref string cursor) { diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs index 64e520218d..fd50b2b4bc 100644 --- a/OpenRA.Mods.Common/Traits/Mobile.cs +++ b/OpenRA.Mods.Common/Traits/Mobile.cs @@ -619,6 +619,7 @@ namespace OpenRA.Mods.Common.Traits { readonly MobileInfo unitType; readonly bool rejectMove; + public bool OverrideSelection { get { return false; } } public MoveOrderTargeter(Actor self, MobileInfo unitType) { diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/GrantUpgradePower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/GrantUpgradePower.cs index 71eeb15d39..76080d3239 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/GrantUpgradePower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/GrantUpgradePower.cs @@ -102,6 +102,10 @@ namespace OpenRA.Mods.Common.Traits public SelectTarget(World world, string order, SupportPowerManager manager, GrantUpgradePower power) { + // Clear selection if using Left-Click Orders + if (Game.Settings.Game.UseClassicMouseStyle) + manager.Self.World.Selection.Clear(); + this.manager = manager; this.order = order; this.power = power; diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs index 85f123158e..395833905e 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs @@ -239,6 +239,10 @@ namespace OpenRA.Mods.Common.Traits public SelectGenericPowerTarget(string order, SupportPowerManager manager, string cursor, MouseButton button) { + // Clear selection if using Left-Click Orders + if (Game.Settings.Game.UseClassicMouseStyle) + manager.Self.World.Selection.Clear(); + this.manager = manager; this.order = order; this.cursor = cursor; diff --git a/OpenRA.Mods.RA/Traits/Minelayer.cs b/OpenRA.Mods.RA/Traits/Minelayer.cs index 706cebe9cc..fda7ea187b 100644 --- a/OpenRA.Mods.RA/Traits/Minelayer.cs +++ b/OpenRA.Mods.RA/Traits/Minelayer.cs @@ -197,6 +197,7 @@ namespace OpenRA.Mods.RA.Traits { public string OrderID { get { return "BeginMinefield"; } } public int OrderPriority { get { return 5; } } + public bool OverrideSelection { get { return true; } } public bool CanTarget(Actor self, Target target, List othersAtTarget, TargetModifiers modifiers, ref string cursor) { diff --git a/OpenRA.Mods.RA/Traits/PortableChrono.cs b/OpenRA.Mods.RA/Traits/PortableChrono.cs index 510d74f8d5..5c7328f66a 100644 --- a/OpenRA.Mods.RA/Traits/PortableChrono.cs +++ b/OpenRA.Mods.RA/Traits/PortableChrono.cs @@ -119,6 +119,7 @@ namespace OpenRA.Mods.RA.Traits public string OrderID { get { return "PortableChronoTeleport"; } } public int OrderPriority { get { return 5; } } public bool IsQueued { get; protected set; } + public bool OverrideSelection { get { return true; } } public bool CanTarget(Actor self, Target target, List othersAtTarget, TargetModifiers modifiers, ref string cursor) { diff --git a/OpenRA.Mods.RA/Traits/SupportPowers/ChronoshiftPower.cs b/OpenRA.Mods.RA/Traits/SupportPowers/ChronoshiftPower.cs index da1481c69d..ea433fbbdc 100644 --- a/OpenRA.Mods.RA/Traits/SupportPowers/ChronoshiftPower.cs +++ b/OpenRA.Mods.RA/Traits/SupportPowers/ChronoshiftPower.cs @@ -101,6 +101,10 @@ namespace OpenRA.Mods.RA.Traits public SelectTarget(World world, string order, SupportPowerManager manager, ChronoshiftPower power) { + // Clear selection if using Left-Click Orders + if (Game.Settings.Game.UseClassicMouseStyle) + manager.Self.World.Selection.Clear(); + this.manager = manager; this.order = order; this.power = power;