uigame.c 51 KB

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