uigame.c 51 KB

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