Replays: use Virtual Keyboard for title entry

- This shortens the maximum title length from 64 to 31
  characters
This commit is contained in:
James R 2024-02-29 21:30:32 -08:00
parent 7d01c3046b
commit 8fa01ee558
6 changed files with 38 additions and 100 deletions

View file

@ -278,12 +278,6 @@ void D_ProcessEvents(void)
HandleGamepadDeviceEvents(ev); HandleGamepadDeviceEvents(ev);
if (demo.savemode == demovars_s::DSM_TITLEENTRY)
{
if (G_DemoTitleResponder(ev))
continue;
}
// console input // console input
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_lock_mutex(&con_mutex); I_lock_mutex(&con_mutex);

View file

@ -65,6 +65,30 @@
#include "k_credits.h" #include "k_credits.h"
#include "k_grandprix.h" #include "k_grandprix.h"
static menuitem_t TitleEntry[] =
{
{IT_NOTHING | IT_SPACE, "Save Replay", NULL,
NULL, {NULL}, 0, 0},
};
static menu_t TitleEntryDef = {
sizeof (TitleEntry) / sizeof (menuitem_t),
NULL,
0,
TitleEntry,
0, 0,
0, 0,
MBF_SOUNDLESS,
NULL,
0, 0,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
boolean nodrawers; // for comparative timing purposes boolean nodrawers; // for comparative timing purposes
boolean noblit; // for comparative timing purposes boolean noblit; // for comparative timing purposes
tic_t demostarttime; // for comparative timing purposes tic_t demostarttime; // for comparative timing purposes
@ -3992,6 +4016,9 @@ void G_SaveDemo(void)
UINT8 i; UINT8 i;
#endif #endif
if (currentMenu == &TitleEntryDef)
M_ClearMenus(true);
// Ensure extrainfo pointer is always available, even if no info is present. // Ensure extrainfo pointer is always available, even if no info is present.
if (demoinfo_p && *(UINT32 *)demoinfo_p == 0) if (demoinfo_p && *(UINT32 *)demoinfo_p == 0)
{ {
@ -4076,55 +4103,6 @@ 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) ? demovars_s::DSM_WILLAUTOSAVE : demovars_s::DSM_NOTSAVING;
return true;
}
if (ch == KEY_ENTER || ch >= NUMKEYS)
{
demo.savemode = demovars_s::DSM_WILLSAVE;
return true;
}
if ((ch >= HU_FONTSTART && ch <= HU_FONTEND && fontv[HU_FONT].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;
}
boolean G_CheckDemoTitleEntry(void) boolean G_CheckDemoTitleEntry(void)
{ {
if (menuactive || chat_on) if (menuactive || chat_on)
@ -4133,7 +4111,17 @@ boolean G_CheckDemoTitleEntry(void)
if (!G_PlayerInputDown(0, gc_b, 0) && !G_PlayerInputDown(0, gc_x, 0)) if (!G_PlayerInputDown(0, gc_b, 0) && !G_PlayerInputDown(0, gc_x, 0))
return false; return false;
demo.savemode = demovars_s::DSM_TITLEENTRY; demo.savemode = demovars_s::DSM_WILLSAVE;
M_OpenVirtualKeyboard(
false,
[](const char* replace) -> const char*
{
if (replace)
strlcpy(demo.titlename, replace, sizeof demo.titlename);
return demo.titlename;
},
&TitleEntryDef
);
return true; return true;
} }

View file

@ -93,7 +93,6 @@ struct demovars_s {
enum { enum {
DSM_NOTSAVING, DSM_NOTSAVING,
DSM_WILLAUTOSAVE, DSM_WILLAUTOSAVE,
DSM_TITLEENTRY,
DSM_WILLSAVE, DSM_WILLSAVE,
DSM_SAVED DSM_SAVED
} savemode; } savemode;
@ -232,8 +231,6 @@ void G_DeferedPlayDemo(const char *demo);
void G_SaveDemo(void); void G_SaveDemo(void);
boolean G_DemoTitleResponder(event_t *ev);
boolean G_CheckDemoTitleEntry(void); boolean G_CheckDemoTitleEntry(void);
typedef enum typedef enum

View file

@ -1303,36 +1303,6 @@ static void ST_overlayDrawer(void)
K_DrawMidVote(); K_DrawMidVote();
} }
void ST_DrawDemoTitleEntry(void)
{
static UINT8 anim = 0;
char *nametodraw;
anim++;
anim %= 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, 0, nametodraw);
if (anim < 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, 0, "Enter the name of the replay.");
M_DrawTextBox(x + 50, y + 20, 20, 1);
V_DrawThinString(x + 58, y + 28, 0, "Escape - Cancel");
V_DrawRightAlignedThinString(x + 220, y + 28, 0, "Enter - Confirm");
#undef x
#undef y
}
// MayonakaStatic: draw Midnight Channel's TV-like borders // MayonakaStatic: draw Midnight Channel's TV-like borders
static void ST_MayonakaStatic(void) static void ST_MayonakaStatic(void)
{ {
@ -1640,10 +1610,6 @@ void ST_Drawer(void)
V_DrawRightAlignedThinString(BASEVIDWIDTH - 2, 2, flags|V_YELLOWMAP, "Replay will be saved."); V_DrawRightAlignedThinString(BASEVIDWIDTH - 2, 2, flags|V_YELLOWMAP, "Replay will be saved.");
break; break;
case DSM_TITLEENTRY:
ST_DrawDemoTitleEntry();
break;
default: // Don't render anything default: // Don't render anything
break; break;
} }

View file

@ -33,9 +33,6 @@ extern "C" {
// Called by main loop. // Called by main loop.
void ST_Ticker(boolean run); void ST_Ticker(boolean run);
// Called when naming a replay.
void ST_DrawDemoTitleEntry(void);
#ifdef HAVE_DISCORDRPC #ifdef HAVE_DISCORDRPC
// Called when you have Discord asks // Called when you have Discord asks
void ST_AskToJoinEnvelope(void); void ST_AskToJoinEnvelope(void);

View file

@ -1710,10 +1710,6 @@ finalcounter:
V_DrawRightAlignedThinString(BASEVIDWIDTH - 2, 2, highlightflags, "Replay saved!"); V_DrawRightAlignedThinString(BASEVIDWIDTH - 2, 2, highlightflags, "Replay saved!");
break; break;
case demovars_s::DSM_TITLEENTRY:
ST_DrawDemoTitleEntry();
break;
default: // Don't render any text here default: // Don't render any text here
break; break;
} }