customisable sort order for file lists in menus
This commit is contained in:
@@ -430,6 +430,8 @@ menuitem [Bot settings...] [ showmenu [Bot s
|
||||
tempalias __screenshottype 0
|
||||
alias askquit 1
|
||||
alias showmenuonstartup 1
|
||||
alias menufilesort_cgz 0
|
||||
alias menufilesort_dmo 0
|
||||
|
||||
newmenu Misc
|
||||
menuitemcheckbox [Auto map download: ] "$autogetmap" [ autogetmap $arg1 ]
|
||||
@@ -448,6 +450,8 @@ menuitemslider [Mini-map background style: ] 0 2 "$showmapbackdrop" 1 ["Fully Tr
|
||||
menuitemcheckbox [Enable compatibility with older cubescripts: ] "$compatibilitymode" [ compatibilitymode $arg1; echo (c 3) This setting requires a restart to take effect. ]
|
||||
menuitemcheckbox [Enable per-official map dynamic gamma: ] "$dyngamma" [ dyngamma = $arg1 ]
|
||||
menuitemtextinput [Set default gamma for this map: ] "(at $ofc_gamma_list (findlist $defaultmaps (curmap 1)))" [ setgamma $arg1 ]
|
||||
menuitemslider [Menu map file sort order: ] 0 (- (listlen (listoptions menufilesortorders)) 1) "$menufilesort_cgz" 1 (listoptions menufilesortorders) [menufilesort_cgz = $arg1]
|
||||
menuitemslider [Menu demo file sort order: ] 0 (- (listlen (listoptions menufilesortorders)) 1) "$menufilesort_dmo" 1 (listoptions menufilesortorders) [menufilesort_dmo = $arg1]
|
||||
|
||||
// Reduced game violence mode...
|
||||
const reducedviolencemode [
|
||||
|
||||
@@ -1343,7 +1343,9 @@ char *strreplace(char *dest, const char *source, const char *search, const char
|
||||
}
|
||||
|
||||
int stringsort(const char **a, const char **b) { return strcmp(*a, *b); }
|
||||
int stringsortrev(const char **a, const char **b) { return strcmp(*b, *a); }
|
||||
int stringsortignorecase(const char **a, const char **b) { return strcasecmp(*a, *b); }
|
||||
int stringsortignorecaserev(const char **a, const char **b) { return strcasecmp(*b, *a); }
|
||||
|
||||
void sortlist(char *list)
|
||||
{
|
||||
@@ -1750,8 +1752,9 @@ COMMAND(getscrext, "");
|
||||
|
||||
void listoptions(char *s)
|
||||
{
|
||||
const char *optionnames[] = { "entities", "ents", "weapons", "teamnames", "teamnames-abbrv", "punctuations", "crosshairnames", "" };
|
||||
const char **optionlists[] = { optionnames, entnames + 1, entnames + 1, gunnames, teamnames, teamnames_s, punctnames, crosshairnames };
|
||||
extern const char *menufilesortorders[];
|
||||
const char *optionnames[] = { "entities", "ents", "weapons", "teamnames", "teamnames-abbrv", "punctuations", "crosshairnames", "menufilesortorders", "" };
|
||||
const char **optionlists[] = { optionnames, entnames + 1, entnames + 1, gunnames, teamnames, teamnames_s, punctnames, crosshairnames, menufilesortorders };
|
||||
const char **listp = optionlists[getlistindex(s, optionnames, true, -1) + 1];
|
||||
commandret = conc(listp, -1, true);
|
||||
}
|
||||
|
||||
@@ -1257,14 +1257,21 @@ void gmenu::conprintmenu()
|
||||
loopv(items) { conoutf("%03d: %s%s%s", 1+i, items[i]->gettext(), items[i]->getaction()?"|\t|":"", items[i]->getaction()?items[i]->getaction():""); }
|
||||
}
|
||||
|
||||
const char *menufilesortorders[] = { "normal", "reverse", "ignorecase", "ignorecase_reverse", "" };
|
||||
int (*menufilesortcmp[])(const char **, const char **) = { stringsort, stringsortrev, stringsortignorecase, stringsortignorecaserev };
|
||||
|
||||
void gmenu::init()
|
||||
{
|
||||
if(dirlist && ((dirlist->dir != NULL) && (dirlist->ext != NULL)))
|
||||
if(dirlist && dirlist->dir && dirlist->ext)
|
||||
{
|
||||
items.deletecontents();
|
||||
vector<char *> files;
|
||||
listfiles(dirlist->dir, dirlist->ext, files);
|
||||
files.sort(stringsort);
|
||||
defformatstring(sortorderalias)("menufilesort_%s", dirlist->ext);
|
||||
int sortorderindex = 0;
|
||||
const char *customsortorder = getalias(sortorderalias);
|
||||
if(customsortorder) sortorderindex = getlistindex(customsortorder, menufilesortorders, true, 0);
|
||||
files.sort(menufilesortcmp[sortorderindex]);
|
||||
loopv(files)
|
||||
{
|
||||
char *f = files[i];
|
||||
|
||||
@@ -791,7 +791,9 @@ extern void renderdocmenu(void *menu, bool init);
|
||||
extern void toggledoc();
|
||||
extern void scrolldoc(int i);
|
||||
extern int stringsort(const char **a, const char **b);
|
||||
extern int stringsortrev(const char **a, const char **b);
|
||||
extern int stringsortignorecase(const char **a, const char **b);
|
||||
extern int stringsortignorecaserev(const char **a, const char **b);
|
||||
extern const char *docgetdesc(const char *name);
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user