From a93a92a2bbf70030ae24bb8d68a35e74209c7bb0 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 10 Aug 2017 19:52:45 +0900 Subject: [PATCH] Remove GlobalHotkeys --- osu.Game/Input/GlobalAction.cs | 23 ---------- .../Input/GlobalActionMappingInputManager.cs | 46 +++++++++++++++++++ osu.Game/Input/GlobalHotkeys.cs | 24 ---------- osu.Game/OsuGame.cs | 10 ++-- osu.Game/OsuGameBase.cs | 2 +- osu.Game/osu.Game.csproj | 2 - 6 files changed, 51 insertions(+), 56 deletions(-) delete mode 100644 osu.Game/Input/GlobalAction.cs delete mode 100644 osu.Game/Input/GlobalHotkeys.cs diff --git a/osu.Game/Input/GlobalAction.cs b/osu.Game/Input/GlobalAction.cs deleted file mode 100644 index c15773b888..0000000000 --- a/osu.Game/Input/GlobalAction.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using System.ComponentModel; - -namespace osu.Game.Input -{ - public enum GlobalAction - { - [Description("Toggle chat overlay")] - ToggleChat, - [Description("Toggle social overlay")] - ToggleSocial, - [Description("Reset input settings")] - ResetInputSettings, - [Description("Toggle toolbar")] - ToggleToolbar, - [Description("Toggle settings")] - ToggleSettings, - [Description("Toggle osu!direct")] - ToggleDirect, - } -} diff --git a/osu.Game/Input/GlobalActionMappingInputManager.cs b/osu.Game/Input/GlobalActionMappingInputManager.cs index 890872be04..3136fa5be5 100644 --- a/osu.Game/Input/GlobalActionMappingInputManager.cs +++ b/osu.Game/Input/GlobalActionMappingInputManager.cs @@ -3,11 +3,23 @@ using OpenTK.Input; using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using osu.Framework.Graphics; +using osu.Framework.Input; namespace osu.Game.Input { public class GlobalActionMappingInputManager : ActionMappingInputManager { + private readonly Drawable handler; + + public GlobalActionMappingInputManager(OsuGameBase game) + { + if (game is IHandleActions) + handler = game; + } + protected override IDictionary CreateDefaultMappings() => new Dictionary { { Key.F8, GlobalAction.ToggleChat }, @@ -17,5 +29,39 @@ namespace osu.Game.Input { new[] { Key.LControl, Key.O }, GlobalAction.ToggleSettings }, { new[] { Key.LControl, Key.D }, GlobalAction.ToggleDirect }, }; + + protected override bool PropagateKeyDown(IEnumerable drawables, InputState state, KeyDownEventArgs args) + { + if (handler != null) + drawables = new[] { handler }.Concat(drawables); + + // always handle ourselves before all children. + return base.PropagateKeyDown(drawables, state, args); + } + + protected override bool PropagateKeyUp(IEnumerable drawables, InputState state, KeyUpEventArgs args) + { + if (handler != null) + drawables = new[] { handler }.Concat(drawables); + + // always handle ourselves before all children. + return base.PropagateKeyUp(drawables, state, args); + } + } + + public enum GlobalAction + { + [Description("Toggle chat overlay")] + ToggleChat, + [Description("Toggle social overlay")] + ToggleSocial, + [Description("Reset input settings")] + ResetInputSettings, + [Description("Toggle toolbar")] + ToggleToolbar, + [Description("Toggle settings")] + ToggleSettings, + [Description("Toggle osu!direct")] + ToggleDirect, } } diff --git a/osu.Game/Input/GlobalHotkeys.cs b/osu.Game/Input/GlobalHotkeys.cs deleted file mode 100644 index f4c11fc9b4..0000000000 --- a/osu.Game/Input/GlobalHotkeys.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using osu.Framework.Graphics; - -namespace osu.Game.Input -{ - /// - /// A simple placeholder container which allows handling keyboard input at a higher level than otherwise possible. - /// - public class GlobalHotkeys : Drawable, IHandleActions - { - public Func Handler; - - public override bool HandleInput => true; - - public GlobalHotkeys() - { - RelativeSizeAxes = Axes.Both; - } - - public bool OnPressed(GlobalAction action) => Handler(action); - - public bool OnReleased(GlobalAction action) => false; - } -} diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 0a76fe1b38..9d24597b96 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -29,7 +29,7 @@ using osu.Game.Input; namespace osu.Game { - public class OsuGame : OsuGameBase + public class OsuGame : OsuGameBase, IHandleActions { public Toolbar Toolbar; @@ -168,10 +168,6 @@ namespace osu.Game volume = new VolumeControl(), overlayContent = new Container { RelativeSizeAxes = Axes.Both }, new OnScreenDisplay(), - new Input.GlobalHotkeys //exists because UserInputManager is at a level below us. - { - Handler = globalHotkeyPressed - } }); LoadComponentAsync(screenStack = new Loader(), d => @@ -251,7 +247,7 @@ namespace osu.Game Cursor.State = Visibility.Hidden; } - private bool globalHotkeyPressed(GlobalAction action) + public bool OnPressed(GlobalAction action) { if (intro == null) return false; @@ -286,6 +282,8 @@ namespace osu.Game return false; } + public bool OnReleased(GlobalAction action) => false; + public event Action ScreenChanged; private Container mainContent; diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 09e4996157..90d86f5371 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -187,7 +187,7 @@ namespace osu.Game Children = new Drawable[] { Cursor = new MenuCursor(), - new GlobalActionMappingInputManager + new GlobalActionMappingInputManager(this) { RelativeSizeAxes = Axes.Both, Child = new OsuTooltipContainer(Cursor) diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 74be1d4262..a240e58895 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -94,10 +94,8 @@ - -