Skip to content

Commit

Permalink
- allow all DHUDMessage calls to substitute SmallFont
Browse files Browse the repository at this point in the history
This is a preparation for setting a generic HUD mode where all these should be able to use the VGA font instead, and not just C_MidPrint.
  • Loading branch information
coelckers committed Apr 9, 2019
1 parent 8b0dd13 commit fe37c3b
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 47 deletions.
42 changes: 23 additions & 19 deletions src/c_console.cpp
Expand Up @@ -79,8 +79,20 @@ CUSTOM_CVAR(Int, con_buffersize, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
if (self >= 0 && self < 128) self = 128;
}

CVAR(Bool, con_consolefont, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Bool, con_midconsolefont, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
bool generic_hud, generic_ui;

EXTERN_CVAR(Bool, ui_generic)

CUSTOM_CVAR(Bool, hud_generic, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // All HUD elements only use generic assets
{
generic_hud = self || ui_generic;
}

CUSTOM_CVAR(Bool, ui_generic, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // The entire UI uses generic assets (this excludes the primary menus)
{
generic_ui = self;
generic_hud = self || hud_generic;
}

FConsoleBuffer *conbuffer;

Expand Down Expand Up @@ -782,9 +794,10 @@ void FNotifyBuffer::AddString(int printlevel, FString source)
con_notifylines == 0)
return;

width = DisplayWidth / active_con_scaletext(con_consolefont);
width = DisplayWidth / active_con_scaletext(hud_generic);

FFont *font = *con_consolefont ? NewSmallFont : SmallFont;
FFont *font = hud_generic ? NewSmallFont : SmallFont;
if (font == nullptr) return; // Without an initialized font we cannot handle the message (this is for those which come here before the font system is ready.)

if (AddType == APPENDLINE && Text.Size() > 0 && Text[Text.Size() - 1].PrintLevel == printlevel)
{
Expand Down Expand Up @@ -897,7 +910,7 @@ int PrintString (int iprintlevel, const char *outline)
I_PrintStr(outline);

conbuffer->AddText(printlevel, outline);
if (vidactive && screen && SmallFont && !(iprintlevel & PRINT_NONOTIFY))
if (vidactive && screen && !(iprintlevel & PRINT_NONOTIFY))
{
NotifyStrings.AddString(printlevel, outline);
}
Expand Down Expand Up @@ -1067,7 +1080,7 @@ void FNotifyBuffer::Draw()
line = Top;
canskip = true;

FFont *font = *con_consolefont ? NewSmallFont : SmallFont;
FFont *font = hud_generic ? NewSmallFont : SmallFont;
lineadv = font->GetHeight ();

for (unsigned i = 0; i < Text.Size(); ++ i)
Expand All @@ -1090,11 +1103,11 @@ void FNotifyBuffer::Draw()
else
color = PrintColors[notify.PrintLevel];

if (color == CR_UNTRANSLATED && *con_consolefont)
if (color == CR_UNTRANSLATED && hud_generic)
{
color = C_GetDefaultFontColor();
}
int scale = active_con_scaletext(con_consolefont);
int scale = active_con_scaletext(hud_generic);
if (!center)
screen->DrawText (font, color, 0, line, notify.Text,
DTA_VirtualWidth, screen->GetWidth() / scale,
Expand All @@ -1103,7 +1116,7 @@ void FNotifyBuffer::Draw()
DTA_Alpha, alpha, TAG_DONE);
else
screen->DrawText (font, color, (screen->GetWidth() -
SmallFont->StringWidth (notify.Text) * scale) / 2 / scale,
font->StringWidth (notify.Text) * scale) / 2 / scale,
line, notify.Text,
DTA_VirtualWidth, screen->GetWidth() / scale,
DTA_VirtualHeight, screen->GetHeight() / scale,
Expand Down Expand Up @@ -1756,16 +1769,7 @@ void C_MidPrint (FFont *font, const char *msg, bool bold)
auto color = (EColorRange)PrintColors[bold? PRINTLEVELS+1 : PRINTLEVELS];
Printf(PRINT_HIGH|PRINT_NONOTIFY, TEXTCOLOR_ESCAPESTR "%c%s\n%s\n%s\n", color, console_bar, msg, console_bar);

bool altscale = false;
if (font == nullptr)
{
altscale = con_midconsolefont;
font = altscale ? NewSmallFont : SmallFont;
if (altscale && color == CR_UNTRANSLATED) color = C_GetDefaultFontColor();
}

StatusBar->AttachMessage (Create<DHUDMessage>(font, msg, 1.5f, 0.375f, 0, 0,
color, con_midtime, altscale), MAKE_ID('C','N','T','R'));
StatusBar->AttachMessage (Create<DHUDMessage>(font, msg, 1.5f, 0.375f, 0, 0, color, con_midtime), MAKE_ID('C','N','T','R'));
}
else
{
Expand Down
7 changes: 0 additions & 7 deletions src/d_main.cpp
Expand Up @@ -1075,13 +1075,6 @@ void D_PageDrawer (void)
DTA_BilinearFilter, true,
TAG_DONE);
}
else
{
if (!PageBlank)
{
screen->DrawText (SmallFont, CR_WHITE, 0, 0, "Page graphic goes here", TAG_DONE);
}
}
if (Advisory != NULL)
{
screen->DrawTexture (Advisory, 4, 160, DTA_320x200, true, TAG_DONE);
Expand Down
2 changes: 2 additions & 0 deletions src/doomstat.h
Expand Up @@ -253,4 +253,6 @@ EXTERN_CVAR (Int, compatflags2);
// Filters from AddAutoloadFiles(). Used to filter files from archives.
extern FString LumpFilterIWAD;

// These control whether certain items use generic text output instead of game-specific one.
extern bool generic_hud, generic_ui;
#endif
6 changes: 3 additions & 3 deletions src/g_game.cpp
Expand Up @@ -350,7 +350,7 @@ CCMD (weapnext)
// [BC] Option to display the name of the weapon being cycled to.
if ((displaynametags & 2) && StatusBar && SmallFont && SendItemUse)
{
StatusBar->AttachMessage(Create<DHUDMessageFadeOut>(SmallFont, SendItemUse->GetTag(),
StatusBar->AttachMessage(Create<DHUDMessageFadeOut>(nullptr, SendItemUse->GetTag(),
1.5f, 0.90f, 0, 0, (EColorRange)*nametagcolor, 2.f, 0.35f), MAKE_ID( 'W', 'E', 'P', 'N' ));
}
if (SendItemUse != players[consoleplayer].ReadyWeapon)
Expand All @@ -376,7 +376,7 @@ CCMD (weapprev)
// [BC] Option to display the name of the weapon being cycled to.
if ((displaynametags & 2) && StatusBar && SmallFont && SendItemUse)
{
StatusBar->AttachMessage(Create<DHUDMessageFadeOut>(SmallFont, SendItemUse->GetTag(),
StatusBar->AttachMessage(Create<DHUDMessageFadeOut>(nullptr, SendItemUse->GetTag(),
1.5f, 0.90f, 0, 0, (EColorRange)*nametagcolor, 2.f, 0.35f), MAKE_ID( 'W', 'E', 'P', 'N' ));
}
if (SendItemUse != players[consoleplayer].ReadyWeapon)
Expand All @@ -389,7 +389,7 @@ static void DisplayNameTag(AActor *actor)
{
auto tag = actor->GetTag();
if ((displaynametags & 1) && StatusBar && SmallFont)
StatusBar->AttachMessage(Create<DHUDMessageFadeOut>(SmallFont, tag,
StatusBar->AttachMessage(Create<DHUDMessageFadeOut>(nullptr, tag,
1.5f, 0.80f, 0, 0, (EColorRange)*nametagcolor, 2.f, 0.35f), MAKE_ID('S', 'I', 'N', 'V'));

}
Expand Down
15 changes: 10 additions & 5 deletions src/g_statusbar/hudmessages.cpp
Expand Up @@ -39,8 +39,11 @@
#include "v_video.h"
#include "cmdlib.h"
#include "serializer.h"
#include "doomstat.h"
#include "vm.h"

EColorRange C_GetDefaultFontColor();

EXTERN_CVAR(Int, con_scaletext)

IMPLEMENT_CLASS(DHUDMessageBase, false, true)
Expand Down Expand Up @@ -128,7 +131,7 @@ void DHUDMessageBase::CallDraw(int bottom, int visibility)
//============================================================================

DHUDMessage::DHUDMessage (FFont *font, const char *text, float x, float y, int hudwidth, int hudheight,
EColorRange textColor, float holdTime, bool altscale)
EColorRange textColor, float holdTime)
{
if (hudwidth == 0 || hudheight == 0)
{
Expand All @@ -139,7 +142,7 @@ DHUDMessage::DHUDMessage (FFont *font, const char *text, float x, float y, int h
// for x range [0.0, 1.0]: Positions center of box
// for x range [1.0, 2.0]: Positions center of box, and centers text inside it
HUDWidth = HUDHeight = 0;
AltScale = altscale;
AltScale = font == nullptr && generic_hud; // generic_hud only takes effect for messages that do not scale the screen and use the default font.
if (fabs (x) > 2.f)
{
CenterX = true;
Expand Down Expand Up @@ -197,10 +200,11 @@ DHUDMessage::DHUDMessage (FFont *font, const char *text, float x, float y, int h
Top = y;
HoldTics = (int)(holdTime * TICRATE);
Tics = -1; // -1 to compensate for one additional Tick the message will receive.
TextColor = textColor;
Font = font? font : AltScale? NewSmallFont : SmallFont;
if (Font == NewSmallFont && textColor == CR_UNTRANSLATED) TextColor = C_GetDefaultFontColor();
else TextColor = textColor;
State = 0;
SourceText = copystring (text);
Font = font;
VisibilityFlags = 0;
Style = STYLE_Translucent;
Alpha = 1.;
Expand Down Expand Up @@ -251,7 +255,8 @@ void DHUDMessage::Serialize(FSerializer &arc)
("handleaspect", HandleAspect)
("visibilityflags", VisibilityFlags)
("style", Style)
("alpha", Alpha);
("alpha", Alpha)
("altscale", AltScale);

if (arc.isReading())
{
Expand Down
4 changes: 2 additions & 2 deletions src/g_statusbar/sbar.h
Expand Up @@ -84,7 +84,7 @@ class DHUDMessage : public DHUDMessageBase
DECLARE_CLASS (DHUDMessage, DHUDMessageBase)
public:
DHUDMessage (FFont *font, const char *text, float x, float y, int hudwidth, int hudheight,
EColorRange textColor, float holdTime, bool altscale = false);
EColorRange textColor, float holdTime);
virtual void OnDestroy () override;

virtual void Serialize(FSerializer &arc);
Expand Down Expand Up @@ -207,7 +207,7 @@ class DHUDMessageTypeOnFadeOut : public DHUDMessageFadeOut
DECLARE_CLASS (DHUDMessageTypeOnFadeOut, DHUDMessageFadeOut)
public:
DHUDMessageTypeOnFadeOut (FFont *font, const char *text, float x, float y, int hudwidth, int hudheight,
EColorRange textColor, float typeTime, float holdTime, float fadeOutTime);
EColorRange textColor, float typeTime, float holdTime, float fadeOutTimee);

virtual void Serialize(FSerializer &arc);
virtual void DoDraw (int linenum, int x, int y, bool clean, int hudheight);
Expand Down
2 changes: 1 addition & 1 deletion src/g_statusbar/shared_sbar.cpp
Expand Up @@ -754,7 +754,7 @@ void DBaseStatusBar::ShowPlayerName ()
EColorRange color;

color = (CPlayer == &players[consoleplayer]) ? CR_GOLD : CR_GREEN;
AttachMessage (Create<DHUDMessageFadeOut> (SmallFont, CPlayer->userinfo.GetName(),
AttachMessage (Create<DHUDMessageFadeOut> (nullptr, CPlayer->userinfo.GetName(),
1.5f, 0.92f, 0, 0, color, 2.f, 0.35f), MAKE_ID('P','N','A','M'));
}

Expand Down
9 changes: 4 additions & 5 deletions src/p_acs.cpp
Expand Up @@ -8662,34 +8662,33 @@ int DLevelScript::RunScript()
color = CLAMPCOLOR(Stack[optstart-4]);
}

FFont *font = activefont ? activefont : SmallFont;
switch (type & 0xFF)
{
default: // normal
alpha = (optstart < sp) ? ACSToFloat(Stack[optstart]) : 1.f;
msg = Create<DHUDMessage> (font, work, x, y, hudwidth, hudheight, color, holdTime);
msg = Create<DHUDMessage> (activefont, work, x, y, hudwidth, hudheight, color, holdTime);
break;
case 1: // fade out
{
float fadeTime = (optstart < sp) ? ACSToFloat(Stack[optstart]) : 0.5f;
alpha = (optstart < sp-1) ? ACSToFloat(Stack[optstart+1]) : 1.f;
msg = Create<DHUDMessageFadeOut> (font, work, x, y, hudwidth, hudheight, color, holdTime, fadeTime);
msg = Create<DHUDMessageFadeOut> (activefont, work, x, y, hudwidth, hudheight, color, holdTime, fadeTime);
}
break;
case 2: // type on, then fade out
{
float typeTime = (optstart < sp) ? ACSToFloat(Stack[optstart]) : 0.05f;
float fadeTime = (optstart < sp-1) ? ACSToFloat(Stack[optstart+1]) : 0.5f;
alpha = (optstart < sp-2) ? ACSToFloat(Stack[optstart+2]) : 1.f;
msg = Create<DHUDMessageTypeOnFadeOut> (font, work, x, y, hudwidth, hudheight, color, typeTime, holdTime, fadeTime);
msg = Create<DHUDMessageTypeOnFadeOut> (activefont, work, x, y, hudwidth, hudheight, color, typeTime, holdTime, fadeTime);
}
break;
case 3: // fade in, then fade out
{
float inTime = (optstart < sp) ? ACSToFloat(Stack[optstart]) : 0.5f;
float outTime = (optstart < sp-1) ? ACSToFloat(Stack[optstart+1]) : 0.5f;
alpha = (optstart < sp-2) ? ACSToFloat(Stack[optstart + 2]) : 1.f;
msg = Create<DHUDMessageFadeInOut> (font, work, x, y, hudwidth, hudheight, color, holdTime, inTime, outTime);
msg = Create<DHUDMessageFadeInOut> (activefont, work, x, y, hudwidth, hudheight, color, holdTime, inTime, outTime);
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/p_conversation.cpp
Expand Up @@ -700,7 +700,7 @@ static void TerminalResponse (const char *str)
// merchants can tell you something like this but continue to show
// their dialogue screen. I think most other conversations use this
// only as a response for terminating the dialogue.
StatusBar->AttachMessage(Create<DHUDMessageFadeOut>(SmallFont, str,
StatusBar->AttachMessage(Create<DHUDMessageFadeOut>(nullptr, str,
float(CleanWidth/2) + 0.4f, float(ConversationMenuY - 110 + CleanHeight/2), CleanWidth, -CleanHeight,
CR_UNTRANSLATED, 3.f, 1.f), MAKE_ID('T','A','L','K'));
}
Expand Down
8 changes: 4 additions & 4 deletions src/p_interaction.cpp
Expand Up @@ -412,7 +412,7 @@ void AActor::Die (AActor *source, AActor *inflictor, int dmgflags, FName MeansOf
PronounMessage (GStrings("SPREEKILLSELF"), buff,
player->userinfo.GetGender(), player->userinfo.GetName(),
player->userinfo.GetName());
StatusBar->AttachMessage (Create<DHUDMessageFadeOut>(SmallFont, buff,
StatusBar->AttachMessage (Create<DHUDMessageFadeOut>(nullptr, buff,
1.5f, 0.2f, 0, 0, CR_WHITE, 3.f, 0.5f), MAKE_ID('K','S','P','R'));
}
}
Expand Down Expand Up @@ -469,7 +469,7 @@ void AActor::Die (AActor *source, AActor *inflictor, int dmgflags, FName MeansOf
{
PronounMessage (GStrings("SPREEOVER"), buff, player->userinfo.GetGender(),
player->userinfo.GetName(), source->player->userinfo.GetName());
StatusBar->AttachMessage (Create<DHUDMessageFadeOut> (SmallFont, buff,
StatusBar->AttachMessage (Create<DHUDMessageFadeOut> (nullptr, buff,
1.5f, 0.2f, 0, 0, CR_WHITE, 3.f, 0.5f), MAKE_ID('K','S','P','R'));
}
}
Expand All @@ -479,7 +479,7 @@ void AActor::Die (AActor *source, AActor *inflictor, int dmgflags, FName MeansOf
{
PronounMessage (spreemsg, buff, player->userinfo.GetGender(),
player->userinfo.GetName(), source->player->userinfo.GetName());
StatusBar->AttachMessage (Create<DHUDMessageFadeOut> (SmallFont, buff,
StatusBar->AttachMessage (Create<DHUDMessageFadeOut> (nullptr, buff,
1.5f, 0.2f, 0, 0, CR_WHITE, 3.f, 0.5f), MAKE_ID('K','S','P','R'));
}
}
Expand Down Expand Up @@ -529,7 +529,7 @@ void AActor::Die (AActor *source, AActor *inflictor, int dmgflags, FName MeansOf
{
PronounMessage (multimsg, buff, player->userinfo.GetGender(),
player->userinfo.GetName(), source->player->userinfo.GetName());
StatusBar->AttachMessage (Create<DHUDMessageFadeOut> (SmallFont, buff,
StatusBar->AttachMessage (Create<DHUDMessageFadeOut> (nullptr, buff,
1.5f, 0.8f, 0, 0, CR_RED, 3.f, 0.5f), MAKE_ID('M','K','I','L'));
}
}
Expand Down

0 comments on commit fe37c3b

Please sign in to comment.