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 "PlaceLiftState.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 "BaseView.h"
29 #include "../Savegame/Base.h"
30 #include "../Savegame/BaseFacility.h"
31 #include "../Ruleset/RuleBaseFacility.h"
32 #include "../Ruleset/Ruleset.h"
33 #include "BasescapeState.h"
34 #include "SelectStartFacilityState.h"
35 #include "../Savegame/SavedGame.h"
36
37 namespace OpenXcom
38 {
39
40 /**
41 * Initializes all the elements in the Place Lift screen.
42 * @param game Pointer to the core game.
43 * @param base Pointer to the base to get info from.
44 * @param globe Pointer to the Geoscape globe.
45 * @param first Is this a custom starting base?
46 */
PlaceLiftState(Game * game,Base * base,Globe * globe,bool first)47 PlaceLiftState::PlaceLiftState(Game *game, Base *base, Globe *globe, bool first) : State(game), _base(base), _globe(globe), _first(first)
48 {
49 // Create objects
50 _view = new BaseView(192, 192, 0, 8);
51 _txtTitle = new Text(320, 9, 0, 0);
52
53 // Set palette
54 setPalette("PAL_BASESCAPE");
55
56 add(_view);
57 add(_txtTitle);
58
59 centerAllSurfaces();
60
61 // Set up objects
62 _view->setTexture(_game->getResourcePack()->getSurfaceSet("BASEBITS.PCK"));
63 _view->setBase(_base);
64 _view->setSelectable(_game->getRuleset()->getBaseFacility("STR_ACCESS_LIFT")->getSize());
65 _view->onMouseClick((ActionHandler)&PlaceLiftState::viewClick);
66
67 _txtTitle->setColor(Palette::blockOffset(13)+10);
68 _txtTitle->setText(tr("STR_SELECT_POSITION_FOR_ACCESS_LIFT"));
69 }
70
71 /**
72 *
73 */
~PlaceLiftState()74 PlaceLiftState::~PlaceLiftState()
75 {
76
77 }
78
79 /**
80 * Processes clicking on facilities.
81 * @param action Pointer to an action.
82 */
viewClick(Action *)83 void PlaceLiftState::viewClick(Action *)
84 {
85 BaseFacility *fac = new BaseFacility(_game->getRuleset()->getBaseFacility("STR_ACCESS_LIFT"), _base);
86 fac->setX(_view->getGridX());
87 fac->setY(_view->getGridY());
88 _base->getFacilities()->push_back(fac);
89 _game->popState();
90 BasescapeState *bState = new BasescapeState(_game, _base, _globe);
91 _game->getSavedGame()->setSelectedBase(_game->getSavedGame()->getBases()->size() - 1);
92 _game->pushState(bState);
93 if (_first)
94 {
95 _game->pushState(new SelectStartFacilityState(_game, _base, bState, _globe));
96 }
97 }
98
99 }
100