- cleanup of automap label printing.

Moved larger parts of the font selection logic into common code.
This commit is contained in:
Christoph Oelckers 2021-05-31 12:32:40 +02:00
parent ee60a92b69
commit 8900cc2f2e
6 changed files with 56 additions and 83 deletions

View file

@ -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);
}

View file

@ -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)
{

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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*/))

View file

@ -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);
}