uigame.c 50 KB

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