From 220e996531873d583331190103463effb432181c Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 8 Aug 2024 16:51:39 +0300 Subject: [PATCH] Test replay search --- src/filesrch.c | 5 +++ src/filesrch.h | 1 + src/m_menu.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 91 insertions(+), 1 deletion(-) diff --git a/src/filesrch.c b/src/filesrch.c index 3a3a576ce..623dbcaa2 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -326,6 +326,7 @@ consvar_t cv_addons_search_type = {"addons_search_type", "Anywhere", CV_SAVE, ad char menupath[1024]; size_t menupathindex[menudepth]; size_t menudepthleft = menudepth; +char *replayhutquery = NULL; char menusearch[MAXSTRINGLENGTH+1]; @@ -691,6 +692,8 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) if (replayhut) { if (strcasecmp(".lmp", dent->d_name+len-5)) continue; // Not a replay + if (replayhutquery != NULL && strcasestr(dent->d_name, replayhutquery) == NULL) + continue; } else if (!cv_addons_showall.value) { @@ -765,6 +768,8 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) if (replayhut) { if (strcasecmp(".lmp", dent->d_name+len-5)) continue; // Not a replay + if (replayhutquery != NULL && strcasestr(dent->d_name, replayhutquery) == NULL) + continue; ext = EXT_TXT; // This isn't used anywhere but better safe than sorry for messing with this... } else diff --git a/src/filesrch.h b/src/filesrch.h index dd0fb404a..9bf4caa24 100644 --- a/src/filesrch.h +++ b/src/filesrch.h @@ -33,6 +33,7 @@ filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *want extern char menupath[1024]; extern size_t menupathindex[menudepth]; extern size_t menudepthleft; +extern char *replayhutquery; extern char menusearch[MAXSTRINGLENGTH+1]; diff --git a/src/m_menu.c b/src/m_menu.c index 2358d93e0..bd270475e 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6714,6 +6714,11 @@ static void M_HandleAddons(INT32 choice) // ---- REPLAY HUT ----- menudemo_t *demolist; +#define MAXREPLAYQUERY 30 +char replayqueryinput[MAXREPLAYQUERY+1]; +size_t replayquerypos = 0; +boolean replayqueryopen = false; + #define DF_ENCORE 0x40 static INT16 replayScrollTitle = 0; static SINT8 replayScrollDelay = TICRATE, replayScrollDir = 1; @@ -6759,6 +6764,13 @@ void M_ReplayHut(INT32 choice) snprintf(menupath, 1024, "%s"PATHSEP"replay"PATHSEP"online"PATHSEP, srb2home); menupathindex[(menudepthleft = menudepth-1)] = strlen(menupath); } + + // Reset + replayhutquery = NULL; + memset(replayqueryinput, 0, 30); + replayquerypos = 0; + replayqueryopen = false; + if (!preparefilemenu(false, true)) { M_StartMessage("No replays found.\n\n(Press a key)\n", NULL, MM_NOTHING); @@ -6782,10 +6794,71 @@ void M_ReplayHut(INT32 choice) S_ChangeMusicInternal("replst", true); } -static void M_HandleReplayHutList(INT32 choice) +static boolean M_HandleReplayHutQuery(INT32 choice) { + if (!replayqueryopen) + return false; + switch (choice) { + case KEY_ENTER: + case KEY_ESCAPE: + replayqueryopen = false; + break; + + case KEY_BACKSPACE: + if (replayquerypos == 0) + break; + + S_StartSound(NULL,sfx_menu1); + + replayquerypos--; + replayqueryinput[replayquerypos] = 0; + + if (!replayquerypos) + replayhutquery = NULL; + + preparefilemenu(false, true); + dir_on[menudepthleft] = 0; + PrepReplayList(); + + break; + + default: + if (choice < 32 || choice > 127) + break; + + if (replayquerypos < MAXREPLAYQUERY) + { + S_StartSound(NULL,sfx_menu1); + + replayqueryinput[replayquerypos] = choice; + replayqueryinput[replayquerypos+1] = 0; + ++replayquerypos; + + replayhutquery = replayqueryinput; + + preparefilemenu(false, true); + dir_on[menudepthleft] = 0; + PrepReplayList(); + } + } + + return true; +} + +static void M_HandleReplayHutList(INT32 choice) +{ + if (M_HandleReplayHutQuery(choice)) + return; + + switch (choice) + { + case 'f': + case 'F': + replayqueryopen = true; + break; + case KEY_UPARROW: if (dir_on[menudepthleft]) dir_on[menudepthleft]--; @@ -7182,6 +7255,17 @@ static void M_DrawReplayHut(void) { DrawReplayHutReplayInfo(); } + + // Draw search query + if (replayqueryopen || replayquerypos) + { + M_DrawTextBox(8, 200 - 16, MAXREPLAYQUERY, 1); + V_DrawString(16, 200 - 8, V_ALLOWLOWERCASE, replayqueryinput); + + // draw text cursor for name + if (replayqueryopen && skullAnimCounter < 4) // blink cursor + V_DrawCharacter(16 + V_StringWidth(replayqueryinput, V_ALLOWLOWERCASE), 200 - 8, '_', false); + } } static void M_DrawReplayStartMenu(void)