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 "PromotionsState.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/SavedGame.h"
30 #include "../Savegame/Base.h"
31 #include "../Savegame/Soldier.h"
32 #include "../Engine/Options.h"
33
34 namespace OpenXcom
35 {
36
37 /**
38 * Initializes all the elements in the Promotions screen.
39 * @param game Pointer to the core game.
40 */
PromotionsState(Game * game)41 PromotionsState::PromotionsState(Game *game) : State(game)
42 {
43 // Create objects
44 _window = new Window(this, 320, 200, 0, 0);
45 _btnOk = new TextButton(288, 16, 16, 176);
46 _txtTitle = new Text(300, 17, 10, 8);
47 _txtName = new Text(114, 9, 16, 32);
48 _txtRank = new Text(90, 9, 130, 32);
49 _txtBase = new Text(80, 9, 220, 32);
50 _lstSoldiers = new TextList(288, 128, 8, 40);
51
52 // Set palette
53 setPalette("PAL_GEOSCAPE", 0);
54
55 add(_window);
56 add(_btnOk);
57 add(_txtTitle);
58 add(_txtName);
59 add(_txtRank);
60 add(_txtBase);
61 add(_lstSoldiers);
62
63 centerAllSurfaces();
64
65 // Set up objects
66 _window->setColor(Palette::blockOffset(15)-1);
67 _window->setBackground(_game->getResourcePack()->getSurface("BACK01.SCR"));
68
69 _btnOk->setColor(Palette::blockOffset(15)-1);
70 _btnOk->setText(tr("STR_OK"));
71 _btnOk->onMouseClick((ActionHandler)&PromotionsState::btnOkClick);
72 _btnOk->onKeyboardPress((ActionHandler)&PromotionsState::btnOkClick, Options::keyOk);
73 _btnOk->onKeyboardPress((ActionHandler)&PromotionsState::btnOkClick, Options::keyCancel);
74
75 _txtTitle->setColor(Palette::blockOffset(8)+5);
76 _txtTitle->setText(tr("STR_PROMOTIONS"));
77 _txtTitle->setAlign(ALIGN_CENTER);
78 _txtTitle->setBig();
79
80 _txtName->setColor(Palette::blockOffset(15)-1);
81 _txtName->setText(tr("STR_NAME"));
82
83 _txtRank->setColor(Palette::blockOffset(15)-1);
84 _txtRank->setText(tr("STR_NEW_RANK"));
85
86 _txtBase->setColor(Palette::blockOffset(15)-1);
87 _txtBase->setText(tr("STR_BASE"));
88
89 _lstSoldiers->setColor(Palette::blockOffset(8)+10);
90 _lstSoldiers->setColumns(3, 114, 90, 84);
91 _lstSoldiers->setSelectable(true);
92 _lstSoldiers->setBackground(_window);
93 _lstSoldiers->setMargin(8);
94
95 for (std::vector<Base*>::iterator i = _game->getSavedGame()->getBases()->begin(); i != _game->getSavedGame()->getBases()->end(); ++i)
96 {
97 for (std::vector<Soldier*>::iterator j = (*i)->getSoldiers()->begin(); j != (*i)->getSoldiers()->end(); ++j)
98 {
99 if ((*j)->isPromoted())
100 {
101 _lstSoldiers->addRow(3, (*j)->getName().c_str(), tr((*j)->getRankString()).c_str(), (*i)->getName().c_str());
102 }
103 }
104 }
105 }
106
107 /**
108 *
109 */
~PromotionsState()110 PromotionsState::~PromotionsState()
111 {
112 }
113
114 /**
115 * Returns to the previous screen.
116 * @param action Pointer to an action.
117 */
btnOkClick(Action *)118 void PromotionsState::btnOkClick(Action *)
119 {
120 _game->popState();
121 }
122
123 }
124