uigame.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007
  1. /* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
  2. //
  3. // Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
  4. // All rights reserved.
  5. //
  6. // This file is part of SDLPAL.
  7. //
  8. // SDLPAL is free software: you can redistribute it and/or modify
  9. // it under the terms of the GNU General Public License as published by
  10. // the Free Software Foundation, either version 3 of the License, or
  11. // (at your option) any later version.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU General Public License
  19. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. //
  21. // Modified by Lou Yihua <louyihua@21cn.com> with unicode support, 2015
  22. //
  23. #include "main.h"
  24. VOID
  25. PAL_DrawOpeningMenuBackground(
  26. VOID
  27. )
  28. /*++
  29. Purpose:
  30. Draw the background of the main menu.
  31. Parameters:
  32. None.
  33. Return value:
  34. None.
  35. --*/
  36. {
  37. LPBYTE buf;
  38. buf = (LPBYTE)malloc(320 * 200);
  39. if (buf == NULL)
  40. {
  41. return;
  42. }
  43. //
  44. // Read the picture from fbp.mkf.
  45. //
  46. PAL_MKFDecompressChunk(buf, 320 * 200, MAINMENU_BACKGROUND_FBPNUM, gpGlobals->f.fpFBP);
  47. //
  48. // ...and blit it to the screen buffer.
  49. //
  50. PAL_FBPBlitToSurface(buf, gpScreen);
  51. VIDEO_UpdateScreen(NULL);
  52. free(buf);
  53. }
  54. INT
  55. PAL_OpeningMenu(
  56. VOID
  57. )
  58. /*++
  59. Purpose:
  60. Show the opening menu.
  61. Parameters:
  62. None.
  63. Return value:
  64. Which saved slot to load from (1-5). 0 to start a new game.
  65. --*/
  66. {
  67. WORD wItemSelected;
  68. WORD wDefaultItem = 0;
  69. INT w[2] = { PAL_WordWidth(MAINMENU_LABEL_NEWGAME), PAL_WordWidth(MAINMENU_LABEL_LOADGAME) };
  70. MENUITEM rgMainMenuItem[2] = {
  71. // value label enabled position
  72. { 0, MAINMENU_LABEL_NEWGAME, TRUE, PAL_XY(125 - (w[0] > 4 ? (w[0] - 4) * 8 : 0), 95) },
  73. { 1, MAINMENU_LABEL_LOADGAME, TRUE, PAL_XY(125 - (w[1] > 4 ? (w[1] - 4) * 8 : 0), 112) }
  74. };
  75. //
  76. // Play the background music
  77. //
  78. SOUND_PlayMUS(RIX_NUM_OPENINGMENU, TRUE, 1);
  79. //
  80. // Draw the background
  81. //
  82. PAL_DrawOpeningMenuBackground();
  83. PAL_FadeIn(0, FALSE, 1);
  84. while (TRUE)
  85. {
  86. //
  87. // Activate the menu
  88. //
  89. wItemSelected = PAL_ReadMenu(NULL, rgMainMenuItem, 2, wDefaultItem, MENUITEM_COLOR);
  90. if (wItemSelected == 0 || wItemSelected == MENUITEM_VALUE_CANCELLED)
  91. {
  92. //
  93. // Start a new game
  94. //
  95. wItemSelected = 0;
  96. break;
  97. }
  98. else
  99. {
  100. //
  101. // Load game
  102. //
  103. wItemSelected = PAL_SaveSlotMenu(1);
  104. if (wItemSelected != MENUITEM_VALUE_CANCELLED)
  105. {
  106. break;
  107. }
  108. wDefaultItem = 1;
  109. }
  110. }
  111. //
  112. // Fade out the screen and the music
  113. //
  114. SOUND_PlayMUS(0, FALSE, 1);
  115. PAL_FadeOut(1);
  116. return (INT)wItemSelected;
  117. }
  118. INT
  119. PAL_SaveSlotMenu(
  120. WORD wDefaultSlot
  121. )
  122. /*++
  123. Purpose:
  124. Show the load game menu.
  125. Parameters:
  126. [IN] wDefaultSlot - default save slot number (1-5).
  127. Return value:
  128. Which saved slot to load from (1-5). MENUITEM_VALUE_CANCELLED if cancelled.
  129. --*/
  130. {
  131. LPBOX rgpBox[5];
  132. int i, w = PAL_WordMaxWidth(LOADMENU_LABEL_SLOT_FIRST, 5);
  133. int dx = (w > 4) ? (w - 4) * 16 : 0;
  134. FILE *fp;
  135. WORD wItemSelected;
  136. WORD wSavedTimes;
  137. MENUITEM rgMenuItem[5];
  138. const SDL_Rect rect = { 195 - dx, 7, 120 + dx, 190 };
  139. //
  140. // Create the boxes and create the menu items
  141. //
  142. for (i = 0; i < 5; i++)
  143. {
  144. rgpBox[i] = PAL_CreateSingleLineBox(PAL_XY(195 - dx, 7 + 38 * i), 6 + (w > 4 ? w - 4 : 0), TRUE);
  145. rgMenuItem[i].wValue = i + 1;
  146. rgMenuItem[i].fEnabled = TRUE;
  147. rgMenuItem[i].wNumWord = LOADMENU_LABEL_SLOT_FIRST + i;
  148. rgMenuItem[i].pos = PAL_XY(210 - dx, 17 + 38 * i);
  149. }
  150. //
  151. // Draw the numbers of saved times
  152. //
  153. for (i = 1; i <= 5; i++)
  154. {
  155. fp = fopen(va("%s%d%s", PAL_SAVE_PREFIX, i, ".rpg"), "rb");
  156. if (fp == NULL)
  157. {
  158. wSavedTimes = 0;
  159. }
  160. else
  161. {
  162. fread(&wSavedTimes, sizeof(WORD), 1, fp);
  163. wSavedTimes = SDL_SwapLE16(wSavedTimes);
  164. fclose(fp);
  165. }
  166. //
  167. // Draw the number
  168. //
  169. PAL_DrawNumber((UINT)wSavedTimes, 4, PAL_XY(270, 38 * i - 17),
  170. kNumColorYellow, kNumAlignRight);
  171. }
  172. VIDEO_UpdateScreen(&rect);
  173. //
  174. // Activate the menu
  175. //
  176. wItemSelected = PAL_ReadMenu(NULL, rgMenuItem, 5, wDefaultSlot - 1, MENUITEM_COLOR);
  177. //
  178. // Delete the boxes
  179. //
  180. for (i = 0; i < 5; i++)
  181. {
  182. PAL_DeleteBox(rgpBox[i]);
  183. }
  184. VIDEO_UpdateScreen(&rect);
  185. return wItemSelected;
  186. }
  187. static
  188. WORD
  189. PAL_SelectionMenu(
  190. int nWords,
  191. int nDefault,
  192. WORD wItems[]
  193. )
  194. /*++
  195. Purpose:
  196. Show a common selection box.
  197. Parameters:
  198. [IN] nWords - number of emnu items.
  199. [IN] nDefault - index of default item.
  200. [IN] wItems - item word array.
  201. Return value:
  202. User-selected index.
  203. --*/
  204. {
  205. LPBOX rgpBox[4];
  206. MENUITEM rgMenuItem[4];
  207. int w[4] = {
  208. (nWords >= 1 && wItems[0]) ? PAL_WordWidth(wItems[0]) : 1,
  209. (nWords >= 2 && wItems[1]) ? PAL_WordWidth(wItems[1]) : 1,
  210. (nWords >= 3 && wItems[2]) ? PAL_WordWidth(wItems[2]) : 1,
  211. (nWords >= 4 && wItems[3]) ? PAL_WordWidth(wItems[3]) : 1 };
  212. int dx[4] = { (w[0] - 1) * 16, (w[1] - 1) * 16, (w[2] - 1) * 16, (w[3] - 1) * 16 }, i;
  213. PAL_POS pos[4] = { PAL_XY(145, 110), PAL_XY(220 + dx[0], 110), PAL_XY(145, 160), PAL_XY(220 + dx[2], 160) };
  214. WORD wReturnValue;
  215. const SDL_Rect rect = { 130, 100, 125 + max(dx[0] + dx[1], dx[2] + dx[3]), 100 };
  216. for (i = 0; i < nWords; i++)
  217. if (nWords > i && !wItems[i])
  218. return MENUITEM_VALUE_CANCELLED;
  219. //
  220. // Create menu items
  221. //
  222. for (i = 0; i < nWords; i++)
  223. {
  224. rgMenuItem[i].fEnabled = TRUE;
  225. rgMenuItem[i].pos = pos[i];
  226. rgMenuItem[i].wValue = i;
  227. rgMenuItem[i].wNumWord = wItems[i];
  228. }
  229. //
  230. // Create the boxes
  231. //
  232. dx[1] = dx[0]; dx[3] = dx[2]; dx[0] = dx[2] = 0;
  233. for (i = 0; i < nWords; i++)
  234. {
  235. rgpBox[i] = PAL_CreateSingleLineBox(PAL_XY(130 + 75 * (i % 2) + dx[i], 100 + 50 * (i / 2)), w[i] + 1, TRUE);
  236. }
  237. VIDEO_UpdateScreen(&rect);
  238. //
  239. // Activate the menu
  240. //
  241. wReturnValue = PAL_ReadMenu(NULL, rgMenuItem, nWords, nDefault, MENUITEM_COLOR);
  242. //
  243. // Delete the boxes
  244. //
  245. for (i = 0; i < nWords; i++)
  246. {
  247. PAL_DeleteBox(rgpBox[i]);
  248. }
  249. VIDEO_UpdateScreen(&rect);
  250. return wReturnValue;
  251. }
  252. WORD
  253. PAL_TripleMenu(
  254. WORD wThirdWord
  255. )
  256. /*++
  257. Purpose:
  258. Show a triple-selection box.
  259. Parameters:
  260. None.
  261. Return value:
  262. User-selected index.
  263. --*/
  264. {
  265. WORD wItems[3] = { CONFIRMMENU_LABEL_NO, CONFIRMMENU_LABEL_YES, wThirdWord };
  266. return PAL_SelectionMenu(3, 0, wItems);
  267. }
  268. BOOL
  269. PAL_ConfirmMenu(
  270. VOID
  271. )
  272. /*++
  273. Purpose:
  274. Show a "Yes or No?" confirm box.
  275. Parameters:
  276. None.
  277. Return value:
  278. TRUE if user selected Yes, FALSE if selected No.
  279. --*/
  280. {
  281. WORD wItems[2] = { CONFIRMMENU_LABEL_NO, CONFIRMMENU_LABEL_YES };
  282. WORD wReturnValue = PAL_SelectionMenu(2, 0, wItems);
  283. return (wReturnValue == MENUITEM_VALUE_CANCELLED || wReturnValue == 0) ? FALSE : TRUE;
  284. }
  285. BOOL
  286. PAL_SwitchMenu(
  287. BOOL fEnabled
  288. )
  289. /*++
  290. Purpose:
  291. Show a "Enable/Disable" selection box.
  292. Parameters:
  293. [IN] fEnabled - whether the option is originally enabled or not.
  294. Return value:
  295. TRUE if user selected "Enable", FALSE if selected "Disable".
  296. --*/
  297. {
  298. WORD wItems[2] = { SWITCHMENU_LABEL_DISABLE, SWITCHMENU_LABEL_ENABLE };
  299. WORD wReturnValue = PAL_SelectionMenu(2, fEnabled ? 1 : 0, wItems);
  300. return (wReturnValue == MENUITEM_VALUE_CANCELLED) ? fEnabled : ((wReturnValue == 0) ? FALSE : TRUE);
  301. }
  302. #ifndef PAL_CLASSIC
  303. static VOID
  304. PAL_BattleSpeedMenu(
  305. VOID
  306. )
  307. /*++
  308. Purpose:
  309. Show the Battle Speed selection box.
  310. Parameters:
  311. None.
  312. Return value:
  313. None.
  314. --*/
  315. {
  316. LPBOX lpBox;
  317. WORD wReturnValue;
  318. const SDL_Rect rect = {131, 100, 165, 50};
  319. MENUITEM rgMenuItem[5] = {
  320. { 1, BATTLESPEEDMENU_LABEL_1, TRUE, PAL_XY(145, 110) },
  321. { 2, BATTLESPEEDMENU_LABEL_2, TRUE, PAL_XY(170, 110) },
  322. { 3, BATTLESPEEDMENU_LABEL_3, TRUE, PAL_XY(195, 110) },
  323. { 4, BATTLESPEEDMENU_LABEL_4, TRUE, PAL_XY(220, 110) },
  324. { 5, BATTLESPEEDMENU_LABEL_5, TRUE, PAL_XY(245, 110) },
  325. };
  326. //
  327. // Create the boxes
  328. //
  329. lpBox = PAL_CreateSingleLineBox(PAL_XY(131, 100), 8, TRUE);
  330. VIDEO_UpdateScreen(&rect);
  331. //
  332. // Activate the menu
  333. //
  334. wReturnValue = PAL_ReadMenu(NULL, rgMenuItem, 5, gpGlobals->bBattleSpeed - 1,
  335. MENUITEM_COLOR);
  336. //
  337. // Delete the boxes
  338. //
  339. PAL_DeleteBox(lpBox);
  340. VIDEO_UpdateScreen(&rect);
  341. if (wReturnValue != MENUITEM_VALUE_CANCELLED)
  342. {
  343. gpGlobals->bBattleSpeed = wReturnValue;
  344. }
  345. }
  346. #endif
  347. LPBOX
  348. PAL_ShowCash(
  349. DWORD dwCash
  350. )
  351. /*++
  352. Purpose:
  353. Show the cash amount at the top left corner of the screen.
  354. Parameters:
  355. [IN] dwCash - amount of cash.
  356. Return value:
  357. pointer to the saved screen part.
  358. --*/
  359. {
  360. LPBOX lpBox;
  361. //
  362. // Create the box.
  363. //
  364. lpBox = PAL_CreateSingleLineBox(PAL_XY(0, 0), 5, TRUE);
  365. if (lpBox == NULL)
  366. {
  367. return NULL;
  368. }
  369. //
  370. // Draw the text label.
  371. //
  372. PAL_DrawText(PAL_GetWord(CASH_LABEL), PAL_XY(10, 10), 0, FALSE, FALSE, FALSE);
  373. //
  374. // Draw the cash amount.
  375. //
  376. PAL_DrawNumber(dwCash, 6, PAL_XY(49, 14), kNumColorYellow, kNumAlignRight);
  377. return lpBox;
  378. }
  379. static VOID
  380. PAL_SystemMenu_OnItemChange(
  381. WORD wCurrentItem
  382. )
  383. /*++
  384. Purpose:
  385. Callback function when user selected another item in the system menu.
  386. Parameters:
  387. [IN] wCurrentItem - current selected item.
  388. Return value:
  389. None.
  390. --*/
  391. {
  392. gpGlobals->iCurSystemMenuItem = wCurrentItem - 1;
  393. }
  394. static BOOL
  395. PAL_SystemMenu(
  396. VOID
  397. )
  398. /*++
  399. Purpose:
  400. Show the system menu.
  401. Parameters:
  402. None.
  403. Return value:
  404. TRUE if user made some operations in the menu, FALSE if user cancelled.
  405. --*/
  406. {
  407. LPBOX lpMenuBox;
  408. WORD wReturnValue;
  409. int iSlot, i, iSavedTimes;
  410. FILE *fp;
  411. const SDL_Rect rect = {40, 60, 120, 135};
  412. //
  413. // Create menu items
  414. //
  415. const MENUITEM rgSystemMenuItem[] =
  416. {
  417. // value label enabled pos
  418. { 1, SYSMENU_LABEL_SAVE, TRUE, PAL_XY(53, 72) },
  419. { 2, SYSMENU_LABEL_LOAD, TRUE, PAL_XY(53, 72 + 18) },
  420. { 3, SYSMENU_LABEL_MUSIC, TRUE, PAL_XY(53, 72 + 36) },
  421. { 4, SYSMENU_LABEL_SOUND, TRUE, PAL_XY(53, 72 + 54) },
  422. { 5, SYSMENU_LABEL_QUIT, TRUE, PAL_XY(53, 72 + 72) },
  423. #if !defined(PAL_CLASSIC)
  424. { 6, SYSMENU_LABEL_BATTLEMODE, TRUE, PAL_XY(53, 72 + 90) },
  425. #endif
  426. };
  427. const int nSystemMenuItem = sizeof(rgSystemMenuItem) / sizeof(MENUITEM);
  428. //
  429. // Create the menu box.
  430. //
  431. lpMenuBox = PAL_CreateBox(PAL_XY(40, 60), nSystemMenuItem - 1, PAL_MenuTextMaxWidth(rgSystemMenuItem, nSystemMenuItem) - 1, 0, TRUE);
  432. VIDEO_UpdateScreen(&rect);
  433. //
  434. // Perform the menu.
  435. //
  436. wReturnValue = PAL_ReadMenu(PAL_SystemMenu_OnItemChange, rgSystemMenuItem, nSystemMenuItem, gpGlobals->iCurSystemMenuItem, MENUITEM_COLOR);
  437. if (wReturnValue == MENUITEM_VALUE_CANCELLED)
  438. {
  439. //
  440. // User cancelled the menu
  441. //
  442. PAL_DeleteBox(lpMenuBox);
  443. VIDEO_UpdateScreen(&rect);
  444. return FALSE;
  445. }
  446. switch (wReturnValue)
  447. {
  448. case 1:
  449. //
  450. // Save game
  451. //
  452. iSlot = PAL_SaveSlotMenu(gpGlobals->bCurrentSaveSlot);
  453. if (iSlot != MENUITEM_VALUE_CANCELLED)
  454. {
  455. gpGlobals->bCurrentSaveSlot = (BYTE)iSlot;
  456. iSavedTimes = 0;
  457. for (i = 1; i <= 5; i++)
  458. {
  459. fp = fopen(va("%s%d%s", PAL_SAVE_PREFIX, i, ".rpg"), "rb");
  460. if (fp != NULL)
  461. {
  462. WORD wSavedTimes;
  463. fread(&wSavedTimes, sizeof(WORD), 1, fp);
  464. fclose(fp);
  465. wSavedTimes = SDL_SwapLE16(wSavedTimes);
  466. if ((int)wSavedTimes > iSavedTimes)
  467. {
  468. iSavedTimes = wSavedTimes;
  469. }
  470. }
  471. }
  472. PAL_SaveGame(va("%s%d%s", PAL_SAVE_PREFIX, iSlot, ".rpg"), iSavedTimes + 1);
  473. }
  474. break;
  475. case 2:
  476. //
  477. // Load game
  478. //
  479. iSlot = PAL_SaveSlotMenu(gpGlobals->bCurrentSaveSlot);
  480. if (iSlot != MENUITEM_VALUE_CANCELLED)
  481. {
  482. SOUND_PlayMUS(0, FALSE, 1);
  483. PAL_FadeOut(1);
  484. PAL_InitGameData(iSlot);
  485. }
  486. break;
  487. case 3:
  488. //
  489. // Music
  490. //
  491. g_fNoMusic = !PAL_SwitchMenu(!g_fNoMusic);
  492. if (gConfig.eMusicType == MUSIC_MIDI)
  493. {
  494. if (g_fNoMusic)
  495. {
  496. SOUND_PlayMUS(0, FALSE, 0);
  497. }
  498. else
  499. {
  500. SOUND_PlayMUS(gpGlobals->wNumMusic, TRUE, 0);
  501. }
  502. }
  503. break;
  504. case 4:
  505. //
  506. // Sound
  507. //
  508. g_fNoSound = !PAL_SwitchMenu(!g_fNoSound);
  509. break;
  510. case 5:
  511. //
  512. // Quit
  513. //
  514. PAL_QuitGame();
  515. break;
  516. #if !defined(PAL_CLASSIC)
  517. case 6:
  518. //
  519. // Battle Mode
  520. //
  521. PAL_BattleSpeedMenu();
  522. break;
  523. #endif
  524. }
  525. PAL_DeleteBox(lpMenuBox);
  526. return TRUE;
  527. }
  528. VOID
  529. PAL_InGameMagicMenu(
  530. VOID
  531. )
  532. /*++
  533. Purpose:
  534. Show the magic menu.
  535. Parameters:
  536. None.
  537. Return value:
  538. None.
  539. --*/
  540. {
  541. MENUITEM rgMenuItem[MAX_PLAYERS_IN_PARTY];
  542. int i, y;
  543. static WORD w;
  544. WORD wMagic;
  545. const SDL_Rect rect = {35, 62, 95, 90};
  546. //
  547. // Draw the player info boxes
  548. //
  549. y = 45;
  550. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  551. {
  552. PAL_PlayerInfoBox(PAL_XY(y, 165), gpGlobals->rgParty[i].wPlayerRole, 100,
  553. TIMEMETER_COLOR_DEFAULT, TRUE);
  554. y += 78;
  555. }
  556. y = 75;
  557. //
  558. // Generate one menu items for each player in the party
  559. //
  560. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  561. {
  562. assert(i <= MAX_PLAYERS_IN_PARTY);
  563. rgMenuItem[i].wValue = i;
  564. rgMenuItem[i].wNumWord =
  565. gpGlobals->g.PlayerRoles.rgwName[gpGlobals->rgParty[i].wPlayerRole];
  566. rgMenuItem[i].fEnabled =
  567. (gpGlobals->g.PlayerRoles.rgwHP[gpGlobals->rgParty[i].wPlayerRole] > 0);
  568. rgMenuItem[i].pos = PAL_XY(48, y);
  569. y += 18;
  570. }
  571. //
  572. // Draw the box
  573. //
  574. PAL_CreateBox(PAL_XY(35, 62), gpGlobals->wMaxPartyMemberIndex, 2, 0, FALSE);
  575. VIDEO_UpdateScreen(&rect);
  576. w = PAL_ReadMenu(NULL, rgMenuItem, gpGlobals->wMaxPartyMemberIndex + 1, w, MENUITEM_COLOR);
  577. if (w == MENUITEM_VALUE_CANCELLED)
  578. {
  579. return;
  580. }
  581. wMagic = 0;
  582. while (TRUE)
  583. {
  584. wMagic = PAL_MagicSelectionMenu(gpGlobals->rgParty[w].wPlayerRole, FALSE, wMagic);
  585. if (wMagic == 0)
  586. {
  587. break;
  588. }
  589. if (gpGlobals->g.rgObject[wMagic].magic.wFlags & kMagicFlagApplyToAll)
  590. {
  591. gpGlobals->g.rgObject[wMagic].magic.wScriptOnUse =
  592. PAL_RunTriggerScript(gpGlobals->g.rgObject[wMagic].magic.wScriptOnUse, 0);
  593. if (g_fScriptSuccess)
  594. {
  595. gpGlobals->g.rgObject[wMagic].magic.wScriptOnSuccess =
  596. PAL_RunTriggerScript(gpGlobals->g.rgObject[wMagic].magic.wScriptOnSuccess, 0);
  597. gpGlobals->g.PlayerRoles.rgwMP[gpGlobals->rgParty[w].wPlayerRole] -=
  598. gpGlobals->g.lprgMagic[gpGlobals->g.rgObject[wMagic].magic.wMagicNumber].wCostMP;
  599. }
  600. if (gpGlobals->fNeedToFadeIn)
  601. {
  602. PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette, 1);
  603. gpGlobals->fNeedToFadeIn = FALSE;
  604. }
  605. }
  606. else
  607. {
  608. //
  609. // Need to select which player to use the magic on.
  610. //
  611. WORD wPlayer = 0;
  612. SDL_Rect rect;
  613. while (wPlayer != MENUITEM_VALUE_CANCELLED)
  614. {
  615. //
  616. // Redraw the player info boxes first
  617. //
  618. y = 45;
  619. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  620. {
  621. PAL_PlayerInfoBox(PAL_XY(y, 165), gpGlobals->rgParty[i].wPlayerRole, 100,
  622. TIMEMETER_COLOR_DEFAULT, TRUE);
  623. y += 78;
  624. }
  625. //
  626. // Draw the cursor on the selected item
  627. //
  628. rect.x = 70 + 78 * wPlayer;
  629. rect.y = 193;
  630. rect.w = 9;
  631. rect.h = 6;
  632. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_CURSOR),
  633. gpScreen, PAL_XY(rect.x, rect.y));
  634. VIDEO_UpdateScreen(&rect);
  635. while (TRUE)
  636. {
  637. PAL_ClearKeyState();
  638. PAL_ProcessEvent();
  639. if (g_InputState.dwKeyPress & kKeyMenu)
  640. {
  641. wPlayer = MENUITEM_VALUE_CANCELLED;
  642. break;
  643. }
  644. else if (g_InputState.dwKeyPress & kKeySearch)
  645. {
  646. gpGlobals->g.rgObject[wMagic].magic.wScriptOnUse =
  647. PAL_RunTriggerScript(gpGlobals->g.rgObject[wMagic].magic.wScriptOnUse,
  648. gpGlobals->rgParty[wPlayer].wPlayerRole);
  649. if (g_fScriptSuccess)
  650. {
  651. gpGlobals->g.rgObject[wMagic].magic.wScriptOnSuccess =
  652. PAL_RunTriggerScript(gpGlobals->g.rgObject[wMagic].magic.wScriptOnSuccess,
  653. gpGlobals->rgParty[wPlayer].wPlayerRole);
  654. if (g_fScriptSuccess)
  655. {
  656. gpGlobals->g.PlayerRoles.rgwMP[gpGlobals->rgParty[w].wPlayerRole] -=
  657. gpGlobals->g.lprgMagic[gpGlobals->g.rgObject[wMagic].magic.wMagicNumber].wCostMP;
  658. //
  659. // Check if we have run out of MP
  660. //
  661. if (gpGlobals->g.PlayerRoles.rgwMP[gpGlobals->rgParty[w].wPlayerRole] <
  662. gpGlobals->g.lprgMagic[gpGlobals->g.rgObject[wMagic].magic.wMagicNumber].wCostMP)
  663. {
  664. //
  665. // Don't go further if run out of MP
  666. //
  667. wPlayer = MENUITEM_VALUE_CANCELLED;
  668. }
  669. }
  670. }
  671. break;
  672. }
  673. else if (g_InputState.dwKeyPress & (kKeyLeft | kKeyUp))
  674. {
  675. if (wPlayer > 0)
  676. {
  677. wPlayer--;
  678. break;
  679. }
  680. }
  681. else if (g_InputState.dwKeyPress & (kKeyRight | kKeyDown))
  682. {
  683. if (wPlayer < gpGlobals->wMaxPartyMemberIndex)
  684. {
  685. wPlayer++;
  686. break;
  687. }
  688. }
  689. SDL_Delay(1);
  690. }
  691. }
  692. }
  693. //
  694. // Redraw the player info boxes
  695. //
  696. y = 45;
  697. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  698. {
  699. PAL_PlayerInfoBox(PAL_XY(y, 165), gpGlobals->rgParty[i].wPlayerRole, 100,
  700. TIMEMETER_COLOR_DEFAULT, TRUE);
  701. y += 78;
  702. }
  703. }
  704. }
  705. static VOID
  706. PAL_InventoryMenu(
  707. VOID
  708. )
  709. /*++
  710. Purpose:
  711. Show the inventory menu.
  712. Parameters:
  713. None.
  714. Return value:
  715. None.
  716. --*/
  717. {
  718. static WORD w = 0;
  719. const SDL_Rect rect = {30, 60, 75, 60};
  720. MENUITEM rgMenuItem[2] =
  721. {
  722. // value label enabled pos
  723. { 1, INVMENU_LABEL_USE, TRUE, PAL_XY(43, 73) },
  724. { 2, INVMENU_LABEL_EQUIP, TRUE, PAL_XY(43, 73 + 18) },
  725. };
  726. PAL_CreateBox(PAL_XY(30, 60), 1, 1, 0, FALSE);
  727. VIDEO_UpdateScreen(&rect);
  728. w = PAL_ReadMenu(NULL, rgMenuItem, 2, w - 1, MENUITEM_COLOR);
  729. switch (w)
  730. {
  731. case 1:
  732. PAL_GameUseItem();
  733. break;
  734. case 2:
  735. PAL_GameEquipItem();
  736. break;
  737. }
  738. }
  739. static VOID
  740. PAL_InGameMenu_OnItemChange(
  741. WORD wCurrentItem
  742. )
  743. /*++
  744. Purpose:
  745. Callback function when user selected another item in the in-game menu.
  746. Parameters:
  747. [IN] wCurrentItem - current selected item.
  748. Return value:
  749. None.
  750. --*/
  751. {
  752. gpGlobals->iCurMainMenuItem = wCurrentItem - 1;
  753. }
  754. VOID
  755. PAL_InGameMenu(
  756. VOID
  757. )
  758. /*++
  759. Purpose:
  760. Show the in-game main menu.
  761. Parameters:
  762. None.
  763. Return value:
  764. None.
  765. --*/
  766. {
  767. LPBOX lpCashBox, lpMenuBox;
  768. WORD wReturnValue;
  769. const SDL_Rect rect = {0, 0, 150, 185};
  770. //
  771. // Create menu items
  772. //
  773. MENUITEM rgMainMenuItem[4] =
  774. {
  775. // value label enabled pos
  776. { 1, GAMEMENU_LABEL_STATUS, TRUE, PAL_XY(16, 50) },
  777. { 2, GAMEMENU_LABEL_MAGIC, TRUE, PAL_XY(16, 50 + 18) },
  778. { 3, GAMEMENU_LABEL_INVENTORY, TRUE, PAL_XY(16, 50 + 36) },
  779. { 4, GAMEMENU_LABEL_SYSTEM, TRUE, PAL_XY(16, 50 + 54) },
  780. };
  781. //
  782. // Display the cash amount.
  783. //
  784. lpCashBox = PAL_ShowCash(gpGlobals->dwCash);
  785. //
  786. // Create the menu box.
  787. //
  788. lpMenuBox = PAL_CreateBox(PAL_XY(3, 37), 3, PAL_MenuTextMaxWidth(rgMainMenuItem, 4) - 1, 0, TRUE);
  789. VIDEO_UpdateScreen(&rect);
  790. //
  791. // Process the menu
  792. //
  793. while (TRUE)
  794. {
  795. wReturnValue = PAL_ReadMenu(PAL_InGameMenu_OnItemChange, rgMainMenuItem, 4,
  796. gpGlobals->iCurMainMenuItem, MENUITEM_COLOR);
  797. if (wReturnValue == MENUITEM_VALUE_CANCELLED)
  798. {
  799. break;
  800. }
  801. switch (wReturnValue)
  802. {
  803. case 1:
  804. //
  805. // Status
  806. //
  807. PAL_PlayerStatus();
  808. goto out;
  809. case 2:
  810. //
  811. // Magic
  812. //
  813. PAL_InGameMagicMenu();
  814. goto out;
  815. case 3:
  816. //
  817. // Inventory
  818. //
  819. PAL_InventoryMenu();
  820. goto out;
  821. case 4:
  822. //
  823. // System
  824. //
  825. if (PAL_SystemMenu())
  826. {
  827. goto out;
  828. }
  829. break;
  830. }
  831. }
  832. out:
  833. //
  834. // Remove the boxes.
  835. //
  836. PAL_DeleteBox(lpCashBox);
  837. PAL_DeleteBox(lpMenuBox);
  838. VIDEO_UpdateScreen(&rect);
  839. }
  840. VOID
  841. PAL_PlayerStatus(
  842. VOID
  843. )
  844. /*++
  845. Purpose:
  846. Show the player status.
  847. Parameters:
  848. None.
  849. Return value:
  850. None.
  851. --*/
  852. {
  853. PAL_LARGE BYTE bufBackground[320 * 200];
  854. PAL_LARGE BYTE bufImage[16384];
  855. PAL_LARGE BYTE bufImageBox[50 * 49];
  856. int labels[] = {
  857. STATUS_LABEL_ATTACKPOWER, STATUS_LABEL_MAGICPOWER, STATUS_LABEL_RESISTANCE,
  858. STATUS_LABEL_DEXTERITY, STATUS_LABEL_FLEERATE
  859. };
  860. int iCurrent;
  861. int iPlayerRole;
  862. int i, j;
  863. WORD w;
  864. PAL_MKFDecompressChunk(bufBackground, 320 * 200, STATUS_BACKGROUND_FBPNUM, gpGlobals->f.fpFBP);
  865. iCurrent = 0;
  866. if (gConfig.fUseCustomScreenLayout)
  867. {
  868. for (i = 0; i < 49; i++)
  869. {
  870. memcpy(&bufImageBox[i * 50], &bufBackground[(i + 39) * 320 + 247], 50);
  871. }
  872. for (i = 0; i < 49; i++)
  873. {
  874. memcpy(&bufBackground[(i + 125) * 320 + 81], &bufBackground[(i + 125) * 320 + 81 - 50], 50);
  875. memcpy(&bufBackground[(i + 141) * 320 + 141], &bufBackground[(i + 141) * 320 + 81 - 50], 50);
  876. memcpy(&bufBackground[(i + 133) * 320 + 201], &bufBackground[(i + 133) * 320 + 81 - 50], 50);
  877. memcpy(&bufBackground[(i + 101) * 320 + 251], &bufBackground[(i + 101) * 320 + 81 - 50], 50);
  878. memcpy(&bufBackground[(i + 39) * 320 + 247], &bufBackground[(i + 39) * 320 + 189 - 50], 50);
  879. if (i > 0) memcpy(&bufBackground[(i - 1) * 320 + 189], &bufBackground[(i - 1) * 320 + 189 - 50], 50);
  880. }
  881. for(i = 0; i < MAX_PLAYER_EQUIPMENTS; i++)
  882. {
  883. short x = PAL_X(gConfig.ScreenLayout.RoleEquipImageBoxes[i]);
  884. short y = PAL_Y(gConfig.ScreenLayout.RoleEquipImageBoxes[i]);
  885. short sx = (x < 0) ? -x : 0, sy = (y < 0) ? -y : 0, d = (x > 270) ? x - 270 : 0;
  886. if (sx >= 50 || sy >= 49 || x >= 320 || y >= 200) continue;
  887. for (; sy < 49 && y + sy < 200; sy++)
  888. {
  889. memcpy(&bufBackground[(y + sy) * 320 + x + sx], &bufImageBox[sy * 50 + sx], 50 - sx - d);
  890. }
  891. }
  892. }
  893. while (iCurrent >= 0 && iCurrent <= gpGlobals->wMaxPartyMemberIndex)
  894. {
  895. iPlayerRole = gpGlobals->rgParty[iCurrent].wPlayerRole;
  896. //
  897. // Draw the background image
  898. //
  899. PAL_FBPBlitToSurface(bufBackground, gpScreen);
  900. //
  901. // Draw the image of player role
  902. //
  903. if (PAL_MKFReadChunk(bufImage, 16384, gpGlobals->g.PlayerRoles.rgwAvatar[iPlayerRole], gpGlobals->f.fpRGM) > 0)
  904. {
  905. PAL_RLEBlitToSurface(bufImage, gpScreen, gConfig.ScreenLayout.RoleImage);
  906. }
  907. //
  908. // Draw the equipments
  909. //
  910. for (i = 0; i < MAX_PLAYER_EQUIPMENTS; i++)
  911. {
  912. int offset;
  913. w = gpGlobals->g.PlayerRoles.rgwEquipment[i][iPlayerRole];
  914. if (w == 0)
  915. {
  916. continue;
  917. }
  918. //
  919. // Draw the image
  920. //
  921. if (PAL_MKFReadChunk(bufImage, 16384,
  922. gpGlobals->g.rgObject[w].item.wBitmap, gpGlobals->f.fpBALL) > 0)
  923. {
  924. PAL_RLEBlitToSurface(bufImage, gpScreen,
  925. PAL_XY_OFFSET(gConfig.ScreenLayout.RoleEquipImageBoxes[i], 1, 1));
  926. }
  927. //
  928. // Draw the text label
  929. //
  930. offset = PAL_WordWidth(w) * 16;
  931. if (PAL_X(gConfig.ScreenLayout.RoleEquipNames[i]) + offset > 320)
  932. {
  933. offset = 320 - PAL_X(gConfig.ScreenLayout.RoleEquipNames[i]) - offset;
  934. }
  935. else
  936. {
  937. offset = 0;
  938. }
  939. PAL_DrawText(PAL_GetWord(w), PAL_XY_OFFSET(gConfig.ScreenLayout.RoleEquipNames[i], offset, 0), STATUS_COLOR_EQUIPMENT, TRUE, FALSE, FALSE);
  940. }
  941. //
  942. // Draw the text labels
  943. //
  944. PAL_DrawText(PAL_GetWord(STATUS_LABEL_EXP), gConfig.ScreenLayout.RoleExpLabel, MENUITEM_COLOR, TRUE, FALSE, FALSE);
  945. PAL_DrawText(PAL_GetWord(STATUS_LABEL_LEVEL), gConfig.ScreenLayout.RoleLevelLabel, MENUITEM_COLOR, TRUE, FALSE, FALSE);
  946. PAL_DrawText(PAL_GetWord(STATUS_LABEL_HP), gConfig.ScreenLayout.RoleHPLabel, MENUITEM_COLOR, TRUE, FALSE, FALSE);
  947. PAL_DrawText(PAL_GetWord(STATUS_LABEL_MP), gConfig.ScreenLayout.RoleMPLabel, MENUITEM_COLOR, TRUE, FALSE, FALSE);
  948. for (i = 0; i < sizeof(labels) / sizeof(int); i++)
  949. {
  950. PAL_DrawText(PAL_GetWord(labels[i]), gConfig.ScreenLayout.RoleStatusLabels[i], MENUITEM_COLOR, TRUE, FALSE, FALSE);
  951. }
  952. PAL_DrawText(PAL_GetWord(gpGlobals->g.PlayerRoles.rgwName[iPlayerRole]),
  953. gConfig.ScreenLayout.RoleName, MENUITEM_COLOR_CONFIRMED, TRUE, FALSE, FALSE);
  954. //
  955. // Draw the stats
  956. //
  957. if (gConfig.ScreenLayout.RoleExpSlash != 0)
  958. {
  959. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_SLASH), gpScreen, gConfig.ScreenLayout.RoleExpSlash);
  960. }
  961. if (gConfig.ScreenLayout.RoleHPSlash != 0)
  962. {
  963. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_SLASH), gpScreen, gConfig.ScreenLayout.RoleHPSlash);
  964. }
  965. if (gConfig.ScreenLayout.RoleMPSlash != 0)
  966. {
  967. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_SLASH), gpScreen, gConfig.ScreenLayout.RoleMPSlash);
  968. }
  969. PAL_DrawNumber(gpGlobals->Exp.rgPrimaryExp[iPlayerRole].wExp, 5,
  970. gConfig.ScreenLayout.RoleCurrExp, kNumColorYellow, kNumAlignRight);
  971. PAL_DrawNumber(gpGlobals->g.rgLevelUpExp[gpGlobals->g.PlayerRoles.rgwLevel[iPlayerRole]], 5,
  972. gConfig.ScreenLayout.RoleNextExp, kNumColorCyan, kNumAlignRight);
  973. PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwLevel[iPlayerRole], 2,
  974. gConfig.ScreenLayout.RoleLevel, kNumColorYellow, kNumAlignRight);
  975. PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwHP[iPlayerRole], 4,
  976. gConfig.ScreenLayout.RoleCurHP, kNumColorYellow, kNumAlignRight);
  977. PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwMaxHP[iPlayerRole], 4,
  978. gConfig.ScreenLayout.RoleMaxHP, kNumColorBlue, kNumAlignRight);
  979. PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwMP[iPlayerRole], 4,
  980. gConfig.ScreenLayout.RoleCurMP, kNumColorYellow, kNumAlignRight);
  981. PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwMaxMP[iPlayerRole], 4,
  982. gConfig.ScreenLayout.RoleMaxMP, kNumColorBlue, kNumAlignRight);
  983. PAL_DrawNumber(PAL_GetPlayerAttackStrength(iPlayerRole), 4,
  984. gConfig.ScreenLayout.RoleStatusValues[0], kNumColorYellow, kNumAlignRight);
  985. PAL_DrawNumber(PAL_GetPlayerMagicStrength(iPlayerRole), 4,
  986. gConfig.ScreenLayout.RoleStatusValues[1], kNumColorYellow, kNumAlignRight);
  987. PAL_DrawNumber(PAL_GetPlayerDefense(iPlayerRole), 4,
  988. gConfig.ScreenLayout.RoleStatusValues[2], kNumColorYellow, kNumAlignRight);
  989. PAL_DrawNumber(PAL_GetPlayerDexterity(iPlayerRole), 4,
  990. gConfig.ScreenLayout.RoleStatusValues[3], kNumColorYellow, kNumAlignRight);
  991. PAL_DrawNumber(PAL_GetPlayerFleeRate(iPlayerRole), 4,
  992. gConfig.ScreenLayout.RoleStatusValues[4], kNumColorYellow, kNumAlignRight);
  993. //
  994. // Draw all poisons
  995. //
  996. for (i = j = 0; i < MAX_POISONS; i++)
  997. {
  998. w = gpGlobals->rgPoisonStatus[i][iCurrent].wPoisonID;
  999. if (w != 0 && gpGlobals->g.rgObject[w].poison.wPoisonLevel <= 3)
  1000. {
  1001. PAL_DrawText(PAL_GetWord(w), gConfig.ScreenLayout.RolePoisonNames[j++], (BYTE)(gpGlobals->g.rgObject[w].poison.wColor + 10), TRUE, FALSE, FALSE);
  1002. }
  1003. }
  1004. //
  1005. // Update the screen
  1006. //
  1007. VIDEO_UpdateScreen(NULL);
  1008. //
  1009. // Wait for input
  1010. //
  1011. PAL_ClearKeyState();
  1012. while (TRUE)
  1013. {
  1014. UTIL_Delay(1);
  1015. if (g_InputState.dwKeyPress & kKeyMenu)
  1016. {
  1017. iCurrent = -1;
  1018. break;
  1019. }
  1020. else if (g_InputState.dwKeyPress & (kKeyLeft | kKeyUp))
  1021. {
  1022. iCurrent--;
  1023. break;
  1024. }
  1025. else if (g_InputState.dwKeyPress & (kKeyRight | kKeyDown | kKeySearch))
  1026. {
  1027. iCurrent++;
  1028. break;
  1029. }
  1030. }
  1031. }
  1032. }
  1033. WORD
  1034. PAL_ItemUseMenu(
  1035. WORD wItemToUse
  1036. )
  1037. /*++
  1038. Purpose:
  1039. Show the use item menu.
  1040. Parameters:
  1041. [IN] wItemToUse - the object ID of the item to use.
  1042. Return value:
  1043. The selected player to use the item onto.
  1044. MENUITEM_VALUE_CANCELLED if user cancelled.
  1045. --*/
  1046. {
  1047. BYTE bColor, bSelectedColor;
  1048. PAL_LARGE BYTE bufImage[2048];
  1049. DWORD dwColorChangeTime;
  1050. static WORD wSelectedPlayer = 0;
  1051. SDL_Rect rect = {110, 2, 200, 180};
  1052. int i;
  1053. bSelectedColor = MENUITEM_COLOR_SELECTED_FIRST;
  1054. dwColorChangeTime = 0;
  1055. while (TRUE)
  1056. {
  1057. if (wSelectedPlayer > gpGlobals->wMaxPartyMemberIndex)
  1058. {
  1059. wSelectedPlayer = 0;
  1060. }
  1061. //
  1062. // Draw the box
  1063. //
  1064. PAL_CreateBox(PAL_XY(110, 2), 7, 9, 0, FALSE);
  1065. //
  1066. // Draw the stats of the selected player
  1067. //
  1068. PAL_DrawText(PAL_GetWord(STATUS_LABEL_LEVEL), PAL_XY(200, 16),
  1069. ITEMUSEMENU_COLOR_STATLABEL, TRUE, FALSE, FALSE);
  1070. PAL_DrawText(PAL_GetWord(STATUS_LABEL_HP), PAL_XY(200, 34),
  1071. ITEMUSEMENU_COLOR_STATLABEL, TRUE, FALSE, FALSE);
  1072. PAL_DrawText(PAL_GetWord(STATUS_LABEL_MP), PAL_XY(200, 52),
  1073. ITEMUSEMENU_COLOR_STATLABEL, TRUE, FALSE, FALSE);
  1074. PAL_DrawText(PAL_GetWord(STATUS_LABEL_ATTACKPOWER), PAL_XY(200, 70),
  1075. ITEMUSEMENU_COLOR_STATLABEL, TRUE, FALSE, FALSE);
  1076. PAL_DrawText(PAL_GetWord(STATUS_LABEL_MAGICPOWER), PAL_XY(200, 88),
  1077. ITEMUSEMENU_COLOR_STATLABEL, TRUE, FALSE, FALSE);
  1078. PAL_DrawText(PAL_GetWord(STATUS_LABEL_RESISTANCE), PAL_XY(200, 106),
  1079. ITEMUSEMENU_COLOR_STATLABEL, TRUE, FALSE, FALSE);
  1080. PAL_DrawText(PAL_GetWord(STATUS_LABEL_DEXTERITY), PAL_XY(200, 124),
  1081. ITEMUSEMENU_COLOR_STATLABEL, TRUE, FALSE, FALSE);
  1082. PAL_DrawText(PAL_GetWord(STATUS_LABEL_FLEERATE), PAL_XY(200, 142),
  1083. ITEMUSEMENU_COLOR_STATLABEL, TRUE, FALSE, FALSE);
  1084. i = gpGlobals->rgParty[wSelectedPlayer].wPlayerRole;
  1085. PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwLevel[i], 4, PAL_XY(240, 20),
  1086. kNumColorYellow, kNumAlignRight);
  1087. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_SLASH), gpScreen,
  1088. PAL_XY(263, 38));
  1089. PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwMaxHP[i], 4,
  1090. PAL_XY(261, 40), kNumColorBlue, kNumAlignRight);
  1091. PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwHP[i], 4,
  1092. PAL_XY(240, 37), kNumColorYellow, kNumAlignRight);
  1093. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_SLASH), gpScreen,
  1094. PAL_XY(263, 56));
  1095. PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwMaxMP[i], 4,
  1096. PAL_XY(261, 58), kNumColorBlue, kNumAlignRight);
  1097. PAL_DrawNumber(gpGlobals->g.PlayerRoles.rgwMP[i], 4,
  1098. PAL_XY(240, 55), kNumColorYellow, kNumAlignRight);
  1099. PAL_DrawNumber(PAL_GetPlayerAttackStrength(i), 4, PAL_XY(240, 74),
  1100. kNumColorYellow, kNumAlignRight);
  1101. PAL_DrawNumber(PAL_GetPlayerMagicStrength(i), 4, PAL_XY(240, 92),
  1102. kNumColorYellow, kNumAlignRight);
  1103. PAL_DrawNumber(PAL_GetPlayerDefense(i), 4, PAL_XY(240, 110),
  1104. kNumColorYellow, kNumAlignRight);
  1105. PAL_DrawNumber(PAL_GetPlayerDexterity(i), 4, PAL_XY(240, 128),
  1106. kNumColorYellow, kNumAlignRight);
  1107. PAL_DrawNumber(PAL_GetPlayerFleeRate(i), 4, PAL_XY(240, 146),
  1108. kNumColorYellow, kNumAlignRight);
  1109. //
  1110. // Draw the names of the players in the party
  1111. //
  1112. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  1113. {
  1114. if (i == wSelectedPlayer)
  1115. {
  1116. bColor = bSelectedColor;
  1117. }
  1118. else
  1119. {
  1120. bColor = MENUITEM_COLOR;
  1121. }
  1122. PAL_DrawText(PAL_GetWord(gpGlobals->g.PlayerRoles.rgwName[gpGlobals->rgParty[i].wPlayerRole]),
  1123. PAL_XY(125, 16 + 20 * i), bColor, TRUE, FALSE, FALSE);
  1124. }
  1125. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_ITEMBOX), gpScreen,
  1126. PAL_XY(120, 80));
  1127. i = PAL_GetItemAmount(wItemToUse);
  1128. if (i > 0)
  1129. {
  1130. //
  1131. // Draw the picture of the item
  1132. //
  1133. if (PAL_MKFReadChunk(bufImage, 2048,
  1134. gpGlobals->g.rgObject[wItemToUse].item.wBitmap, gpGlobals->f.fpBALL) > 0)
  1135. {
  1136. PAL_RLEBlitToSurface(bufImage, gpScreen, PAL_XY(127, 88));
  1137. }
  1138. //
  1139. // Draw the amount and label of the item
  1140. //
  1141. PAL_DrawText(PAL_GetWord(wItemToUse), PAL_XY(116, 143), STATUS_COLOR_EQUIPMENT, TRUE, FALSE, FALSE);
  1142. PAL_DrawNumber(i, 2, PAL_XY(170, 133), kNumColorCyan, kNumAlignRight);
  1143. }
  1144. //
  1145. // Update the screen area
  1146. //
  1147. VIDEO_UpdateScreen(&rect);
  1148. //
  1149. // Wait for key
  1150. //
  1151. PAL_ClearKeyState();
  1152. while (TRUE)
  1153. {
  1154. //
  1155. // See if we should change the highlight color
  1156. //
  1157. if (SDL_TICKS_PASSED(SDL_GetTicks(), dwColorChangeTime))
  1158. {
  1159. if ((WORD)bSelectedColor + 1 >=
  1160. (WORD)MENUITEM_COLOR_SELECTED_FIRST + MENUITEM_COLOR_SELECTED_TOTALNUM)
  1161. {
  1162. bSelectedColor = MENUITEM_COLOR_SELECTED_FIRST;
  1163. }
  1164. else
  1165. {
  1166. bSelectedColor++;
  1167. }
  1168. dwColorChangeTime = SDL_GetTicks() + (600 / MENUITEM_COLOR_SELECTED_TOTALNUM);
  1169. //
  1170. // Redraw the selected item.
  1171. //
  1172. PAL_DrawText(
  1173. PAL_GetWord(gpGlobals->g.PlayerRoles.rgwName[gpGlobals->rgParty[wSelectedPlayer].wPlayerRole]),
  1174. PAL_XY(125, 16 + 20 * wSelectedPlayer), bSelectedColor, FALSE, TRUE, FALSE);
  1175. }
  1176. PAL_ProcessEvent();
  1177. if (g_InputState.dwKeyPress != 0)
  1178. {
  1179. break;
  1180. }
  1181. SDL_Delay(1);
  1182. }
  1183. if (i <= 0)
  1184. {
  1185. return MENUITEM_VALUE_CANCELLED;
  1186. }
  1187. if (g_InputState.dwKeyPress & (kKeyUp | kKeyLeft))
  1188. {
  1189. wSelectedPlayer--;
  1190. }
  1191. else if (g_InputState.dwKeyPress & (kKeyDown | kKeyRight))
  1192. {
  1193. if (wSelectedPlayer < gpGlobals->wMaxPartyMemberIndex)
  1194. {
  1195. wSelectedPlayer++;
  1196. }
  1197. }
  1198. else if (g_InputState.dwKeyPress & kKeyMenu)
  1199. {
  1200. break;
  1201. }
  1202. else if (g_InputState.dwKeyPress & kKeySearch)
  1203. {
  1204. return gpGlobals->rgParty[wSelectedPlayer].wPlayerRole;
  1205. }
  1206. }
  1207. return MENUITEM_VALUE_CANCELLED;
  1208. }
  1209. static VOID
  1210. PAL_BuyMenu_OnItemChange(
  1211. WORD wCurrentItem
  1212. )
  1213. /*++
  1214. Purpose:
  1215. Callback function which is called when player selected another item
  1216. in the buy menu.
  1217. Parameters:
  1218. [IN] wCurrentItem - current item on the menu, indicates the object ID of
  1219. the currently selected item.
  1220. Return value:
  1221. None.
  1222. --*/
  1223. {
  1224. const SDL_Rect rect = {20, 8, 128, 175};
  1225. int i, n;
  1226. PAL_LARGE BYTE bufImage[2048];
  1227. //
  1228. // Draw the picture of current selected item
  1229. //
  1230. PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_ITEMBOX), gpScreen,
  1231. PAL_XY(35, 8));
  1232. if (PAL_MKFReadChunk(bufImage, 2048,
  1233. gpGlobals->g.rgObject[wCurrentItem].item.wBitmap, gpGlobals->f.fpBALL) > 0)
  1234. {
  1235. PAL_RLEBlitToSurface(bufImage, gpScreen, PAL_XY(42, 16));
  1236. }
  1237. //
  1238. // See how many of this item we have in the inventory
  1239. //
  1240. n = 0;
  1241. for (i = 0; i < MAX_INVENTORY; i++)
  1242. {
  1243. if (gpGlobals->rgInventory[i].wItem == 0)
  1244. {
  1245. break;
  1246. }
  1247. else if (gpGlobals->rgInventory[i].wItem == wCurrentItem)
  1248. {
  1249. n = gpGlobals->rgInventory[i].nAmount;
  1250. break;
  1251. }
  1252. }
  1253. //
  1254. // Draw the amount of this item in the inventory
  1255. //
  1256. PAL_CreateSingleLineBox(PAL_XY(20, 105), 5, FALSE);
  1257. PAL_DrawText(PAL_GetWord(BUYMENU_LABEL_CURRENT), PAL_XY(30, 115), 0, FALSE, FALSE, FALSE);
  1258. PAL_DrawNumber(n, 6, PAL_XY(69, 119), kNumColorYellow, kNumAlignRight);
  1259. //
  1260. // Draw the cash amount
  1261. //
  1262. PAL_CreateSingleLineBox(PAL_XY(20, 145), 5, FALSE);
  1263. PAL_DrawText(PAL_GetWord(CASH_LABEL), PAL_XY(30, 155), 0, FALSE, FALSE, FALSE);
  1264. PAL_DrawNumber(gpGlobals->dwCash, 6, PAL_XY(69, 159), kNumColorYellow, kNumAlignRight);
  1265. VIDEO_UpdateScreen(&rect);
  1266. }
  1267. VOID
  1268. PAL_BuyMenu(
  1269. WORD wStoreNum
  1270. )
  1271. /*++
  1272. Purpose:
  1273. Show the buy item menu.
  1274. Parameters:
  1275. [IN] wStoreNum - number of the store to buy items from.
  1276. Return value:
  1277. None.
  1278. --*/
  1279. {
  1280. MENUITEM rgMenuItem[MAX_STORE_ITEM];
  1281. int i, y;
  1282. WORD w;
  1283. SDL_Rect rect = {125, 8, 190, 190};
  1284. //
  1285. // create the menu items
  1286. //
  1287. y = 22;
  1288. for (i = 0; i < MAX_STORE_ITEM; i++)
  1289. {
  1290. if (gpGlobals->g.lprgStore[wStoreNum].rgwItems[i] == 0)
  1291. {
  1292. break;
  1293. }
  1294. rgMenuItem[i].wValue = gpGlobals->g.lprgStore[wStoreNum].rgwItems[i];
  1295. rgMenuItem[i].wNumWord = gpGlobals->g.lprgStore[wStoreNum].rgwItems[i];
  1296. rgMenuItem[i].fEnabled = TRUE;
  1297. rgMenuItem[i].pos = PAL_XY(150, y);
  1298. y += 18;
  1299. }
  1300. //
  1301. // Draw the box
  1302. //
  1303. PAL_CreateBox(PAL_XY(125, 8), 8, 8, 1, FALSE);
  1304. //
  1305. // Draw the number of prices
  1306. //
  1307. for (y = 0; y < i; y++)
  1308. {
  1309. w = gpGlobals->g.rgObject[rgMenuItem[y].wValue].item.wPrice;
  1310. PAL_DrawNumber(w, 6, PAL_XY(235, 25 + y * 18), kNumColorCyan, kNumAlignRight);
  1311. }
  1312. VIDEO_UpdateScreen(&rect);
  1313. w = 0;
  1314. while (TRUE)
  1315. {
  1316. w = PAL_ReadMenu(PAL_BuyMenu_OnItemChange, rgMenuItem, i, w, MENUITEM_COLOR);
  1317. if (w == MENUITEM_VALUE_CANCELLED)
  1318. {
  1319. break;
  1320. }
  1321. if (gpGlobals->g.rgObject[w].item.wPrice <= gpGlobals->dwCash)
  1322. {
  1323. if (PAL_ConfirmMenu())
  1324. {
  1325. //
  1326. // Player bought an item
  1327. //
  1328. gpGlobals->dwCash -= gpGlobals->g.rgObject[w].item.wPrice;
  1329. PAL_AddItemToInventory(w, 1);
  1330. }
  1331. }
  1332. //
  1333. // Place the cursor to the current item on next loop
  1334. //
  1335. for (y = 0; y < i; y++)
  1336. {
  1337. if (w == rgMenuItem[y].wValue)
  1338. {
  1339. w = y;
  1340. break;
  1341. }
  1342. }
  1343. }
  1344. }
  1345. static VOID
  1346. PAL_SellMenu_OnItemChange(
  1347. WORD wCurrentItem
  1348. )
  1349. /*++
  1350. Purpose:
  1351. Callback function which is called when player selected another item
  1352. in the sell item menu.
  1353. Parameters:
  1354. [IN] wCurrentItem - current item on the menu, indicates the object ID of
  1355. the currently selected item.
  1356. Return value:
  1357. None.
  1358. --*/
  1359. {
  1360. //
  1361. // Draw the cash amount
  1362. //
  1363. PAL_CreateSingleLineBox(PAL_XY(100, 150), 5, FALSE);
  1364. PAL_DrawText(PAL_GetWord(CASH_LABEL), PAL_XY(110, 160), 0, FALSE, FALSE, FALSE);
  1365. PAL_DrawNumber(gpGlobals->dwCash, 6, PAL_XY(149, 164), kNumColorYellow, kNumAlignRight);
  1366. //
  1367. // Draw the price
  1368. //
  1369. PAL_CreateSingleLineBox(PAL_XY(220, 150), 5, FALSE);
  1370. if (gpGlobals->g.rgObject[wCurrentItem].item.wFlags & kItemFlagSellable)
  1371. {
  1372. PAL_DrawText(PAL_GetWord(SELLMENU_LABEL_PRICE), PAL_XY(230, 160), 0, FALSE, FALSE, FALSE);
  1373. PAL_DrawNumber(gpGlobals->g.rgObject[wCurrentItem].item.wPrice / 2, 6,
  1374. PAL_XY(269, 164), kNumColorYellow, kNumAlignRight);
  1375. }
  1376. }
  1377. VOID
  1378. PAL_SellMenu(
  1379. VOID
  1380. )
  1381. /*++
  1382. Purpose:
  1383. Show the sell item menu.
  1384. Parameters:
  1385. None.
  1386. Return value:
  1387. None.
  1388. --*/
  1389. {
  1390. WORD w;
  1391. while (TRUE)
  1392. {
  1393. w = PAL_ItemSelectMenu(PAL_SellMenu_OnItemChange, kItemFlagSellable);
  1394. if (w == 0)
  1395. {
  1396. break;
  1397. }
  1398. if (PAL_ConfirmMenu())
  1399. {
  1400. if (PAL_AddItemToInventory(w, -1))
  1401. {
  1402. gpGlobals->dwCash += gpGlobals->g.rgObject[w].item.wPrice / 2;
  1403. }
  1404. }
  1405. }
  1406. }
  1407. VOID
  1408. PAL_EquipItemMenu(
  1409. WORD wItem
  1410. )
  1411. /*++
  1412. Purpose:
  1413. Show the menu which allow players to equip the specified item.
  1414. Parameters:
  1415. [IN] wItem - the object ID of the item.
  1416. Return value:
  1417. None.
  1418. --*/
  1419. {
  1420. PAL_LARGE BYTE bufBackground[320 * 200];
  1421. PAL_LARGE BYTE bufImageBox[72 * 72];
  1422. PAL_LARGE BYTE bufImage[2048];
  1423. WORD w;
  1424. int iCurrentPlayer, i;
  1425. BYTE bColor, bSelectedColor;
  1426. DWORD dwColorChangeTime;
  1427. gpGlobals->wLastUnequippedItem = wItem;
  1428. PAL_MKFDecompressChunk(bufBackground, 320 * 200, EQUIPMENU_BACKGROUND_FBPNUM,
  1429. gpGlobals->f.fpFBP);
  1430. if (gConfig.fUseCustomScreenLayout)
  1431. {
  1432. int x = PAL_X(gConfig.ScreenLayout.EquipImageBox);
  1433. int y = PAL_Y(gConfig.ScreenLayout.EquipImageBox);
  1434. for (i = 8; i < 72; i++)
  1435. {
  1436. memcpy(&bufBackground[i * 320 + 92], &bufBackground[(i + 128) * 320 + 92], 32);
  1437. memcpy(&bufBackground[(i + 64) * 320 + 92], &bufBackground[(i + 128) * 320 + 92], 32);
  1438. }
  1439. for (i = 9; i < 90; i++)
  1440. {
  1441. memcpy(&bufBackground[i * 320 + 226], &bufBackground[(i + 104) * 320 + 226], 32);
  1442. }
  1443. for (i = 99; i < 113; i++)
  1444. {
  1445. memcpy(&bufBackground[i * 320 + 226], &bufBackground[(i + 16) * 320 + 226], 32);
  1446. }
  1447. for (i = 8; i < 80; i++)
  1448. {
  1449. memcpy(&bufImageBox[(i - 8) * 72], &bufBackground[i * 320 + 8], 72);
  1450. memcpy(&bufBackground[i * 320 + 8], &bufBackground[(i + 72) * 320 + 8], 72);
  1451. }
  1452. for (i = 0; i < 72; i++)
  1453. {
  1454. memcpy(&bufBackground[(i + y) * 320 + x], &bufImageBox[i * 72], 72);
  1455. }
  1456. }
  1457. iCurrentPlayer = 0;
  1458. bSelectedColor = MENUITEM_COLOR_SELECTED_FIRST;
  1459. dwColorChangeTime = SDL_GetTicks() + (600 / MENUITEM_COLOR_SELECTED_TOTALNUM);
  1460. while (TRUE)
  1461. {
  1462. wItem = gpGlobals->wLastUnequippedItem;
  1463. //
  1464. // Draw the background
  1465. //
  1466. PAL_FBPBlitToSurface(bufBackground, gpScreen);
  1467. //
  1468. // Draw the item picture
  1469. //
  1470. if (PAL_MKFReadChunk(bufImage, 2048,
  1471. gpGlobals->g.rgObject[wItem].item.wBitmap, gpGlobals->f.fpBALL) > 0)
  1472. {
  1473. PAL_RLEBlitToSurface(bufImage, gpScreen, PAL_XY_OFFSET(gConfig.ScreenLayout.EquipImageBox, 8, 8));
  1474. }
  1475. if (gConfig.fUseCustomScreenLayout)
  1476. {
  1477. int labels1[] = { STATUS_LABEL_ATTACKPOWER, STATUS_LABEL_MAGICPOWER, STATUS_LABEL_RESISTANCE, STATUS_LABEL_DEXTERITY, STATUS_LABEL_FLEERATE };
  1478. int labels2[] = { EQUIP_LABEL_HEAD, EQUIP_LABEL_SHOULDER, EQUIP_LABEL_BODY, EQUIP_LABEL_HAND, EQUIP_LABEL_FOOT, EQUIP_LABEL_NECK };
  1479. for (i = 0; i < sizeof(labels1) / sizeof(int); i++)
  1480. {
  1481. int index = &gConfig.ScreenLayout.EquipStatusLabels[i] - gConfig.ScreenLayoutArray;
  1482. BOOL fShadow = (gConfig.ScreenLayoutFlag[index] & DISABLE_SHADOW) ? FALSE : TRUE;
  1483. BOOL fUse8x8Font = (gConfig.ScreenLayoutFlag[index] & USE_8x8_FONT) ? TRUE : FALSE;
  1484. PAL_DrawText(PAL_GetWord(labels1[i]), gConfig.ScreenLayoutArray[index], MENUITEM_COLOR, fShadow, FALSE, fUse8x8Font);
  1485. }
  1486. for (i = 0; i < sizeof(labels2) / sizeof(int); i++)
  1487. {
  1488. int index = &gConfig.ScreenLayout.EquipLabels[i] - gConfig.ScreenLayoutArray;
  1489. BOOL fShadow = (gConfig.ScreenLayoutFlag[index] & DISABLE_SHADOW) ? FALSE : TRUE;
  1490. BOOL fUse8x8Font = (gConfig.ScreenLayoutFlag[index] & USE_8x8_FONT) ? TRUE : FALSE;
  1491. PAL_DrawText(PAL_GetWord(labels2[i]), gConfig.ScreenLayoutArray[index], MENUITEM_COLOR, fShadow, FALSE, fUse8x8Font);
  1492. }
  1493. }
  1494. //
  1495. // Draw the current equipment of the selected player
  1496. //
  1497. w = gpGlobals->rgParty[iCurrentPlayer].wPlayerRole;
  1498. for (i = 0; i < MAX_PLAYER_EQUIPMENTS; i++)
  1499. {
  1500. if (gpGlobals->g.PlayerRoles.rgwEquipment[i][w] != 0)
  1501. {
  1502. PAL_DrawText(PAL_GetWord(gpGlobals->g.PlayerRoles.rgwEquipment[i][w]),
  1503. gConfig.ScreenLayout.EquipNames[i], MENUITEM_COLOR, TRUE, FALSE, FALSE);
  1504. }
  1505. }
  1506. //
  1507. // Draw the stats of the currently selected player
  1508. //
  1509. PAL_DrawNumber(PAL_GetPlayerAttackStrength(w), 4, gConfig.ScreenLayout.EquipStatusValues[0], kNumColorCyan, kNumAlignRight);
  1510. PAL_DrawNumber(PAL_GetPlayerMagicStrength(w), 4, gConfig.ScreenLayout.EquipStatusValues[1], kNumColorCyan, kNumAlignRight);
  1511. PAL_DrawNumber(PAL_GetPlayerDefense(w), 4, gConfig.ScreenLayout.EquipStatusValues[2], kNumColorCyan, kNumAlignRight);
  1512. PAL_DrawNumber(PAL_GetPlayerDexterity(w), 4, gConfig.ScreenLayout.EquipStatusValues[3], kNumColorCyan, kNumAlignRight);
  1513. PAL_DrawNumber(PAL_GetPlayerFleeRate(w), 4, gConfig.ScreenLayout.EquipStatusValues[4], kNumColorCyan, kNumAlignRight);
  1514. //
  1515. // Draw a box for player selection
  1516. //
  1517. PAL_CreateBox(gConfig.ScreenLayout.EquipRoleListBox, gpGlobals->wMaxPartyMemberIndex, PAL_WordMaxWidth(36, 4) - 1, 0, FALSE);
  1518. //
  1519. // Draw the label of players
  1520. //
  1521. for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
  1522. {
  1523. w = gpGlobals->rgParty[i].wPlayerRole;
  1524. if (iCurrentPlayer == i)
  1525. {
  1526. if (gpGlobals->g.rgObject[wItem].item.wFlags & (kItemFlagEquipableByPlayerRole_First << w))
  1527. {
  1528. bColor = bSelectedColor;
  1529. }
  1530. else
  1531. {
  1532. bColor = MENUITEM_COLOR_SELECTED_INACTIVE;
  1533. }
  1534. }
  1535. else
  1536. {
  1537. if (gpGlobals->g.rgObject[wItem].item.wFlags & (kItemFlagEquipableByPlayerRole_First << w))
  1538. {
  1539. bColor = MENUITEM_COLOR;
  1540. }
  1541. else
  1542. {
  1543. bColor = MENUITEM_COLOR_INACTIVE;
  1544. }
  1545. }
  1546. PAL_DrawText(PAL_GetWord(gpGlobals->g.PlayerRoles.rgwName[w]),
  1547. PAL_XY_OFFSET(gConfig.ScreenLayout.EquipRoleListBox, 13, 13 + 18 * i), bColor, TRUE, FALSE, FALSE);
  1548. }
  1549. //
  1550. // Draw the text label and amount of the item
  1551. //
  1552. if (wItem != 0)
  1553. {
  1554. PAL_DrawText(PAL_GetWord(wItem), gConfig.ScreenLayout.EquipItemName, MENUITEM_COLOR_CONFIRMED, TRUE, FALSE, FALSE);
  1555. PAL_DrawNumber(PAL_GetItemAmount(wItem), 2, gConfig.ScreenLayout.EquipItemAmount, kNumColorCyan, kNumAlignRight);
  1556. }
  1557. //
  1558. // Update the screen
  1559. //
  1560. VIDEO_UpdateScreen(NULL);
  1561. //
  1562. // Accept input
  1563. //
  1564. PAL_ClearKeyState();
  1565. while (TRUE)
  1566. {
  1567. PAL_ProcessEvent();
  1568. //
  1569. // See if we should change the highlight color
  1570. //
  1571. if (SDL_TICKS_PASSED(SDL_GetTicks(), dwColorChangeTime))
  1572. {
  1573. if ((WORD)bSelectedColor + 1 >=
  1574. (WORD)MENUITEM_COLOR_SELECTED_FIRST + MENUITEM_COLOR_SELECTED_TOTALNUM)
  1575. {
  1576. bSelectedColor = MENUITEM_COLOR_SELECTED_FIRST;
  1577. }
  1578. else
  1579. {
  1580. bSelectedColor++;
  1581. }
  1582. dwColorChangeTime = SDL_GetTicks() + (600 / MENUITEM_COLOR_SELECTED_TOTALNUM);
  1583. //
  1584. // Redraw the selected item if needed.
  1585. //
  1586. w = gpGlobals->rgParty[iCurrentPlayer].wPlayerRole;
  1587. if (gpGlobals->g.rgObject[wItem].item.wFlags & (kItemFlagEquipableByPlayerRole_First << w))
  1588. {
  1589. PAL_DrawText(PAL_GetWord(gpGlobals->g.PlayerRoles.rgwName[w]),
  1590. PAL_XY_OFFSET(gConfig.ScreenLayout.EquipRoleListBox, 13, 13 + 18 * iCurrentPlayer), bSelectedColor, TRUE, TRUE, FALSE);
  1591. }
  1592. }
  1593. if (g_InputState.dwKeyPress != 0)
  1594. {
  1595. break;
  1596. }
  1597. SDL_Delay(1);
  1598. }
  1599. if (wItem == 0)
  1600. {
  1601. return;
  1602. }
  1603. if (g_InputState.dwKeyPress & (kKeyUp | kKeyLeft))
  1604. {
  1605. iCurrentPlayer--;
  1606. if (iCurrentPlayer < 0)
  1607. {
  1608. iCurrentPlayer = 0;
  1609. }
  1610. }
  1611. else if (g_InputState.dwKeyPress & (kKeyDown | kKeyRight))
  1612. {
  1613. iCurrentPlayer++;
  1614. if (iCurrentPlayer > gpGlobals->wMaxPartyMemberIndex)
  1615. {
  1616. iCurrentPlayer = gpGlobals->wMaxPartyMemberIndex;
  1617. }
  1618. }
  1619. else if (g_InputState.dwKeyPress & kKeyMenu)
  1620. {
  1621. return;
  1622. }
  1623. else if (g_InputState.dwKeyPress & kKeySearch)
  1624. {
  1625. w = gpGlobals->rgParty[iCurrentPlayer].wPlayerRole;
  1626. if (gpGlobals->g.rgObject[wItem].item.wFlags & (kItemFlagEquipableByPlayerRole_First << w))
  1627. {
  1628. //
  1629. // Run the equip script
  1630. //
  1631. gpGlobals->g.rgObject[wItem].item.wScriptOnEquip =
  1632. PAL_RunTriggerScript(gpGlobals->g.rgObject[wItem].item.wScriptOnEquip,
  1633. gpGlobals->rgParty[iCurrentPlayer].wPlayerRole);
  1634. }
  1635. }
  1636. }
  1637. }
  1638. VOID
  1639. PAL_QuitGame(
  1640. VOID
  1641. )
  1642. {
  1643. WORD wReturnValue = PAL_TripleMenu(SYSMENU_LABEL_LAUNCHSETTING);
  1644. if (wReturnValue == 1 || wReturnValue == 2)
  1645. {
  1646. if (wReturnValue == 2) gConfig.fLaunchSetting = TRUE;
  1647. PAL_SaveConfig(); // Keep the fullscreen state
  1648. SOUND_PlayMUS(0, FALSE, 2);
  1649. PAL_FadeOut(2);
  1650. PAL_Shutdown(0);
  1651. }
  1652. }