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 "ResearchCompleteState.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/RuleResearch.h"
28 #include "../Ruleset/Ruleset.h"
29 #include "../Ruleset/ArticleDefinition.h"
30 #include "../Ufopaedia/Ufopaedia.h"
31 #include <algorithm>
32 #include "../Engine/Options.h"
33 
34 namespace OpenXcom
35 {
36 /**
37  * Initializes all the elements in the EndResearch screen.
38  * @param game Pointer to the core game.
39  * @param research Pointer to the completed research.
40  * @param bonus Pointer to bonus unlocked research.
41  */
ResearchCompleteState(Game * game,const RuleResearch * research,const RuleResearch * bonus)42 ResearchCompleteState::ResearchCompleteState(Game * game, const RuleResearch * research, const RuleResearch * bonus): State (game), _research(research), _bonus(bonus)
43 {
44 	_screen = false;
45 
46 	// Create objects
47 	_window = new Window(this, 230, 140, 45, 30, POPUP_BOTH);
48 	_btnOk = new TextButton(80, 16, 64, 146);
49 	_btnReport = new TextButton(80, 16, 176, 146);
50 	_txtTitle = new Text(230, 17, 45, 70);
51 	_txtResearch = new Text(230, 32, 45, 96);
52 
53 	// Set palette
54 	setPalette("PAL_GEOSCAPE", 0);
55 
56 	add(_window);
57 	add(_btnOk);
58 	add(_btnReport);
59 	add(_txtTitle);
60 	add(_txtResearch);
61 
62 	centerAllSurfaces();
63 
64 	// Set up objects
65 	_window->setColor(Palette::blockOffset(15)-1);
66 	_window->setBackground(_game->getResourcePack()->getSurface("BACK05.SCR"));
67 
68 	_btnOk->setColor(Palette::blockOffset(8)+5);
69 	_btnOk->setText(tr("STR_OK"));
70 	_btnOk->onMouseClick((ActionHandler)&ResearchCompleteState::btnOkClick);
71 	_btnOk->onKeyboardPress((ActionHandler)&ResearchCompleteState::btnOkClick, Options::keyCancel);
72 
73 	_btnReport->setColor(Palette::blockOffset(8)+5);
74 	_btnReport->setText(tr("STR_VIEW_REPORTS"));
75 	_btnReport->onMouseClick((ActionHandler)&ResearchCompleteState::btnReportClick);
76 	_btnReport->onKeyboardPress((ActionHandler)&ResearchCompleteState::btnReportClick, Options::keyOk);
77 
78 	_txtTitle->setColor(Palette::blockOffset(15)-1);
79 	_txtTitle->setBig();
80 	_txtTitle->setAlign(ALIGN_CENTER);
81 	_txtTitle->setText(tr("STR_RESEARCH_COMPLETED"));
82 
83 	_txtResearch->setColor(Palette::blockOffset(8)+10);
84 	_txtResearch->setAlign(ALIGN_CENTER);
85 	_txtResearch->setBig();
86 	_txtResearch->setWordWrap(true);
87 	if (research)
88 	{
89 		_txtResearch->setText(tr(research->getName()));
90 	}
91 }
92 
93 /**
94  * return to the previous screen
95  * @param action Pointer to an action.
96  */
btnOkClick(Action *)97 void ResearchCompleteState::btnOkClick(Action *)
98 {
99 	_game->popState();
100 }
101 
102 /**
103  * open the Ufopaedia to the entry about the Research.
104  * @param action Pointer to an action.
105  */
btnReportClick(Action *)106 void ResearchCompleteState::btnReportClick(Action *)
107 {
108 	_game->popState();
109 	std::string name;
110 	std::string bonusName;
111 	if (_bonus)
112 	{
113 		if (_bonus->getLookup() == "")
114 			bonusName = _bonus->getName();
115 		else
116 			bonusName = _bonus->getLookup();
117 		Ufopaedia::openArticle(_game, bonusName);
118 	}
119 	if (_research)
120 	{
121 		if (_research->getLookup() == "")
122 			name = _research->getName();
123 		else
124 			name = _research->getLookup();
125 		Ufopaedia::openArticle(_game, name);
126 	}
127 }
128 
129 }
130