- 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

@ -1041,47 +1041,34 @@ void DBaseStatusBar::Draw (EHudState state)
screen->DrawText(SmallFont, CR_GREY, SCREENWIDTH - 80 * CleanXfac, y, line, DTA_CleanNoMove, true, TAG_DONE);
}
// 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;
unsigned int numlines;
ST_FormatMapName(mapname, TEXTCOLOR_GREY);
screen->DrawText (SmallFont, highlight,
(SCREENWIDTH - SmallFont->StringWidth (mapname)*CleanXfac)/2, y, mapname,
DTA_CleanNoMove, true, TAG_DONE);
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 * numlines - int(hres);
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);