uigame.c 51 KB

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