From 6934e045df2525eeeab800b4c9b543eed8d38256 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 25 Oct 2023 14:33:06 +0900 Subject: [PATCH] Fix editor not prompting before saving beatmap for export --- .../Editing/TestSceneEditorTestGameplay.cs | 4 +-- osu.Game/Screens/Edit/Editor.cs | 35 ++++++++++++------- ...stDialog.cs => SaveRequiredPopupDialog.cs} | 12 +++---- 3 files changed, 31 insertions(+), 20 deletions(-) rename osu.Game/Screens/Edit/{GameplayTest/SaveBeforeGameplayTestDialog.cs => SaveRequiredPopupDialog.cs} (60%) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneEditorTestGameplay.cs b/osu.Game.Tests/Visual/Editing/TestSceneEditorTestGameplay.cs index 007716bd6c..bbd7123f20 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneEditorTestGameplay.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneEditorTestGameplay.cs @@ -138,7 +138,7 @@ namespace osu.Game.Tests.Visual.Editing InputManager.MoveMouseTo(button); InputManager.Click(MouseButton.Left); }); - AddUntilStep("save prompt shown", () => DialogOverlay.CurrentDialog is SaveBeforeGameplayTestDialog); + AddUntilStep("save prompt shown", () => DialogOverlay.CurrentDialog is SaveRequiredPopupDialog); AddStep("dismiss prompt", () => { @@ -165,7 +165,7 @@ namespace osu.Game.Tests.Visual.Editing InputManager.MoveMouseTo(button); InputManager.Click(MouseButton.Left); }); - AddUntilStep("save prompt shown", () => DialogOverlay.CurrentDialog is SaveBeforeGameplayTestDialog); + AddUntilStep("save prompt shown", () => DialogOverlay.CurrentDialog is SaveRequiredPopupDialog); AddStep("save changes", () => DialogOverlay.CurrentDialog.PerformOkAction()); diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 899a782755..91c3c98f01 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -425,7 +425,7 @@ namespace osu.Game.Screens.Edit { if (HasUnsavedChanges) { - dialogOverlay.Push(new SaveBeforeGameplayTestDialog(() => + dialogOverlay.Push(new SaveRequiredPopupDialog("The beatmap will be saved in order to test it.", () => { if (!Save()) return; @@ -1018,25 +1018,36 @@ namespace osu.Game.Screens.Edit { var exportItems = new List { - new EditorMenuItem(EditorStrings.ExportForEditing, MenuItemType.Standard, exportBeatmap) { Action = { Disabled = !RuntimeInfo.IsDesktop } }, - new EditorMenuItem(EditorStrings.ExportForCompatibility, MenuItemType.Standard, exportLegacyBeatmap) { Action = { Disabled = !RuntimeInfo.IsDesktop } }, + new EditorMenuItem(EditorStrings.ExportForEditing, MenuItemType.Standard, () => exportBeatmap(false)) { Action = { Disabled = !RuntimeInfo.IsDesktop } }, + new EditorMenuItem(EditorStrings.ExportForCompatibility, MenuItemType.Standard, () => exportBeatmap(true)) { Action = { Disabled = !RuntimeInfo.IsDesktop } }, }; return new EditorMenuItem(CommonStrings.Export) { Items = exportItems }; } - private void exportBeatmap() + private void exportBeatmap(bool legacy) { - if (!Save()) return; + if (HasUnsavedChanges) + { + dialogOverlay.Push(new SaveRequiredPopupDialog("The beatmap will be saved in order to export it.", () => + { + if (!Save()) return; - beatmapManager.Export(Beatmap.Value.BeatmapSetInfo); - } + runExport(); + })); + } + else + { + runExport(); + } - private void exportLegacyBeatmap() - { - if (!Save()) return; - - beatmapManager.ExportLegacy(Beatmap.Value.BeatmapSetInfo); + void runExport() + { + if (legacy) + beatmapManager.ExportLegacy(Beatmap.Value.BeatmapSetInfo); + else + beatmapManager.Export(Beatmap.Value.BeatmapSetInfo); + } } /// diff --git a/osu.Game/Screens/Edit/GameplayTest/SaveBeforeGameplayTestDialog.cs b/osu.Game/Screens/Edit/SaveRequiredPopupDialog.cs similarity index 60% rename from osu.Game/Screens/Edit/GameplayTest/SaveBeforeGameplayTestDialog.cs rename to osu.Game/Screens/Edit/SaveRequiredPopupDialog.cs index eb1df43ddd..3ca92876f1 100644 --- a/osu.Game/Screens/Edit/GameplayTest/SaveBeforeGameplayTestDialog.cs +++ b/osu.Game/Screens/Edit/SaveRequiredPopupDialog.cs @@ -1,17 +1,17 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using osu.Framework.Graphics.Sprites; using osu.Game.Overlays.Dialog; -namespace osu.Game.Screens.Edit.GameplayTest +namespace osu.Game.Screens.Edit { - public partial class SaveBeforeGameplayTestDialog : PopupDialog + public partial class SaveRequiredPopupDialog : PopupDialog { - public SaveBeforeGameplayTestDialog(Action saveAndPreview) + public SaveRequiredPopupDialog(string headerText, Action saveAndAction) { - HeaderText = "The beatmap will be saved in order to test it."; + HeaderText = headerText; Icon = FontAwesome.Regular.Save; @@ -20,7 +20,7 @@ namespace osu.Game.Screens.Edit.GameplayTest new PopupDialogOkButton { Text = "Sounds good, let's go!", - Action = saveAndPreview + Action = saveAndAction }, new PopupDialogCancelButton {