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 "ResearchRequiredState.h"
20 #include "../Engine/Game.h"
21 #include "../Engine/Palette.h"
22 #include "../Engine/Language.h"
23 #include "../Resource/ResourcePack.h"
24 #include "../Interface/TextButton.h"
25 #include "../Interface/Window.h"
26 #include "../Interface/Text.h"
27 #include "../Ruleset/Ruleset.h"
28 #include "../Ruleset/RuleItem.h"
29 #include "../Savegame/SavedGame.h"
30 #include "../Engine/Options.h"
31
32 namespace OpenXcom
33 {
34 /**
35 * Initializes all the elements in the Research Required screen.
36 * @param game Pointer to the core game.
37 * @param item Pointer to the researched weapon.
38 */
ResearchRequiredState(Game * game,RuleItem * item)39 ResearchRequiredState::ResearchRequiredState(Game *game, RuleItem *item) : State(game)
40 {
41 _screen = false;
42
43 // Create objects
44 _window = new Window(this, 288, 180, 16, 10);
45 _btnOk = new TextButton(160, 18, 80, 150);
46 _txtTitle = new Text(288, 80, 16, 50);
47
48 // Set palette
49 setPalette("PAL_GEOSCAPE", 0);
50
51 add(_window);
52 add(_btnOk);
53 add(_txtTitle);
54
55 centerAllSurfaces();
56
57 std::string weapon = item->getType();
58 std::string clip = item->getCompatibleAmmo()->front();
59
60 // Set up objects
61 _window->setColor(Palette::blockOffset(15)-1);
62 _window->setBackground(_game->getResourcePack()->getSurface("BACK05.SCR"));
63
64 _btnOk->setColor(Palette::blockOffset(8)+5);
65 _btnOk->setText(tr("STR_OK"));
66 _btnOk->onMouseClick((ActionHandler)&ResearchRequiredState::btnOkClick);
67 _btnOk->onKeyboardPress((ActionHandler)&ResearchRequiredState::btnOkClick, Options::keyCancel);
68 _btnOk->onKeyboardPress((ActionHandler)&ResearchRequiredState::btnOkClick, Options::keyOk);
69
70 _txtTitle->setColor(Palette::blockOffset(15)-1);
71 _txtTitle->setBig();
72 _txtTitle->setAlign(ALIGN_CENTER);
73 _txtTitle->setVerticalAlign(ALIGN_MIDDLE);
74 _txtTitle->setText(tr("STR_YOU_NEED_TO_RESEARCH_ITEM_TO_PRODUCE_ITEM")
75 .arg(tr(clip))
76 .arg(tr(weapon)));
77 }
78
79 /**
80 * Returns to the previous screen.
81 * @param action Pointer to an action.
82 */
btnOkClick(Action *)83 void ResearchRequiredState::btnOkClick(Action *)
84 {
85 _game->popState();
86 }
87
88 }
89