- added an option to use the new console font for centered messages.

Like the notification messages, this is optional to not affect existing settings.
This commit is contained in:
Christoph Oelckers 2019-03-11 19:54:03 +01:00
parent ed1615babb
commit 60c5350e8b
10 changed files with 60 additions and 39 deletions

View file

@ -80,6 +80,7 @@ CUSTOM_CVAR(Int, con_buffersize, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
} }
CVAR(Bool, con_consolefont, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, con_consolefont, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Bool, con_midconsolefont, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
FConsoleBuffer *conbuffer; FConsoleBuffer *conbuffer;
@ -628,6 +629,12 @@ void DequeueConsoleText ()
EnqueuedTextTail = &EnqueuedText; EnqueuedTextTail = &EnqueuedText;
} }
EColorRange C_GetDefaultFontColor()
{
// Ideally this should analyze the SmallFont and pick a matching color.
return gameinfo.gametype == GAME_Doom ? CR_RED : gameinfo.gametype == GAME_Chex ? CR_GREEN : gameinfo.gametype == GAME_Strife ? CR_GOLD : CR_GRAY;
}
void C_InitConback() void C_InitConback()
{ {
conback = TexMan.CheckForTexture ("CONBACK", ETextureType::MiscPatch); conback = TexMan.CheckForTexture ("CONBACK", ETextureType::MiscPatch);
@ -1097,8 +1104,7 @@ void FNotifyBuffer::Draw()
if (color == CR_UNTRANSLATED && *con_consolefont) if (color == CR_UNTRANSLATED && *con_consolefont)
{ {
// Ideally this should analyze the SmallFont and pick a matching color. color = C_GetDefaultFontColor();
color = gameinfo.gametype == GAME_Doom ? CR_RED : gameinfo.gametype == GAME_Chex ? CR_GREEN : gameinfo.gametype == GAME_Strife ? CR_GOLD : CR_GRAY;
} }
int scale = active_con_scaletext(con_consolefont); int scale = active_con_scaletext(con_consolefont);
if (!center) if (!center)
@ -1772,8 +1778,18 @@ void C_MidPrint (FFont *font, const char *msg)
AddToConsole (-1, msg); AddToConsole (-1, msg);
AddToConsole (-1, bar3); AddToConsole (-1, bar3);
auto color = (EColorRange)PrintColors[PRINTLEVELS];
bool altscale = false;
if (font == nullptr)
{
altscale = con_midconsolefont;
font = altscale ? NewConsoleFont : SmallFont;
if (altscale && color == CR_UNTRANSLATED) color = C_GetDefaultFontColor();
}
StatusBar->AttachMessage (Create<DHUDMessage>(font, msg, 1.5f, 0.375f, 0, 0, StatusBar->AttachMessage (Create<DHUDMessage>(font, msg, 1.5f, 0.375f, 0, 0,
(EColorRange)PrintColors[PRINTLEVELS], con_midtime), MAKE_ID('C','N','T','R')); color, con_midtime, altscale), MAKE_ID('C','N','T','R'));
} }
else else
{ {
@ -1789,8 +1805,17 @@ void C_MidPrintBold (FFont *font, const char *msg)
AddToConsole (-1, msg); AddToConsole (-1, msg);
AddToConsole (-1, bar3); AddToConsole (-1, bar3);
auto color = (EColorRange)PrintColors[PRINTLEVELS+1];
bool altscale = false;
if (font == nullptr)
{
altscale = con_midconsolefont;
font = altscale ? NewConsoleFont : SmallFont;
if (altscale && color == CR_UNTRANSLATED) color = C_GetDefaultFontColor();
}
StatusBar->AttachMessage (Create<DHUDMessage> (font, msg, 1.5f, 0.375f, 0, 0, StatusBar->AttachMessage (Create<DHUDMessage> (font, msg, 1.5f, 0.375f, 0, 0,
(EColorRange)PrintColors[PRINTLEVELS+1], con_midtime), MAKE_ID('C','N','T','R')); color, con_midtime, altscale), MAKE_ID('C','N','T','R'));
} }
else else
{ {
@ -1801,7 +1826,7 @@ void C_MidPrintBold (FFont *font, const char *msg)
DEFINE_ACTION_FUNCTION(_Console, MidPrint) DEFINE_ACTION_FUNCTION(_Console, MidPrint)
{ {
PARAM_PROLOGUE; PARAM_PROLOGUE;
PARAM_POINTER_NOT_NULL(fnt, FFont); PARAM_POINTER(fnt, FFont);
PARAM_STRING(text); PARAM_STRING(text);
PARAM_BOOL(bold); PARAM_BOOL(bold);

View file

@ -47,7 +47,10 @@ typedef enum cstate_t
} }
constate_e; constate_e;
#define PRINTLEVELS 5 enum
{
PRINTLEVELS = 5
};
extern int PrintColors[PRINTLEVELS + 2]; extern int PrintColors[PRINTLEVELS + 2];
extern constate_e ConsoleState; extern constate_e ConsoleState;

View file

@ -2169,7 +2169,7 @@ void Net_DoCommand (int type, uint8_t **stream, int player)
case DEM_CENTERPRINT: case DEM_CENTERPRINT:
s = ReadString (stream); s = ReadString (stream);
C_MidPrint (SmallFont, s); C_MidPrint (nullptr, s);
break; break;
case DEM_UINFCHANGED: case DEM_UINFCHANGED:

View file

@ -623,7 +623,7 @@ void FParser::SF_Tip(void)
if (t_argc>0 && Script->trigger && if (t_argc>0 && Script->trigger &&
Script->trigger->CheckLocalView()) Script->trigger->CheckLocalView())
{ {
C_MidPrint(SmallFont, GetFormatString(0).GetChars()); C_MidPrint(nullptr, GetFormatString(0).GetChars());
} }
} }
@ -643,7 +643,7 @@ void FParser::SF_TimedTip(void)
{ {
float saved = con_midtime; float saved = con_midtime;
con_midtime = intvalue(t_argv[0])/100.0f; con_midtime = intvalue(t_argv[0])/100.0f;
C_MidPrint(SmallFont, GetFormatString(1).GetChars()); C_MidPrint(nullptr, GetFormatString(1).GetChars());
con_midtime=saved; con_midtime=saved;
} }
} }
@ -662,7 +662,7 @@ void FParser::SF_PlayerTip(void)
int plnum = T_GetPlayerNum(t_argv[0]); int plnum = T_GetPlayerNum(t_argv[0]);
if (plnum!=-1 && Level->Players[plnum]->mo->CheckLocalView()) if (plnum!=-1 && Level->Players[plnum]->mo->CheckLocalView())
{ {
C_MidPrint(SmallFont, GetFormatString(1).GetChars()); C_MidPrint(nullptr, GetFormatString(1).GetChars());
} }
} }
} }

View file

@ -128,7 +128,7 @@ void DHUDMessageBase::CallDraw(int bottom, int visibility)
//============================================================================ //============================================================================
DHUDMessage::DHUDMessage (FFont *font, const char *text, float x, float y, int hudwidth, int hudheight, DHUDMessage::DHUDMessage (FFont *font, const char *text, float x, float y, int hudwidth, int hudheight,
EColorRange textColor, float holdTime) EColorRange textColor, float holdTime, bool altscale)
{ {
if (hudwidth == 0 || hudheight == 0) if (hudwidth == 0 || hudheight == 0)
{ {
@ -139,6 +139,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 [0.0, 1.0]: Positions center of box
// for x range [1.0, 2.0]: Positions center of box, and centers text inside it // for x range [1.0, 2.0]: Positions center of box, and centers text inside it
HUDWidth = HUDHeight = 0; HUDWidth = HUDHeight = 0;
AltScale = altscale;
if (fabs (x) > 2.f) if (fabs (x) > 2.f)
{ {
CenterX = true; CenterX = true;
@ -319,7 +320,7 @@ void DHUDMessage::ResetText (const char *text)
} }
else else
{ {
width = SCREENWIDTH / active_con_scaletext(); width = SCREENWIDTH / active_con_scaletext(AltScale);
} }
Lines = V_BreakLines (Font, NoWrap ? INT_MAX : width, (uint8_t *)text); Lines = V_BreakLines (Font, NoWrap ? INT_MAX : width, (uint8_t *)text);
@ -379,7 +380,7 @@ void DHUDMessage::Draw (int bottom, int visibility)
xscale = yscale = 1; xscale = yscale = 1;
if (HUDWidth == 0) if (HUDWidth == 0)
{ {
int scale = active_con_scaletext(); int scale = active_con_scaletext(AltScale);
screen_width /= scale; screen_width /= scale;
screen_height /= scale; screen_height /= scale;
bottom /= scale; bottom /= scale;
@ -483,7 +484,7 @@ void DHUDMessage::DoDraw (int linenum, int x, int y, bool clean, int hudheight)
{ {
if (hudheight == 0) if (hudheight == 0)
{ {
int scale = active_con_scaletext(); int scale = active_con_scaletext(AltScale);
screen->DrawText (Font, TextColor, x, y, Lines[linenum].Text, screen->DrawText (Font, TextColor, x, y, Lines[linenum].Text,
DTA_VirtualWidth, SCREENWIDTH / scale, DTA_VirtualWidth, SCREENWIDTH / scale,
DTA_VirtualHeight, SCREENHEIGHT / scale, DTA_VirtualHeight, SCREENHEIGHT / scale,
@ -576,7 +577,7 @@ void DHUDMessageFadeOut::DoDraw (int linenum, int x, int y, bool clean, int hudh
float trans = float(Alpha * -(Tics - FadeOutTics) / FadeOutTics); float trans = float(Alpha * -(Tics - FadeOutTics) / FadeOutTics);
if (hudheight == 0) if (hudheight == 0)
{ {
int scale = active_con_scaletext(); int scale = active_con_scaletext(AltScale);
screen->DrawText (Font, TextColor, x, y, Lines[linenum].Text, screen->DrawText (Font, TextColor, x, y, Lines[linenum].Text,
DTA_VirtualWidth, SCREENWIDTH / scale, DTA_VirtualWidth, SCREENWIDTH / scale,
DTA_VirtualHeight, SCREENHEIGHT / scale, DTA_VirtualHeight, SCREENHEIGHT / scale,
@ -665,7 +666,7 @@ void DHUDMessageFadeInOut::DoDraw (int linenum, int x, int y, bool clean, int hu
float trans = float(Alpha * Tics / FadeInTics); float trans = float(Alpha * Tics / FadeInTics);
if (hudheight == 0) if (hudheight == 0)
{ {
int scale = active_con_scaletext(); int scale = active_con_scaletext(AltScale);
screen->DrawText (Font, TextColor, x, y, Lines[linenum].Text, screen->DrawText (Font, TextColor, x, y, Lines[linenum].Text,
DTA_VirtualWidth, SCREENWIDTH / scale, DTA_VirtualWidth, SCREENWIDTH / scale,
DTA_VirtualHeight, SCREENHEIGHT / scale, DTA_VirtualHeight, SCREENHEIGHT / scale,
@ -836,7 +837,7 @@ void DHUDMessageTypeOnFadeOut::DoDraw (int linenum, int x, int y, bool clean, in
{ {
if (hudheight == 0) if (hudheight == 0)
{ {
int scale = active_con_scaletext(); int scale = active_con_scaletext(AltScale);
screen->DrawText (Font, TextColor, x, y, Lines[linenum].Text, screen->DrawText (Font, TextColor, x, y, Lines[linenum].Text,
DTA_VirtualWidth, SCREENWIDTH / scale, DTA_VirtualWidth, SCREENWIDTH / scale,
DTA_VirtualHeight, SCREENHEIGHT / scale, DTA_VirtualHeight, SCREENHEIGHT / scale,

View file

@ -84,7 +84,7 @@ class DHUDMessage : public DHUDMessageBase
DECLARE_CLASS (DHUDMessage, DHUDMessageBase) DECLARE_CLASS (DHUDMessage, DHUDMessageBase)
public: public:
DHUDMessage (FFont *font, const char *text, float x, float y, int hudwidth, int hudheight, DHUDMessage (FFont *font, const char *text, float x, float y, int hudwidth, int hudheight,
EColorRange textColor, float holdTime); EColorRange textColor, float holdTime, bool altscale = false);
virtual void OnDestroy () override; virtual void OnDestroy () override;
virtual void Serialize(FSerializer &arc); virtual void Serialize(FSerializer &arc);
@ -140,6 +140,7 @@ protected:
int ClipX, ClipY, ClipWidth, ClipHeight, WrapWidth; // in HUD coords int ClipX, ClipY, ClipWidth, ClipHeight, WrapWidth; // in HUD coords
int ClipLeft, ClipTop, ClipRight, ClipBot; // in screen coords int ClipLeft, ClipTop, ClipRight, ClipBot; // in screen coords
bool HandleAspect; bool HandleAspect;
bool AltScale;
EColorRange TextColor; EColorRange TextColor;
FFont *Font; FFont *Font;
FRenderStyle Style; FRenderStyle Style;

View file

@ -220,7 +220,7 @@ static void PrintMessage (const char *str)
{ {
str = GStrings(str+1); str = GStrings(str+1);
} }
C_MidPrint (SmallFont, str); C_MidPrint (nullptr, str);
} }
} }

View file

@ -705,7 +705,7 @@ protected:
TObjPtr<AActor*> activator; TObjPtr<AActor*> activator;
line_t *activationline; line_t *activationline;
bool backSide; bool backSide;
FFont *activefont; FFont *activefont = nullptr;
int hudwidth, hudheight; int hudwidth, hudheight;
int ClipRectLeft, ClipRectTop, ClipRectWidth, ClipRectHeight; int ClipRectLeft, ClipRectTop, ClipRectWidth, ClipRectHeight;
int WrapWidth; int WrapWidth;
@ -774,7 +774,7 @@ protected:
private: private:
DLevelScript(); DLevelScript() = default;
friend class DACSThinker; friend class DACSThinker;
}; };
@ -3506,11 +3506,6 @@ void DLevelScript::Serialize(FSerializer &arc)
} }
} }
DLevelScript::DLevelScript ()
{
activefont = SmallFont;
}
void DLevelScript::Unlink () void DLevelScript::Unlink ()
{ {
DACSThinker *controller = Level->ACSThinker; DACSThinker *controller = Level->ACSThinker;
@ -3924,10 +3919,6 @@ void DLevelScript::DoSetFont (int fontnum)
{ {
const char *fontname = Level->Behaviors.LookupString (fontnum); const char *fontname = Level->Behaviors.LookupString (fontnum);
activefont = V_GetFont (fontname); activefont = V_GetFont (fontname);
if (activefont == NULL)
{
activefont = SmallFont;
}
} }
int DLevelScript::DoSetMaster (AActor *self, AActor *master) int DLevelScript::DoSetMaster (AActor *self, AActor *master)
@ -8676,17 +8667,18 @@ scriptwait:
color = CLAMPCOLOR(Stack[optstart-4]); color = CLAMPCOLOR(Stack[optstart-4]);
} }
FFont *font = activefont ? activefont : SmallFont;
switch (type & 0xFF) switch (type & 0xFF)
{ {
default: // normal default: // normal
alpha = (optstart < sp) ? ACSToFloat(Stack[optstart]) : 1.f; alpha = (optstart < sp) ? ACSToFloat(Stack[optstart]) : 1.f;
msg = Create<DHUDMessage> (activefont, work, x, y, hudwidth, hudheight, color, holdTime); msg = Create<DHUDMessage> (font, work, x, y, hudwidth, hudheight, color, holdTime);
break; break;
case 1: // fade out case 1: // fade out
{ {
float fadeTime = (optstart < sp) ? ACSToFloat(Stack[optstart]) : 0.5f; float fadeTime = (optstart < sp) ? ACSToFloat(Stack[optstart]) : 0.5f;
alpha = (optstart < sp-1) ? ACSToFloat(Stack[optstart+1]) : 1.f; alpha = (optstart < sp-1) ? ACSToFloat(Stack[optstart+1]) : 1.f;
msg = Create<DHUDMessageFadeOut> (activefont, work, x, y, hudwidth, hudheight, color, holdTime, fadeTime); msg = Create<DHUDMessageFadeOut> (font, work, x, y, hudwidth, hudheight, color, holdTime, fadeTime);
} }
break; break;
case 2: // type on, then fade out case 2: // type on, then fade out
@ -8694,7 +8686,7 @@ scriptwait:
float typeTime = (optstart < sp) ? ACSToFloat(Stack[optstart]) : 0.05f; float typeTime = (optstart < sp) ? ACSToFloat(Stack[optstart]) : 0.05f;
float fadeTime = (optstart < sp-1) ? ACSToFloat(Stack[optstart+1]) : 0.5f; float fadeTime = (optstart < sp-1) ? ACSToFloat(Stack[optstart+1]) : 0.5f;
alpha = (optstart < sp-2) ? ACSToFloat(Stack[optstart+2]) : 1.f; alpha = (optstart < sp-2) ? ACSToFloat(Stack[optstart+2]) : 1.f;
msg = Create<DHUDMessageTypeOnFadeOut> (activefont, work, x, y, hudwidth, hudheight, color, typeTime, holdTime, fadeTime); msg = Create<DHUDMessageTypeOnFadeOut> (font, work, x, y, hudwidth, hudheight, color, typeTime, holdTime, fadeTime);
} }
break; break;
case 3: // fade in, then fade out case 3: // fade in, then fade out
@ -8702,7 +8694,7 @@ scriptwait:
float inTime = (optstart < sp) ? ACSToFloat(Stack[optstart]) : 0.5f; float inTime = (optstart < sp) ? ACSToFloat(Stack[optstart]) : 0.5f;
float outTime = (optstart < sp-1) ? ACSToFloat(Stack[optstart+1]) : 0.5f; float outTime = (optstart < sp-1) ? ACSToFloat(Stack[optstart+1]) : 0.5f;
alpha = (optstart < sp-2) ? ACSToFloat(Stack[optstart + 2]) : 1.f; alpha = (optstart < sp-2) ? ACSToFloat(Stack[optstart + 2]) : 1.f;
msg = Create<DHUDMessageFadeInOut> (activefont, work, x, y, hudwidth, hudheight, color, holdTime, inTime, outTime); msg = Create<DHUDMessageFadeInOut> (font, work, x, y, hudwidth, hudheight, color, holdTime, inTime, outTime);
} }
break; break;
} }
@ -10286,7 +10278,6 @@ DLevelScript::DLevelScript (FLevelLocals *l, AActor *who, line_t *where, int num
activator = who; activator = who;
activationline = where; activationline = where;
backSide = flags & ACS_BACKSIDE; backSide = flags & ACS_BACKSIDE;
activefont = SmallFont;
hudwidth = hudheight = 0; hudwidth = hudheight = 0;
ClipRectLeft = ClipRectTop = ClipRectWidth = ClipRectHeight = WrapWidth = 0; ClipRectLeft = ClipRectTop = ClipRectWidth = ClipRectHeight = WrapWidth = 0;
HandleAspect = true; HandleAspect = true;

View file

@ -1309,7 +1309,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_Print)
con_midtime = float(time); con_midtime = float(time);
} }
FString formatted = strbin1(text); FString formatted = strbin1(text);
C_MidPrint(font != NULL ? font : SmallFont, formatted.GetChars()); C_MidPrint(font, formatted.GetChars());
con_midtime = saved; con_midtime = saved;
} }
return 0; return 0;
@ -1341,7 +1341,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_PrintBold)
con_midtime = float(time); con_midtime = float(time);
} }
FString formatted = strbin1(text); FString formatted = strbin1(text);
C_MidPrintBold(font != NULL ? font : SmallFont, formatted.GetChars()); C_MidPrintBold(font, formatted.GetChars());
con_midtime = saved; con_midtime = saved;
return 0; return 0;
} }

View file

@ -592,12 +592,12 @@ void P_GiveSecret(FLevelLocals *Level, AActor *actor, bool printmessage, bool pl
{ {
if (printmessage) if (printmessage)
{ {
if (!showsecretsector || sectornum < 0) C_MidPrint(SmallFont, GStrings["SECRETMESSAGE"]); if (!showsecretsector || sectornum < 0) C_MidPrint(nullptr, GStrings["SECRETMESSAGE"]);
else else
{ {
FString s = GStrings["SECRETMESSAGE"]; FString s = GStrings["SECRETMESSAGE"];
s.AppendFormat(" (Sector %d)", sectornum); s.AppendFormat(" (Sector %d)", sectornum);
C_MidPrint(SmallFont, s); C_MidPrint(nullptr, s);
} }
} }
if (playsound) S_Sound (CHAN_AUTO | CHAN_UI, "misc/secret", 1, ATTN_NORM); if (playsound) S_Sound (CHAN_AUTO | CHAN_UI, "misc/secret", 1, ATTN_NORM);