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 "SoldierMemorialState.h"
20 #include <sstream>
21 #include <iomanip>
22 #include "../Engine/Game.h"
23 #include "../Resource/ResourcePack.h"
24 #include "../Engine/Music.h"
25 #include "../Engine/Language.h"
26 #include "../Engine/Palette.h"
27 #include "../Engine/Options.h"
28 #include "../Interface/TextButton.h"
29 #include "../Interface/Window.h"
30 #include "../Interface/Text.h"
31 #include "../Interface/TextList.h"
32 #include "../Savegame/SavedGame.h"
33 #include "../Savegame/Base.h"
34 #include "../Savegame/Soldier.h"
35 #include "../Savegame/SoldierDeath.h"
36 #include "../Savegame/GameTime.h"
37 #include "SoldierInfoState.h"
38
39 namespace OpenXcom
40 {
41
42 /**
43 * Initializes all the elements in the Soldier Memorial screen.
44 * @param game Pointer to the core game.
45 */
SoldierMemorialState(Game * game)46 SoldierMemorialState::SoldierMemorialState(Game *game) : State(game)
47 {
48 // Create objects
49 _window = new Window(this, 320, 200, 0, 0);
50 _btnOk = new TextButton(288, 16, 16, 176);
51 _txtTitle = new Text(310, 17, 5, 8);
52 _txtName = new Text(114, 9, 16, 36);
53 _txtRank = new Text(102, 9, 130, 36);
54 _txtDate = new Text(90, 9, 218, 36);
55 _txtRecruited = new Text(150, 9, 16, 24);
56 _txtLost = new Text(150, 9, 160, 24);
57 _lstSoldiers = new TextList(288, 120, 8, 44);
58
59 // Set palette
60 setPalette("PAL_BASESCAPE", 7);
61
62 _game->getResourcePack()->playMusic("GMLOSE");
63
64 add(_window);
65 add(_btnOk);
66 add(_txtTitle);
67 add(_txtName);
68 add(_txtRank);
69 add(_txtDate);
70 add(_txtRecruited);
71 add(_txtLost);
72 add(_lstSoldiers);
73
74 centerAllSurfaces();
75
76 // Set up objects
77 _window->setColor(Palette::blockOffset(13)+10);
78 _window->setBackground(_game->getResourcePack()->getSurface("BACK02.SCR"));
79
80 _btnOk->setColor(Palette::blockOffset(13)+10);
81 _btnOk->setText(tr("STR_OK"));
82 _btnOk->onMouseClick((ActionHandler)&SoldierMemorialState::btnOkClick);
83 _btnOk->onKeyboardPress((ActionHandler)&SoldierMemorialState::btnOkClick, Options::keyCancel);
84
85 _txtTitle->setColor(Palette::blockOffset(13)+10);
86 _txtTitle->setBig();
87 _txtTitle->setAlign(ALIGN_CENTER);
88 _txtTitle->setText(tr("STR_MEMORIAL"));
89
90 _txtName->setColor(Palette::blockOffset(13)+10);
91 _txtName->setText(tr("STR_NAME_UC"));
92
93 _txtRank->setColor(Palette::blockOffset(13)+10);
94 _txtRank->setText(tr("STR_RANK"));
95
96 _txtDate->setColor(Palette::blockOffset(13)+10);
97 _txtDate->setText(tr("STR_DATE_UC"));
98
99 size_t lost = _game->getSavedGame()->getDeadSoldiers()->size();
100 size_t recruited = lost;
101 for (std::vector<Base*>::iterator i = _game->getSavedGame()->getBases()->begin(); i != _game->getSavedGame()->getBases()->end(); ++i)
102 {
103 recruited += (*i)->getTotalSoldiers();
104 }
105
106 _txtRecruited->setColor(Palette::blockOffset(13)+10);
107 _txtRecruited->setSecondaryColor(Palette::blockOffset(13));
108 _txtRecruited->setText(tr("STR_SOLDIERS_RECRUITED").arg(recruited));
109
110 _txtLost->setColor(Palette::blockOffset(13)+10);
111 _txtLost->setSecondaryColor(Palette::blockOffset(13));
112 _txtLost->setText(tr("STR_SOLDIERS_LOST").arg(lost));
113
114 _lstSoldiers->setColor(Palette::blockOffset(15)+6);
115 _lstSoldiers->setArrowColor(Palette::blockOffset(13)+10);
116 _lstSoldiers->setColumns(5, 114, 88, 30, 25, 35);
117 _lstSoldiers->setSelectable(true);
118 _lstSoldiers->setBackground(_window);
119 _lstSoldiers->setMargin(8);
120 _lstSoldiers->onMouseClick((ActionHandler)&SoldierMemorialState::lstSoldiersClick);
121
122 for (std::vector<Soldier*>::reverse_iterator i = _game->getSavedGame()->getDeadSoldiers()->rbegin(); i != _game->getSavedGame()->getDeadSoldiers()->rend(); ++i)
123 {
124 SoldierDeath *death = (*i)->getDeath();
125
126 std::wostringstream saveDay, saveMonth, saveYear;
127 saveDay << death->getTime()->getDayString(_game->getLanguage());
128 saveMonth << tr(death->getTime()->getMonthString());
129 saveYear << death->getTime()->getYear();
130 _lstSoldiers->addRow(5, (*i)->getName().c_str(), tr((*i)->getRankString()).c_str(), saveDay.str().c_str(), saveMonth.str().c_str(), saveYear.str().c_str());
131 }
132 }
133
134 /**
135 *
136 */
~SoldierMemorialState()137 SoldierMemorialState::~SoldierMemorialState()
138 {
139
140 }
141
142 /**
143 * Returns to the previous screen.
144 * @param action Pointer to an action.
145 */
btnOkClick(Action *)146 void SoldierMemorialState::btnOkClick(Action *)
147 {
148 _game->popState();
149 _game->getResourcePack()->playMusic("GMGEO", true);
150 }
151
152 /**
153 * Shows the selected soldier's info.
154 * @param action Pointer to an action.
155 */
lstSoldiersClick(Action *)156 void SoldierMemorialState::lstSoldiersClick(Action *)
157 {
158 _game->pushState(new SoldierInfoState(_game, 0, _lstSoldiers->getSelectedRow()));
159 }
160
161 }
162