diff --git a/source/funkin/editors/SaveWarning.hx b/source/funkin/editors/SaveWarning.hx index 8361e9d4..b712ad07 100644 --- a/source/funkin/editors/SaveWarning.hx +++ b/source/funkin/editors/SaveWarning.hx @@ -6,6 +6,7 @@ class SaveWarning { return WindowUtils.preventClosing = showWarning = warning; public static var selectionClass:Class = null; + public static var saveFunc:Void->Void = null; public static function init() { showWarning = false; @@ -18,29 +19,46 @@ class SaveWarning { public static function triggerWarning(?closingWindow:Bool = false) { if (FlxG.state != null && FlxG.state is UIState) { FlxG.state.openSubState(new UIWarningSubstate("Unsaved Changes!", "Your changes will be lost if you don't save them. (Can't be recovered)\n\n\nWould you like to Cancel?", - [{ - label: closingWindow ? "Exit Game" : "Exit To Menu", - color: 0x969533, - onClick: function(_) { - if (!closingWindow) { - if (selectionClass != null) FlxG.switchState(Type.createInstance(SaveWarning.selectionClass, [])); - if (closingWindow) WindowUtils.resetClosing(); - } else { - WindowUtils.preventClosing = false; WindowUtils.resetClosing(); - Sys.exit(0); + [ + { + label: "Cancel", + color: 0x969533, + onClick: function (_) {if (closingWindow) WindowUtils.resetClosing();} + }, + { + label: closingWindow ? "Exit Game" : "Exit To Menu", + color: 0x969533, + onClick: function(_) { + if (!closingWindow) { + if (selectionClass != null) FlxG.switchState(Type.createInstance(SaveWarning.selectionClass, [])); + if (closingWindow) WindowUtils.resetClosing(); + } else { + WindowUtils.preventClosing = false; WindowUtils.resetClosing(); + Sys.exit(0); + } + } + }, + { + label: closingWindow ? "Save & Exit Game" : "Save&Exit To Menu", + color: 0x969533, + onClick: function(_) { + if (saveFunc != null) saveFunc(); + if (!closingWindow) { + if (selectionClass != null) FlxG.switchState(Type.createInstance(SaveWarning.selectionClass, [])); + if (closingWindow) WindowUtils.resetClosing(); + } else { + WindowUtils.preventClosing = false; WindowUtils.resetClosing(); + Sys.exit(0); + } } } - }, - { - label: "Cancel", - color: 0x969533, - onClick: function (_) {if (closingWindow) WindowUtils.resetClosing();} - }], false)); + ], false)); } } public static inline function reset() { SaveWarning.showWarning = false; SaveWarning.selectionClass = null; + SaveWarning.saveFunc = null; } } \ No newline at end of file diff --git a/source/funkin/editors/character/CharacterEditor.hx b/source/funkin/editors/character/CharacterEditor.hx index 4628b929..24166263 100644 --- a/source/funkin/editors/character/CharacterEditor.hx +++ b/source/funkin/editors/character/CharacterEditor.hx @@ -53,6 +53,8 @@ class CharacterEditor extends UIState { WindowUtils.endfix = " (Character Editor)"; SaveWarning.selectionClass = CharacterSelection; + SaveWarning.saveFunc = () -> {_file_save(null);}; + topMenu = [ { label: "File", diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx index 32d0a597..f5bc9219 100644 --- a/source/funkin/editors/charter/Charter.hx +++ b/source/funkin/editors/charter/Charter.hx @@ -101,6 +101,8 @@ class Charter extends UIState { WindowUtils.endfix = " (Chart Editor)"; SaveWarning.selectionClass = CharterSelection; + SaveWarning.saveFunc = () -> {_file_save(null);}; + topMenu = [ { label: "File",