mirror of https://github.com/OpenRCT2/OpenRCT2.git
Add LoadOrQuiteAction
This commit is contained in:
parent
b7db6cb03b
commit
eadef45ffd
|
@ -18,6 +18,7 @@
|
|||
#include <openrct2/Game.h>
|
||||
#include <openrct2/Input.h>
|
||||
#include <openrct2/OpenRCT2.h>
|
||||
#include <openrct2/actions/LoadOrQuitAction.hpp>
|
||||
#include <openrct2/audio/audio.h>
|
||||
#include <openrct2/config/Config.h>
|
||||
#include <openrct2/interface/Chat.h>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <openrct2/EditorObjectSelectionSession.h>
|
||||
#include <openrct2/Game.h>
|
||||
#include <openrct2/OpenRCT2.h>
|
||||
#include <openrct2/actions/LoadOrQuitAction.hpp>
|
||||
#include <openrct2/audio/audio.h>
|
||||
#include <openrct2/config/Config.h>
|
||||
#include <openrct2/core/String.hpp>
|
||||
|
@ -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
|
||||
{
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <openrct2/Input.h>
|
||||
#include <openrct2/ParkImporter.h>
|
||||
#include <openrct2/PlatformEnvironment.h>
|
||||
#include <openrct2/actions/LoadOrQuitAction.hpp>
|
||||
#include <openrct2/config/Config.h>
|
||||
#include <openrct2/localisation/Localisation.h>
|
||||
#include <openrct2/sprites.h>
|
||||
|
@ -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:
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <openrct2/OpenRCT2.h>
|
||||
#include <openrct2/ParkImporter.h>
|
||||
#include <openrct2/actions/ClearAction.hpp>
|
||||
#include <openrct2/actions/LoadOrQuitAction.hpp>
|
||||
#include <openrct2/actions/PauseToggleAction.hpp>
|
||||
#include <openrct2/audio/audio.h>
|
||||
#include <openrct2/config/Config.h>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<TrackRemoveAction>();
|
||||
Register<ClearAction>();
|
||||
Register<PauseToggleAction>();
|
||||
Register<LoadOrQuitAction>();
|
||||
}
|
||||
} // namespace GameActions
|
||||
|
|
|
@ -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<uint8_t>(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>();
|
||||
}
|
||||
|
||||
GameActionResult::Ptr Execute() const override
|
||||
{
|
||||
auto mode = static_cast<LoadOrQuitModes>(_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<GameActionResult>();
|
||||
}
|
||||
};
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue