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 "AlienTerrorState.h"
20 #include <sstream>
21 #include "../Engine/Game.h"
22 #include "../Resource/ResourcePack.h"
23 #include "../Engine/Language.h"
24 #include "../Engine/Palette.h"
25 #include "../Interface/TextButton.h"
26 #include "../Interface/Window.h"
27 #include "../Interface/Text.h"
28 #include "GeoscapeState.h"
29 #include "Globe.h"
30 #include "../Savegame/SavedGame.h"
31 #include "../Savegame/TerrorSite.h"
32 #include "../Engine/Options.h"
33 #include "InterceptState.h"
34
35 namespace OpenXcom
36 {
37
38 /**
39 * Initializes all the elements in the Aliens Terrorise window.
40 * @param game Pointer to the core game.
41 * @param terror Pointer to the respective Terror Site.
42 * @param city Terrorized city name.
43 * @param state Pointer to the Geoscape.
44 */
AlienTerrorState(Game * game,TerrorSite * terror,const std::string & city,GeoscapeState * state)45 AlienTerrorState::AlienTerrorState(Game *game, TerrorSite *terror, const std::string &city, GeoscapeState *state) : State(game), _terror(terror), _state(state)
46 {
47 _screen = false;
48
49 // Create objects
50 _window = new Window(this, 256, 200, 0, 0, POPUP_BOTH);
51 _btnIntercept = new TextButton(200, 16, 28, 130);
52 _btnCentre = new TextButton(200, 16, 28, 150);
53 _btnCancel = new TextButton(200, 16, 28, 170);
54 _txtTitle = new Text(246, 32, 5, 48);
55 _txtCity = new Text(246, 17, 5, 80);
56
57 // Set palette
58 setPalette("PAL_GEOSCAPE", 3);
59
60 add(_window);
61 add(_btnIntercept);
62 add(_btnCentre);
63 add(_btnCancel);
64 add(_txtTitle);
65 add(_txtCity);
66
67 centerAllSurfaces();
68
69 // Set up objects
70 _window->setColor(Palette::blockOffset(8)+5);
71 _window->setBackground(_game->getResourcePack()->getSurface("BACK03.SCR"));
72
73 _btnIntercept->setColor(Palette::blockOffset(8)+5);
74 _btnIntercept->setText(tr("STR_INTERCEPT"));
75 _btnIntercept->onMouseClick((ActionHandler)&AlienTerrorState::btnInterceptClick);
76
77 _btnCentre->setColor(Palette::blockOffset(8)+5);
78 _btnCentre->setText(tr("STR_CENTER_ON_SITE_TIME_5_SECONDS"));
79 _btnCentre->onMouseClick((ActionHandler)&AlienTerrorState::btnCentreClick);
80
81 _btnCancel->setColor(Palette::blockOffset(8)+5);
82 _btnCancel->setText(tr("STR_CANCEL_UC"));
83 _btnCancel->onMouseClick((ActionHandler)&AlienTerrorState::btnCancelClick);
84 _btnCancel->onKeyboardPress((ActionHandler)&AlienTerrorState::btnCancelClick, Options::keyCancel);
85
86 _txtTitle->setColor(Palette::blockOffset(8)+5);
87 _txtTitle->setBig();
88 _txtTitle->setAlign(ALIGN_CENTER);
89 _txtTitle->setWordWrap(true);
90 _txtTitle->setText(tr("STR_ALIENS_TERRORISE"));
91
92 _txtCity->setColor(Palette::blockOffset(8)+5);
93 _txtCity->setBig();
94 _txtCity->setAlign(ALIGN_CENTER);
95 _txtCity->setText(tr(city));
96 }
97
98 /**
99 *
100 */
~AlienTerrorState()101 AlienTerrorState::~AlienTerrorState()
102 {
103
104 }
105
106 /**
107 * Picks a craft to intercept the UFO.
108 * @param action Pointer to an action.
109 */
btnInterceptClick(Action *)110 void AlienTerrorState::btnInterceptClick(Action *)
111 {
112 _state->timerReset();
113 _state->getGlobe()->center(_terror->getLongitude(), _terror->getLatitude());
114 _game->pushState(new InterceptState(_game, _state->getGlobe(), 0, _terror));
115 }
116
117 /**
118 * Centers on the UFO and returns to the previous screen.
119 * @param action Pointer to an action.
120 */
btnCentreClick(Action *)121 void AlienTerrorState::btnCentreClick(Action *)
122 {
123 _state->timerReset();
124 _state->getGlobe()->center(_terror->getLongitude(), _terror->getLatitude());
125 _game->popState();
126 }
127
128 /**
129 * Returns to the previous screen.
130 * @param action Pointer to an action.
131 */
btnCancelClick(Action *)132 void AlienTerrorState::btnCancelClick(Action *)
133 {
134 _game->popState();
135 }
136
137 }
138