make PlayerSettingsGroup expand on hover

This commit is contained in:
integer 2023-01-13 23:07:59 +00:00
parent 0b5c89d01f
commit c3c1d77e8e
2 changed files with 26 additions and 4 deletions

View File

@ -16,7 +16,6 @@ namespace osu.Game.Screens.Play.HUD
{ {
private const int fade_duration = 200; private const int fade_duration = 200;
public bool ReplayLoaded; public bool ReplayLoaded;
public readonly PlaybackSettings PlaybackSettings; public readonly PlaybackSettings PlaybackSettings;
@ -42,13 +41,12 @@ namespace osu.Game.Screens.Play.HUD
{ {
//CollectionSettings = new CollectionSettings(), //CollectionSettings = new CollectionSettings(),
//DiscussionSettings = new DiscussionSettings(), //DiscussionSettings = new DiscussionSettings(),
PlaybackSettings = new PlaybackSettings(), PlaybackSettings = new PlaybackSettings { Expanded = { Value = false } },
VisualSettings = new VisualSettings() VisualSettings = new VisualSettings { Expanded = { Value = false } }
} }
}; };
} }
protected override void PopIn() => this.FadeIn(fade_duration); protected override void PopIn() => this.FadeIn(fade_duration);
protected override void PopOut() => this.FadeOut(fade_duration); protected override void PopOut() => this.FadeOut(fade_duration);

View File

@ -4,6 +4,7 @@
#nullable disable #nullable disable
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Threading;
using osu.Game.Overlays; using osu.Game.Overlays;
namespace osu.Game.Screens.Play.PlayerSettings namespace osu.Game.Screens.Play.PlayerSettings
@ -15,12 +16,35 @@ namespace osu.Game.Screens.Play.PlayerSettings
{ {
} }
private ScheduledDelegate hoverExpandEvent;
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
{ {
updateHoverExpansion();
base.OnHover(e); base.OnHover(e);
// Importantly, return true to correctly take focus away from PlayerLoader. // Importantly, return true to correctly take focus away from PlayerLoader.
return true; return true;
} }
protected override void OnHoverLost(HoverLostEvent e)
{
if (hoverExpandEvent == null) return;
hoverExpandEvent?.Cancel();
hoverExpandEvent = null;
Expanded.Value = false;
base.OnHoverLost(e);
}
private void updateHoverExpansion()
{
hoverExpandEvent?.Cancel();
if (IsHovered && !Expanded.Value)
hoverExpandEvent = Scheduler.AddDelayed(() => Expanded.Value = true, 0);
}
} }
} }