diff --git a/src/openrct2-ui/input/KeyboardShortcut.cpp b/src/openrct2-ui/input/KeyboardShortcut.cpp index 99324a88ba..291fc6cc0e 100644 --- a/src/openrct2-ui/input/KeyboardShortcut.cpp +++ b/src/openrct2-ui/input/KeyboardShortcut.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -729,7 +730,8 @@ static void shortcut_load_game() { if (!(gScreenFlags & (SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER))) { - game_do_command(0, 1, 0, 0, GAME_COMMAND_LOAD_OR_QUIT, 0, 0); + auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::OpenSavePrompt); + GameActions::Execute(&loadOrQuitAction); } } diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index 1c3dae22f2..9a75289a6f 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -467,7 +468,8 @@ static void window_editor_object_selection_mouseup(rct_window* w, rct_widgetinde case WIDX_CLOSE: if (gScreenFlags & SCREEN_FLAGS_EDITOR) { - game_do_command(0, 1, 0, 0, GAME_COMMAND_LOAD_OR_QUIT, 1, 0); + auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::OpenSavePrompt, 1); + GameActions::Execute(&loadOrQuitAction); } else { diff --git a/src/openrct2-ui/windows/TitleMenu.cpp b/src/openrct2-ui/windows/TitleMenu.cpp index 630d94ed02..54ed089a81 100644 --- a/src/openrct2-ui/windows/TitleMenu.cpp +++ b/src/openrct2-ui/windows/TitleMenu.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -153,7 +154,8 @@ static void window_title_menu_mouseup(rct_window* w, rct_widgetindex widgetIndex { window_close_by_class(WC_SCENARIO_SELECT); window_close_by_class(WC_SERVER_LIST); - game_do_command(0, 1, 0, 0, GAME_COMMAND_LOAD_OR_QUIT, 0, 0); + auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::OpenSavePrompt); + GameActions::Execute(&loadOrQuitAction); } break; case WIDX_MULTIPLAYER: diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index 48280cd28b..a59b053920 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -587,8 +588,11 @@ static void window_top_toolbar_dropdown(rct_window* w, rct_widgetindex widgetInd break; } case DDIDX_LOAD_GAME: - game_do_command(0, 1, 0, 0, GAME_COMMAND_LOAD_OR_QUIT, 0, 0); + { + auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::OpenSavePrompt); + GameActions::Execute(&loadOrQuitAction); break; + } case DDIDX_SAVE_GAME: tool_cancel(); save_game(); @@ -620,10 +624,13 @@ static void window_top_toolbar_dropdown(rct_window* w, rct_widgetindex widgetInd screenshot_giant(); break; case DDIDX_QUIT_TO_MENU: + { window_close_by_class(WC_MANAGE_TRACK_DESIGN); window_close_by_class(WC_TRACK_DELETE_PROMPT); - game_do_command(0, 1, 0, 0, GAME_COMMAND_LOAD_OR_QUIT, 1, 0); + auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::OpenSavePrompt, 1); + GameActions::Execute(&loadOrQuitAction); break; + } case DDIDX_EXIT_OPENRCT2: context_quit(); break; @@ -3054,7 +3061,8 @@ static void window_top_toolbar_tool_drag(rct_window* w, rct_widgetindex widgetIn game_do_command( gMapSelectPositionA.x, 1, gMapSelectPositionA.y, gLandToolTerrainSurface | (gLandToolTerrainEdge << 8), GAME_COMMAND_CHANGE_SURFACE_STYLE, gMapSelectPositionB.x, gMapSelectPositionB.y); - // The tool is set to 12 here instead of 3 so that the dragging cursor is not the elevation change cursor + // The tool is set to 12 here instead of 3 so that the dragging cursor is not the elevation change + // cursor gCurrentToolId = TOOL_CROSSHAIR; } } diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 0b206b8174..6fc0828593 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -17,6 +17,7 @@ #include "OpenRCT2.h" #include "ParkImporter.h" #include "ReplayManager.h" +#include "actions/LoadOrQuitAction.hpp" #include "audio/audio.h" #include "config/Config.h" #include "core/FileScanner.h" @@ -1280,7 +1281,9 @@ void game_load_or_quit_no_save_prompt() switch (gSavePromptMode) { case PM_SAVE_BEFORE_LOAD: - game_do_command(0, 1, 0, 1, GAME_COMMAND_LOAD_OR_QUIT, 0, 0); + { + auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::CloseSavePrompt); + GameActions::Execute(&loadOrQuitAction); tool_cancel(); if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) { @@ -1294,8 +1297,11 @@ void game_load_or_quit_no_save_prompt() context_open_intent(&intent); } break; + } case PM_SAVE_BEFORE_QUIT: - game_do_command(0, 1, 0, 1, GAME_COMMAND_LOAD_OR_QUIT, 0, 0); + { + auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::CloseSavePrompt); + GameActions::Execute(&loadOrQuitAction); tool_cancel(); if (input_test_flag(INPUT_FLAG_5)) { @@ -1305,6 +1311,7 @@ void game_load_or_quit_no_save_prompt() gFirstTimeSaving = true; title_load(); break; + } default: openrct2_finish(); break; diff --git a/src/openrct2/actions/GameActionRegistration.cpp b/src/openrct2/actions/GameActionRegistration.cpp index ccd395562e..f64b646f9c 100644 --- a/src/openrct2/actions/GameActionRegistration.cpp +++ b/src/openrct2/actions/GameActionRegistration.cpp @@ -41,6 +41,7 @@ #include "TrackPlaceAction.hpp" #include "TrackRemoveAction.hpp" #include "WallRemoveAction.hpp" +#include "LoadOrQuitAction.hpp" namespace GameActions { @@ -79,5 +80,6 @@ namespace GameActions Register(); Register(); Register(); + Register(); } } // namespace GameActions diff --git a/src/openrct2/actions/LoadOrQuitAction.hpp b/src/openrct2/actions/LoadOrQuitAction.hpp new file mode 100644 index 0000000000..2a925ac8a7 --- /dev/null +++ b/src/openrct2/actions/LoadOrQuitAction.hpp @@ -0,0 +1,73 @@ +/***************************************************************************** + * Copyright (c) 2014-2018 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +#include "GameAction.h" +#include "../OpenRCT2.h" + +enum class LoadOrQuitModes : uint8_t +{ + OpenSavePrompt, + CloseSavePrompt +}; + +DEFINE_GAME_ACTION(LoadOrQuitAction, GAME_COMMAND_LOAD_OR_QUIT, GameActionResult) +{ +private: + uint8_t _mode{ 0 }; + uint8_t _savePromptMode{ 0 }; + +public: + LoadOrQuitAction() + { + } + + LoadOrQuitAction(LoadOrQuitModes mode, uint8_t savePromptMode = 0) + : _mode(static_cast(mode)) + , _savePromptMode(savePromptMode) + { + } + + uint16_t GetActionFlags() const override + { + return GameAction::GetActionFlags() | GA_FLAGS::CLIENT_ONLY | GA_FLAGS::ALLOW_WHILE_PAUSED; + } + + void Serialise(DataSerialiser & stream) override + { + GameAction::Serialise(stream); + + stream << DS_TAG(_mode) << DS_TAG(_savePromptMode); + } + + GameActionResult::Ptr Query() const override + { + return std::make_unique(); + } + + GameActionResult::Ptr Execute() const override + { + auto mode = static_cast(_mode); + switch (mode) + { + case LoadOrQuitModes::OpenSavePrompt: + gSavePromptMode = _savePromptMode; + context_open_window(WC_SAVE_PROMPT); + break; + case LoadOrQuitModes::CloseSavePrompt: + window_close_by_class(WC_SAVE_PROMPT); + break; + default: + game_load_or_quit_no_save_prompt(); + break; + } + return std::make_unique(); + } +}; diff --git a/src/openrct2/network/Network.cpp b/src/openrct2/network/Network.cpp index 77a73becea..adca75d8a9 100644 --- a/src/openrct2/network/Network.cpp +++ b/src/openrct2/network/Network.cpp @@ -13,6 +13,7 @@ #include "../Game.h" #include "../OpenRCT2.h" #include "../PlatformEnvironment.h" +#include "../actions/LoadOrQuitAction.hpp" #include "../core/Guard.hpp" #include "../platform/platform.h" #include "../ui/UiContext.h" @@ -2551,7 +2552,8 @@ void Network::Client_Handle_MAP([[maybe_unused]] NetworkConnection& connection, else { // Something went wrong, game is not loaded. Return to main screen. - game_do_command(0, GAME_COMMAND_FLAG_APPLY, 0, 0, GAME_COMMAND_LOAD_OR_QUIT, 1, 0); + auto loadOrQuitAction = LoadOrQuitAction(LoadOrQuitModes::OpenSavePrompt, 1); + GameActions::Execute(&loadOrQuitAction); } if (has_to_free) {