diff --git a/source/blood/src/blood.h b/source/blood/src/blood.h index eda86e57c..5328b470b 100644 --- a/source/blood/src/blood.h +++ b/source/blood/src/blood.h @@ -97,6 +97,8 @@ struct GameInterface : ::GameInterface void DrawMenuCaption(const DVector2& origin, const char* text) override; bool SaveGame(FSaveGameNode*) override; bool LoadGame(FSaveGameNode*) override; + void DoPrintMessage(int prio, const char*) override; + }; END_BLD_NS diff --git a/source/blood/src/messages.cpp b/source/blood/src/messages.cpp index 0ceafed93..0e5f3bea5 100644 --- a/source/blood/src/messages.cpp +++ b/source/blood/src/messages.cpp @@ -325,7 +325,7 @@ void CGameMessageMgr::SetState(char state) void CGameMessageMgr::Add(const char *pText, char a2, const int pal, const MESSAGE_PRIORITY priority) { - if (a2 && messageFlags) + if (a2 && messageFlags && hud_messages == 1) // add only if messages are enabled and in native format { messageStruct *pMessage = &messages[nextMessagesIndex]; strncpy(pMessage->text, pText, kMaxMessageTextLength-1); diff --git a/source/blood/src/view.cpp b/source/blood/src/view.cpp index 61acd766a..6044a2176 100644 --- a/source/blood/src/view.cpp +++ b/source/blood/src/view.cpp @@ -2759,16 +2759,23 @@ void viewSetSystemMessage(const char* pMessage, ...) { char buffer[1024]; va_list args; va_start(args, pMessage); vsprintf(buffer, pMessage, args); - OSD_Printf("%s\n", buffer); // print it also in console + Printf(PRINT_HIGH | PRINT_NOTIFY, "%s\n", buffer); // print it also in console gGameMessageMgr.Add(buffer, 15, 7, MESSAGE_PRIORITY_SYSTEM); } void viewSetMessage(const char *pMessage, const int pal, const MESSAGE_PRIORITY priority) { - OSD_Printf("%s\n", pMessage); + int printlevel = priority < 0 ? PRINT_LOW : priority < MESSAGE_PRIORITY_SYSTEM ? PRINT_MEDIUM : PRINT_HIGH; + Printf(printlevel|PRINT_NOTIFY, "%s\n", pMessage); gGameMessageMgr.Add(pMessage, 15, pal, priority); } +void GameInterface::DoPrintMessage(int prio, const char*msg) +{ + viewSetMessage(msg, 0, prio == PRINT_LOW ? MESSAGE_PRIORITY_PICKUP : prio == PRINT_MEDIUM ? MESSAGE_PRIORITY_NORMAL : MESSAGE_PRIORITY_SYSTEM); +} + + void viewDisplayMessage(void) { gGameMessageMgr.Display(); diff --git a/source/build/include/baselayer.h b/source/build/include/baselayer.h index c65cbd35b..4d9ac6269 100644 --- a/source/build/include/baselayer.h +++ b/source/build/include/baselayer.h @@ -227,6 +227,15 @@ struct GameInterface virtual void DrawMenuCaption(const DVector2& origin, const char* text) {} virtual bool SaveGame(FSaveGameNode*) { return false; } virtual bool LoadGame(FSaveGameNode*) { return false; } + virtual void DoPrintMessage(int prio, const char*) = 0; + void PrintMessage(int prio, const char*fmt, ...) + { + va_list ap; + va_start(ap, fmt); + FString f; + f.VFormat(fmt, ap); + DoPrintMessage(prio, fmt); + } }; extern GameInterface* gi; diff --git a/source/common/console/c_console.cpp b/source/common/console/c_console.cpp index 594d56137..0b9ab28e8 100644 --- a/source/common/console/c_console.cpp +++ b/source/common/console/c_console.cpp @@ -901,7 +901,7 @@ int PrintString (int iprintlevel, const char *outline) #endif conbuffer->AddText(printlevel, outline); - if (vidactive && screen && !(iprintlevel & PRINT_NONOTIFY)) + if (vidactive && screen && (iprintlevel & PRINT_NOTIFY)) { NotifyStrings.AddString(printlevel, outline); } @@ -959,7 +959,7 @@ void OSD_Printf(const char *format, ...) int count; va_start (argptr, format); - count = VPrintf (PRINT_HIGH|PRINT_NONOTIFY, format, argptr); + count = VPrintf (PRINT_HIGH, format, argptr); va_end (argptr); } @@ -1802,7 +1802,7 @@ void C_MidPrint (FFont *font, const char *msg, bool bold) if (msg != nullptr) { 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); + Printf(PRINT_HIGH, TEXTCOLOR_ESCAPESTR "%c%s\n%s\n%s\n", color, console_bar, msg, console_bar); StatusBar->AttachMessage (Create(font, msg, 1.5f, 0.375f, 0, 0, color, con_midtime), MAKE_ID('C','N','T','R')); } diff --git a/source/common/gamecvars.cpp b/source/common/gamecvars.cpp index c5d018470..a99cf27a1 100644 --- a/source/common/gamecvars.cpp +++ b/source/common/gamecvars.cpp @@ -266,12 +266,6 @@ CUSTOM_CVARD(Int, hud_messages, 1, CVAR_ARCHIVE, "enable/disable showing message CCMD (togglemessages) { - // Fixme: Needs to redirect to the frontend specific routine to handle on-screen messages. - // Ideally as an option to use the ZDoom-style notification. - // P_DoQuote(fta ? QUOTE_MESSAGES_ON : QUOTE_MESSAGES_OFF, &myplayer); (Duke/Redneck - beware of crappy implementation!!! - // void viewSetMessage(const char *pMessage, const int pal, const MESSAGE_PRIORITY priority) Blood - // void viewSetSystemMessage(const char* pMessage, ...) alternative - // void PutStringInfo(PLAYERp pp, const char *string) SW if (hud_messages) { diff --git a/source/common/secrets.cpp b/source/common/secrets.cpp index 21cd0d5d7..2e2b32a78 100644 --- a/source/common/secrets.cpp +++ b/source/common/secrets.cpp @@ -166,7 +166,7 @@ void SECRET_SetMapName(const char *filename, const char *_maptitle) void SECRET_Trigger(int num) { - if (secret_notify) Printf(PRINT_NONOTIFY, "Secret #%d found\n", num); + if (secret_notify) Printf("Secret #%d found\n", num); if (discovered_secrets.Find(num) == discovered_secrets.Size()) discovered_secrets.Push(num); } diff --git a/source/common/utility/printf.h b/source/common/utility/printf.h index fababaa95..ad5a04575 100644 --- a/source/common/utility/printf.h +++ b/source/common/utility/printf.h @@ -23,7 +23,7 @@ enum 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_NOTIFY = 1024, // Flag - add to notify buffer PRINT_NOLOG = 2048, // Flag - do not print to log file }; @@ -67,12 +67,12 @@ inline void buildprintf(const char *format, Args&&... args) //ATTRIBUTE((format( inline void initputs(const char *s) { - PrintString(PRINT_HIGH|PRINT_NONOTIFY, s); + PrintString(PRINT_HIGH, s); } inline void buildputs(const char *s) { - PrintString(PRINT_HIGH|PRINT_NONOTIFY, s); + PrintString(PRINT_HIGH, s); } void debugprintf(const char* f, ...); // Prints to the debugger's log. diff --git a/source/duke3d/src/duke3d.h b/source/duke3d/src/duke3d.h index d43f0f2e3..85978763d 100644 --- a/source/duke3d/src/duke3d.h +++ b/source/duke3d/src/duke3d.h @@ -168,6 +168,7 @@ struct GameInterface : ::GameInterface void DrawMenuCaption(const DVector2& origin, const char* text) override; bool SaveGame(FSaveGameNode*) override; bool LoadGame(FSaveGameNode*) override; + void DoPrintMessage(int prio, const char*) override; }; diff --git a/source/duke3d/src/screentext.cpp b/source/duke3d/src/screentext.cpp index 5af0e37b0..e3cf83e13 100644 --- a/source/duke3d/src/screentext.cpp +++ b/source/duke3d/src/screentext.cpp @@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "gstrings.h" #include "quotemgr.h" +#include "c_dispatch.h" BEGIN_DUKE_NS // get the string length until the next '\n' @@ -988,16 +989,20 @@ void G_AddUserQuote(const char *daquote) { int32_t i; - for (i=MAXUSERQUOTES-1; i>0; i--) - { - Bstrcpy(user_quote[i], user_quote[i-1]); - user_quote_time[i] = user_quote_time[i-1]; - } - Bstrcpy(user_quote[0], daquote); - OSD_Printf("%s\n", daquote); + if (hud_messages == 0) return; + Printf(PRINT_MEDIUM | PRINT_NOTIFY, "%s\n", daquote); + if (hud_messages == 1) + { + for (i = MAXUSERQUOTES - 1; i > 0; i--) + { + Bstrcpy(user_quote[i], user_quote[i - 1]); + user_quote_time[i] = user_quote_time[i - 1]; + } + Bstrcpy(user_quote[0], daquote); - user_quote_time[0] = hud_messagetime; - pub = NUMPAGES; + user_quote_time[0] = hud_messagetime; + pub = NUMPAGES; + } } int32_t textsc(int32_t sc) @@ -1006,6 +1011,7 @@ int32_t textsc(int32_t sc) } + #define FTAOPAQUETIME 30 // alpha increments of 8 --> 256 / 8 = 32 --> round up to power of 2 --> 32 --> divide by 2 --> 16 alphatabs required @@ -1050,6 +1056,8 @@ static FORCE_INLINE int32_t text_ypos(void) #endif } +static FString text_quote; // To put text into the quote display that does not come from the quote array. (Is it really necessary to implement everything as a hack??? :( ) + // this handles both multiplayer and item pickup message type text // both are passed on to gametext void G_PrintGameQuotes(int32_t snum) @@ -1099,7 +1107,8 @@ void G_PrintGameQuotes(int32_t snum) } #endif - height = gametext_(x, y, quoteMgr.GetQuote(ps->ftq), textsh(k), pal, texto(k), texta(k), TEXT_XCENTER).y + (1<<16); + if (text_quote.IsNotEmpty() && ps->ftq == -32878) height = gametext_(x, y, text_quote, textsh(k), pal, texto(k), texta(k), TEXT_XCENTER).y + (1 << 16); + else height = gametext_(x, y, quoteMgr.GetQuote(ps->ftq), textsh(k), pal, texto(k), texta(k), TEXT_XCENTER).y + (1<<16); } while (0); @@ -1141,18 +1150,47 @@ void P_DoQuote(int32_t q, DukePlayer_t *p) if (p->fta > 0 && q != QUOTE_RESERVED && q != QUOTE_RESERVED2) if (p->ftq == QUOTE_RESERVED || p->ftq == QUOTE_RESERVED2) return; - p->fta = 100; - if (p->ftq != q) { auto qu = quoteMgr.GetQuote(q); if (p == g_player[screenpeek].ps && qu[0] != '\0') - OSD_Printf(cq ? OSDTEXT_DEFAULT "%s\n" : "%s\n", qu); + Printf(PRINT_MEDIUM | PRINT_NOTIFY, cq ? OSDTEXT_DEFAULT "%s\n" : "%s\n", qu); - p->ftq = q; - } + } - pub = NUMPAGES; - pus = NUMPAGES; + if (hud_messages == 1) + { + p->ftq = q; + p->fta = 100; + pub = NUMPAGES; + pus = NUMPAGES; + } } + +void GameInterface::DoPrintMessage(int prio, const char* t) +{ + auto p = g_player[myconnectindex].ps; // text quotes always belong to the local player. + int32_t cq = 0; + + if (hud_messages == 0 || !(p->gm & MODE_GAME)) + return; + + if (p->fta > 0) + if (p->ftq == QUOTE_RESERVED || p->ftq == QUOTE_RESERVED2) return; + + if (p == g_player[screenpeek].ps) + Printf(prio | PRINT_NOTIFY, cq ? OSDTEXT_DEFAULT "%s\n" : "%s\n", t); + + if (hud_messages == 1) + { + p->fta = 100; + p->ftq = -32768; + text_quote = t; + pub = NUMPAGES; + pus = NUMPAGES; + } + +} + + END_DUKE_NS diff --git a/source/rr/src/duke3d.h b/source/rr/src/duke3d.h index 44fd44bce..52b1985e2 100644 --- a/source/rr/src/duke3d.h +++ b/source/rr/src/duke3d.h @@ -168,6 +168,7 @@ struct GameInterface : ::GameInterface void DrawMenuCaption(const DVector2& origin, const char* text) override; bool SaveGame(FSaveGameNode*) override; bool LoadGame(FSaveGameNode*) override; + void DoPrintMessage(int prio, const char* text) override; }; END_RR_NS diff --git a/source/rr/src/screentext.cpp b/source/rr/src/screentext.cpp index ec66b14c2..327fcb6c4 100644 --- a/source/rr/src/screentext.cpp +++ b/source/rr/src/screentext.cpp @@ -986,20 +986,24 @@ void captionmenutext(int32_t x, int32_t y, char const *t) int32_t user_quote_time[MAXUSERQUOTES]; static char user_quote[MAXUSERQUOTES][178]; -void G_AddUserQuote(const char *daquote) +void G_AddUserQuote(const char* daquote) { - int32_t i; + int32_t i; - for (i=MAXUSERQUOTES-1; i>0; i--) - { - Bstrcpy(user_quote[i], user_quote[i-1]); - user_quote_time[i] = user_quote_time[i-1]; - } - Bstrcpy(user_quote[0], daquote); - OSD_Printf("%s\n", daquote); + if (hud_messages == 0) return; + Printf(PRINT_MEDIUM | PRINT_NOTIFY, "%s\n", daquote); + if (hud_messages == 1) + { + for (i = MAXUSERQUOTES - 1; i > 0; i--) + { + Bstrcpy(user_quote[i], user_quote[i - 1]); + user_quote_time[i] = user_quote_time[i - 1]; + } + Bstrcpy(user_quote[0], daquote); - user_quote_time[0] = hud_messagetime; - pub = NUMPAGES; + user_quote_time[0] = hud_messagetime; + pub = NUMPAGES; + } } int32_t textsc(int32_t sc) @@ -1051,6 +1055,8 @@ static FORCE_INLINE int32_t text_ypos(void) #endif } +static FString text_quote; // To put text into the quote display that does not come from the quote array. (Is it really necessary to implement everything as a hack??? :( ) + // this handles both multiplayer and item pickup message type text // both are passed on to gametext void G_PrintGameQuotes(int32_t snum) @@ -1100,8 +1106,9 @@ void G_PrintGameQuotes(int32_t snum) } #endif - height = gametext_(x, y, quoteMgr.GetQuote(ps->ftq), textsh(k), pal, texto(k), texta(k), TEXT_XCENTER).y + (1<<16); - } + if (text_quote.IsNotEmpty() && ps->ftq == -32768) height = gametext_(x, y, text_quote, textsh(k), pal, texto(k), texta(k), TEXT_XCENTER).y + (1 << 16); + else height = gametext_(x, y, quoteMgr.GetQuote(ps->ftq), textsh(k), pal, texto(k), texta(k), TEXT_XCENTER).y + (1 << 16); + } while (0); @@ -1142,18 +1149,45 @@ void P_DoQuote(int32_t q, DukePlayer_t *p) if (p->fta > 0 && q != QUOTE_RESERVED && q != QUOTE_RESERVED2) if (p->ftq == QUOTE_RESERVED || p->ftq == QUOTE_RESERVED2) return; - p->fta = 100; - if (p->ftq != q) { auto qu = quoteMgr.GetQuote(q); if (p == g_player[screenpeek].ps && qu[0] != '\0') - OSD_Printf(cq ? OSDTEXT_DEFAULT "%s\n" : "%s\n", qu); + Printf(PRINT_NOTIFY, cq ? OSDTEXT_DEFAULT "%s\n" : "%s\n", qu); - p->ftq = q; } - pub = NUMPAGES; - pus = NUMPAGES; + if (hud_messages == 1) + { + p->ftq = q; + p->fta = 100; + pub = NUMPAGES; + pus = NUMPAGES; + } } + +void GameInterface::DoPrintMessage(int prio, const char* t) +{ + auto p = g_player[myconnectindex].ps; // text quotes always belong to the local player. + int32_t cq = 0; + + if (hud_messages == 0 || !(p->gm & MODE_GAME)) + return; + + if (p->fta > 0) + if (p->ftq == QUOTE_RESERVED || p->ftq == QUOTE_RESERVED2) return; + + if (p == g_player[screenpeek].ps) + Printf(PRINT_NOTIFY, cq ? OSDTEXT_DEFAULT "%s\n" : "%s\n", t); + + if (hud_messages == 1) + { + p->fta = 100; + p->ftq = -32768; + text_quote = t; + pub = NUMPAGES; + pus = NUMPAGES; + } +} + END_RR_NS diff --git a/source/sw/src/game.h b/source/sw/src/game.h index 9658cb7cf..50005d389 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -2387,6 +2387,7 @@ struct GameInterface : ::GameInterface void DrawCenteredTextScreen(const DVector2& origin, const char* text, int position) override; bool LoadGame(FSaveGameNode* sv) override; bool SaveGame(FSaveGameNode* sv) override; + void DoPrintMessage(int prio, const char* text) override; }; diff --git a/source/sw/src/text.cpp b/source/sw/src/text.cpp index 2eec36424..842b77f7d 100644 --- a/source/sw/src/text.cpp +++ b/source/sw/src/text.cpp @@ -447,8 +447,17 @@ void PutStringInfo(PLAYERp pp, const char *string) if (!hud_messages) return; - OSD_Printf("%s", string); // Put it in the console too - PutStringInfoLine(pp, string); + Printf(PRINT_LOW|PRINT_NOTIFY, "%s", string); // Put it in the console too + if (hud_messages == 1) PutStringInfoLine(pp, string); +} + +void GameInterface::DoPrintMessage(int prio, const char* string) +{ + if (!hud_messages) + return; + + Printf(prio | PRINT_NOTIFY, "%s", string); // Put it in the console too + if (hud_messages == 1) PutStringInfoLine(&Player[myconnectindex], string); } void PutStringInfoLine(PLAYERp pp, const char *string) @@ -475,22 +484,6 @@ void PutStringInfoLine(PLAYERp pp, const char *string) //PutStringInfoLine2(pp, ""); } -void PutStringInfoLine2(PLAYERp pp, const char *string) -{ - short x,y; - short w,h; - - if (pp-Player != myconnectindex) - return; - - MNU_MeasureString(string, &w, &h); - - x = TEXT_XCENTER(w); - y = TEXT_INFO_LINE(1); - - PutStringTimer(pp, x, y, string, GlobInfoStringTime); -} - void pMenuClearTextLine(PLAYERp pp) { pMenuClearTextLineID(pp, ID_TEXT, TEXT_INFO_LINE(0), PRI_FRONT_MAX); @@ -500,22 +493,4 @@ void pMenuClearTextLine(PLAYERp pp) #define TEXT_PLAYER_INFO_TIME (3) #define TEXT_PLAYER_INFO_Y (200 - 40) -void PutStringPlayerInfo(PLAYERp pp, const char *string) -{ - short x,y; - short w,h; - - if (pp-Player != myconnectindex) - return; - - if (!hud_messages) - return; - - MNU_MeasureString(string, &w, &h); - - x = TEXT_XCENTER(w); - y = TEXT_PLAYER_INFO_Y; - - PutStringTimer(pp, x, y, string, GlobInfoStringTime); -} END_SW_NS