From 14e94aa6c1269ac5acf32263dd6d74eb79ba6622 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 17 Oct 2020 14:00:29 +0200 Subject: [PATCH] - added localization fallback handling for the BigFont in menu items and captions. --- src/common/fonts/font.cpp | 1 + src/common/fonts/singlelumpfont.cpp | 27 +++++++++++++++++++ src/common/fonts/v_font.cpp | 3 ++- src/common/fonts/v_font.h | 4 +-- src/common/fonts/v_text.cpp | 13 ++++++++- src/common/rendering/v_video.cpp | 1 + wadsrc/static/zscript/base.zs | 1 + .../static/zscript/ui/menu/listmenuitems.zs | 8 +++--- .../static/zscript/ui/menu/menucustomize.zs | 7 +++++ wadsrc/static/zscript/ui/menu/optionmenu.zs | 2 +- 10 files changed, 58 insertions(+), 9 deletions(-) diff --git a/src/common/fonts/font.cpp b/src/common/fonts/font.cpp index 2a67aab37..d5d57790e 100644 --- a/src/common/fonts/font.cpp +++ b/src/common/fonts/font.cpp @@ -579,6 +579,7 @@ void RecordTextureColors (FImageSource *pic, uint32_t *usedcolors) { usedcolors[pixels[x]]++; } + } //========================================================================== diff --git a/src/common/fonts/singlelumpfont.cpp b/src/common/fonts/singlelumpfont.cpp index a9cd6ee04..3678ee441 100644 --- a/src/common/fonts/singlelumpfont.cpp +++ b/src/common/fonts/singlelumpfont.cpp @@ -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); diff --git a/src/common/fonts/v_font.cpp b/src/common/fonts/v_font.cpp index 1d75d9f18..b90a74866 100644 --- a/src/common/fonts/v_font.cpp +++ b/src/common/fonts/v_font.cpp @@ -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; diff --git a/src/common/fonts/v_font.h b/src/common/fonts/v_font.h index 6de1dae86..37bf049a3 100644 --- a/src/common/fonts/v_font.h +++ b/src/common/fonts/v_font.h @@ -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(); diff --git a/src/common/fonts/v_text.cpp b/src/common/fonts/v_text.cpp index 742a99e6f..59d843496 100644 --- a/src/common/fonts/v_text.cpp +++ b/src/common/fonts/v_text.cpp @@ -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; + } } } diff --git a/src/common/rendering/v_video.cpp b/src/common/rendering/v_video.cpp index 3cf9f7bb1..815b73a6b 100644 --- a/src/common/rendering/v_video.cpp +++ b/src/common/rendering/v_video.cpp @@ -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) diff --git a/wadsrc/static/zscript/base.zs b/wadsrc/static/zscript/base.zs index 223ac495f..4f0e64f9a 100644 --- a/wadsrc/static/zscript/base.zs +++ b/wadsrc/static/zscript/base.zs @@ -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; diff --git a/wadsrc/static/zscript/ui/menu/listmenuitems.zs b/wadsrc/static/zscript/ui/menu/listmenuitems.zs index 13d96281c..8b47d288c 100644 --- a/wadsrc/static/zscript/ui/menu/listmenuitems.zs +++ b/wadsrc/static/zscript/ui/menu/listmenuitems.zs @@ -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); diff --git a/wadsrc/static/zscript/ui/menu/menucustomize.zs b/wadsrc/static/zscript/ui/menu/menucustomize.zs index 4d15d2cdb..75b114e54 100644 --- a/wadsrc/static/zscript/ui/menu/menucustomize.zs +++ b/wadsrc/static/zscript/ui/menu/menucustomize.zs @@ -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; + } } diff --git a/wadsrc/static/zscript/ui/menu/optionmenu.zs b/wadsrc/static/zscript/ui/menu/optionmenu.zs index 6392adf3f..7f126c1e8 100644 --- a/wadsrc/static/zscript/ui/menu/optionmenu.zs +++ b/wadsrc/static/zscript/ui/menu/optionmenu.zs @@ -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);