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 "CraftPatrolState.h"
20 #include <string>
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 "../Savegame/Target.h"
30 #include "GeoscapeCraftState.h"
31 #include "../Engine/Options.h"
32
33 namespace OpenXcom
34 {
35
36 /**
37 * Initializes all the elements in the Craft Patrol window.
38 * @param game Pointer to the core game.
39 * @param craft Pointer to the craft to display.
40 * @param globe Pointer to the Geoscape globe.
41 */
CraftPatrolState(Game * game,Craft * craft,Globe * globe)42 CraftPatrolState::CraftPatrolState(Game *game, Craft *craft, Globe *globe) : State(game), _craft(craft), _globe(globe)
43 {
44 _screen = false;
45
46 // Create objects
47 _window = new Window(this, 224, 168, 16, 16, POPUP_BOTH);
48 _btnOk = new TextButton(140, 12, 58, 144);
49 _btnRedirect = new TextButton(140, 12, 58, 160);
50 _txtDestination = new Text(224, 64, 16, 48);
51 _txtPatrolling = new Text(224, 17, 16, 120);
52
53 // Set palette
54 setPalette("PAL_GEOSCAPE", 4);
55
56 add(_window);
57 add(_btnOk);
58 add(_btnRedirect);
59 add(_txtDestination);
60 add(_txtPatrolling);
61
62 centerAllSurfaces();
63
64 // Set up objects
65 _window->setColor(Palette::blockOffset(15)-1);
66 _window->setBackground(_game->getResourcePack()->getSurface("BACK12.SCR"));
67
68 _btnOk->setColor(Palette::blockOffset(8)+5);
69 _btnOk->setText(tr("STR_OK"));
70 _btnOk->onMouseClick((ActionHandler)&CraftPatrolState::btnOkClick);
71 _btnOk->onKeyboardPress((ActionHandler)&CraftPatrolState::btnOkClick, Options::keyCancel);
72
73 _btnRedirect->setColor(Palette::blockOffset(8)+5);
74 _btnRedirect->setText(tr("STR_REDIRECT_CRAFT"));
75 _btnRedirect->onMouseClick((ActionHandler)&CraftPatrolState::btnRedirectClick);
76 _btnRedirect->onKeyboardPress((ActionHandler)&CraftPatrolState::btnRedirectClick, Options::keyOk);
77
78 _txtDestination->setColor(Palette::blockOffset(15)-1);
79 _txtDestination->setBig();
80 _txtDestination->setAlign(ALIGN_CENTER);
81 _txtDestination->setWordWrap(true);
82 _txtDestination->setText(tr("STR_CRAFT_HAS_REACHED_DESTINATION")
83 .arg(_craft->getName(_game->getLanguage()))
84 .arg(_craft->getDestination()->getName(_game->getLanguage())));
85
86 _txtPatrolling->setColor(Palette::blockOffset(15)-1);
87 _txtPatrolling->setBig();
88 _txtPatrolling->setAlign(ALIGN_CENTER);
89 _txtPatrolling->setText(tr("STR_NOW_PATROLLING"));
90 }
91
92 /**
93 *
94 */
~CraftPatrolState()95 CraftPatrolState::~CraftPatrolState()
96 {
97
98 }
99
100 /**
101 * Closes the window.
102 * @param action Pointer to an action.
103 */
btnOkClick(Action *)104 void CraftPatrolState::btnOkClick(Action *)
105 {
106 _game->popState();
107 }
108
109 /**
110 * Opens up the Craft window.
111 * @param action Pointer to an action.
112 */
btnRedirectClick(Action *)113 void CraftPatrolState::btnRedirectClick(Action *)
114 {
115 _game->popState();
116 _game->pushState(new GeoscapeCraftState(_game, _craft, _globe, 0));
117 }
118
119 }
120