- added option to print custom messages with Duke Nukem's quote system.

- hooked up all front ends with a generic message printing function so that common code can access the native message displays. This is needed for consolidation of some input actions which are mostly identical but print messages.
- preparations for a generic message system.
This commit is contained in:
Christoph Oelckers 2019-12-04 21:35:35 +01:00
parent 5b0033c08c
commit 6d04f0f159
14 changed files with 150 additions and 88 deletions

View file

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

View file

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

View file

@ -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();

View file

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

View file

@ -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<DHUDMessage>(font, msg, 1.5f, 0.375f, 0, 0, color, con_midtime), MAKE_ID('C','N','T','R'));
}

View file

@ -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)
{

View file

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

View file

@ -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.

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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