- added localization fallback handling for the BigFont in menu items and captions.

This commit is contained in:
Christoph Oelckers 2020-10-17 14:00:29 +02:00
parent 473072d556
commit 14e94aa6c1
10 changed files with 58 additions and 9 deletions

View file

@ -579,6 +579,7 @@ void RecordTextureColors (FImageSource *pic, uint32_t *usedcolors)
{
usedcolors[pixels[x]]++;
}
}
//==========================================================================

View file

@ -87,6 +87,7 @@ class FSingleLumpFont : public FFont
{
public:
FSingleLumpFont (const char *fontname, int lump);
void RecordAllTextureColors(uint32_t* usedcolors) override;
protected:
void CheckFON1Chars (double *luminosity);
@ -649,6 +650,32 @@ void FSingleLumpFont::FixupPalette (uint8_t *identity, double *luminosity, const
}
}
//==========================================================================
//
// RecordAllTextureColors
//
// Given a 256 entry buffer, sets every entry that corresponds to a color
// used by the font.
//
//==========================================================================
void FSingleLumpFont::RecordAllTextureColors(uint32_t* usedcolors)
{
double luminosity[256];
uint8_t identity[256];
PalEntry local_palette[256];
if (FontType == BMFFONT || FontType == FONT2)
{
FixupPalette(identity, luminosity, PaletteData, RescalePalette, local_palette);
for (int i = 0; i < 256; i++)
{
if (identity[i] != 0) usedcolors[identity[i]]++;
}
}
}
FFont *CreateSingleLumpFont (const char *fontname, int lump)
{
return new FSingleLumpFont(fontname, lump);

View file

@ -85,7 +85,8 @@ static int TranslationMapCompare (const void *a, const void *b);
extern int PrintColors[];
// PUBLIC DATA DEFINITIONS -------------------------------------------------
FFont* SmallFont, * SmallFont2, * BigFont, * BigUpper, * ConFont, * IntermissionFont, * NewConsoleFont, * NewSmallFont, * CurrentConsoleFont, * OriginalSmallFont, * AlternativeSmallFont, * OriginalBigFont;
FFont* SmallFont, * SmallFont2, * BigFont, * BigUpper, * ConFont, * IntermissionFont, * NewConsoleFont, * NewSmallFont,
* CurrentConsoleFont, * OriginalSmallFont, * AlternativeSmallFont, * OriginalBigFont, *AlternativeBigFont;
FFont *FFont::FirstFont = nullptr;
int NumTextColors;

View file

@ -127,7 +127,7 @@ public:
void SetCursor(char c) { Cursor = c; }
void SetKerning(int c) { GlobalKerning = c; }
bool NoTranslate() const { return noTranslate; }
void RecordAllTextureColors(uint32_t *usedcolors);
virtual void RecordAllTextureColors(uint32_t *usedcolors);
virtual void SetDefaultTranslation(uint32_t *colors);
void CheckCase();
@ -182,7 +182,7 @@ protected:
};
extern FFont *SmallFont, *SmallFont2, *BigFont, *BigUpper, *ConFont, *IntermissionFont, *NewConsoleFont, *NewSmallFont, *CurrentConsoleFont, *OriginalSmallFont, *AlternativeSmallFont, *OriginalBigFont;
extern FFont *SmallFont, *SmallFont2, *BigFont, *BigUpper, *ConFont, *IntermissionFont, *NewConsoleFont, *NewSmallFont, *CurrentConsoleFont, *OriginalSmallFont, *AlternativeSmallFont, *OriginalBigFont, *AlternativeBigFont;
void V_InitFonts();
void V_ClearFonts();

View file

@ -276,7 +276,18 @@ void UpdateGenericUI(bool cvar)
AlternativeSmallFont = NewSmallFont;
}
// Todo: Do the same for the BigFont
if (CheckFontComplete(BigFont))
{
AlternativeBigFont = BigFont;
}
else if (OriginalBigFont && CheckFontComplete(OriginalBigFont))
{
AlternativeBigFont = OriginalBigFont;
}
else
{
AlternativeBigFont = NewSmallFont;
}
}
}

View file

@ -445,6 +445,7 @@ DEFINE_GLOBAL(ConFont)
DEFINE_GLOBAL(NewConsoleFont)
DEFINE_GLOBAL(NewSmallFont)
DEFINE_GLOBAL(AlternativeSmallFont)
DEFINE_GLOBAL(AlternativeBigFont)
DEFINE_GLOBAL(OriginalSmallFont)
DEFINE_GLOBAL(OriginalBigFont)
DEFINE_GLOBAL(IntermissionFont)

View file

@ -157,6 +157,7 @@ struct _ native // These are the global variables, the struct is only here to av
native readonly Font NewConsoleFont;
native readonly Font NewSmallFont;
native readonly Font AlternativeSmallFont;
native readonly Font AlternativeBigFont;
native readonly Font OriginalSmallFont;
native readonly Font OriginalBigFont;
native readonly Font intermissionfont;

View file

@ -293,13 +293,13 @@ class ListMenuItemTextItem : ListMenuItemSelectable
override void Draw(bool selected, ListMenuDescriptor desc)
{
let font = generic_ui ? NewSmallFont : mFont;
let font = menuDelegate.PickFont(mFont);
DrawText(desc, font, selected ? mColorSelected : mColor, mXpos, mYpos, mText);
}
override int GetWidth()
{
let font = generic_ui? NewSmallFont : mFont;
let font = menuDelegate.PickFont(mFont);
return max(1, font.StringWidth(StringTable.Localize(mText)));
}
}
@ -360,7 +360,7 @@ class ListMenuItemCaptionItem : ListMenuItem
override void Draw(bool selected, ListMenuDescriptor desc)
{
let font = generic_ui || !desc.mFont ? NewSmallFont : desc.mFont;
let font = menuDelegate.PickFont(desc.mFont);
if (font && mText.Length() > 0)
{
menuDelegate.DrawCaption(mText, font, 0, true);

View file

@ -22,4 +22,11 @@ class MenuDelegateBase ui
// overriding this allows to execute special actions when the menu closes
}
virtual Font PickFont(Font fnt)
{
if (generic_ui || !fnt) return NewSmallFont;
if (fnt == SmallFont) return AlternativeSmallFont;
if (fnt == BigFont) return AlternativeBigFont;
return fnt;
}
}

View file

@ -430,7 +430,7 @@ class OptionMenu : Menu
virtual int DrawCaption(String title, int y, bool drawit)
{
let font = generic_ui || !mDesc.mFont ? NewSmallFont : mDesc.mFont;
let font = menuDelegate.PickFont(mDesc.mFont);
if (font && mDesc.mTitle.Length() > 0)
{
return menuDelegate.DrawCaption(title, font, y, drawit);