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 "TargetInfoState.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 "../Savegame/Target.h"
28 #include "../Engine/Options.h"
29 #include "InterceptState.h"
30
31 namespace OpenXcom
32 {
33
34 /**
35 * Initializes all the elements in the Target Info window.
36 * @param game Pointer to the core game.
37 * @param target Pointer to the target to show info from.
38 * @param globe Pointer to the Geoscape globe.
39 */
TargetInfoState(Game * game,Target * target,Globe * globe)40 TargetInfoState::TargetInfoState(Game *game, Target *target, Globe *globe) : State(game), _target(target), _globe(globe)
41 {
42 _screen = false;
43
44 // Create objects
45 _window = new Window(this, 192, 120, 32, 40, POPUP_BOTH);
46 _btnIntercept = new TextButton(160, 12, 48, 124);
47 _btnOk = new TextButton(160, 12, 48, 140);
48 _txtTitle = new Text(182, 32, 37, 46);
49 _txtTargetted = new Text(182, 9, 37, 78);
50 _txtFollowers = new Text(182, 40, 37, 88);
51
52 // Set palette
53 setPalette("PAL_GEOSCAPE", 0);
54
55 add(_window);
56 add(_btnIntercept);
57 add(_btnOk);
58 add(_txtTitle);
59 add(_txtTargetted);
60 add(_txtFollowers);
61
62 centerAllSurfaces();
63
64 // Set up objects
65 _window->setColor(Palette::blockOffset(8)+10);
66 _window->setBackground(_game->getResourcePack()->getSurface("BACK01.SCR"));
67
68 _btnIntercept->setColor(Palette::blockOffset(8)+5);
69 _btnIntercept->setText(tr("STR_INTERCEPT"));
70 _btnIntercept->onMouseClick((ActionHandler)&TargetInfoState::btnInterceptClick);
71
72 _btnOk->setColor(Palette::blockOffset(8)+5);
73 _btnOk->setText(tr("STR_OK"));
74 _btnOk->onMouseClick((ActionHandler)&TargetInfoState::btnOkClick);
75 _btnOk->onKeyboardPress((ActionHandler)&TargetInfoState::btnOkClick, Options::keyCancel);
76
77 _txtTitle->setColor(Palette::blockOffset(8)+10);
78 _txtTitle->setBig();
79 _txtTitle->setAlign(ALIGN_CENTER);
80 _txtTitle->setVerticalAlign(ALIGN_MIDDLE);
81 _txtTitle->setWordWrap(true);
82 _txtTitle->setText(_target->getName(_game->getLanguage()));
83
84 _txtTargetted->setColor(Palette::blockOffset(15)-1);
85 _txtTargetted->setAlign(ALIGN_CENTER);
86 _txtTargetted->setText(tr("STR_TARGETTED_BY"));
87
88 _txtFollowers->setColor(Palette::blockOffset(15)-1);
89 _txtFollowers->setAlign(ALIGN_CENTER);
90 std::wostringstream ss;
91 for (std::vector<Target*>::iterator i = _target->getFollowers()->begin(); i != _target->getFollowers()->end(); ++i)
92 {
93 ss << (*i)->getName(_game->getLanguage()) << L'\n';
94 }
95 _txtFollowers->setText(ss.str());
96 }
97
98 /**
99 *
100 */
~TargetInfoState()101 TargetInfoState::~TargetInfoState()
102 {
103
104 }
105
106 /**
107 * Picks a craft to intercept the UFO.
108 * @param action Pointer to an action.
109 */
btnInterceptClick(Action *)110 void TargetInfoState::btnInterceptClick(Action *)
111 {
112 _game->pushState(new InterceptState(_game, _globe, 0, _target));
113 }
114
115 /**
116 * Closes the window.
117 * @param action Pointer to an action.
118 */
btnOkClick(Action *)119 void TargetInfoState::btnOkClick(Action *)
120 {
121 _game->popState();
122 }
123
124 }
125