From c0a702a386cf6482704010c867ffb80a4bdd7a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 2 Mar 2013 11:53:45 +0100 Subject: [PATCH 1/4] new hotkey to center your view on the current selection --- OpenRA.Game/GameRules/Settings.cs | 3 ++- .../Widgets/Logic/SettingsMenuLogic.cs | 6 +++++- OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs | 19 ++++++++++++++----- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/OpenRA.Game/GameRules/Settings.cs b/OpenRA.Game/GameRules/Settings.cs index bb8d3fc0ed..a0b6b7793e 100644 --- a/OpenRA.Game/GameRules/Settings.cs +++ b/OpenRA.Game/GameRules/Settings.cs @@ -125,7 +125,8 @@ namespace OpenRA.GameRules public string PauseKey = "f3"; public string CycleBaseKey = "backspace"; - public string GotoLastEventKey = "space"; + public string ToLastEventKey = "space"; + public string ToSelectionKey = "home"; public string SellKey = "v"; public string PowerDownKey = "b"; public string RepairKey = "n"; diff --git a/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs index 5846ddd6ce..37a4b443af 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/SettingsMenuLogic.cs @@ -137,9 +137,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic specialHotkeyList.AddChild(viewportToBase); var lastEventKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); - SetupKeyBinding(lastEventKey, "Move Viewport to Last Event:", () => keyConfig.GotoLastEventKey, k => keyConfig.GotoLastEventKey = k); + SetupKeyBinding(lastEventKey, "Move Viewport to Last Event:", () => keyConfig.ToLastEventKey, k => keyConfig.ToLastEventKey = k); specialHotkeyList.AddChild(lastEventKey); + var viewportToSelectionKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); + SetupKeyBinding(viewportToSelectionKey, "Move Viewport to Selection:", () => keyConfig.ToSelectionKey, k => keyConfig.ToSelectionKey = k); + specialHotkeyList.AddChild(viewportToSelectionKey); + var sellKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {}); SetupKeyBinding(sellKey, "Switch to Sell-Cursor:", () => keyConfig.SellKey, k => keyConfig.SellKey = k); specialHotkeyList.AddChild(sellKey); diff --git a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs index b40b9f6890..1aea04de56 100644 --- a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs +++ b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs @@ -47,8 +47,11 @@ namespace OpenRA.Mods.RA.Widgets if (e.KeyName == Game.Settings.Keys.CycleBaseKey) return CycleBases(); - if (e.KeyName == Game.Settings.Keys.GotoLastEventKey) - return GotoLastEvent(); + if (e.KeyName == Game.Settings.Keys.ToLastEventKey) + return ToLastEvent(); + + if (e.KeyName == Game.Settings.Keys.ToSelectionKey) + return ToSelection(); if (e.KeyName == Game.Settings.Keys.SellKey) return PerformSwitchToSellMode(); @@ -168,11 +171,11 @@ namespace OpenRA.Mods.RA.Widgets next = bases.Select(b => b.Actor).First(); World.Selection.Combine(World, new Actor[] { next }, false, true); - Game.viewport.Center(World.Selection.Actors); - return true; + + return ToSelection(); } - bool GotoLastEvent() + bool ToLastEvent() { if (World.LocalPlayer == null) return true; @@ -188,6 +191,12 @@ namespace OpenRA.Mods.RA.Widgets return true; } + bool ToSelection() + { + Game.viewport.Center(World.Selection.Actors); + return true; + } + bool PerformSwitchToSellMode() { World.ToggleInputMode(); From 1083f8cf553235fe9ac9e51a337afda3bb0483fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 2 Mar 2013 15:51:35 +0100 Subject: [PATCH 2/4] double-tap 0-9: select and center the control group --- OpenRA.Game/Selection.cs | 4 ++-- OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/OpenRA.Game/Selection.cs b/OpenRA.Game/Selection.cs index 34ffd57939..72c12ae85e 100644 --- a/OpenRA.Game/Selection.cs +++ b/OpenRA.Game/Selection.cs @@ -64,7 +64,7 @@ namespace OpenRA Cache> controlGroups = new Cache>(_ => new List()); - public void DoControlGroup(World world, int group, Modifiers mods) + public void DoControlGroup(World world, int group, Modifiers mods, int MultiTapCount) { var addModifier = Platform.CurrentPlatform == PlatformType.OSX ? Modifiers.Meta : Modifiers.Ctrl; if (mods.HasModifier(addModifier)) @@ -82,7 +82,7 @@ namespace OpenRA return; } - if (mods.HasModifier(Modifiers.Alt)) + if (mods.HasModifier(Modifiers.Alt) || MultiTapCount >= 2) { Game.viewport.Center(controlGroups[group]); return; diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs index de7dc03c7b..fa3d6a95fc 100644 --- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs @@ -171,7 +171,7 @@ namespace OpenRA.Widgets { if (e.KeyName.Length == 1 && char.IsDigit(e.KeyName[0])) { - world.Selection.DoControlGroup(world, e.KeyName[0] - '0', e.Modifiers); + world.Selection.DoControlGroup(world, e.KeyName[0] - '0', e.Modifiers, e.MultiTapCount); return true; } else if (e.KeyName == "pause" || e.KeyName == "f3") From 775b0409c4e124869c84469b5a4d3aba9b019f3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 2 Mar 2013 15:56:13 +0100 Subject: [PATCH 3/4] don't hard-code the pause-key --- OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs index fa3d6a95fc..1cebd7be69 100644 --- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs @@ -174,7 +174,7 @@ namespace OpenRA.Widgets world.Selection.DoControlGroup(world, e.KeyName[0] - '0', e.Modifiers, e.MultiTapCount); return true; } - else if (e.KeyName == "pause" || e.KeyName == "f3") + else if (e.KeyName == Game.Settings.Keys.PauseKey) { world.IssueOrder(Order.PauseRequest()); } From 0978d21439d74f58e45fb9e03228ddf295647461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 2 Mar 2013 16:51:36 +0100 Subject: [PATCH 4/4] fix problems in MultiTapDetection --- OpenRA.Game/Selection.cs | 2 +- OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs | 2 +- .../MultiTapDetection.cs | 21 ++++++++++++++++++- OpenRA.Renderer.SdlCommon/SdlInput.cs | 20 ++++++++++++------ 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/OpenRA.Game/Selection.cs b/OpenRA.Game/Selection.cs index 72c12ae85e..a248a61142 100644 --- a/OpenRA.Game/Selection.cs +++ b/OpenRA.Game/Selection.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, diff --git a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs index 1aea04de56..7e181fb528 100644 --- a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs +++ b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, diff --git a/OpenRA.Renderer.SdlCommon/MultiTapDetection.cs b/OpenRA.Renderer.SdlCommon/MultiTapDetection.cs index a9408533bc..75255e03e7 100644 --- a/OpenRA.Renderer.SdlCommon/MultiTapDetection.cs +++ b/OpenRA.Renderer.SdlCommon/MultiTapDetection.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2013 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation. For more information, @@ -25,11 +25,23 @@ public static class MultiTapDetection return clickHistory.GetTapCount(xy); } + public static int InfoFromMouse(byte MBName) + { + var clickHistory = ClickHistoryCache[MBName]; + return clickHistory.LastTapCount(); + } + public static int DetectFromKeyboard(string KeyName) { var keyHistory = KeyHistoryCache[KeyName]; return keyHistory.GetTapCount(int2.Zero); } + + public static int InfoFromKeyboard(string KeyName) + { + var keyHistory = KeyHistoryCache[KeyName]; + return keyHistory.LastTapCount(); + } } class TapHistory @@ -57,4 +69,11 @@ class TapHistory if (!CloseEnough(SecondRelease, FirstRelease)) return 2; return 3; } + + public int LastTapCount() + { + if (!CloseEnough(ThirdRelease, SecondRelease)) return 1; + if (!CloseEnough(SecondRelease, FirstRelease)) return 2; + return 3; + } } \ No newline at end of file diff --git a/OpenRA.Renderer.SdlCommon/SdlInput.cs b/OpenRA.Renderer.SdlCommon/SdlInput.cs index 34bb61e489..17675ce829 100644 --- a/OpenRA.Renderer.SdlCommon/SdlInput.cs +++ b/OpenRA.Renderer.SdlCommon/SdlInput.cs @@ -67,8 +67,12 @@ namespace OpenRA.Renderer.SdlCommon var button = MakeButton( e.button.button ); lastButtonBits |= button; - inputHandler.OnMouseInput( new MouseInput( - MouseInputEvent.Down, button, new int2( e.button.x, e.button.y ), mods, 1 ) ); + var pos = new int2( e.button.x, e.button.y ); + + inputHandler.OnMouseInput(new MouseInput( + MouseInputEvent.Down, button, pos, mods, + MultiTapDetection.DetectFromMouse(e.button.button, pos) + )); } break; case Sdl.SDL_MOUSEBUTTONUP: @@ -83,9 +87,10 @@ namespace OpenRA.Renderer.SdlCommon lastButtonBits &= ~button; var pos = new int2( e.button.x, e.button.y ); - inputHandler.OnMouseInput( new MouseInput( + inputHandler.OnMouseInput(new MouseInput( MouseInputEvent.Up, button, pos, mods, - MultiTapDetection.DetectFromMouse( e.button.button, pos ))); + MultiTapDetection.InfoFromMouse(e.button.button) + )); } break; case Sdl.SDL_MOUSEMOTION: @@ -99,13 +104,16 @@ namespace OpenRA.Renderer.SdlCommon case Sdl.SDL_KEYDOWN: { + var keyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ); + var keyEvent = new KeyInput { Event = KeyInputEvent.Down, Modifiers = mods, UnicodeChar = (char)e.key.keysym.unicode, KeyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ), - VirtKey = e.key.keysym.sym + VirtKey = e.key.keysym.sym, + MultiTapCount = MultiTapDetection.DetectFromKeyboard(keyName) }; if( !HandleSpecialKey( keyEvent ) ) @@ -123,7 +131,7 @@ namespace OpenRA.Renderer.SdlCommon UnicodeChar = (char)e.key.keysym.unicode, KeyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ), VirtKey = e.key.keysym.sym, - MultiTapCount = MultiTapDetection.DetectFromKeyboard(keyName) + MultiTapCount = MultiTapDetection.InfoFromKeyboard(keyName) }; inputHandler.OnKeyInput( keyEvent );