Repository navigation
Expand file tree
/
Copy pathUfoDetectedState.cpp
More file actions
153 lines (135 loc) · 4.76 KB
/
Copy pathUfoDetectedState.cpp
File metadata and controls
153 lines (135 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* Copyright 2010 OpenXcom Developers.
*
* This file is part of OpenXcom.
*
* OpenXcom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenXcom is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UfoDetectedState.h"
#include <sstream>
#include "../Engine/Game.h"
#include "../Resource/ResourcePack.h"
#include "../Engine/Language.h"
#include "../Engine/Font.h"
#include "../Engine/Palette.h"
#include "../Interface/TextButton.h"
#include "../Interface/Window.h"
#include "../Interface/Text.h"
#include "../Interface/TextList.h"
#include "../Savegame/Ufo.h"
#include "../Ruleset/RuleUfo.h"
#include "GeoscapeState.h"
#include "Globe.h"
#include "../Savegame/SavedGame.h"
namespace OpenXcom
{
/**
* Initializes all the elements in the Ufo Detected window.
* @param game Pointer to the core game.
* @param ufo Pointer to the UFO to get info from.
* @param state Pointer to the Geoscape.
* @param detected Was the UFO detected?
*/
UfoDetectedState::UfoDetectedState(Game *game, Ufo *ufo, GeoscapeState *state, bool detected) : State(game), _ufo(ufo), _state(state), _detected(detected)
{
// Generate UFO ID
if (_ufo->getId() == 0)
{
_ufo->setId(*_game->getSavedGame()->getUfoId());
(*_game->getSavedGame()->getUfoId())++;
}
_screen = false;
// Create objects
_window = new Window(this, 208, 120, 24, 48, POPUP_BOTH);
_btnCentre = new TextButton(160, 12, 48, 128);
_btnCancel = new TextButton(160, 12, 48, 144);
_txtUfo = new Text(160, 16, 48, 56);
_txtDetected = new Text(80, 8, 48, 72);
_lstInfo = new TextList(160, 32, 48, 82);
// Set palette
_game->setPalette(_game->getResourcePack()->getPalette("BACKPALS.DAT")->getColors(Palette::blockOffset(7)), Palette::backPos, 16);
add(_window);
add(_btnCentre);
add(_btnCancel);
add(_txtUfo);
add(_txtDetected);
add(_lstInfo);
// Set up objects
_window->setColor(Palette::blockOffset(8)+8);
_window->setBackground(_game->getResourcePack()->getSurface("BACK15.SCR"));
_btnCentre->setColor(Palette::blockOffset(8)+8);
_btnCentre->setText(_game->getLanguage()->getString("STR_CENTER_ON_UFO_TIME_5_SECS"));
_btnCentre->onMouseClick((ActionHandler)&UfoDetectedState::btnCentreClick);
_btnCancel->setColor(Palette::blockOffset(8)+8);
_btnCancel->setText(_game->getLanguage()->getString("STR_CANCEL_UC"));
_btnCancel->onMouseClick((ActionHandler)&UfoDetectedState::btnCancelClick);
_txtDetected->setColor(Palette::blockOffset(8)+5);
if (_detected)
{
_txtDetected->setText(_game->getLanguage()->getString("STR_DETECTED"));
}
else
{
_txtDetected->setText(L"");
}
_txtUfo->setColor(Palette::blockOffset(8)+5);
_txtUfo->setBig();
_txtUfo->setText(_ufo->getName(_game->getLanguage()));
_lstInfo->setColor(Palette::blockOffset(8)+5);
_lstInfo->setColumns(2, 82, 78);
_lstInfo->setDot(true);
_lstInfo->addRow(2, _game->getLanguage()->getString("STR_SIZE_UC").c_str(), _game->getLanguage()->getString(_ufo->getRules()->getSize()).c_str());
_lstInfo->getCell(0, 1)->setColor(Palette::blockOffset(8)+10);
_lstInfo->addRow(2, _game->getLanguage()->getString("STR_ALTITUDE").c_str(), _game->getLanguage()->getString(_ufo->getAltitude()).c_str());
_lstInfo->getCell(1, 1)->setColor(Palette::blockOffset(8)+10);
_lstInfo->addRow(2, _game->getLanguage()->getString("STR_HEADING").c_str(), _game->getLanguage()->getString(_ufo->getDirection()).c_str());
_lstInfo->getCell(2, 1)->setColor(Palette::blockOffset(8)+10);
std::wstringstream ss;
ss << _ufo->getSpeed();
_lstInfo->addRow(2, _game->getLanguage()->getString("STR_SPEED").c_str(), ss.str().c_str());
_lstInfo->getCell(3, 1)->setColor(Palette::blockOffset(8)+10);
_lstInfo->draw();
}
/**
*
*/
UfoDetectedState::~UfoDetectedState()
{
}
/**
* Resets the palette.
*/
void UfoDetectedState::init()
{
_game->setPalette(_game->getResourcePack()->getPalette("BACKPALS.DAT")->getColors(Palette::blockOffset(7)), Palette::backPos, 16);
}
/**
* Centers on the UFO and returns to the previous screen.
* @param action Pointer to an action.
*/
void UfoDetectedState::btnCentreClick(Action *action)
{
_state->timerReset();
_state->getGlobe()->center(_ufo->getLongitude(), _ufo->getLatitude());
_game->popState();
}
/**
* Returns to the previous screen.
* @param action Pointer to an action.
*/
void UfoDetectedState::btnCancelClick(Action *action)
{
_game->popState();
}
}