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

This reverts commit 91d3c4b606.

This completely breaks the menus, so it needs to go.
This commit is contained in:
Christoph Oelckers 2022-12-04 08:13:04 +01:00
parent cd46f97dcc
commit 1e5e65546d
7 changed files with 35 additions and 48 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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