From 5c7bf732df5e7c3435e8f32c8399928a4fa0af2e Mon Sep 17 00:00:00 2001 From: Jaime Moreira Date: Sat, 8 Oct 2022 17:21:50 -0300 Subject: [PATCH] Player skins in menu sorted alphabetically Mods in menu are now ordered: baseq2, xatrix, rogue, ctf, the rest --- src/client/menu/menu.c | 3 +++ src/common/filesystem.c | 28 +++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/client/menu/menu.c b/src/client/menu/menu.c index 6c88bc31..0ecf4f82 100644 --- a/src/client/menu/menu.c +++ b/src/client/menu/menu.c @@ -5514,6 +5514,9 @@ PlayerModelList(void) } } + // sort skin names alphabetically + qsort(s_skinnames[mdl].data, s_skinnames[mdl].num, sizeof(char**), Q_sort_strcomp); + s_skinnames[mdl].num++; // guard pointer // at this point we have a valid player model diff --git a/src/common/filesystem.c b/src/common/filesystem.c index b7872825..66c67cd5 100644 --- a/src/common/filesystem.c +++ b/src/common/filesystem.c @@ -1357,6 +1357,32 @@ FS_FreeList(char **list, int nfiles) list = 0; } +/* + * Comparator for mod sorting + */ +static int +Q_sort_modcmp(const void *p1, const void *p2) +{ + static const char *first_mods[] = {BASEDIRNAME, "xatrix", "rogue", "ctf"}; + static const unsigned short int first_mods_qty = 4; + + const char * s1 = * (char * const *)p1; + const char * s2 = * (char * const *)p2; + + for (unsigned short int i = 0; i < first_mods_qty; i++) + { + if (!strcmp(first_mods[i], s1)) + { + return -1; + } + if (!strcmp(first_mods[i], s2)) + { + return 1; + } + } + return strcmp(s1, s2); +} + /* * Combs all Raw search paths to find game dirs containing PAK/PK2/PK3 files. * Returns an alphabetized array of unique relative dir names. @@ -1452,7 +1478,7 @@ FS_ListMods(int *nummods) modnames[nmods] = 0; - qsort(modnames, nmods, sizeof(modnames[0]), Q_sort_strcomp); + qsort(modnames, nmods, sizeof(modnames[0]), Q_sort_modcmp); *nummods = nmods; return modnames;