Repository navigation
Expand file tree
/
Copy pathNewGameState.cpp
More file actions
161 lines (142 loc) · 4.69 KB
/
Copy pathNewGameState.cpp
File metadata and controls
161 lines (142 loc) · 4.69 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* Copyright 2010-2012 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 "NewGameState.h"
#include "../Engine/Game.h"
#include "../Resource/ResourcePack.h"
#include "../Engine/Language.h"
#include "../Engine/Font.h"
#include "../Engine/Palette.h"
#include "../Interface/TextButton.h"
#include "../Interface/Window.h"
#include "../Interface/Text.h"
#include "../Ruleset/XcomRuleset.h"
#include "../Geoscape/GeoscapeState.h"
#include "../Geoscape/BuildNewBaseState.h"
namespace OpenXcom
{
/**
* Initializes all the elements in the Difficulty window.
* @param game Pointer to the core game.
*/
NewGameState::NewGameState(Game *game) : State(game)
{
// Create objects
_window = new Window(this, 192, 180, 64, 10, POPUP_VERTICAL);
_btnBeginner = new TextButton(160, 18, 80, 55);
_btnExperienced = new TextButton(160, 18, 80, 80);
_btnVeteran = new TextButton(160, 18, 80, 105);
_btnGenius = new TextButton(160, 18, 80, 130);
_btnSuperhuman = new TextButton(160, 18, 80, 155);
_txtTitle = new Text(192, 10, 64, 30);
add(_window);
add(_btnBeginner);
add(_btnExperienced);
add(_btnVeteran);
add(_btnGenius);
add(_btnSuperhuman);
add(_txtTitle);
// Set up objects
_window->setColor(Palette::blockOffset(8)+5);
_window->setBackground(_game->getResourcePack()->getSurface("BACK01.SCR"));
_btnBeginner->setColor(Palette::blockOffset(8)+5);
_btnBeginner->setText(_game->getLanguage()->getString("STR_1_BEGINNER"));
_btnBeginner->onMouseClick((ActionHandler)&NewGameState::btnBeginnerClick);
_btnExperienced->setColor(Palette::blockOffset(8)+5);
_btnExperienced->setText(_game->getLanguage()->getString("STR_2_EXPERIENCED"));
_btnExperienced->onMouseClick((ActionHandler)&NewGameState::btnExperiencedClick);
_btnVeteran->setColor(Palette::blockOffset(8)+5);
_btnVeteran->setText(_game->getLanguage()->getString("STR_3_VETERAN"));
_btnVeteran->onMouseClick((ActionHandler)&NewGameState::btnVeteranClick);
_btnGenius->setColor(Palette::blockOffset(8)+5);
_btnGenius->setText(_game->getLanguage()->getString("STR_4_GENIUS"));
_btnGenius->onMouseClick((ActionHandler)&NewGameState::btnGeniusClick);
_btnSuperhuman->setColor(Palette::blockOffset(8)+5);
_btnSuperhuman->setText(_game->getLanguage()->getString("STR_5_SUPERHUMAN"));
_btnSuperhuman->onMouseClick((ActionHandler)&NewGameState::btnSuperhumanClick);
_txtTitle->setColor(Palette::blockOffset(8)+10);
_txtTitle->setAlign(ALIGN_CENTER);
_txtTitle->setSmall();
_txtTitle->setText(_game->getLanguage()->getString("STR_SELECT_DIFFICULTY_LEVEL"));
}
/**
*
*/
NewGameState::~NewGameState()
{
}
/**
* Sets up a new saved game and jumps to the Geoscape.
* @param diff Difficulty for the saved game.
*/
void NewGameState::newGame(GameDifficulty diff)
{
//_game->setRuleset(new XcomRuleset());
_game->setSavedGame(_game->getRuleset()->newSave());
_game->getSavedGame()->setDifficulty(diff);
GeoscapeState *gs = new GeoscapeState(_game);
_game->setState(gs);
gs->init();
_game->pushState(new BuildNewBaseState(_game, _game->getSavedGame()->getBases()->back(), gs->getGlobe(), true));
}
/**
* Creates a new game in Beginner difficulty and
* jumps to the Geoscape screen.
* @param action Pointer to an action.
*/
void NewGameState::btnBeginnerClick(Action *action)
{
newGame(DIFF_BEGINNER);
}
/**
* Creates a new game in Experienced difficulty and
* jumps to the Geoscape screen.
* @param action Pointer to an action.
*/
void NewGameState::btnExperiencedClick(Action *action)
{
newGame(DIFF_EXPERIENCED);
}
/**
* Creates a new game in Veteran difficulty and
* jumps to the Geoscape screen.
* @param action Pointer to an action.
*/
void NewGameState::btnVeteranClick(Action *action)
{
newGame(DIFF_VETERAN);
}
/**
* Creates a new game in Genius difficulty and
* jumps to the Geoscape screen.
* @param action Pointer to an action.
*/
void NewGameState::btnGeniusClick(Action *action)
{
newGame(DIFF_GENIUS);
}
/**
* Creates a new game in Superhuman difficulty and
* jumps to the Geoscape screen.
* @param action Pointer to an action.
*/
void NewGameState::btnSuperhumanClick(Action *action)
{
newGame(DIFF_SUPERHUMAN);
}
}