uigame.c 49 KB

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