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 <algorithm>
20 #include "NewPossibleResearchState.h"
21 #include "../Engine/Game.h"
22 #include "../Engine/Palette.h"
23 #include "../Engine/Language.h"
24 #include "../Resource/ResourcePack.h"
25 #include "../Interface/TextButton.h"
26 #include "../Interface/Window.h"
27 #include "../Interface/Text.h"
28 #include "../Interface/TextList.h"
29 #include "../Ruleset/Ruleset.h"
30 #include "../Ruleset/RuleResearch.h"
31 #include "../Basescape/ResearchState.h"
32 #include "../Savegame/SavedGame.h"
33 #include "../Engine/Options.h"
34
35 namespace OpenXcom
36 {
37 /**
38 * Initializes all the elements in the EndResearch screen.
39 * @param game Pointer to the core game.
40 * @param base Pointer to the base to get info from.
41 * @param possibilities List of newly possible ResearchProject
42 */
NewPossibleResearchState(Game * game,Base * base,const std::vector<RuleResearch * > & possibilities)43 NewPossibleResearchState::NewPossibleResearchState(Game * game, Base * base, const std::vector<RuleResearch *> & possibilities) : State (game), _base(base)
44 {
45 _screen = false;
46
47 // Create objects
48 _window = new Window(this, 288, 180, 16, 10);
49 _btnOk = new TextButton(160, 14, 80, 149);
50 _btnResearch = new TextButton(160, 14, 80, 165);
51 _txtTitle = new Text(288, 40, 16, 20);
52 _lstPossibilities = new TextList(288, 80, 16, 56);
53
54 // Set palette
55 setPalette("PAL_GEOSCAPE", 1);
56
57 add(_window);
58 add(_btnOk);
59 add(_btnResearch);
60 add(_txtTitle);
61 add(_lstPossibilities);
62
63 centerAllSurfaces();
64
65 // Set up objects
66 _window->setColor(Palette::blockOffset(15)-1);
67 _window->setBackground(_game->getResourcePack()->getSurface("BACK05.SCR"));
68
69 _btnOk->setColor(Palette::blockOffset(8)+5);
70 _btnOk->setText(tr("STR_OK"));
71 _btnOk->onMouseClick((ActionHandler)&NewPossibleResearchState::btnOkClick);
72 _btnOk->onKeyboardPress((ActionHandler)&NewPossibleResearchState::btnOkClick, Options::keyCancel);
73 _btnResearch->setColor(Palette::blockOffset(8)+5);
74 _btnResearch->setText(tr("STR_ALLOCATE_RESEARCH"));
75 _btnResearch->onMouseClick((ActionHandler)&NewPossibleResearchState::btnResearchClick);
76 _btnResearch->onKeyboardPress((ActionHandler)&NewPossibleResearchState::btnResearchClick, Options::keyOk);
77 _txtTitle->setColor(Palette::blockOffset(15)-1);
78 _txtTitle->setBig();
79 _txtTitle->setAlign(ALIGN_CENTER);
80
81 _lstPossibilities->setColor(Palette::blockOffset(8)+10);
82 _lstPossibilities->setColumns(1, 288);
83 _lstPossibilities->setBig();
84 _lstPossibilities->setAlign(ALIGN_CENTER);
85
86 size_t tally(0);
87 for(std::vector<RuleResearch *>::const_iterator iter = possibilities.begin (); iter != possibilities.end (); ++iter)
88 {
89 bool liveAlien = _game->getRuleset()->getUnit((*iter)->getName()) != 0;
90 if(!_game->getSavedGame()->wasResearchPopped(*iter) && (*iter)->getRequirements().empty() && !liveAlien)
91 {
92 _game->getSavedGame()->addPoppedResearch((*iter));
93 _lstPossibilities->addRow (1, tr((*iter)->getName ()).c_str());
94 }
95 else
96 {
97 tally++;
98 }
99 }
100
101 if (!(tally == possibilities.size () || possibilities.empty ()))
102 {
103 _txtTitle->setText(tr("STR_WE_CAN_NOW_RESEARCH"));
104 }
105 }
106
107 /**
108 * return to the previous screen
109 * @param action Pointer to an action.
110 */
btnOkClick(Action *)111 void NewPossibleResearchState::btnOkClick(Action *)
112 {
113 _game->popState();
114 }
115
116 /**
117 * Open the ResearchState so the player can dispatch available scientist.
118 * @param action Pointer to an action.
119 */
btnResearchClick(Action *)120 void NewPossibleResearchState::btnResearchClick(Action *)
121 {
122 _game->popState();
123 _game->pushState (new ResearchState(_game, _base));
124 }
125
126 }
127