text.c 21 KB

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