Close #12412: Refactor PROMPT_MODE to use strong enum (#13076)

This commit is contained in:
Julia Pinheiro 2020-10-02 23:04:59 -03:00 committed by GitHub
parent 4c26fb09b3
commit 6a76547c5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 22 additions and 20 deletions

View File

@ -89,13 +89,13 @@ rct_window* window_save_prompt_open()
int32_t width, height;
rct_string_id stringId;
rct_window* window;
uint8_t prompt_mode;
PromptMode prompt_mode;
rct_widget* widgets;
uint64_t enabled_widgets;
prompt_mode = gSavePromptMode;
if (prompt_mode == PM_QUIT)
prompt_mode = PM_SAVE_BEFORE_QUIT;
if (prompt_mode == PromptMode::Quit)
prompt_mode = PromptMode::SaveBeforeQuit;
// do not show save prompt if we're in the title demo and click on load game
if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)
@ -141,7 +141,7 @@ rct_window* window_save_prompt_open()
height = WH_SAVE;
}
if (prompt_mode >= std::size(window_save_prompt_labels))
if (EnumValue(prompt_mode) >= std::size(window_save_prompt_labels))
{
log_warning("Invalid save prompt mode %u", prompt_mode);
return nullptr;
@ -162,13 +162,13 @@ rct_window* window_save_prompt_open()
window_invalidate_by_class(WC_TOP_TOOLBAR);
stringId = window_save_prompt_labels[prompt_mode][0];
stringId = window_save_prompt_labels[EnumValue(prompt_mode)][0];
if (stringId == STR_LOAD_GAME_PROMPT_TITLE && gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR)
stringId = STR_LOAD_LANDSCAPE_PROMPT_TITLE;
if (stringId == STR_QUIT_GAME_PROMPT_TITLE && gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR)
stringId = STR_QUIT_SCENARIO_EDITOR;
window_save_prompt_widgets[WIDX_TITLE].text = stringId;
window_save_prompt_widgets[WIDX_LABEL].text = window_save_prompt_labels[prompt_mode][1];
window_save_prompt_widgets[WIDX_LABEL].text = window_save_prompt_labels[EnumValue(prompt_mode)][1];
return window;
}

View File

@ -587,7 +587,7 @@ static void window_top_toolbar_dropdown(rct_window* w, rct_widgetindex widgetInd
{
window_close_by_class(WC_MANAGE_TRACK_DESIGN);
window_close_by_class(WC_TRACK_DELETE_PROMPT);
auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::OpenSavePrompt, PM_SAVE_BEFORE_QUIT);
auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::OpenSavePrompt, PromptMode::SaveBeforeQuit);
GameActions::Execute(&loadOrQuitAction);
break;
}

View File

@ -281,7 +281,7 @@ namespace OpenRCT2
void Quit() override
{
gSavePromptMode = PM_QUIT;
gSavePromptMode = PromptMode::Quit;
context_open_window(WC_SAVE_PROMPT);
}

View File

@ -813,7 +813,7 @@ void game_load_or_quit_no_save_prompt()
{
switch (gSavePromptMode)
{
case PM_SAVE_BEFORE_LOAD:
case PromptMode::SaveBeforeLoad:
{
auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::CloseSavePrompt);
GameActions::Execute(&loadOrQuitAction);
@ -831,7 +831,7 @@ void game_load_or_quit_no_save_prompt()
}
break;
}
case PM_SAVE_BEFORE_QUIT:
case PromptMode::SaveBeforeQuit:
{
auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::CloseSavePrompt);
GameActions::Execute(&loadOrQuitAction);

View File

@ -27,4 +27,4 @@ bool gOpenRCT2SilentBreakpad;
uint32_t gCurrentDrawCount = 0;
uint8_t gScreenFlags;
uint32_t gScreenAge;
uint8_t gSavePromptMode;
PromptMode gSavePromptMode;

View File

@ -13,6 +13,8 @@
#include <string>
enum class PromptMode : uint8_t;
enum class StartupAction
{
None,
@ -57,7 +59,7 @@ extern std::string gNetworkStartAddress;
extern uint32_t gCurrentDrawCount;
extern uint8_t gScreenFlags;
extern uint32_t gScreenAge;
extern uint8_t gSavePromptMode;
extern PromptMode gSavePromptMode;
void openrct2_write_full_version_info(utf8* buffer, size_t bufferSize);
void openrct2_finish();

View File

@ -23,14 +23,14 @@ DEFINE_GAME_ACTION(LoadOrQuitAction, GAME_COMMAND_LOAD_OR_QUIT, GameActionResult
{
private:
uint8_t _mode{ 0 };
uint8_t _savePromptMode{ PM_SAVE_BEFORE_LOAD };
PromptMode _savePromptMode{ PromptMode::SaveBeforeLoad };
public:
LoadOrQuitAction()
{
}
LoadOrQuitAction(LoadOrQuitModes mode, uint8_t savePromptMode = PM_SAVE_BEFORE_LOAD)
LoadOrQuitAction(LoadOrQuitModes mode, PromptMode savePromptMode = PromptMode::SaveBeforeLoad)
: _mode(static_cast<uint8_t>(mode))
, _savePromptMode(savePromptMode)
{

View File

@ -595,12 +595,12 @@ enum
#define WC_TILE_INSPECTOR__WIDX_CORRUPT_SPINNER_HEIGHT_INCREASE 26
#define WC_TILE_INSPECTOR__WIDX_CORRUPT_SPINNER_HEIGHT_DECREASE 27
enum PROMPT_MODE
enum class PromptMode : uint8_t
{
PM_SAVE_BEFORE_LOAD = 0,
PM_SAVE_BEFORE_QUIT,
PM_SAVE_BEFORE_QUIT2,
PM_QUIT
SaveBeforeLoad = 0,
SaveBeforeQuit,
SaveBeforeQuit2,
Quit
};
enum BTM_TOOLBAR_DIRTY_FLAGS

View File

@ -2703,7 +2703,7 @@ void NetworkBase::Client_Handle_MAP([[maybe_unused]] NetworkConnection& connecti
else
{
// Something went wrong, game is not loaded. Return to main screen.
auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::OpenSavePrompt, PM_SAVE_BEFORE_QUIT);
auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::OpenSavePrompt, PromptMode::SaveBeforeQuit);
GameActions::Execute(&loadOrQuitAction);
}
if (has_to_free)