diff --git a/osu-framework b/osu-framework index f1527e5456..ba70b8eaa9 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit f1527e5456cd228ddfb68cf6d56eb5d28dc360bf +Subproject commit ba70b8eaa9b79d4248873d4399f3b9e918fc3c8f diff --git a/osu.Game/Graphics/UserInterface/Volume/VolumeControl.cs b/osu.Game/Graphics/UserInterface/Volume/VolumeControl.cs index cd77fb9f5b..4c108e793a 100644 --- a/osu.Game/Graphics/UserInterface/Volume/VolumeControl.cs +++ b/osu.Game/Graphics/UserInterface/Volume/VolumeControl.cs @@ -3,11 +3,11 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Input; using osu.Framework.Threading; using OpenTK; using osu.Framework.Audio; using osu.Framework.Allocation; +using osu.Game.Input.Bindings; namespace osu.Game.Graphics.UserInterface.Volume { @@ -64,15 +64,25 @@ namespace osu.Game.Graphics.UserInterface.Volume volumeMeterMusic.Bindable.ValueChanged -= volumeChanged; } - public void Adjust(InputState state) + public bool Adjust(GlobalAction action) { - if (State == Visibility.Hidden) + switch (action) { - Show(); - return; + case GlobalAction.DecreaseVolume: + if (State == Visibility.Hidden) + Show(); + else + volumeMeterMaster.Decrease(); + return true; + case GlobalAction.IncreaseVolume: + if (State == Visibility.Hidden) + Show(); + else + volumeMeterMaster.Increase(); + return true; } - volumeMeterMaster.TriggerOnWheel(state); + return false; } [BackgroundDependencyLoader] diff --git a/osu.Game/Graphics/UserInterface/Volume/VolumeControlReceptor.cs b/osu.Game/Graphics/UserInterface/Volume/VolumeControlReceptor.cs index c155871f33..c222fecb5d 100644 --- a/osu.Game/Graphics/UserInterface/Volume/VolumeControlReceptor.cs +++ b/osu.Game/Graphics/UserInterface/Volume/VolumeControlReceptor.cs @@ -3,32 +3,16 @@ using System; using osu.Framework.Graphics.Containers; -using osu.Framework.Input; -using OpenTK.Input; +using osu.Framework.Input.Bindings; +using osu.Game.Input.Bindings; namespace osu.Game.Graphics.UserInterface.Volume { - internal class VolumeControlReceptor : Container + internal class VolumeControlReceptor : Container, IKeyBindingHandler { - public Action ActionRequested; + public Func ActionRequested; - protected override bool OnWheel(InputState state) - { - ActionRequested?.Invoke(state); - return true; - } - - protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) - { - switch (args.Key) - { - case Key.Up: - case Key.Down: - ActionRequested?.Invoke(state); - return true; - } - - return base.OnKeyDown(state, args); - } + public bool OnPressed(GlobalAction action) => ActionRequested?.Invoke(action) ?? false; + public bool OnReleased(GlobalAction action) => false; } } diff --git a/osu.Game/Graphics/UserInterface/Volume/VolumeMeter.cs b/osu.Game/Graphics/UserInterface/Volume/VolumeMeter.cs index 41fa60bec2..81c4fa9bae 100644 --- a/osu.Game/Graphics/UserInterface/Volume/VolumeMeter.cs +++ b/osu.Game/Graphics/UserInterface/Volume/VolumeMeter.cs @@ -4,15 +4,16 @@ using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Input; using osu.Game.Graphics.Sprites; using OpenTK; using OpenTK.Graphics; using osu.Framework.Graphics.Shapes; +using osu.Framework.Input.Bindings; +using osu.Game.Input.Bindings; namespace osu.Game.Graphics.UserInterface.Volume { - internal class VolumeMeter : Container + internal class VolumeMeter : Container, IKeyBindingHandler { private readonly Box meterFill; public BindableDouble Bindable { get; } = new BindableDouble(); @@ -76,12 +77,35 @@ namespace osu.Game.Graphics.UserInterface.Volume } } - protected override bool OnWheel(InputState state) + public void Increase() { - Volume += 0.05f * state.Mouse.WheelDelta; - return true; + Volume += 0.05f; + } + + public void Decrease() + { + Volume -= 0.05f; } private void updateFill() => meterFill.ScaleTo(new Vector2(1, (float)Volume), 300, Easing.OutQuint); + + public bool OnPressed(GlobalAction action) + { + if (!IsHovered) return false; + + switch (action) + { + case GlobalAction.DecreaseVolume: + Decrease(); + return true; + case GlobalAction.IncreaseVolume: + Increase(); + return true; + } + + return false; + } + + public bool OnReleased(GlobalAction action) => false; } } \ No newline at end of file diff --git a/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs b/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs index 5ea66fa600..759396e195 100644 --- a/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs +++ b/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs @@ -26,7 +26,10 @@ namespace osu.Game.Input.Bindings 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), + new KeyBinding(new[] { InputKey.Up }, GlobalAction.IncreaseVolume), + new KeyBinding(new[] { InputKey.MouseWheelUp }, GlobalAction.IncreaseVolume), + new KeyBinding(new[] { InputKey.Down }, GlobalAction.DecreaseVolume), + new KeyBinding(new[] { InputKey.MouseWheelDown }, GlobalAction.DecreaseVolume), }; protected override IEnumerable KeyBindingInputQueue => @@ -47,5 +50,9 @@ namespace osu.Game.Input.Bindings ToggleSettings, [Description("Toggle osu!direct")] ToggleDirect, + [Description("Increase Volume")] + IncreaseVolume, + [Description("Decrease Volume")] + DecreaseVolume, } } diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 8cb45c39a5..8c82071c23 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -8,7 +8,6 @@ using osu.Game.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Overlays; -using osu.Framework.Input; using osu.Framework.Logging; using osu.Game.Graphics.UserInterface.Volume; using osu.Framework.Allocation; @@ -160,7 +159,7 @@ namespace osu.Game new VolumeControlReceptor { RelativeSizeAxes = Axes.Both, - ActionRequested = delegate(InputState state) { volume.Adjust(state); } + ActionRequested = action => volume.Adjust(action) }, mainContent = new Container { diff --git a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs index a3361743a1..6c697c8660 100644 --- a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs +++ b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs @@ -136,40 +136,49 @@ namespace osu.Game.Overlays.KeyBinding protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) { - if (HasFocus) - { - if (bindTarget.IsHovered) - { - if (!AllowMainMouseButtons) - { - switch (args.Button) - { - case MouseButton.Left: - case MouseButton.Right: - return true; - } - } + if (!HasFocus || !bindTarget.IsHovered) + return base.OnMouseDown(state, args); - bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(state)); - return true; + if (!AllowMainMouseButtons) + { + switch (args.Button) + { + case MouseButton.Left: + case MouseButton.Right: + return true; } } - return base.OnMouseDown(state, args); + bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(state)); + return true; } protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) { - if (HasFocus && !state.Mouse.Buttons.Any()) + // don't do anything until the last button is released. + if (!HasFocus || state.Mouse.Buttons.Any()) + return base.OnMouseUp(state, args); + + if (bindTarget.IsHovered) + finalise(); + else + updateBindTarget(); + return true; + } + + protected override bool OnWheel(InputState state) + { + if (HasFocus) { if (bindTarget.IsHovered) + { + bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(state)); finalise(); - else - updateBindTarget(); - return true; + return true; + } } - return base.OnMouseUp(state, args); + return base.OnWheel(state); } protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) @@ -196,13 +205,10 @@ namespace osu.Game.Overlays.KeyBinding protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) { - if (HasFocus) - { - finalise(); - return true; - } + if (!HasFocus) return base.OnKeyUp(state, args); - return base.OnKeyUp(state, args); + finalise(); + return true; } private void finalise()