From d786f197d1ebb967707f0570c7d5c0f45205c0a5 Mon Sep 17 00:00:00 2001 From: Daggolin Date: Sat, 11 Nov 2023 23:27:34 +0100 Subject: [PATCH] [SP] Map the UI module internal font numbers 1 to 4 to the names of default fonts and dynamically register them to avoid undesired font changes when registering other fonts too early. --- code/ui/ui_shared.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/code/ui/ui_shared.cpp b/code/ui/ui_shared.cpp index 885d0e9019..0306ba6c72 100644 --- a/code/ui/ui_shared.cpp +++ b/code/ui/ui_shared.cpp @@ -3072,7 +3072,19 @@ qboolean ItemParse_name( itemDef_t *item) return qtrue; } +int MenuFontToReal( int menuFontIndex ) +{ + // Default fonts from a clean installation + switch ( menuFontIndex ) { + case 1: return UI_RegisterFont( "aurabesh" ); + case 2: return UI_RegisterFont( "ergoec" ); + case 3: return UI_RegisterFont( "anewhope" ); + case 4: return UI_RegisterFont( "arialnb" ); + default: + return DC->Assets.qhMediumFont; + } +} qboolean ItemParse_font( itemDef_t *item ) { @@ -3080,6 +3092,10 @@ qboolean ItemParse_font( itemDef_t *item ) { return qfalse; } + + // Translate to real font + item->font = MenuFontToReal( item->font ); + return qtrue; } @@ -8261,7 +8277,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw) while (1) { // FIXME - add some type of parameter in the menu file like descfont to specify the font for the descriptions for this menu. - textWidth = DC->textWidth(textPtr, fDescScale, 4); // item->font); + textWidth = DC->textWidth(textPtr, fDescScale, MenuFontToReal(4)); // item->font); if (parent->descAlignment == ITEM_ALIGN_RIGHT) { @@ -8297,7 +8313,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw) } // FIXME - add some type of parameter in the menu file like descfont to specify the font for the descriptions for this menu. - DC->drawText(xPos, parent->descY + iYadj, fDescScale, parent->descColor, textPtr, 0, parent->descTextStyle, 4); //item->font); + DC->drawText(xPos, parent->descY + iYadj, fDescScale, parent->descColor, textPtr, 0, parent->descTextStyle, MenuFontToReal(4)); //item->font); break; } }