|
@@ -26,10 +26,6 @@
|
|
|
|
|
|
#include "main.h"
|
|
|
|
|
|
-#ifndef PAL_UNICODE
|
|
|
-#define WORD_LENGTH 10
|
|
|
-#endif
|
|
|
-
|
|
|
#define FONT_COLOR_DEFAULT 0x4F
|
|
|
#define FONT_COLOR_YELLOW 0x2D
|
|
|
#define FONT_COLOR_RED 0x1A
|
|
@@ -38,7 +34,6 @@
|
|
|
|
|
|
BOOL g_fUpdatedInBattle = FALSE;
|
|
|
|
|
|
-#ifdef PAL_UNICODE
|
|
|
#define INCLUDE_CODEPAGE_H
|
|
|
#include "codepage.h"
|
|
|
|
|
@@ -48,27 +43,11 @@ static const WCHAR* gc_rgszAdditionalWords[CP_MAX][6] = {
|
|
|
{ L"\x6226\x95D8\x901F\x5EA6", L"\x4E00", L"\x4E8C", L"\x4E09", L"\x56DB", L"\x4E94" },
|
|
|
};
|
|
|
static const WCHAR** g_rgszAdditionalWords;
|
|
|
-#else
|
|
|
-static const char g_rgszAdditionalWords[][WORD_LENGTH + 1] = {
|
|
|
- {0xBE, 0xD4, 0xB0, 0xAB, 0xB3, 0x74, 0xAB, 0xD7, 0x00, 0x00, 0x00},
|
|
|
- {0xA4, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
- {0xA4, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
- {0xA4, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
- {0xA5, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
- {0xA4, 0xAD, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
-};
|
|
|
-#endif
|
|
|
|
|
|
typedef struct tagTEXTLIB
|
|
|
{
|
|
|
-#ifdef PAL_UNICODE
|
|
|
LPWSTR* lpWordBuf;
|
|
|
LPWSTR* lpMsgBuf;
|
|
|
-#else
|
|
|
- LPBYTE lpWordBuf;
|
|
|
- LPBYTE lpMsgBuf;
|
|
|
- LPDWORD lpMsgOffset;
|
|
|
-#endif
|
|
|
|
|
|
int nWords;
|
|
|
int nMsgs;
|
|
@@ -110,12 +89,10 @@ PAL_InitText(
|
|
|
--*/
|
|
|
{
|
|
|
FILE *fpMsg, *fpWord;
|
|
|
-#ifdef PAL_UNICODE
|
|
|
DWORD *offsets;
|
|
|
LPBYTE temp;
|
|
|
LPWSTR tmp;
|
|
|
int wlen, wpos;
|
|
|
-#endif
|
|
|
int i;
|
|
|
|
|
|
|
|
@@ -130,46 +107,29 @@ PAL_InitText(
|
|
|
fseek(fpWord, 0, SEEK_END);
|
|
|
i = ftell(fpWord);
|
|
|
|
|
|
-#ifdef PAL_UNICODE
|
|
|
|
|
|
|
|
|
|
|
|
g_TextLib.nWords = (i + (gpGlobals->dwWordLength - 1)) / gpGlobals->dwWordLength;
|
|
|
-#else
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- g_TextLib.nWords = (i + (WORD_LENGTH - 1)) / WORD_LENGTH;
|
|
|
-#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-#ifdef PAL_UNICODE
|
|
|
temp = (LPBYTE)malloc(i);
|
|
|
if (temp == NULL)
|
|
|
-#else
|
|
|
- g_TextLib.lpWordBuf = (LPBYTE)malloc(i);
|
|
|
- if (g_TextLib.lpWordBuf == NULL)
|
|
|
-#endif
|
|
|
{
|
|
|
fclose(fpWord);
|
|
|
fclose(fpMsg);
|
|
|
return -1;
|
|
|
}
|
|
|
fseek(fpWord, 0, SEEK_SET);
|
|
|
-#ifdef PAL_UNICODE
|
|
|
fread(temp, i, 1, fpWord);
|
|
|
-#else
|
|
|
- fread(g_TextLib.lpWordBuf, i, 1, fpWord);
|
|
|
-#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fclose(fpWord);
|
|
|
|
|
|
-#ifdef PAL_UNICODE
|
|
|
|
|
|
for (i = 0, wlen = 0; i < g_TextLib.nWords; i++)
|
|
|
{
|
|
@@ -191,7 +151,6 @@ PAL_InitText(
|
|
|
wpos += l + 1;
|
|
|
}
|
|
|
free(temp);
|
|
|
-#endif
|
|
|
|
|
|
|
|
|
|
|
@@ -199,25 +158,15 @@ PAL_InitText(
|
|
|
i = PAL_MKFGetChunkSize(3, gpGlobals->f.fpSSS) / sizeof(DWORD);
|
|
|
g_TextLib.nMsgs = i - 1;
|
|
|
|
|
|
-#ifdef PAL_UNICODE
|
|
|
offsets = (LPDWORD)malloc(i * sizeof(DWORD));
|
|
|
if (offsets == NULL)
|
|
|
-#else
|
|
|
- g_TextLib.lpMsgOffset = (LPDWORD)malloc(i * sizeof(DWORD));
|
|
|
- if (g_TextLib.lpMsgOffset == NULL)
|
|
|
-#endif
|
|
|
{
|
|
|
free(g_TextLib.lpWordBuf);
|
|
|
fclose(fpMsg);
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
-#ifdef PAL_UNICODE
|
|
|
PAL_MKFReadChunk((LPBYTE)(offsets), i * sizeof(DWORD), 3, gpGlobals->f.fpSSS);
|
|
|
-#else
|
|
|
- PAL_MKFReadChunk((LPBYTE)(g_TextLib.lpMsgOffset), i * sizeof(DWORD), 3,
|
|
|
- gpGlobals->f.fpSSS);
|
|
|
-#endif
|
|
|
|
|
|
|
|
|
|
|
@@ -225,35 +174,21 @@ PAL_InitText(
|
|
|
fseek(fpMsg, 0, SEEK_END);
|
|
|
i = ftell(fpMsg);
|
|
|
|
|
|
-#ifdef PAL_UNICODE
|
|
|
temp = (LPBYTE)malloc(i);
|
|
|
if (temp == NULL)
|
|
|
-#else
|
|
|
- g_TextLib.lpMsgBuf = (LPBYTE)malloc(i);
|
|
|
- if (g_TextLib.lpMsgBuf == NULL)
|
|
|
-#endif
|
|
|
{
|
|
|
-#ifdef PAL_UNICODE
|
|
|
free(offsets);
|
|
|
free(g_TextLib.lpWordBuf[0]);
|
|
|
-#else
|
|
|
- free(g_TextLib.lpMsgOffset);
|
|
|
-#endif
|
|
|
free(g_TextLib.lpWordBuf);
|
|
|
fclose(fpMsg);
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
fseek(fpMsg, 0, SEEK_SET);
|
|
|
-#ifdef PAL_UNICODE
|
|
|
fread(temp, 1, i, fpMsg);
|
|
|
-#else
|
|
|
- fread(g_TextLib.lpMsgBuf, 1, i, fpMsg);
|
|
|
-#endif
|
|
|
|
|
|
fclose(fpMsg);
|
|
|
|
|
|
-#ifdef PAL_UNICODE
|
|
|
|
|
|
for (i = 0, wlen = 0; i < g_TextLib.nMsgs; i++)
|
|
|
{
|
|
@@ -273,7 +208,6 @@ PAL_InitText(
|
|
|
free(offsets);
|
|
|
|
|
|
g_rgszAdditionalWords = gc_rgszAdditionalWords[gpGlobals->iCodePage];
|
|
|
-#endif
|
|
|
|
|
|
g_TextLib.bCurrentFontColor = FONT_COLOR_DEFAULT;
|
|
|
g_TextLib.bIcon = 0;
|
|
@@ -311,34 +245,19 @@ PAL_FreeText(
|
|
|
{
|
|
|
if (g_TextLib.lpMsgBuf != NULL)
|
|
|
{
|
|
|
-# ifdef PAL_UNICODE
|
|
|
free(g_TextLib.lpMsgBuf[0]);
|
|
|
-# endif
|
|
|
free(g_TextLib.lpMsgBuf);
|
|
|
g_TextLib.lpMsgBuf = NULL;
|
|
|
}
|
|
|
-#ifndef PAL_UNICODE
|
|
|
- if (g_TextLib.lpMsgOffset != NULL)
|
|
|
- {
|
|
|
- free(g_TextLib.lpMsgOffset);
|
|
|
- g_TextLib.lpMsgOffset = NULL;
|
|
|
- }
|
|
|
-#endif
|
|
|
if (g_TextLib.lpWordBuf != NULL)
|
|
|
{
|
|
|
-# ifdef PAL_UNICODE
|
|
|
free(g_TextLib.lpWordBuf[0]);
|
|
|
-# endif
|
|
|
free(g_TextLib.lpWordBuf);
|
|
|
g_TextLib.lpWordBuf = NULL;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-#ifdef PAL_UNICODE
|
|
|
LPCWSTR
|
|
|
-#else
|
|
|
-LPCSTR
|
|
|
-#endif
|
|
|
PAL_GetWord(
|
|
|
WORD wNumWord
|
|
|
)
|
|
@@ -357,10 +276,6 @@ PAL_GetWord(
|
|
|
|
|
|
--*/
|
|
|
{
|
|
|
-#ifndef PAL_UNICODE
|
|
|
- static char buf[WORD_LENGTH + 1];
|
|
|
-#endif
|
|
|
-
|
|
|
if (wNumWord >= PAL_ADDITIONAL_WORD_FIRST)
|
|
|
{
|
|
|
return g_rgszAdditionalWords[wNumWord - PAL_ADDITIONAL_WORD_FIRST];
|
|
@@ -371,31 +286,10 @@ PAL_GetWord(
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
-#ifdef PAL_UNICODE
|
|
|
return g_TextLib.lpWordBuf[wNumWord];
|
|
|
-#else
|
|
|
- memcpy(buf, &g_TextLib.lpWordBuf[wNumWord * WORD_LENGTH], WORD_LENGTH);
|
|
|
- buf[WORD_LENGTH] = '\0';
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- trim(buf);
|
|
|
-
|
|
|
- if ((strlen(buf) & 1) != 0 && buf[strlen(buf) - 1] == '1')
|
|
|
- {
|
|
|
- buf[strlen(buf) - 1] = '\0';
|
|
|
- }
|
|
|
-
|
|
|
- return buf;
|
|
|
-#endif
|
|
|
}
|
|
|
|
|
|
-#ifdef PAL_UNICODE
|
|
|
LPCWSTR
|
|
|
-#else
|
|
|
-LPCSTR
|
|
|
-#endif
|
|
|
PAL_GetMsg(
|
|
|
WORD wNumMsg
|
|
|
)
|
|
@@ -414,35 +308,12 @@ PAL_GetMsg(
|
|
|
|
|
|
--*/
|
|
|
{
|
|
|
-#ifdef PAL_UNICODE
|
|
|
- return (wNumMsg >= g_TextLib.nMsgs) ? NULL : g_TextLib.lpMsgBuf[wNumMsg];
|
|
|
-#else
|
|
|
- static char buf[256];
|
|
|
- DWORD dwOffset, dwSize;
|
|
|
-
|
|
|
- if (wNumMsg >= g_TextLib.nMsgs)
|
|
|
- {
|
|
|
- return NULL;
|
|
|
- }
|
|
|
-
|
|
|
- dwOffset = SWAP32(g_TextLib.lpMsgOffset[wNumMsg]);
|
|
|
- dwSize = SWAP32(g_TextLib.lpMsgOffset[wNumMsg + 1]) - dwOffset;
|
|
|
- assert(dwSize < 255);
|
|
|
-
|
|
|
- memcpy(buf, &g_TextLib.lpMsgBuf[dwOffset], dwSize);
|
|
|
- buf[dwSize] = '\0';
|
|
|
-
|
|
|
- return buf;
|
|
|
-#endif
|
|
|
+ return (wNumMsg >= g_TextLib.nMsgs) ? NULL : g_TextLib.lpMsgBuf[wNumMsg];
|
|
|
}
|
|
|
|
|
|
VOID
|
|
|
PAL_DrawText(
|
|
|
-#ifdef PAL_UNICODE
|
|
|
LPCWSTR lpszText,
|
|
|
-#else
|
|
|
- LPCSTR lpszText,
|
|
|
-#endif
|
|
|
PAL_POS pos,
|
|
|
BYTE bColor,
|
|
|
BOOL fShadow,
|
|
@@ -472,20 +343,13 @@ PAL_DrawText(
|
|
|
--*/
|
|
|
{
|
|
|
SDL_Rect rect, urect;
|
|
|
-#ifndef PAL_UNICODE
|
|
|
- WORD wChar;
|
|
|
-#endif
|
|
|
|
|
|
rect.x = PAL_X(pos);
|
|
|
rect.y = PAL_Y(pos);
|
|
|
|
|
|
urect.x = rect.x;
|
|
|
urect.y = rect.y;
|
|
|
-#if defined(PAL_UNICODE)
|
|
|
- urect.h = 17;
|
|
|
-#else
|
|
|
- urect.h = 16;
|
|
|
-#endif
|
|
|
+ urect.h = gpGlobals->fUseEmbeddedFonts ? 16 : 17;
|
|
|
urect.w = 0;
|
|
|
|
|
|
while (*lpszText)
|
|
@@ -493,7 +357,6 @@ PAL_DrawText(
|
|
|
|
|
|
|
|
|
|
|
|
-# ifdef PAL_UNICODE
|
|
|
int char_width = PAL_CharWidth(*lpszText);
|
|
|
|
|
|
if (fShadow)
|
|
@@ -505,39 +368,6 @@ PAL_DrawText(
|
|
|
lpszText++;
|
|
|
rect.x += char_width;
|
|
|
urect.w += char_width;
|
|
|
-# else
|
|
|
- if (*lpszText & 0x80)
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- wChar = SWAP16(((LPBYTE)lpszText)[0] | (((LPBYTE)lpszText)[1] << 8));
|
|
|
- if (fShadow)
|
|
|
- {
|
|
|
- PAL_DrawCharOnSurface(wChar, gpScreen, PAL_XY(rect.x + 1, rect.y + 1), 0);
|
|
|
- PAL_DrawCharOnSurface(wChar, gpScreen, PAL_XY(rect.x + 1, rect.y), 0);
|
|
|
- }
|
|
|
- PAL_DrawCharOnSurface(wChar, gpScreen, PAL_XY(rect.x, rect.y), bColor);
|
|
|
- lpszText += 2;
|
|
|
- rect.x += 16;
|
|
|
- urect.w += 16;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (fShadow)
|
|
|
- {
|
|
|
- PAL_DrawASCIICharOnSurface(*lpszText, gpScreen, PAL_XY(rect.x + 1, rect.y + 1), 0);
|
|
|
- PAL_DrawASCIICharOnSurface(*lpszText, gpScreen, PAL_XY(rect.x + 1, rect.y), 0);
|
|
|
- }
|
|
|
- PAL_DrawASCIICharOnSurface(*lpszText, gpScreen, PAL_XY(rect.x, rect.y), bColor);
|
|
|
- lpszText++;
|
|
|
- rect.x += 8;
|
|
|
- urect.w += 8;
|
|
|
- }
|
|
|
-# endif
|
|
|
}
|
|
|
|
|
|
|
|
@@ -802,11 +632,7 @@ PAL_DialogWaitForKey(
|
|
|
|
|
|
VOID
|
|
|
PAL_ShowDialogText(
|
|
|
-#ifdef PAL_UNICODE
|
|
|
LPCWSTR lpszText
|
|
|
-#else
|
|
|
- LPCSTR lpszText
|
|
|
-#endif
|
|
|
)
|
|
|
|
|
|
Purpose:
|
|
@@ -824,11 +650,7 @@ PAL_ShowDialogText(
|
|
|
--*/
|
|
|
{
|
|
|
SDL_Rect rect;
|
|
|
-#ifdef PAL_UNICODE
|
|
|
int x, y;
|
|
|
-#else
|
|
|
- int x, y, len = strlen(lpszText);
|
|
|
-#endif
|
|
|
|
|
|
PAL_ClearKeyState();
|
|
|
g_TextLib.bIcon = 0;
|
|
@@ -871,12 +693,10 @@ PAL_ShowDialogText(
|
|
|
{
|
|
|
PAL_POS pos;
|
|
|
LPBOX lpBox;
|
|
|
-# ifdef PAL_UNICODE
|
|
|
int i, w = wcslen(lpszText), len = 0;
|
|
|
|
|
|
for (i = 0; i < w; i++)
|
|
|
len += PAL_CharWidth(lpszText[i]) >> 3;
|
|
|
-# endif
|
|
|
|
|
|
|
|
|
|
|
@@ -908,18 +728,10 @@ PAL_ShowDialogText(
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
-# ifdef PAL_UNICODE
|
|
|
int len = wcslen(lpszText);
|
|
|
-# endif
|
|
|
if (g_TextLib.nCurrentDialogLine == 0 &&
|
|
|
g_TextLib.bDialogPosition != kDialogCenter &&
|
|
|
-# ifdef PAL_UNICODE
|
|
|
(lpszText[len - 1] == 0xff1a ||
|
|
|
-# else
|
|
|
- (((BYTE)lpszText[len - 1] == 0x47 && (BYTE)lpszText[len - 2] == 0xA1) ||
|
|
|
- ((BYTE)lpszText[len - 1] == 0xBA && (BYTE)lpszText[len - 2] == 0xA3) ||
|
|
|
- ((BYTE)lpszText[len - 1] == 0xC3 && (BYTE)lpszText[len - 2] == 0xA1) ||
|
|
|
-# endif
|
|
|
lpszText[len - 1] == ':'))
|
|
|
{
|
|
|
|
|
@@ -932,11 +744,7 @@ PAL_ShowDialogText(
|
|
|
|
|
|
|
|
|
|
|
|
-# ifdef PAL_UNICODE
|
|
|
WCHAR text[2];
|
|
|
-# else
|
|
|
- char text[3];
|
|
|
-# endif
|
|
|
|
|
|
if (!g_TextLib.fPlayingRNG && g_TextLib.nCurrentDialogLine == 0)
|
|
|
{
|
|
@@ -998,11 +806,7 @@ PAL_ShowDialogText(
|
|
|
|
|
|
|
|
|
|
|
|
-# ifdef PAL_UNICODE
|
|
|
g_TextLib.iDelayTime = wcstol(lpszText + 1, NULL, 10) * 10 / 7;
|
|
|
-# else
|
|
|
- g_TextLib.iDelayTime = atoi(lpszText + 1) * 10 / 7;
|
|
|
-# endif
|
|
|
lpszText += 3;
|
|
|
break;
|
|
|
|
|
@@ -1010,11 +814,7 @@ PAL_ShowDialogText(
|
|
|
|
|
|
|
|
|
|
|
|
-# ifdef PAL_UNICODE
|
|
|
UTIL_Delay(wcstol(lpszText + 1, NULL, 10) * 80 / 7);
|
|
|
-# else
|
|
|
- UTIL_Delay(atoi(lpszText + 1) * 80 / 7);
|
|
|
-# endif
|
|
|
g_TextLib.nCurrentDialogLine = 0;
|
|
|
g_TextLib.fUserSkip = FALSE;
|
|
|
return;
|
|
@@ -1039,31 +839,11 @@ PAL_ShowDialogText(
|
|
|
lpszText++;
|
|
|
|
|
|
default:
|
|
|
-# ifdef PAL_UNICODE
|
|
|
text[0] = *lpszText++;
|
|
|
text[1] = 0;
|
|
|
-# else
|
|
|
- if (*lpszText & 0x80)
|
|
|
- {
|
|
|
- text[0] = lpszText[0];
|
|
|
- text[1] = lpszText[1];
|
|
|
- text[2] = '\0';
|
|
|
- lpszText += 2;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- text[0] = *lpszText;
|
|
|
- text[1] = '\0';
|
|
|
- lpszText++;
|
|
|
- }
|
|
|
-# endif
|
|
|
|
|
|
PAL_DrawText(text, PAL_XY(x, y), g_TextLib.bCurrentFontColor, TRUE, TRUE);
|
|
|
-# ifdef PAL_UNICODE
|
|
|
x += PAL_CharWidth(text[0]);
|
|
|
-# else
|
|
|
- x += ((text[0] & 0x80) ? 16 : 8);
|
|
|
-# endif
|
|
|
|
|
|
if (!g_TextLib.fUserSkip)
|
|
|
{
|
|
@@ -1199,7 +979,6 @@ PAL_DialogIsPlayingRNG(
|
|
|
return g_TextLib.fPlayingRNG;
|
|
|
}
|
|
|
|
|
|
-#ifdef PAL_UNICODE
|
|
|
INT
|
|
|
PAL_MultiByteToWideChar(
|
|
|
LPCSTR mbs,
|
|
@@ -1397,4 +1176,3 @@ PAL_GetInvalidChar(
|
|
|
default: return 0;
|
|
|
}
|
|
|
}
|
|
|
-#endif
|