diff --git a/src/openrct2-ui/interface/FileBrowser.cpp b/src/openrct2-ui/interface/FileBrowser.cpp index 0a0727f82a..0fc656bbf9 100644 --- a/src/openrct2-ui/interface/FileBrowser.cpp +++ b/src/openrct2-ui/interface/FileBrowser.cpp @@ -196,7 +196,7 @@ namespace OpenRCT2::Ui::FileBrowser return result; } - void RegisterCallback(std::function callback) + void RegisterCallback(LoadSaveCallback callback) { _loadSaveCallback = callback; } diff --git a/src/openrct2-ui/interface/FileBrowser.h b/src/openrct2-ui/interface/FileBrowser.h index f4754f92c1..7593135f61 100644 --- a/src/openrct2-ui/interface/FileBrowser.h +++ b/src/openrct2-ui/interface/FileBrowser.h @@ -58,7 +58,7 @@ namespace OpenRCT2::Ui::FileBrowser const char* GetFilterPatternByType(const LoadSaveType type, const bool isSave); u8string RemovePatternWildcard(u8string_view pattern); u8string GetDir(const LoadSaveType type); - void RegisterCallback(std::function callback); + void RegisterCallback(LoadSaveCallback callback); void InvokeCallback(ModalResult result, const utf8* path); void Select(const char* path, LoadSaveAction action, LoadSaveType type, TrackDesign* trackDesignPtr); StringId GetTitleStringId(LoadSaveType type, bool isSave); diff --git a/src/openrct2-ui/windows/EditorBottomToolbar.cpp b/src/openrct2-ui/windows/EditorBottomToolbar.cpp index 60d9fe48ff..7aab0b3b1d 100644 --- a/src/openrct2-ui/windows/EditorBottomToolbar.cpp +++ b/src/openrct2-ui/windows/EditorBottomToolbar.cpp @@ -271,19 +271,34 @@ namespace OpenRCT2::Ui::Windows GfxInvalidateScreen(); } + static void SaveScenarioCallback(ModalResult result, const utf8* path) + { + if (result == ModalResult::ok) + { + GameUnloadScripts(); + } + else + { + getGameState().editorStep = EditorStep::ScenarioDetails; + } + } + void JumpForwardToSaveScenario() const { auto& gameState = getGameState(); + gameState.editorStep = EditorStep::SaveScenario; + GfxInvalidateScreen(); + const auto savePrepareResult = ScenarioPrepareForSave(gameState); if (!savePrepareResult.Successful) { ContextShowError(STR_UNABLE_TO_SAVE_SCENARIO_FILE, savePrepareResult.Message, {}); - GfxInvalidateScreen(); return; } auto* windowMgr = Ui::GetWindowManager(); windowMgr->CloseAll(); + auto intent = Intent(WindowClass::Loadsave); intent.PutEnumExtra(INTENT_EXTRA_LOADSAVE_ACTION, LoadSaveAction::save); intent.PutEnumExtra(INTENT_EXTRA_LOADSAVE_TYPE, LoadSaveType::scenario); @@ -292,16 +307,6 @@ namespace OpenRCT2::Ui::Windows ContextOpenIntent(&intent); } - static void SaveScenarioCallback(ModalResult result, const utf8* path) - { - if (result != ModalResult::ok) - { - return; - } - - GameUnloadScripts(); - } - void HidePreviousStepButton() { widgets[WIDX_PREVIOUS_STEP_BUTTON].type = WindowWidgetType::Empty; diff --git a/src/openrct2-ui/windows/LoadSave.cpp b/src/openrct2-ui/windows/LoadSave.cpp index 2de63cc7fe..e64ce7a970 100644 --- a/src/openrct2-ui/windows/LoadSave.cpp +++ b/src/openrct2-ui/windows/LoadSave.cpp @@ -764,6 +764,7 @@ namespace OpenRCT2::Ui::Windows switch (widgetIndex) { case WIDX_CLOSE: + InvokeCallback(ModalResult::cancel, ""); Close(); break;