- 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.
This commit is contained in:
Christoph Oelckers 2017-03-29 10:36:16 +02:00
parent fabf8451e7
commit 2f06c09681
6 changed files with 61 additions and 46 deletions

View file

@ -1586,7 +1586,6 @@ DBaseStatusBar *CreateCustomStatusBar(int scriptno)
auto core = new DSBarInfo(sbar, script);
sbar->PointerVar<DSBarInfo>("core") = core;
sbar->SetSize(script->height, script->_resW, script->_resH);
sbar->SetScaled(sbar->Scaled);
sbar->CompleteBorder = script->completeBorder;
return sbar;
}

View file

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

View file

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

View file

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

View file

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

View file

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