Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change menus to fade out with a slight delay so settings changes are visible #31779

Merged
merged 3 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 6 additions & 28 deletions osu.Game/Graphics/UserInterface/OsuContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,11 @@ namespace osu.Game.Graphics.UserInterface
{
public partial class OsuContextMenu : OsuMenu
{
private const int fade_duration = 250;

[Resolved]
private OsuMenuSamples menuSamples { get; set; } = null!;

// todo: this shouldn't be required after https://github.com/ppy/osu-framework/issues/4519 is fixed.
private bool wasOpened;
private readonly bool playClickSample;

public OsuContextMenu(bool playClickSample = false)
: base(Direction.Vertical)
public OsuContextMenu(bool playSamples)
: base(Direction.Vertical, topLevelMenu: false, playSamples)
{
MaskingContainer.CornerRadius = 5;
MaskingContainer.EdgeEffect = new EdgeEffectParameters
Expand All @@ -35,8 +29,6 @@ public OsuContextMenu(bool playClickSample = false)
ItemsContainer.Padding = new MarginPadding { Vertical = DrawableOsuMenuItem.MARGIN_VERTICAL };

MaxHeight = 250;

this.playClickSample = playClickSample;
}

[BackgroundDependencyLoader]
Expand All @@ -47,26 +39,12 @@ private void load(OsuColour colours)

protected override void AnimateOpen()
{
wasOpened = true;
this.FadeIn(fade_duration, Easing.OutQuint);

if (!playClickSample)
return;

menuSamples.PlayClickSample();
menuSamples.PlayOpenSample();
}

protected override void AnimateClose()
{
this.FadeOut(fade_duration, Easing.OutQuint);

if (wasOpened)
menuSamples.PlayCloseSample();
if (PlaySamples && !WasOpened)
menuSamples.PlayClickSample();

wasOpened = false;
base.AnimateOpen();
}

protected override Menu CreateSubMenu() => new OsuContextMenu();
protected override Menu CreateSubMenu() => new OsuContextMenu(false); // sub menu samples are handled by OsuMenu.OnSubmenuOpen.
}
}
42 changes: 32 additions & 10 deletions osu.Game/Graphics/UserInterface/OsuMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,32 @@ namespace osu.Game.Graphics.UserInterface
{
public partial class OsuMenu : Menu
{
protected const double DELAY_BEFORE_FADE_OUT = 50;
protected const double FADE_DURATION = 280;

// todo: this shouldn't be required after https://github.com/ppy/osu-framework/issues/4519 is fixed.
private bool wasOpened;
protected bool WasOpened { get; private set; }

public bool PlaySamples { get; }

[Resolved]
private OsuMenuSamples menuSamples { get; set; } = null!;

public OsuMenu(Direction direction, bool topLevelMenu = false)
: this(direction, topLevelMenu, playSamples: !topLevelMenu)
{
}

protected OsuMenu(Direction direction, bool topLevelMenu, bool playSamples)
: base(direction, topLevelMenu)
{
PlaySamples = playSamples;
BackgroundColour = Color4.Black.Opacity(0.5f);

MaskingContainer.CornerRadius = 4;
ItemsContainer.Padding = new MarginPadding(5);

OnSubmenuOpen += _ => { menuSamples?.PlaySubOpenSample(); };
OnSubmenuOpen += _ => menuSamples?.PlaySubOpenSample();
}

protected override void Update()
Expand All @@ -56,33 +67,44 @@ protected override void Update()

protected override void AnimateOpen()
{
if (!TopLevelMenu && !wasOpened)
if (PlaySamples && !WasOpened)
menuSamples?.PlayOpenSample();

this.FadeIn(300, Easing.OutQuint);
wasOpened = true;
WasOpened = true;
this.FadeIn(FADE_DURATION, Easing.OutQuint);
}

protected override void AnimateClose()
{
if (!TopLevelMenu && wasOpened)
if (PlaySamples && WasOpened)
menuSamples?.PlayCloseSample();

this.FadeOut(300, Easing.OutQuint);
wasOpened = false;
this.Delay(DELAY_BEFORE_FADE_OUT)
.FadeOut(FADE_DURATION, Easing.OutQuint);

WasOpened = false;
}

protected override void UpdateSize(Vector2 newSize)
{
if (Direction == Direction.Vertical)
{
Width = newSize.X;
this.ResizeHeightTo(newSize.Y, 300, Easing.OutQuint);

if (newSize.Y > 0)
this.ResizeHeightTo(newSize.Y, 300, Easing.OutQuint);
else
// Delay until the fade out finishes from AnimateClose.
this.Delay(DELAY_BEFORE_FADE_OUT + FADE_DURATION).ResizeHeightTo(0);
}
else
{
Height = newSize.Y;
this.ResizeWidthTo(newSize.X, 300, Easing.OutQuint);
if (newSize.X > 0)
this.ResizeWidthTo(newSize.X, 300, Easing.OutQuint);
else
// Delay until the fade out finishes from AnimateClose.
this.Delay(DELAY_BEFORE_FADE_OUT + FADE_DURATION).ResizeWidthTo(0);
}
}

Expand Down