Let VolumeMeter request focus instead of taking it

This commit is contained in:
Derrick Timmermans 2021-07-04 15:31:43 +02:00
parent d1553f0864
commit e151c7ffd0
No known key found for this signature in database
GPG Key ID: 8681B60806EF4A17
2 changed files with 27 additions and 19 deletions

View File

@ -12,7 +12,6 @@
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Transforms;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
@ -28,10 +27,7 @@ namespace osu.Game.Overlays.Volume
{
public class VolumeMeter : Container, IKeyBindingHandler<GlobalAction>
{
[Resolved(canBeNull: true)]
private Bindable<VolumeMeter> focusedMeter { get; set; }
private bool isFocused => focusedMeter == null || focusedMeter.Value == this;
private bool isFocused = true;
private CircularProgress volumeCircle;
private CircularProgress volumeCircleGlow;
@ -320,20 +316,19 @@ protected override bool OnScroll(ScrollEvent e)
public void Focus()
{
if (focusedMeter != null)
focusedMeter.Value = this;
isFocused = true;
this.ScaleTo(1.04f, transition_length, Easing.OutExpo);
}
public void Unfocus()
{
isFocused = false;
this.ScaleTo(1f, transition_length, Easing.OutExpo);
}
protected override bool OnHover(HoverEvent e)
{
Focus();
RequestFocus?.Invoke(this);
return false;
}

View File

@ -19,7 +19,6 @@
namespace osu.Game.Overlays
{
[Cached]
public class VolumeOverlay : VisibilityContainer
{
private const float offset = 10;
@ -64,11 +63,20 @@ private void load(AudioManager audio, OsuColour colours)
Origin = Anchor.CentreLeft,
Spacing = new Vector2(0, offset),
Margin = new MarginPadding { Left = offset },
Children = new VolumeMeter[]
Children = new []
{
volumeMeterEffect = new VolumeMeter("EFFECTS", 125, colours.BlueDarker),
volumeMeterMaster = new VolumeMeter("MASTER", 150, colours.PinkDarker),
volumeMeterMusic = new VolumeMeter("MUSIC", 125, colours.BlueDarker),
volumeMeterEffect = new VolumeMeter("EFFECTS", 125, colours.BlueDarker)
{
RequestFocus = v => focusedMeter.Value = v
},
volumeMeterMaster = new VolumeMeter("MASTER", 150, colours.PinkDarker)
{
RequestFocus = v => focusedMeter.Value = v
},
volumeMeterMusic = new VolumeMeter("MUSIC", 125, colours.BlueDarker)
{
RequestFocus = v => focusedMeter.Value = v
},
}
}
});
@ -85,11 +93,14 @@ private void load(AudioManager audio, OsuColour colours)
audio.RemoveAdjustment(AdjustableProperty.Volume, muteAdjustment);
});
focusedMeter.BindValueChanged(meter => meter.OldValue?.Unfocus());
focusedMeter.BindValueChanged(meter =>
{
meter.OldValue?.Unfocus();
meter.NewValue?.Focus();
});
}
[Cached]
private Bindable<VolumeMeter> focusedMeter = new Bindable<VolumeMeter>();
private readonly Bindable<VolumeMeter> focusedMeter = new Bindable<VolumeMeter>();
protected override void LoadComplete()
{
@ -165,19 +176,21 @@ public bool Adjust(GlobalAction action, float amount = 1, bool isPrecise = false
private void focusShift(int direction = 1)
{
Show();
var newIndex = volumeMeters.IndexOf(focusedMeter.Value) + direction;
if (newIndex < 0)
newIndex += volumeMeters.Count;
volumeMeters.Children[newIndex % volumeMeters.Count].Focus();
focusedMeter.Value = volumeMeters.Children[newIndex % volumeMeters.Count];
}
private ScheduledDelegate popOutDelegate;
public override void Show()
{
// Focus on the master meter as a default if previously hidden
if (State.Value == Visibility.Hidden)
volumeMeterMaster.Focus();
focusedMeter.Value = volumeMeterMaster;
if (State.Value == Visibility.Visible)
schedulePopOut();