uigame.c 52 KB

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