From 8900cc2f2e2f8402a578ec45447c9af3e3eb53de Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 31 May 2021 12:32:40 +0200 Subject: [PATCH] - cleanup of automap label printing. Moved larger parts of the font selection logic into common code. --- wadsrc/static/zscript/games/blood/ui/sbar.zs | 24 ++------- wadsrc/static/zscript/games/duke/ui/sbar.zs | 31 +++--------- .../static/zscript/games/exhumed/ui/menu.zs | 10 ++-- .../static/zscript/games/exhumed/ui/sbar.zs | 2 +- wadsrc/static/zscript/games/sw/ui/sbar.zs | 23 ++------- wadsrc/static/zscript/statusbar.zs | 49 +++++++++++++------ 6 files changed, 56 insertions(+), 83 deletions(-) diff --git a/wadsrc/static/zscript/games/blood/ui/sbar.zs b/wadsrc/static/zscript/games/blood/ui/sbar.zs index e1d5c3d7e..62fb5582d 100644 --- a/wadsrc/static/zscript/games/blood/ui/sbar.zs +++ b/wadsrc/static/zscript/games/blood/ui/sbar.zs @@ -138,7 +138,6 @@ class BloodStatusBar : RazeStatusBar StatsPrintInfo stats; stats.fontscale = 1.; - stats.spacing = SmallFont.GetHeight() + 2; stats.screenbottomspace = bottomy; stats.statfont = SmallFont; stats.letterColor = TEXTCOLOR_DARKRED; @@ -146,29 +145,16 @@ class BloodStatusBar : RazeStatusBar if (automapMode == am_full) { - bool textfont = am_textfont; - if (!am_textfont) - { - // For non-English languages force use of the text font. The tiny one is simply too small to ever add localized characters to it. - let p = StringTable.Localize("$REQUIRED_CHARACTERS"); - if (p.length() > 0) - { - stats.statfont = Raze.PickSmallFont(); - textfont = true; - } - } - - if (!textfont) - { - stats.statfont = SmallFont2; - stats.spacing = 6; - } + stats.statfont = SmallFont2; + stats.spacing = 6; + stats.altspacing = SmallFont.GetHeight() + 2; if (hud_size <= Hud_StbarOverlay) stats.screenbottomspace = 56; - PrintAutomapInfo(stats, textfont); + PrintAutomapInfo(stats, false); } if (automapMode == am_off && hud_stats) { stats.completeColor = TEXTCOLOR_DARKGREEN; + stats.spacing = SmallFont.GetHeight() + 2; PrintLevelStats(stats, summary); } diff --git a/wadsrc/static/zscript/games/duke/ui/sbar.zs b/wadsrc/static/zscript/games/duke/ui/sbar.zs index e21489895..006a99c2c 100644 --- a/wadsrc/static/zscript/games/duke/ui/sbar.zs +++ b/wadsrc/static/zscript/games/duke/ui/sbar.zs @@ -174,32 +174,15 @@ class DukeCommonStatusBar : RazeStatusBar if (automapMode == am_full) { - bool textfont = am_textfont; - if (!am_textfont) - { - // For non-English languages force use of the text font. The tiny one is simply too small to ever add localized characters to it. - let p = StringTable.Localize("$REQUIRED_CHARACTERS"); - if (p.length() > 0) - { - stats.statfont = Raze.PickSmallFont(); - textfont = true; - } - } + stats.statfont = SmallFont2; + stats.spacing = 6; + if (Raze.isNamWW2GI()) stats.altspacing = 10; + else if (!Raze.isRR()) stats.altspacing = 11; + else stats.altspacing = 14; - if (!textfont) - { - stats.statfont = SmallFont2; - stats.spacing = 6; - } - else - { - if (Raze.isNamWW2GI()) stats.spacing = 12; - else if (!Raze.isRR()) stats.spacing = 11; - else stats.spacing = 14; - } - stats.standardColor = (Raze.isNamWW2GI() && am_textfont)? Font.TEXTCOLOR_ORANGE : Font.TEXTCOLOR_UNTRANSLATED; + stats.standardColor = Font.TEXTCOLOR_UNTRANSLATED; stats.letterColor = Font.TEXTCOLOR_GOLD; - PrintAutomapInfo(stats, textfont); + PrintAutomapInfo(stats, false); } else if (hud_stats) { diff --git a/wadsrc/static/zscript/games/exhumed/ui/menu.zs b/wadsrc/static/zscript/games/exhumed/ui/menu.zs index 898ada378..12eade483 100644 --- a/wadsrc/static/zscript/games/exhumed/ui/menu.zs +++ b/wadsrc/static/zscript/games/exhumed/ui/menu.zs @@ -87,12 +87,12 @@ class ListMenuItemExhumedTextItem : ListMenuItemTextItem override void Draw(bool selected, ListMenuDescriptor desc) { - let font = Raze.PickBigFont(); - let cr = generic_ui ? Font.CR_FIRE : Font.CR_UNTRANSLATED; // this ignores the passed font intentionally. + let myfont = Raze.PickBigFont(); + let cr = generic_ui ? Font.CR_FIRE : Font.CR_UNTRANSLATED; // this ignores the passed myfont intentionally. let tex = TexMan.CheckForTexture("MENUBLANK"); let texsize = TexMan.GetScaledSize(tex); - let fonth = font.GetGlyphHeight("A"); - int width = font.StringWidth(mText); + let fonth = myfont.GetGlyphHeight("A"); + int width = myfont.StringWidth(mText); let delegate = ExhumedMenuDelegate(menuDelegate); let zoom = delegate ? delegate.zoomsize : 1.; @@ -114,7 +114,7 @@ class ListMenuItemExhumedTextItem : ListMenuItemTextItem } screen.DrawTexture(tex, false, 160, y, DTA_FullscreenScale, FSMode_Fit320x200, DTA_CenterOffset, true, DTA_ScaleX, scalex, DTA_Color, color, DTA_ScaleX, zoom, DTA_ScaleY, zoom); - screen.DrawText(font, cr, 160 - zoom * width / 2, y - zoom * fonth / 2, mText, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Color, color, DTA_ScaleX, zoom * scalex, DTA_ScaleY, zoom); + screen.DrawText(myfont, cr, 160 - zoom * width / 2, y - zoom * fonth / 2, mText, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Color, color, DTA_ScaleX, zoom * scalex, DTA_ScaleY, zoom); } } diff --git a/wadsrc/static/zscript/games/exhumed/ui/sbar.zs b/wadsrc/static/zscript/games/exhumed/ui/sbar.zs index 7ae8b83c6..5bbc32eb6 100644 --- a/wadsrc/static/zscript/games/exhumed/ui/sbar.zs +++ b/wadsrc/static/zscript/games/exhumed/ui/sbar.zs @@ -440,7 +440,7 @@ class ExhumedStatusBar : RazeStatusBar StatsPrintInfo stats; stats.fontscale = 1.; - stats.spacing = SmallFont.GetHeight(); + stats.altspacing = stats.spacing = SmallFont.GetHeight(); stats.screenbottomspace = bottomy; stats.statfont = SmallFont; stats.letterColor = TEXTCOLOR_RED; diff --git a/wadsrc/static/zscript/games/sw/ui/sbar.zs b/wadsrc/static/zscript/games/sw/ui/sbar.zs index 63d455ad5..d1897a761 100644 --- a/wadsrc/static/zscript/games/sw/ui/sbar.zs +++ b/wadsrc/static/zscript/games/sw/ui/sbar.zs @@ -859,25 +859,10 @@ class SWStatusBar : RazeStatusBar stats.letterColor = Font.TEXTCOLOR_SAPPHIRE; stats.standardColor = Font.TEXTCOLOR_UNTRANSLATED; - bool textfont = am_textfont; - if (!am_textfont) - { - // For non-English languages force use of the text font. The tiny one is simply too small to ever add localized characters to it. - let p = StringTable.Localize("$REQUIRED_CHARACTERS"); - if (p.length() > 0) - { - stats.statfont = Raze.PickSmallFont(); - textfont = true; - } - } - - if (!textfont) - { - stats.statfont = SmallFont2; - stats.spacing = 6; - } - else stats.spacing = SmallFont.GetHeight() + 1; - PrintAutomapInfo(stats, textfont); + stats.statfont = SmallFont2; + stats.spacing = 6; + stats.altspacing = SmallFont.GetHeight() + 1; + PrintAutomapInfo(stats, false); } // JBF 20040124: display level stats in screen corner else if (hud_stats && !(netgame /*|| numplayers > 1*/)) diff --git a/wadsrc/static/zscript/statusbar.zs b/wadsrc/static/zscript/statusbar.zs index f667b541b..0abfcc11d 100644 --- a/wadsrc/static/zscript/statusbar.zs +++ b/wadsrc/static/zscript/statusbar.zs @@ -4,6 +4,7 @@ struct StatsPrintInfo { int screenbottomspace; int spacing; // uses fontheight if 0 or less. + int altspacing; // in case a larger replacement font is needed. String letterColor, standardColor, completeColor; double fontscale; Font statfont; @@ -110,19 +111,40 @@ class RazeStatusBar : StatusBarCore void PrintAutomapInfo(StatsPrintInfo info, bool forcetextfont = false) { - let TEXTCOLOR_ESCAPESTR= "\034"; + let TEXTCOLOR_ESCAPESTR = "\034"; let lev = currentLevel; - String mapname; - if (am_showlabel) - mapname = String.Format("%s%s: %s%s", info.letterColor, lev.GetLabelName(), info.standardColor, lev.DisplayName()); - else - mapname = String.Format("%s%s", info.standardColor, lev.DisplayName()); + let levname = lev.DisplayName(); - forcetextfont |= am_textfont; + let cluster = lev.GetCluster(); + String volname; + if (cluster) volname = cluster.name; + + let allname = levname .. volname; + + double scale, spacing; + String tcol = info.standardColor; + Font myfont; + if (!forcetextfont && !am_textfont && info.statfont.CanPrint(allname)) + { + scale = info.fontscale; + spacing = info.spacing; + myfont = info.statfont; + } + else + { + scale = info.fontscale * hud_statscale; + spacing = info.altspacing * hud_statscale; + myfont = Raze.isNamWW2GI()? ConFont : Raze.PickSmallFont(allname); + } + + String mapname; + if (am_showlabel) mapname = String.Format("%s%s: %s%s", info.letterColor, lev.GetLabelName(), tcol, levname); + else mapname = String.Format("%s%s", tcol, levname); + + + + double y; - double scale = info.fontScale * (forcetextfont ? hud_statscale : 1); // the tiny default font used by all games here cannot be scaled for readability purposes. - if (info.spacing <= 0) info.spacing = info.statfont.GetHeight() * info.fontScale; - double spacing = info.spacing * (forcetextfont ? hud_statscale : 1); if (am_nameontop) { y = spacing + 1; @@ -135,16 +157,13 @@ class RazeStatusBar : StatusBarCore { y = 200 - info.screenbottomspace * hud_scalefactor - spacing; } - let cluster = lev.GetCluster(); - String volname; - if (cluster) volname = cluster.name; if (volname.length() == 0 && am_nameontop) y = 1; - Screen.DrawText(info.statfont, Font.CR_UNTRANSLATED, 2 * hud_statscale, y, mapname, DTA_FullscreenScale, FSMode_ScaleToHeight, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, + Screen.DrawText(myfont, Font.CR_UNTRANSLATED, 2 * hud_statscale, y, mapname, DTA_FullscreenScale, FSMode_ScaleToHeight, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_ScaleX, scale, DTA_ScaleY, scale, DTA_KeepRatio, true); y -= spacing; if (volname.length() > 0) - Screen.DrawText(info.statfont, Font.CR_UNTRANSLATED, 2 * hud_statscale, y, volname, DTA_FullscreenScale, FSMode_ScaleToHeight, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, + Screen.DrawText(myfont, Font.CR_UNTRANSLATED, 2 * hud_statscale, y, volname, DTA_FullscreenScale, FSMode_ScaleToHeight, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_ScaleX, scale, DTA_ScaleY, scale, DTA_KeepRatio, true); }