Clean up international_string_util

This commit is contained in:
GriffinR 2021-10-17 21:51:11 -04:00
parent f2e0c9ec9d
commit a950f9c771
7 changed files with 36 additions and 39 deletions

View File

@ -10,15 +10,15 @@ int GetStringCenterAlignXOffset(int fontId, const u8 *str, int totalWidth);
int GetStringRightAlignXOffset(int fontId, const u8 *str, int totalWidth);
int GetStringCenterAlignXOffsetWithLetterSpacing(int fontId, const u8 *str, int totalWidth, int letterSpacing);
int GetStringWidthDifference(int fontId, const u8 *str, int totalWidth, int letterSpacing);
int GetMaxWidthInMenuTable(const struct MenuAction *str, int arg1);
int sub_81DB3D8(const struct MenuAction *str, const u8* arg1, int arg2);
int GetMaxWidthInMenuTable(const struct MenuAction *actions, int numActions);
int GetMaxWidthInSubsetOfMenuTable(const struct MenuAction *actions, const u8* actionIds, int numActions);
int Intl_GetListMenuWidth(const struct ListMenuTemplate *listMenu);
void CopyMonCategoryText(int dexNum, u8 *dest);
u8 *sub_81DB494(u8 *str, int fontId, const u8 *str2, int totalStringWidth);
u8 *GetStringClearToWidth(u8 *dest, int fontId, const u8 *str, int totalStringWidth);
void PadNameString(u8 *dest, u8 padChar);
void ConvertInternationalPlayerNameStripChar(u8 *, u8);
void ConvertInternationalContestantName(u8 *);
int sub_81DB604(u8 *);
int GetNicknameLanguage(u8 *);
void sub_81DB620(int windowId, int columnStart, int rowStart, int numFillTiles, int numRows);
#endif // GUARD_INTERNATIONAL_STRING_UTIL_H

View File

@ -34,32 +34,32 @@ int GetStringWidthDifference(int fontId, const u8 *str, int totalWidth, int lett
return 0;
}
int GetMaxWidthInMenuTable(const struct MenuAction *str, int numActions)
int GetMaxWidthInMenuTable(const struct MenuAction *actions, int numActions)
{
int i, var;
int i, maxWidth;
for (var = 0, i = 0; i < numActions; i++)
for (maxWidth = 0, i = 0; i < numActions; i++)
{
int stringWidth = GetStringWidth(1, str[i].text, 0);
if (stringWidth > var)
var = stringWidth;
int stringWidth = GetStringWidth(1, actions[i].text, 0);
if (stringWidth > maxWidth)
maxWidth = stringWidth;
}
return ConvertPixelWidthToTileWidth(var);
return ConvertPixelWidthToTileWidth(maxWidth);
}
int sub_81DB3D8(const struct MenuAction *str, const u8* arg1, int arg2)
int GetMaxWidthInSubsetOfMenuTable(const struct MenuAction *actions, const u8* actionIds, int numActions)
{
int i, var;
int i, maxWidth;
for (var = 0, i = 0; i < arg2; i++)
for (maxWidth = 0, i = 0; i < numActions; i++)
{
int stringWidth = GetStringWidth(1, str[arg1[i]].text, 0);
if (stringWidth > var)
var = stringWidth;
int stringWidth = GetStringWidth(1, actions[actionIds[i]].text, 0);
if (stringWidth > maxWidth)
maxWidth = stringWidth;
}
return ConvertPixelWidthToTileWidth(var);
return ConvertPixelWidthToTileWidth(maxWidth);
}
int Intl_GetListMenuWidth(const struct ListMenuTemplate *listMenu)
@ -93,32 +93,29 @@ void CopyMonCategoryText(int dexNum, u8 *dest)
StringCopy(str + 1, gText_Pokemon);
}
u8 *sub_81DB494(u8 *str, int fontId, const u8 *str2, int totalStringWidth)
u8 *GetStringClearToWidth(u8 *dest, int fontId, const u8 *str, int totalStringWidth)
{
u8 *buffer;
int width;
int clearWidth;
if (str2)
if (str)
{
buffer = StringCopy(str, str2);
width = GetStringWidth(fontId, str2, 0);
buffer = StringCopy(dest, str);
width = GetStringWidth(fontId, str, 0);
}
else
{
buffer = str;
buffer = dest;
width = 0;
}
clearWidth = totalStringWidth - width;
if (clearWidth > 0)
{
*buffer = EXT_CTRL_CODE_BEGIN;
buffer++;
*buffer = EXT_CTRL_CODE_CLEAR;
buffer++;
*buffer = clearWidth;
buffer++;
*(buffer++) = EXT_CTRL_CODE_BEGIN;
*(buffer++) = EXT_CTRL_CODE_CLEAR;
*(buffer++) = clearWidth;
*buffer = EOS;
}
@ -209,7 +206,7 @@ void TVShowConvertInternationalString(u8 *dest, const u8 *src, int language)
ConvertInternationalString(dest, language);
}
int sub_81DB604(u8 *str)
int GetNicknameLanguage(u8 *str)
{
if (str[0] == EXT_CTRL_CODE_BEGIN && str[1] == EXT_CTRL_CODE_JPN)
return LANGUAGE_JAPANESE;

View File

@ -396,7 +396,7 @@ static void InitPlayerPCMenu(u8 taskId)
else // Bedroom PC
windowTemplate = sWindowTemplates_MainMenus[WIN_MAIN_MENU_BEDROOM];
windowTemplate.width = sub_81DB3D8(sPlayerPCMenuActions, sTopMenuOptionOrder, sTopMenuNumOptions);
windowTemplate.width = GetMaxWidthInSubsetOfMenuTable(sPlayerPCMenuActions, sTopMenuOptionOrder, sTopMenuNumOptions);
tWindowId = AddWindow(&windowTemplate);
SetStandardWindowBorderStyle(tWindowId, 0);
sub_81995E4(tWindowId, sTopMenuNumOptions, sPlayerPCMenuActions, sTopMenuOptionOrder);

View File

@ -705,7 +705,7 @@ static void PrintSearchMonListItem(struct PokenavMonList * item, u8 * dest)
}
StringGetEnd10(gStringVar3);
dest = sub_81DB494(dest, 1, gStringVar3, 60);
dest = GetStringClearToWidth(dest, 1, gStringVar3, 60);
switch (gender)
{
default:
@ -723,5 +723,5 @@ static void PrintSearchMonListItem(struct PokenavMonList * item, u8 * dest)
*s++ = CHAR_EXTRA_SYMBOL;
*s++ = CHAR_LV_2;
ConvertIntToDecimalStringN(s, level, STR_CONV_MODE_LEFT_ALIGN, 3);
sub_81DB494(dest, 1, gStringVar1, 40);
GetStringClearToWidth(dest, 1, gStringVar1, 40);
}

View File

@ -413,12 +413,12 @@ void BufferMatchCallNameAndDesc(struct PokenavMatchCallEntries *matchCallEntry,
if (className && trainerName)
{
u8 *str2 = sub_81DB494(str, 7, className, 69);
sub_81DB494(str2, 7, trainerName, 51);
u8 *str2 = GetStringClearToWidth(str, 7, className, 69);
GetStringClearToWidth(str2, 7, trainerName, 51);
}
else
{
sub_81DB494(str, 7, NULL, 120);
GetStringClearToWidth(str, 7, NULL, 120);
}
}

View File

@ -722,7 +722,7 @@ static void BufferRibbonMonInfoText(struct PokenavMonList * item0, u8 * dest)
}
StringGetEnd10(gStringVar3);
dest = sub_81DB494(dest, 1, gStringVar3, 60);
dest = GetStringClearToWidth(dest, 1, gStringVar3, 60);
switch (gender)
{
default:
@ -741,6 +741,6 @@ static void BufferRibbonMonInfoText(struct PokenavMonList * item0, u8 * dest)
*s++ = CHAR_EXTRA_SYMBOL;
*s++ = CHAR_LV_2;
ConvertIntToDecimalStringN(s, level, STR_CONV_MODE_LEFT_ALIGN, 3);
dest = sub_81DB494(dest, 1, gStringVar1, 54);
dest = GetStringClearToWidth(dest, 1, gStringVar1, 54);
ConvertIntToDecimalStringN(dest, item->data, STR_CONV_MODE_RIGHT_ALIGN, 2);
}

View File

@ -1155,7 +1155,7 @@ void TryPutPokemonTodayOnAir(void)
show->pokemonToday.ball = itemLastUsed;
StringCopy(show->pokemonToday.playerName, gSaveBlock2Ptr->playerName);
StringCopy(show->pokemonToday.nickname, gBattleResults.caughtMonNick);
language2 = sub_81DB604(show->pokemonToday.nickname);
language2 = GetNicknameLanguage(show->pokemonToday.nickname);
StripExtCtrlCodes(show->pokemonToday.nickname);
show->pokemonToday.species = gBattleResults.caughtMonSpecies;
StorePlayerIdInRecordMixShow(show);