From 9e5deb63d1bc7d8a409012d1c93f362e39caca09 Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Tue, 15 Aug 2017 16:42:26 +0930 Subject: [PATCH 01/11] Fix spinner not handling left/right action bindings --- .../Objects/Drawables/Pieces/SpinnerDisc.cs | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs index cd808abe9d..99c287f6fb 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs @@ -5,13 +5,14 @@ using System; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Input; +using osu.Framework.Input.Bindings; using osu.Game.Graphics; using OpenTK; using OpenTK.Graphics; namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces { - public class SpinnerDisc : CircularContainer, IHasAccentColour + public class SpinnerDisc : CircularContainer, IHasAccentColour, IKeyBindingHandler { private readonly Spinner spinner; @@ -66,26 +67,53 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces } } + private void updateTracking() + { + Tracking = mouseHasMainButtonPressed || actionLeftButtonPressed || actionRightButtonPressed; + } + protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) { - Tracking |= state.Mouse.HasMainButtonPressed; + mouseHasMainButtonPressed |= state.Mouse.HasMainButtonPressed; + updateTracking(); return base.OnMouseDown(state, args); } protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) { - Tracking &= state.Mouse.HasMainButtonPressed; + mouseHasMainButtonPressed &= state.Mouse.HasMainButtonPressed; + updateTracking(); return base.OnMouseUp(state, args); } protected override bool OnMouseMove(InputState state) { - Tracking |= state.Mouse.HasMainButtonPressed; + mouseHasMainButtonPressed |= state.Mouse.HasMainButtonPressed; mousePosition = Parent.ToLocalSpace(state.Mouse.NativeState.Position); + updateTracking(); return base.OnMouseMove(state); } + public bool OnPressed(OsuAction action) + { + actionLeftButtonPressed |= action == OsuAction.LeftButton; + actionRightButtonPressed |= action == OsuAction.RightButton; + updateTracking(); + return false; + } + + public bool OnReleased(OsuAction action) + { + actionLeftButtonPressed &= action == OsuAction.LeftButton; + actionRightButtonPressed &= action == OsuAction.RightButton; + updateTracking(); + return false; + } + private Vector2 mousePosition; + private bool mouseHasMainButtonPressed; + private bool actionLeftButtonPressed; + private bool actionRightButtonPressed; private float lastAngle; private float currentRotation; From 9448e2f192bfee608ad6b620c495fcef2c22e09b Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Wed, 16 Aug 2017 17:25:48 +0930 Subject: [PATCH 02/11] Remove unnecessary OnMouseDown/Up from SpinnerDisc --- .../Objects/Drawables/Pieces/SpinnerDisc.cs | 26 ++----------------- 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs index 99c287f6fb..eda6334b7a 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs @@ -67,30 +67,9 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces } } - private void updateTracking() - { - Tracking = mouseHasMainButtonPressed || actionLeftButtonPressed || actionRightButtonPressed; - } - - protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) - { - mouseHasMainButtonPressed |= state.Mouse.HasMainButtonPressed; - updateTracking(); - return base.OnMouseDown(state, args); - } - - protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) - { - mouseHasMainButtonPressed &= state.Mouse.HasMainButtonPressed; - updateTracking(); - return base.OnMouseUp(state, args); - } - protected override bool OnMouseMove(InputState state) { - mouseHasMainButtonPressed |= state.Mouse.HasMainButtonPressed; mousePosition = Parent.ToLocalSpace(state.Mouse.NativeState.Position); - updateTracking(); return base.OnMouseMove(state); } @@ -98,7 +77,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces { actionLeftButtonPressed |= action == OsuAction.LeftButton; actionRightButtonPressed |= action == OsuAction.RightButton; - updateTracking(); + Tracking = actionLeftButtonPressed || actionRightButtonPressed; return false; } @@ -106,12 +85,11 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces { actionLeftButtonPressed &= action == OsuAction.LeftButton; actionRightButtonPressed &= action == OsuAction.RightButton; - updateTracking(); + Tracking = actionLeftButtonPressed || actionRightButtonPressed; return false; } private Vector2 mousePosition; - private bool mouseHasMainButtonPressed; private bool actionLeftButtonPressed; private bool actionRightButtonPressed; From b1abf83fee82bfb3bdb6ab1d0a538d67b5f242ca Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Wed, 16 Aug 2017 17:50:24 +0930 Subject: [PATCH 03/11] Change spinner action checks to switches --- .../Objects/Drawables/Pieces/SpinnerDisc.cs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs index eda6334b7a..1e56a2559a 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs @@ -75,16 +75,30 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces public bool OnPressed(OsuAction action) { - actionLeftButtonPressed |= action == OsuAction.LeftButton; - actionRightButtonPressed |= action == OsuAction.RightButton; + switch (action) + { + case OsuAction.LeftButton: + actionLeftButtonPressed = true; + break; + case OsuAction.RightButton: + actionRightButtonPressed = true; + break; + } Tracking = actionLeftButtonPressed || actionRightButtonPressed; return false; } public bool OnReleased(OsuAction action) { - actionLeftButtonPressed &= action == OsuAction.LeftButton; - actionRightButtonPressed &= action == OsuAction.RightButton; + switch (action) + { + case OsuAction.LeftButton: + actionLeftButtonPressed = false; + break; + case OsuAction.RightButton: + actionRightButtonPressed = false; + break; + } Tracking = actionLeftButtonPressed || actionRightButtonPressed; return false; } From 306c00e593089589c98ddeea266ffc87d4871037 Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Fri, 18 Aug 2017 16:26:48 +0930 Subject: [PATCH 04/11] Update framework to include PR #977 --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 5c22092e59..03b7608f21 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 5c22092e590d589927962b8d0173dae5f9b1405c +Subproject commit 03b7608f210b35dbcd3a811bda002e7a9334d081 From 9c6ca2d15928742fb2dbae1b56333d3656a2a7a9 Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Fri, 18 Aug 2017 16:34:01 +0930 Subject: [PATCH 05/11] Add lazy weak property to DrawableOsuHitObject to find and cache the containing OsuInputManager, if it exists --- .../Objects/Drawables/DrawableOsuHitObject.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs index ca1b44e1c7..c5d75f076b 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using System.ComponentModel; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Osu.Judgements; @@ -51,6 +52,19 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables protected virtual void UpdateCurrentState(ArmedState state) { } + + private WeakReference osuActionInputManager = new WeakReference(null); + internal OsuInputManager OsuActionInputManager + { + get + { + OsuInputManager target = null; + if (osuActionInputManager.TryGetTarget(out target)) return target; + target = GetContainingInputManager() as OsuInputManager; + osuActionInputManager.SetTarget(target); + return target; + } + } } public enum ComboResult From 9628c0b6d656a2a63a62b46f649344a80399a08b Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Fri, 18 Aug 2017 16:46:00 +0930 Subject: [PATCH 06/11] Change spinner to check currently pressed actions rather than implementing IKeyBindingHandler --- .../Objects/Drawables/DrawableSpinner.cs | 8 +++++ .../Objects/Drawables/Pieces/SpinnerDisc.cs | 34 +------------------ 2 files changed, 9 insertions(+), 33 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs index 4a0b8422f1..307ef5d636 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System.Linq; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Rulesets.Objects.Drawables; @@ -165,6 +166,13 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables glow.Colour = colours.BlueDark; } + protected override void Update() + { + disc.Tracking = OsuActionInputManager.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton); + + base.Update(); + } + protected override void UpdateAfterChildren() { base.UpdateAfterChildren(); diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs index 1e56a2559a..80d4391718 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs @@ -12,7 +12,7 @@ using OpenTK.Graphics; namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces { - public class SpinnerDisc : CircularContainer, IHasAccentColour, IKeyBindingHandler + public class SpinnerDisc : CircularContainer, IHasAccentColour { private readonly Spinner spinner; @@ -73,39 +73,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces return base.OnMouseMove(state); } - public bool OnPressed(OsuAction action) - { - switch (action) - { - case OsuAction.LeftButton: - actionLeftButtonPressed = true; - break; - case OsuAction.RightButton: - actionRightButtonPressed = true; - break; - } - Tracking = actionLeftButtonPressed || actionRightButtonPressed; - return false; - } - - public bool OnReleased(OsuAction action) - { - switch (action) - { - case OsuAction.LeftButton: - actionLeftButtonPressed = false; - break; - case OsuAction.RightButton: - actionRightButtonPressed = false; - break; - } - Tracking = actionLeftButtonPressed || actionRightButtonPressed; - return false; - } - private Vector2 mousePosition; - private bool actionLeftButtonPressed; - private bool actionRightButtonPressed; private float lastAngle; private float currentRotation; From 90dacd9861809f715151bbcae699afc758914a3b Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Fri, 18 Aug 2017 16:49:10 +0930 Subject: [PATCH 07/11] Trim whitespace --- osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs index 307ef5d636..8473cc2453 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs @@ -169,7 +169,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables protected override void Update() { disc.Tracking = OsuActionInputManager.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton); - + base.Update(); } From 529732ea473093a5a7bbd4fcd27f94b09872fb83 Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Fri, 18 Aug 2017 16:58:01 +0930 Subject: [PATCH 08/11] More CI fixes --- .../Objects/Drawables/DrawableOsuHitObject.cs | 4 ++-- osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs index c5d75f076b..cca91925f0 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs @@ -53,12 +53,12 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables { } - private WeakReference osuActionInputManager = new WeakReference(null); + private readonly WeakReference osuActionInputManager = new WeakReference(null); internal OsuInputManager OsuActionInputManager { get { - OsuInputManager target = null; + OsuInputManager target; if (osuActionInputManager.TryGetTarget(out target)) return target; target = GetContainingInputManager() as OsuInputManager; osuActionInputManager.SetTarget(target); diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs index 80d4391718..6577c7fd50 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs @@ -5,7 +5,6 @@ using System; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Input; -using osu.Framework.Input.Bindings; using osu.Game.Graphics; using OpenTK; using OpenTK.Graphics; From 44feef78f14f4d13c7cd173cef22af6980e34bb9 Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Fri, 18 Aug 2017 19:32:08 +0930 Subject: [PATCH 09/11] Simplify OsuActionInputManager property --- .../Objects/Drawables/DrawableOsuHitObject.cs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs index cca91925f0..409244998e 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs @@ -53,18 +53,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables { } - private readonly WeakReference osuActionInputManager = new WeakReference(null); - internal OsuInputManager OsuActionInputManager - { - get - { - OsuInputManager target; - if (osuActionInputManager.TryGetTarget(out target)) return target; - target = GetContainingInputManager() as OsuInputManager; - osuActionInputManager.SetTarget(target); - return target; - } - } + private OsuInputManager osuActionInputManager; + internal OsuInputManager OsuActionInputManager => osuActionInputManager ?? (osuActionInputManager = GetContainingInputManager() as OsuInputManager); } public enum ComboResult From 9558d2a16185c5e1b3b2dd8e96f779970df100a9 Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Fri, 18 Aug 2017 19:39:28 +0930 Subject: [PATCH 10/11] Remove unnecessary using --- osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs index 409244998e..b3043d18f6 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs @@ -1,7 +1,6 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; using System.ComponentModel; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Osu.Judgements; From d6249e7a633a4df5d504728c7af5404fd8d284d1 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 18 Aug 2017 18:22:00 +0900 Subject: [PATCH 11/11] Add support for binding mouse buttons to actions --- osu-framework | 2 +- osu.Game.Rulesets.Catch/CatchRuleset.cs | 12 +- osu.Game.Rulesets.Osu/OsuRuleset.cs | 8 +- .../Bindings/GlobalKeyBindingInputManager.cs | 17 ++- osu.Game/Overlays/KeyBinding/KeyBindingRow.cs | 126 ++++++++++++------ .../Overlays/KeyBinding/KeyBindingsSection.cs | 5 +- 6 files changed, 111 insertions(+), 59 deletions(-) diff --git a/osu-framework b/osu-framework index 03b7608f21..825505e788 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 03b7608f210b35dbcd3a811bda002e7a9334d081 +Subproject commit 825505e788c4f093b269c61b485d38d50cd68096 diff --git a/osu.Game.Rulesets.Catch/CatchRuleset.cs b/osu.Game.Rulesets.Catch/CatchRuleset.cs index b486566b7d..f7662030fc 100644 --- a/osu.Game.Rulesets.Catch/CatchRuleset.cs +++ b/osu.Game.Rulesets.Catch/CatchRuleset.cs @@ -23,12 +23,12 @@ namespace osu.Game.Rulesets.Catch public override IEnumerable GetDefaultKeyBindings(int variant = 0) => new[] { - new KeyBinding(Key.Z, CatchAction.MoveLeft), - new KeyBinding(Key.Left, CatchAction.MoveLeft), - new KeyBinding(Key.X, CatchAction.MoveRight), - new KeyBinding(Key.Right, CatchAction.MoveRight), - new KeyBinding(Key.LShift, CatchAction.Dash), - new KeyBinding(Key.RShift, CatchAction.Dash), + new KeyBinding(InputKey.Z, CatchAction.MoveLeft), + new KeyBinding(InputKey.Left, CatchAction.MoveLeft), + new KeyBinding(InputKey.X, CatchAction.MoveRight), + new KeyBinding(InputKey.Right, CatchAction.MoveRight), + new KeyBinding(InputKey.Shift, CatchAction.Dash), + new KeyBinding(InputKey.Shift, CatchAction.Dash), }; public override IEnumerable GetModsFor(ModType type) diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index 75b7be01a4..aaa1dff820 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -27,10 +27,10 @@ namespace osu.Game.Rulesets.Osu public override IEnumerable GetDefaultKeyBindings(int variant = 0) => new[] { - new KeyBinding(Key.Z, OsuAction.LeftButton), - new KeyBinding(Key.X, OsuAction.RightButton), - new KeyBinding(Key.LastKey + 1, OsuAction.LeftButton), - new KeyBinding(Key.LastKey + 2, OsuAction.RightButton), + new KeyBinding(InputKey.Z, OsuAction.LeftButton), + new KeyBinding(InputKey.X, OsuAction.RightButton), + new KeyBinding(InputKey.LastKey + 1, OsuAction.LeftButton), + new KeyBinding(InputKey.LastKey + 2, OsuAction.RightButton), }; public override IEnumerable GetBeatmapStatistics(WorkingBeatmap beatmap) => new[] diff --git a/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs b/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs index 31be2e6adc..5ea66fa600 100644 --- a/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs +++ b/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs @@ -1,7 +1,6 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using OpenTK.Input; using System.Collections.Generic; using System.ComponentModel; using System.Linq; @@ -22,16 +21,16 @@ namespace osu.Game.Input.Bindings public override IEnumerable DefaultKeyBindings => new[] { - new KeyBinding(Key.F8, GlobalAction.ToggleChat), - new KeyBinding(Key.F9, GlobalAction.ToggleSocial), - new KeyBinding(new[] { Key.LControl, Key.LAlt, Key.R }, GlobalAction.ResetInputSettings), - new KeyBinding(new[] { Key.LControl, Key.T }, GlobalAction.ToggleToolbar), - new KeyBinding(new[] { Key.LControl, Key.O }, GlobalAction.ToggleSettings), - new KeyBinding(new[] { Key.LControl, Key.D }, GlobalAction.ToggleDirect), + new KeyBinding(InputKey.F8, GlobalAction.ToggleChat), + new KeyBinding(InputKey.F9, GlobalAction.ToggleSocial), + new KeyBinding(new[] { InputKey.Control, InputKey.Alt, InputKey.R }, GlobalAction.ResetInputSettings), + new KeyBinding(new[] { InputKey.Control, InputKey.T }, GlobalAction.ToggleToolbar), + new KeyBinding(new[] { InputKey.Control, InputKey.O }, GlobalAction.ToggleSettings), + new KeyBinding(new[] { InputKey.Control, InputKey.D }, GlobalAction.ToggleDirect), }; - protected override IEnumerable GetKeyboardInputQueue() => - handler == null ? base.GetKeyboardInputQueue() : new[] { handler }.Concat(base.GetKeyboardInputQueue()); + protected override IEnumerable KeyBindingInputQueue => + handler == null ? base.KeyBindingInputQueue : new[] { handler }.Concat(base.KeyBindingInputQueue); } public enum GlobalAction diff --git a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs index 44aee0e666..a3361743a1 100644 --- a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs +++ b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs @@ -11,6 +11,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Input; +using osu.Framework.Input.Bindings; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Input; @@ -123,46 +124,74 @@ namespace osu.Game.Overlays.KeyBinding base.OnHoverLost(state); } - public override bool AcceptsFocus => true; + public override bool AcceptsFocus => bindTarget == null; private KeyButton bindTarget; - protected override void OnFocus(InputState state) - { - AutoSizeDuration = 500; - AutoSizeEasing = Easing.OutQuint; - - pressAKey.FadeIn(300, Easing.OutQuint); - pressAKey.Padding = new MarginPadding(); - - base.OnFocus(state); - } + public bool AllowMainMouseButtons; private bool isModifier(Key k) => k < Key.F1; - protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) - { - switch (args.Key) - { - case Key.Escape: - GetContainingInputManager().ChangeFocus(null); - return true; - case Key.Delete: - bindTarget.UpdateKeyCombination(Key.Unknown); - store.Update(bindTarget.KeyBinding); - GetContainingInputManager().ChangeFocus(null); - return true; - } + protected override bool OnClick(InputState state) => true; + protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) + { if (HasFocus) { - bindTarget.UpdateKeyCombination(state.Keyboard.Keys.ToArray()); - if (!isModifier(args.Key)) + if (bindTarget.IsHovered) + { + if (!AllowMainMouseButtons) + { + switch (args.Button) + { + case MouseButton.Left: + case MouseButton.Right: + return true; + } + } + + bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(state)); + return true; + } + } + + return base.OnMouseDown(state, args); + } + + protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) + { + if (HasFocus && !state.Mouse.Buttons.Any()) + { + if (bindTarget.IsHovered) finalise(); + else + updateBindTarget(); return true; } - return base.OnKeyDown(state, args); + return base.OnMouseUp(state, args); + } + + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + { + if (!HasFocus) + return false; + + switch (args.Key) + { + case Key.Escape: + finalise(); + return true; + case Key.Delete: + bindTarget.UpdateKeyCombination(InputKey.None); + finalise(); + return true; + } + + bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(state)); + if (!isModifier(args.Key)) finalise(); + + return true; } protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) @@ -178,27 +207,48 @@ namespace osu.Game.Overlays.KeyBinding private void finalise() { - store.Update(bindTarget.KeyBinding); - GetContainingInputManager().ChangeFocus(null); + if (bindTarget != null) + { + store.Update(bindTarget.KeyBinding); + + bindTarget.IsBinding = false; + Schedule(() => + { + // schedule to ensure we don't instantly get focus back on next OnMouseClick (see AcceptFocus impl.) + bindTarget = null; + }); + } + + if (HasFocus) + GetContainingInputManager().ChangeFocus(null); + + pressAKey.FadeOut(300, Easing.OutQuint); + pressAKey.Padding = new MarginPadding { Bottom = -pressAKey.DrawHeight }; + } + + protected override void OnFocus(InputState state) + { + AutoSizeDuration = 500; + AutoSizeEasing = Easing.OutQuint; + + pressAKey.FadeIn(300, Easing.OutQuint); + pressAKey.Padding = new MarginPadding(); + + updateBindTarget(); + base.OnFocus(state); } protected override void OnFocusLost(InputState state) { - bindTarget.IsBinding = false; - bindTarget = null; - - pressAKey.FadeOut(300, Easing.OutQuint); - pressAKey.Padding = new MarginPadding { Bottom = -pressAKey.DrawHeight }; + finalise(); base.OnFocusLost(state); } - protected override bool OnClick(InputState state) + private void updateBindTarget() { if (bindTarget != null) bindTarget.IsBinding = false; bindTarget = buttons.FirstOrDefault(b => b.IsHovered) ?? buttons.FirstOrDefault(); if (bindTarget != null) bindTarget.IsBinding = true; - - return bindTarget != null; } private class KeyButton : Container @@ -296,7 +346,7 @@ namespace osu.Game.Overlays.KeyBinding } } - public void UpdateKeyCombination(params Key[] newCombination) + public void UpdateKeyCombination(KeyCombination newCombination) { KeyBinding.KeyCombination = newCombination; Text.Text = KeyBinding.KeyCombination.ReadableString(); diff --git a/osu.Game/Overlays/KeyBinding/KeyBindingsSection.cs b/osu.Game/Overlays/KeyBinding/KeyBindingsSection.cs index 19baeca771..44c28ee9c8 100644 --- a/osu.Game/Overlays/KeyBinding/KeyBindingsSection.cs +++ b/osu.Game/Overlays/KeyBinding/KeyBindingsSection.cs @@ -40,7 +40,10 @@ namespace osu.Game.Overlays.KeyBinding foreach (Enum v in Enum.GetValues(enumType)) // one row per valid action. - Add(new KeyBindingRow(v, bindings.Where(b => b.Action.Equals((int)(object)v)))); + Add(new KeyBindingRow(v, bindings.Where(b => b.Action.Equals((int)(object)v))) + { + AllowMainMouseButtons = Ruleset != null + }); } } } \ No newline at end of file