Add name/date/rating sorting to the qi plugin to make it a smidge more friendly.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5901 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
98da911996
commit
b0e4884b7b
1 changed files with 113 additions and 30 deletions
143
plugins/qi/qi.c
143
plugins/qi/qi.c
|
@ -331,7 +331,7 @@ static void QI_RefreshMapList(qboolean forcedisplay)
|
||||||
day = atoi(date?date:"1");
|
day = atoi(date?date:"1");
|
||||||
date = date?strchr(date, '.'):NULL;
|
date = date?strchr(date, '.'):NULL;
|
||||||
month = atoi(date?date+1:"1");
|
month = atoi(date?date+1:"1");
|
||||||
date = date?strchr(date, '.'):NULL;
|
date = date?strchr(date+1, '.'):NULL;
|
||||||
year = atoi(date?date+1:"1990");
|
year = atoi(date?date+1:"1990");
|
||||||
if (year < 90)
|
if (year < 90)
|
||||||
year += 2000;
|
year += 2000;
|
||||||
|
@ -365,6 +365,7 @@ static void QI_RefreshMapList(qboolean forcedisplay)
|
||||||
Con_SubPrintf(console, "^[Change Filter^]\n");
|
Con_SubPrintf(console, "^[Change Filter^]\n");
|
||||||
Con_SubPrintf(console, "^[Maps^] %s\n", (filters.type!=2)?"shown":"hidden");
|
Con_SubPrintf(console, "^[Maps^] %s\n", (filters.type!=2)?"shown":"hidden");
|
||||||
Con_SubPrintf(console, "^[Mods^] %s\n", (filters.type!=1)?"shown":"hidden");
|
Con_SubPrintf(console, "^[Mods^] %s\n", (filters.type!=1)?"shown":"hidden");
|
||||||
|
Con_SubPrintf(console, "Sort: ^[Alphabetically^] ^[Date^] ^[Rating^]\n");
|
||||||
if (filters.minrating == filters.maxrating)
|
if (filters.minrating == filters.maxrating)
|
||||||
{
|
{
|
||||||
char *gah[] = {"Any Rating", "Unrated", "1","2","3","4","5"};
|
char *gah[] = {"Any Rating", "Unrated", "1","2","3","4","5"};
|
||||||
|
@ -525,6 +526,79 @@ static void QI_RunMap(xmltree_t *qifile, const char *map)
|
||||||
cmdfuncs->AddText("\n", false);
|
cmdfuncs->AddText("\n", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static unsigned int QI_GetDate(xmltree_t *file)
|
||||||
|
{
|
||||||
|
unsigned int day, month, year;
|
||||||
|
const char *date = XML_GetChildBody(file, "date", "1.1.1990");
|
||||||
|
day = atoi(date?date:"1");
|
||||||
|
date = date?strchr(date, '.'):NULL;
|
||||||
|
month = atoi(date?date+1:"1");
|
||||||
|
date = date?strchr(date+1, '.'):NULL;
|
||||||
|
year = atoi(date?date+1:"1990");
|
||||||
|
if (year < 90)
|
||||||
|
year += 2000;
|
||||||
|
else if (year < 1900)
|
||||||
|
year += 1900;
|
||||||
|
return year*10000 + month*100 + day;
|
||||||
|
}
|
||||||
|
static int QDECL QI_ResortName (const void *v1, const void *v2)
|
||||||
|
{
|
||||||
|
const char *n1 = XML_GetChildBody(*(xmltree_t*const*)v1, "title", "<NO TITLE>");
|
||||||
|
const char *n2 = XML_GetChildBody(*(xmltree_t*const*)v2, "title", "<NO TITLE>");
|
||||||
|
return strcasecmp(n1,n2);
|
||||||
|
}
|
||||||
|
static int QDECL QI_ResortDate (const void *v1, const void *v2)
|
||||||
|
{
|
||||||
|
unsigned int d1 = QI_GetDate(*(xmltree_t*const*)v1);
|
||||||
|
unsigned int d2 = QI_GetDate(*(xmltree_t*const*)v2);
|
||||||
|
|
||||||
|
if (d1>d2)
|
||||||
|
return 1;
|
||||||
|
if (d1<d2)
|
||||||
|
return -1;
|
||||||
|
return QI_ResortName(v1,v2);
|
||||||
|
}
|
||||||
|
static int QDECL QI_ResortRating (const void *v1, const void *v2)
|
||||||
|
{
|
||||||
|
int r1 = atoi(XML_GetParameter(*(xmltree_t*const*)v1, "rating", ""));
|
||||||
|
int r2 = atoi(XML_GetParameter(*(xmltree_t*const*)v2, "rating", ""));
|
||||||
|
|
||||||
|
if (r1>r2)
|
||||||
|
return 1;
|
||||||
|
if (r1<r2)
|
||||||
|
return -1;
|
||||||
|
return QI_ResortDate(v1,v2); //equal... go by date.
|
||||||
|
}
|
||||||
|
|
||||||
|
static qboolean QI_Resort(int sorttype)
|
||||||
|
{
|
||||||
|
xmltree_t *file;
|
||||||
|
xmltree_t **files;
|
||||||
|
unsigned int count;
|
||||||
|
if (!thedatabase || !thedatabase->child)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
for (count = 0, file = thedatabase->child; file; file = file->sibling)
|
||||||
|
count++;
|
||||||
|
files = malloc(sizeof(*files)*count);
|
||||||
|
for (count = 0, file = thedatabase->child; file; file = file->sibling)
|
||||||
|
files[count++] = file;
|
||||||
|
if (sorttype == 0)
|
||||||
|
qsort(files, count, sizeof(*files), QI_ResortName);
|
||||||
|
else if (sorttype == 1)
|
||||||
|
qsort(files, count, sizeof(*files), QI_ResortDate);
|
||||||
|
else if (sorttype == 2)
|
||||||
|
qsort(files, count, sizeof(*files), QI_ResortRating);
|
||||||
|
thedatabase->child = NULL;
|
||||||
|
while (count --> 0)
|
||||||
|
{
|
||||||
|
file = files[count];
|
||||||
|
file->sibling = thedatabase->child;
|
||||||
|
thedatabase->child = file;
|
||||||
|
}
|
||||||
|
QI_RefreshMapList(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
static qboolean QDECL QI_ConsoleLink(void)
|
static qboolean QDECL QI_ConsoleLink(void)
|
||||||
{
|
{
|
||||||
xmltree_t *file;
|
xmltree_t *file;
|
||||||
|
@ -536,36 +610,45 @@ static qboolean QDECL QI_ConsoleLink(void)
|
||||||
cmdfuncs->Argv(0, text, sizeof(text));
|
cmdfuncs->Argv(0, text, sizeof(text));
|
||||||
cmdfuncs->Argv(1, link, sizeof(link));
|
cmdfuncs->Argv(1, link, sizeof(link));
|
||||||
|
|
||||||
if (!strcmp(text, "Change Filter") && !*link)
|
if (!*link)
|
||||||
{
|
{
|
||||||
const char *console = WINDOWNAME;
|
if (!strcmp(text, "Change Filter"))
|
||||||
confuncs->SetConsoleFloat(console, "linebuffered", true);
|
{
|
||||||
confuncs->SetConsoleString(console, "footer", "Please enter filter:");
|
const char *console = WINDOWNAME;
|
||||||
return true;
|
confuncs->SetConsoleFloat(console, "linebuffered", true);
|
||||||
}
|
confuncs->SetConsoleString(console, "footer", "Please enter filter:");
|
||||||
if (!strcmp(text, "Maps") && !*link)
|
return true;
|
||||||
{
|
}
|
||||||
filters.type = (filters.type==2)?0:2;
|
if (!strcmp(text, "Maps"))
|
||||||
QI_RefreshMapList(true);
|
{
|
||||||
return true;
|
filters.type = (filters.type==2)?0:2;
|
||||||
}
|
QI_RefreshMapList(true);
|
||||||
if (!strcmp(text, "Mods") && !*link)
|
return true;
|
||||||
{
|
}
|
||||||
filters.type = (filters.type==1)?0:1;
|
if (!strcmp(text, "Mods"))
|
||||||
QI_RefreshMapList(true);
|
{
|
||||||
return true;
|
filters.type = (filters.type==1)?0:1;
|
||||||
}
|
QI_RefreshMapList(true);
|
||||||
if (!strcmp(text, "Any Rating") && !*link)
|
return true;
|
||||||
{
|
}
|
||||||
filters.minrating = filters.maxrating = -1;
|
if (!strcmp(text, "Any Rating"))
|
||||||
QI_RefreshMapList(true);
|
{
|
||||||
return true;
|
filters.minrating = filters.maxrating = -1;
|
||||||
}
|
QI_RefreshMapList(true);
|
||||||
if ((atoi(text) || !strcmp(text, "Unrated")) && !*link)
|
return true;
|
||||||
{
|
}
|
||||||
filters.minrating = filters.maxrating = atoi(text);
|
if (atoi(text) || !strcmp(text, "Unrated"))
|
||||||
QI_RefreshMapList(true);
|
{
|
||||||
return true;
|
filters.minrating = filters.maxrating = atoi(text);
|
||||||
|
QI_RefreshMapList(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (atoi(text) || !strcmp(text, "Alphabetically"))
|
||||||
|
return QI_Resort(0);
|
||||||
|
if (atoi(text) || !strcmp(text, "Date"))
|
||||||
|
return QI_Resort(1);
|
||||||
|
if (atoi(text) || !strcmp(text, "Rating"))
|
||||||
|
return QI_Resort(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue