diff --git a/src/c_console.cpp b/src/c_console.cpp index 745ffc5adf..8693b57d4b 100644 --- a/src/c_console.cpp +++ b/src/c_console.cpp @@ -583,9 +583,7 @@ CUSTOM_CVAR (Int, msgmidcolor2, 4, CVAR_ARCHIVE) EColorRange C_GetDefaultFontColor() { - // Ideally this should analyze the SmallFont and pick a matching color. - if (!generic_ui) return CR_UNTRANSLATED; - return gameinfo.gametype == GAME_Doom ? CR_RED : gameinfo.gametype == GAME_Chex ? CR_GREEN : gameinfo.gametype == GAME_Strife ? CR_GOLD : CR_GRAY; + return CR_UNTRANSLATED; } FFont * C_GetDefaultHUDFont() diff --git a/src/g_statusbar/hudmessages.cpp b/src/g_statusbar/hudmessages.cpp index a94ab2b420..3ec35b2056 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? SmallFont : AlternativeSmallFont; + Font = font? font : generic_ui? NewSmallFont : AlternativeSmallFont; TextColor = textColor; State = 0; SourceText = copystring (text); diff --git a/src/gamedata/fonts/font.cpp b/src/gamedata/fonts/font.cpp index 22dc94030a..7d09f37cba 100644 --- a/src/gamedata/fonts/font.cpp +++ b/src/gamedata/fonts/font.cpp @@ -547,7 +547,10 @@ void FFont::RecordAllTextureColors(uint32_t *usedcolors) FFontChar1 *pic = static_cast(Chars[i].TranslatedPic->GetImage()); if (pic) { - RecordTextureColors(pic->GetBase(), usedcolors); + // The remap must be temporarily reset here because this can be called on an initialized font. + auto sr = pic->ResetSourceRemap(); + RecordTextureColors(pic, usedcolors); + pic->SetSourceRemap(sr); } } } diff --git a/src/gamedata/fonts/hexfont.cpp b/src/gamedata/fonts/hexfont.cpp index 2980af2c93..e579829282 100644 --- a/src/gamedata/fonts/hexfont.cpp +++ b/src/gamedata/fonts/hexfont.cpp @@ -194,33 +194,36 @@ TArray FHexFontChar2::CreatePalettedPixels(int) TArray Pixels(destSize, true); uint8_t *dest_p = Pixels.Data(); - auto drawLayer = [&](int ix, int iy, int color) + assert(SourceData); + if (SourceData) { - const uint8_t *src_p = SourceData; - for (int y = 0; y < Height-2; y++) + auto drawLayer = [&](int ix, int iy, int color) { - for (int x = 0; x < SourceWidth; x++) + const uint8_t *src_p = SourceData; + for (int y = 0; y < Height - 2; y++) { - int byte = *src_p++; - uint8_t *pixelstart = dest_p + (ix + 8 * x) * Height + (iy+y); - for (int bit = 0; bit < 8; bit++) + for (int x = 0; x < SourceWidth; x++) { - if (byte & (128 >> bit)) + int byte = *src_p++; + uint8_t *pixelstart = dest_p + (ix + 8 * x) * Height + (iy + y); + for (int bit = 0; bit < 8; bit++) { - pixelstart[bit*Height] = color; + if (byte & (128 >> bit)) + { + pixelstart[bit*Height] = color; + } } } } - } - }; - memset(dest_p, 0, destSize); - - const int darkcolor = 3; - const int brightcolor = 14; - for (int xx=0;xx<3;xx++) for (int yy=0;yy<3;yy++) if (xx !=1 || yy != 1) - drawLayer(xx, yy, darkcolor); - drawLayer(1, 1, brightcolor); + }; + memset(dest_p, 0, destSize); + const int darkcolor = 1; + const int brightcolor = 14; + for (int xx = 0; xx < 3; xx++) for (int yy = 0; yy < 3; yy++) if (xx != 1 || yy != 1) + drawLayer(xx, yy, darkcolor); + drawLayer(1, 1, brightcolor); + } return Pixels; } @@ -369,6 +372,56 @@ public: BuildTranslations(luminosity, nullptr, &TranslationParms[0][0], ActiveColors, nullptr); } + void SetDefaultTranslation(uint32_t *colors) override + { + double myluminosity[18]; + + myluminosity[0] = 0; + for (int i = 1; i < 18; i++) + { + myluminosity[i] = (i - 1) / 16.; + } + + uint8_t othertranslation[256], otherreverse[256]; + TArray otherluminosity; + + SimpleTranslation(colors, othertranslation, otherreverse, otherluminosity); + + FRemapTable remap(ActiveColors); + remap.Remap[0] = 0; + remap.Palette[0] = 0; + + for (unsigned l = 1; l < 18; l++) + { + for (unsigned o = 1; o < otherluminosity.Size() - 1; o++) // luminosity[0] is for the transparent color + { + if (myluminosity[l] >= otherluminosity[o] && myluminosity[l] <= otherluminosity[o + 1]) + { + PalEntry color1 = GPalette.BaseColors[otherreverse[o]]; + PalEntry color2 = GPalette.BaseColors[otherreverse[o + 1]]; + double weight = 0; + if (otherluminosity[o] != otherluminosity[o + 1]) + { + weight = (myluminosity[l] - otherluminosity[o]) / (otherluminosity[o + 1] - otherluminosity[o]); + } + int r = int(color1.r + weight * (color2.r - color1.r)); + int g = int(color1.g + weight * (color2.g - color1.g)); + int b = int(color1.b + weight * (color2.b - color1.b)); + + r = clamp(r, 0, 255); + g = clamp(g, 0, 255); + b = clamp(b, 0, 255); + remap.Remap[l] = ColorMatcher.Pick(r, g, b); + remap.Palette[l] = PalEntry(255, r, g, b); + break; + } + } + } + Ranges[CR_UNTRANSLATED] = remap; + forceremap = true; + + } + }; diff --git a/src/gamedata/fonts/v_font.cpp b/src/gamedata/fonts/v_font.cpp index 298119ee03..a2217b6c14 100644 --- a/src/gamedata/fonts/v_font.cpp +++ b/src/gamedata/fonts/v_font.cpp @@ -1532,12 +1532,10 @@ void V_InitFonts() } } } - if (OriginalSmallFont != nullptr) - { - uint32_t colors[256] = {}; - SmallFont->RecordAllTextureColors(colors); - OriginalSmallFont->SetDefaultTranslation(colors); - } + uint32_t colors[256] = {}; + SmallFont->RecordAllTextureColors(colors); + if (OriginalSmallFont != nullptr) OriginalSmallFont->SetDefaultTranslation(colors); + NewSmallFont->SetDefaultTranslation(colors); if (!(SmallFont2 = V_GetFont("SmallFont2"))) // Only used by Strife { diff --git a/src/gamedata/fonts/v_font.h b/src/gamedata/fonts/v_font.h index 203843304c..5a799c1fd1 100644 --- a/src/gamedata/fonts/v_font.h +++ b/src/gamedata/fonts/v_font.h @@ -119,7 +119,7 @@ public: void SetKerning(int c) { GlobalKerning = c; } bool NoTranslate() const { return noTranslate; } void RecordAllTextureColors(uint32_t *usedcolors); - void SetDefaultTranslation(uint32_t *colors); + virtual void SetDefaultTranslation(uint32_t *colors); protected: FFont (int lump); diff --git a/src/gamedata/textures/formats/fontchars.cpp b/src/gamedata/textures/formats/fontchars.cpp index 6ff30ab8c6..250e34ac57 100644 --- a/src/gamedata/textures/formats/fontchars.cpp +++ b/src/gamedata/textures/formats/fontchars.cpp @@ -86,17 +86,6 @@ TArray FFontChar1::CreatePalettedPixels (int) return Pixels; } -//========================================================================== -// -// FFontChar1 :: SetSourceRemap -// -//========================================================================== - -void FFontChar1::SetSourceRemap(const uint8_t *sourceremap) -{ - SourceRemap = sourceremap; -} - //========================================================================== // // FFontChar2 :: FFontChar2 diff --git a/src/gamedata/textures/formats/fontchars.h b/src/gamedata/textures/formats/fontchars.h index 7d9c261601..341fb9445f 100644 --- a/src/gamedata/textures/formats/fontchars.h +++ b/src/gamedata/textures/formats/fontchars.h @@ -6,7 +6,8 @@ class FFontChar1 : public FImageSource public: FFontChar1 (FImageSource *sourcelump); TArray CreatePalettedPixels(int conversion) override; - void SetSourceRemap(const uint8_t *sourceremap); + void SetSourceRemap(const uint8_t *sourceremap) { SourceRemap = sourceremap; } + const uint8_t *ResetSourceRemap() { auto p = SourceRemap; SourceRemap = nullptr; return p; } FImageSource *GetBase() const { return BaseTexture; } protected: diff --git a/wadsrc/static/zscript/ui/menu/menu.zs b/wadsrc/static/zscript/ui/menu/menu.zs index da1fbe81be..1e006d815e 100644 --- a/wadsrc/static/zscript/ui/menu/menu.zs +++ b/wadsrc/static/zscript/ui/menu/menu.zs @@ -290,13 +290,6 @@ class Menu : Object native ui version("2.4") screen.DrawText (ConFont, color, x, y, str, DTA_CellX, 8 * CleanXfac, DTA_CellY, 8 * CleanYfac); } - static int OptionColor(int color) - { - if (color != Font.CR_UNTRANSLATED) return color; - // This needs fixing for mods with custom fonts. - return gameinfo.gametype == GAME_Doom ? Font.CR_RED : gameinfo.gametype == GAME_Chex ? Font.CR_GREEN : gameinfo.gametype == GAME_Strife ? Font.CR_GOLD : Font.CR_GRAY; - } - static Font OptionFont() { return NewSmallFont; @@ -316,7 +309,7 @@ class Menu : Object native ui version("2.4") { String label = Stringtable.Localize(text); int overlay = grayed? Color(96,48,0,0) : 0; - screen.DrawText (OptionFont(), OptionColor(color), x, y, text, DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay); + screen.DrawText (OptionFont(), color, x, y, text, DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay); } diff --git a/wadsrc/static/zscript/ui/menu/optionmenu.zs b/wadsrc/static/zscript/ui/menu/optionmenu.zs index 2dff1a8739..51f03e227b 100644 --- a/wadsrc/static/zscript/ui/menu/optionmenu.zs +++ b/wadsrc/static/zscript/ui/menu/optionmenu.zs @@ -461,7 +461,7 @@ class OptionMenu : Menu { if (((MenuTime() % 8) < 6) || GetCurrentMenu() != self) { - DrawOptionText(cur_indent + 3 * CleanXfac_1, y, Font.CR_UNTRANSLATED, "◄"); + DrawOptionText(cur_indent + 3 * CleanXfac_1, y, OptionMenuSettings.mFontColorSelection, "◄"); } } y += fontheight; @@ -473,11 +473,11 @@ class OptionMenu : Menu if (CanScrollUp) { - DrawOptionText(screen.GetWidth() - 11 * CleanXfac_1, ytop, Font.CR_UNTRANSLATED, "▲"); + DrawOptionText(screen.GetWidth() - 11 * CleanXfac_1, ytop, OptionMenuSettings.mFontColorSelection, "▲"); } if (CanScrollDown) { - DrawOptionText(screen.GetWidth() - 11 * CleanXfac_1 , y - 8*CleanYfac_1, Font.CR_UNTRANSLATED, "▼"); + DrawOptionText(screen.GetWidth() - 11 * CleanXfac_1 , y - 8*CleanYfac_1, OptionMenuSettings.mFontColorSelection, "▼"); } Super.Drawer(); }