mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-02-02 05:52:15 +00:00
menu: fix players model menu
This commit is contained in:
parent
ded6b9c858
commit
a324ef51c9
2 changed files with 138 additions and 22 deletions
|
@ -5494,9 +5494,9 @@ PlayerDirectoryList(void)
|
||||||
{
|
{
|
||||||
char* findname = "players/*";
|
char* findname = "players/*";
|
||||||
char** list = 0;
|
char** list = 0;
|
||||||
int num = 0;
|
int num = 0, dirnum = 0;
|
||||||
|
|
||||||
/* get a list of "players" subdirectories */
|
/* get a list of "players" subdirectories or files */
|
||||||
if ((list = FS_ListFiles2(findname, &num, 0, 0)) == NULL)
|
if ((list = FS_ListFiles2(findname, &num, 0, 0)) == NULL)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -5512,10 +5512,12 @@ PlayerDirectoryList(void)
|
||||||
YQ2_COM_CHECK_OOM(data, "calloc()", num * sizeof(char*))
|
YQ2_COM_CHECK_OOM(data, "calloc()", num * sizeof(char*))
|
||||||
|
|
||||||
s_directory.data = data;
|
s_directory.data = data;
|
||||||
s_directory.num = num;
|
|
||||||
|
|
||||||
for (int i = 0; i < num; ++i)
|
for (int i = 0; i < num; ++i)
|
||||||
{
|
{
|
||||||
|
char dirname[MAX_QPATH], *dirsize;
|
||||||
|
int dirnamelen = 0, j;
|
||||||
|
|
||||||
// last element of FS_FileList maybe null
|
// last element of FS_FileList maybe null
|
||||||
if (list[i] == 0)
|
if (list[i] == 0)
|
||||||
{
|
{
|
||||||
|
@ -5524,14 +5526,39 @@ PlayerDirectoryList(void)
|
||||||
|
|
||||||
ReplaceCharacters(list[i], '\\', '/');
|
ReplaceCharacters(list[i], '\\', '/');
|
||||||
|
|
||||||
|
dirsize = strchr(list[i] + strlen(findname), '/');
|
||||||
|
if (dirsize)
|
||||||
|
{
|
||||||
|
dirnamelen = dirsize - list[i];
|
||||||
|
memcpy(dirname, list[i], dirnamelen);
|
||||||
|
dirname[dirnamelen] = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strcpy(dirname, list[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (j = 0; j < dirnum; j++)
|
||||||
|
{
|
||||||
|
if (!strcmp(dirname, data[j]))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j == dirnum)
|
||||||
|
{
|
||||||
char* s = (char*)malloc(MAX_QPATH);
|
char* s = (char*)malloc(MAX_QPATH);
|
||||||
char* t = list[i];
|
|
||||||
|
|
||||||
YQ2_COM_CHECK_OOM(s, "malloc()", MAX_QPATH * sizeof(char))
|
YQ2_COM_CHECK_OOM(s, "malloc()", MAX_QPATH * sizeof(char))
|
||||||
|
|
||||||
Q_strlcpy(s, t, MAX_QPATH);
|
Q_strlcpy(s, dirname, MAX_QPATH);
|
||||||
data[i] = s;
|
data[dirnum] = s;
|
||||||
|
dirnum ++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
s_directory.num = dirnum;
|
||||||
|
|
||||||
// free file list
|
// free file list
|
||||||
FS_FreeList(list, num);
|
FS_FreeList(list, num);
|
||||||
|
@ -5554,6 +5581,94 @@ HasSkinInDir(const char *dirname, const char *ext, int *num)
|
||||||
return FS_ListFiles2(findname, num, 0, 0);
|
return FS_ListFiles2(findname, num, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char**
|
||||||
|
HasSkinsInDir(const char *dirname, int *num)
|
||||||
|
{
|
||||||
|
char **list_png, **list_pcx, **list_m8;
|
||||||
|
char **curr = NULL, **list = NULL;
|
||||||
|
int num_png, num_pcx, num_m8;
|
||||||
|
|
||||||
|
*num = 0;
|
||||||
|
|
||||||
|
list_png = HasSkinInDir(dirname, "png", &num_png);
|
||||||
|
if (list_png)
|
||||||
|
{
|
||||||
|
*num += num_png - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
list_pcx = HasSkinInDir(dirname, "pcx", &num_pcx);
|
||||||
|
if (list_pcx)
|
||||||
|
{
|
||||||
|
*num += num_pcx - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
list_m8 = HasSkinInDir(dirname, "m8", &num_m8);
|
||||||
|
if (list_m8)
|
||||||
|
{
|
||||||
|
*num += num_m8 - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (num)
|
||||||
|
{
|
||||||
|
curr = list = malloc(sizeof(char *) * (*num + 1));
|
||||||
|
YQ2_COM_CHECK_OOM(list, "realloc()", (size_t)sizeof(char *) * (*num + 1))
|
||||||
|
|
||||||
|
if (list_png)
|
||||||
|
{
|
||||||
|
int j;
|
||||||
|
|
||||||
|
for (j = 0; j < num_png; j ++)
|
||||||
|
{
|
||||||
|
if (list_png[j])
|
||||||
|
{
|
||||||
|
*curr = list_png[j];
|
||||||
|
curr++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(list_png);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (list_pcx)
|
||||||
|
{
|
||||||
|
int j;
|
||||||
|
|
||||||
|
for (j = 0; j < num_pcx; j ++)
|
||||||
|
{
|
||||||
|
if (list_pcx[j])
|
||||||
|
{
|
||||||
|
*curr = list_pcx[j];
|
||||||
|
curr++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(list_pcx);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (list_m8)
|
||||||
|
{
|
||||||
|
int j;
|
||||||
|
|
||||||
|
for (j = 0; j < num_m8; j ++)
|
||||||
|
{
|
||||||
|
if (list_m8[j])
|
||||||
|
{
|
||||||
|
*curr = list_m8[j];
|
||||||
|
curr++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(list_m8);
|
||||||
|
}
|
||||||
|
|
||||||
|
*curr = NULL;
|
||||||
|
curr++;
|
||||||
|
*num = curr - list;
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* list all valid player models.
|
* list all valid player models.
|
||||||
|
@ -5586,15 +5701,6 @@ PlayerModelList(void)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get a list of pcx files */
|
|
||||||
if (
|
|
||||||
(list = HasSkinInDir(s_directory.data[i], "png", &num)) == NULL &&
|
|
||||||
(list = HasSkinInDir(s_directory.data[i], "pcx", &num)) == NULL &&
|
|
||||||
(list = HasSkinInDir(s_directory.data[i], "m8", &num)) == NULL)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* contains triangle .md2 model */
|
/* contains triangle .md2 model */
|
||||||
s = s_directory.data[i];
|
s = s_directory.data[i];
|
||||||
|
|
||||||
|
@ -5608,6 +5714,13 @@ PlayerModelList(void)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list = HasSkinsInDir(s_directory.data[i], &num);
|
||||||
|
/* get a list of pcx files */
|
||||||
|
if (!num || !list)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* count valid skins, which consist of a skin with a matching "_i" icon */
|
/* count valid skins, which consist of a skin with a matching "_i" icon */
|
||||||
s_skinnames[mdl].num = 0;
|
s_skinnames[mdl].num = 0;
|
||||||
|
|
||||||
|
|
|
@ -98,9 +98,9 @@ typedef struct
|
||||||
} fsPackTypes_t;
|
} fsPackTypes_t;
|
||||||
|
|
||||||
fsHandle_t fs_handles[MAX_HANDLES];
|
fsHandle_t fs_handles[MAX_HANDLES];
|
||||||
fsLink_t *fs_links;
|
fsLink_t *fs_links = NULL;
|
||||||
fsSearchPath_t *fs_searchPaths;
|
fsSearchPath_t *fs_searchPaths = NULL;
|
||||||
fsSearchPath_t *fs_baseSearchPaths;
|
fsSearchPath_t *fs_baseSearchPaths = NULL;
|
||||||
|
|
||||||
/* Pack formats / suffixes. */
|
/* Pack formats / suffixes. */
|
||||||
fsPackTypes_t fs_packtypes[] = {
|
fsPackTypes_t fs_packtypes[] = {
|
||||||
|
@ -422,9 +422,12 @@ FS_FOpenFile(const char *rawname, fileHandle_t *f, qboolean gamedir_only)
|
||||||
// TODO: A flag to ignore paks would be better
|
// TODO: A flag to ignore paks would be better
|
||||||
if ((strcmp(fs_gamedirvar->string, "") == 0) && search->pack) {
|
if ((strcmp(fs_gamedirvar->string, "") == 0) && search->pack) {
|
||||||
if ((strcmp(name, "maps.lst") == 0) || (strncmp(name, "players/", 8) == 0)) {
|
if ((strcmp(name, "maps.lst") == 0) || (strncmp(name, "players/", 8) == 0)) {
|
||||||
|
if (FS_FileInGamedir(name))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Search inside a pack file. */
|
/* Search inside a pack file. */
|
||||||
if (search->pack)
|
if (search->pack)
|
||||||
|
@ -877,7 +880,7 @@ FS_LoadPK3(const char *packPath)
|
||||||
if (unzGetGlobalInfo(handle, &global) != UNZ_OK)
|
if (unzGetGlobalInfo(handle, &global) != UNZ_OK)
|
||||||
{
|
{
|
||||||
unzClose(handle);
|
unzClose(handle);
|
||||||
Com_Error(ERR_FATAL, "FS_LoadPK3: '%s' is not a pack file", packPath);
|
Com_Error(ERR_FATAL, "%s: '%s' is not a pack file", __func__, packPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
numFiles = global.number_entry;
|
numFiles = global.number_entry;
|
||||||
|
|
Loading…
Reference in a new issue