From 2a9dd8e1f9066199cc89cbd9ba0d28d5f396adff Mon Sep 17 00:00:00 2001 From: fickleheart Date: Sun, 24 Mar 2019 22:40:52 -0500 Subject: [PATCH] Allow entering a title for replays on save --- src/d_main.c | 6 ++++++ src/g_game.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++- src/g_game.h | 1 + src/p_tick.c | 2 +- src/st_stuff.c | 36 ++++++++++++++++++++++++++++++++++- src/st_stuff.h | 3 +++ src/y_inter.c | 6 +++++- 7 files changed, 101 insertions(+), 4 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 6edb1cf4..16a70519 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -248,6 +248,12 @@ void D_ProcessEvents(void) continue; } + if (demo.savemode == DSM_TITLEENTRY) + { + if (G_DemoTitleResponder(ev)) + continue; + } + // Menu input if (M_Responder(ev)) continue; // menu ate the event diff --git a/src/g_game.c b/src/g_game.c index fc636537..ca2f0208 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -7603,7 +7603,7 @@ boolean G_CheckDemoStatus(void) return true; } - if (demo.recording && (!multiplayer || cv_recordmultiplayerdemos.value == 2)) + if (demo.recording && demo.savemode != DSM_NOTSAVING) { G_SaveDemo(); return true; @@ -7684,6 +7684,55 @@ void G_SaveDemo(void) } } +boolean G_DemoTitleResponder(event_t *ev) +{ + size_t len; + INT32 ch; + + if (ev->type != ev_keydown) + return false; + + ch = (INT32)ev->data1; + + // Only ESC and non-keyboard keys abort connection + if (ch == KEY_ESCAPE) + { + demo.savemode = (cv_recordmultiplayerdemos.value == 2) ? DSM_WILLAUTOSAVE : DSM_NOTSAVING; + return true; + } + + if (ch == KEY_ENTER || ch >= KEY_MOUSE1) + { + demo.savemode = DSM_WILLSAVE; + return true; + } + + if ((ch >= HU_FONTSTART && ch <= HU_FONTEND && hu_font[ch-HU_FONTSTART]) + || ch == ' ') // Allow spaces, of course + { + len = strlen(demo.titlename); + if (len < 64) + { + demo.titlename[len+1] = 0; + demo.titlename[len] = CON_ShiftChar(ch); + } + } + else if (ch == KEY_BACKSPACE) + { + if (shiftdown) + memset(demo.titlename, 0, sizeof(demo.titlename)); + else + { + len = strlen(demo.titlename); + + if (len > 0) + demo.titlename[len-1] = 0; + } + } + + return true; +} + // // G_SetGamestate // diff --git a/src/g_game.h b/src/g_game.h index c9bcaf01..d97752b2 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -230,6 +230,7 @@ ATTRNORETURN void FUNCNORETURN G_StopMetalRecording(void); void G_StopDemo(void); boolean G_CheckDemoStatus(void); void G_SaveDemo(void); +boolean G_DemoTitleResponder(event_t *ev); boolean G_IsSpecialStage(INT32 mapnum); boolean G_GametypeUsesLives(void); diff --git a/src/p_tick.c b/src/p_tick.c index 03ce05c3..177f3b65 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -733,7 +733,7 @@ void P_Ticker(boolean run) G_WriteAllGhostTics(); if (demo.savebutton && demo.savebutton + 3*TICRATE < leveltime && InputDown(gc_lookback, 1)) - demo.savemode = DSM_WILLSAVE; // DSM_TITLEENTRY + demo.savemode = DSM_TITLEENTRY; } if (demo.playback) // Use Ghost data for consistency checks. { diff --git a/src/st_stuff.c b/src/st_stuff.c index dec7ee0c..acb01fb6 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -2024,13 +2024,17 @@ static void ST_overlayDrawer(void) break; case DSM_WILLAUTOSAVE: - V_DrawRightAlignedThinString(BASEVIDWIDTH - 2, 2, V_HUDTRANS|V_SNAPTOTOP|V_SNAPTORIGHT|V_ALLOWLOWERCASE|(G_BattleGametype() ? V_REDMAP : V_SKYMAP), "Replay will be saved." /*" (Look Backward: Change title)"*/); + V_DrawRightAlignedThinString(BASEVIDWIDTH - 2, 2, V_HUDTRANS|V_SNAPTOTOP|V_SNAPTORIGHT|V_ALLOWLOWERCASE|(G_BattleGametype() ? V_REDMAP : V_SKYMAP), "Replay will be saved. (Look Backward: Change title)"); break; case DSM_WILLSAVE: V_DrawRightAlignedThinString(BASEVIDWIDTH - 2, 2, V_HUDTRANS|V_SNAPTOTOP|V_SNAPTORIGHT|V_ALLOWLOWERCASE|(G_BattleGametype() ? V_REDMAP : V_SKYMAP), "Replay will be saved."); break; + case DSM_TITLEENTRY: + ST_DrawDemoTitleEntry(); + break; + default: // Don't render anything break; } @@ -2039,6 +2043,36 @@ static void ST_overlayDrawer(void) ST_drawDebugInfo(); } +void ST_DrawDemoTitleEntry(void) +{ + static UINT8 skullAnimCounter = 0; + char *nametodraw; + + skullAnimCounter++; + skullAnimCounter %= 8; + + nametodraw = demo.titlename; + while (V_StringWidth(nametodraw, 0) > MAXSTRINGLENGTH*8 - 8) + nametodraw++; + +#define x (BASEVIDWIDTH/2 - 139) +#define y (BASEVIDHEIGHT/2) + M_DrawTextBox(x, y + 4, MAXSTRINGLENGTH, 1); + V_DrawString(x + 8, y + 12, V_ALLOWLOWERCASE, nametodraw); + if (skullAnimCounter < 4) + V_DrawCharacter(x + 8 + V_StringWidth(nametodraw, 0), y + 12, + '_' | 0x80, false); + + M_DrawTextBox(x + 30, y - 24, 26, 1); + V_DrawString(x + 38, y - 16, V_ALLOWLOWERCASE, "Enter the name of the replay."); + + M_DrawTextBox(x + 50, y + 20, 20, 1); + V_DrawThinString(x + 58, y + 28, V_ALLOWLOWERCASE, "Escape - Cancel"); + V_DrawRightAlignedThinString(x + 220, y + 28, V_ALLOWLOWERCASE, "Enter - Confirm"); +#undef x +#undef y +} + // MayonakaStatic: draw Midnight Channel's TV-like borders static void ST_MayonakaStatic(void) { diff --git a/src/st_stuff.h b/src/st_stuff.h index f96aee93..16f7b881 100644 --- a/src/st_stuff.h +++ b/src/st_stuff.h @@ -26,6 +26,9 @@ // Called by main loop. void ST_Ticker(void); +// Called when naming a replay. +void ST_DrawDemoTitleEntry(void); + // Called by main loop. void ST_Drawer(void); diff --git a/src/y_inter.c b/src/y_inter.c index 1e6d945c..256a8566 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -573,6 +573,10 @@ dotimer: V_DrawRightAlignedThinString(BASEVIDWIDTH - 2, 2, V_SNAPTOTOP|V_SNAPTORIGHT|V_ALLOWLOWERCASE|hilicol, "Replay saved!"); break; + case DSM_TITLEENTRY: + ST_DrawDemoTitleEntry(); + break; + default: // Don't render any text here break; } @@ -595,7 +599,7 @@ void Y_Ticker(void) if (demo.recording) { if (demo.savemode == DSM_NOTSAVING && InputDown(gc_lookback, 1)) - demo.savemode = DSM_WILLSAVE; // DSM_TITLEENTRY + demo.savemode = DSM_TITLEENTRY; if (demo.savemode == DSM_WILLSAVE || demo.savemode == DSM_WILLAUTOSAVE) G_SaveDemo();