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 "NewPossibleManufactureState.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 "../Interface/TextList.h"
28 #include "../Ruleset/RuleManufacture.h"
29 #include "../Basescape/ManufactureState.h"
30 #include "../Engine/Options.h"
31 
32 namespace OpenXcom
33 {
34 /**
35  * Initializes all the elements in the EndManufacture screen.
36  * @param game Pointer to the core game.
37  * @param base Pointer to the base to get info from.
38  * @param possibilities List of newly possible ManufactureProject
39  */
NewPossibleManufactureState(Game * game,Base * base,const std::vector<RuleManufacture * > & possibilities)40 NewPossibleManufactureState::NewPossibleManufactureState(Game * game, Base * base, const std::vector<RuleManufacture *> & possibilities) : State (game), _base(base)
41 {
42 	_screen = false;
43 
44 	// Create objects
45 	_window = new Window(this, 288, 180, 16, 10);
46 	_btnOk = new TextButton(160, 14, 80, 149);
47 	_btnManufacture = new TextButton(160, 14, 80, 165);
48 	_txtTitle = new Text(288, 40, 16, 20);
49 	_lstPossibilities = new TextList(288, 80, 16, 56);
50 
51 	// Set palette
52 	setPalette("PAL_GEOSCAPE", 6);
53 
54 	add(_window);
55 	add(_btnOk);
56 	add(_btnManufacture);
57 	add(_txtTitle);
58 	add(_lstPossibilities);
59 
60 	centerAllSurfaces();
61 
62 	// Set up objects
63 	_window->setColor(Palette::blockOffset(15)-1);
64 	_window->setBackground(_game->getResourcePack()->getSurface("BACK17.SCR"));
65 
66 	_btnOk->setColor(Palette::blockOffset(8)+5);
67 	_btnOk->setText(tr("STR_OK"));
68 	_btnOk->onMouseClick((ActionHandler)&NewPossibleManufactureState::btnOkClick);
69 	_btnOk->onKeyboardPress((ActionHandler)&NewPossibleManufactureState::btnOkClick, Options::keyCancel);
70 	_btnManufacture->setColor(Palette::blockOffset(8)+5);
71 	_btnManufacture->setText(tr("STR_ALLOCATE_MANUFACTURE"));
72 	_btnManufacture->onMouseClick((ActionHandler)&NewPossibleManufactureState::btnManufactureClick);
73 	_btnManufacture->onKeyboardPress((ActionHandler)&NewPossibleManufactureState::btnManufactureClick, Options::keyOk);
74 	_txtTitle->setColor(Palette::blockOffset(15)-1);
75 	_txtTitle->setBig();
76 	_txtTitle->setAlign(ALIGN_CENTER);
77 	_txtTitle->setText(tr("STR_WE_CAN_NOW_PRODUCE"));
78 
79 	_lstPossibilities->setColor(Palette::blockOffset(8)+10);
80 	_lstPossibilities->setColumns(1, 288);
81 	_lstPossibilities->setBig();
82 	_lstPossibilities->setAlign(ALIGN_CENTER);
83 	for(std::vector<RuleManufacture *>::const_iterator iter = possibilities.begin (); iter != possibilities.end (); ++iter)
84 	{
85 		_lstPossibilities->addRow (1, tr((*iter)->getName ()).c_str());
86 	}
87 }
88 
89 /**
90  * return to the previous screen
91  * @param action Pointer to an action.
92  */
btnOkClick(Action *)93 void NewPossibleManufactureState::btnOkClick(Action *)
94 {
95 	_game->popState();
96 }
97 
98 /**
99  * Open the ManufactureState so the player can dispatch available scientist.
100  * @param action Pointer to an action.
101  */
btnManufactureClick(Action *)102 void NewPossibleManufactureState::btnManufactureClick(Action *)
103 {
104 	_game->popState();
105 	_game->pushState (new ManufactureState(_game, _base));
106 }
107 
108 }
109