Disallow exiting the editor without saving (unless explicitly confirming)

This commit is contained in:
Dean Herbert
2022-03-22 15:28:31 +09:00
parent f95bd89166
commit 61ddf1e6cf
3 changed files with 30 additions and 8 deletions

View File

@ -7,10 +7,13 @@ using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.IO.Stores;
using osu.Framework.Platform;
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Online.API;
using osu.Game.Overlays;
using osu.Game.Overlays.Dialog;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Edit;
using osu.Game.Screens.Edit;
@ -93,6 +96,9 @@ namespace osu.Game.Tests.Visual
protected class TestEditor : Editor
{
[Resolved(canBeNull: true)]
private DialogOverlay dialogOverlay { get; set; }
public new void Undo() => base.Undo();
public new void Redo() => base.Redo();
@ -111,6 +117,18 @@ namespace osu.Game.Tests.Visual
public new bool HasUnsavedChanges => base.HasUnsavedChanges;
public override bool OnExiting(IScreen next)
{
// For testing purposes allow the screen to exit without saving on second attempt.
if (!ExitConfirmed && dialogOverlay.CurrentDialog is PromptForSaveDialog saveDialog)
{
saveDialog.PerformAction<PopupDialogDangerousButton>();
return true;
}
return base.OnExiting(next);
}
public TestEditor(EditorLoader loader = null)
: base(loader)
{