From 34b12fbfa45c3275c1100e842ae627ded93e3e28 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 9 Aug 2017 17:10:32 +0900 Subject: [PATCH] Add global actions; improve default assignment --- osu.Game.Rulesets.Catch/CatchInputManager.cs | 19 +++++++------- osu.Game/Input/ActionMappingInputManager.cs | 8 ++++-- .../Input/GlobalActionMappingInputManager.cs | 18 +++++++++++++ osu.Game/Input/OsuAction.cs | 12 +++++++++ osu.Game/OsuGame.cs | 25 ++++++++----------- osu.Game/OsuGameBase.cs | 7 +++--- osu.Game/osu.Game.csproj | 2 ++ 7 files changed, 62 insertions(+), 29 deletions(-) create mode 100644 osu.Game/Input/GlobalActionMappingInputManager.cs create mode 100644 osu.Game/Input/OsuAction.cs diff --git a/osu.Game.Rulesets.Catch/CatchInputManager.cs b/osu.Game.Rulesets.Catch/CatchInputManager.cs index eada5cf532..98d9e7f505 100644 --- a/osu.Game.Rulesets.Catch/CatchInputManager.cs +++ b/osu.Game.Rulesets.Catch/CatchInputManager.cs @@ -11,16 +11,17 @@ namespace osu.Game.Rulesets.Catch { public CatchInputManager(RulesetInfo ruleset) : base(ruleset) { - Mappings = new Dictionary - { - { Key.Z, CatchAction.MoveLeft }, - { Key.Left, CatchAction.MoveLeft }, - { Key.X, CatchAction.MoveRight }, - { Key.Right, CatchAction.MoveRight }, - { Key.LShift, CatchAction.Dash }, - { Key.RShift, CatchAction.Dash }, - }; } + + protected override IDictionary CreateDefaultMappings() => new Dictionary + { + { Key.Z, CatchAction.MoveLeft }, + { Key.Left, CatchAction.MoveLeft }, + { Key.X, CatchAction.MoveRight }, + { Key.Right, CatchAction.MoveRight }, + { Key.LShift, CatchAction.Dash }, + { Key.RShift, CatchAction.Dash }, + }; } public enum CatchAction diff --git a/osu.Game/Input/ActionMappingInputManager.cs b/osu.Game/Input/ActionMappingInputManager.cs index c918982fab..b329d69ccd 100644 --- a/osu.Game/Input/ActionMappingInputManager.cs +++ b/osu.Game/Input/ActionMappingInputManager.cs @@ -14,7 +14,7 @@ namespace osu.Game.Input /// Maps custom action data of type and stores to . /// /// The type of the custom action. - public class ActionMappingInputManager : PassThroughInputManager + public abstract class ActionMappingInputManager : PassThroughInputManager where T : struct { private readonly RulesetInfo ruleset; @@ -30,9 +30,13 @@ namespace osu.Game.Input { this.ruleset = ruleset; this.variant = variant; + + Mappings = CreateDefaultMappings(); } - protected IDictionary Mappings { get; set; } + protected IDictionary Mappings { get; private set; } + + protected abstract IDictionary CreateDefaultMappings(); [BackgroundDependencyLoader] private void load(BindingStore bindings) diff --git a/osu.Game/Input/GlobalActionMappingInputManager.cs b/osu.Game/Input/GlobalActionMappingInputManager.cs new file mode 100644 index 0000000000..782520b3c9 --- /dev/null +++ b/osu.Game/Input/GlobalActionMappingInputManager.cs @@ -0,0 +1,18 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Input; +using OpenTK.Input; +using System.Collections.Generic; + +namespace osu.Game +{ + public class GlobalActionMappingInputManager : ActionMappingInputManager + { + protected override IDictionary CreateDefaultMappings() => new Dictionary() + { + { Key.F8, OsuAction.ToggleChat }, + { Key.F9, OsuAction.ToggleSocial }, + }; + } +} diff --git a/osu.Game/Input/OsuAction.cs b/osu.Game/Input/OsuAction.cs new file mode 100644 index 0000000000..5e25bb26b6 --- /dev/null +++ b/osu.Game/Input/OsuAction.cs @@ -0,0 +1,12 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + + +namespace osu.Game +{ + public enum OsuAction + { + ToggleChat, + ToggleSocial + } +} diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 8d8c5cf26e..8ad2dd96ef 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -256,22 +256,17 @@ namespace osu.Game { if (args.Repeat || intro == null) return false; - switch (args.Key) + if (state.Data is OsuAction) { - case Key.F8: - chat.ToggleVisibility(); - return true; - case Key.F9: - social.ToggleVisibility(); - return true; - case Key.PageUp: - case Key.PageDown: - var swClock = (Clock as ThrottledFrameClock)?.Source as StopwatchClock; - if (swClock == null) return false; - - swClock.Rate *= args.Key == Key.PageUp ? 1.1f : 0.9f; - Logger.Log($@"Adjusting game clock to {swClock.Rate}", LoggingTarget.Debug); - return true; + switch ((OsuAction)state.Data) + { + case OsuAction.ToggleChat: + chat.ToggleVisibility(); + return true; + case OsuAction.ToggleSocial: + social.ToggleVisibility(); + return true; + } } if (state.Keyboard.ControlPressed) diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index b76235f3f4..09e4996157 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -187,13 +187,14 @@ namespace osu.Game Children = new Drawable[] { Cursor = new MenuCursor(), - new OsuTooltipContainer(Cursor) + new GlobalActionMappingInputManager { RelativeSizeAxes = Axes.Both, - Child = content = new OsuContextMenuContainer + Child = new OsuTooltipContainer(Cursor) { RelativeSizeAxes = Axes.Both, - }, + Child = content = new OsuContextMenuContainer { RelativeSizeAxes = Axes.Both }, + } } } }); diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index aba4384b59..539e77f142 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -94,6 +94,8 @@ + +