diff --git a/src/filesrch.c b/src/filesrch.c index 17f0db7e8..9db81ad37 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -561,15 +561,15 @@ char exttable[NUM_EXT_TABLE][7] = { // maximum extension length (currently 4) pl char filenamebuf[MAX_WADFILES][MAX_WADPATH]; -static boolean filemenucmp(char *haystack, char *needle) +static boolean filemenucmp(char *haystack) { static char localhaystack[128]; strlcpy(localhaystack, haystack, 128); if (!cv_addons_search_case.value) strupr(localhaystack); if (cv_addons_search_type.value) - return (strstr(localhaystack, needle) != 0); - return (!strncmp(localhaystack, needle, menusearch[0])); + return (strstr(localhaystack, menusearch+1) != 0); + return (!strncmp(localhaystack, menusearch+1, menusearch[0])); } void closefilemenu(boolean validsize) @@ -616,7 +616,6 @@ void closefilemenu(boolean validsize) void searchfilemenu(char *tempname) { size_t i, first; - char localmenusearch[MAXSTRINGLENGTH] = ""; if (dirmenu) { @@ -662,14 +661,10 @@ void searchfilemenu(char *tempname) return; } - strcpy(localmenusearch, menusearch+1); - if (!cv_addons_search_case.value) - strupr(localmenusearch); - sizedirmenu = 0; for (i = first; i < sizecoredirmenu; i++) { - if (filemenucmp(coredirmenu[i]+DIR_STRING, localmenusearch)) + if (filemenucmp(coredirmenu[i]+DIR_STRING)) sizedirmenu++; } @@ -691,7 +686,7 @@ void searchfilemenu(char *tempname) sizedirmenu = 0; for (i = first; i < sizecoredirmenu; i++) { - if (filemenucmp(coredirmenu[i]+DIR_STRING, localmenusearch)) + if (filemenucmp(coredirmenu[i]+DIR_STRING)) { if (tempname && !strcmp(coredirmenu[i]+DIR_STRING, tempname)) { @@ -724,7 +719,10 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) tempname = Z_StrDup(dirmenu[dir_on[menudepthleft]]+DIR_STRING); // don't need to I_Error if can't make - not important, just QoL } else + { menusearch[0] = menusearch[1] = 0; // clear search + CV_StealthSet(&cv_dummyaddonsearch, ""); + } if (!(dirhandle = opendir(menupath))) // get directory { diff --git a/src/k_menu.h b/src/k_menu.h index 356a0a4ee..e85d2425e 100644 --- a/src/k_menu.h +++ b/src/k_menu.h @@ -966,6 +966,7 @@ void M_Addons(INT32 choice); void M_AddonsRefresh(void); void M_HandleAddons(INT32 choice); char *M_AddonsHeaderPath(void); +extern consvar_t cv_dummyaddonsearch; void M_Manual(INT32 choice); void M_HandleImageDef(INT32 choice); diff --git a/src/k_menudef.c b/src/k_menudef.c index 6d32a4646..b83c27273 100644 --- a/src/k_menudef.c +++ b/src/k_menudef.c @@ -1726,9 +1726,11 @@ menuitem_t MISC_Manual[] = { menu_t MISC_ManualDef = IMAGEDEF(MISC_Manual); -// Addons menu! (Just a straight port for now) +// Addons menu! menuitem_t MISC_AddonsMenu[] = { + {IT_STRING | IT_CVAR | IT_CV_STRING, NULL, NULL, + NULL, {.cvar = &cv_dummyaddonsearch}, 0, 0}, {IT_KEYHANDLER | IT_NOTHING, NULL, NULL, NULL, {.routine = M_HandleAddons}, 0, 0}, // dummy menuitem for the control func }; diff --git a/src/k_menudraw.c b/src/k_menudraw.c index 7d3f186fb..5fc87bbb4 100644 --- a/src/k_menudraw.c +++ b/src/k_menudraw.c @@ -4191,7 +4191,7 @@ void M_DrawReplayStartMenu(void) // Draw misc menus: -// Addons (this is merely copypasted, original code by toaster) +// Addons #define lsheadingheight 16 @@ -4318,16 +4318,23 @@ void M_DrawAddons(void) y += 10; M_DrawTextBox(x - (21 + 5), y, MAXSTRINGLENGTH, 1); - if (menusearch[0]) - V_DrawString(x - 18, y+8, V_ALLOWLOWERCASE, menusearch+1); - else - V_DrawString(x - 18, y+8, V_ALLOWLOWERCASE|V_TRANSLUCENT, "Type to search..."); + { + const char *str = (menusearch[0] ? cv_dummyaddonsearch.string : "Search..."); + INT32 tflag = (menusearch[0] ? 0 : V_TRANSLUCENT); + INT32 xoffs = 0; + if (itemOn == 0) + { + xoffs += 8; + V_DrawString(x + (skullAnimCounter/5) - 20, y+8, highlightflags, "\x1D"); + } + V_DrawString(x + xoffs - 18, y+8, V_ALLOWLOWERCASE|tflag, str); + } V_DrawSmallScaledPatch(x - (21 + 5 + 16), y+4, (menusearch[0] ? 0 : V_TRANSLUCENT), addonsp[NUM_EXT+3]); y += 21; - m = (addonsseperation*(2*numaddonsshown + 1)) + 2*(16-addonsseperation); + m = (addonsseperation*(2*numaddonsshown + 1)) + 1 + 2*(16-addonsseperation); V_DrawFill(x - 21, y - 1, MAXSTRINGLENGTH*8+6, m, 159); // scrollbar! @@ -4385,7 +4392,7 @@ void M_DrawAddons(void) else V_DrawSmallScaledPatch(x-(16+4), y, 0, addonsp[(type & ~EXT_LOADED)]); - if ((size_t)i == dir_on[menudepthleft]) + if (itemOn == 1 && (size_t)i == dir_on[menudepthleft]) { V_DrawFixedPatch((x-(16+4))< currentMenu->numitems - 1) + { + // Prevent looparound here + // If you're going to add any extra exceptions, DON'T. + // Add a "don't loop" flag to the menu_t struct instead. + if (currentMenu == &MISC_AddonsDef) + return false; itemOn = 0; + } else itemOn++; } while (oldItemOn != itemOn && (currentMenu->menuitems[itemOn].status & IT_TYPE) == IT_SPACE); M_UpdateMenuBGImage(false); + + return true; } -static void M_PrevOpt(void) +static boolean M_PrevOpt(void) { INT16 oldItemOn = itemOn; // prevent infinite loop @@ -747,12 +759,21 @@ static void M_PrevOpt(void) do { if (!itemOn) + { + // Prevent looparound here + // If you're going to add any extra exceptions, DON'T. + // Add a "don't loop" flag to the menu_t struct instead. + if (currentMenu == &MISC_AddonsDef) + return false; itemOn = currentMenu->numitems - 1; + } else itemOn--; } while (oldItemOn != itemOn && (currentMenu->menuitems[itemOn].status & IT_TYPE) == IT_SPACE); M_UpdateMenuBGImage(false); + + return true; } // @@ -1436,15 +1457,15 @@ static void M_HandleMenuInput(void) // Keys usable within menu if (ud > 0) { - M_NextOpt(); - S_StartSound(NULL, sfx_s3k5b); + if (M_NextOpt()) + S_StartSound(NULL, sfx_s3k5b); M_SetMenuDelay(pid); return; } else if (ud < 0) { - M_PrevOpt(); - S_StartSound(NULL, sfx_s3k5b); + if (M_PrevOpt()) + S_StartSound(NULL, sfx_s3k5b); M_SetMenuDelay(pid); return; } @@ -1683,6 +1704,8 @@ void M_Init(void) CV_RegisterVar(&cv_dummygpencore); CV_RegisterVar(&cv_dummymatchbots); + CV_RegisterVar(&cv_dummyaddonsearch); + M_UpdateMenuBGImage(true); #if 0 @@ -6280,6 +6303,8 @@ void M_Addons(INT32 choice) else dir_on[menudepthleft] = 0; + MISC_AddonsDef.lastOn = 0; // Always start on search + MISC_AddonsDef.prevMenu = currentMenu; M_SetupNextMenu(&MISC_AddonsDef, false); } @@ -6387,43 +6412,23 @@ static void M_AddonExec(INT32 ch) } } -#define len menusearch[0] -static boolean M_ChangeStringAddons(INT32 choice) +static void M_UpdateAddonsSearch(void) { - if (shiftdown && choice >= 32 && choice <= 127) - choice = shiftxform[choice]; + menusearch[0] = strlen(cv_dummyaddonsearch.string); + strlcpy(menusearch+1, cv_dummyaddonsearch.string, MAXSTRINGLENGTH); + if (!cv_addons_search_case.value) + strupr(menusearch+1); - switch (choice) +#if 0 // much slower + if (!preparefilemenu(true, false)) { - case KEY_DEL: - if (len) - { - len = menusearch[1] = 0; - return true; - } - break; - case KEY_BACKSPACE: - if (len) - { - menusearch[1+--len] = 0; - return true; - } - break; - default: - if (choice >= 32 && choice <= 127) - { - if (len < MAXSTRINGLENGTH - 1) - { - menusearch[1+len++] = (char)choice; - menusearch[1+len] = 0; - return true; - } - } - break; + UNEXIST; + return; } - return false; +#else // streamlined + searchfilemenu(NULL); +#endif } -#undef len void M_HandleAddons(INT32 choice) { @@ -6432,34 +6437,30 @@ void M_HandleAddons(INT32 choice) (void) choice; - if (M_ChangeStringAddons(choice)) - { - char *tempname = NULL; - if (dirmenu && dirmenu[dir_on[menudepthleft]]) - tempname = Z_StrDup(dirmenu[dir_on[menudepthleft]]+DIR_STRING); // don't need to I_Error if can't make - not important, just QoL -#if 0 // much slower - if (!preparefilemenu(true, false)) - { - UNEXIST; - return; - } -#else // streamlined - searchfilemenu(tempname); -#endif - } - if (menucmd[pid].dpad_ud > 0) { if (dir_on[menudepthleft] < sizedirmenu-1) + { dir_on[menudepthleft]++; - S_StartSound(NULL, sfx_s3k5b); + S_StartSound(NULL, sfx_s3k5b); + } + else if (M_NextOpt()) + { + S_StartSound(NULL, sfx_s3k5b); + } M_SetMenuDelay(pid); } else if (menucmd[pid].dpad_ud < 0) { if (dir_on[menudepthleft]) + { dir_on[menudepthleft]--; - S_StartSound(NULL, sfx_s3k5b); + S_StartSound(NULL, sfx_s3k5b); + } + else if (M_PrevOpt()) + { + S_StartSound(NULL, sfx_s3k5b); + } M_SetMenuDelay(pid); }