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 "MainMenuState.h"
20 #include <sstream>
21 #include "../version.h"
22 #include "../Engine/Game.h"
23 #include "../Resource/ResourcePack.h"
24 #include "../Engine/Language.h"
25 #include "../Engine/Screen.h"
26 #include "../Engine/Palette.h"
27 #include "../Interface/TextButton.h"
28 #include "../Interface/Window.h"
29 #include "../Interface/Text.h"
30 #include "../Engine/Music.h"
31 #include "../Interface/Cursor.h"
32 #include "../Interface/FpsCounter.h"
33 #include "NewGameState.h"
34 #include "NewBattleState.h"
35 #include "ListLoadState.h"
36 #include "OptionsVideoState.h"
37 
38 namespace OpenXcom
39 {
40 
41 /**
42  * Initializes all the elements in the Main Menu window.
43  * @param game Pointer to the core game.
44  */
MainMenuState(Game * game)45 MainMenuState::MainMenuState(Game *game) : State(game)
46 {
47 	// Create objects
48 	_window = new Window(this, 256, 160, 32, 20, POPUP_BOTH);
49 	_btnNewGame = new TextButton(92, 20, 64, 90);
50 	_btnNewBattle = new TextButton(92, 20, 164, 90);
51 	_btnLoad = new TextButton(92, 20, 64, 118);
52 	_btnOptions = new TextButton(92, 20, 164, 118);
53 	_btnQuit = new TextButton(192, 20, 64, 146);
54 	_txtTitle = new Text(256, 30, 32, 45);
55 
56 	// Set palette
57 	setPalette("PAL_GEOSCAPE", 0);
58 
59 	add(_window);
60 	add(_btnNewGame);
61 	add(_btnNewBattle);
62 	add(_btnLoad);
63 	add(_btnOptions);
64 	add(_btnQuit);
65 	add(_txtTitle);
66 
67 	centerAllSurfaces();
68 
69 	// Set up objects
70 	_window->setColor(Palette::blockOffset(8)+5);
71 	_window->setBackground(_game->getResourcePack()->getSurface("BACK01.SCR"));
72 
73 	_btnNewGame->setColor(Palette::blockOffset(8)+5);
74 	_btnNewGame->setText(tr("STR_NEW_GAME"));
75 	_btnNewGame->onMouseClick((ActionHandler)&MainMenuState::btnNewGameClick);
76 
77 	_btnNewBattle->setColor(Palette::blockOffset(8)+5);
78 	_btnNewBattle->setText(tr("STR_NEW_BATTLE"));
79 	_btnNewBattle->onMouseClick((ActionHandler)&MainMenuState::btnNewBattleClick);
80 
81 	_btnLoad->setColor(Palette::blockOffset(8)+5);
82 	_btnLoad->setText(tr("STR_LOAD_SAVED_GAME"));
83 	_btnLoad->onMouseClick((ActionHandler)&MainMenuState::btnLoadClick);
84 
85 	_btnOptions->setColor(Palette::blockOffset(8)+5);
86 	_btnOptions->setText(tr("STR_OPTIONS"));
87 	_btnOptions->onMouseClick((ActionHandler)&MainMenuState::btnOptionsClick);
88 
89 	_btnQuit->setColor(Palette::blockOffset(8)+5);
90 	_btnQuit->setText(tr("STR_QUIT"));
91 	_btnQuit->onMouseClick((ActionHandler)&MainMenuState::btnQuitClick);
92 
93 	_txtTitle->setColor(Palette::blockOffset(8)+10);
94 	_txtTitle->setAlign(ALIGN_CENTER);
95 	_txtTitle->setBig();
96 	std::wostringstream title;
97 	title << tr("STR_OPENXCOM") << L"\x02";
98 	title << Language::utf8ToWstr(OPENXCOM_VERSION_SHORT) << Language::utf8ToWstr(OPENXCOM_VERSION_GIT);
99 	_txtTitle->setText(title.str());
100 
101 	// Set music
102 	_game->getResourcePack()->playMusic("GMSTORY");
103 
104 	_game->getCursor()->setColor(Palette::blockOffset(15)+12);
105 	_game->getFpsCounter()->setColor(Palette::blockOffset(15)+12);
106 }
107 
108 /**
109  *
110  */
~MainMenuState()111 MainMenuState::~MainMenuState()
112 {
113 
114 }
115 
116 /**
117  * Opens the New Game window.
118  * @param action Pointer to an action.
119  */
btnNewGameClick(Action *)120 void MainMenuState::btnNewGameClick(Action *)
121 {
122 	_game->pushState(new NewGameState(_game));
123 }
124 
125 /**
126  * Opens the New Battle screen.
127  * @param action Pointer to an action.
128  */
btnNewBattleClick(Action *)129 void MainMenuState::btnNewBattleClick(Action *)
130 {
131 	_game->pushState(new NewBattleState(_game));
132 }
133 
134 /**
135  * Opens the Load Game screen.
136  * @param action Pointer to an action.
137  */
btnLoadClick(Action *)138 void MainMenuState::btnLoadClick(Action *)
139 {
140 	_game->pushState(new ListLoadState(_game, OPT_MENU));
141 }
142 
143 /**
144  * Opens the Options screen.
145  * @param action Pointer to an action.
146  */
btnOptionsClick(Action *)147 void MainMenuState::btnOptionsClick(Action *)
148 {
149 	Options::backupDisplay();
150 	_game->pushState(new OptionsVideoState(_game, OPT_MENU));
151 }
152 
153 /**
154  * Quits the game.
155  * @param action Pointer to an action.
156  */
btnQuitClick(Action *)157 void MainMenuState::btnQuitClick(Action *)
158 {
159 	_game->quit();
160 }
161 
162 /**
163  * Updates the scale.
164  * @param dX delta of X;
165  * @param dY delta of Y;
166  */
resize(int & dX,int & dY)167 void MainMenuState::resize(int &dX, int &dY)
168 {
169 	dX = Options::baseXResolution;
170 	dY = Options::baseYResolution;
171 	Screen::updateScale(Options::geoscapeScale, Options::geoscapeScale, Options::baseXGeoscape, Options::baseYGeoscape, true);
172 	dX = Options::baseXResolution - dX;
173 	dY = Options::baseYResolution - dY;
174 	State::resize(dX, dY);
175 }
176 }
177