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 <assert.h>
20 #include "ProductionCompleteState.h"
21 #include "../Engine/Game.h"
22 #include "../Resource/ResourcePack.h"
23 #include "../Engine/Language.h"
24 #include "../Engine/Palette.h"
25 #include "../Interface/TextButton.h"
26 #include "../Interface/Window.h"
27 #include "../Interface/Text.h"
28 #include "GeoscapeState.h"
29 #include "../Engine/Options.h"
30 #include "../Basescape/BasescapeState.h"
31 #include "../Basescape/ManufactureState.h"
32 #include "../Savegame/Base.h"
33 
34 namespace OpenXcom
35 {
36 
37 /**
38  * Initializes all the elements in a Production Complete window.
39  * @param game Pointer to the core game.
40  * @param base Pointer to base the production belongs to.
41  * @param item Item that finished producing.
42  * @param state Pointer to the Geoscape state.
43  * @param endType What ended the production.
44  */
ProductionCompleteState(Game * game,Base * base,const std::wstring & item,GeoscapeState * state,productionProgress_e endType)45 ProductionCompleteState::ProductionCompleteState(Game *game, Base *base, const std::wstring &item, GeoscapeState *state, productionProgress_e endType) : State(game), _base(base), _state(state), _endType(endType)
46 {
47 	_screen = false;
48 
49 	// Create objects
50 	_window = new Window(this, 256, 160, 32, 20, POPUP_BOTH);
51 	_btnOk = new TextButton(118, 18, 40, 154);
52 	_btnGotoBase = new TextButton(118, 18, 162, 154);
53 	_txtMessage = new Text(246, 110, 37, 35);
54 
55 	// Set palette
56 	setPalette("PAL_GEOSCAPE", 6);
57 
58 	add(_window);
59 	add(_btnOk);
60 	add(_btnGotoBase);
61 	add(_txtMessage);
62 
63 	centerAllSurfaces();
64 
65 	// Set up objects
66 	_window->setColor(Palette::blockOffset(15)-1);
67 	_window->setBackground(_game->getResourcePack()->getSurface("BACK17.SCR"));
68 
69 	_btnOk->setColor(Palette::blockOffset(8)+5);
70 	_btnOk->setText(tr("STR_OK"));
71 	_btnOk->onMouseClick((ActionHandler)&ProductionCompleteState::btnOkClick);
72 	_btnOk->onKeyboardPress((ActionHandler)&ProductionCompleteState::btnOkClick, Options::keyCancel);
73 
74 	_btnGotoBase->setColor(Palette::blockOffset(8)+5);
75 	if (_endType != PROGRESS_CONSTRUCTION)
76 	{
77 		_btnGotoBase->setText(tr("STR_ALLOCATE_MANUFACTURE"));
78 	}
79 	else
80 	{
81 		_btnGotoBase->setText(tr("STR_GO_TO_BASE"));
82 	}
83 	_btnGotoBase->onMouseClick((ActionHandler)&ProductionCompleteState::btnGotoBaseClick);
84 
85 	_txtMessage->setColor(Palette::blockOffset(15)-1);
86 	_txtMessage->setAlign(ALIGN_CENTER);
87 	_txtMessage->setVerticalAlign(ALIGN_MIDDLE);
88 	_txtMessage->setBig();
89 	_txtMessage->setWordWrap(true);
90 	std::wstring s;
91 	switch(_endType)
92 	{
93 	case PROGRESS_CONSTRUCTION:
94 		s = tr("STR_CONSTRUCTION_OF_FACILITY_AT_BASE_IS_COMPLETE").arg(item).arg(base->getName());
95 		break;
96 	case PROGRESS_COMPLETE:
97 		s = tr("STR_PRODUCTION_OF_ITEM_AT_BASE_IS_COMPLETE").arg(item).arg(base->getName());
98 		break;
99 	case PROGRESS_NOT_ENOUGH_MONEY:
100 		s = tr("STR_NOT_ENOUGH_MONEY_TO_PRODUCE_ITEM_AT_BASE").arg(item).arg(base->getName());
101 		break;
102 	case PROGRESS_NOT_ENOUGH_MATERIALS:
103 		s = tr("STR_NOT_ENOUGH_SPECIAL_MATERIALS_TO_PRODUCE_ITEM_AT_BASE").arg(item).arg(base->getName());
104 		break;
105 	default:
106 		assert(false);
107 	}
108 	_txtMessage->setText(s);
109 }
110 
111 /**
112  *
113  */
~ProductionCompleteState()114 ProductionCompleteState::~ProductionCompleteState()
115 {
116 
117 }
118 
119 /**
120  * Closes the window.
121  * @param action Pointer to an action.
122  */
btnOkClick(Action *)123 void ProductionCompleteState::btnOkClick(Action *)
124 {
125 	_game->popState();
126 }
127 
128 /**
129  * Goes to the base for the respective production.
130  * @param action Pointer to an action.
131  */
btnGotoBaseClick(Action *)132 void ProductionCompleteState::btnGotoBaseClick(Action *)
133 {
134 	_state->timerReset();
135 	_game->popState();
136 	if (_endType != PROGRESS_CONSTRUCTION)
137 	{
138 		_game->pushState(new ManufactureState(_game, _base));
139 	}
140 	else
141 	{
142 		_game->pushState(new BasescapeState(_game, _base, _state->getGlobe()));
143 	}
144 }
145 
146 }
147