diff --git a/OpenRA.Game/Input/HotkeyReference.cs b/OpenRA.Game/Input/HotkeyReference.cs index 8d1f081f72..83f75d66fa 100644 --- a/OpenRA.Game/Input/HotkeyReference.cs +++ b/OpenRA.Game/Input/HotkeyReference.cs @@ -45,5 +45,11 @@ namespace OpenRA { return getValue(); } + + public bool IsActivatedBy(KeyInput e) + { + var currentValue = getValue(); + return currentValue.Key == e.Key && currentValue.Modifiers == e.Modifiers; + } } } diff --git a/OpenRA.Mods.Common/Widgets/ButtonWidget.cs b/OpenRA.Mods.Common/Widgets/ButtonWidget.cs index 2e67a79723..d7e3a19640 100644 --- a/OpenRA.Mods.Common/Widgets/ButtonWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ButtonWidget.cs @@ -130,7 +130,7 @@ namespace OpenRA.Mods.Common.Widgets public override bool HandleKeyPress(KeyInput e) { - if (Hotkey.FromKeyInput(e) != Key.GetValue() || e.Event != KeyInputEvent.Down || (DisableKeyRepeat && e.IsRepeat)) + if (!Key.IsActivatedBy(e) || e.Event != KeyInputEvent.Down || (DisableKeyRepeat && e.IsRepeat)) return false; if (!IsDisabled()) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorLogic.cs index 19eb3ce86a..a162cb291d 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/MapEditorLogic.cs @@ -72,8 +72,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic zoomDropdown.GetText = () => zoomDropdown.SelectedItem; zoomDropdown.OnKeyPress = e => { - var key = Hotkey.FromKeyInput(e); - if (key != changeZoomKey.GetValue()) + if (!changeZoomKey.IsActivatedBy(e)) return; var selected = (options.IndexOf(float.Parse(selectedZoom)) + 1) % options.Length; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/CommandBarLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/CommandBarLogic.cs index 53afcbe675..c1b210f7a1 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/CommandBarLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/CommandBarLogic.cs @@ -208,8 +208,8 @@ namespace OpenRA.Mods.Common.Widgets keyOverrides.AddHandler(e => { // HACK: enable attack move to be triggered if the ctrl key is pressed - var modified = new Hotkey(e.Key, e.Modifiers & ~Modifiers.Ctrl); - if (!attackMoveDisabled && attackMoveButton.Key.GetValue() == modified) + e.Modifiers &= ~Modifiers.Ctrl; + if (!attackMoveDisabled && attackMoveButton.Key.IsActivatedBy(e)) { attackMoveButton.OnKeyPress(e); return true; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/MenuButtonsChromeLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/MenuButtonsChromeLogic.cs index 872d84a29f..80106f0373 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/MenuButtonsChromeLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/MenuButtonsChromeLogic.cs @@ -104,10 +104,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic { if (e.Event == KeyInputEvent.Down && !e.IsRepeat) { - var key = Hotkey.FromKeyInput(e); for (var i = 0; i < statsHotkeys.Length; i++) { - if (key == statsHotkeys[i].GetValue()) + if (statsHotkeys[i].IsActivatedBy(e)) { OpenMenuPanel(stats, new WidgetArgs() { { "activePanel", i } }); return true; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs index de557ce63c..d427524e41 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs @@ -148,8 +148,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { if (e.Event == KeyInputEvent.Down && !e.IsRepeat) { - var h = Hotkey.FromKeyInput(e); - if (h == combinedViewKey.GetValue() && !limitViews) + if (combinedViewKey.IsActivatedBy(e) && !limitViews) { selected = combined; selected.OnClick(); @@ -157,7 +156,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic return true; } - if (h == worldViewKey.GetValue() && !limitViews) + if (worldViewKey.IsActivatedBy(e) && !limitViews) { selected = disableShroud; selected.OnClick(); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs index efc9fb330a..bddb4b718a 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs @@ -124,10 +124,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic { if (e.Event == KeyInputEvent.Down && !e.IsRepeat) { - var key = Hotkey.FromKeyInput(e); for (var i = 0; i < statsHotkeys.Length; i++) { - if (key == statsHotkeys[i].GetValue()) + if (statsHotkeys[i].IsActivatedBy(e)) { statsDropDownOptions[i].OnClick(); return true; diff --git a/OpenRA.Mods.Common/Widgets/Logic/MusicHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MusicHotkeyLogic.cs index bd0432b5af..42247efbbf 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MusicHotkeyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MusicHotkeyLogic.cs @@ -50,15 +50,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic { if (e.Event == KeyInputEvent.Down) { - var key = Hotkey.FromKeyInput(e); - - if (key == nextKey.GetValue()) + if (nextKey.IsActivatedBy(e)) musicPlaylist.Play(musicPlaylist.GetNextSong()); - else if (key == prevKey.GetValue()) + else if (prevKey.IsActivatedBy(e)) musicPlaylist.Play(musicPlaylist.GetPrevSong()); - else if (key == stopKey.GetValue()) + else if (stopKey.IsActivatedBy(e)) StopMusic(); - else if (key == pauseKey.GetValue()) + else if (pauseKey.IsActivatedBy(e)) PauseOrResumeMusic(); } diff --git a/OpenRA.Mods.Common/Widgets/Logic/SingleHotkeyBaseLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/SingleHotkeyBaseLogic.cs index 4534d648c0..6fcfcdbf30 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/SingleHotkeyBaseLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/SingleHotkeyBaseLogic.cs @@ -30,11 +30,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic keyhandler.AddHandler(e => { if (e.Event == KeyInputEvent.Down) - { - var key = Hotkey.FromKeyInput(e); - if (key == namedKey.GetValue()) + if (namedKey.IsActivatedBy(e)) return OnHotkeyActivated(e); - } return false; }); diff --git a/OpenRA.Mods.Common/Widgets/ProductionPaletteWidget.cs b/OpenRA.Mods.Common/Widgets/ProductionPaletteWidget.cs index 9797a9b5ca..f75343a4c5 100644 --- a/OpenRA.Mods.Common/Widgets/ProductionPaletteWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ProductionPaletteWidget.cs @@ -342,12 +342,11 @@ namespace OpenRA.Mods.Common.Widgets if (e.Event == KeyInputEvent.Up || CurrentQueue == null) return false; - var hotkey = Hotkey.FromKeyInput(e); var batchModifiers = e.Modifiers.HasModifier(Modifiers.Shift) ? Modifiers.Shift : Modifiers.None; - if (batchModifiers != Modifiers.None) - hotkey = new Hotkey(hotkey.Key, hotkey.Modifiers ^ Modifiers.Shift); - var toBuild = icons.Values.FirstOrDefault(i => i.Hotkey != null && i.Hotkey.GetValue() == hotkey); + // HACK: enable production if the shift key is pressed + e.Modifiers &= ~Modifiers.Shift; + var toBuild = icons.Values.FirstOrDefault(i => i.Hotkey != null && i.Hotkey.IsActivatedBy(e)); return toBuild != null ? HandleEvent(toBuild, MouseButton.Left, batchModifiers) : false; } diff --git a/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs b/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs index 9d8fd92a21..bd212cae2e 100644 --- a/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ProductionTabsWidget.cs @@ -287,14 +287,13 @@ namespace OpenRA.Mods.Common.Widgets if (e.Event != KeyInputEvent.Down) return false; - var hotkey = Hotkey.FromKeyInput(e); - if (hotkey == PreviousProductionTabKey.GetValue()) + if (PreviousProductionTabKey.IsActivatedBy(e)) { Game.Sound.PlayNotification(world.Map.Rules, null, "Sounds", "ClickSound", null); return SelectNextTab(true); } - if (hotkey == NextProductionTabKey.GetValue()) + if (NextProductionTabKey.IsActivatedBy(e)) { Game.Sound.PlayNotification(world.Map.Rules, null, "Sounds", "ClickSound", null); return SelectNextTab(false); diff --git a/OpenRA.Mods.Common/Widgets/SupportPowersWidget.cs b/OpenRA.Mods.Common/Widgets/SupportPowersWidget.cs index 0b4aee34ca..24c1be0f8a 100644 --- a/OpenRA.Mods.Common/Widgets/SupportPowersWidget.cs +++ b/OpenRA.Mods.Common/Widgets/SupportPowersWidget.cs @@ -161,8 +161,7 @@ namespace OpenRA.Mods.Common.Widgets { if (e.Event == KeyInputEvent.Down) { - var hotkey = Hotkey.FromKeyInput(e); - var a = icons.Values.FirstOrDefault(i => i.Hotkey != null && i.Hotkey.GetValue() == hotkey); + var a = icons.Values.FirstOrDefault(i => i.Hotkey != null && i.Hotkey.IsActivatedBy(e)); if (a != null) { diff --git a/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs b/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs index 6ed52c003b..a4a6d117d6 100644 --- a/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs @@ -447,25 +447,25 @@ namespace OpenRA.Mods.Common.Widgets if (e.Event != KeyInputEvent.Down) return false; - if (key == JumpToTopEdgeKey.GetValue()) + if (JumpToTopEdgeKey.IsActivatedBy(e)) { worldRenderer.Viewport.Center(new WPos(worldRenderer.Viewport.CenterPosition.X, 0, 0)); return true; } - if (key == JumpToBottomEdgeKey.GetValue()) + if (JumpToBottomEdgeKey.IsActivatedBy(e)) { worldRenderer.Viewport.Center(new WPos(worldRenderer.Viewport.CenterPosition.X, worldRenderer.World.Map.ProjectedBottomRight.Y, 0)); return true; } - if (key == JumpToLeftEdgeKey.GetValue()) + if (JumpToLeftEdgeKey.IsActivatedBy(e)) { worldRenderer.Viewport.Center(new WPos(0, worldRenderer.Viewport.CenterPosition.Y, 0)); return true; } - if (key == JumpToRightEdgeKey.GetValue()) + if (JumpToRightEdgeKey.IsActivatedBy(e)) { worldRenderer.Viewport.Center(new WPos(worldRenderer.World.Map.ProjectedBottomRight.X, worldRenderer.Viewport.CenterPosition.Y, 0)); return true; @@ -473,7 +473,7 @@ namespace OpenRA.Mods.Common.Widgets for (var i = 0; i < saveBookmarkHotkeys.Length; i++) { - if (key == saveBookmarkHotkeys[i].GetValue()) + if (saveBookmarkHotkeys[i].IsActivatedBy(e)) { bookmarkPositions[i] = worldRenderer.Viewport.CenterPosition; return true; @@ -482,7 +482,7 @@ namespace OpenRA.Mods.Common.Widgets for (var i = 0; i < restoreBookmarkHotkeys.Length; i++) { - if (key == restoreBookmarkHotkeys[i].GetValue()) + if (restoreBookmarkHotkeys[i].IsActivatedBy(e)) { var bookmark = bookmarkPositions[i]; if (bookmark.HasValue) diff --git a/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs index 7193eda947..9b966bd021 100644 --- a/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs @@ -244,9 +244,7 @@ namespace OpenRA.Mods.Common.Widgets if (e.Event == KeyInputEvent.Down) { - var key = Hotkey.FromKeyInput(e); - - if (key == SelectAllKey.GetValue() && !World.IsGameOver) + if (SelectAllKey.IsActivatedBy(e) && !World.IsGameOver) { // Select actors on the screen which belong to the current player var ownUnitsOnScreen = SelectActorsOnScreen(World, worldRenderer, null, player).SubsetWithHighestSelectionPriority().ToList(); @@ -263,7 +261,7 @@ namespace OpenRA.Mods.Common.Widgets World.Selection.Combine(World, ownUnitsOnScreen, false, false); } - else if (key == SelectSameTypeKey.GetValue() && !World.IsGameOver) + else if (SelectSameTypeKey.IsActivatedBy(e) && !World.IsGameOver) { if (!World.Selection.Actors.Any()) return false;