Skip to content

Commit

Permalink
Merge pull request #24953 from peppy/flash-dialog-on-stuck
Browse files Browse the repository at this point in the history
Flash dialog popup when attempting to exit editor while exit is being blocked
  • Loading branch information
bdach authored Sep 28, 2023
2 parents afa1815 + 7908b36 commit 90326f6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
27 changes: 27 additions & 0 deletions osu.Game/Overlays/Dialog/PopupDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
Expand All @@ -28,6 +31,9 @@ public abstract partial class PopupDialog : VisibilityContainer
private readonly Vector2 ringMinifiedSize = new Vector2(20f);
private readonly Vector2 buttonsEnterSpacing = new Vector2(0f, 50f);

private readonly Box flashLayer;
private Sample flashSample = null!;

private readonly Container content;
private readonly Container ring;
private readonly FillFlowContainer<PopupDialogButton> buttonsContainer;
Expand Down Expand Up @@ -208,6 +214,13 @@ protected PopupDialog()
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
},
flashLayer = new Box
{
Alpha = 0,
RelativeSizeAxes = Axes.Both,
Blending = BlendingParameters.Additive,
Colour = Color4Extensions.FromHex(@"221a21"),
},
},
},
};
Expand All @@ -217,6 +230,12 @@ protected PopupDialog()
Show();
}

[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
flashSample = audio.Samples.Get(@"UI/default-select-disabled");
}

/// <summary>
/// Programmatically clicks the first <see cref="PopupDialogOkButton"/>.
/// </summary>
Expand All @@ -232,6 +251,14 @@ public void PerformAction<T>() where T : PopupDialogButton
Scheduler.AddOnce(() => Buttons.OfType<T>().FirstOrDefault()?.TriggerClick());
}

public void Flash()
{
flashLayer.FadeInFromZero(80, Easing.OutQuint)
.Then()
.FadeOutFromOne(1500, Easing.OutQuint);
flashSample.Play();
}

protected override bool OnKeyDown(KeyDownEvent e)
{
if (e.Repeat) return false;
Expand Down
5 changes: 4 additions & 1 deletion osu.Game/Screens/Edit/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,11 @@ public override bool OnExiting(ScreenExitEvent e)
}

// if the dialog is already displayed, block exiting until the user explicitly makes a decision.
if (dialogOverlay.CurrentDialog is PromptForSaveDialog)
if (dialogOverlay.CurrentDialog is PromptForSaveDialog saveDialog)
{
saveDialog.Flash();
return true;
}

if (isNewBeatmap || HasUnsavedChanges)
{
Expand Down

0 comments on commit 90326f6

Please sign in to comment.