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 "StoresState.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 "../Ruleset/Ruleset.h"
33 #include "../Ruleset/RuleItem.h"
34 #include "../Savegame/ItemContainer.h"
35
36 namespace OpenXcom
37 {
38
39 /**
40 * Initializes all the elements in the Stores window.
41 * @param game Pointer to the core game.
42 * @param base Pointer to the base to get info from.
43 */
StoresState(Game * game,Base * base)44 StoresState::StoresState(Game *game, Base *base) : State(game), _base(base)
45 {
46 // Create objects
47 _window = new Window(this, 320, 200, 0, 0);
48 _btnOk = new TextButton(300, 16, 10, 176);
49 _txtTitle = new Text(310, 17, 5, 8);
50 _txtItem = new Text(142, 9, 10, 32);
51 _txtQuantity = new Text(88, 9, 152, 32);
52 _txtSpaceUsed = new Text(74, 9, 240, 32);
53 _lstStores = new TextList(288, 128, 8, 40);
54
55 // Set palette
56 setPalette("PAL_BASESCAPE", 0);
57
58 add(_window);
59 add(_btnOk);
60 add(_txtTitle);
61 add(_txtItem);
62 add(_txtQuantity);
63 add(_txtSpaceUsed);
64 add(_lstStores);
65
66 centerAllSurfaces();
67
68 // Set up objects
69 _window->setColor(Palette::blockOffset(13)+10);
70 _window->setBackground(_game->getResourcePack()->getSurface("BACK13.SCR"));
71
72 _btnOk->setColor(Palette::blockOffset(13)+10);
73 _btnOk->setText(tr("STR_OK"));
74 _btnOk->onMouseClick((ActionHandler)&StoresState::btnOkClick);
75 _btnOk->onKeyboardPress((ActionHandler)&StoresState::btnOkClick, Options::keyOk);
76 _btnOk->onKeyboardPress((ActionHandler)&StoresState::btnOkClick, Options::keyCancel);
77
78 _txtTitle->setColor(Palette::blockOffset(13)+10);
79 _txtTitle->setBig();
80 _txtTitle->setAlign(ALIGN_CENTER);
81 _txtTitle->setText(tr("STR_STORES"));
82
83 _txtItem->setColor(Palette::blockOffset(13)+10);
84 _txtItem->setText(tr("STR_ITEM"));
85
86 _txtQuantity->setColor(Palette::blockOffset(13)+10);
87 _txtQuantity->setText(tr("STR_QUANTITY_UC"));
88
89 _txtSpaceUsed->setColor(Palette::blockOffset(13)+10);
90 _txtSpaceUsed->setText(tr("STR_SPACE_USED_UC"));
91
92 _lstStores->setColor(Palette::blockOffset(13)+10);
93 _lstStores->setColumns(3, 162, 92, 32);
94 _lstStores->setSelectable(true);
95 _lstStores->setBackground(_window);
96 _lstStores->setMargin(2);
97
98 const std::vector<std::string> &items = _game->getRuleset()->getItemsList();
99 for (std::vector<std::string>::const_iterator i = items.begin(); i != items.end(); ++i)
100 {
101 int qty = _base->getItems()->getItem(*i);
102 if (qty > 0)
103 {
104 RuleItem *rule = _game->getRuleset()->getItem(*i);
105 std::wostringstream ss, ss2;
106 ss << qty;
107 ss2 << qty * rule->getSize();
108 _lstStores->addRow(3, tr(*i).c_str(), ss.str().c_str(), ss2.str().c_str());
109 }
110 }
111 }
112
113 /**
114 *
115 */
~StoresState()116 StoresState::~StoresState()
117 {
118
119 }
120
121 /**
122 * Returns to the previous screen.
123 * @param action Pointer to an action.
124 */
btnOkClick(Action *)125 void StoresState::btnOkClick(Action *)
126 {
127 _game->popState();
128 }
129
130 }
131