From e151c7ffd017fe07aa7a6555dad88425b1fb1c1c Mon Sep 17 00:00:00 2001 From: Derrick Timmermans Date: Sun, 4 Jul 2021 15:31:43 +0200 Subject: [PATCH] Let VolumeMeter request focus instead of taking it --- osu.Game/Overlays/Volume/VolumeMeter.cs | 13 +++------- osu.Game/Overlays/VolumeOverlay.cs | 33 +++++++++++++++++-------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/osu.Game/Overlays/Volume/VolumeMeter.cs b/osu.Game/Overlays/Volume/VolumeMeter.cs index df8f1b7012..530a10ea7b 100644 --- a/osu.Game/Overlays/Volume/VolumeMeter.cs +++ b/osu.Game/Overlays/Volume/VolumeMeter.cs @@ -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 { - [Resolved(canBeNull: true)] - private Bindable 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; } diff --git a/osu.Game/Overlays/VolumeOverlay.cs b/osu.Game/Overlays/VolumeOverlay.cs index 750d54e091..c9321f5d60 100644 --- a/osu.Game/Overlays/VolumeOverlay.cs +++ b/osu.Game/Overlays/VolumeOverlay.cs @@ -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 focusedMeter = new Bindable(); + private readonly Bindable focusedMeter = new Bindable(); 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();