mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-06 06:32:56 +01:00
Refactor MODAL_RESULT_* to enum
This commit is contained in:
@@ -264,7 +264,7 @@ public:
|
||||
TrackDesign* trackDesign = static_cast<TrackDesign*>(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());
|
||||
|
||||
@@ -195,12 +195,12 @@ namespace OpenRCT2::Ui::FileBrowser
|
||||
return result;
|
||||
}
|
||||
|
||||
void RegisterCallback(std::function<void(int32_t result, std::string_view)> callback)
|
||||
void RegisterCallback(std::function<void(ModalResult result, std::string_view)> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <openrct2/localisation/StringIdType.h>
|
||||
#include <string>
|
||||
|
||||
enum class ModalResult : int8_t;
|
||||
struct TrackDesign;
|
||||
|
||||
namespace OpenRCT2
|
||||
@@ -44,7 +45,7 @@ namespace OpenRCT2::Ui::FileBrowser
|
||||
bool loaded{ false };
|
||||
};
|
||||
|
||||
using LoadSaveCallback = std::function<void(int32_t result, std::string_view)>;
|
||||
using LoadSaveCallback = std::function<void(ModalResult result, std::string_view)>;
|
||||
|
||||
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<void(int32_t result, std::string_view)> callback);
|
||||
void InvokeCallback(int32_t result, const utf8* path);
|
||||
void RegisterCallback(std::function<void(ModalResult result, std::string_view)> 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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<MapGenWindow>(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<MapGenWindow*>(MapgenOpen());
|
||||
w->AfterLoadingHeightMap(result, path);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<void(int32_t result, std::string_view)> callback,
|
||||
int32_t type, std::string_view defaultPath, std::function<void(ModalResult result, std::string_view)> callback,
|
||||
TrackDesign* trackDesign);
|
||||
void WindowLoadSaveInputKey(WindowBase* w, uint32_t keycode);
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace OpenRCT2::Editor
|
||||
{
|
||||
static std::array<std::vector<uint8_t>, 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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user