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 "MonthlyCostsState.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/Base.h"
31 #include "../Savegame/SavedGame.h"
32 #include "../Ruleset/Ruleset.h"
33 #include "../Ruleset/RuleCraft.h"
34
35 namespace OpenXcom
36 {
37
38 /**
39 * Initializes all the elements in the Monthly Costs screen.
40 * @param game Pointer to the core game.
41 * @param base Pointer to the base to get info from.
42 */
MonthlyCostsState(Game * game,Base * base)43 MonthlyCostsState::MonthlyCostsState(Game *game, Base *base) : State(game), _base(base)
44 {
45 // Create objects
46 _window = new Window(this, 320, 200, 0, 0);
47 _btnOk = new TextButton(300, 20, 10, 170);
48 _txtTitle = new Text(310, 17, 5, 12);
49 _txtCost = new Text(80, 9, 115, 32);
50 _txtQuantity = new Text(55, 9, 195, 32);
51 _txtTotal = new Text(60, 9, 249, 32);
52 _txtRental = new Text(150, 9, 10, 48);
53 _txtSalaries = new Text(150, 9, 10, 80);
54 _txtIncome = new Text(150, 9, 10, 136);
55 _lstCrafts = new TextList(288, 24, 10, 56);
56 _lstSalaries = new TextList(300, 30, 10, 88);
57 _lstMaintenance = new TextList(300, 9, 10, 120);
58 _lstTotal = new TextList(100, 9, 205, 136);
59
60 // Set palette
61 setPalette("PAL_BASESCAPE", 6);
62
63 add(_window);
64 add(_btnOk);
65 add(_txtTitle);
66 add(_txtCost);
67 add(_txtQuantity);
68 add(_txtTotal);
69 add(_txtRental);
70 add(_txtSalaries);
71 add(_txtIncome);
72 add(_lstCrafts);
73 add(_lstSalaries);
74 add(_lstMaintenance);
75 add(_lstTotal);
76
77 centerAllSurfaces();
78
79 // Set up objects
80 _window->setColor(Palette::blockOffset(15)+1);
81 _window->setBackground(_game->getResourcePack()->getSurface("BACK13.SCR"));
82
83 _btnOk->setColor(Palette::blockOffset(15)+1);
84 _btnOk->setText(tr("STR_OK"));
85 _btnOk->onMouseClick((ActionHandler)&MonthlyCostsState::btnOkClick);
86 _btnOk->onKeyboardPress((ActionHandler)&MonthlyCostsState::btnOkClick, Options::keyOk);
87 _btnOk->onKeyboardPress((ActionHandler)&MonthlyCostsState::btnOkClick, Options::keyCancel);
88
89 _txtTitle->setColor(Palette::blockOffset(15)+1);
90 _txtTitle->setBig();
91 _txtTitle->setAlign(ALIGN_CENTER);
92 _txtTitle->setText(tr("STR_MONTHLY_COSTS"));
93
94 _txtCost->setColor(Palette::blockOffset(15)+1);
95 _txtCost->setText(tr("STR_COST_PER_UNIT"));
96
97 _txtQuantity->setColor(Palette::blockOffset(15)+1);
98 _txtQuantity->setText(tr("STR_QUANTITY"));
99
100 _txtTotal->setColor(Palette::blockOffset(15)+1);
101 _txtTotal->setText(tr("STR_TOTAL"));
102
103 _txtRental->setColor(Palette::blockOffset(15)+1);
104 _txtRental->setText(tr("STR_CRAFT_RENTAL"));
105
106 _txtSalaries->setColor(Palette::blockOffset(15)+1);
107 _txtSalaries->setText(tr("STR_SALARIES"));
108
109 _txtIncome->setColor(Palette::blockOffset(13)+10);
110 std::wostringstream ss;
111 ss << tr("STR_INCOME") << L"=" << Text::formatFunding(_game->getSavedGame()->getCountryFunding());
112 _txtIncome->setText(ss.str());
113
114 _lstCrafts->setColor(Palette::blockOffset(13)+10);
115 _lstCrafts->setColumns(4, 125, 70, 44, 60);
116 _lstCrafts->setDot(true);
117
118 const std::vector<std::string> &crafts = _game->getRuleset()->getCraftsList();
119 for (std::vector<std::string>::const_iterator i = crafts.begin(); i != crafts.end(); ++i)
120 {
121 RuleCraft *craft = _game->getRuleset()->getCraft(*i);
122 if (craft->getRentCost() != 0 && _game->getSavedGame()->isResearched(craft->getRequirements()))
123 {
124 std::wostringstream ss2;
125 ss2 << _base->getCraftCount((*i));
126 _lstCrafts->addRow(4, tr(*i).c_str(), Text::formatFunding(craft->getRentCost()).c_str(), ss2.str().c_str(), Text::formatFunding(_base->getCraftCount(*i) * craft->getRentCost()).c_str());
127 }
128 }
129
130 _lstSalaries->setColor(Palette::blockOffset(13)+10);
131 _lstSalaries->setColumns(4, 125, 70, 44, 60);
132 _lstSalaries->setDot(true);
133
134 std::wostringstream ss4;
135 ss4 << _base->getSoldiers()->size();
136 _lstSalaries->addRow(4, tr("STR_SOLDIERS").c_str(), Text::formatFunding(_game->getRuleset()->getSoldierCost()).c_str(), ss4.str().c_str(), Text::formatFunding(_base->getSoldiers()->size() * _game->getRuleset()->getSoldierCost()).c_str());
137 std::wostringstream ss5;
138 ss5 << _base->getTotalEngineers();
139 _lstSalaries->addRow(4, tr("STR_ENGINEERS").c_str(), Text::formatFunding(_game->getRuleset()->getEngineerCost()).c_str(), ss5.str().c_str(), Text::formatFunding(_base->getTotalEngineers() * _game->getRuleset()->getEngineerCost()).c_str());
140 std::wostringstream ss6;
141 ss6 << _base->getTotalScientists();
142 _lstSalaries->addRow(4, tr("STR_SCIENTISTS").c_str(), Text::formatFunding(_game->getRuleset()->getScientistCost()).c_str(), ss6.str().c_str(), Text::formatFunding(_base->getTotalScientists() * _game->getRuleset()->getScientistCost()).c_str());
143
144 _lstMaintenance->setColor(Palette::blockOffset(13)+10);
145 _lstMaintenance->setColumns(2, 239, 60);
146 _lstMaintenance->setDot(true);
147 _lstMaintenance->addRow(2, tr("STR_BASE_MAINTENANCE").c_str(), Text::formatFunding(_base->getFacilityMaintenance()).c_str());
148 _lstMaintenance->setCellColor(0, 0, Palette::blockOffset(15)+1);
149
150 _lstTotal->setColor(Palette::blockOffset(13));
151 _lstTotal->setColumns(2, 44, 55);
152 _lstTotal->setDot(true);
153 _lstTotal->addRow(2, tr("STR_TOTAL").c_str(), Text::formatFunding(_base->getMonthlyMaintenace()).c_str());
154 }
155
156 /**
157 *
158 */
~MonthlyCostsState()159 MonthlyCostsState::~MonthlyCostsState()
160 {
161
162 }
163
164 /**
165 * Returns to the previous screen.
166 * @param action Pointer to an action.
167 */
btnOkClick(Action *)168 void MonthlyCostsState::btnOkClick(Action *)
169 {
170 _game->popState();
171 }
172
173 }
174