Browse Source

Fix japanese item menu

louyihua 9 years ago
parent
commit
4ba4cf325c
7 changed files with 127 additions and 48 deletions
  1. 7 1
      global.c
  2. 1 0
      global.h
  3. 41 17
      itemmenu.c
  4. 40 18
      magicmenu.c
  5. 33 11
      script.c
  6. 4 0
      script.h
  7. 1 1
      sdlpal.vcxproj

+ 7 - 1
global.c

@@ -59,8 +59,9 @@ PAL_InitGlobals(
 {
 #ifdef PAL_UNICODE
    FILE     *fp;
-   CODEPAGE  iCodePage = CP_BIG5;	// Default for PAL DOS
+   CODEPAGE  iCodePage = CP_BIG5;	// Default for PAL DOS/WIN95
    DWORD     dwWordLength = 10;		// Default for PAL DOS/WIN95
+   DWORD     dwExtraDescLines = 0;	// Default for PAL DOS/WIN95
 #endif
 
    if (gpGlobals == NULL)
@@ -113,6 +114,10 @@ PAL_InitGlobals(
 				   {
 					   sscanf(ptr, "%u", &dwWordLength);
 				   }
+				   else if (SDL_strcasecmp(p, "EXTRADESCLINES") == 0)
+				   {
+					   sscanf(ptr, "%u", &dwExtraDescLines);
+				   }
 			   }
 		   }
 	   }
@@ -139,6 +144,7 @@ PAL_InitGlobals(
 #ifdef PAL_UNICODE
    gpGlobals->iCodePage = iCodePage;
    gpGlobals->dwWordLength = dwWordLength;
+   gpGlobals->dwExtraDescLines = dwExtraDescLines;
 #endif
 
    return 0;

+ 1 - 0
global.h

@@ -568,6 +568,7 @@ typedef struct tagGLOBALVARS
 #ifdef PAL_UNICODE
    CODEPAGE         iCodePage;
    DWORD            dwWordLength;
+   DWORD            dwExtraDescLines;
 #endif
 } GLOBALVARS, *LPGLOBALVARS;
 

+ 41 - 17
itemmenu.c

@@ -56,17 +56,34 @@ PAL_ItemSelectMenuUpdate(
    BYTE               bColor;
    static BYTE        bufImage[2048];
    static WORD        wPrevImageIndex = 0xFFFF;
+#ifdef PAL_UNICODE
+   const int          iItemsPerLine = 34 / gpGlobals->dwWordLength;
+   const int          iItemTextWidth = 8 * gpGlobals->dwWordLength + 20;
+   const int          iLinesPerPage = 7 - gpGlobals->dwExtraDescLines;
+   const int          iBoxHeightOffset = gpGlobals->dwExtraDescLines * 16;
+   const int          iCursorXOffset = gpGlobals->dwWordLength * 5 / 2;
+   const int          iAmountXOffset = gpGlobals->dwWordLength * 8 + 1;
+   const int          iPageLineOffset = (iLinesPerPage + 1) / 2;
+#else
+   const int          iItemsPerLine = 3;
+   const int          iItemTextWidth = 100;
+   const int          iLinesPerPage = 7;
+   const int          iBoxHeightOffset = 0;
+   const int          iCursorXOffset = 25;
+   const int          iAmountXOffset = 81;
+   const int          iPageLineOffset = 4;
+#endif
 
    //
    // Process input
    //
    if (g_InputState.dwKeyPress & kKeyUp)
    {
-      gpGlobals->iCurInvMenuItem -= 3;
+      gpGlobals->iCurInvMenuItem -= iItemsPerLine;
    }
    else if (g_InputState.dwKeyPress & kKeyDown)
    {
-      gpGlobals->iCurInvMenuItem += 3;
+      gpGlobals->iCurInvMenuItem += iItemsPerLine;
    }
    else if (g_InputState.dwKeyPress & kKeyLeft)
    {
@@ -78,11 +95,11 @@ PAL_ItemSelectMenuUpdate(
    }
    else if (g_InputState.dwKeyPress & kKeyPgUp)
    {
-      gpGlobals->iCurInvMenuItem -= 3 * 7;
+      gpGlobals->iCurInvMenuItem -= iItemsPerLine * iLinesPerPage;
    }
    else if (g_InputState.dwKeyPress & kKeyPgDn)
    {
-      gpGlobals->iCurInvMenuItem += 3 * 7;
+      gpGlobals->iCurInvMenuItem += iItemsPerLine * iLinesPerPage;
    }
    else if (g_InputState.dwKeyPress & kKeyMenu)
    {
@@ -104,20 +121,20 @@ PAL_ItemSelectMenuUpdate(
    //
    // Redraw the box
    //
-   PAL_CreateBox(PAL_XY(2, 0), 6, 17, 1, FALSE);
+   PAL_CreateBox(PAL_XY(2, 0), iLinesPerPage - 1, 17, 1, FALSE);
 
    //
    // Draw the texts in the current page
    //
-   i = gpGlobals->iCurInvMenuItem / 3 * 3 - 3 * 4;
+   i = gpGlobals->iCurInvMenuItem / iItemsPerLine * iItemsPerLine - iItemsPerLine * iPageLineOffset;
    if (i < 0)
    {
       i = 0;
    }
 
-   for (j = 0; j < 7; j++)
+   for (j = 0; j < iLinesPerPage; j++)
    {
-      for (k = 0; k < 3; k++)
+      for (k = 0; k < iItemsPerLine; k++)
       {
          wObject = gpGlobals->rgInventory[i].wItem;
          bColor = MENUITEM_COLOR;
@@ -127,7 +144,7 @@ PAL_ItemSelectMenuUpdate(
             //
             // End of the list reached
             //
-            j = 7;
+            j = iLinesPerPage;
             break;
          }
 
@@ -172,7 +189,7 @@ PAL_ItemSelectMenuUpdate(
          //
          // Draw the text
          //
-         PAL_DrawText(PAL_GetWord(wObject), PAL_XY(15 + k * 100, 12 + j * 18),
+		 PAL_DrawText(PAL_GetWord(wObject), PAL_XY(15 + k * iItemTextWidth, 12 + j * 18),
             bColor, TRUE, FALSE);
 
          //
@@ -181,7 +198,7 @@ PAL_ItemSelectMenuUpdate(
          if (i == gpGlobals->iCurInvMenuItem)
          {
             PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_CURSOR),
-               gpScreen, PAL_XY(40 + k * 100, 22 + j * 18));
+               gpScreen, PAL_XY(15 + iCursorXOffset + k * iItemTextWidth, 22 + j * 18));
          }
 
          //
@@ -190,7 +207,7 @@ PAL_ItemSelectMenuUpdate(
 		 if ((SHORT)gpGlobals->rgInventory[i].nAmount - (SHORT)gpGlobals->rgInventory[i].nAmountInUse > 1)
 		 {
             PAL_DrawNumber(gpGlobals->rgInventory[i].nAmount - gpGlobals->rgInventory[i].nAmountInUse,
-               2, PAL_XY(96 + k * 100, 17 + j * 18), kNumColorCyan, kNumAlignRight);
+               2, PAL_XY(15 + iAmountXOffset + k * iItemTextWidth, 17 + j * 18), kNumColorCyan, kNumAlignRight);
 		 }
 
          i++;
@@ -281,8 +298,15 @@ PAL_ItemSelectMenuUpdate(
       {
          if (gpGlobals->g.lprgScriptEntry[wScript].wOperation == 0xFFFF)
          {
-            wScript = PAL_RunAutoScript(wScript, (1 << 15) | line);
-            line++;
+#ifdef PAL_UNICODE
+			 int line_incr = (gpGlobals->g.lprgScriptEntry[wScript].rgwOperand[1] != 1) ? 1 : 0;
+#endif
+			 wScript = PAL_RunAutoScript(wScript, PAL_ITEM_DESC_BOTTOM | line);
+#ifdef PAL_UNICODE
+			 line += line_incr;
+#else
+			 line++;
+#endif
          }
          else
          {
@@ -300,10 +324,10 @@ PAL_ItemSelectMenuUpdate(
       {
          if (gpGlobals->rgInventory[gpGlobals->iCurInvMenuItem].nAmount > 0)
          {
-            j = (gpGlobals->iCurInvMenuItem < 3 * 4) ? (gpGlobals->iCurInvMenuItem / 3) : 4;
-            k = gpGlobals->iCurInvMenuItem % 3;
+			 j = (gpGlobals->iCurInvMenuItem < iItemsPerLine * iPageLineOffset) ? (gpGlobals->iCurInvMenuItem / iItemsPerLine) : iPageLineOffset;
+			k = gpGlobals->iCurInvMenuItem % iItemsPerLine;
 
-            PAL_DrawText(PAL_GetWord(wObject), PAL_XY(15 + k * 100, 12 + j * 18),
+            PAL_DrawText(PAL_GetWord(wObject), PAL_XY(15 + k * iItemTextWidth, 12 + j * 18),
                MENUITEM_COLOR_CONFIRMED, FALSE, FALSE);
          }
 

+ 40 - 18
magicmenu.c

@@ -61,17 +61,32 @@ PAL_MagicSelectionMenuUpdate(
    BYTE        bColor;
    WORD        wScript;
 #endif
+#ifdef PAL_UNICODE
+   const int   iItemsPerLine = 32 / gpGlobals->dwWordLength;
+   const int   iItemTextWidth = 8 * gpGlobals->dwWordLength + 7;
+   const int   iLinesPerPage = 5 - gpGlobals->dwExtraDescLines;
+   const int   iBoxYOffset = gpGlobals->dwExtraDescLines * 16;
+   const int   iCursorXOffset = gpGlobals->dwWordLength * 5 / 2;
+   const int   iPageLineOffset = iLinesPerPage / 2;
+#else
+   const int   iItemsPerLine = 3;
+   const int   iItemTextWidth = 87;
+   const int   iLinesPerPage = 5;
+   const int   iBoxYOffset = 0;
+   const int   iCursorXOffset = 25;
+   const int   iPageLineOffset = 2;
+#endif
 
    //
    // Check for inputs
    //
    if (g_InputState.dwKeyPress & kKeyUp)
    {
-      g_iCurrentItem -= 3;
+      g_iCurrentItem -= iItemsPerLine;
    }
    else if (g_InputState.dwKeyPress & kKeyDown)
    {
-      g_iCurrentItem += 3;
+      g_iCurrentItem += iItemsPerLine;
    }
    else if (g_InputState.dwKeyPress & kKeyLeft)
    {
@@ -83,11 +98,11 @@ PAL_MagicSelectionMenuUpdate(
    }
    else if (g_InputState.dwKeyPress & kKeyPgUp)
    {
-      g_iCurrentItem -= 3 * 5;
+      g_iCurrentItem -= iItemsPerLine * iLinesPerPage;
    }
    else if (g_InputState.dwKeyPress & kKeyPgDn)
    {
-      g_iCurrentItem += 3 * 5;
+      g_iCurrentItem += iItemsPerLine * iLinesPerPage;
    }
    else if (g_InputState.dwKeyPress & kKeyMenu)
    {
@@ -109,7 +124,7 @@ PAL_MagicSelectionMenuUpdate(
    //
    // Create the box.
    //
-   PAL_CreateBox(PAL_XY(10, 42), 4, 16, 1, FALSE);
+   PAL_CreateBox(PAL_XY(10, 42 + iBoxYOffset), iLinesPerPage - 1, 16, 1, FALSE);
 
 #ifndef PAL_WIN95
    if (gpGlobals->lpObjectDesc == NULL)
@@ -196,9 +211,16 @@ PAL_MagicSelectionMenuUpdate(
    {
       if (gpGlobals->g.lprgScriptEntry[wScript].wOperation == 0xFFFF)
       {
-         wScript = PAL_RunAutoScript(wScript, line);
-         line++;
-      }
+#ifdef PAL_UNICODE
+         int line_incr = (gpGlobals->g.lprgScriptEntry[wScript].rgwOperand[1] != 1) ? 1 : 0;
+#endif
+		 wScript = PAL_RunAutoScript(wScript, line);
+#ifdef PAL_UNICODE
+		 line += line_incr;
+#else
+		 line++;
+#endif
+	  }
       else
       {
          wScript = PAL_RunAutoScript(wScript, 0);
@@ -220,15 +242,15 @@ PAL_MagicSelectionMenuUpdate(
    //
    // Draw the texts of the current page
    //
-   i = g_iCurrentItem / 3 * 3 - 3 * 2;
+   i = g_iCurrentItem / iItemsPerLine * iItemsPerLine - iItemsPerLine * iPageLineOffset;
    if (i < 0)
    {
       i = 0;
    }
 
-   for (j = 0; j < 5; j++)
+   for (j = 0; j < iLinesPerPage; j++)
    {
-      for (k = 0; k < 3; k++)
+      for (k = 0; k < iItemsPerLine; k++)
       {
          bColor = MENUITEM_COLOR;
 
@@ -237,7 +259,7 @@ PAL_MagicSelectionMenuUpdate(
             //
             // End of the list reached
             //
-            j = 5;
+            j = iLinesPerPage;
             break;
          }
 
@@ -261,7 +283,7 @@ PAL_MagicSelectionMenuUpdate(
          // Draw the text
          //
          PAL_DrawText(PAL_GetWord(rgMagicItem[i].wMagic),
-            PAL_XY(35 + k * 87, 54 + j * 18), bColor, TRUE, FALSE);
+            PAL_XY(35 + k * iItemTextWidth, 54 + j * 18 + iBoxYOffset), bColor, TRUE, FALSE);
 
          //
          // Draw the cursor on the current selected item
@@ -269,7 +291,7 @@ PAL_MagicSelectionMenuUpdate(
          if (i == g_iCurrentItem)
          {
             PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_CURSOR),
-               gpScreen, PAL_XY(60 + k * 87, 64 + j * 18));
+               gpScreen, PAL_XY(35 + iCursorXOffset + k * iItemTextWidth, 64 + j * 18 + iBoxYOffset));
          }
 
          i++;
@@ -280,11 +302,11 @@ PAL_MagicSelectionMenuUpdate(
    {
       if (rgMagicItem[g_iCurrentItem].fEnabled)
       {
-         j = g_iCurrentItem % 3;
-         k = (g_iCurrentItem < 3 * 2) ? (g_iCurrentItem / 3) : 2;
+         j = g_iCurrentItem % iItemsPerLine;
+		 k = (g_iCurrentItem < iItemsPerLine * iPageLineOffset) ? (g_iCurrentItem / iItemsPerLine) : iPageLineOffset;
 
-         j = 35 + j * 87;
-         k = 54 + k * 18;
+		 j = 35 + j * iItemTextWidth;
+		 k = 54 + k * 18 + iBoxYOffset;
 
          PAL_DrawText(PAL_GetWord(rgMagicItem[g_iCurrentItem].wMagic), PAL_XY(j, k),
             MENUITEM_COLOR_CONFIRMED, FALSE, TRUE);

+ 33 - 11
script.c

@@ -3497,18 +3497,40 @@ begin:
 
    case 0xFFFF:
 #ifdef PAL_WIN95
-      iDescLine = (wEventObjectID & ~(1 << 15));
-      if (wEventObjectID & (1 << 15))
-      {
-         PAL_DrawText(PAL_GetMsg(pScript->rgwOperand[0]), PAL_XY(75, iDescLine * 16 + 150), DESCTEXT_COLOR, TRUE, FALSE);
-      }
-      else
-      {
-         PAL_DrawText(PAL_GetMsg(pScript->rgwOperand[0]), PAL_XY(100, iDescLine * 16 + 3), DESCTEXT_COLOR, TRUE, FALSE);
-      }
-      iDescLine++;
-#endif
+	  // Support for Japanese
+	  // If the second parameter is zero, then follow the standard behavior
+	  // Otherwise, use the extended behavior
+      // Either zero or two displays text
+	  if (pScript->rgwOperand[1] == 0 || pScript->rgwOperand[1] == 2)
+	  {
+		  iDescLine = (wEventObjectID & ~PAL_ITEM_DESC_BOTTOM);
+		  if (wEventObjectID & PAL_ITEM_DESC_BOTTOM)
+		  {
+#  ifdef PAL_UNICODE
+			  int YOffset = gpGlobals->dwExtraDescLines * 16;
+#  else
+			  int YOffset = 0;
+#  endif
+			  PAL_DrawText(PAL_GetMsg(pScript->rgwOperand[0]), PAL_XY(75, iDescLine * 16 + 150 - YOffset), DESCTEXT_COLOR, TRUE, FALSE);
+		  }
+		  else
+		  {
+			  PAL_DrawText(PAL_GetMsg(pScript->rgwOperand[0]), PAL_XY(100, iDescLine * 16 + 3), DESCTEXT_COLOR, TRUE, FALSE);
+		  }
+		  iDescLine++;
+	  }
+	  if (pScript->rgwOperand[1] != 0)
+	  {
+		  // Then, jump to script given by the third parameter.
+		  wScriptEntry = pScript->rgwOperand[2];
+	  }
+	  else
+	  {
+		  wScriptEntry++;
+	  }
+#else
 	  wScriptEntry++;
+#endif
 	  break;
 
 #ifdef PAL_WIN95

+ 4 - 0
script.h

@@ -27,6 +27,10 @@ extern "C"
 {
 #endif
 
+#ifdef PAL_WIN95
+#define PAL_ITEM_DESC_BOTTOM	(1 << 15)
+#endif
+
 WORD
 PAL_RunTriggerScript(
    WORD           wScriptEntry,

+ 1 - 1
sdlpal.vcxproj

@@ -95,7 +95,6 @@
       <WarningLevel>Level3</WarningLevel>
       <SuppressStartupBanner>true</SuppressStartupBanner>
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <Optimization>Disabled</Optimization>
     </ClCompile>
     <ResourceCompile>
       <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -133,6 +132,7 @@
       <WarningLevel>Level3</WarningLevel>
       <SuppressStartupBanner>true</SuppressStartupBanner>
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <Optimization>Disabled</Optimization>
     </ClCompile>
     <ResourceCompile>
       <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>