diff --git a/source/funkin/ui/debug/charting/ChartEditorState.hx b/source/funkin/ui/debug/charting/ChartEditorState.hx index 6892bd62c..6f570880d 100644 --- a/source/funkin/ui/debug/charting/ChartEditorState.hx +++ b/source/funkin/ui/debug/charting/ChartEditorState.hx @@ -95,9 +95,6 @@ import haxe.ui.components.Button; import haxe.ui.components.DropDown; import haxe.ui.components.Label; import haxe.ui.components.Slider; -import haxe.ui.containers.dialogs.Dialogs; -import haxe.ui.containers.dialogs.Dialog.DialogButton; -import haxe.ui.containers.dialogs.MessageBox.MessageBoxType; import haxe.ui.containers.dialogs.CollapsibleDialog; import haxe.ui.containers.menus.Menu; import haxe.ui.containers.menus.MenuBar; @@ -5675,19 +5672,8 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState { if (saveDataDirty) { - this.isHaxeUIDialogOpen = true; - var dialog = Dialogs.messageBox("You are about to leave the editor without saving.\n\nAre you sure?", "Leave Editor", MessageBoxType.TYPE_YESNO, true, - function(button:DialogButton) { - if (button == DialogButton.YES) - { - autoSave(); - quitChartEditor(); - } - }); - + this.openLeaveConfirmationDialog(); return; - - dialog.onDialogClosed = (_) -> this.isHaxeUIDialogOpen = false; } stopWelcomeMusic(); diff --git a/source/funkin/ui/debug/charting/handlers/ChartEditorDialogHandler.hx b/source/funkin/ui/debug/charting/handlers/ChartEditorDialogHandler.hx index c39e2d441..e94eec641 100644 --- a/source/funkin/ui/debug/charting/handlers/ChartEditorDialogHandler.hx +++ b/source/funkin/ui/debug/charting/handlers/ChartEditorDialogHandler.hx @@ -32,6 +32,7 @@ import haxe.ui.containers.Box; import haxe.ui.containers.dialogs.Dialog; import haxe.ui.containers.dialogs.Dialog.DialogButton; import haxe.ui.containers.dialogs.Dialogs; +import haxe.ui.containers.dialogs.MessageBox.MessageBoxType; import haxe.ui.containers.Form; import haxe.ui.containers.menus.Menu; import haxe.ui.core.Component; @@ -1315,6 +1316,37 @@ class ChartEditorDialogHandler return dialog; } + /** + * Builds and opens a dialog where the user can confirm to leave the chart editor if they have unsaved changes. + * @param state The current chart editor state. + * @return The dialog that was opened. + */ + public static function openLeaveConfirmationDialog(state:ChartEditorState):Dialog + { + var dialog:Null = Dialogs.messageBox("You are about to leave the editor without saving.\n\nAre you sure?", "Leave Editor", MessageBoxType.TYPE_YESNO, true, + function(button:DialogButton) + { + state.isHaxeUIDialogOpen = false; + if (button == DialogButton.YES) + { + state.autoSave(); + state.quitChartEditor(); + } + } + ); + + dialog.destroyOnClose = true; + state.isHaxeUIDialogOpen = true; + + dialog.onDialogClosed = function(event:UIEvent) { + state.isHaxeUIDialogOpen = false; + }; + + dialog.zIndex = 1000; + + return dialog; + } + /** * Builds and opens a dialog from a given layout path. * @param modal Makes the background uninteractable while the dialog is open.