From 1ed6a672f20987336683f354f313400ce1f52c95 Mon Sep 17 00:00:00 2001 From: ekrctb Date: Wed, 27 Jun 2018 18:43:29 +0900 Subject: [PATCH 1/3] Update volme control Use IMouseWheelBindingHandler for volume VolumeControlReceptor. VolumeMeter is no longer an IKeyBindingHandler because it is unused. --- osu.Game/OsuGame.cs | 3 +- osu.Game/Overlays/KeyBinding/KeyBindingRow.cs | 2 +- .../Overlays/Volume/VolumeControlReceptor.cs | 4 +- osu.Game/Overlays/Volume/VolumeMeter.cs | 62 +++++-------------- osu.Game/Overlays/VolumeOverlay.cs | 6 +- 5 files changed, 23 insertions(+), 54 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index ba8685b5b2..bc680193bc 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -247,7 +247,8 @@ namespace osu.Game new VolumeControlReceptor { RelativeSizeAxes = Axes.Both, - ActionRequested = action => volume.Adjust(action) + ActionRequested = action => volume.Adjust(action), + WheelActionRequested = (action, amount, isPrecise) => volume.Adjust(action, amount, isPrecise), }, mainContent = new Container { RelativeSizeAxes = Axes.Both }, overlayContent = new Container { RelativeSizeAxes = Axes.Both, Depth = float.MinValue }, diff --git a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs index a12f9dee7e..d537a68486 100644 --- a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs +++ b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs @@ -186,7 +186,7 @@ namespace osu.Game.Overlays.KeyBinding { if (bindTarget.IsHovered) { - bindTarget.UpdateKeyCombination(new KeyCombination(KeyCombination.FromInputState(state).Keys.Append(state.Mouse.ScrollDelta.Y > 0 ? InputKey.MouseWheelUp : InputKey.MouseWheelDown))); + bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(state, state.Mouse.ScrollDelta)); finalise(); return true; } diff --git a/osu.Game/Overlays/Volume/VolumeControlReceptor.cs b/osu.Game/Overlays/Volume/VolumeControlReceptor.cs index 572b3f0c27..bb9aadb888 100644 --- a/osu.Game/Overlays/Volume/VolumeControlReceptor.cs +++ b/osu.Game/Overlays/Volume/VolumeControlReceptor.cs @@ -9,11 +9,13 @@ using osu.Game.Input.Bindings; namespace osu.Game.Overlays.Volume { - public class VolumeControlReceptor : Container, IKeyBindingHandler, IHandleGlobalInput + public class VolumeControlReceptor : Container, IMouseWheelBindingHandler, IHandleGlobalInput { public Func ActionRequested; + public Func WheelActionRequested; public bool OnPressed(GlobalAction action) => ActionRequested?.Invoke(action) ?? false; + public bool OnMouseWheel(GlobalAction action, float amount, bool isPrecise) => WheelActionRequested?.Invoke(action, amount, isPrecise) ?? false; public bool OnReleased(GlobalAction action) => false; } } diff --git a/osu.Game/Overlays/Volume/VolumeMeter.cs b/osu.Game/Overlays/Volume/VolumeMeter.cs index 1d392e6ee8..9aeca1f35f 100644 --- a/osu.Game/Overlays/Volume/VolumeMeter.cs +++ b/osu.Game/Overlays/Volume/VolumeMeter.cs @@ -12,17 +12,15 @@ using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.UserInterface; using osu.Framework.Input; -using osu.Framework.Input.Bindings; using osu.Framework.MathUtils; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; -using osu.Game.Input.Bindings; using OpenTK; using OpenTK.Graphics; namespace osu.Game.Overlays.Volume { - public class VolumeMeter : Container, IKeyBindingHandler + public class VolumeMeter : Container { private CircularProgress volumeCircle; private CircularProgress volumeCircleGlow; @@ -226,59 +224,27 @@ namespace osu.Game.Overlays.Volume private const float adjust_step = 0.05f; - public void Increase() => adjust(1); - public void Decrease() => adjust(-1); - - private void adjust(int direction) - { - float amount = adjust_step * direction; - - // handle the case where the OnPressed action was actually a mouse wheel. - // this allows for precise wheel handling. - var state = GetContainingInputManager().CurrentState; - if (state.Mouse?.ScrollDelta.Y != 0) - { - OnScroll(state); - return; - } - - Volume += amount; - } - - 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 void Increase(double amount = 1, bool isPrecise = false) => adjust(amount, isPrecise); + public void Decrease(double amount = 1, bool isPrecise = false) => adjust(-amount, isPrecise); // because volume precision is set to 0.01, this local is required to keep track of more precise adjustments and only apply when possible. - private double scrollAmount; + private double adjustAccumulator; + + private void adjust(double delta, bool isPrecise) + { + adjustAccumulator += delta * adjust_step * (isPrecise ? 0.1 : 1); + if (Math.Abs(adjustAccumulator) < Bindable.Precision) + return; + Volume += adjustAccumulator; + adjustAccumulator = 0; + } protected override bool OnScroll(InputState state) { - scrollAmount += adjust_step * state.Mouse.ScrollDelta.Y * (state.Mouse.HasPreciseScroll ? 0.1f : 1); - - if (Math.Abs(scrollAmount) < Bindable.Precision) - return true; - - Volume += scrollAmount; - scrollAmount = 0; + adjust(state.Mouse.ScrollDelta.Y, state.Mouse.HasPreciseScroll); return true; } - public bool OnReleased(GlobalAction action) => false; - private const float transition_length = 500; protected override bool OnHover(InputState state) diff --git a/osu.Game/Overlays/VolumeOverlay.cs b/osu.Game/Overlays/VolumeOverlay.cs index 1c9c615bbb..e40597b2d4 100644 --- a/osu.Game/Overlays/VolumeOverlay.cs +++ b/osu.Game/Overlays/VolumeOverlay.cs @@ -93,7 +93,7 @@ namespace osu.Game.Overlays muteButton.Current.ValueChanged += _ => Show(); } - public bool Adjust(GlobalAction action) + public bool Adjust(GlobalAction action, float amount = 1, bool isPrecise = false) { if (!IsLoaded) return false; @@ -103,13 +103,13 @@ namespace osu.Game.Overlays if (State == Visibility.Hidden) Show(); else - volumeMeterMaster.Decrease(); + volumeMeterMaster.Decrease(amount, isPrecise); return true; case GlobalAction.IncreaseVolume: if (State == Visibility.Hidden) Show(); else - volumeMeterMaster.Increase(); + volumeMeterMaster.Increase(amount, isPrecise); return true; case GlobalAction.ToggleMute: Show(); From bbceac6cdaa93a215899cd6b137b1f61053152d8 Mon Sep 17 00:00:00 2001 From: ekrctb Date: Thu, 5 Jul 2018 16:50:04 +0900 Subject: [PATCH 2/3] Apply renaming of wheel -> scroll --- osu.Game/OsuGame.cs | 2 +- osu.Game/Overlays/Volume/VolumeControlReceptor.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index bc680193bc..49c774a5a0 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -248,7 +248,7 @@ namespace osu.Game { RelativeSizeAxes = Axes.Both, ActionRequested = action => volume.Adjust(action), - WheelActionRequested = (action, amount, isPrecise) => volume.Adjust(action, amount, isPrecise), + ScrollActionRequested = (action, amount, isPrecise) => volume.Adjust(action, amount, isPrecise), }, mainContent = new Container { RelativeSizeAxes = Axes.Both }, overlayContent = new Container { RelativeSizeAxes = Axes.Both, Depth = float.MinValue }, diff --git a/osu.Game/Overlays/Volume/VolumeControlReceptor.cs b/osu.Game/Overlays/Volume/VolumeControlReceptor.cs index bb9aadb888..3a64e12b27 100644 --- a/osu.Game/Overlays/Volume/VolumeControlReceptor.cs +++ b/osu.Game/Overlays/Volume/VolumeControlReceptor.cs @@ -9,13 +9,13 @@ using osu.Game.Input.Bindings; namespace osu.Game.Overlays.Volume { - public class VolumeControlReceptor : Container, IMouseWheelBindingHandler, IHandleGlobalInput + public class VolumeControlReceptor : Container, IScrollBindingHandler, IHandleGlobalInput { public Func ActionRequested; - public Func WheelActionRequested; + public Func ScrollActionRequested; public bool OnPressed(GlobalAction action) => ActionRequested?.Invoke(action) ?? false; - public bool OnMouseWheel(GlobalAction action, float amount, bool isPrecise) => WheelActionRequested?.Invoke(action, amount, isPrecise) ?? false; + public bool OnScroll(GlobalAction action, float amount, bool isPrecise) => ScrollActionRequested?.Invoke(action, amount, isPrecise) ?? false; public bool OnReleased(GlobalAction action) => false; } } From 7e28a993f7e0e86132d91f1cbc310518e6bcd76f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 5 Jul 2018 21:08:53 +0900 Subject: [PATCH 3/3] Update framework --- osu.Game/osu.Game.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 56c33c47af..da55726447 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -18,7 +18,7 @@ - +