- add support for not localizing some text functions, and modify menu text fields to use this

This commit is contained in:
Gutawer 2022-11-25 13:50:34 +00:00 committed by Christoph Oelckers
parent f666edc60c
commit 91d3c4b606
7 changed files with 48 additions and 35 deletions

View file

@ -831,7 +831,7 @@ static inline FSpecialColormap * ListGetSpecialColormap(VMVa_List &tags)
//==========================================================================
template<class T>
bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture *img, double x, double y, uint32_t tag, T& tags, DrawParms *parms, int type, PalEntry fill, double fillalpha)
bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture *img, double x, double y, uint32_t tag, T& tags, DrawParms *parms, int type, PalEntry fill, double fillalpha, bool scriptDifferences)
{
INTBOOL boolval;
int intval;
@ -886,6 +886,7 @@ bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture *img, double x, double
parms->scalex = parms->scaley = 1;
parms->cellx = parms->celly = 0;
parms->maxstrlen = INT_MAX;
parms->localize = scriptDifferences ? false : true;
parms->virtBottom = false;
parms->srcx = 0.;
parms->srcy = 0.;
@ -1323,6 +1324,10 @@ bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture *img, double x, double
parms->maxstrlen = ListGetInt(tags);
break;
case DTA_Localize:
parms->localize = ListGetInt(tags);
break;
case DTA_CellX:
parms->cellx = ListGetInt(tags);
break;
@ -1434,8 +1439,8 @@ bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture *img, double x, double
}
// explicitly instantiate both versions for v_text.cpp.
template bool ParseDrawTextureTags<Va_List>(F2DDrawer* drawer, FGameTexture *img, double x, double y, uint32_t tag, Va_List& tags, DrawParms *parms, int type, PalEntry fill, double fillalpha);
template bool ParseDrawTextureTags<VMVa_List>(F2DDrawer* drawer, FGameTexture *img, double x, double y, uint32_t tag, VMVa_List& tags, DrawParms *parms, int type, PalEntry fill, double fillalpha);
template bool ParseDrawTextureTags<Va_List>(F2DDrawer* drawer, FGameTexture *img, double x, double y, uint32_t tag, Va_List& tags, DrawParms *parms, int type, PalEntry fill, double fillalpha, bool scriptDifferences);
template bool ParseDrawTextureTags<VMVa_List>(F2DDrawer* drawer, FGameTexture *img, double x, double y, uint32_t tag, VMVa_List& tags, DrawParms *parms, int type, PalEntry fill, double fillalpha, bool scriptDifferences);
//==========================================================================
//

View file

@ -100,6 +100,7 @@ enum
// For DrawText calls:
DTA_TextLen, // stop after this many characters, even if \0 not hit
DTA_Localize, // localize text
DTA_CellX, // horizontal size of character cell
DTA_CellY, // vertical size of character cell
@ -194,6 +195,7 @@ struct DrawParms
int monospace;
int spacing;
int maxstrlen;
bool localize;
bool fortext;
bool virtBottom;
bool burn;
@ -266,7 +268,7 @@ enum
};
template<class T>
bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture* img, double x, double y, uint32_t tag, T& tags, DrawParms* parms, int type, PalEntry fill = ~0u, double fillalpha = 0.0);
bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture* img, double x, double y, uint32_t tag, T& tags, DrawParms* parms, int type, PalEntry fill = ~0u, double fillalpha = 0.0, bool scriptDifferences = false);
template<class T>
void DrawTextCommon(F2DDrawer *drawer, FFont* font, int normalcolor, double x, double y, const T* string, DrawParms& parms);

View file

@ -380,6 +380,7 @@ void DrawText(F2DDrawer *drawer, FFont* font, int normalcolor, double x, double
{
return;
}
const char *txt = (parms.localize && string[0] == '$') ? GStrings(&string[1]) : string;
DrawTextCommon(drawer, font, normalcolor, x, y, (const uint8_t*)string, parms);
}
@ -399,24 +400,27 @@ void DrawText(F2DDrawer *drawer, FFont* font, int normalcolor, double x, double
{
return;
}
// [Gutawer] right now nothing needs the char32_t version to have localisation support, and i don't know how to do it
assert(parms.localize == false);
DrawTextCommon(drawer, font, normalcolor, x, y, string, parms);
}
void DrawText(F2DDrawer *drawer, FFont *font, int normalcolor, double x, double y, const char *string, VMVa_List &args)
void DrawText(F2DDrawer *drawer, FFont *font, int normalcolor, double x, double y, const FString& string, VMVa_List &args)
{
DrawParms parms;
if (font == NULL || string == NULL)
if (font == NULL)
return;
uint32_t tag = ListGetInt(args);
bool res = ParseDrawTextureTags(drawer, nullptr, 0, 0, tag, args, &parms, DrawTexture_Text);
bool res = ParseDrawTextureTags(drawer, nullptr, 0, 0, tag, args, &parms, DrawTexture_Text, ~0u, 0.0, true);
if (!res)
{
return;
}
DrawTextCommon(drawer, font, normalcolor, x, y, (const uint8_t*)string, parms);
const char *txt = (parms.localize && string[0] == '$') ? GStrings(&string[1]) : string.GetChars();
DrawTextCommon(drawer, font, normalcolor, x, y, (uint8_t*)txt, parms);
}
DEFINE_ACTION_FUNCTION(_Screen, DrawText)
@ -432,8 +436,7 @@ DEFINE_ACTION_FUNCTION(_Screen, DrawText)
if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
VMVa_List args = { param + 5, 0, numparam - 6, va_reginfo + 5 };
const char *txt = chr[0] == '$' ? GStrings(&chr[1]) : chr.GetChars();
DrawText(twod, font, cr, x, y, txt, args);
DrawText(twod, font, cr, x, y, chr, args);
return 0;
}
@ -450,8 +453,7 @@ DEFINE_ACTION_FUNCTION(FCanvas, DrawText)
PARAM_VA_POINTER(va_reginfo) // Get the hidden type information array
VMVa_List args = { param + 6, 0, numparam - 7, va_reginfo + 6 };
const char *txt = chr[0] == '$' ? GStrings(&chr[1]) : chr.GetChars();
DrawText(&self->Drawer, font, cr, x, y, txt, args);
DrawText(&self->Drawer, font, cr, x, y, chr, args);
self->Tex->NeedUpdate();
return 0;
}

View file

@ -631,9 +631,9 @@ DEFINE_ACTION_FUNCTION_NATIVE(FFont, GetBottomAlignOffset, GetBottomAlignOffset)
ACTION_RETURN_FLOAT(GetBottomAlignOffset(self, code));
}
static int StringWidth(FFont *font, const FString &str)
static int StringWidth(FFont *font, const FString &str, bool localize)
{
const char *txt = str[0] == '$' ? GStrings(&str[1]) : str.GetChars();
const char *txt = (localize && str[0] == '$') ? GStrings(&str[1]) : str.GetChars();
return font->StringWidth(txt);
}
@ -641,12 +641,13 @@ DEFINE_ACTION_FUNCTION_NATIVE(FFont, StringWidth, StringWidth)
{
PARAM_SELF_STRUCT_PROLOGUE(FFont);
PARAM_STRING(str);
ACTION_RETURN_INT(StringWidth(self, str));
PARAM_BOOL(localize);
ACTION_RETURN_INT(StringWidth(self, str, localize));
}
static int GetMaxAscender(FFont* font, const FString& str)
static int GetMaxAscender(FFont* font, const FString& str, bool localize)
{
const char* txt = str[0] == '$' ? GStrings(&str[1]) : str.GetChars();
const char* txt = (localize && str[0] == '$') ? GStrings(&str[1]) : str.GetChars();
return font->GetMaxAscender(txt);
}
@ -654,12 +655,13 @@ DEFINE_ACTION_FUNCTION_NATIVE(FFont, GetMaxAscender, GetMaxAscender)
{
PARAM_SELF_STRUCT_PROLOGUE(FFont);
PARAM_STRING(str);
ACTION_RETURN_INT(GetMaxAscender(self, str));
PARAM_BOOL(localize);
ACTION_RETURN_INT(GetMaxAscender(self, str, localize));
}
static int CanPrint(FFont *font, const FString &str)
static int CanPrint(FFont *font, const FString &str, bool localize)
{
const char *txt = str[0] == '$' ? GStrings(&str[1]) : str.GetChars();
const char *txt = (localize && str[0] == '$') ? GStrings(&str[1]) : str.GetChars();
return font->CanPrint(txt);
}
@ -667,7 +669,8 @@ DEFINE_ACTION_FUNCTION_NATIVE(FFont, CanPrint, CanPrint)
{
PARAM_SELF_STRUCT_PROLOGUE(FFont);
PARAM_STRING(str);
ACTION_RETURN_INT(CanPrint(self, str));
PARAM_BOOL(localize);
ACTION_RETURN_INT(CanPrint(self, str, localize));
}
static int FindFontColor(int name)

View file

@ -429,6 +429,7 @@ enum DrawTextureTags
// For DrawText calls only:
DTA_TextLen, // stop after this many characters, even if \0 not hit
DTA_Localize, // localize drawn string
DTA_CellX, // horizontal size of character cell
DTA_CellY, // vertical size of character cell
@ -640,9 +641,9 @@ struct Font native
// native Font(const Name name);
native int GetCharWidth(int code);
native int StringWidth(String code);
native int GetMaxAscender(String code);
native bool CanPrint(String code);
native int StringWidth(String code, bool localize = true);
native int GetMaxAscender(String code, bool localize = true);
native bool CanPrint(String code, bool localize = true);
native int GetHeight();
native int GetDisplacement();
native String GetCursor();

View file

@ -346,16 +346,16 @@ class Menu : Object native ui version("2.4")
return OptionFont().GetHeight();
}
static int OptionWidth(String s)
static int OptionWidth(String s, bool localize = true)
{
return OptionFont().StringWidth(s);
return OptionFont().StringWidth(s, localize);
}
static void DrawOptionText(int x, int y, int color, String text, bool grayed = false)
static void DrawOptionText(int x, int y, int color, String text, bool grayed = false, bool localize = true)
{
String label = Stringtable.Localize(text);
String label = localize ? Stringtable.Localize(text) : text;
int overlay = grayed? Color(96,48,0,0) : 0;
screen.DrawText (OptionFont(), color, x, y, text, DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay);
screen.DrawText (OptionFont(), color, x, y, text, DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay, DTA_Localize, localize);
}
@ -377,4 +377,4 @@ class GenericMenu : Menu
{
Super.Init(parent);
}
}
}

View file

@ -61,9 +61,9 @@ class OptionMenuItem : MenuItemBase
return x;
}
protected void drawValue(int indent, int y, int color, String text, bool grayed = false)
protected void drawValue(int indent, int y, int color, String text, bool grayed = false, bool localize = true)
{
Menu.DrawOptionText(indent + CursorSpace(), y, color, text, grayed);
Menu.DrawOptionText(indent + CursorSpace(), y, color, text, grayed, localize);
}
@ -999,7 +999,7 @@ class OptionMenuFieldBase : OptionMenuItem
{
bool grayed = mGrayCheck != null && !mGrayCheck.GetInt();
drawLabel(indent, y, selected ? OptionMenuSettings.mFontColorSelection : OptionMenuSettings.mFontColor, grayed);
drawValue(indent, y, OptionMenuSettings.mFontColorValue, Represent(), grayed);
drawValue(indent, y, OptionMenuSettings.mFontColorValue, Represent(), grayed, false);
return indent;
}
@ -1068,7 +1068,7 @@ class OptionMenuItemTextField : OptionMenuFieldBase
{
// reposition the text so that the cursor is visible when in entering mode.
String text = Represent();
int tlen = Menu.OptionWidth(text) * CleanXfac_1;
int tlen = Menu.OptionWidth(text, false) * CleanXfac_1;
int newindent = screen.GetWidth() - tlen - CursorSpace();
if (newindent < indent) indent = newindent;
}
@ -1295,4 +1295,4 @@ class OptionMenuItemFlagOption : OptionMenuItemOption
}
}
}
}
}