Browse Source

some UI text tweak, mainly for using in international project

Pal Lockheart 7 years ago
parent
commit
1080ef28b3
4 changed files with 38 additions and 9 deletions
  1. 29 6
      ui.c
  2. 5 0
      ui.h
  3. 2 1
      uibattle.c
  4. 2 2
      uigame.c

+ 29 - 6
ui.c

@@ -682,6 +682,34 @@ PAL_DrawNumber(
    }
 }
 
+INT
+PAL_TextWidth(
+LPCWSTR lpszItemText
+)
+/*++
+ Purpose:
+ 
+ Calculate the text width of the given text.
+ 
+ Parameters:
+ 
+ [IN]  itemText - Pointer to the text.
+ 
+ Return value:
+ 
+ text width.
+ 
+ --*/
+{
+    size_t l = wcslen(lpszItemText);
+    int j = 0, w = 0;
+    for (j = 0; j < l; j++)
+    {
+        w += PAL_CharWidth(lpszItemText[j]);
+    }
+    return w;
+}
+
 INT
 PAL_MenuTextMaxWidth(
    LPCMENUITEM    rgMenuItem,
@@ -707,12 +735,7 @@ PAL_MenuTextMaxWidth(
 	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;
+		int w = (PAL_TextWidth(itemText) + 8) >> 4;
 		if (r < w)
 		{
 			r = w;

+ 5 - 0
ui.h

@@ -219,6 +219,11 @@ PAL_DrawNumber(
    NUMCOLOR        color,
    NUMALIGN        align
 );
+    
+INT
+PAL_TextWidth(
+   LPCWSTR        lpszItemText
+);
 
 INT
 PAL_MenuTextMaxWidth(

+ 2 - 1
uibattle.c

@@ -813,7 +813,8 @@ PAL_BattleUIUpdate(
       }
       else
       {
-         PAL_DrawText(PAL_GetWord(BATTLEUI_LABEL_AUTO), PAL_XY(280, 10),
+         LPCWSTR itemText = PAL_GetWord(BATTLEUI_LABEL_AUTO);
+         PAL_DrawText(itemText, PAL_XY(312-PAL_TextWidth(itemText), 10),
             MENUITEM_COLOR_CONFIRMED, TRUE, FALSE, FALSE);
       }
    }

+ 2 - 2
uigame.c

@@ -713,7 +713,7 @@ PAL_InGameMagicMenu(
    //
    // Draw the box
    //
-   PAL_CreateBox(PAL_XY(35, 62), gpGlobals->wMaxPartyMemberIndex, 2, 0, FALSE);
+   PAL_CreateBox(PAL_XY(35, 62), gpGlobals->wMaxPartyMemberIndex, PAL_MenuTextMaxWidth(rgMenuItem, sizeof(rgMenuItem)/sizeof(MENUITEM)) - 1, 0, FALSE);
    VIDEO_UpdateScreen(&rect);
 
    w = PAL_ReadMenu(NULL, rgMenuItem, gpGlobals->wMaxPartyMemberIndex + 1, w, MENUITEM_COLOR);
@@ -896,7 +896,7 @@ PAL_InventoryMenu(
       { 2,      INVMENU_LABEL_EQUIP,      TRUE,     PAL_XY(43, 73 + 18) },
    };
 
-   PAL_CreateBox(PAL_XY(30, 60), 1, 1, 0, FALSE);
+   PAL_CreateBox(PAL_XY(30, 60), 1, PAL_MenuTextMaxWidth(rgMenuItem, sizeof(rgMenuItem)/sizeof(MENUITEM)) - 1, 0, FALSE);
    VIDEO_UpdateScreen(&rect);
 
    w = PAL_ReadMenu(NULL, rgMenuItem, 2, w - 1, MENUITEM_COLOR);