uigame.c 48 KB

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