Allow custom status bars to override notifications, centered prints and chat prompt.

# Conflicts:
#	src/c_console.cpp
#	src/ct_chat.cpp
This commit is contained in:
Marisa Kirisame 2019-08-16 15:45:49 +02:00 committed by drfrag
parent f63f833ed1
commit b08ba350d3
4 changed files with 75 additions and 11 deletions

View file

@ -831,6 +831,19 @@ void FNotifyBuffer::AddString(int printlevel, FString source)
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();
if (AddType == APPENDLINE && Text.Size() > 0 && Text[Text.Size() - 1].PrintLevel == printlevel)
@ -977,6 +990,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 ()
@ -1857,6 +1876,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)
{
AddToConsole (-1, bar1);

View file

@ -44,6 +44,7 @@
#include "d_event.h"
#include "sbar.h"
#include "utf8.h"
#include "vm.h"
enum
{
@ -236,8 +237,30 @@ void CT_PasteChat(const char *clip)
void CT_Drawer (void)
{
FFont *displayfont = ConFont;
if (players[consoleplayer].camera != nullptr &&
(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;
}
static const char *prompt = "Say: ";
int x, scalex, y, promptwidth;
@ -273,16 +296,6 @@ void CT_Drawer (void)
BorderTopRefresh = screen->GetPageCount ();
}
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]);
}
}
//===========================================================================

View file

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

View file

@ -337,7 +337,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.