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 "LowFuelState.h"
20 #include <sstream>
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 "../Savegame/Craft.h"
29 #include "GeoscapeState.h"
30 #include "../Engine/Options.h"
31 
32 namespace OpenXcom
33 {
34 
35 /**
36  * Initializes all the elements in the Low Fuel window.
37  * @param game Pointer to the core game.
38  * @param craft Pointer to the craft to display.
39  * @param state Pointer to the Geoscape.
40  */
LowFuelState(Game * game,Craft * craft,GeoscapeState * state)41 LowFuelState::LowFuelState(Game *game, Craft *craft, GeoscapeState *state) : State(game), _craft(craft), _state(state)
42 {
43 	_screen = false;
44 
45 	// Create objects
46 	_window = new Window(this, 224, 120, 16, 40, POPUP_BOTH);
47 	_btnOk = new TextButton(90, 18, 30, 120);
48 	_btnOk5Secs = new TextButton(90, 18, 136, 120);
49 	_txtTitle = new Text(214, 17, 21, 60);
50 	_txtMessage = new Text(214, 17, 21, 90);
51 
52 	// Set palette
53 	setPalette("PAL_GEOSCAPE", 4);
54 
55 	add(_window);
56 	add(_btnOk);
57 	add(_btnOk5Secs);
58 	add(_txtTitle);
59 	add(_txtMessage);
60 
61 	centerAllSurfaces();
62 
63 	// Set up objects
64 	_window->setColor(Palette::blockOffset(15)-1);
65 	_window->setBackground(_game->getResourcePack()->getSurface("BACK12.SCR"));
66 
67 	_btnOk->setColor(Palette::blockOffset(8)+5);
68 	_btnOk->setText(tr("STR_OK"));
69 	_btnOk->onMouseClick((ActionHandler)&LowFuelState::btnOkClick);
70 	_btnOk->onKeyboardPress((ActionHandler)&LowFuelState::btnOkClick, Options::keyCancel);
71 
72 	_btnOk5Secs->setColor(Palette::blockOffset(8)+5);
73 	_btnOk5Secs->setText(tr("STR_OK_5_SECONDS"));
74 	_btnOk5Secs->onMouseClick((ActionHandler)&LowFuelState::btnOk5SecsClick);
75 	_btnOk5Secs->onKeyboardPress((ActionHandler)&LowFuelState::btnOk5SecsClick, Options::keyOk);
76 
77 	_txtTitle->setColor(Palette::blockOffset(8)+10);
78 	_txtTitle->setAlign(ALIGN_CENTER);
79 	_txtTitle->setBig();
80 	_txtTitle->setText(_craft->getName(_game->getLanguage()));
81 
82 	_txtMessage->setColor(Palette::blockOffset(8)+10);
83 	_txtMessage->setAlign(ALIGN_CENTER);
84 	_txtMessage->setText(tr("STR_IS_LOW_ON_FUEL_RETURNING_TO_BASE"));
85 
86 
87 }
88 
89 /**
90  *
91  */
~LowFuelState()92 LowFuelState::~LowFuelState()
93 {
94 
95 }
96 
97 /**
98  * Closes the window.
99  * @param action Pointer to an action.
100  */
btnOkClick(Action *)101 void LowFuelState::btnOkClick(Action *)
102 {
103 	_game->popState();
104 }
105 
106 /**
107  * Closes the window and sets the timer to 5 Secs.
108  * @param action Pointer to an action.
109  */
btnOk5SecsClick(Action *)110 void LowFuelState::btnOk5SecsClick(Action *)
111 {
112 	_state->timerReset();
113 	_game->popState();
114 }
115 
116 }
117