uigame.c 52 KB

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