uigame.c 52 KB

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