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 "NewGameState.h"
20 #include "../Engine/Game.h"
21 #include "../Resource/ResourcePack.h"
22 #include "../Ruleset/Ruleset.h"
23 #include "../Engine/Language.h"
24 #include "../Engine/Palette.h"
25 #include "../Interface/TextButton.h"
26 #include "../Interface/ToggleTextButton.h"
27 #include "../Interface/Window.h"
28 #include "../Interface/Text.h"
29 #include "../Geoscape/GeoscapeState.h"
30 #include "../Geoscape/BuildNewBaseState.h"
31 #include "../Engine/Options.h"
32
33 namespace OpenXcom
34 {
35
36 /**
37 * Initializes all the elements in the Difficulty window.
38 * @param game Pointer to the core game.
39 */
NewGameState(Game * game)40 NewGameState::NewGameState(Game *game) : State(game)
41 {
42 // Create objects
43 _window = new Window(this, 192, 180, 64, 10, POPUP_VERTICAL);
44 _btnBeginner = new TextButton(160, 18, 80, 32);
45 _btnExperienced = new TextButton(160, 18, 80, 52);
46 _btnVeteran = new TextButton(160, 18, 80, 72);
47 _btnGenius = new TextButton(160, 18, 80, 92);
48 _btnSuperhuman = new TextButton(160, 18, 80, 112);
49 _btnIronman = new ToggleTextButton(78, 18, 80, 138);
50 _btnOk = new TextButton(78, 16, 80, 164);
51 _btnCancel = new TextButton(78, 16, 162, 164);
52 _txtTitle = new Text(192, 9, 64, 20);
53 _txtIronman = new Text(90, 24, 162, 135);
54
55 _difficulty = _btnBeginner;
56
57 // Set palette
58 setPalette("PAL_GEOSCAPE", 0);
59
60 add(_window);
61 add(_btnBeginner);
62 add(_btnExperienced);
63 add(_btnVeteran);
64 add(_btnGenius);
65 add(_btnSuperhuman);
66 add(_btnIronman);
67 add(_btnOk);
68 add(_btnCancel);
69 add(_txtTitle);
70 add(_txtIronman);
71
72 centerAllSurfaces();
73
74 // Set up objects
75 _window->setColor(Palette::blockOffset(8)+5);
76 _window->setBackground(_game->getResourcePack()->getSurface("BACK01.SCR"));
77
78 _btnBeginner->setColor(Palette::blockOffset(8)+5);
79 _btnBeginner->setText(tr("STR_1_BEGINNER"));
80 _btnBeginner->setGroup(&_difficulty);
81
82 _btnExperienced->setColor(Palette::blockOffset(8)+5);
83 _btnExperienced->setText(tr("STR_2_EXPERIENCED"));
84 _btnExperienced->setGroup(&_difficulty);
85
86 _btnVeteran->setColor(Palette::blockOffset(8)+5);
87 _btnVeteran->setText(tr("STR_3_VETERAN"));
88 _btnVeteran->setGroup(&_difficulty);
89
90 _btnGenius->setColor(Palette::blockOffset(8)+5);
91 _btnGenius->setText(tr("STR_4_GENIUS"));
92 _btnGenius->setGroup(&_difficulty);
93
94 _btnSuperhuman->setColor(Palette::blockOffset(8)+5);
95 _btnSuperhuman->setText(tr("STR_5_SUPERHUMAN"));
96 _btnSuperhuman->setGroup(&_difficulty);
97
98 _btnIronman->setColor(Palette::blockOffset(8)+10);
99 _btnIronman->setText(tr("STR_IRONMAN"));
100
101 _btnOk->setColor(Palette::blockOffset(8)+5);
102 _btnOk->setText(tr("STR_OK"));
103 _btnOk->onMouseClick((ActionHandler)&NewGameState::btnOkClick);
104 _btnOk->onKeyboardPress((ActionHandler)&NewGameState::btnOkClick, Options::keyOk);
105
106 _btnCancel->setColor(Palette::blockOffset(8)+5);
107 _btnCancel->setText(tr("STR_CANCEL"));
108 _btnCancel->onMouseClick((ActionHandler)&NewGameState::btnCancelClick);
109 _btnCancel->onKeyboardPress((ActionHandler)&NewGameState::btnCancelClick, Options::keyCancel);
110
111 _txtTitle->setColor(Palette::blockOffset(8)+10);
112 _txtTitle->setAlign(ALIGN_CENTER);
113 _txtTitle->setText(tr("STR_SELECT_DIFFICULTY_LEVEL"));
114
115 _txtIronman->setColor(Palette::blockOffset(8)+10);
116 _txtIronman->setWordWrap(true);
117 _txtIronman->setVerticalAlign(ALIGN_MIDDLE);
118 _txtIronman->setText(tr("STR_IRONMAN_DESC"));
119 }
120
121 /**
122 *
123 */
~NewGameState()124 NewGameState::~NewGameState()
125 {
126
127 }
128
129 /**
130 * Returns to the previous screen.
131 * @param action Pointer to an action.
132 */
btnOkClick(Action *)133 void NewGameState::btnOkClick(Action *)
134 {
135 GameDifficulty diff;
136 if (_difficulty == _btnBeginner)
137 {
138 diff = DIFF_BEGINNER;
139 }
140 else if (_difficulty == _btnExperienced)
141 {
142 diff = DIFF_EXPERIENCED;
143 }
144 else if (_difficulty == _btnVeteran)
145 {
146 diff = DIFF_VETERAN;
147 }
148 else if (_difficulty == _btnGenius)
149 {
150 diff = DIFF_GENIUS;
151 }
152 else if (_difficulty == _btnSuperhuman)
153 {
154 diff = DIFF_SUPERHUMAN;
155 }
156 SavedGame *save = _game->getRuleset()->newSave();
157 save->setDifficulty(diff);
158 save->setIronman(_btnIronman->getPressed());
159 _game->setSavedGame(save);
160
161 GeoscapeState *gs = new GeoscapeState(_game);
162 _game->setState(gs);
163 gs->init();
164 _game->pushState(new BuildNewBaseState(_game, _game->getSavedGame()->getBases()->back(), gs->getGlobe(), true));
165 }
166
167 /**
168 * Returns to the previous screen.
169 * @param action Pointer to an action.
170 */
btnCancelClick(Action *)171 void NewGameState::btnCancelClick(Action *)
172 {
173 _game->setSavedGame(0);
174 _game->popState();
175 }
176
177 }
178