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 "AlienBaseState.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/Region.h"
32 #include "../Savegame/Country.h"
33 #include "../Ruleset/RuleRegion.h"
34 #include "../Ruleset/RuleCountry.h"
35 #include "../Savegame/AlienBase.h"
36 #include "../Engine/Options.h"
37
38 namespace OpenXcom
39 {
40
41 /**
42 * Initializes all the elements in the Aliens Base discovered window.
43 * @param game Pointer to the core game.
44 * @param base Pointer to the alien base to get info from.
45 * @param state Pointer to the Geoscape.
46 */
AlienBaseState(Game * game,AlienBase * base,GeoscapeState * state)47 AlienBaseState::AlienBaseState(Game *game, AlienBase *base, GeoscapeState *state) : State(game), _state(state), _base(base)
48 {
49 // Create objects
50 _window = new Window(this, 320, 200, 0, 0);
51 _btnOk = new TextButton(50, 12, 135, 180);
52 _txtTitle = new Text(308, 60, 6, 60);
53
54 setPalette("PAL_GEOSCAPE", 3);
55
56 add(_window);
57 add(_btnOk);
58 add(_txtTitle);
59
60 centerAllSurfaces();
61
62
63 // Set up objects
64 _window->setColor(Palette::blockOffset(15)-1);
65 _window->setBackground(_game->getResourcePack()->getSurface("BACK13.SCR"));
66
67 _btnOk->setColor(Palette::blockOffset(8)+10);
68 _btnOk->setText(tr("STR_OK"));
69 _btnOk->onMouseClick((ActionHandler)&AlienBaseState::btnOkClick);
70 _btnOk->onKeyboardPress((ActionHandler)&AlienBaseState::btnOkClick, Options::keyOk);
71 _btnOk->onKeyboardPress((ActionHandler)&AlienBaseState::btnOkClick, Options::keyCancel);
72
73 _txtTitle->setColor(Palette::blockOffset(8)+5);
74 _txtTitle->setAlign(ALIGN_CENTER);
75 _txtTitle->setBig();
76 _txtTitle->setWordWrap(true);
77
78 // Check location of base
79 std::wstring region, country;
80 for (std::vector<Country*>::iterator i = _game->getSavedGame()->getCountries()->begin(); i != _game->getSavedGame()->getCountries()->end(); ++i)
81 {
82 if ((*i)->getRules()->insideCountry(_base->getLongitude(), _base->getLatitude()))
83 {
84 country = tr((*i)->getRules()->getType());
85 break;
86 }
87 }
88 for (std::vector<Region*>::iterator i = _game->getSavedGame()->getRegions()->begin(); i != _game->getSavedGame()->getRegions()->end(); ++i)
89 {
90 if ((*i)->getRules()->insideRegion(_base->getLongitude(), _base->getLatitude()))
91 {
92 region = tr((*i)->getRules()->getType());
93 break;
94 }
95 }
96 std::wstring location;
97 if (!country.empty())
98 {
99 location = tr("STR_COUNTRIES_COMMA").arg(country).arg(region);
100 }
101 else if (!region.empty())
102 {
103 location = region;
104 }
105 else
106 {
107 location = tr("STR_UNKNOWN");
108 }
109 _txtTitle->setText(tr("STR_XCOM_AGENTS_HAVE_LOCATED_AN_ALIEN_BASE_IN_REGION").arg(location));
110 }
111
112 /**
113 *
114 */
~AlienBaseState()115 AlienBaseState::~AlienBaseState()
116 {
117
118 }
119
120 /**
121 * Returns to the previous screen.
122 * @param action Pointer to an action.
123 */
btnOkClick(Action *)124 void AlienBaseState::btnOkClick(Action *)
125 {
126 _state->timerReset();
127 _state->getGlobe()->center(_base->getLongitude(), _base->getLatitude());
128 _game->popState();
129 }
130
131 }
132