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 "FundingState.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 "../Interface/TextList.h"
29 #include "../Savegame/Country.h"
30 #include "../Ruleset/RuleCountry.h"
31 #include "../Savegame/SavedGame.h"
32 #include "../Engine/Options.h"
33
34 namespace OpenXcom
35 {
36
37 /**
38 * Initializes all the elements in the Funding screen.
39 * @param game Pointer to the core game.
40 */
FundingState(Game * game)41 FundingState::FundingState(Game *game) : State(game)
42 {
43 _screen = false;
44
45 // Create objects
46 _window = new Window(this, 320, 200, 0, 0, POPUP_BOTH);
47 _btnOk = new TextButton(50, 12, 135, 180);
48 _txtTitle = new Text(320, 17, 0, 8);
49 _txtCountry = new Text(100, 9, 32, 30);
50 _txtFunding = new Text(100, 9, 140, 30);
51 _txtChange = new Text(72, 9, 240, 30);
52 _lstCountries = new TextList(260, 136, 32, 40);
53
54 // Set palette
55 setPalette("PAL_GEOSCAPE", 0);
56
57 add(_window);
58 add(_btnOk);
59 add(_txtTitle);
60 add(_txtCountry);
61 add(_txtFunding);
62 add(_txtChange);
63 add(_lstCountries);
64
65 centerAllSurfaces();
66
67 // Set up objects
68 _window->setColor(Palette::blockOffset(15)-1);
69 _window->setBackground(_game->getResourcePack()->getSurface("BACK13.SCR"));
70
71 _btnOk->setColor(Palette::blockOffset(15)-1);
72 _btnOk->setText(tr("STR_OK"));
73 _btnOk->onMouseClick((ActionHandler)&FundingState::btnOkClick);
74 _btnOk->onKeyboardPress((ActionHandler)&FundingState::btnOkClick, Options::keyOk);
75 _btnOk->onKeyboardPress((ActionHandler)&FundingState::btnOkClick, Options::keyCancel);
76 _btnOk->onKeyboardPress((ActionHandler)&FundingState::btnOkClick, Options::keyGeoFunding);
77
78 _txtTitle->setColor(Palette::blockOffset(15)-1);
79 _txtTitle->setAlign(ALIGN_CENTER);
80 _txtTitle->setBig();
81 _txtTitle->setText(tr("STR_INTERNATIONAL_RELATIONS"));
82
83 _txtCountry->setColor(Palette::blockOffset(8)+5);
84 _txtCountry->setText(tr("STR_COUNTRY"));
85
86 _txtFunding->setColor(Palette::blockOffset(8)+5);
87 _txtFunding->setText(tr("STR_FUNDING"));
88
89 _txtChange->setColor(Palette::blockOffset(8)+5);
90 _txtChange->setText(tr("STR_CHANGE"));
91
92 _lstCountries->setColor(Palette::blockOffset(15)-1);
93 _lstCountries->setSecondaryColor(Palette::blockOffset(8)+10);
94 _lstCountries->setColumns(3, 108, 100, 52);
95 _lstCountries->setDot(true);
96 for (std::vector<Country*>::iterator i = _game->getSavedGame()->getCountries()->begin(); i != _game->getSavedGame()->getCountries()->end(); ++i)
97 {
98 std::wostringstream ss, ss2;
99 ss << L'\x01' << Text::formatFunding((*i)->getFunding().at((*i)->getFunding().size()-1)) << L'\x01';
100 if((*i)->getFunding().size() > 1)
101 {
102 ss2 << L'\x01';
103 int change = (*i)->getFunding().back() - (*i)->getFunding().at((*i)->getFunding().size()-2);
104 if (change > 0)
105 ss2 << L'+';
106 ss2 << Text::formatFunding(change);
107 ss2 << L'\x01';
108 }
109 else
110 {
111 ss2 << Text::formatFunding(0);
112 }
113 _lstCountries->addRow(3, tr((*i)->getRules()->getType()).c_str(), ss.str().c_str(), ss2.str().c_str());
114 }
115 _lstCountries->addRow(2, tr("STR_TOTAL_UC").c_str(), Text::formatFunding(_game->getSavedGame()->getCountryFunding()).c_str());
116 _lstCountries->setRowColor(_game->getSavedGame()->getCountries()->size(), Palette::blockOffset(8)+5);
117 }
118
119 /**
120 *
121 */
~FundingState()122 FundingState::~FundingState()
123 {
124
125 }
126
127 /**
128 * Returns to the previous screen.
129 * @param action Pointer to an action.
130 */
btnOkClick(Action *)131 void FundingState::btnOkClick(Action *)
132 {
133 _game->popState();
134 }
135
136 }
137