uigame.c 51 KB

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