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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program 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 2
* of the License, or (at your option) any later version.
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "common/events.h"
#include "common/stream.h"
#include "graphics/cursorman.h"
#include "startrek/graphics.h"
namespace StarTrek {
/**
* Returns the index of the button at the given position, or -1 if none.
*/
int StarTrekEngine::getMenuButtonAt(const Menu &menu, int x, int y) {
for (int i = 0; i < menu.numButtons; i++) {
const Sprite &spr = menu.sprites[i];
if (spr.drawMode != 2)
continue;
int left = spr.pos.x - spr.bitmap->xoffset;
int top = spr.pos.y - spr.bitmap->yoffset;
// Oddly, this doesn't account for x/yoffset...
int right = spr.pos.x + spr.bitmap->width - 1;
int bottom = spr.pos.y + spr.bitmap->height - 1;
if (x >= left && x <= right && y >= top && y <= bottom)
return i;
}
return -1;
}
/**
* This chooses a sprite from the list to place the mouse cursor at. The sprite it chooses
* may be, for example, the top-leftmost one in the list. Exact behaviour is determined by
* the "mode" parameter.
*
* If "containMouseSprite" is a valid index, it's ensured that the mouse is contained
* within it. "mode" should be -1 in this case.
*/
void StarTrekEngine::chooseMousePositionFromSprites(Sprite *sprites, int numSprites, int containMouseSprite, int mode) {
uint16 mouseX1 = 0x7fff; // Candidate positions to warp mouse to
uint16 mouseY1 = 0x7fff;
uint16 mouseX2 = 0x7fff;
uint16 mouseY2 = 0x7fff;
Common::Point mousePos = _gfx->getMousePos();
// Ensure the cursor is contained within one of the sprites
if (containMouseSprite >= 0 && containMouseSprite < numSprites) {
Common::Rect rect = sprites[containMouseSprite].getRect();
if (mousePos.x < rect.left || mousePos.x >= rect.right
|| mousePos.y < rect.top || mousePos.y >= rect.bottom) {
mousePos.x = (rect.left + rect.right) / 2;
mousePos.y = (rect.top + rect.bottom) / 2;
}
}
// Choose a sprite to warp the cursor to
for (int i = 0; i < numSprites; i++) {
Sprite *sprite = &sprites[i];
if (sprite->drawMode != 2) // Skip hidden buttons
continue;
Common::Rect rect = sprite->getRect();
int hCenter = (rect.left + rect.right) / 2;
int vCenter = (rect.top + rect.bottom) / 2;
// Choose which sprite is closest based on certain criteria?
switch(mode) {
case 0: // Choose topmost, leftmost sprite that's below the cursor
if (((vCenter == mousePos.y && hCenter > mousePos.x) || vCenter > mousePos.y)
&& (vCenter < mouseY1 || (vCenter == mouseY1 && hCenter < mouseX1))) {
mouseX1 = hCenter;
mouseY1 = vCenter;
}
// fall through
case 4: // Choose topmost, leftmost sprite
if (vCenter < mouseY2 || (vCenter == mouseY2 && hCenter < mouseX2)) {
mouseX2 = hCenter;
mouseY2 = vCenter;
}
break;
case 1: // Choose bottommost, rightmost sprite that's above the cursor
if (((vCenter == mousePos.y && hCenter < mousePos.x) || vCenter < mousePos.y)
&& (mouseY1 == 0x7fff || vCenter > mouseY1
|| (vCenter == mouseY1 && hCenter > mouseX1))) {
mouseX1 = hCenter;
mouseY1 = vCenter;
}
// fall through
case 5: // Choose bottommost, rightmost sprite
if (mouseY2 == 0x7fff || vCenter > mouseY2
|| (vCenter == mouseY2 && hCenter > mouseX2)) {
mouseX2 = hCenter;
mouseY2 = vCenter;
}
break;
case 2:
// This seems broken... OR condition on first line has no affect on the logic...
if ((vCenter < mousePos.y || (vCenter == mouseY1 && hCenter == mousePos.x))
&& (mouseX1 == 0x7fff || vCenter >= mouseY1)) {
mouseX1 = hCenter;
mouseY1 = vCenter;
debug("Try %d %d", mouseX1, mouseY1);
}
if (mouseX2 == 0x7fff || vCenter > mouseY2
|| (hCenter == mouseX2 && vCenter == mouseY2)) {
mouseX2 = hCenter;
mouseY2 = vCenter;
}
break;
case 3:
// Similar to above...
if ((vCenter > mousePos.y || (vCenter == mouseY1 && hCenter == mousePos.x))
&& (mouseX1 == 0x7fff || vCenter <= mouseY1)) {
mouseX1 = hCenter;
mouseY1 = vCenter;
}
if (mouseX2 == 0x7fff || vCenter < mouseY2
|| (hCenter == mouseX2 && vCenter == mouseY2)) {
mouseX2 = hCenter;
mouseY2 = vCenter;
}
break;
}
}
// Warp mouse to one of the coordinates, if one is valid
if (mouseX1 != 0x7fff) {
mousePos.x = mouseX1;
mousePos.y = mouseY1;
}
else if (mouseX2 != 0x7fff) {
mousePos.x = mouseX2;
mousePos.y = mouseY2;
}
_gfx->warpMouse(mousePos.x, mousePos.y);
}
/**
* Draws or removes the outline on menu buttons when the cursor hovers on them, or leaves
* them.
*/
void StarTrekEngine::drawMenuButtonOutline(SharedPtr<Bitmap> bitmap, byte color) {
int lineWidth = bitmap->width-2;
int offsetToBottom = (bitmap->height-3)*bitmap->width;
byte *dest = bitmap->pixels + bitmap->width + 1;
while (lineWidth--) {
*dest = color;
*(dest+offsetToBottom) = color;
dest++;
}
int lineHeight = bitmap->height - 2;
int offsetToRight = bitmap->width - 3;
dest = bitmap->pixels + bitmap->width + 1;
while (lineHeight--) {
*dest = color;
*(dest+offsetToRight) = color;
dest += bitmap->width;
}
}
void StarTrekEngine::showOptionsMenu(int x, int y) {
bool tmpMouseControllingShip = _mouseControllingShip;
_mouseControllingShip = false;
Common::Point oldMousePos = _gfx->getMousePos();
SharedPtr<Bitmap> oldMouseBitmap = _gfx->getMouseBitmap();
_gfx->setMouseBitmap(_gfx->loadBitmap("options"));
loadMenuButtons("options", x, y);
uint32 disabledButtons = 0;
if (_musicWorking) {
if (_musicEnabled)
disabledButtons |= (1 << OPTIONBUTTON_ENABLEMUSIC);
else
disabledButtons |= (1 << OPTIONBUTTON_DISABLEMUSIC);
}
else
disabledButtons |= (1 << OPTIONBUTTON_ENABLEMUSIC) | (1 << OPTIONBUTTON_DISABLEMUSIC);
if (_sfxWorking) {
if (_sfxEnabled)
disabledButtons |= (1 << OPTIONBUTTON_ENABLESFX);
else
disabledButtons |= (1 << OPTIONBUTTON_DISABLESFX);
}
else
disabledButtons |= (1 << OPTIONBUTTON_ENABLESFX) | (1 << OPTIONBUTTON_DISABLESFX);
disableMenuButtons(disabledButtons);
chooseMousePositionFromSprites(_activeMenu->sprites, _activeMenu->numButtons, -1, 4);
int event = handleMenuEvents(0, false);
unloadMenuButtons();
_mouseControllingShip = tmpMouseControllingShip;
_gfx->setMouseBitmap(oldMouseBitmap);
if (event != MENUEVENT_LCLICK_OFFBUTTON && event != MENUEVENT_RCLICK_OFFBUTTON)
_gfx->warpMouse(oldMousePos.x, oldMousePos.y);
// Can't use OPTIONBUTTON constants since the button retvals differ from the button
// indices...
switch(event) {
case 0: // Save
showSaveMenu();
break;
case 1: // Load
showLoadMenu();
break;
case 2: // Enable music
_sound->setMusicEnabled(true);
break;
case 3: // Disable music
_sound->setMusicEnabled(false);
break;
case 4: // Enable sfx
_sound->setSfxEnabled(true);
break;
case 5: // Disable sfx
_sound->setSfxEnabled(false);
break;
case 6: // Quit
showQuitGamePrompt(20, 20);
break;
case 7: // Text
showTextConfigurationMenu(true);
break;
default:
break;
}
}
/**
* Show the "action selection" menu, ie. look, talk, etc.
*/
int StarTrekEngine::showActionMenu() {
const int actionMappingUp[] = { // Actions to jump to when up is pressed
ACTION_TALK, // <- ACTION_WALK
ACTION_TALK, // <- ACTION_USE
ACTION_OPTIONS, // <- ACTION_GET
ACTION_LOOK, // <- ACTION_LOOK
ACTION_LOOK, // <- ACTION_TALK
ACTION_OPTIONS // <- ACTION_OPTIONS
};
const int actionMappingRight[] = { // Actions to jump to when right is pressed
ACTION_GET, // <- ACTION_WALK
ACTION_WALK, // <- ACTION_USE
ACTION_GET, // <- ACTION_GET
ACTION_OPTIONS, // <- ACTION_LOOK
ACTION_OPTIONS, // <- ACTION_TALK
ACTION_OPTIONS // <- ACTION_OPTIONS
};
const int actionMappingDown[] = { // Actions to jump to when down is pressed
ACTION_GET, // <- ACTION_WALK
ACTION_WALK, // <- ACTION_USE
ACTION_GET, // <- ACTION_GET
ACTION_TALK, // <- ACTION_LOOK
ACTION_WALK, // <- ACTION_TALK
ACTION_GET // <- ACTION_OPTIONS
};
const int actionMappingLeft[] = { // Actions to jump to when left is pressed
ACTION_USE, // <- ACTION_WALK
ACTION_USE, // <- ACTION_USE
ACTION_WALK, // <- ACTION_GET
ACTION_USE, // <- ACTION_LOOK
ACTION_USE, // <- ACTION_TALK
ACTION_LOOK // <- ACTION_OPTIONS
};
const Common::Point pos(50, 50); // Top-left position to put action menu at
// Positions to put mouse cursor at to select actions (when using arrow keys)
const Common::Point actionPositions[] = {
Common::Point(7, 21), // ACTION_USE
Common::Point(48, 38), // ACTION_GET
Common::Point(28, 5), // ACTION_LOOK
Common::Point(28, 14), // ACTION_TALK
Common::Point(45, 9) // ACTION_OPTIONS
};
TrekEvent event;
Sprite menuSprite;
bool keyboardControlledMouse = _keyboardControlsMouse;
Common::Point oldMousePos = _gfx->getMousePos();
bool addEventBack = false;
int action = ACTION_WALK;
menuSprite.bitmap = _gfx->loadBitmap("action");
int menuWidth = menuSprite.bitmap->width;
int menuHeight = menuSprite.bitmap->height;
_gfx->warpMouse(pos.x + menuWidth / 2, pos.y + menuHeight / 2);
_gfx->addSprite(&menuSprite);
menuSprite.pos = pos;
menuSprite.drawPriority = 15;
chooseMouseBitmapForAction(action, false);
_gfx->drawAllSprites();
menuSprite.drawPriority2 = 8;
bool displayMenu = true;
while (displayMenu) {
_sound->checkLoopMusic();
if (!popNextEvent(&event))
continue;
switch (event.type) {
case TREKEVENT_TICK:
_gfx->incPaletteFadeLevel();
_gfx->drawAllSprites();
break;
case TREKEVENT_LBUTTONDOWN:
selectAndExit:
displayMenu = false;
addEventBack = true;
break;
case TREKEVENT_MOUSEMOVE:
mousePosChanged:
{
Common::Point mouse = _gfx->getMousePos();
Common::Point relMouse(mouse.x - pos.x, mouse.y - pos.y);
Common::String bitmapName;
Common::Point lockMousePoint(-1, -1);
// Check if the mouse is hovering over one of the selectable actions
if (relMouse.x >= 39 && relMouse.x <= 50 && relMouse.y >= 2 && relMouse.y <= 17) {
action = ACTION_OPTIONS;
bitmapName = "options";
lockMousePoint = Common::Point(pos.x + 44, pos.y + 2);
}
else if (relMouse.x >= 18 && relMouse.x <= 38 && relMouse.y >= 2 && relMouse.y <= 9) {
action = ACTION_LOOK;
bitmapName = "look";
lockMousePoint = Common::Point(pos.x + 28, pos.y + 6);
}
else if (relMouse.x >= 18 && relMouse.x <= 38 && relMouse.y >= 11 && relMouse.y <= 17) {
action = ACTION_TALK;
bitmapName = "talk";
lockMousePoint = Common::Point(pos.x + 27, pos.y + 14);
}
else if (relMouse.x >= 2 && relMouse.x <= 13 && relMouse.y >= 16 && relMouse.y <= 26) {
action = ACTION_USE;
bitmapName = "use";
lockMousePoint = Common::Point(pos.x + 7, pos.y + 19);
}
else if (relMouse.x >= 40 && relMouse.x <= 53 && relMouse.y >= 34 && relMouse.y <= 43) {
action = ACTION_GET;
bitmapName = "get";
lockMousePoint = Common::Point(pos.x + 44, pos.y + 38);
}
else {
action = ACTION_WALK;
bitmapName = "walk";
}
_gfx->setMouseBitmap(_gfx->loadBitmap(bitmapName));
if (lockMousePoint.x != -1)
_gfx->lockMousePosition(lockMousePoint.x, lockMousePoint.y);
else
_gfx->unlockMousePosition();
}
break;
case TREKEVENT_RBUTTONDOWN:
exitMenu:
displayMenu = false;
action = ACTION_WALK;
break;
case TREKEVENT_KEYDOWN: {
int nextAction = action;
const int *lookupArray;
switch (event.kbd.keycode) {
case Common::KEYCODE_ESCAPE:
case Common::KEYCODE_SPACE:
case Common::KEYCODE_F2: // Exit menu without selecting anything
goto exitMenu;
goto exitMenu;
case Common::KEYCODE_RETURN:
case Common::KEYCODE_KP_ENTER:
case Common::KEYCODE_F1: // Exit menu with whatever is selected
goto selectAndExit;
case Common::KEYCODE_PAGEUP:
case Common::KEYCODE_KP9:
nextAction = ACTION_OPTIONS;
break;
case Common::KEYCODE_PAGEDOWN:
case Common::KEYCODE_KP3:
nextAction = ACTION_GET;
break;
// Direction buttons
case Common::KEYCODE_UP:
case Common::KEYCODE_KP8:
lookupArray = actionMappingUp;
goto lookupNextAction;
case Common::KEYCODE_RIGHT:
case Common::KEYCODE_KP6:
lookupArray = actionMappingRight;
goto lookupNextAction;
case Common::KEYCODE_DOWN:
case Common::KEYCODE_KP2:
lookupArray = actionMappingDown;
goto lookupNextAction;
case Common::KEYCODE_LEFT:
case Common::KEYCODE_KP4:
lookupArray = actionMappingLeft;
goto lookupNextAction;
lookupNextAction:
// Use a lookup table to decide which action is next after a direction
// button is pressed.
assert((action >= ACTION_WALK && action <= ACTION_TALK) || action == ACTION_OPTIONS);
nextAction = lookupArray[action == ACTION_OPTIONS ? 5 : action - 1];
break;
default:
break;
}
if (nextAction == action)
break;
action = nextAction;
// Warp mouse to the position of the selected action
if (nextAction == ACTION_WALK)
_gfx->warpMouse(pos.x + menuWidth / 2, pos.y + menuHeight / 2);
else {
assert((action >= ACTION_WALK && action <= ACTION_TALK) || action == ACTION_OPTIONS);
const Common::Point &p = actionPositions[action == ACTION_OPTIONS ? 4 : action - 2];
_gfx->warpMouse(pos.x + p.x, pos.y + p.y);
}
goto mousePosChanged;
}
default:
break;
}
}
playSoundEffectIndex(0x10);
menuSprite.dontDrawNextFrame();
_gfx->drawAllSprites();
_gfx->delSprite(&menuSprite);
_gfx->unlockMousePosition();
if (action == ACTION_OPTIONS) {
showOptionsMenu(50, 50);
action = ACTION_WALK;
}
Common::Point mouse = _gfx->getMousePos();
if (mouse.x < pos.x || mouse.x >= pos.x + menuWidth || mouse.y < pos.y || mouse.y >= pos.y + menuHeight) {
if (action == ACTION_WALK && addEventBack)
addEventToQueue(event); // Add left-click event back to queue so Kirk can walk there
}
else
_gfx->warpMouse(oldMousePos.x, oldMousePos.y);
chooseMouseBitmapForAction(action, false);
_keyboardControlsMouse = keyboardControlledMouse;
return action;
}
/**
* Loads a .MNU file, which is a list of buttons to display.
*/
void StarTrekEngine::loadMenuButtons(String mnuFilename, int xpos, int ypos) {
if (_activeMenu == nullptr)
_keyboardControlsMouseOutsideMenu = _keyboardControlsMouse;
SharedPtr<Menu> oldMenu = _activeMenu;
_activeMenu = SharedPtr<Menu>(new Menu());
_activeMenu->nextMenu = oldMenu;
SharedPtr<FileStream> stream = loadFile(mnuFilename + ".MNU");
_activeMenu->menuFile = stream;
_activeMenu->numButtons = _activeMenu->menuFile->size() / 16;
for (int i = 0; i < _activeMenu->numButtons; i++) {
memset(&_activeMenu->sprites[i], 0, sizeof(Sprite));
_gfx->addSprite(&_activeMenu->sprites[i]);
_activeMenu->sprites[i].drawMode = 2;
char bitmapBasename[11];
stream->seek(i * 16, SEEK_SET);
stream->read(bitmapBasename, 10);
for (int j = 0; j < 10; j++) {
if (bitmapBasename[j] == ' ')
bitmapBasename[j] = '\0';
}
bitmapBasename[10] = '\0';
_activeMenu->sprites[i].bitmap = _gfx->loadBitmap(bitmapBasename);
_activeMenu->sprites[i].pos.x = stream->readUint16() + xpos;
_activeMenu->sprites[i].pos.y = stream->readUint16() + ypos;
_activeMenu->retvals[i] = stream->readUint16();
_activeMenu->sprites[i].drawPriority = 15;
_activeMenu->sprites[i].drawPriority2 = 8;
}
if (_activeMenu->retvals[_activeMenu->numButtons - 1] == 0) {
// Set default retvals for buttons
for (int i = 0; i < _activeMenu->numButtons; i++)
_activeMenu->retvals[i] = i;
}
_activeMenu->selectedButton = -1;
_activeMenu->disabledButtons = 0;
_keyboardControlsMouse = false;
}
/**
* Sets which buttons are visible based on the given bitmask.
*/
void StarTrekEngine::setVisibleMenuButtons(uint32 bits) {
for (int i = 0; i < _activeMenu->numButtons; i++) {
Sprite *sprite = &_activeMenu->sprites[i];
uint32 spriteBitmask = (1 << i);
if (spriteBitmask == 0)
break;
if ((bits & spriteBitmask) == 0 || sprite->drawMode != 0) {
if ((bits & spriteBitmask) == 0 && sprite->drawMode == 2) {
if (i == _activeMenu->selectedButton) {
drawMenuButtonOutline(sprite->bitmap, 0x00);
_activeMenu->selectedButton = -1;
}
sprite->field16 = true;
sprite->bitmapChanged = true;
}
}
else {
_gfx->addSprite(sprite);
sprite->drawMode = 2;
sprite->bitmapChanged = true;
}
}
_gfx->drawAllSprites();
for (int i = 0; i < _activeMenu->numButtons; i++) {
Sprite *sprite = &_activeMenu->sprites[i];
uint32 spriteBitmask = (1 << i);
if (spriteBitmask == 0)
break;
if ((bits & spriteBitmask) == 0 && sprite->drawMode == 2) {
_gfx->delSprite(sprite);
// Setting drawMode to 0 is the game's way of saying that the menu button is
// hidden (since it would normally be 2).
sprite->drawMode = 0;
}
}
}
/**
* Disables the given bitmask of buttons.
*/
void StarTrekEngine::disableMenuButtons(uint32 bits) {
_activeMenu->disabledButtons |= bits;
if (_activeMenu->selectedButton != -1
&& (_activeMenu->disabledButtons & (1 << _activeMenu->selectedButton))) {
Sprite *sprite = &_activeMenu->sprites[_activeMenu->selectedButton];
drawMenuButtonOutline(sprite->bitmap, 0x00);
sprite->bitmapChanged = true;
_activeMenu->selectedButton = -1;
}
}
void StarTrekEngine::enableMenuButtons(uint32 bits) {
_activeMenu->disabledButtons &= ~bits;
}
/**
* This returns either a special menu event (negative number) or the retval of the button
* clicked (usually an index, always positive).
*/
int StarTrekEngine::handleMenuEvents(uint32 ticksUntilClickingEnabled, bool arg4) {
// TODO: finish
uint32 tickWhenClickingEnabled = _clockTicks + ticksUntilClickingEnabled;
while (true) {
TrekEvent event;
while (popNextEvent(&event)) {
switch(event.type) {
case TREKEVENT_TICK: {
case TREKEVENT_MOUSEMOVE: // FIXME: actual game only uses TICK event here
Common::Point mousePos = _gfx->getMousePos();
int buttonIndex = getMenuButtonAt(*_activeMenu, mousePos.x, mousePos.y);
if (buttonIndex != -1) {
if (_activeMenu->disabledButtons & (1<<buttonIndex))
buttonIndex = -1;
}
if (buttonIndex != _activeMenu->selectedButton) {
if (_activeMenu->selectedButton != -1) {
Sprite &spr = _activeMenu->sprites[_activeMenu->selectedButton];
drawMenuButtonOutline(spr.bitmap, 0x00);
spr.bitmapChanged = true;
}
if (buttonIndex != -1) {
Sprite &spr = _activeMenu->sprites[buttonIndex];
drawMenuButtonOutline(spr.bitmap, 0xda);
spr.bitmapChanged = true;
}
_activeMenu->selectedButton = buttonIndex;
}
// Not added: updating mouse position (scummvm handles that)
// sub_10492();
// sub_10A91();
_gfx->drawAllSprites();
// sub_10BE7();
// sub_2A4B1();
if (_finishedPlayingSpeech != 0) {
_finishedPlayingSpeech = 0;
if (_textDisplayMode != TEXTDISPLAY_WAIT) {
return TEXTBUTTON_SPEECH_DONE;
}
}
// sub_1E88C();
_frameIndex++;
if (ticksUntilClickingEnabled != 0 && _clockTicks >= tickWhenClickingEnabled)
return MENUEVENT_ENABLEINPUT;
break;
}
case TREKEVENT_LBUTTONDOWN:
if (_activeMenu->selectedButton != -1) {
playSoundEffectIndex(0x10);
return _activeMenu->retvals[_activeMenu->selectedButton];
}
else {
Common::Point mouse = _gfx->getMousePos();
if (getMenuButtonAt(*_activeMenu, mouse.x, mouse.y) == -1) {
playSoundEffectIndex(0x10);
return MENUEVENT_LCLICK_OFFBUTTON;
}
}
break;
case TREKEVENT_RBUTTONDOWN:
// TODO
break;
case TREKEVENT_KEYDOWN:
// TODO
break;
default:
break;
}
}
}
}
void StarTrekEngine::unloadMenuButtons() {
if (_activeMenu->selectedButton != -1)
drawMenuButtonOutline(_activeMenu->sprites[_activeMenu->selectedButton].bitmap, 0x00);
for (int i = 0; i < _activeMenu->numButtons; i++) {
Sprite *sprite = &_activeMenu->sprites[i];
if (sprite->drawMode == 2) {
sprite->field16 = true;
sprite->bitmapChanged = true;
}
}
_gfx->drawAllSprites();
for (int i = 0; i < _activeMenu->numButtons; i++) {
Sprite *sprite = &_activeMenu->sprites[i];
sprite->bitmap.reset();
if (sprite->drawMode == 2)
_gfx->delSprite(sprite);
}
_activeMenu = _activeMenu->nextMenu;
if (_activeMenu == nullptr)
_keyboardControlsMouse = _keyboardControlsMouseOutsideMenu;
}
/**
* Sets the mouse bitmap based on which action is selected.
*/
void StarTrekEngine::chooseMouseBitmapForAction(int action, bool withRedOutline) {
const char *lookActionBitmaps[] = {
"lookh0", // The "look" action randomly animates with these images
"lookh0",
"lookh0",
"lookh0",
"lookh0",
"lookh1",
"lookh2",
"lookh3"
};
Common::String bitmapName;
switch (action) {
case ACTION_USE:
if (withRedOutline)
bitmapName = "useh";
else
bitmapName = "usen";
break;
case ACTION_GET:
if (withRedOutline)
bitmapName = "geth";
else
bitmapName = "getn";
break;
case ACTION_LOOK:
if (withRedOutline) {
if ((getRandomWord() & 7) == 0)
_lookActionBitmapIndex = getRandomWord() & 7; // Choose an image randomly
bitmapName = lookActionBitmaps[_lookActionBitmapIndex];
}
else
bitmapName = "lookn";
break;
case ACTION_TALK:
if (withRedOutline) {
if (getRandomWord() & 3)
bitmapName = "talkh0";
else
bitmapName = "talkh1";
}
else
bitmapName = "talkn";
break;
case ACTION_OPTIONS:
bitmapName = "options";
break;
case ACTION_WALK:
default:
bitmapName = "walk";
break;
}
_gfx->setMouseBitmap(_gfx->loadBitmap(bitmapName));
}
void StarTrekEngine::showSaveMenu() {
// TODO
}
void StarTrekEngine::showLoadMenu() {
// TODO
}
void StarTrekEngine::showQuitGamePrompt(int x, int y) {
const char *options[] = {
"Quit Game",
"#GENE\\GENER028#Yes, quit the game.",
"#GENE\\GENER008#No, do not quit the game.",
""
};
if (_inQuitGameMenu)
return;
_inQuitGameMenu = true;
int val = showText(&StarTrekEngine::readTextFromArray, (uintptr)options, x, y, 0xb0, true, 0, 1);
_inQuitGameMenu = false;
if (val == 0) {
// sub_1e70d();
_system->quit();
}
}
/**
* This can be called from startup or from the options menu.
* On startup, this tries to load the setting without user input.
*/
void StarTrekEngine::showTextConfigurationMenu(bool fromOptionMenu) {
const char *options[] = { // TODO: languages...
"Text display",
"Text subtitles.",
"Display text until you press enter.",
"No text displayed.",
""
};
int val;
if (fromOptionMenu || (val = loadTextDisplayMode()) == -1) {
val = showText(&StarTrekEngine::readTextFromArray, (uintptr)options, 20, 30, 0xb0, true, 0, 1);
saveTextDisplayMode(val);
}
switch(val) {
case 0:
_textDisplayMode = TEXTDISPLAY_SUBTITLES;
break;
case 1:
_textDisplayMode = TEXTDISPLAY_WAIT;
break;
case 2:
_textDisplayMode = TEXTDISPLAY_NONE;
break;
}
}
int StarTrekEngine::loadTextDisplayMode() {
return -1; // TODO
}
void StarTrekEngine::saveTextDisplayMode(int value) {
// TODO;
}
}
|