forked from OpenXcom/OpenXcom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadState.cpp
More file actions
145 lines (133 loc) · 4.24 KB
/
Copy pathLoadState.cpp
File metadata and controls
145 lines (133 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* Copyright 2010-2013 OpenXcom Developers.
*
* This file is part of OpenXcom.
*
* OpenXcom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenXcom is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include "LoadState.h"
#include "../Engine/Logger.h"
#include "../Savegame/SavedGame.h"
#include "../Savegame/SavedBattleGame.h"
#include "../Engine/Game.h"
#include "../Engine/Exception.h"
#include "../Engine/Language.h"
#include "../Engine/Palette.h"
#include "../Engine/Action.h"
#include "../Interface/Text.h"
#include "../Interface/TextList.h"
#include "../Geoscape/GeoscapeState.h"
#include "ErrorMessageState.h"
#include "../Battlescape/BattlescapeState.h"
#include "DeleteGameState.h"
namespace OpenXcom
{
/**
* Initializes all the elements in the Load Game screen.
* @param game Pointer to the core game.
* @param geo True to use Geoscape palette, false to use Battlescape palette.
*/
LoadState::LoadState(Game *game, bool geo) : SavedGameState(game, geo)
{
// Set up objects
_txtTitle->setText(_game->getLanguage()->getString("STR_SELECT_GAME_TO_LOAD"));
_lstSaves->onMousePress((ActionHandler)&LoadState::lstSavesPress);
}
/**
* Creates the Quick Load Game state.
* @param game Pointer to the core game.
* @param geo True to use Geoscape palette, false to use Battlescape palette.
* @param showMsg True if need to show messages like "Loading game" or "Saving game".
*/
LoadState::LoadState(Game *game, bool geo, bool showMsg) : SavedGameState(game, geo, showMsg)
{
quickLoad(L"autosave");
}
/**
*
*/
LoadState::~LoadState()
{
}
/**
* Loads the selected save.
* @param action Pointer to an action.
*/
void LoadState::lstSavesPress(Action *action)
{
if (action->getDetails()->button.button == SDL_BUTTON_LEFT)
{
quickLoad(_lstSaves->getCellText(_lstSaves->getSelectedRow(), 0));
}
else if (action->getDetails()->button.button == SDL_BUTTON_RIGHT)
{
_game->pushState(new DeleteGameState(_game, _geo, _lstSaves->getCellText(_lstSaves->getSelectedRow(), 0), this));
}
}
/**
* Quick load game.
* @param filename16 name of file without ".sav"
*/
void LoadState::quickLoad(const std::wstring &filename16)
{
if (_showMsg) updateStatus("STR_LOADING_GAME");
#ifdef _WIN32
std::string filename = Language::wstrToCp(filename16);
#else
std::string filename = Language::wstrToUtf8(filename16);
#endif
SavedGame *s = new SavedGame();
try
{
s->load(filename, _game->getRuleset());
_game->setSavedGame(s);
_game->setState(new GeoscapeState(_game));
if (_game->getSavedGame()->getSavedBattle() != 0)
{
_game->getSavedGame()->getSavedBattle()->loadMapResources(_game);
BattlescapeState *bs = new BattlescapeState(_game);
_game->pushState(bs);
_game->getSavedGame()->getSavedBattle()->setBattleState(bs);
}
}
catch (Exception &e)
{
Log(LOG_ERROR) << e.what();
std::wstringstream error;
error << _game->getLanguage()->getString("STR_LOAD_UNSUCCESSFUL") << L'\x02' << Language::utf8ToWstr(e.what());
if (_geo)
_game->pushState(new ErrorMessageState(_game, error.str(), Palette::blockOffset(8)+10, "BACK01.SCR", 6));
else
_game->pushState(new ErrorMessageState(_game, error.str(), Palette::blockOffset(0), "TAC00.SCR", -1));
if (_game->getSavedGame() == s)
_game->setSavedGame(0);
else
delete s;
}
catch (YAML::Exception &e)
{
Log(LOG_ERROR) << e.what();
std::wstringstream error;
error << _game->getLanguage()->getString("STR_LOAD_UNSUCCESSFUL") << L'\x02' << Language::utf8ToWstr(e.what());
if (_geo)
_game->pushState(new ErrorMessageState(_game, error.str(), Palette::blockOffset(8)+10, "BACK01.SCR", 6));
else
_game->pushState(new ErrorMessageState(_game, error.str(), Palette::blockOffset(0), "TAC00.SCR", -1));
if (_game->getSavedGame() == s)
_game->setSavedGame(0);
else
delete s;
}
}
}