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 "CraftErrorState.h"
20 #include "../Engine/Game.h"
21 #include "../Resource/ResourcePack.h"
22 #include "../Engine/Language.h"
23 #include "../Engine/Palette.h"
24 #include "../Interface/TextButton.h"
25 #include "../Interface/Window.h"
26 #include "../Interface/Text.h"
27 #include "GeoscapeState.h"
28 #include "../Engine/Options.h"
29 
30 namespace OpenXcom
31 {
32 
33 /**
34  * Initializes all the elements in a Cannot Rearm window.
35  * @param game Pointer to the core game.
36  * @param state Pointer to the Geoscape state.
37  * @param msg Error message.
38  */
CraftErrorState(Game * game,GeoscapeState * state,const std::wstring & msg)39 CraftErrorState::CraftErrorState(Game *game, GeoscapeState *state, const std::wstring &msg) : State(game), _state(state)
40 {
41 	_screen = false;
42 
43 	// Create objects
44 	_window = new Window(this, 256, 160, 32, 20, POPUP_BOTH);
45 	_btnOk = new TextButton(100, 18, 48, 150);
46 	_btnOk5Secs = new TextButton(100, 18, 172, 150);
47 	_txtMessage = new Text(246, 96, 37, 42);
48 
49 	// Set palette
50 	setPalette("PAL_GEOSCAPE", 4);
51 
52 	add(_window);
53 	add(_btnOk);
54 	add(_btnOk5Secs);
55 	add(_txtMessage);
56 
57 	centerAllSurfaces();
58 
59 	// Set up objects
60 	_window->setColor(Palette::blockOffset(15)-1);
61 	_window->setBackground(_game->getResourcePack()->getSurface("BACK12.SCR"));
62 
63 	_btnOk->setColor(Palette::blockOffset(8)+5);
64 	_btnOk->setText(tr("STR_OK"));
65 	_btnOk->onMouseClick((ActionHandler)&CraftErrorState::btnOkClick);
66 	_btnOk->onKeyboardPress((ActionHandler)&CraftErrorState::btnOkClick, Options::keyCancel);
67 
68 	_btnOk5Secs->setColor(Palette::blockOffset(8)+5);
69 	_btnOk5Secs->setText(tr("STR_OK_5_SECONDS"));
70 	_btnOk5Secs->onMouseClick((ActionHandler)&CraftErrorState::btnOk5SecsClick);
71 	_btnOk5Secs->onKeyboardPress((ActionHandler)&CraftErrorState::btnOk5SecsClick, Options::keyOk);
72 
73 	_txtMessage->setColor(Palette::blockOffset(15)-1);
74 	_txtMessage->setAlign(ALIGN_CENTER);
75 	_txtMessage->setVerticalAlign(ALIGN_MIDDLE);
76 	_txtMessage->setBig();
77 	_txtMessage->setWordWrap(true);
78 	_txtMessage->setText(msg);
79 }
80 
81 /**
82  *
83  */
~CraftErrorState()84 CraftErrorState::~CraftErrorState()
85 {
86 
87 }
88 
89 /**
90  * Closes the window.
91  * @param action Pointer to an action.
92  */
btnOkClick(Action *)93 void CraftErrorState::btnOkClick(Action *)
94 {
95 	_game->popState();
96 }
97 
98 /**
99  * Closes the window.
100  * @param action Pointer to an action.
101  */
btnOk5SecsClick(Action *)102 void CraftErrorState::btnOk5SecsClick(Action *)
103 {
104 	_state->timerReset();
105 	_game->popState();
106 }
107 
108 }
109