-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuigame.c
2032 lines (1676 loc) · 51.8 KB
/
uigame.c
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
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- mode: c; tab-width: 4; c-basic-offset: 4; c-file-style: "linux" -*- */
//
// Copyright (c) 2009-2011, Wei Mingzhi <[email protected]>.
// Copyright (c) 2011-2020, SDLPAL development team.
// All rights reserved.
//
// This file is part of SDLPAL.
//
// SDLPAL 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.
//
// 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, see <http://www.gnu.org/licenses/>.
//
#include "main.h"
static BOOL __buymenu_firsttime_render;
static WORD GetSavedTimes(int iSaveSlot)
{
FILE *fp = UTIL_OpenFileAtPath(gConfig.pszSavePath, PAL_va(0, "%d.rpg", iSaveSlot));
WORD wSavedTimes = 0;
if (fp != NULL)
{
if (fread(&wSavedTimes, sizeof(WORD), 1, fp) == 1)
wSavedTimes = SDL_SwapLE16(wSavedTimes);
else
wSavedTimes = 0;
fclose(fp);
}
return wSavedTimes;
}
VOID
PAL_DrawOpeningMenuBackground(
VOID
)
/*++
Purpose:
Draw the background of the main menu.
Parameters:
None.
Return value:
None.
--*/
{
LPBYTE buf;
buf = (LPBYTE)malloc(320 * 200);
if (buf == NULL)
{
return;
}
//
// Read the picture from fbp.mkf.
//
PAL_MKFDecompressChunk(buf, 320 * 200, MAINMENU_BACKGROUND_FBPNUM, gpGlobals->f.fpFBP);
//
// ...and blit it to the screen buffer.
//
PAL_FBPBlitToSurface(buf, gpScreen);
VIDEO_UpdateScreen(NULL);
free(buf);
}
INT
PAL_OpeningMenu(
VOID
)
/*++
Purpose:
Show the opening menu.
Parameters:
None.
Return value:
Which saved slot to load from (1-5). 0 to start a new game.
--*/
{
WORD wItemSelected;
WORD wDefaultItem = 0;
INT w[2] = { PAL_WordWidth(MAINMENU_LABEL_NEWGAME), PAL_WordWidth(MAINMENU_LABEL_LOADGAME) };
MENUITEM rgMainMenuItem[2] = {
// value label enabled position
{ 0, MAINMENU_LABEL_NEWGAME, TRUE, PAL_XY(125 - (w[0] > 4 ? (w[0] - 4) * 8 : 0), 95) },
{ 1, MAINMENU_LABEL_LOADGAME, TRUE, PAL_XY(125 - (w[1] > 4 ? (w[1] - 4) * 8 : 0), 112) }
};
//
// Play the background music
//
AUDIO_PlayMusic(RIX_NUM_OPENINGMENU, TRUE, 1);
//
// Draw the background
//
PAL_DrawOpeningMenuBackground();
PAL_FadeIn(0, FALSE, 1);
while (TRUE)
{
//
// Activate the menu
//
wItemSelected = PAL_ReadMenu(NULL, rgMainMenuItem, 2, wDefaultItem, MENUITEM_COLOR);
if (wItemSelected == 0 || wItemSelected == MENUITEM_VALUE_CANCELLED)
{
//
// Start a new game
//
wItemSelected = 0;
break;
}
else
{
//
// Load game
//
VIDEO_BackupScreen(gpScreen);
wItemSelected = PAL_SaveSlotMenu(1);
VIDEO_RestoreScreen(gpScreen);
VIDEO_UpdateScreen(NULL);
if (wItemSelected != MENUITEM_VALUE_CANCELLED)
{
break;
}
wDefaultItem = 1;
}
}
//
// Fade out the screen and the music
//
AUDIO_PlayMusic(0, FALSE, 1);
PAL_FadeOut(1);
if (wItemSelected == 0)
{
PAL_PlayAVI("3.avi");
}
return (INT)wItemSelected;
}
INT
PAL_SaveSlotMenu(
WORD wDefaultSlot
)
/*++
Purpose:
Show the load game menu.
Parameters:
[IN] wDefaultSlot - default save slot number (1-5).
Return value:
Which saved slot to load from (1-5). MENUITEM_VALUE_CANCELLED if cancelled.
--*/
{
LPBOX rgpBox[5];
int i, w = PAL_WordMaxWidth(LOADMENU_LABEL_SLOT_FIRST, 5);
int dx = (w > 4) ? (w - 4) * 16 : 0;
WORD wItemSelected;
MENUITEM rgMenuItem[5];
const SDL_Rect rect = { 195 - dx, 7, 120 + dx, 190 };
//
// Create the boxes and create the menu items
//
for (i = 0; i < 5; i++)
{
// Fix render problem with shadow
rgpBox[i] = PAL_CreateSingleLineBox(PAL_XY(195 - dx, 7 + 38 * i), 6 + (w > 4 ? w - 4 : 0), FALSE);
rgMenuItem[i].wValue = i + 1;
rgMenuItem[i].fEnabled = TRUE;
rgMenuItem[i].wNumWord = LOADMENU_LABEL_SLOT_FIRST + i;
rgMenuItem[i].pos = PAL_XY(210 - dx, 17 + 38 * i);
}
//
// Draw the numbers of saved times
//
for (i = 1; i <= 5; i++)
{
//
// Draw the number
//
PAL_DrawNumber((UINT)GetSavedTimes(i), 4, PAL_XY(270, 38 * i - 17),
kNumColorYellow, kNumAlignRight);
}
//
// Activate the menu
//
wItemSelected = PAL_ReadMenu(NULL, rgMenuItem, 5, wDefaultSlot - 1, MENUITEM_COLOR);
//
// Delete the boxes
//
for (i = 0; i < 5; i++)
{
PAL_DeleteBox(rgpBox[i]);
}
VIDEO_UpdateScreen(&rect);
return wItemSelected;
}
static
WORD
PAL_SelectionMenu(
int nWords,
int nDefault,
WORD wItems[]
)
/*++
Purpose:
Show a common selection box.
Parameters:
[IN] nWords - number of emnu items.
[IN] nDefault - index of default item.
[IN] wItems - item word array.
Return value:
User-selected index.
--*/
{
LPBOX rgpBox[4];
MENUITEM rgMenuItem[4];
int w[4] = {
(nWords >= 1 && wItems[0]) ? PAL_WordWidth(wItems[0]) : 1,
(nWords >= 2 && wItems[1]) ? PAL_WordWidth(wItems[1]) : 1,
(nWords >= 3 && wItems[2]) ? PAL_WordWidth(wItems[2]) : 1,
(nWords >= 4 && wItems[3]) ? PAL_WordWidth(wItems[3]) : 1 };
int dx[4] = { (w[0] - 1) * 16, (w[1] - 1) * 16, (w[2] - 1) * 16, (w[3] - 1) * 16 }, i;
PAL_POS pos[4] = { PAL_XY(145, 110), PAL_XY(220 + dx[0], 110), PAL_XY(145, 160), PAL_XY(220 + dx[2], 160) };
WORD wReturnValue;
const SDL_Rect rect = { 130, 100, 125 + max(dx[0] + dx[1], dx[2] + dx[3]), 100 };
for (i = 0; i < nWords; i++)
if (nWords > i && !wItems[i])
return MENUITEM_VALUE_CANCELLED;
//
// Create menu items
//
for (i = 0; i < nWords; i++)
{
rgMenuItem[i].fEnabled = TRUE;
rgMenuItem[i].pos = pos[i];
rgMenuItem[i].wValue = i;
rgMenuItem[i].wNumWord = wItems[i];
}
//
// Create the boxes
//
dx[1] = dx[0]; dx[3] = dx[2]; dx[0] = dx[2] = 0;
for (i = 0; i < nWords; i++)
{
rgpBox[i] = PAL_CreateSingleLineBox(PAL_XY(130 + 75 * (i % 2) + dx[i], 100 + 50 * (i / 2)), w[i] + 1, TRUE);
}
//
// Activate the menu
//
wReturnValue = PAL_ReadMenu(NULL, rgMenuItem, nWords, nDefault, MENUITEM_COLOR);
//
// Delete the boxes
//
for (i = 0; i < nWords; i++)
{
PAL_DeleteBox(rgpBox[i]);
}
VIDEO_UpdateScreen(&rect);
return wReturnValue;
}
WORD
PAL_TripleMenu(
WORD wThirdWord
)
/*++
Purpose:
Show a triple-selection box.
Parameters:
None.
Return value:
User-selected index.
--*/
{
WORD wItems[3] = { CONFIRMMENU_LABEL_NO, CONFIRMMENU_LABEL_YES, wThirdWord };
return PAL_SelectionMenu(3, 0, wItems);
}
BOOL
PAL_ConfirmMenu(
VOID
)
/*++
Purpose:
Show a "Yes or No?" confirm box.
Parameters:
None.
Return value:
TRUE if user selected Yes, FALSE if selected No.
--*/
{
WORD wItems[2] = { CONFIRMMENU_LABEL_NO, CONFIRMMENU_LABEL_YES };
WORD wReturnValue = PAL_SelectionMenu(2, 0, wItems);
return (wReturnValue == MENUITEM_VALUE_CANCELLED || wReturnValue == 0) ? FALSE : TRUE;
}
BOOL
PAL_SwitchMenu(
BOOL fEnabled
)
/*++
Purpose:
Show a "Enable/Disable" selection box.
Parameters:
[IN] fEnabled - whether the option is originally enabled or not.
Return value:
TRUE if user selected "Enable", FALSE if selected "Disable".
--*/
{
WORD wItems[2] = { SWITCHMENU_LABEL_DISABLE, SWITCHMENU_LABEL_ENABLE };
WORD wReturnValue = PAL_SelectionMenu(2, fEnabled ? 1 : 0, wItems);
return (wReturnValue == MENUITEM_VALUE_CANCELLED) ? fEnabled : ((wReturnValue == 0) ? FALSE : TRUE);
}
#ifndef PAL_CLASSIC
static VOID
PAL_BattleSpeedMenu(
VOID
)
/*++
Purpose:
Show the Battle Speed selection box.
Parameters:
None.
Return value:
None.
--*/
{
LPBOX lpBox;
WORD wReturnValue;
const SDL_Rect rect = {131, 100, 165, 50};
MENUITEM rgMenuItem[5] = {
{ 1, BATTLESPEEDMENU_LABEL_1, TRUE, PAL_XY(145, 110) },
{ 2, BATTLESPEEDMENU_LABEL_2, TRUE, PAL_XY(170, 110) },
{ 3, BATTLESPEEDMENU_LABEL_3, TRUE, PAL_XY(195, 110) },
{ 4, BATTLESPEEDMENU_LABEL_4, TRUE, PAL_XY(220, 110) },
{ 5, BATTLESPEEDMENU_LABEL_5, TRUE, PAL_XY(245, 110) },
};
//
// Create the boxes
//
lpBox = PAL_CreateSingleLineBox(PAL_XY(131, 100), 8, TRUE);
//
// Activate the menu
//
wReturnValue = PAL_ReadMenu(NULL, rgMenuItem, 5, gpGlobals->bBattleSpeed - 1,
MENUITEM_COLOR);
//
// Delete the boxes
//
PAL_DeleteBox(lpBox);
VIDEO_UpdateScreen(&rect);
if (wReturnValue != MENUITEM_VALUE_CANCELLED)
{
gpGlobals->bBattleSpeed = wReturnValue;
}
}
#endif
LPBOX
PAL_ShowCash(
DWORD dwCash
)
/*++
Purpose:
Show the cash amount at the top left corner of the screen.
Parameters:
[IN] dwCash - amount of cash.
Return value:
pointer to the saved screen part.
--*/
{
LPBOX lpBox;
//
// Create the box.
//
lpBox = PAL_CreateSingleLineBox(PAL_XY(0, 0), 5, TRUE);
if (lpBox == NULL)
{
return NULL;
}
//
// Draw the text label.
//
PAL_DrawText(PAL_GetWord(CASH_LABEL), PAL_XY(10, 10), 0, FALSE, FALSE, FALSE);
//
// Draw the cash amount.
//
PAL_DrawNumber(dwCash, 6, PAL_XY(49, 14), kNumColorYellow, kNumAlignRight);
return lpBox;
}
static VOID
PAL_SystemMenu_OnItemChange(
WORD wCurrentItem
)
/*++
Purpose:
Callback function when user selected another item in the system menu.
Parameters:
[IN] wCurrentItem - current selected item.
Return value:
None.
--*/
{
gpGlobals->iCurSystemMenuItem = wCurrentItem - 1;
}
static BOOL
PAL_SystemMenu(
VOID
)
/*++
Purpose:
Show the system menu.
Parameters:
None.
Return value:
TRUE if user made some operations in the menu, FALSE if user cancelled.
--*/
{
LPBOX lpMenuBox;
WORD wReturnValue;
int iSlot, i;
const SDL_Rect rect = {40, 60, 280, 135};
//
// Create menu items
//
const MENUITEM rgSystemMenuItem[] =
{
// value label enabled pos
{ 1, SYSMENU_LABEL_SAVE, TRUE, PAL_XY(53, 72) },
{ 2, SYSMENU_LABEL_LOAD, TRUE, PAL_XY(53, 72 + 18) },
{ 3, SYSMENU_LABEL_MUSIC, TRUE, PAL_XY(53, 72 + 36) },
{ 4, SYSMENU_LABEL_SOUND, TRUE, PAL_XY(53, 72 + 54) },
{ 5, SYSMENU_LABEL_QUIT, TRUE, PAL_XY(53, 72 + 72) },
#if !defined(PAL_CLASSIC)
{ 6, SYSMENU_LABEL_BATTLEMODE, TRUE, PAL_XY(53, 72 + 90) },
#endif
};
const int nSystemMenuItem = sizeof(rgSystemMenuItem) / sizeof(MENUITEM);
//
// Create the menu box.
//
lpMenuBox = PAL_CreateBox(PAL_XY(40, 60), nSystemMenuItem - 1, PAL_MenuTextMaxWidth(rgSystemMenuItem, nSystemMenuItem) - 1, 0, TRUE);
//
// Perform the menu.
//
wReturnValue = PAL_ReadMenu(PAL_SystemMenu_OnItemChange, rgSystemMenuItem, nSystemMenuItem, gpGlobals->iCurSystemMenuItem, MENUITEM_COLOR);
if (wReturnValue == MENUITEM_VALUE_CANCELLED)
{
//
// User cancelled the menu
//
PAL_DeleteBox(lpMenuBox);
VIDEO_UpdateScreen(&rect);
return FALSE;
}
switch (wReturnValue)
{
case 1:
//
// Save game
//
iSlot = PAL_SaveSlotMenu(gpGlobals->bCurrentSaveSlot);
if (iSlot != MENUITEM_VALUE_CANCELLED)
{
WORD wSavedTimes = 0;
gpGlobals->bCurrentSaveSlot = (BYTE)iSlot;
for (i = 1; i <= 5; i++)
{
WORD curSavedTimes = GetSavedTimes(i);
if (curSavedTimes > wSavedTimes)
{
wSavedTimes = curSavedTimes;
}
}
PAL_SaveGame(iSlot, wSavedTimes + 1);
}
break;
case 2:
//
// Load game
//
iSlot = PAL_SaveSlotMenu(gpGlobals->bCurrentSaveSlot);
if (iSlot != MENUITEM_VALUE_CANCELLED)
{
AUDIO_PlayMusic(0, FALSE, 1);
PAL_FadeOut(1);
PAL_InitGameData(iSlot);
}
break;
case 3:
//
// Music
//
AUDIO_EnableMusic(PAL_SwitchMenu(AUDIO_MusicEnabled()));
if (gConfig.eMusicType == MUSIC_MIDI)
{
AUDIO_PlayMusic(AUDIO_MusicEnabled() ? gpGlobals->wNumMusic : 0, AUDIO_MusicEnabled(), 0);
}
break;
case 4:
//
// Sound
//
AUDIO_EnableSound(PAL_SwitchMenu(AUDIO_SoundEnabled()));
break;
case 5:
//
// Quit
//
PAL_QuitGame();
break;
#if !defined(PAL_CLASSIC)
case 6:
//
// Battle Mode
//
PAL_BattleSpeedMenu();
break;
#endif
}
PAL_DeleteBox(lpMenuBox);
return TRUE;
}
VOID
PAL_InGameMagicMenu(
VOID
)
/*++
Purpose:
Show the magic menu.
Parameters:
None.
Return value:
None.
--*/
{
MENUITEM rgMenuItem[MAX_PLAYERS_IN_PARTY];
int i, y;
static WORD w;
WORD wMagic;
const SDL_Rect rect = {35, 62, 285, 90};
//
// Draw the player info boxes
//
y = 45;
for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
{
PAL_PlayerInfoBox(PAL_XY(y, 165), gpGlobals->rgParty[i].wPlayerRole, 100,
TIMEMETER_COLOR_DEFAULT, TRUE);
y += 78;
}
y = 75;
//
// Generate one menu items for each player in the party
//
for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
{
assert(i <= MAX_PLAYERS_IN_PARTY);
rgMenuItem[i].wValue = i;
rgMenuItem[i].wNumWord =
gpGlobals->g.PlayerRoles.rgwName[gpGlobals->rgParty[i].wPlayerRole];
rgMenuItem[i].fEnabled =
(gpGlobals->g.PlayerRoles.rgwHP[gpGlobals->rgParty[i].wPlayerRole] > 0);
rgMenuItem[i].pos = PAL_XY(48, y);
y += 18;
}
//
// Draw the box
//
PAL_CreateBox(PAL_XY(35, 62), gpGlobals->wMaxPartyMemberIndex, PAL_MenuTextMaxWidth(rgMenuItem, sizeof(rgMenuItem)/sizeof(MENUITEM)) - 1, 0, FALSE);
w = PAL_ReadMenu(NULL, rgMenuItem, gpGlobals->wMaxPartyMemberIndex + 1, w, MENUITEM_COLOR);
if (w == MENUITEM_VALUE_CANCELLED)
{
return;
}
wMagic = 0;
while (TRUE)
{
wMagic = PAL_MagicSelectionMenu(gpGlobals->rgParty[w].wPlayerRole, FALSE, wMagic);
if (wMagic == 0)
{
break;
}
if (gpGlobals->g.rgObject[wMagic].magic.wFlags & kMagicFlagApplyToAll)
{
gpGlobals->g.rgObject[wMagic].magic.wScriptOnUse =
PAL_RunTriggerScript(gpGlobals->g.rgObject[wMagic].magic.wScriptOnUse, 0);
if (g_fScriptSuccess)
{
gpGlobals->g.rgObject[wMagic].magic.wScriptOnSuccess =
PAL_RunTriggerScript(gpGlobals->g.rgObject[wMagic].magic.wScriptOnSuccess, 0);
if(g_fScriptSuccess)
gpGlobals->g.PlayerRoles.rgwMP[gpGlobals->rgParty[w].wPlayerRole] -=
gpGlobals->g.lprgMagic[gpGlobals->g.rgObject[wMagic].magic.wMagicNumber].wCostMP;
}
if (gpGlobals->fNeedToFadeIn)
{
PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette, 1);
gpGlobals->fNeedToFadeIn = FALSE;
}
}
else
{
//
// Need to select which player to use the magic on.
//
WORD wPlayer = 0;
SDL_Rect rect;
while (wPlayer != MENUITEM_VALUE_CANCELLED)
{
//
// Redraw the player info boxes first
//
y = 45;
for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
{
PAL_PlayerInfoBox(PAL_XY(y, 165), gpGlobals->rgParty[i].wPlayerRole, 100,
TIMEMETER_COLOR_DEFAULT, TRUE);
y += 78;
}
//
// Draw the cursor on the selected item
//
rect.x = 70 + 78 * wPlayer;
rect.y = 193;
rect.w = 9;
rect.h = 6;
PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_CURSOR),
gpScreen, PAL_XY(rect.x, rect.y));
VIDEO_UpdateScreen(&rect);
while (TRUE)
{
PAL_ClearKeyState();
PAL_ProcessEvent();
if (g_InputState.dwKeyPress & kKeyMenu)
{
wPlayer = MENUITEM_VALUE_CANCELLED;
break;
}
else if (g_InputState.dwKeyPress & kKeySearch)
{
gpGlobals->g.rgObject[wMagic].magic.wScriptOnUse =
PAL_RunTriggerScript(gpGlobals->g.rgObject[wMagic].magic.wScriptOnUse,
gpGlobals->rgParty[wPlayer].wPlayerRole);
if (g_fScriptSuccess)
{
gpGlobals->g.rgObject[wMagic].magic.wScriptOnSuccess =
PAL_RunTriggerScript(gpGlobals->g.rgObject[wMagic].magic.wScriptOnSuccess,
gpGlobals->rgParty[wPlayer].wPlayerRole);
if (g_fScriptSuccess)
{
gpGlobals->g.PlayerRoles.rgwMP[gpGlobals->rgParty[w].wPlayerRole] -=
gpGlobals->g.lprgMagic[gpGlobals->g.rgObject[wMagic].magic.wMagicNumber].wCostMP;
//
// Check if we have run out of MP
//
if (gpGlobals->g.PlayerRoles.rgwMP[gpGlobals->rgParty[w].wPlayerRole] <
gpGlobals->g.lprgMagic[gpGlobals->g.rgObject[wMagic].magic.wMagicNumber].wCostMP)
{
//
// Don't go further if run out of MP
//
wPlayer = MENUITEM_VALUE_CANCELLED;
}
}
}
break;
}
else if (g_InputState.dwKeyPress & (kKeyLeft | kKeyUp))
{
if (wPlayer > 0)
{
wPlayer--;
break;
}
}
else if (g_InputState.dwKeyPress & (kKeyRight | kKeyDown))
{
if (wPlayer < gpGlobals->wMaxPartyMemberIndex)
{
wPlayer++;
break;
}
}
SDL_Delay(1);
}
}
}
//
// Redraw the player info boxes
//
y = 45;
for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
{
PAL_PlayerInfoBox(PAL_XY(y, 165), gpGlobals->rgParty[i].wPlayerRole, 100,
TIMEMETER_COLOR_DEFAULT, TRUE);
y += 78;
}
}
}
static VOID
PAL_InventoryMenu(
VOID
)
/*++
Purpose:
Show the inventory menu.
Parameters:
None.
Return value:
None.
--*/
{
static WORD w = 0;
const SDL_Rect rect = {30, 60, 290, 60};
MENUITEM rgMenuItem[2] =
{
// value label enabled pos
{ 1, INVMENU_LABEL_EQUIP, TRUE, PAL_XY(43, 73) },
{ 2, INVMENU_LABEL_USE, TRUE, PAL_XY(43, 73 + 18) },
};
PAL_CreateBox(PAL_XY(30, 60), 1, PAL_MenuTextMaxWidth(rgMenuItem, sizeof(rgMenuItem)/sizeof(MENUITEM)) - 1, 0, FALSE);
w = PAL_ReadMenu(NULL, rgMenuItem, 2, w - 1, MENUITEM_COLOR);
switch (w)
{
case 1:
PAL_GameEquipItem();
break;
case 2:
PAL_GameUseItem();
break;
}
}
static VOID
PAL_InGameMenu_OnItemChange(
WORD wCurrentItem
)
/*++
Purpose:
Callback function when user selected another item in the in-game menu.
Parameters:
[IN] wCurrentItem - current selected item.
Return value:
None.
--*/
{
gpGlobals->iCurMainMenuItem = wCurrentItem - 1;
}
VOID
PAL_InGameMenu(
VOID
)
/*++
Purpose:
Show the in-game main menu.
Parameters:
None.
Return value:
None.
--*/
{
LPBOX lpCashBox, lpMenuBox;
WORD wReturnValue;
const SDL_Rect rect = {0, 0, 320, 185};
// Fix render problem with shadow
VIDEO_BackupScreen(gpScreen);
//
// Create menu items
//
MENUITEM rgMainMenuItem[4] =
{
// value label enabled pos
{ 1, GAMEMENU_LABEL_STATUS, TRUE, PAL_XY(16, 50) },
{ 2, GAMEMENU_LABEL_MAGIC, TRUE, PAL_XY(16, 50 + 18) },
{ 3, GAMEMENU_LABEL_INVENTORY, TRUE, PAL_XY(16, 50 + 36) },
{ 4, GAMEMENU_LABEL_SYSTEM, TRUE, PAL_XY(16, 50 + 54) },
};
//
// Display the cash amount.
//
lpCashBox = PAL_ShowCash(gpGlobals->dwCash);
//
// Create the menu box.
//
// Fix render problem with shadow
lpMenuBox = PAL_CreateBox(PAL_XY(3, 37), 3, PAL_MenuTextMaxWidth(rgMainMenuItem, 4) - 1, 0, FALSE);
//
// Process the menu
//
while (TRUE)
{
wReturnValue = PAL_ReadMenu(PAL_InGameMenu_OnItemChange, rgMainMenuItem, 4,
gpGlobals->iCurMainMenuItem, MENUITEM_COLOR);
if (wReturnValue == MENUITEM_VALUE_CANCELLED)
{
break;
}
switch (wReturnValue)
{
case 1:
//
// Status