1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 21:27:24 +08:00

Merge pull request #2744 from peppy/improve-volume-controls

Improve UX of volume controls
This commit is contained in:
Dean Herbert 2018-06-22 13:51:18 +09:00 committed by GitHub
commit 155db6969a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 17 deletions

View File

@ -66,7 +66,7 @@ namespace osu.Game.Overlays.Volume
protected override bool OnHover(InputState state)
{
this.TransformTo<MuteButton, SRGBColour>("BorderColour", hoveredColour, 500, Easing.OutQuint);
return true;
return false;
}
protected override void OnHoverLost(InputState state)

View File

@ -11,6 +11,7 @@ using osu.Framework.Graphics.Containers;
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;
@ -232,12 +233,13 @@ namespace osu.Game.Overlays.Volume
{
float amount = adjust_step * direction;
var mouse = GetContainingInputManager().CurrentState.Mouse;
if (mouse.HasPreciseScroll)
// 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)
{
float scrollDelta = mouse.ScrollDelta.Y;
if (scrollDelta != 0)
amount *= Math.Abs(scrollDelta / 10);
OnScroll(state);
return;
}
Volume += amount;
@ -260,6 +262,34 @@ namespace osu.Game.Overlays.Volume
return false;
}
// 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;
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;
return true;
}
public bool OnReleased(GlobalAction action) => false;
private const float transition_length = 500;
protected override bool OnHover(InputState state)
{
this.ScaleTo(1.04f, transition_length, Easing.OutExpo);
return false;
}
protected override void OnHoverLost(InputState state)
{
this.ScaleTo(1f, transition_length, Easing.OutExpo);
}
}
}

View File

@ -9,6 +9,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input;
using osu.Framework.Threading;
using osu.Game.Graphics;
using osu.Game.Input.Bindings;
@ -86,16 +87,10 @@ namespace osu.Game.Overlays
{
base.LoadComplete();
volumeMeterMaster.Bindable.ValueChanged += _ => settingChanged();
volumeMeterEffect.Bindable.ValueChanged += _ => settingChanged();
volumeMeterMusic.Bindable.ValueChanged += _ => settingChanged();
muteButton.Current.ValueChanged += _ => settingChanged();
}
private void settingChanged()
{
Show();
schedulePopOut();
volumeMeterMaster.Bindable.ValueChanged += _ => Show();
volumeMeterEffect.Bindable.ValueChanged += _ => Show();
volumeMeterMusic.Bindable.ValueChanged += _ => Show();
muteButton.Current.ValueChanged += _ => Show();
}
public bool Adjust(GlobalAction action)
@ -127,6 +122,14 @@ namespace osu.Game.Overlays
private ScheduledDelegate popOutDelegate;
public override void Show()
{
if (State == Visibility.Visible)
schedulePopOut();
base.Show();
}
protected override void PopIn()
{
ClearTransforms();
@ -140,10 +143,33 @@ namespace osu.Game.Overlays
this.FadeOut(100);
}
protected override bool OnMouseMove(InputState state)
{
// keep the scheduled event correctly timed as long as we have movement.
schedulePopOut();
return base.OnMouseMove(state);
}
protected override bool OnHover(InputState state)
{
schedulePopOut();
return true;
}
protected override void OnHoverLost(InputState state)
{
schedulePopOut();
base.OnHoverLost(state);
}
private void schedulePopOut()
{
popOutDelegate?.Cancel();
this.Delay(1000).Schedule(Hide, out popOutDelegate);
this.Delay(1000).Schedule(() =>
{
if (!IsHovered)
Hide();
}, out popOutDelegate);
}
}
}