text.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989
  1. /* -*- mode: c; tab-width: 4; c-basic-offset: 3; c-file-style: "linux" -*- */
  2. //
  3. // Copyright (c) 2008, Wei Mingzhi <whistler_wmz@users.sf.net>.
  4. // All rights reserved.
  5. //
  6. // Portions based on PALx Project by palxex.
  7. // Copyright (c) 2006-2008, Pal Lockheart <palxex@gmail.com>.
  8. //
  9. // This file is part of SDLPAL.
  10. //
  11. // SDLPAL is free software: you can redistribute it and/or modify
  12. // it under the terms of the GNU General Public License as published by
  13. // the Free Software Foundation, either version 3 of the License, or
  14. // (at your option) any later version.
  15. //
  16. // This program is distributed in the hope that it will be useful,
  17. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. // GNU General Public License for more details.
  20. //
  21. // You should have received a copy of the GNU General Public License
  22. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. //
  24. #include "main.h"
  25. #define WORD_LENGTH 10
  26. #define FONT_COLOR_DEFAULT 0x4F
  27. #define FONT_COLOR_YELLOW 0x2D
  28. #define FONT_COLOR_RED 0x1A
  29. #define FONT_COLOR_CYAN 0x8D
  30. #define FONT_COLOR_CYAN_ALT 0x8C
  31. BOOL g_fUpdatedInBattle = FALSE;
  32. static const char g_rgszAdditionalWords[][WORD_LENGTH + 1] = {
  33. {0xBE, 0xD4, 0xB0, 0xAB, 0xB3, 0x74, 0xAB, 0xD7, 0x00, 0x00, 0x00}, // Battle Speed
  34. {0xA4, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 1
  35. {0xA4, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 2
  36. {0xA4, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 3
  37. {0xA5, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 4
  38. {0xA4, 0xAD, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 5
  39. };
  40. typedef struct tagTEXTLIB
  41. {
  42. LPBYTE lpWordBuf;
  43. LPBYTE lpMsgBuf;
  44. LPDWORD lpMsgOffset;
  45. int nWords;
  46. int nMsgs;
  47. int nCurrentDialogLine;
  48. BYTE bCurrentFontColor;
  49. PAL_POS posIcon;
  50. PAL_POS posDialogTitle;
  51. PAL_POS posDialogText;
  52. BYTE bDialogPosition;
  53. BYTE bIcon;
  54. int iDelayTime;
  55. BOOL fUserSkip;
  56. BOOL fPlayingRNG;
  57. BYTE bufDialogIcons[282];
  58. } TEXTLIB, *LPTEXTLIB;
  59. static TEXTLIB g_TextLib;
  60. INT
  61. PAL_InitText(
  62. VOID
  63. )
  64. /*++
  65. Purpose:
  66. Initialize the in-game texts.
  67. Parameters:
  68. None.
  69. Return value:
  70. 0 = success.
  71. -1 = memory allocation error.
  72. --*/
  73. {
  74. FILE *fpMsg, *fpWord;
  75. int i;
  76. //
  77. // Open the message and word data files.
  78. //
  79. fpMsg = UTIL_OpenRequiredFile("m.msg");
  80. fpWord = UTIL_OpenRequiredFile("word.dat");
  81. //
  82. // See how many words we have
  83. //
  84. fseek(fpWord, 0, SEEK_END);
  85. i = ftell(fpWord);
  86. //
  87. // Each word has 10 bytes
  88. //
  89. g_TextLib.nWords = (i + (WORD_LENGTH - 1)) / WORD_LENGTH;
  90. //
  91. // Read the words
  92. //
  93. g_TextLib.lpWordBuf = (LPBYTE)malloc(i);
  94. if (g_TextLib.lpWordBuf == NULL)
  95. {
  96. fclose(fpWord);
  97. fclose(fpMsg);
  98. return -1;
  99. }
  100. fseek(fpWord, 0, SEEK_SET);
  101. fread(g_TextLib.lpWordBuf, i, 1, fpWord);
  102. //
  103. // Close the words file
  104. //
  105. fclose(fpWord);
  106. //
  107. // Read the message offsets. The message offsets are in SSS.MKF #3
  108. //
  109. i = PAL_MKFGetChunkSize(3, gpGlobals->f.fpSSS) / sizeof(DWORD);
  110. g_TextLib.nMsgs = i - 1;
  111. g_TextLib.lpMsgOffset = (LPDWORD)malloc(i * sizeof(DWORD));
  112. if (g_TextLib.lpMsgOffset == NULL)
  113. {
  114. free(g_TextLib.lpWordBuf);
  115. fclose(fpMsg);
  116. return -1;
  117. }
  118. PAL_MKFReadChunk((LPBYTE)(g_TextLib.lpMsgOffset), i * sizeof(DWORD), 3,
  119. gpGlobals->f.fpSSS);
  120. //
  121. // Read the messages.
  122. //
  123. fseek(fpMsg, 0, SEEK_END);
  124. i = ftell(fpMsg);
  125. g_TextLib.lpMsgBuf = (LPBYTE)malloc(i);
  126. if (g_TextLib.lpMsgBuf == NULL)
  127. {
  128. free(g_TextLib.lpMsgOffset);
  129. free(g_TextLib.lpWordBuf);
  130. fclose(fpMsg);
  131. return -1;
  132. }
  133. fseek(fpMsg, 0, SEEK_SET);
  134. fread(g_TextLib.lpMsgBuf, 1, i, fpMsg);
  135. fclose(fpMsg);
  136. g_TextLib.bCurrentFontColor = FONT_COLOR_DEFAULT;
  137. g_TextLib.bIcon = 0;
  138. g_TextLib.posIcon = 0;
  139. g_TextLib.nCurrentDialogLine = 0;
  140. g_TextLib.iDelayTime = 3;
  141. g_TextLib.posDialogTitle = PAL_XY(12, 8);
  142. g_TextLib.posDialogText = PAL_XY(44, 26);
  143. g_TextLib.bDialogPosition = kDialogUpper;
  144. g_TextLib.fUserSkip = FALSE;
  145. PAL_MKFReadChunk(g_TextLib.bufDialogIcons, 282, 12, gpGlobals->f.fpDATA);
  146. return 0;
  147. }
  148. VOID
  149. PAL_FreeText(
  150. VOID
  151. )
  152. /*++
  153. Purpose:
  154. Free the memory used by the texts.
  155. Parameters:
  156. None.
  157. Return value:
  158. None.
  159. --*/
  160. {
  161. if (g_TextLib.lpMsgBuf != NULL)
  162. {
  163. free(g_TextLib.lpMsgBuf);
  164. g_TextLib.lpMsgBuf = NULL;
  165. }
  166. if (g_TextLib.lpMsgOffset != NULL)
  167. {
  168. free(g_TextLib.lpMsgOffset);
  169. g_TextLib.lpMsgOffset = NULL;
  170. }
  171. if (g_TextLib.lpWordBuf != NULL)
  172. {
  173. free(g_TextLib.lpWordBuf);
  174. g_TextLib.lpWordBuf = NULL;
  175. }
  176. }
  177. LPCSTR
  178. PAL_GetWord(
  179. WORD wNumWord
  180. )
  181. /*++
  182. Purpose:
  183. Get the specified word.
  184. Parameters:
  185. [IN] wNumWord - the number of the requested word.
  186. Return value:
  187. Pointer to the requested word. NULL if not found.
  188. --*/
  189. {
  190. static char buf[WORD_LENGTH + 1];
  191. if (wNumWord >= PAL_ADDITIONAL_WORD_FIRST)
  192. {
  193. return g_rgszAdditionalWords[wNumWord - PAL_ADDITIONAL_WORD_FIRST];
  194. }
  195. if (wNumWord >= g_TextLib.nWords)
  196. {
  197. return NULL;
  198. }
  199. memcpy(buf, &g_TextLib.lpWordBuf[wNumWord * WORD_LENGTH], WORD_LENGTH);
  200. buf[WORD_LENGTH] = '\0';
  201. //
  202. // Remove the trailing spaces
  203. //
  204. trim(buf);
  205. if ((strlen(buf) & 1) != 0 && buf[strlen(buf) - 1] == '1')
  206. {
  207. buf[strlen(buf) - 1] = '\0';
  208. }
  209. return buf;
  210. }
  211. LPCSTR
  212. PAL_GetMsg(
  213. WORD wNumMsg
  214. )
  215. /*++
  216. Purpose:
  217. Get the specified message.
  218. Parameters:
  219. [IN] wNumMsg - the number of the requested message.
  220. Return value:
  221. Pointer to the requested message. NULL if not found.
  222. --*/
  223. {
  224. static char buf[256];
  225. DWORD dwOffset, dwSize;
  226. if (wNumMsg >= g_TextLib.nMsgs)
  227. {
  228. return NULL;
  229. }
  230. dwOffset = SWAP32(g_TextLib.lpMsgOffset[wNumMsg]);
  231. dwSize = SWAP32(g_TextLib.lpMsgOffset[wNumMsg + 1]) - dwOffset;
  232. assert(dwSize < 255);
  233. memcpy(buf, &g_TextLib.lpMsgBuf[dwOffset], dwSize);
  234. buf[dwSize] = '\0';
  235. return buf;
  236. }
  237. VOID
  238. PAL_DrawText(
  239. LPCSTR lpszText,
  240. PAL_POS pos,
  241. BYTE bColor,
  242. BOOL fShadow,
  243. BOOL fUpdate
  244. )
  245. /*++
  246. Purpose:
  247. Draw text on the screen.
  248. Parameters:
  249. [IN] lpszText - the text to be drawn.
  250. [IN] pos - Position of the text.
  251. [IN] bColor - Color of the text.
  252. [IN] fShadow - TRUE if the text is shadowed or not.
  253. [IN] fUpdate - TRUE if update the screen area.
  254. Return value:
  255. None.
  256. --*/
  257. {
  258. SDL_Rect rect, urect;
  259. WORD wChar;
  260. rect.x = PAL_X(pos);
  261. rect.y = PAL_Y(pos);
  262. urect.x = rect.x;
  263. urect.y = rect.y;
  264. urect.h = 16;
  265. urect.w = 0;
  266. while (*lpszText)
  267. {
  268. //
  269. // Draw the character
  270. //
  271. if (*lpszText & 0x80)
  272. {
  273. //
  274. // BIG-5 Chinese Character
  275. //
  276. wChar = SWAP16(((LPBYTE)lpszText)[0] | (((LPBYTE)lpszText)[1] << 8));
  277. if (fShadow)
  278. {
  279. PAL_DrawCharOnSurface(wChar, gpScreen, PAL_XY(rect.x + 1, rect.y + 1), 0);
  280. PAL_DrawCharOnSurface(wChar, gpScreen, PAL_XY(rect.x + 1, rect.y), 0);
  281. }
  282. PAL_DrawCharOnSurface(wChar, gpScreen, PAL_XY(rect.x, rect.y), bColor);
  283. lpszText += 2;
  284. rect.x += 16;
  285. urect.w += 16;
  286. }
  287. else
  288. {
  289. //
  290. // ASCII character
  291. //
  292. if (fShadow)
  293. {
  294. PAL_DrawASCIICharOnSurface(*lpszText, gpScreen, PAL_XY(rect.x + 1, rect.y + 1), 0);
  295. PAL_DrawASCIICharOnSurface(*lpszText, gpScreen, PAL_XY(rect.x + 1, rect.y), 0);
  296. }
  297. PAL_DrawASCIICharOnSurface(*lpszText, gpScreen, PAL_XY(rect.x, rect.y), bColor);
  298. lpszText++;
  299. rect.x += 8;
  300. urect.w += 8;
  301. }
  302. }
  303. //
  304. // Update the screen area
  305. //
  306. if (fUpdate && urect.w > 0)
  307. {
  308. VIDEO_UpdateScreen(&urect);
  309. }
  310. }
  311. VOID
  312. PAL_DialogSetDelayTime(
  313. INT iDelayTime
  314. )
  315. /*++
  316. Purpose:
  317. Set the delay time for dialog.
  318. Parameters:
  319. [IN] iDelayTime - the delay time to be set.
  320. Return value:
  321. None.
  322. --*/
  323. {
  324. g_TextLib.iDelayTime = iDelayTime;
  325. }
  326. VOID
  327. PAL_StartDialog(
  328. BYTE bDialogLocation,
  329. BYTE bFontColor,
  330. INT iNumCharFace,
  331. BOOL fPlayingRNG
  332. )
  333. /*++
  334. Purpose:
  335. Start a new dialog.
  336. Parameters:
  337. [IN] bDialogLocation - the location of the text on the screen.
  338. [IN] bFontColor - the font color of the text.
  339. [IN] iNumCharFace - number of the character face in RGM.MKF.
  340. [IN] fPlayingRNG - whether we are playing a RNG video or not.
  341. Return value:
  342. None.
  343. --*/
  344. {
  345. PAL_LARGE BYTE buf[16384];
  346. SDL_Rect rect;
  347. if (gpGlobals->fInBattle && !g_fUpdatedInBattle)
  348. {
  349. //
  350. // Update the screen in battle, or the graphics may seem messed up
  351. //
  352. VIDEO_UpdateScreen(NULL);
  353. g_fUpdatedInBattle = TRUE;
  354. }
  355. g_TextLib.bIcon = 0;
  356. g_TextLib.posIcon = 0;
  357. g_TextLib.nCurrentDialogLine = 0;
  358. g_TextLib.posDialogTitle = PAL_XY(12, 8);
  359. g_TextLib.fUserSkip = FALSE;
  360. if (bFontColor != 0)
  361. {
  362. g_TextLib.bCurrentFontColor = bFontColor;
  363. }
  364. if (fPlayingRNG && iNumCharFace)
  365. {
  366. VIDEO_BackupScreen();
  367. g_TextLib.fPlayingRNG = TRUE;
  368. }
  369. switch (bDialogLocation)
  370. {
  371. case kDialogUpper:
  372. if (iNumCharFace > 0)
  373. {
  374. //
  375. // Display the character face at the upper part of the screen
  376. //
  377. if (PAL_MKFReadChunk(buf, 16384, iNumCharFace, gpGlobals->f.fpRGM) > 0)
  378. {
  379. rect.w = PAL_RLEGetWidth((LPCBITMAPRLE)buf);
  380. rect.h = PAL_RLEGetHeight((LPCBITMAPRLE)buf);
  381. rect.x = 48 - rect.w / 2;
  382. rect.y = 55 - rect.h / 2;
  383. if (rect.x < 0)
  384. {
  385. rect.x = 0;
  386. }
  387. if (rect.y < 0)
  388. {
  389. rect.y = 0;
  390. }
  391. PAL_RLEBlitToSurface((LPCBITMAPRLE)buf, gpScreen, PAL_XY(rect.x, rect.y));
  392. if (rect.x < 0)
  393. {
  394. rect.x = 0;
  395. }
  396. if (rect.y < 0)
  397. {
  398. rect.y = 0;
  399. }
  400. VIDEO_UpdateScreen(&rect);
  401. }
  402. }
  403. g_TextLib.posDialogTitle = PAL_XY(iNumCharFace > 0 ? 80 : 12, 8);
  404. g_TextLib.posDialogText = PAL_XY(iNumCharFace > 0 ? 96 : 44, 26);
  405. break;
  406. case kDialogCenter:
  407. g_TextLib.posDialogText = PAL_XY(80, 40);
  408. break;
  409. case kDialogLower:
  410. if (iNumCharFace > 0)
  411. {
  412. //
  413. // Display the character face at the lower part of the screen
  414. //
  415. if (PAL_MKFReadChunk(buf, 16384, iNumCharFace, gpGlobals->f.fpRGM) > 0)
  416. {
  417. rect.x = 270 - PAL_RLEGetWidth((LPCBITMAPRLE)buf) / 2;
  418. rect.y = 144 - PAL_RLEGetHeight((LPCBITMAPRLE)buf) / 2;
  419. PAL_RLEBlitToSurface((LPCBITMAPRLE)buf, gpScreen, PAL_XY(rect.x, rect.y));
  420. VIDEO_UpdateScreen(NULL);
  421. }
  422. }
  423. g_TextLib.posDialogTitle = PAL_XY(iNumCharFace > 0 ? 4 : 12, 108);
  424. g_TextLib.posDialogText = PAL_XY(iNumCharFace > 0 ? 20 : 44, 126);
  425. break;
  426. case kDialogCenterWindow:
  427. g_TextLib.posDialogText = PAL_XY(160, 40);
  428. break;
  429. }
  430. g_TextLib.bDialogPosition = bDialogLocation;
  431. }
  432. static VOID
  433. PAL_DialogWaitForKey(
  434. VOID
  435. )
  436. /*++
  437. Purpose:
  438. Wait for player to press a key after showing a dialog.
  439. Parameters:
  440. None.
  441. Return value:
  442. None.
  443. --*/
  444. {
  445. PAL_LARGE SDL_Color palette[256];
  446. SDL_Color *pCurrentPalette, t;
  447. int i;
  448. //
  449. // get the current palette
  450. //
  451. pCurrentPalette = PAL_GetPalette(gpGlobals->wNumPalette, gpGlobals->fNightPalette);
  452. memcpy(palette, pCurrentPalette, sizeof(palette));
  453. if (g_TextLib.bDialogPosition != kDialogCenterWindow &&
  454. g_TextLib.bDialogPosition != kDialogCenter)
  455. {
  456. //
  457. // show the icon
  458. //
  459. LPCBITMAPRLE p = PAL_SpriteGetFrame(g_TextLib.bufDialogIcons, g_TextLib.bIcon);
  460. if (p != NULL)
  461. {
  462. SDL_Rect rect;
  463. rect.x = PAL_X(g_TextLib.posIcon);
  464. rect.y = PAL_Y(g_TextLib.posIcon);
  465. rect.w = 16;
  466. rect.h = 16;
  467. PAL_RLEBlitToSurface(p, gpScreen, g_TextLib.posIcon);
  468. VIDEO_UpdateScreen(&rect);
  469. }
  470. }
  471. PAL_ClearKeyState();
  472. while (TRUE)
  473. {
  474. UTIL_Delay(100);
  475. if (g_TextLib.bDialogPosition != kDialogCenterWindow &&
  476. g_TextLib.bDialogPosition != kDialogCenter)
  477. {
  478. //
  479. // palette shift
  480. //
  481. t = palette[0xF9];
  482. for (i = 0xF9; i < 0xFE; i++)
  483. {
  484. palette[i] = palette[i + 1];
  485. }
  486. palette[0xFE] = t;
  487. VIDEO_SetPalette(palette);
  488. }
  489. if (g_InputState.dwKeyPress != 0)
  490. {
  491. break;
  492. }
  493. }
  494. if (g_TextLib.bDialogPosition != kDialogCenterWindow &&
  495. g_TextLib.bDialogPosition != kDialogCenter)
  496. {
  497. PAL_SetPalette(gpGlobals->wNumPalette, gpGlobals->fNightPalette);
  498. }
  499. PAL_ClearKeyState();
  500. g_TextLib.fUserSkip = FALSE;
  501. }
  502. VOID
  503. PAL_ShowDialogText(
  504. LPCSTR lpszText
  505. )
  506. /*++
  507. Purpose:
  508. Show one line of the dialog text.
  509. Parameters:
  510. [IN] lpszText - the text to be shown.
  511. Return value:
  512. None.
  513. --*/
  514. {
  515. SDL_Rect rect;
  516. int x, y, len = strlen(lpszText);
  517. PAL_ClearKeyState();
  518. g_TextLib.bIcon = 0;
  519. if (gpGlobals->fInBattle && !g_fUpdatedInBattle)
  520. {
  521. //
  522. // Update the screen in battle, or the graphics may seem messed up
  523. //
  524. VIDEO_UpdateScreen(NULL);
  525. g_fUpdatedInBattle = TRUE;
  526. }
  527. if (g_TextLib.nCurrentDialogLine > 3)
  528. {
  529. //
  530. // The rest dialogs should be shown in the next page.
  531. //
  532. PAL_DialogWaitForKey();
  533. g_TextLib.nCurrentDialogLine = 0;
  534. VIDEO_RestoreScreen();
  535. VIDEO_UpdateScreen(NULL);
  536. }
  537. x = PAL_X(g_TextLib.posDialogText);
  538. y = PAL_Y(g_TextLib.posDialogText) + g_TextLib.nCurrentDialogLine * 18;
  539. if (g_TextLib.bDialogPosition == kDialogCenterWindow)
  540. {
  541. //
  542. // The text should be shown in a small window at the center of the screen
  543. //
  544. #ifndef PAL_CLASSIC
  545. if (gpGlobals->fInBattle && g_Battle.BattleResult == kBattleResultOnGoing)
  546. {
  547. PAL_BattleUIShowText(lpszText, 1400);
  548. }
  549. else
  550. #endif
  551. {
  552. PAL_POS pos;
  553. LPBOX lpBox;
  554. //
  555. // Create the window box
  556. //
  557. pos = PAL_XY(PAL_X(g_TextLib.posDialogText) - len * 4, PAL_Y(g_TextLib.posDialogText));
  558. lpBox = PAL_CreateSingleLineBox(pos, (len + 1) / 2, TRUE);
  559. rect.x = PAL_X(pos);
  560. rect.y = PAL_Y(pos);
  561. rect.w = 320 - rect.x * 2 + 32;
  562. rect.h = 64;
  563. //
  564. // Show the text on the screen
  565. //
  566. pos = PAL_XY(PAL_X(pos) + 8 + ((len & 1) << 2), PAL_Y(pos) + 10);
  567. PAL_DrawText(lpszText, pos, 0, FALSE, FALSE);
  568. VIDEO_UpdateScreen(&rect);
  569. PAL_DialogWaitForKey();
  570. //
  571. // Delete the box
  572. //
  573. PAL_DeleteBox(lpBox);
  574. VIDEO_UpdateScreen(&rect);
  575. PAL_EndDialog();
  576. }
  577. }
  578. else
  579. {
  580. if (g_TextLib.nCurrentDialogLine == 0 &&
  581. g_TextLib.bDialogPosition != kDialogCenter &&
  582. (BYTE)lpszText[len - 1] == 0x47 && (BYTE)lpszText[len - 2] == 0xA1)
  583. {
  584. //
  585. // name of character
  586. //
  587. PAL_DrawText(lpszText, g_TextLib.posDialogTitle, FONT_COLOR_CYAN_ALT, TRUE, TRUE);
  588. }
  589. else
  590. {
  591. //
  592. // normal texts
  593. //
  594. char text[3];
  595. if (!g_TextLib.fPlayingRNG && g_TextLib.nCurrentDialogLine == 0)
  596. {
  597. //
  598. // Save the screen before we show the first line of dialog
  599. //
  600. VIDEO_BackupScreen();
  601. }
  602. while (lpszText != NULL && *lpszText != '\0')
  603. {
  604. switch (*lpszText)
  605. {
  606. case '-':
  607. //
  608. // Set the font color to Cyan
  609. //
  610. if (g_TextLib.bCurrentFontColor == FONT_COLOR_CYAN)
  611. {
  612. g_TextLib.bCurrentFontColor = FONT_COLOR_DEFAULT;
  613. }
  614. else
  615. {
  616. g_TextLib.bCurrentFontColor = FONT_COLOR_CYAN;
  617. }
  618. lpszText++;
  619. break;
  620. case '\'':
  621. //
  622. // Set the font color to Red
  623. //
  624. if (g_TextLib.bCurrentFontColor == FONT_COLOR_RED)
  625. {
  626. g_TextLib.bCurrentFontColor = FONT_COLOR_DEFAULT;
  627. }
  628. else
  629. {
  630. g_TextLib.bCurrentFontColor = FONT_COLOR_RED;
  631. }
  632. lpszText++;
  633. break;
  634. case '\"':
  635. //
  636. // Set the font color to Yellow
  637. //
  638. if (g_TextLib.bCurrentFontColor == FONT_COLOR_YELLOW)
  639. {
  640. g_TextLib.bCurrentFontColor = FONT_COLOR_DEFAULT;
  641. }
  642. else
  643. {
  644. g_TextLib.bCurrentFontColor = FONT_COLOR_YELLOW;
  645. }
  646. lpszText++;
  647. break;
  648. case '$':
  649. //
  650. // Set the delay time of text-displaying
  651. //
  652. g_TextLib.iDelayTime = atoi(lpszText + 1) * 10 / 7;
  653. lpszText += 3;
  654. break;
  655. case '~':
  656. //
  657. // Delay for a period and quit
  658. //
  659. UTIL_Delay(atoi(lpszText + 1) * 80 / 7);
  660. g_TextLib.nCurrentDialogLine = 0;
  661. g_TextLib.fUserSkip = FALSE;
  662. return; // don't go further
  663. case ')':
  664. //
  665. // Set the waiting icon
  666. //
  667. g_TextLib.bIcon = 1;
  668. lpszText++;
  669. break;
  670. case '(':
  671. //
  672. // Set the waiting icon
  673. //
  674. g_TextLib.bIcon = 2;
  675. lpszText++;
  676. break;
  677. case '\\':
  678. lpszText++;
  679. default:
  680. if (*lpszText & 0x80)
  681. {
  682. text[0] = lpszText[0];
  683. text[1] = lpszText[1];
  684. text[2] = '\0';
  685. lpszText += 2;
  686. }
  687. else
  688. {
  689. text[0] = *lpszText;
  690. text[1] = '\0';
  691. lpszText++;
  692. }
  693. PAL_DrawText(text, PAL_XY(x, y), g_TextLib.bCurrentFontColor, TRUE, TRUE);
  694. x += ((text[0] & 0x80) ? 16 : 8);
  695. if (!g_TextLib.fUserSkip)
  696. {
  697. PAL_ClearKeyState();
  698. UTIL_Delay(g_TextLib.iDelayTime * 8);
  699. if (g_InputState.dwKeyPress & (kKeySearch | kKeyMenu))
  700. {
  701. //
  702. // User pressed a key to skip the dialog
  703. //
  704. g_TextLib.fUserSkip = TRUE;
  705. }
  706. }
  707. }
  708. }
  709. g_TextLib.posIcon = PAL_XY(x, y);
  710. g_TextLib.nCurrentDialogLine++;
  711. }
  712. }
  713. }
  714. VOID
  715. PAL_ClearDialog(
  716. BOOL fWaitForKey
  717. )
  718. /*++
  719. Purpose:
  720. Clear the state of the dialog.
  721. Parameters:
  722. [IN] fWaitForKey - whether wait for any key or not.
  723. Return value:
  724. None.
  725. --*/
  726. {
  727. if (g_TextLib.nCurrentDialogLine > 0 && fWaitForKey)
  728. {
  729. PAL_DialogWaitForKey();
  730. }
  731. g_TextLib.nCurrentDialogLine = 0;
  732. if (g_TextLib.bDialogPosition == kDialogCenter)
  733. {
  734. g_TextLib.posDialogTitle = PAL_XY(12, 8);
  735. g_TextLib.posDialogText = PAL_XY(44, 26);
  736. g_TextLib.bCurrentFontColor = FONT_COLOR_DEFAULT;
  737. g_TextLib.bDialogPosition = kDialogUpper;
  738. }
  739. }
  740. VOID
  741. PAL_EndDialog(
  742. VOID
  743. )
  744. /*++
  745. Purpose:
  746. Ends a dialog.
  747. Parameters:
  748. None.
  749. Return value:
  750. None.
  751. --*/
  752. {
  753. PAL_ClearDialog(TRUE);
  754. //
  755. // Set some default parameters, as there are some parts of script
  756. // which doesn't have a "start dialog" instruction before showing the dialog.
  757. //
  758. g_TextLib.posDialogTitle = PAL_XY(12, 8);
  759. g_TextLib.posDialogText = PAL_XY(44, 26);
  760. g_TextLib.bCurrentFontColor = FONT_COLOR_DEFAULT;
  761. g_TextLib.bDialogPosition = kDialogUpper;
  762. g_TextLib.fUserSkip = FALSE;
  763. g_TextLib.fPlayingRNG = FALSE;
  764. }
  765. BOOL
  766. PAL_IsInDialog(
  767. VOID
  768. )
  769. /*++
  770. Purpose:
  771. Check if there are dialog texts on the screen.
  772. Parameters:
  773. None.
  774. Return value:
  775. TRUE if there are dialog texts on the screen, FALSE if not.
  776. --*/
  777. {
  778. return (g_TextLib.nCurrentDialogLine != 0);
  779. }
  780. BOOL
  781. PAL_DialogIsPlayingRNG(
  782. VOID
  783. )
  784. /*++
  785. Purpose:
  786. Check if the script used the RNG playing parameter when displaying texts.
  787. Parameters:
  788. None.
  789. Return value:
  790. TRUE if the script used the RNG playing parameter, FALSE if not.
  791. --*/
  792. {
  793. return g_TextLib.fPlayingRNG;
  794. }