1 /*
2 * Copyright 2010-2014 OpenXcom Developers.
3 *
4 * This file is part of OpenXcom.
5 *
6 * OpenXcom is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * OpenXcom is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include "PauseState.h"
20 #include "../Engine/Game.h"
21 #include "../Resource/ResourcePack.h"
22 #include "../Engine/Language.h"
23 #include "../Engine/Palette.h"
24 #include "../Interface/TextButton.h"
25 #include "../Interface/Window.h"
26 #include "../Interface/Text.h"
27 #include "AbandonGameState.h"
28 #include "ListLoadState.h"
29 #include "ListSaveState.h"
30 #include "../Engine/Options.h"
31 #include "OptionsVideoState.h"
32 #include "OptionsGeoscapeState.h"
33 #include "OptionsBattlescapeState.h"
34
35 namespace OpenXcom
36 {
37
38 /**
39 * Initializes all the elements in the Pause window.
40 * @param game Pointer to the core game.
41 * @param origin Game section that originated this state.
42 */
PauseState(Game * game,OptionsOrigin origin)43 PauseState::PauseState(Game *game, OptionsOrigin origin) : State(game), _origin(origin)
44 {
45 _screen = false;
46
47 int x;
48 if (_origin == OPT_GEOSCAPE)
49 {
50 x = 20;
51 }
52 else
53 {
54 x = 52;
55 }
56
57 // Create objects
58 _window = new Window(this, 216, 160, x, 20, POPUP_BOTH);
59 _btnLoad = new TextButton(180, 18, x+18, 52);
60 _btnSave = new TextButton(180, 18, x+18, 74);
61 _btnAbandon = new TextButton(180, 18, x+18, 96);
62 _btnOptions = new TextButton(180, 18, x+18, 122);
63 _btnCancel = new TextButton(180, 18, x+18, 150);
64 _txtTitle = new Text(206, 17, x+5, 32);
65
66 // Set palette
67 if (_origin == OPT_BATTLESCAPE)
68 {
69 setPalette("PAL_BATTLESCAPE");
70 }
71 else
72 {
73 setPalette("PAL_GEOSCAPE", 0);
74 }
75
76 add(_window);
77 add(_btnLoad);
78 add(_btnSave);
79 add(_btnAbandon);
80 add(_btnOptions);
81 add(_btnCancel);
82 add(_txtTitle);
83
84 centerAllSurfaces();
85
86 // Set up objects
87 _window->setColor(Palette::blockOffset(15)-1);
88 _window->setBackground(_game->getResourcePack()->getSurface("BACK01.SCR"));
89
90 _btnLoad->setColor(Palette::blockOffset(15)-1);
91 _btnLoad->setText(tr("STR_LOAD_GAME"));
92 _btnLoad->onMouseClick((ActionHandler)&PauseState::btnLoadClick);
93
94 _btnSave->setColor(Palette::blockOffset(15)-1);
95 _btnSave->setText(tr("STR_SAVE_GAME"));
96 _btnSave->onMouseClick((ActionHandler)&PauseState::btnSaveClick);
97
98 _btnAbandon->setColor(Palette::blockOffset(15)-1);
99 _btnAbandon->setText(tr("STR_ABANDON_GAME"));
100 _btnAbandon->onMouseClick((ActionHandler)&PauseState::btnAbandonClick);
101
102 _btnOptions->setColor(Palette::blockOffset(15)-1);
103 _btnOptions->setText(tr("STR_GAME_OPTIONS"));
104 _btnOptions->onMouseClick((ActionHandler)&PauseState::btnOptionsClick);
105
106 _btnCancel->setColor(Palette::blockOffset(15)-1);
107 _btnCancel->setText(tr("STR_CANCEL_UC"));
108 _btnCancel->onMouseClick((ActionHandler)&PauseState::btnCancelClick);
109 _btnCancel->onKeyboardPress((ActionHandler)&PauseState::btnCancelClick, Options::keyCancel);
110 if (origin == OPT_GEOSCAPE)
111 {
112 _btnCancel->onKeyboardPress((ActionHandler)&PauseState::btnCancelClick, Options::keyGeoOptions);
113 }
114 else if (origin == OPT_BATTLESCAPE)
115 {
116 _btnCancel->onKeyboardPress((ActionHandler)&PauseState::btnCancelClick, Options::keyBattleOptions);
117 }
118
119 _txtTitle->setColor(Palette::blockOffset(15)-1);
120 _txtTitle->setAlign(ALIGN_CENTER);
121 _txtTitle->setBig();
122 _txtTitle->setText(tr("STR_OPTIONS_UC"));
123
124 if (_origin == OPT_BATTLESCAPE)
125 {
126 applyBattlescapeTheme();
127 }
128
129 if (_game->getSavedGame()->isIronman())
130 {
131 _btnLoad->setVisible(false);
132 _btnSave->setVisible(false);
133 _btnAbandon->setText(tr("STR_SAVE_AND_ABANDON_GAME"));
134 }
135 }
136
137 /**
138 *
139 */
~PauseState()140 PauseState::~PauseState()
141 {
142
143 }
144
145 /**
146 * Opens the Load Game screen.
147 * @param action Pointer to an action.
148 */
btnLoadClick(Action *)149 void PauseState::btnLoadClick(Action *)
150 {
151 _game->pushState(new ListLoadState(_game, _origin));
152 }
153
154 /**
155 * Opens the Save Game screen.
156 * @param action Pointer to an action.
157 */
btnSaveClick(Action *)158 void PauseState::btnSaveClick(Action *)
159 {
160 _game->pushState(new ListSaveState(_game, _origin));
161 }
162
163 /**
164 * Opens the Game Options screen.
165 * @param action Pointer to an action.
166 */
btnOptionsClick(Action *)167 void PauseState::btnOptionsClick(Action *)
168 {
169 Options::backupDisplay();
170 if (_origin == OPT_GEOSCAPE)
171 {
172 _game->pushState(new OptionsGeoscapeState(_game, _origin));
173 }
174 else if (_origin == OPT_BATTLESCAPE)
175 {
176 _game->pushState(new OptionsBattlescapeState(_game, _origin));
177 }
178 else
179 {
180 _game->pushState(new OptionsVideoState(_game, _origin));
181 }
182 }
183
184 /**
185 * Opens the Abandon Game window.
186 * @param action Pointer to an action.
187 */
btnAbandonClick(Action *)188 void PauseState::btnAbandonClick(Action *)
189 {
190 _game->pushState(new AbandonGameState(_game, _origin));
191 }
192
193 /**
194 * Returns to the previous screen.
195 * @param action Pointer to an action.
196 */
btnCancelClick(Action *)197 void PauseState::btnCancelClick(Action *)
198 {
199 _game->popState();
200 }
201
202 }
203