mirror of
https://github.com/ppy/osu
synced 2025-02-15 17:47:28 +00: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.Containers;
|
||||||
using osu.Framework.Graphics.Effects;
|
using osu.Framework.Graphics.Effects;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Graphics.Transforms;
|
|
||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Framework.Input.Bindings;
|
using osu.Framework.Input.Bindings;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
@ -28,10 +27,7 @@ namespace osu.Game.Overlays.Volume
|
|||||||
{
|
{
|
||||||
public class VolumeMeter : Container, IKeyBindingHandler<GlobalAction>
|
public class VolumeMeter : Container, IKeyBindingHandler<GlobalAction>
|
||||||
{
|
{
|
||||||
[Resolved(canBeNull: true)]
|
private bool isFocused = true;
|
||||||
private Bindable<VolumeMeter> focusedMeter { get; set; }
|
|
||||||
|
|
||||||
private bool isFocused => focusedMeter == null || focusedMeter.Value == this;
|
|
||||||
|
|
||||||
private CircularProgress volumeCircle;
|
private CircularProgress volumeCircle;
|
||||||
private CircularProgress volumeCircleGlow;
|
private CircularProgress volumeCircleGlow;
|
||||||
@ -320,20 +316,19 @@ namespace osu.Game.Overlays.Volume
|
|||||||
|
|
||||||
public void Focus()
|
public void Focus()
|
||||||
{
|
{
|
||||||
if (focusedMeter != null)
|
isFocused = true;
|
||||||
focusedMeter.Value = this;
|
|
||||||
|
|
||||||
this.ScaleTo(1.04f, transition_length, Easing.OutExpo);
|
this.ScaleTo(1.04f, transition_length, Easing.OutExpo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Unfocus()
|
public void Unfocus()
|
||||||
{
|
{
|
||||||
|
isFocused = false;
|
||||||
this.ScaleTo(1f, transition_length, Easing.OutExpo);
|
this.ScaleTo(1f, transition_length, Easing.OutExpo);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnHover(HoverEvent e)
|
protected override bool OnHover(HoverEvent e)
|
||||||
{
|
{
|
||||||
Focus();
|
RequestFocus?.Invoke(this);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@ using osuTK.Graphics;
|
|||||||
|
|
||||||
namespace osu.Game.Overlays
|
namespace osu.Game.Overlays
|
||||||
{
|
{
|
||||||
[Cached]
|
|
||||||
public class VolumeOverlay : VisibilityContainer
|
public class VolumeOverlay : VisibilityContainer
|
||||||
{
|
{
|
||||||
private const float offset = 10;
|
private const float offset = 10;
|
||||||
@ -64,11 +63,20 @@ namespace osu.Game.Overlays
|
|||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
Spacing = new Vector2(0, offset),
|
Spacing = new Vector2(0, offset),
|
||||||
Margin = new MarginPadding { Left = offset },
|
Margin = new MarginPadding { Left = offset },
|
||||||
Children = new VolumeMeter[]
|
Children = new []
|
||||||
{
|
{
|
||||||
volumeMeterEffect = new VolumeMeter("EFFECTS", 125, colours.BlueDarker),
|
volumeMeterEffect = new VolumeMeter("EFFECTS", 125, colours.BlueDarker)
|
||||||
volumeMeterMaster = new VolumeMeter("MASTER", 150, colours.PinkDarker),
|
{
|
||||||
volumeMeterMusic = new VolumeMeter("MUSIC", 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);
|
audio.RemoveAdjustment(AdjustableProperty.Volume, muteAdjustment);
|
||||||
});
|
});
|
||||||
|
|
||||||
focusedMeter.BindValueChanged(meter => meter.OldValue?.Unfocus());
|
focusedMeter.BindValueChanged(meter =>
|
||||||
|
{
|
||||||
|
meter.OldValue?.Unfocus();
|
||||||
|
meter.NewValue?.Focus();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[Cached]
|
private readonly Bindable<VolumeMeter> focusedMeter = new Bindable<VolumeMeter>();
|
||||||
private Bindable<VolumeMeter> focusedMeter = new Bindable<VolumeMeter>();
|
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
@ -165,19 +176,21 @@ namespace osu.Game.Overlays
|
|||||||
private void focusShift(int direction = 1)
|
private void focusShift(int direction = 1)
|
||||||
{
|
{
|
||||||
Show();
|
Show();
|
||||||
|
|
||||||
var newIndex = volumeMeters.IndexOf(focusedMeter.Value) + direction;
|
var newIndex = volumeMeters.IndexOf(focusedMeter.Value) + direction;
|
||||||
if (newIndex < 0)
|
if (newIndex < 0)
|
||||||
newIndex += volumeMeters.Count;
|
newIndex += volumeMeters.Count;
|
||||||
|
|
||||||
volumeMeters.Children[newIndex % volumeMeters.Count].Focus();
|
focusedMeter.Value = volumeMeters.Children[newIndex % volumeMeters.Count];
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScheduledDelegate popOutDelegate;
|
private ScheduledDelegate popOutDelegate;
|
||||||
|
|
||||||
public override void Show()
|
public override void Show()
|
||||||
{
|
{
|
||||||
|
// Focus on the master meter as a default if previously hidden
|
||||||
if (State.Value == Visibility.Hidden)
|
if (State.Value == Visibility.Hidden)
|
||||||
volumeMeterMaster.Focus();
|
focusedMeter.Value = volumeMeterMaster;
|
||||||
|
|
||||||
if (State.Value == Visibility.Visible)
|
if (State.Value == Visibility.Visible)
|
||||||
schedulePopOut();
|
schedulePopOut();
|
||||||
|
Loading…
Reference in New Issue
Block a user