uigame.c 47 KB

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