uigame.c 51 KB

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