-
Notifications
You must be signed in to change notification settings - Fork 2
/
bridge.cpp
322 lines (274 loc) · 9.01 KB
/
bridge.cpp
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "bridge.h"
#include "graphics.h"
#include "sound.h"
namespace Unity {
BridgeScreen::BridgeScreen(UnityEngine *vm) : UIScreen(vm) {
}
BridgeScreen::~BridgeScreen() {
}
void BridgeScreen::start() {
_vm->clearObjects();
_vm->data._currentScreen.polygons.clear();
_vm->data._currentScreen.world = 0x5f;
_vm->data._currentScreen.screen = 0xff;
for (unsigned int i = 0; i < _vm->data._bridgeObjects.size(); i++) {
Object *obj = new Object(_vm);
// TODO: correct?
obj->x = _vm->data._bridgeObjects[i].x;
obj->y = _vm->data._bridgeObjects[i].y;
obj->y_adjust = _vm->data._bridgeObjects[i].y_adjust;
obj->y_adjust = -obj->y_adjust; // TODO: stupid hack
obj->flags = OBJFLAG_ACTIVE;
obj->objwalktype = OBJWALKTYPE_NORMAL;
obj->sprite = new SpritePlayer(_vm->data._bridgeObjects[i].filename.c_str(), obj, _vm);
// TODO: hardcoded random Riker walk-on anim, somewhere
/*if (i == 1 && _vm->_rnd->getRandomNumber(3) == 3)
obj->sprite->startAnim(5);
else*/
obj->sprite->startAnim(0);
/*debugN("%s: %d, %d\n", _vm->data._bridgeObjects[i].filename.c_str(),
_vm->data._bridgeObjects[i].unknown2);*/
_vm->data._currentScreen.objects.push_back(obj);
}
_vm->_gfx->setBackgroundImage("bridge.rm");
for (unsigned int i = 0; i < 6; i++) {
_bridgeObjects[i] = NULL;
}
_viewscreenMode = true;
_viewscreenView = NULL;
toggleViewscreen();
// TODO: create shared UI
_vm->_snd->playMusic("bridgamb.rac", 0x3f, 0);
}
void BridgeScreen::shutdown() {
for (unsigned int i = 0; i < 6; i++) {
if (_bridgeObjects[i])
_vm->removeObject(_bridgeObjects[i]);
delete _bridgeObjects[i];
_bridgeObjects[i] = NULL;
}
if (_viewscreenView)
_vm->removeObject(_viewscreenView);
delete _viewscreenView;
_viewscreenView = NULL;
// all remaining objects should still belong to us..
for (uint i = 0; i < _vm->data._currentScreen.objects.size(); i++) {
delete _vm->data._currentScreen.objects[i];
}
_vm->data._currentScreen.objects.clear();
}
void BridgeScreen::toggleViewscreen() {
_viewscreenMode = !_viewscreenMode;
// force palette reset
_vm->_gfx->setBackgroundImage("bridge.rm");
for (unsigned int i = 0; i < 6; i++) {
if (_bridgeObjects[i])
_vm->removeObject(_bridgeObjects[i]);
delete _bridgeObjects[i];
_bridgeObjects[i] = NULL;
}
if (_viewscreenView) {
_vm->removeObject(_viewscreenView);
delete _viewscreenView;
_viewscreenView = NULL;
}
if (_viewscreenMode) {
for (unsigned int i = 3; i < 6; i++) {
createBridgeUIObject(i);
}
_viewscreenView = new Object(_vm);
// TODO: correct?
_viewscreenView->x = 0;
_viewscreenView->y = 0;
_viewscreenView->y_adjust = -1501;
_viewscreenView->y_adjust = -_viewscreenView->y_adjust; // TODO: stupid hack
_viewscreenView->flags = OBJFLAG_ACTIVE;
_viewscreenView->objwalktype = OBJWALKTYPE_NORMAL;
uint spriteId = _vm->_viewscreen_sprite_id;
// TODO: deal with other ids?
Common::String sprFilename = _vm->data.getSpriteFilename(spriteId);
_viewscreenView->sprite = new SpritePlayer(sprFilename.c_str(), _viewscreenView, _vm);
_viewscreenView->sprite->startAnim(0);
_vm->data._currentScreen.objects.push_back(_viewscreenView);
} else {
for (unsigned int i = 0; i < 4; i++) {
createBridgeUIObject(i);
}
}
mouseMove(Common::Point(0, 0));
}
void BridgeScreen::mouseMove(const Common::Point &pos) {
_statusText.clear();
if (_viewscreenMode) {
_vm->_gfx->setCursor(0xffffffff, false);
return;
}
for (unsigned int i = 0; i < _vm->data._bridgeItems.size(); i++) {
BridgeItem &item = _vm->data._bridgeItems[i];
if ((uint)pos.x < item.x) continue;
if ((uint)pos.y < item.y) continue;
if ((uint)pos.x > item.x + item.width) continue;
if ((uint)pos.y > item.y + item.height) continue;
_statusText = item.description;
// TODO: this is kinda random :)
if (item.unknown1 < 0x32)
_vm->_gfx->setCursor(3, false);
else
_vm->_gfx->setCursor(5, false);
return;
}
_vm->_gfx->setCursor(0xffffffff, false);
}
void BridgeScreen::mouseClick(const Common::Point &pos) {
Common::Rect buttonRect(484, 426, 604, 467);
if (buttonRect.contains(pos)) {
// TODO: sound?
toggleViewscreen();
return;
}
// TODO: shared UI elements!
if (_viewscreenMode)
return;
for (unsigned int i = 0; i < _vm->data._bridgeItems.size(); i++) {
BridgeItem &item = _vm->data._bridgeItems[i];
if ((uint)pos.x < item.x) continue;
if ((uint)pos.y < item.y) continue;
if ((uint)pos.x > item.x + item.width) continue;
if ((uint)pos.y > item.y + item.height) continue;
debug(1, "user clicked bridge item %d", i);
if (item.id.world != 0) {
// bridge crew member
Object *obj = _vm->data.getObject(item.id);
obj->runHail(obj->talk_string);
} else {
switch (i) {
case 0: // conference lounge
// TODO
break;
case 1: // turbolift (menu)
_vm->_dialog_text.clear();
assert(!_vm->_choice_list.size());
_vm->_choice_list.clear();
assert(!_vm->_dialog_choosing);
for (unsigned int j = 0; j < _vm->data._bridgeScreenEntries.size(); j++) {
_vm->_choice_list.push_back(_vm->data._bridgeScreenEntries[j].text);
}
_vm->runDialog();
// TODO: do this properly
if (_vm->_beam_world != 0) {
_vm->startAwayTeam(_vm->_beam_world, _vm->_beam_screen);
}
_vm->_choice_list.clear();
break;
case 2: // comms
_vm->_snd->playSfx("beep7.mac");
// TODO
break;
case 3: // tactical
_vm->_snd->playSfx("tactical.mac");
_vm->changeToScreen(TacticalScreenType);
break;
case 4: // astrogation
_vm->_snd->playSfx("beep7.mac");
_vm->changeToScreen(AstrogationScreenType);
break;
case 5: // computer
_vm->_snd->playSfx("beep7.mac");
_vm->changeToScreen(ComputerScreenType);
break;
case 10: // replay conversation
// TODO
break;
default:
error("unknown bridge item");
}
}
return;
}
}
void BridgeScreen::draw() {
// the advice button is drawn as a sprite (see startBridge), sigh
// TODO: draw icons there if there's no subtitles
// sensor.mrg has buttons
// 4 sprites: "bridge" in/out and "viewscreen" in/out
MRGFile mrg;
_vm->_gfx->loadMRG("sensor.mrg", &mrg);
uint buttonId = 3;
if (_viewscreenMode)
buttonId = 1;
_vm->_gfx->drawMRG(&mrg, buttonId, 484, 426);
// transp.mrg
// 0-5: up arrows (normal, hilight, grayed) + down arrows
// 5-11: seek arrows (normal, hilight, grayed): 3 left then 3 right
// 11-17: 6 transporter room stuff?
// 18-19: normal admin menu, hilighted admin menu
// 20: some grey thing
// draw grayed up/down arrows
MRGFile tmrg;
_vm->_gfx->loadMRG("transp.mrg", &tmrg);
_vm->_gfx->drawMRG(&tmrg, 2, 117, 426);
_vm->_gfx->drawMRG(&tmrg, 5, 117, 450);
// display text (TODO: list of visited sectors)
Common::String buffer;
// TODO: sane max width/heights
// TODO: the location doesn't actually seem to come from this object
Object *ship = _vm->data.getObject(objectID(0x00, 0x01, 0x5f));
// TODO: updates while warping, etc
Common::String sector_name = _vm->data.getSectorName(ship->universe_x, ship->universe_y, ship->universe_z);
buffer = Common::String::format("SECTOR: %s", sector_name.c_str());
_vm->_gfx->drawString(9, 395, buffer, 2);
unsigned int warp_hi = 0, warp_lo = 0; // TODO
buffer = Common::String::format("WARP: %d.%d", warp_hi, warp_lo);
_vm->_gfx->drawString(168, 395, buffer, 2);
buffer = Common::String::format("%s", _statusText.c_str());
uint strwidth = _vm->_gfx->getStringWidth(buffer, 2);
// draw centered, with 544 being the centre
_vm->_gfx->drawString(544 - strwidth/2, 393, buffer, 2);
}
void BridgeScreen::createBridgeUIObject(uint i) {
const char *bridge_sprites[6] = {
"brdgldor.spr", // Left Door (conference room)
"brdgdoor.spr", // Door
"brdgtitl.spr", // Episode Title
"advice.spr", // advice button in UI :(
"viewscr.spr", // viewscreen UI
"viewscan.spr" // viewscreen anim
};
Object *obj = new Object(_vm);
_bridgeObjects[i] = obj;
obj->x = obj->y = 0;
switch (i) {
case 4:
// viewscr
obj->y_adjust = -1500;
break;
case 5:
// viewscan
obj->y_adjust = -1501;
break;
default:
obj->y_adjust = -1;
break;
}
obj->y_adjust = -obj->y_adjust; // TODO: stupid hack
obj->flags = OBJFLAG_ACTIVE;
obj->objwalktype = OBJWALKTYPE_NORMAL;
obj->sprite = new SpritePlayer(bridge_sprites[i], obj, _vm);
obj->sprite->startAnim(0);
_vm->data._currentScreen.objects.push_back(obj);
}
} // Unity