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 "TransferBaseState.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 "../Engine/Options.h"
26 #include "../Interface/TextButton.h"
27 #include "../Interface/Window.h"
28 #include "../Interface/Text.h"
29 #include "../Interface/TextList.h"
30 #include "../Savegame/SavedGame.h"
31 #include "../Savegame/Base.h"
32 #include "../Savegame/Region.h"
33 #include "../Ruleset/RuleRegion.h"
34 #include "TransferItemsState.h"
35
36 namespace OpenXcom
37 {
38
39 /**
40 * Initializes all the elements in the Select Destination Base window.
41 * @param game Pointer to the core game.
42 * @param base Pointer to the base to get info from.
43 */
TransferBaseState(Game * game,Base * base)44 TransferBaseState::TransferBaseState(Game *game, Base *base) : State(game), _base(base), _bases()
45 {
46 // Create objects
47 _window = new Window(this, 280, 140, 20, 30);
48 _btnCancel = new TextButton(264, 16, 28, 146);
49 _txtTitle = new Text(270, 17, 25, 38);
50 _txtFunds = new Text(250, 9, 30, 54);
51 _txtName = new Text(130, 17, 28, 64);
52 _txtArea = new Text(130, 17, 160, 64);
53 _lstBases = new TextList(248, 64, 28, 80);
54
55 // Set palette
56 setPalette("PAL_BASESCAPE", 4);
57
58 add(_window);
59 add(_btnCancel);
60 add(_txtTitle);
61 add(_txtFunds);
62 add(_txtName);
63 add(_txtArea);
64 add(_lstBases);
65
66 centerAllSurfaces();
67
68 // Set up objects
69 _window->setColor(Palette::blockOffset(13)+5);
70 _window->setBackground(_game->getResourcePack()->getSurface("BACK13.SCR"));
71
72 _btnCancel->setColor(Palette::blockOffset(13)+5);
73 _btnCancel->setText(tr("STR_CANCEL"));
74 _btnCancel->onMouseClick((ActionHandler)&TransferBaseState::btnCancelClick);
75 _btnCancel->onKeyboardPress((ActionHandler)&TransferBaseState::btnCancelClick, Options::keyCancel);
76
77 _txtTitle->setColor(Palette::blockOffset(13)+5);
78 _txtTitle->setBig();
79 _txtTitle->setAlign(ALIGN_CENTER);
80 _txtTitle->setText(tr("STR_SELECT_DESTINATION_BASE"));
81
82 _txtFunds->setColor(Palette::blockOffset(13)+5);
83 _txtFunds->setSecondaryColor(Palette::blockOffset(13));
84 _txtFunds->setText(tr("STR_CURRENT_FUNDS").arg(Text::formatFunding(_game->getSavedGame()->getFunds())));
85
86 _txtName->setColor(Palette::blockOffset(13)+5);
87 _txtName->setText(tr("STR_NAME"));
88 _txtName->setBig();
89
90 _txtArea->setColor(Palette::blockOffset(13)+5);
91 _txtArea->setText(tr("STR_AREA"));
92 _txtArea->setBig();
93
94 _lstBases->setColor(Palette::blockOffset(15)+1);
95 _lstBases->setArrowColor(Palette::blockOffset(13)+5);
96 _lstBases->setColumns(2, 130, 116);
97 _lstBases->setSelectable(true);
98 _lstBases->setBackground(_window);
99 _lstBases->setMargin(2);
100 _lstBases->onMouseClick((ActionHandler)&TransferBaseState::lstBasesClick);
101
102 int row = 0;
103 for (std::vector<Base*>::iterator i = _game->getSavedGame()->getBases()->begin(); i != _game->getSavedGame()->getBases()->end(); ++i)
104 {
105 if ((*i) != _base)
106 {
107 // Get area
108 std::wstring area = L"";
109 for (std::vector<Region*>::iterator j = _game->getSavedGame()->getRegions()->begin(); j != _game->getSavedGame()->getRegions()->end(); ++j)
110 {
111 if ((*j)->getRules()->insideRegion((*i)->getLongitude(), (*i)->getLatitude()))
112 {
113 area = tr((*j)->getRules()->getType());
114 break;
115 }
116 }
117
118 _lstBases->addRow(2, (*i)->getName().c_str(), area.c_str());
119 _lstBases->setCellColor(row, 1, Palette::blockOffset(13)+5);
120 _bases.push_back(*i);
121 row++;
122 }
123 }
124 }
125
126 /**
127 *
128 */
~TransferBaseState()129 TransferBaseState::~TransferBaseState()
130 {
131 }
132
133 /**
134 * Returns to the previous screen.
135 * @param action Pointer to an action.
136 */
btnCancelClick(Action *)137 void TransferBaseState::btnCancelClick(Action *)
138 {
139 _game->popState();
140 }
141
142 /**
143 * Shows the Transfer screen for the selected base.
144 * @param action Pointer to an action.
145 */
lstBasesClick(Action *)146 void TransferBaseState::lstBasesClick(Action *)
147 {
148 _game->pushState(new TransferItemsState(_game, _base, _bases[_lstBases->getSelectedRow()]));
149 }
150
151 }
152