1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-14 05:47:20 +08:00

Merge pull request #31779 from peppy/menu-fade-out

Change menus to fade out with a slight delay so settings changes are visible
This commit is contained in:
Bartłomiej Dach 2025-02-05 09:29:56 +01:00 committed by GitHub
commit 4f629478b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 38 deletions

View File

@ -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
@ -35,8 +29,6 @@ namespace osu.Game.Graphics.UserInterface
ItemsContainer.Padding = new MarginPadding { Vertical = DrawableOsuMenuItem.MARGIN_VERTICAL };
MaxHeight = 250;
this.playClickSample = playClickSample;
}
[BackgroundDependencyLoader]
@ -47,26 +39,12 @@ namespace osu.Game.Graphics.UserInterface
protected override void AnimateOpen()
{
wasOpened = true;
this.FadeIn(fade_duration, Easing.OutQuint);
if (PlaySamples && !WasOpened)
menuSamples.PlayClickSample();
if (!playClickSample)
return;
menuSamples.PlayClickSample();
menuSamples.PlayOpenSample();
base.AnimateOpen();
}
protected override void AnimateClose()
{
this.FadeOut(fade_duration, Easing.OutQuint);
if (wasOpened)
menuSamples.PlayCloseSample();
wasOpened = false;
}
protected override Menu CreateSubMenu() => new OsuContextMenu();
protected override Menu CreateSubMenu() => new OsuContextMenu(false); // sub menu samples are handled by OsuMenu.OnSubmenuOpen.
}
}

View File

@ -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()
@ -56,20 +67,22 @@ namespace osu.Game.Graphics.UserInterface
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)
@ -77,12 +90,21 @@ namespace osu.Game.Graphics.UserInterface
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);
}
}