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 "TransfersState.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/Transfer.h"
33
34 namespace OpenXcom
35 {
36
37 /**
38 * Initializes all the elements in the Transfers window.
39 * @param game Pointer to the core game.
40 * @param base Pointer to the base to get info from.
41 */
TransfersState(Game * game,Base * base)42 TransfersState::TransfersState(Game *game, Base *base) : State(game), _base(base)
43 {
44 _screen = false;
45
46 // Create objects
47 _window = new Window(this, 320, 184, 0, 8, POPUP_BOTH);
48 _btnOk = new TextButton(288, 16, 16, 166);
49 _txtTitle = new Text(278, 17, 21, 18);
50 _txtItem = new Text(114, 9, 16, 34);
51 _txtQuantity = new Text(54, 9, 152, 34);
52 _txtArrivalTime = new Text(112, 9, 212, 34);
53 _lstTransfers = new TextList(273, 112, 14, 50);
54
55 // Set palette
56 setPalette("PAL_BASESCAPE", 6);
57
58 add(_window);
59 add(_btnOk);
60 add(_txtTitle);
61 add(_txtItem);
62 add(_txtQuantity);
63 add(_txtArrivalTime);
64 add(_lstTransfers);
65
66 centerAllSurfaces();
67
68 // Set up objects
69 _window->setColor(Palette::blockOffset(15)+6);
70 _window->setBackground(_game->getResourcePack()->getSurface("BACK13.SCR"));
71
72 _btnOk->setColor(Palette::blockOffset(15)+6);
73 _btnOk->setText(tr("STR_OK"));
74 _btnOk->onMouseClick((ActionHandler)&TransfersState::btnOkClick);
75 _btnOk->onKeyboardPress((ActionHandler)&TransfersState::btnOkClick, Options::keyOk);
76 _btnOk->onKeyboardPress((ActionHandler)&TransfersState::btnOkClick, Options::keyCancel);
77
78 _txtTitle->setColor(Palette::blockOffset(15)+6);
79 _txtTitle->setBig();
80 _txtTitle->setAlign(ALIGN_CENTER);
81 _txtTitle->setText(tr("STR_TRANSFERS"));
82
83 _txtItem->setColor(Palette::blockOffset(15)+6);
84 _txtItem->setText(tr("STR_ITEM"));
85
86 _txtQuantity->setColor(Palette::blockOffset(15)+6);
87 _txtQuantity->setText(tr("STR_QUANTITY_UC"));
88
89 _txtArrivalTime->setColor(Palette::blockOffset(15)+6);
90 _txtArrivalTime->setText(tr("STR_ARRIVAL_TIME_HOURS"));
91
92 _lstTransfers->setColor(Palette::blockOffset(13)+10);
93 _lstTransfers->setArrowColor(Palette::blockOffset(15)+6);
94 _lstTransfers->setColumns(3, 155, 75, 46);
95 _lstTransfers->setSelectable(true);
96 _lstTransfers->setBackground(_window);
97 _lstTransfers->setMargin(2);
98
99 for (std::vector<Transfer*>::iterator i = _base->getTransfers()->begin(); i != _base->getTransfers()->end(); ++i)
100 {
101 std::wostringstream ss, ss2;
102 ss << (*i)->getQuantity();
103 ss2 << (*i)->getHours();
104 _lstTransfers->addRow(3, (*i)->getName(_game->getLanguage()).c_str(), ss.str().c_str(), ss2.str().c_str());
105 }
106 }
107
108 /**
109 *
110 */
~TransfersState()111 TransfersState::~TransfersState()
112 {
113
114 }
115
116 /**
117 * Returns to the previous screen.
118 * @param action Pointer to an action.
119 */
btnOkClick(Action *)120 void TransfersState::btnOkClick(Action *)
121 {
122 _game->popState();
123 }
124
125 }
126