From 2f06c09681de7e00ee29ce49e56fbdfb86a69243 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Mar 2017 10:36:16 +0200 Subject: [PATCH] - fixed map name display on the automap HUD This would cut off overlong names and the handling for status bars with protruding elements was far too simplistic and worse, making assumptions based on game mode. It now uses a virtual function to query the status bar itself for returning this information so it can be overridden and uses V_BreakLines to split the text if it is wider than the display. --- src/g_statusbar/sbarinfo.cpp | 1 - src/g_statusbar/shared_sbar.cpp | 77 ++++++++----------- .../static/zscript/statusbar/heretic_sbar.txt | 5 ++ .../static/zscript/statusbar/hexen_sbar.txt | 5 ++ wadsrc/static/zscript/statusbar/statusbar.txt | 14 ++++ .../static/zscript/statusbar/strife_sbar.txt | 5 ++ 6 files changed, 61 insertions(+), 46 deletions(-) diff --git a/src/g_statusbar/sbarinfo.cpp b/src/g_statusbar/sbarinfo.cpp index 8c775dd84c..a28205ae26 100644 --- a/src/g_statusbar/sbarinfo.cpp +++ b/src/g_statusbar/sbarinfo.cpp @@ -1586,7 +1586,6 @@ DBaseStatusBar *CreateCustomStatusBar(int scriptno) auto core = new DSBarInfo(sbar, script); sbar->PointerVar("core") = core; sbar->SetSize(script->height, script->_resW, script->_resH); - sbar->SetScaled(sbar->Scaled); sbar->CompleteBorder = script->completeBorder; return sbar; } diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index f6b0644ccf..a5ed1f78a8 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -1025,63 +1025,50 @@ void DBaseStatusBar::Draw (EHudState state) EColorRange highlight = (gameinfo.gametype & GAME_DoomChex) ? CR_UNTRANSLATED : CR_YELLOW; - height = SmallFont->GetHeight () * CleanYfac; + height = SmallFont->GetHeight() * CleanYfac; // Draw timer y = 8; if (am_showtime) { - mysnprintf (line, countof(line), "%02d:%02d:%02d", time/3600, (time%3600)/60, time%60); // Time - screen->DrawText (SmallFont, CR_GREY, SCREENWIDTH - 80*CleanXfac, y, line, DTA_CleanNoMove, true, TAG_DONE); - y+=8*CleanYfac; + mysnprintf(line, countof(line), "%02d:%02d:%02d", time / 3600, (time % 3600) / 60, time % 60); // Time + screen->DrawText(SmallFont, CR_GREY, SCREENWIDTH - 80 * CleanXfac, y, line, DTA_CleanNoMove, true, TAG_DONE); + y += 8 * CleanYfac; } if (am_showtotaltime) { - mysnprintf (line, countof(line), "%02d:%02d:%02d", totaltime/3600, (totaltime%3600)/60, totaltime%60); // Total time - screen->DrawText (SmallFont, CR_GREY, SCREENWIDTH - 80*CleanXfac, y, line, DTA_CleanNoMove, true, TAG_DONE); + mysnprintf(line, countof(line), "%02d:%02d:%02d", totaltime / 3600, (totaltime % 3600) / 60, totaltime % 60); // Total time + screen->DrawText(SmallFont, CR_GREY, SCREENWIDTH - 80 * CleanXfac, y, line, DTA_CleanNoMove, true, TAG_DONE); } + FString mapname; + unsigned int numlines; + ST_FormatMapName(mapname, TEXTCOLOR_GREY); + int width = SmallFont->StringWidth(mapname); + FBrokenLines *lines = V_BreakLines(SmallFont, SCREENWIDTH / CleanXfac, mapname, true, &numlines); + int finalwidth = lines[numlines - 1].Width * CleanXfac; + double tmp = 0; + double hres = HorizontalResolution; + StatusbarToRealCoords(tmp, tmp, hres, tmp); + int protrusion = 0; + + IFVIRTUAL(DBaseStatusBar, GetProtrusion) + { + VMValue params[] = { (DObject*)this, finalwidth / hres }; + VMReturn ret(&protrusion); + GlobalVMStack.Call(func, params, 2, &ret, 1); + } + hres = protrusion; + StatusbarToRealCoords(tmp, tmp, tmp, hres); + // Draw map name - y = gST_Y - height; - if (gameinfo.gametype == GAME_Heretic && SCREENWIDTH > 320 && !Scaled) - { - y -= 8; - } - else if (gameinfo.gametype == GAME_Hexen) - { - if (Scaled) - { - y -= Scale (11, SCREENHEIGHT, 200); - } - else - { - if (SCREENWIDTH < 640) - { - y -= 12; - } - else - { // Get past the tops of the gargoyles' wings - y -= 28; - } - } - } - else if (gameinfo.gametype == GAME_Strife) - { - if (Scaled) - { - y -= Scale (8, SCREENHEIGHT, 200); - } - else - { - y -= 8; - } - } - FString mapname; + y = gST_Y - height * numlines - int(hres); - ST_FormatMapName(mapname, TEXTCOLOR_GREY); - screen->DrawText (SmallFont, highlight, - (SCREENWIDTH - SmallFont->StringWidth (mapname)*CleanXfac)/2, y, mapname, - DTA_CleanNoMove, true, TAG_DONE); + for(unsigned i = 0; i < numlines; i++) + { + screen->DrawText(SmallFont, highlight, (SCREENWIDTH - lines[i].Width * CleanXfac) / 2, y, lines[i].Text, DTA_CleanNoMove, true, TAG_DONE); + y += height; + } if (!deathmatch) { diff --git a/wadsrc/static/zscript/statusbar/heretic_sbar.txt b/wadsrc/static/zscript/statusbar/heretic_sbar.txt index 1273ad4ce1..821621d97e 100644 --- a/wadsrc/static/zscript/statusbar/heretic_sbar.txt +++ b/wadsrc/static/zscript/statusbar/heretic_sbar.txt @@ -25,6 +25,11 @@ class HereticStatusBar : BaseStatusBar mHealthInterpolator = DynamicValueInterpolator.Create(0, 0.25, 1, 8); } + override int GetProtrusion(double scaleratio) const + { + return scaleratio > 0.7? 8 : 0; + } + override void NewGame () { Super.NewGame(); diff --git a/wadsrc/static/zscript/statusbar/hexen_sbar.txt b/wadsrc/static/zscript/statusbar/hexen_sbar.txt index f1ff81693d..f88c70070f 100644 --- a/wadsrc/static/zscript/statusbar/hexen_sbar.txt +++ b/wadsrc/static/zscript/statusbar/hexen_sbar.txt @@ -34,6 +34,11 @@ class HexenStatusBar : BaseStatusBar mHealthInterpolator2.Reset (0); } + override int GetProtrusion(double scaleratio) const + { + return scaleratio > 0.85? 20 : 12; // need to get past the gargoyle's wings + } + override void Tick() { Super.Tick(); diff --git a/wadsrc/static/zscript/statusbar/statusbar.txt b/wadsrc/static/zscript/statusbar/statusbar.txt index 01fbcc7aee..7ce351c748 100644 --- a/wadsrc/static/zscript/statusbar/statusbar.txt +++ b/wadsrc/static/zscript/statusbar/statusbar.txt @@ -381,6 +381,20 @@ class BaseStatusBar native ui return icon, scale; } + //============================================================================ + // + // Returns how much the status bar's graphics extend into the view + // Used for automap text positioning + // The parameter specifies how much of the status bar area will be covered + // by the element requesting this information. + // + //============================================================================ + + virtual int GetProtrusion(double scaleratio) const + { + return 0; + } + //============================================================================ // // Convenience functions to retrieve item tags diff --git a/wadsrc/static/zscript/statusbar/strife_sbar.txt b/wadsrc/static/zscript/statusbar/strife_sbar.txt index 148b1e2371..c302eebe0e 100644 --- a/wadsrc/static/zscript/statusbar/strife_sbar.txt +++ b/wadsrc/static/zscript/statusbar/strife_sbar.txt @@ -74,6 +74,11 @@ class StrifeStatusBar : BaseStatusBar Reset (); } + override int GetProtrusion(double scaleratio) const + { + return 8; + } + override void Draw (int state, double TicFrac) { Super.Draw (state, TicFrac);