diff --git a/src/c_console.cpp b/src/c_console.cpp index eb50c3ee7..745ffc5ad 100644 --- a/src/c_console.cpp +++ b/src/c_console.cpp @@ -787,7 +787,7 @@ void FNotifyBuffer::AddString(int printlevel, FString source) width = DisplayWidth / active_con_scaletext(generic_ui); - FFont *font = generic_ui ? NewSmallFont : SmallFont; + FFont *font = generic_ui ? NewSmallFont : AlternativeSmallFont; if (font == nullptr) return; // Without an initialized font we cannot handle the message (this is for those which come here before the font system is ready.) if (AddType == APPENDLINE && Text.Size() > 0 && Text[Text.Size() - 1].PrintLevel == printlevel) @@ -1071,7 +1071,7 @@ void FNotifyBuffer::Draw() line = Top; canskip = true; - FFont *font = generic_ui ? NewSmallFont : SmallFont; + FFont *font = generic_ui ? NewSmallFont : AlternativeSmallFont; lineadv = font->GetHeight (); for (unsigned i = 0; i < Text.Size(); ++ i) diff --git a/src/g_statusbar/hudmessages.cpp b/src/g_statusbar/hudmessages.cpp index c6eda73c5..a94ab2b42 100644 --- a/src/g_statusbar/hudmessages.cpp +++ b/src/g_statusbar/hudmessages.cpp @@ -197,7 +197,7 @@ DHUDMessage::DHUDMessage (FFont *font, const char *text, float x, float y, int h Top = y; HoldTics = (int)(holdTime * TICRATE); Tics = -1; // -1 to compensate for one additional Tick the message will receive. - Font = font? font : generic_ui? NewSmallFont : SmallFont; + Font = font? font : generic_ui? SmallFont : AlternativeSmallFont; TextColor = textColor; State = 0; SourceText = copystring (text); diff --git a/src/gamedata/fonts/font.cpp b/src/gamedata/fonts/font.cpp index 05dcbcbc2..1b93148e8 100644 --- a/src/gamedata/fonts/font.cpp +++ b/src/gamedata/fonts/font.cpp @@ -69,7 +69,7 @@ // //========================================================================== -FFont::FFont (const char *name, const char *nametemplate, const char *filetemplate, int lfirst, int lcount, int start, int fdlump, int spacewidth, bool notranslate) +FFont::FFont (const char *name, const char *nametemplate, const char *filetemplate, int lfirst, int lcount, int start, int fdlump, int spacewidth, bool notranslate, bool iwadonly) { int i; FTextureID lump; @@ -189,31 +189,74 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla { if (nametemplate != nullptr) { - for (i = 0; i < lcount; i++) + if (!iwadonly) { - int position = '!' + i; - mysnprintf(buffer, countof(buffer), nametemplate, i + start); + for (i = 0; i < lcount; i++) + { + int position = '!' + i; + mysnprintf(buffer, countof(buffer), nametemplate, i + start); - lump = TexMan.CheckForTexture(buffer, ETextureType::MiscPatch); - if (doomtemplate && lump.isValid() && i + start == 121) - { // HACKHACK: Don't load STCFN121 in doom(2), because - // it's not really a lower-case 'y' but a '|'. - // Because a lot of wads with their own font seem to foolishly - // copy STCFN121 and make it a '|' themselves, wads must - // provide STCFN120 (x) and STCFN122 (z) for STCFN121 to load as a 'y'. - if (!TexMan.CheckForTexture("STCFN120", ETextureType::MiscPatch).isValid() || - !TexMan.CheckForTexture("STCFN122", ETextureType::MiscPatch).isValid()) + lump = TexMan.CheckForTexture(buffer, ETextureType::MiscPatch); + if (doomtemplate && lump.isValid() && i + start == 121) + { // HACKHACK: Don't load STCFN121 in doom(2), because + // it's not really a lower-case 'y' but a '|'. + // Because a lot of wads with their own font seem to foolishly + // copy STCFN121 and make it a '|' themselves, wads must + // provide STCFN120 (x) and STCFN122 (z) for STCFN121 to load as a 'y'. + if (!TexMan.CheckForTexture("STCFN120", ETextureType::MiscPatch).isValid() || + !TexMan.CheckForTexture("STCFN122", ETextureType::MiscPatch).isValid()) + { + // insert the incorrectly named '|' graphic in its correct position. + position = 124; + } + } + if (lump.isValid()) { - // insert the incorrectly named '|' graphic in its correct position. - position = 124; + Type = Multilump; + if (position < minchar) minchar = position; + if (position > maxchar) maxchar = position; + charMap.Insert(position, TexMan.GetTexture(lump)); } } - if (lump.isValid()) + } + else + { + FTexture *texs[256 - '!'] = {}; + for (i = 0; i < lcount; i++) { - Type = Multilump; - if (position < minchar) minchar = position; - if (position > maxchar) maxchar = position; - charMap.Insert(position, TexMan.GetTexture(lump)); + TArray array; + mysnprintf(buffer, countof(buffer), nametemplate, i + start); + + TexMan.ListTextures(buffer, array, true); + for (auto entry : array) + { + FTexture *tex = TexMan.GetTexture(entry, false); + if (tex && tex->SourceLump >= 0 && Wads.GetLumpFile(tex->SourceLump) <= Wads.GetIwadNum() && tex->UseType == ETextureType::MiscPatch) + { + texs[i] = tex; + } + } + } + if (doomtemplate) + { + // Handle the misplaced '|'. + if (texs[121 - start] && !texs[120 - start] && !texs[122 - start] && !texs[124 - start]) + { + texs[124 - start] = texs[121 - start]; + texs[121 - start] = nullptr; + } + } + + for (i = 0; i < lcount; i++) + { + if (texs[i]) + { + int position = '!' + i; + Type = Multilump; + if (position < minchar) minchar = position; + if (position > maxchar) maxchar = position; + charMap.Insert(position, TexMan.GetTexture(lump)); + } } } } diff --git a/src/gamedata/fonts/v_font.cpp b/src/gamedata/fonts/v_font.cpp index 996f919e1..d98babb2b 100644 --- a/src/gamedata/fonts/v_font.cpp +++ b/src/gamedata/fonts/v_font.cpp @@ -1497,12 +1497,39 @@ void V_InitFonts() { if (Wads.CheckNumForName("FONTA_S") >= 0) { - SmallFont = new FFont("SmallFont", "FONTA%02u", "defsmallfont", HU_FONTSTART, HU_FONTSIZE, 1, -1); - SmallFont->SetCursor('['); + int wadfile = -1; + auto a = Wads.CheckNumForName("FONTA33", ns_graphics); + if (a != -1) wadfile = Wads.GetLumpFile(a); + if (wadfile > Wads.GetIwadNum()) + { + // The font has been replaced, so we need to create a copy of the original as well. + SmallFont = new FFont("SmallFont", "FONTA%02u", nullptr, HU_FONTSTART, HU_FONTSIZE, 1, -1); + SmallFont->SetCursor('['); + + OriginalSmallFont = new FFont("SmallFont", "FONTA%02u", "defsmallfont", HU_FONTSTART, HU_FONTSIZE, 1, -1, -1, false, true); + OriginalSmallFont->SetCursor('['); + } + else + { + SmallFont = new FFont("SmallFont", "FONTA%02u", "defsmallfont", HU_FONTSTART, HU_FONTSIZE, 1, -1); + SmallFont->SetCursor('['); + } } else if (Wads.CheckNumForName("STCFN033", ns_graphics) >= 0) { - SmallFont = new FFont("SmallFont", "STCFN%.3d", "defsmallfont", HU_FONTSTART, HU_FONTSIZE, HU_FONTSTART, -1); + int wadfile = -1; + auto a = Wads.CheckNumForName("STCFN065", ns_graphics); + if (a != -1) wadfile = Wads.GetLumpFile(a); + if (wadfile > Wads.GetIwadNum()) + { + // The font has been replaced, so we need to create a copy of the original as well. + SmallFont = new FFont("SmallFont", "STCFN%.3d", nullptr, HU_FONTSTART, HU_FONTSIZE, HU_FONTSTART, -1); + OriginalSmallFont = new FFont("SmallFont", "FONTA%02u", "defsmallfont", HU_FONTSTART, HU_FONTSIZE, 1, -1, -1, false, true); + } + else + { + SmallFont = new FFont("SmallFont", "STCFN%.3d", "defsmallfont", HU_FONTSTART, HU_FONTSIZE, HU_FONTSTART, -1); + } } } if (!(SmallFont2 = V_GetFont("SmallFont2"))) // Only used by Strife @@ -1566,8 +1593,9 @@ void V_InitFonts() } if (BigFont == nullptr) { - BigFont = SmallFont; + BigFont = NewSmallFont; } + AlternativeSmallFont = SmallFont; } void V_ClearFonts() @@ -1577,6 +1605,6 @@ void V_ClearFonts() delete FFont::FirstFont; } FFont::FirstFont = nullptr; - CurrentConsoleFont = NewSmallFont = NewConsoleFont = SmallFont = SmallFont2 = BigFont = ConFont = IntermissionFont = nullptr; + AlternativeSmallFont = OriginalSmallFont = CurrentConsoleFont = NewSmallFont = NewConsoleFont = SmallFont = SmallFont2 = BigFont = ConFont = IntermissionFont = nullptr; } diff --git a/src/gamedata/fonts/v_font.h b/src/gamedata/fonts/v_font.h index cb1376407..cd066fc7c 100644 --- a/src/gamedata/fonts/v_font.h +++ b/src/gamedata/fonts/v_font.h @@ -93,7 +93,7 @@ public: Custom }; - FFont (const char *fontname, const char *nametemplate, const char *filetemplate, int first, int count, int base, int fdlump, int spacewidth=-1, bool notranslate = false); + FFont (const char *fontname, const char *nametemplate, const char *filetemplate, int first, int count, int base, int fdlump, int spacewidth=-1, bool notranslate = false, bool iwadonly = false); virtual ~FFont (); virtual FTexture *GetChar (int code, int translation, int *const width, bool *redirected = nullptr) const; @@ -164,7 +164,7 @@ protected: }; -extern FFont *SmallFont, *SmallFont2, *BigFont, *BigUpper, *ConFont, *IntermissionFont, *NewConsoleFont, *NewSmallFont, *CurrentConsoleFont; +extern FFont *SmallFont, *SmallFont2, *BigFont, *BigUpper, *ConFont, *IntermissionFont, *NewConsoleFont, *NewSmallFont, *CurrentConsoleFont, *OriginalSmallFont, *AlternativeSmallFont; void V_InitFonts(); void V_ClearFonts(); diff --git a/src/v_video.cpp b/src/v_video.cpp index 2afc45e3e..a968304ed 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -145,7 +145,7 @@ public: int DisplayWidth, DisplayHeight; -FFont *SmallFont, *SmallFont2, *BigFont, *BigUpper, *ConFont, *IntermissionFont, *NewConsoleFont, *NewSmallFont, *CurrentConsoleFont; +FFont *SmallFont, *SmallFont2, *BigFont, *BigUpper, *ConFont, *IntermissionFont, *NewConsoleFont, *NewSmallFont, *CurrentConsoleFont, *OriginalSmallFont, *AlternativeSmallFont; uint32_t Col2RGB8[65][256]; uint32_t *Col2RGB8_LessPrecision[65]; @@ -913,6 +913,7 @@ DEFINE_GLOBAL(BigFont) DEFINE_GLOBAL(ConFont) DEFINE_GLOBAL(NewConsoleFont) DEFINE_GLOBAL(NewSmallFont) +DEFINE_GLOBAL(AlternativeSmallFont) DEFINE_GLOBAL(IntermissionFont) DEFINE_GLOBAL(CleanXfac) DEFINE_GLOBAL(CleanYfac) diff --git a/wadsrc/static/zscript/base.zs b/wadsrc/static/zscript/base.zs index fe929e41e..b52548d6d 100644 --- a/wadsrc/static/zscript/base.zs +++ b/wadsrc/static/zscript/base.zs @@ -24,6 +24,7 @@ struct _ native // These are the global variables, the struct is only here to av native readonly Font confont; native readonly Font NewConsoleFont; native readonly Font NewSmallFont; + native readonly Font AlternativeSmallFont; native readonly Font intermissionfont; native readonly int CleanXFac; native readonly int CleanYFac; diff --git a/wadsrc/static/zscript/ui/menu/messagebox.zs b/wadsrc/static/zscript/ui/menu/messagebox.zs index fe1fd6320..1ed970f35 100644 --- a/wadsrc/static/zscript/ui/menu/messagebox.zs +++ b/wadsrc/static/zscript/ui/menu/messagebox.zs @@ -72,7 +72,7 @@ class MessageBoxMenu : Menu } else { - textFont = SmallFont; + textFont = AlternativeSmallFont; arrowFont = ConFont; destWidth = CleanWidth; destHeight = CleanHeight;