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 diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index 685349370a..aa554152f9 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -370,6 +370,9 @@ namespace osu.Game.Screens.Select if (!track.IsRunning) { + // Ensure the track is added to the TrackManager, since it is removed after the player finishes the map. + // Using AddItemToList rather than AddItem so that it doesn't attempt to register adjustment dependencies more than once. + Game.Audio.Track.AddItemToList(track); if (preview) track.Seek(Beatmap.Value.Metadata.PreviewTime); track.Start(); }