Browse Source

Some fixes for better japanese support

louyihua 9 years ago
parent
commit
6bd2c3e469
10 changed files with 207 additions and 151 deletions
  1. 8 1
      big5font.h
  2. 12 10
      font.c
  3. 2 2
      fontglyph.h
  4. 7 0
      gbfont.h
  5. 40 13
      script.c
  6. 106 0
      ui.c
  7. 17 0
      ui.h
  8. 1 1
      uibattle.c
  9. 14 107
      uigame.c
  10. 0 17
      uigame.h

+ 8 - 1
big5font.h

@@ -1,4 +1,10 @@
-unsigned char big5font[] = {
+#if !defined(PAL_UNICODE) && defined(PAL_WIN95)
+
+#ifndef _FONT_C
+#error "This file should only be included inside font.c!"
+#endif
+
+static unsigned char big5font[] = {
 	0xb0, 0x34, 0x07, 0x00, 0x10, 0x10, 0xa4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
@@ -29516,3 +29522,4 @@ unsigned char big5font[] = {
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
 };
+#endif

+ 12 - 10
font.c

@@ -24,6 +24,8 @@
 #include "font.h"
 #include "util.h"
 
+#define _FONT_C
+
 #if defined(PAL_UNICODE)
 
 #include "fontglyph.h"
@@ -262,7 +264,7 @@ BOOL fIsBig5 = FALSE;
 
 INT
 PAL_InitFont(
-VOID
+   VOID
 )
 /*++
 Purpose:
@@ -299,7 +301,7 @@ Return value:
 
 VOID
 PAL_FreeFont(
-VOID
+   VOID
 )
 /*++
 Purpose:
@@ -329,10 +331,10 @@ static BOOL is_gb(unsigned char b1, unsigned char b2)
 
 VOID
 PAL_DrawCharOnSurface(
-WORD                     wChar,
-SDL_Surface             *lpSurface,
-PAL_POS                  pos,
-BYTE                     bColor
+   WORD                     wChar,
+   SDL_Surface             *lpSurface,
+   PAL_POS                  pos,
+   BYTE                     bColor
 )
 /*++
 Purpose:
@@ -426,10 +428,10 @@ None.
 
 VOID
 PAL_DrawASCIICharOnSurface(
-BYTE                     bChar,
-SDL_Surface             *lpSurface,
-PAL_POS                  pos,
-BYTE                     bColor
+   BYTE                     bChar,
+   SDL_Surface             *lpSurface,
+   PAL_POS                  pos,
+   BYTE                     bColor
 )
 /*++
 Purpose:

+ 2 - 2
fontglyph.h

@@ -23,8 +23,8 @@
 #ifndef _FONTGLYPH_H
 #define _FONTGLYPH_H
 
-#ifndef FONT_H
-#error "This file should only be included after font.h!"
+#ifndef _FONT_C
+#error "This file should only be included inside font.c!"
 #endif
 
 #ifdef __cplusplus

+ 7 - 0
gbfont.h

@@ -24,6 +24,12 @@
  * SUCH DAMAGE.
  *
  */
+#if !defined(PAL_UNICODE) && defined(PAL_WIN95)
+
+#ifndef _FONT_C
+#error "This file should only be included inside font.c!"
+#endif
+
 unsigned char gbfont[] = {
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
@@ -17698,3 +17704,4 @@ unsigned char gbfont[] = {
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
 };
+#endif

+ 40 - 13
script.c

@@ -519,15 +519,35 @@ PAL_AdditionalCredits(
 --*/
 {
 #ifdef PAL_UNICODE
+   LPCWSTR rgszcps[][CP_MAX] = {
+	   // Traditional Chinese, Simplified Chinese, Japanese
+	   { L"", L"", L"" },
+	   { L"        (\x7D93\x5178\x7279\x5225\x7BC7", L"        (\x7ECF\x5178\x7279\x522B\x7BC7", L"(\x53E4\x5178\x7684\x306A\x30D0\x30FC\x30B8\x30E7\x30F3" },
+	   { L"", L"", L"" },
+	   { L"", L"", L"" },
+	   { L"", L"", L"" },
+#if defined(__SYMBIAN32__) || defined(GPH) || defined(GEKKO) || defined(DINGOO) || defined(ANDROID)
+	   { L"", L"", L"" },
+#endif
+	   { L"", L"", L"" },
+	   { L"\x672C\x7A0B\x5F0F\x662F\x81EA\x7531\x8EDF\x9AD4\xFF0C\x6309\x7167 GNU General",
+	     L"\x672C\x7A0B\x5E8F\x662F\x81EA\x7531\x8F6F\x4EF6\xFF0C\x6309\x7167 GNU General",
+		 L"\x3053\x306E\x30D7\x30ED\x30B0\x30E9\x30E0\x306F\x30D5\x30EA\x30FC\x30BD\x30D5\x30C8\x30A6\x30A7\x30A2\x3001"
+	   },
+	   { L"Public License (GPLv3) \x767C\x4F48", L"Public License (GPLv3) \x53D1\x5E03", L"GNU General Public License (GPLv3)\x306E" },
+	   { L"", L"", L"\x4E0B\x3067\x30EA\x30EA\x30FC\x30B9\x3055\x308C\x3066" },
+	   { L"              ...\x6309 Enter \x7D50\x675F", L"              ...\x6309 Enter \x7ED3\x675F", L"...Enter\x30AD\x30FC\x3092\x62BC\x3057\x3066\x7D42\x4E86\x3057\x307E\x3059" }
+   };
+
    LPCWSTR rgszStrings[] = {
       L"SDLPAL (http://sdlpal.codeplex.com/)",
 #  ifdef PAL_CLASSIC
-	  L"         (\x7D93\x5178\x7279\x5225\x7BC7  " WIDETEXT(__DATE__) L")",
+	  L" %s  " WIDETEXT(__DATE__) L")",
 #  else
 	  L"                    (" WIDETEXT(__DATE__) L")",
 #  endif
       L" ",
-	  L"  (c) 2009-2011, Wei Mingzhi",
+	  L"  (c) 2009-2015, Wei Mingzhi",
 	  L"      <whistler_wmz@users.sf.net>.",
 #  ifdef __SYMBIAN32__
 	  L"  Symbian S60 \x79FB\x690D (c) 2009, netwan.",
@@ -545,12 +565,11 @@ PAL_AdditionalCredits(
 	  L"  ANDROID \x79FB\x690D (c) 2013, Rikku2000.",
 #  endif
 	  L" ",
-	  L"\x672C\x7A0B\x5F0F\x662F\x81EA\x7531\x8EDF\x9AD4\xFF0C\x6309\x7167"
-	  L" GNU General",
-	  L"Public License (GPLv3) \x767C\x4F48",
-	  L" ",
-	  L"                 ...\x6309 Enter \x7D50\x675F",
-	  L""
+	  L"%s",
+	  L"%s",
+	  L"%s",
+	  L"   %s",
+      NULL
    };
 #else
    LPCSTR rgszStrings[] = {
@@ -561,7 +580,7 @@ PAL_AdditionalCredits(
       "                    (" __DATE__ ")",
 #  endif
       " ",
-      "  (c) 2009-2014, Wei Mingzhi",
+      "  (c) 2009-2015, Wei Mingzhi",
       "      <whistler_wmz@users.sf.net>.",
 #  ifdef __SYMBIAN32__
       "  Symbian S60 \xB2\xBE\xB4\xD3 (c) 2009, netwan.",
@@ -575,13 +594,16 @@ PAL_AdditionalCredits(
 #  ifdef DINGOO
       "  DINGOO & Dingux \xB2\xBE\xB4\xD3 (c) 2011, Rikku2000.",
 #  endif
-      " ",
+#  ifdef ANDROID
+	  "  ANDROID \xB2\xBE\xB4\xD3 (c) 2013, Rikku2000.",
+#  endif
+	  " ",
       "\xA5\xBB\xB5\x7B\xA6\xA1\xAC\x4F\xA6\xDB\xA5\xD1\xB3\x6E\xC5\xE9\xA1\x41\xAB\xF6\xB7\xD3"
       " GNU General",
       "Public License (GPLv3) \xB5\x6F\xA7\x47",
       " ",
       "                 ...\xAB\xF6 Enter \xB5\xB2\xA7\xF4",
-      ""
+      NULL
    };
 #endif
 
@@ -594,10 +616,15 @@ PAL_AdditionalCredits(
 
    PAL_DrawOpeningMenuBackground();
 
-   while (rgszStrings[i][0] != '\0')
+   for (i = 0; rgszStrings[i]; i++)
    {
+#ifdef PAL_UNICODE
+      WCHAR buffer[50];
+	  swprintf(buffer, 50, rgszStrings[i], rgszcps[i][gpGlobals->iCodePage]);
+	  PAL_DrawText(buffer, PAL_XY(25, 20 + i * 16), DESCTEXT_COLOR, TRUE, FALSE);
+#else
       PAL_DrawText(rgszStrings[i], PAL_XY(25, 20 + i * 16), DESCTEXT_COLOR, TRUE, FALSE);
-      i++;
+#endif
    }
 
    PAL_SetPalette(0, FALSE);

+ 106 - 0
ui.c

@@ -683,6 +683,112 @@ PAL_DrawNumber(
    }
 }
 
+INT
+PAL_MenuTextMaxWidth(
+   LPMENUITEM     rgMenuItem,
+   INT            nMenuItem
+)
+/*++
+  Purpose:
+
+    Calculate the maximal text width of all the menu items in number of full width characters.
+
+  Parameters:
+
+    [IN]  rgMenuItem - Pointer to the menu item array.
+	[IN]  nMenuItem - Number of menu items.
+
+  Return value:
+
+    Maximal text width.
+
+--*/
+{
+	int i, r = 0;
+	for (i = 0; i < nMenuItem; i++)
+	{
+		LPCWSTR itemText = PAL_GetWord(rgMenuItem[i].wNumWord);
+		int j = 0, l = wcslen(itemText), w = 0;
+		for (j = 0; j < l; j++)
+		{
+			w += PAL_CharWidth(itemText[j]);
+		}
+		w = (w + 8) >> 4;
+		if (r < w)
+		{
+			r = w;
+		}
+	}
+	return r;
+}
+
+INT
+PAL_WordMaxWidth(
+   INT            nFirstWord,
+   INT            nWordNum
+)
+/*++
+  Purpose:
+
+    Calculate the maximal text width of a specific range of words in number of full width characters.
+
+  Parameters:
+
+    [IN]  nFirstWord - First index of word.
+	[IN]  nWordNum - Number of words.
+
+  Return value:
+
+    Maximal text width.
+
+--*/
+{
+	int i, r = 0;
+	for (i = 0; i < nWordNum; i++)
+	{
+		LPCWSTR itemText = PAL_GetWord(nFirstWord + i);
+		int j = 0, l = wcslen(itemText), w = 0;
+		for (j = 0; j < l; j++)
+		{
+			w += PAL_CharWidth(itemText[j]);
+		}
+		w = (w + 8) >> 4;
+		if (r < w)
+		{
+			r = w;
+		}
+	}
+	return r;
+}
+
+INT
+PAL_WordWidth(
+   INT            nWordIndex
+)
+/*++
+  Purpose:
+
+    Calculate the text width of a specific word.
+
+  Parameters:
+
+	[IN]  nWordNum - Index of the word.
+
+  Return value:
+
+    Text width.
+
+--*/
+{
+	LPCWSTR itemText = PAL_GetWord(nWordIndex);
+	int i, l = wcslen(itemText), w = 0;
+	for (i = 0; i < l; i++)
+	{
+		w += PAL_CharWidth(itemText[i]);
+	}
+	return (w + 8) >> 4;
+}
+
 #ifndef PAL_WIN95
 
 LPOBJECTDESC

+ 17 - 0
ui.h

@@ -218,6 +218,23 @@ PAL_DrawNumber(
    NUMALIGN        align
 );
 
+INT
+PAL_MenuTextMaxWidth(
+   LPMENUITEM     rgMenuItem,
+   INT            nMenuItem
+);
+
+INT
+PAL_WordMaxWidth(
+   INT            nFirstWord,
+   INT            nWordNum
+);
+
+INT
+PAL_WordWidth(
+   INT            nWordIndex
+);
+
 #ifndef PAL_WIN95
 LPOBJECTDESC
 PAL_LoadObjectDesc(

+ 1 - 1
uibattle.c

@@ -503,7 +503,7 @@ PAL_BattleUIMiscItemSubMenuUpdate(
 #else
    PAL_BattleUIDrawMiscMenu(0, TRUE);
 #endif
-   PAL_CreateBox(PAL_XY(30, 50), 1, 1, 0, FALSE);
+   PAL_CreateBox(PAL_XY(30, 50), 1, PAL_MenuTextMaxWidth(rgMenuItem, 2) - 1, 0, FALSE);
 
    //
    // Draw the menu items

+ 14 - 107
uigame.c

@@ -1163,6 +1163,8 @@ PAL_PlayerStatus(
       //
       for (i = 0; i < MAX_PLAYER_EQUIPMENTS; i++)
       {
+         int offset = 0;
+
          w = gpGlobals->g.PlayerRoles.rgwEquipment[i][iPlayerRole];
 
          if (w == 0)
@@ -1183,8 +1185,19 @@ PAL_PlayerStatus(
          //
          // Draw the text label
          //
+#ifdef PAL_UNICODE
+         offset = PAL_WordWidth(w) * 16;
+         if (rgEquipPos[i][0] + offset + 5 > 320)
+         {
+            offset = 314 - rgEquipPos[i][0] - offset;
+         }
+         else
+         {
+            offset = 0;
+         }
+#endif
          PAL_DrawText(PAL_GetWord(w),
-            PAL_XY(rgEquipPos[i][0] + 5, rgEquipPos[i][1] + 38), STATUS_COLOR_EQUIPMENT, TRUE, FALSE);
+            PAL_XY(rgEquipPos[i][0] + offset + 5, rgEquipPos[i][1] + 38), STATUS_COLOR_EQUIPMENT, TRUE, FALSE);
       }
 
       //
@@ -1927,109 +1940,3 @@ PAL_EquipItemMenu(
       }
    }
 }
-
-INT
-PAL_MenuTextMaxWidth(
-   LPMENUITEM     rgMenuItem,
-   INT            nMenuItem
-)
-/*++
-  Purpose:
-
-    Calculate the maximal text width of all the menu items in number of full width characters.
-
-  Parameters:
-
-    [IN]  rgMenuItem - Pointer to the menu item array.
-	[IN]  nMenuItem - Number of menu items.
-
-  Return value:
-
-    Maximal text width.
-
---*/
-{
-	int i, r = 0;
-	for (i = 0; i < nMenuItem; i++)
-	{
-		LPCWSTR itemText = PAL_GetWord(rgMenuItem[i].wNumWord);
-		int j = 0, l = wcslen(itemText), w = 0;
-		for (j = 0; j < l; j++)
-		{
-			w += PAL_CharWidth(itemText[j]);
-		}
-		w = (w + 8) >> 4;
-		if (r < w)
-		{
-			r = w;
-		}
-	}
-	return r;
-}
-
-INT
-PAL_WordMaxWidth(
-   INT            nFirstWord,
-   INT            nWordNum
-)
-/*++
-  Purpose:
-
-    Calculate the maximal text width of a specific range of words in number of full width characters.
-
-  Parameters:
-
-    [IN]  nFirstWord - First index of word.
-	[IN]  nWordNum - Number of words.
-
-  Return value:
-
-    Maximal text width.
-
---*/
-{
-	int i, r = 0;
-	for (i = 0; i < nWordNum; i++)
-	{
-		LPCWSTR itemText = PAL_GetWord(nFirstWord + i);
-		int j = 0, l = wcslen(itemText), w = 0;
-		for (j = 0; j < l; j++)
-		{
-			w += PAL_CharWidth(itemText[j]);
-		}
-		w = (w + 8) >> 4;
-		if (r < w)
-		{
-			r = w;
-		}
-	}
-	return r;
-}
-
-INT
-PAL_WordWidth(
-   INT            nWordIndex
-)
-/*++
-  Purpose:
-
-    Calculate the text width of a specific word.
-
-  Parameters:
-
-	[IN]  nWordNum - Index of the word.
-
-  Return value:
-
-    Text width.
-
---*/
-{
-	LPCWSTR itemText = PAL_GetWord(nWordIndex);
-	int i, l = wcslen(itemText), w = 0;
-	for (i = 0; i < l; i++)
-	{
-		w += PAL_CharWidth(itemText[i]);
-	}
-	return (w + 8) >> 4;
-}

+ 0 - 17
uigame.h

@@ -91,23 +91,6 @@ PAL_EquipItemMenu(
    WORD           wItem
 );
 
-INT
-PAL_MenuTextMaxWidth(
-   LPMENUITEM     rgMenuItem,
-   INT            nMenuItem
-);
-
-INT
-PAL_WordMaxWidth(
-   INT            nFirstWord,
-   INT            nWordNum
-);
-
-INT
-PAL_WordWidth(
-   INT            nWordIndex
-);
-
 #ifdef __cplusplus
 }
 #endif