diff --git a/src/openrct2-ui/WindowManager.cpp b/src/openrct2-ui/WindowManager.cpp index f476eba83b..0157b6847f 100644 --- a/src/openrct2-ui/WindowManager.cpp +++ b/src/openrct2-ui/WindowManager.cpp @@ -264,7 +264,7 @@ public: TrackDesign* trackDesign = static_cast(intent->GetPointerExtra(INTENT_EXTRA_TRACK_DESIGN)); auto* w = FileBrowser::OpenPreferred( type, defaultPath, - [callback](int32_t result, std::string_view path) { + [callback](ModalResult result, std::string_view path) { if (callback != nullptr) { callback(result, std::string(path).c_str()); diff --git a/src/openrct2-ui/interface/FileBrowser.cpp b/src/openrct2-ui/interface/FileBrowser.cpp index 46856e0d99..e2453e73eb 100644 --- a/src/openrct2-ui/interface/FileBrowser.cpp +++ b/src/openrct2-ui/interface/FileBrowser.cpp @@ -195,12 +195,12 @@ namespace OpenRCT2::Ui::FileBrowser return result; } - void RegisterCallback(std::function callback) + void RegisterCallback(std::function callback) { _loadSaveCallback = callback; } - void InvokeCallback(int32_t result, const utf8* path) + void InvokeCallback(ModalResult result, const utf8* path) { if (_loadSaveCallback != nullptr) { @@ -233,7 +233,7 @@ namespace OpenRCT2::Ui::FileBrowser SetAndSaveConfigPath(Config::Get().general.LastSaveGameDirectory, pathBuffer); if (GetContext()->LoadParkFromFile(pathBuffer)) { - InvokeCallback(MODAL_RESULT_OK, pathBuffer); + InvokeCallback(ModalResult::ok, pathBuffer); windowMgr->CloseByClass(WindowClass::Loadsave); GfxInvalidateScreen(); } @@ -245,7 +245,7 @@ namespace OpenRCT2::Ui::FileBrowser // Not the best message... ContextShowError(STR_LOAD_GAME, STR_FAILED_TO_LOAD_FILE_CONTAINS_INVALID_DATA, {}); } - InvokeCallback(MODAL_RESULT_FAIL, pathBuffer); + InvokeCallback(ModalResult::fail, pathBuffer); } break; @@ -261,12 +261,12 @@ namespace OpenRCT2::Ui::FileBrowser windowMgr->CloseByClass(WindowClass::Loadsave); GfxInvalidateScreen(); - InvokeCallback(MODAL_RESULT_OK, pathBuffer); + InvokeCallback(ModalResult::ok, pathBuffer); } else { ContextShowError(STR_SAVE_GAME, STR_GAME_SAVE_FAILED, {}); - InvokeCallback(MODAL_RESULT_FAIL, pathBuffer); + InvokeCallback(ModalResult::fail, pathBuffer); } break; @@ -276,13 +276,13 @@ namespace OpenRCT2::Ui::FileBrowser { gCurrentLoadedPath = pathBuffer; GfxInvalidateScreen(); - InvokeCallback(MODAL_RESULT_OK, pathBuffer); + InvokeCallback(ModalResult::ok, pathBuffer); } else { // Not the best message... ContextShowError(STR_LOAD_LANDSCAPE, STR_FAILED_TO_LOAD_FILE_CONTAINS_INVALID_DATA, {}); - InvokeCallback(MODAL_RESULT_FAIL, pathBuffer); + InvokeCallback(ModalResult::fail, pathBuffer); } break; @@ -294,12 +294,12 @@ namespace OpenRCT2::Ui::FileBrowser gCurrentLoadedPath = pathBuffer; windowMgr->CloseByClass(WindowClass::Loadsave); GfxInvalidateScreen(); - InvokeCallback(MODAL_RESULT_OK, pathBuffer); + InvokeCallback(ModalResult::ok, pathBuffer); } else { ContextShowError(STR_SAVE_LANDSCAPE, STR_LANDSCAPE_SAVE_FAILED, {}); - InvokeCallback(MODAL_RESULT_FAIL, pathBuffer); + InvokeCallback(ModalResult::fail, pathBuffer); } break; @@ -316,7 +316,7 @@ namespace OpenRCT2::Ui::FileBrowser if (success) { windowMgr->CloseByClass(WindowClass::Loadsave); - InvokeCallback(MODAL_RESULT_OK, pathBuffer); + InvokeCallback(ModalResult::ok, pathBuffer); auto* context = GetContext(); context->SetActiveScene(context->GetTitleScene()); @@ -325,7 +325,7 @@ namespace OpenRCT2::Ui::FileBrowser { ContextShowError(STR_FILE_DIALOG_TITLE_SAVE_SCENARIO, STR_SCENARIO_SAVE_FAILED, {}); gameState.EditorStep = EditorStep::ObjectiveSelection; - InvokeCallback(MODAL_RESULT_FAIL, pathBuffer); + InvokeCallback(ModalResult::fail, pathBuffer); } break; } @@ -337,7 +337,7 @@ namespace OpenRCT2::Ui::FileBrowser intent.PutExtra(INTENT_EXTRA_PATH, std::string{ pathBuffer }); ContextOpenIntent(&intent); windowMgr->CloseByClass(WindowClass::Loadsave); - InvokeCallback(MODAL_RESULT_OK, pathBuffer); + InvokeCallback(ModalResult::ok, pathBuffer); break; } @@ -356,19 +356,19 @@ namespace OpenRCT2::Ui::FileBrowser { windowMgr->CloseByClass(WindowClass::Loadsave); Windows::WindowRideMeasurementsDesignCancel(); - InvokeCallback(MODAL_RESULT_OK, path); + InvokeCallback(ModalResult::ok, path); } else { ContextShowError(STR_FILE_DIALOG_TITLE_SAVE_TRACK, STR_TRACK_SAVE_FAILED, {}); - InvokeCallback(MODAL_RESULT_FAIL, path); + InvokeCallback(ModalResult::fail, path); } break; } case (LOADSAVETYPE_LOAD | LOADSAVETYPE_HEIGHTMAP): windowMgr->CloseByClass(WindowClass::Loadsave); - InvokeCallback(MODAL_RESULT_OK, pathBuffer); + InvokeCallback(ModalResult::ok, pathBuffer); break; } } diff --git a/src/openrct2-ui/interface/FileBrowser.h b/src/openrct2-ui/interface/FileBrowser.h index baf4855785..184fc6c69d 100644 --- a/src/openrct2-ui/interface/FileBrowser.h +++ b/src/openrct2-ui/interface/FileBrowser.h @@ -15,6 +15,7 @@ #include #include +enum class ModalResult : int8_t; struct TrackDesign; namespace OpenRCT2 @@ -44,7 +45,7 @@ namespace OpenRCT2::Ui::FileBrowser bool loaded{ false }; }; - using LoadSaveCallback = std::function; + using LoadSaveCallback = std::function; bool ListItemSort(LoadSaveListItem& a, LoadSaveListItem& b); void SetAndSaveConfigPath(u8string& config_str, u8string_view path); @@ -54,8 +55,8 @@ namespace OpenRCT2::Ui::FileBrowser const char* GetFilterPatternByType(const int32_t type, const bool isSave); u8string RemovePatternWildcard(u8string_view pattern); u8string GetDir(const int32_t type); - void RegisterCallback(std::function callback); - void InvokeCallback(int32_t result, const utf8* path); + void RegisterCallback(std::function callback); + void InvokeCallback(ModalResult result, const utf8* path); void Select(const char* path, int32_t type, TrackDesign* trackDesignPtr); StringId GetTitleStringId(int32_t type, bool isSave); u8string OpenSystemFileBrowser(bool isSave, int32_t type, u8string defaultDirectory, u8string defaultPath); diff --git a/src/openrct2-ui/scripting/ScUi.hpp b/src/openrct2-ui/scripting/ScUi.hpp index 996dcc56c6..0f5ed93f9d 100644 --- a/src/openrct2-ui/scripting/ScUi.hpp +++ b/src/openrct2-ui/scripting/ScUi.hpp @@ -287,8 +287,8 @@ namespace OpenRCT2::Scripting LoadsaveOpen( loadSaveType, defaultPath, - [this, plugin, callback](int32_t result, std::string_view path) { - if (result == MODAL_RESULT_OK) + [this, plugin, callback](ModalResult result, std::string_view path) { + if (result == ModalResult::ok) { auto dukValue = ToDuk(_scriptEngine.GetContext(), path); _scriptEngine.ExecutePluginCall(plugin, callback, { dukValue }, false); diff --git a/src/openrct2-ui/windows/MapGen.cpp b/src/openrct2-ui/windows/MapGen.cpp index dde484d2ec..8e5d942aad 100644 --- a/src/openrct2-ui/windows/MapGen.cpp +++ b/src/openrct2-ui/windows/MapGen.cpp @@ -260,7 +260,7 @@ namespace OpenRCT2::Ui::Windows Y, }; - static void HeightmapLoadsaveCallback(int32_t result, const utf8* path); + static void HeightmapLoadsaveCallback(ModalResult result, const utf8* path); class MapGenWindow final : public Window { @@ -1504,9 +1504,9 @@ namespace OpenRCT2::Ui::Windows } } - void AfterLoadingHeightMap(int32_t result, const utf8* path) + void AfterLoadingHeightMap(ModalResult result, const utf8* path) { - if (result == MODAL_RESULT_OK) + if (result == ModalResult::ok) { if (!MapGenerator::LoadHeightmapImage(path)) { @@ -1534,7 +1534,7 @@ namespace OpenRCT2::Ui::Windows return windowMgr->FocusOrCreate(WindowClass::Mapgen, WW, WH, WF_10 | WF_AUTO_POSITION | WF_CENTRE_SCREEN); } - static void HeightmapLoadsaveCallback(int32_t result, const utf8* path) + static void HeightmapLoadsaveCallback(ModalResult result, const utf8* path) { auto* w = static_cast(MapgenOpen()); w->AfterLoadingHeightMap(result, path); diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index fb26010eb6..6ea613c2cb 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -5378,9 +5378,9 @@ namespace OpenRCT2::Ui::Windows } } - static void TrackDesignCallback(int32_t result, [[maybe_unused]] const utf8* path) + static void TrackDesignCallback(ModalResult result, [[maybe_unused]] const utf8* path) { - if (result == MODAL_RESULT_OK) + if (result == ModalResult::ok) { TrackRepositoryScan(); } diff --git a/src/openrct2-ui/windows/SavePrompt.cpp b/src/openrct2-ui/windows/SavePrompt.cpp index c6a9615279..29fcb65c5e 100644 --- a/src/openrct2-ui/windows/SavePrompt.cpp +++ b/src/openrct2-ui/windows/SavePrompt.cpp @@ -73,9 +73,9 @@ namespace OpenRCT2::Ui::Windows { STR_NEW_GAME, STR_SAVE_BEFORE_QUITTING }, }; - static void WindowSavePromptCallback(int32_t result, const utf8* path) + static void WindowSavePromptCallback(ModalResult result, const utf8* path) { - if (result == MODAL_RESULT_OK) + if (result == ModalResult::ok) { GameLoadOrQuitNoSavePrompt(); } diff --git a/src/openrct2-ui/windows/ServerStart.cpp b/src/openrct2-ui/windows/ServerStart.cpp index 4bd5750a35..50282e5574 100644 --- a/src/openrct2-ui/windows/ServerStart.cpp +++ b/src/openrct2-ui/windows/ServerStart.cpp @@ -271,9 +271,9 @@ namespace OpenRCT2::Ui::Windows } } - static void LoadSaveCallback(int32_t result, const utf8* path) + static void LoadSaveCallback(ModalResult result, const utf8* path) { - if (result == MODAL_RESULT_OK) + if (result == ModalResult::ok) { GameNotifyMapChange(); GetContext()->LoadParkFromFile(path); diff --git a/src/openrct2-ui/windows/Windows.h b/src/openrct2-ui/windows/Windows.h index 013907362a..84e771d9a7 100644 --- a/src/openrct2-ui/windows/Windows.h +++ b/src/openrct2-ui/windows/Windows.h @@ -29,7 +29,7 @@ struct Vehicle; enum class GuestListFilterType : int32_t; enum class ScatterToolDensity : uint8_t; -using LoadSaveCallback = void (*)(int32_t result, const utf8* path); +using LoadSaveCallback = void (*)(ModalResult result, const utf8* path); using ScenarioSelectCallback = void (*)(const utf8* path); namespace OpenRCT2::Ui::Windows @@ -133,7 +133,7 @@ namespace OpenRCT2::Ui::Windows // LoadSave WindowBase* LoadsaveOpen( - int32_t type, std::string_view defaultPath, std::function callback, + int32_t type, std::string_view defaultPath, std::function callback, TrackDesign* trackDesign); void WindowLoadSaveInputKey(WindowBase* w, uint32_t keycode); diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index eb07114ef5..a67c572302 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -56,7 +56,7 @@ namespace OpenRCT2::Editor { static std::array, EnumValue(ObjectType::count)> _editorSelectedObjectFlags; - static void ConvertSaveToScenarioCallback(int32_t result, const utf8* path); + static void ConvertSaveToScenarioCallback(ModalResult result, const utf8* path); static void SetAllLandOwned(); static void FinaliseMainView(); static void ClearMapForEditing(bool fromSave); @@ -131,9 +131,9 @@ namespace OpenRCT2::Editor ContextOpenIntent(&intent); } - static void ConvertSaveToScenarioCallback(int32_t result, const utf8* path) + static void ConvertSaveToScenarioCallback(ModalResult result, const utf8* path) { - if (result != MODAL_RESULT_OK) + if (result != ModalResult::ok) { return; } diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 6173bbe02f..21a23a74ac 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -612,9 +612,9 @@ void GameAutosave() Console::Error::WriteLine("Could not autosave the scenario. Is the save folder writeable?"); } -static void GameLoadOrQuitNoSavePromptCallback(int32_t result, const utf8* path) +static void GameLoadOrQuitNoSavePromptCallback(ModalResult result, const utf8* path) { - if (result == MODAL_RESULT_OK) + if (result == ModalResult::ok) { GameNotifyMapChange(); GameUnloadScripts(); diff --git a/src/openrct2/interface/Window.h b/src/openrct2/interface/Window.h index 9e76743220..f764c839bb 100644 --- a/src/openrct2/interface/Window.h +++ b/src/openrct2/interface/Window.h @@ -225,11 +225,11 @@ enum LOADSAVETYPE_HEIGHTMAP = 4 << 1, }; -enum +enum class ModalResult : int8_t { - MODAL_RESULT_FAIL = -1, - MODAL_RESULT_CANCEL, - MODAL_RESULT_OK + fail = -1, + cancel, + ok, }; enum class VisibilityCache : uint8_t @@ -282,7 +282,6 @@ namespace OpenRCT2 extern Tool gCurrentToolId; extern WidgetRef gCurrentToolWidget; - using modal_callback = void (*)(int32_t result); using CloseCallback = void (*)(); constexpr int8_t kWindowLimitMin = 4;