mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 23:12:56 +08:00
Let VolumeMeter request focus instead of taking it
This commit is contained in:
parent
d1553f0864
commit
e151c7ffd0
@ -12,7 +12,6 @@ using osu.Framework.Graphics;
|
||||
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 @@ namespace osu.Game.Overlays.Volume
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,6 @@ using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays
|
||||
{
|
||||
[Cached]
|
||||
public class VolumeOverlay : VisibilityContainer
|
||||
{
|
||||
private const float offset = 10;
|
||||
@ -64,11 +63,20 @@ namespace osu.Game.Overlays
|
||||
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 @@ namespace osu.Game.Overlays
|
||||
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 @@ namespace osu.Game.Overlays
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user