Skip to content

Commit

Permalink
Merge pull request #907 from OrdinaryMagician/sbar_overrides
Browse files Browse the repository at this point in the history
Allow status bars to override notifications/prints/chat prompt
  • Loading branch information
coelckers committed Aug 19, 2019
2 parents 1a94e16 + 14dc288 commit 8b6c051
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 11 deletions.
30 changes: 30 additions & 0 deletions src/console/c_console.cpp
Expand Up @@ -773,6 +773,19 @@ void FNotifyBuffer::AddString(int printlevel, FString source)
con_notifylines == 0)
return;

// [MK] allow the status bar to take over notify printing
if (StatusBar != nullptr)
{
IFVIRTUALPTR(StatusBar, DBaseStatusBar, ProcessNotify)
{
VMValue params[] = { (DObject*)StatusBar, printlevel, &source };
int rv;
VMReturn ret(&rv);
VMCall(func, params, countof(params), &ret, 1);
if (!!rv) return;
}
}

width = DisplayWidth / active_con_scaletext(generic_ui);

FFont *font = generic_ui ? NewSmallFont : AlternativeSmallFont;
Expand Down Expand Up @@ -960,6 +973,12 @@ int DPrintf (int level, const char *format, ...)
void C_FlushDisplay ()
{
NotifyStrings.Clear();
if (StatusBar == nullptr) return;
IFVIRTUALPTR(StatusBar, DBaseStatusBar, FlushNotify)
{
VMValue params[] = { (DObject*)StatusBar };
VMCall(func, params, countof(params), nullptr, 1);
}
}

void C_AdjustBottom ()
Expand Down Expand Up @@ -1740,6 +1759,17 @@ void C_MidPrint (FFont *font, const char *msg, bool bold)
if (StatusBar == nullptr || screen == nullptr)
return;

// [MK] allow the status bar to take over MidPrint
IFVIRTUALPTR(StatusBar, DBaseStatusBar, ProcessMidPrint)
{
FString msgstr = msg;
VMValue params[] = { (DObject*)StatusBar, font, &msg, bold };
int rv;
VMReturn ret(&rv);
VMCall(func, params, countof(params), &ret, 1);
if (!!rv) return;
}

if (msg != nullptr)
{
auto color = (EColorRange)PrintColors[bold? PRINTLEVELS+1 : PRINTLEVELS];
Expand Down
33 changes: 23 additions & 10 deletions src/ct_chat.cpp
Expand Up @@ -41,6 +41,7 @@
#include "v_video.h"
#include "utf8.h"
#include "gstrings.h"
#include "vm.h"

enum
{
Expand Down Expand Up @@ -233,8 +234,30 @@ void CT_PasteChat(const char *clip)
void CT_Drawer (void)
{
FFont *displayfont = NewConsoleFont;

if (players[consoleplayer].camera != NULL &&
(Button_ShowScores.bDown ||
players[consoleplayer].camera->health <= 0 ||
SB_ForceActive) &&
// Don't draw during intermission, since it has its own scoreboard in wi_stuff.cpp.
gamestate != GS_INTERMISSION)
{
HU_DrawScores (&players[consoleplayer]);
}
if (chatmodeon)
{
// [MK] allow the status bar to take over chat prompt drawing
bool skip = false;
IFVIRTUALPTR(StatusBar, DBaseStatusBar, DrawChat)
{
FString txt = ChatQueue;
VMValue params[] = { (DObject*)StatusBar, &txt };
int rv;
VMReturn ret(&rv);
VMCall(func, params, countof(params), &ret, 1);
if (!!rv) return;
}

FStringf prompt("%s ", GStrings("TXT_SAY"));
int x, scalex, y, promptwidth;

Expand Down Expand Up @@ -268,16 +291,6 @@ void CT_Drawer (void)
screen->DrawText (displayfont, CR_GREY, promptwidth, y, printstr,
DTA_VirtualWidth, screen_width, DTA_VirtualHeight, screen_height, DTA_KeepRatio, true, TAG_DONE);
}

if (players[consoleplayer].camera != NULL &&
(Button_ShowScores.bDown ||
players[consoleplayer].camera->health <= 0 ||
SB_ForceActive) &&
// Don't draw during intermission, since it has its own scoreboard in wi_stuff.cpp.
gamestate != GS_INTERMISSION)
{
HU_DrawScores (&players[consoleplayer]);
}
}

//===========================================================================
Expand Down
14 changes: 14 additions & 0 deletions wadsrc/static/zscript/constants.zs
Expand Up @@ -1352,3 +1352,17 @@ enum EMonospacing
Mono_CellCenter = 2,
Mono_CellRight = 3
};

enum EPrintLevel
{
PRINT_LOW, // pickup messages
PRINT_MEDIUM, // death messages
PRINT_HIGH, // critical messages
PRINT_CHAT, // chat messages
PRINT_TEAMCHAT, // chat messages from a teammate
PRINT_LOG, // only to logfile
PRINT_BOLD = 200, // What Printf_Bold used
PRINT_TYPES = 1023, // Bitmask.
PRINT_NONOTIFY = 1024, // Flag - do not add to notify buffer
PRINT_NOLOG = 2048, // Flag - do not print to log file
};
9 changes: 8 additions & 1 deletion wadsrc/static/zscript/ui/statusbar/statusbar.zs
Expand Up @@ -334,7 +334,14 @@ class BaseStatusBar native ui
virtual void NewGame () { if (CPlayer != null) AttachToPlayer(CPlayer); }
virtual void ShowPop (int popnum) { ShowLog = (popnum == POP_Log && !ShowLog); }
virtual bool MustDrawLog(int state) { return true; }


// [MK] let the HUD handle notifications and centered print messages
virtual bool ProcessNotify(EPrintLevel printlevel, String outline) { return false; }
virtual void FlushNotify() {}
virtual bool ProcessMidPrint(Font fnt, String msg, bool bold) { return false; }
// [MK] let the HUD handle drawing the chat prompt
virtual bool DrawChat(String txt) { return false; }

native TextureID GetMugshot(int accuracy, int stateflags=MugShot.STANDARD, String default_face = "STF");

// These functions are kept native solely for performance reasons. They get called repeatedly and can drag down performance easily if they get too slow.
Expand Down

0 comments on commit 8b6c051

Please sign in to comment.