fastarrays works properly now.
changed stereo -> numchannels in the sound code added/tweeked the download menu fixed a coupld of fs functions switched the key config menu to mouse-driven right click now closes menus git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@1901 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
f3f02e5353
commit
6f98f6f108
15 changed files with 611 additions and 245 deletions
|
@ -14,6 +14,7 @@
|
|||
#define DPF_DISPLAYVERSION 4 //some sort of conflict, the package is listed twice, so show versions so the user knows what's old.
|
||||
#define DPF_DELETEONUNINSTALL 8 //for previously installed packages, remove them from the list
|
||||
#define DPF_DOWNLOADING 16
|
||||
#define DPF_ENQUED 32
|
||||
|
||||
|
||||
int dlcount=1;
|
||||
|
@ -25,6 +26,7 @@ char *downloadablelist[256] = {
|
|||
char *downloadablelistnameprefix[256] = {
|
||||
""
|
||||
};
|
||||
char downloadablelistreceived[256]; //well
|
||||
int numdownloadablelists = 1;
|
||||
|
||||
typedef struct package_s {
|
||||
|
@ -45,10 +47,9 @@ typedef struct package_s {
|
|||
typedef struct {
|
||||
menucustom_t *list;
|
||||
char intermediatefilename[MAX_QPATH];
|
||||
char pathprefix[MAX_QPATH];
|
||||
int parsedsourcenum;
|
||||
|
||||
int firstpackagenum;
|
||||
int highlightednum;
|
||||
qboolean populated;
|
||||
} dlmenu_t;
|
||||
|
||||
package_t *availablepackages;
|
||||
|
@ -100,14 +101,12 @@ static package_t *BuildPackageList(vfsfile_t *f, int flags, char *prefix)
|
|||
int i;
|
||||
sl = Cmd_Argv(1);
|
||||
|
||||
for (i = 0; i < sizeof(downloadablelist)/sizeof(downloadablelist[0])-1; i++)
|
||||
for (i = 0; i < numdownloadablelists; i++)
|
||||
{
|
||||
if (!downloadablelist[i])
|
||||
break;
|
||||
if (!strcmp(downloadablelist[i], sl))
|
||||
break;
|
||||
}
|
||||
if (!downloadablelist[i])
|
||||
if (i == numdownloadablelists && i != 256)
|
||||
{
|
||||
downloadablelist[i] = BZ_Malloc(strlen(sl)+1);
|
||||
strcpy(downloadablelist[i], sl);
|
||||
|
@ -119,6 +118,8 @@ static package_t *BuildPackageList(vfsfile_t *f, int flags, char *prefix)
|
|||
downloadablelistnameprefix[i] = BZ_Malloc(strlen(sl)+1);
|
||||
strcpy(downloadablelistnameprefix[i], sl);
|
||||
|
||||
numdownloadablelists++;
|
||||
|
||||
i++;
|
||||
}
|
||||
continue;
|
||||
|
@ -246,15 +247,289 @@ static void dlnotification(char *localfile, qboolean sucess)
|
|||
int i;
|
||||
vfsfile_t *f;
|
||||
COM_RefreshFSCache_f();
|
||||
|
||||
i = atoi(localfile+7);
|
||||
|
||||
f = FS_OpenVFS (localfile, "rb", FS_GAME);
|
||||
if (f)
|
||||
{
|
||||
i = atoi(localfile+7);
|
||||
downloadablelistreceived[i] = 1;
|
||||
ConcatPackageLists(BuildPackageList(f, 0, downloadablelistnameprefix[i]));
|
||||
VFS_CLOSE(f);
|
||||
}
|
||||
else
|
||||
downloadablelistreceived[i] = -1;
|
||||
}
|
||||
|
||||
static void MD_Draw (int x, int y, struct menucustom_s *c, struct menu_s *m)
|
||||
{
|
||||
package_t *p;
|
||||
p = c->data;
|
||||
if (p)
|
||||
{
|
||||
Draw_Character (x, y, 128);
|
||||
Draw_Character (x+8, y, 130);
|
||||
Draw_Character (x+16, y, 128);
|
||||
Draw_Character (x+24, y, 130);
|
||||
|
||||
if (p->flags&DPF_WANTTOINSTALL)
|
||||
Draw_Character (x+4, y, 131);
|
||||
else
|
||||
Draw_Character (x+4, y, 129);
|
||||
|
||||
//if you have it already
|
||||
if (p->flags&(DPF_HAVEAVERSION | ((((int)(realtime*4))&1)?(DPF_DOWNLOADING|DPF_ENQUED):0) ))
|
||||
Draw_Character (x+20, y, 131);
|
||||
else
|
||||
Draw_Character (x+20, y, 129);
|
||||
|
||||
|
||||
if (&m->selecteditem->common == &c->common)
|
||||
Draw_Alt_String (x+48, y, p->name);
|
||||
else
|
||||
Draw_String(x+48, y, p->name);
|
||||
|
||||
if (p->flags & DPF_DISPLAYVERSION)
|
||||
{
|
||||
Draw_String(x+48+strlen(p->name)*8, y, va(" (%i.%i)", p->version/1000, p->version%1000));
|
||||
}
|
||||
}
|
||||
}
|
||||
static qboolean MD_Key (struct menucustom_s *c, struct menu_s *m, int key)
|
||||
{
|
||||
package_t *p, *p2;
|
||||
p = c->data;
|
||||
if (key == K_ENTER || key == K_MOUSE1)
|
||||
{
|
||||
p->flags ^= DPF_WANTTOINSTALL;
|
||||
|
||||
if (p->flags&DPF_WANTTOINSTALL)
|
||||
{
|
||||
for (p2 = availablepackages; p2; p2 = p2->next)
|
||||
{
|
||||
if (p == p2)
|
||||
continue;
|
||||
if (!strcmp(p->dest, p2->dest))
|
||||
p2->flags &= ~DPF_WANTTOINSTALL;
|
||||
}
|
||||
}
|
||||
else
|
||||
p->flags &= ~DPF_ENQUED;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
qboolean MD_PopMenu (union menuoption_s *mo,struct menu_s *m,int key)
|
||||
{
|
||||
if (key == K_ENTER || key == K_MOUSE1)
|
||||
{
|
||||
M_RemoveMenu(m);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void Menu_Download_Got(char *fname, qboolean successful);
|
||||
qboolean MD_ApplyDownloads (union menuoption_s *mo,struct menu_s *m,int key)
|
||||
{
|
||||
if (key == K_ENTER || key == K_MOUSE1)
|
||||
{
|
||||
char *temp;
|
||||
package_t *last = NULL, *p;
|
||||
|
||||
for (p = availablepackages; p ; p=p->next)
|
||||
{
|
||||
if (!(p->flags&DPF_WANTTOINSTALL) && (p->flags&DPF_HAVEAVERSION))
|
||||
{ //if we don't want it but we have it anyway:
|
||||
if (*p->gamedir)
|
||||
{
|
||||
char *fname = va("%s", p->gamedir, p->dest);
|
||||
FS_Remove(fname, FS_BASE);
|
||||
}
|
||||
else
|
||||
FS_Remove(p->dest, FS_GAME);
|
||||
p->flags&=~DPF_HAVEAVERSION; //FIXME: This is error prone.
|
||||
|
||||
WriteInstalledPackages();
|
||||
|
||||
if (p->flags & DPF_DELETEONUNINSTALL)
|
||||
{
|
||||
if (last)
|
||||
last->next = p->next;
|
||||
else
|
||||
availablepackages = p->next;
|
||||
|
||||
// BZ_Free(p);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
last = p;
|
||||
}
|
||||
|
||||
for (p = availablepackages; p ; p=p->next)
|
||||
{
|
||||
if ((p->flags&DPF_WANTTOINSTALL) && !(p->flags&(DPF_HAVEAVERSION|DPF_DOWNLOADING)))
|
||||
{ //if we want it and don't have it:
|
||||
p->dlnum = dlcount++;
|
||||
temp = va("dl_%i.tmp", p->dlnum);
|
||||
Con_Printf("Downloading %s (to %s)\n", p->fullname, temp);
|
||||
p->flags|=DPF_DOWNLOADING;
|
||||
if (!HTTP_CL_Get(p->src, temp, Menu_Download_Got))
|
||||
p->flags&=~DPF_DOWNLOADING;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void M_AddItemsToDownloadMenu(menu_t *m)
|
||||
{
|
||||
char path[MAX_QPATH];
|
||||
int y;
|
||||
package_t *p;
|
||||
menucustom_t *c;
|
||||
int slashpos;
|
||||
char *slash;
|
||||
menuoption_t *mo;
|
||||
dlmenu_t *info = m->data;
|
||||
int prefixlen;
|
||||
p = availablepackages;
|
||||
|
||||
MC_AddWhiteText(m, 4, 40, "W H (want, have)", false);
|
||||
|
||||
prefixlen = strlen(info->pathprefix);
|
||||
y = 48;
|
||||
for (p = availablepackages; p; p = p->next)
|
||||
{
|
||||
if (strncmp(p->fullname, info->pathprefix, prefixlen))
|
||||
continue;
|
||||
slash = strchr(p->fullname+prefixlen, '/');
|
||||
if (slash)
|
||||
{
|
||||
Q_strncpyz(path, p->fullname, MAX_QPATH);
|
||||
slash = strchr(path+prefixlen, '/');
|
||||
if (slash)
|
||||
*slash = '\0';
|
||||
|
||||
for (mo = m->options; mo; mo = mo->common.next)
|
||||
if (mo->common.type == mt_button)
|
||||
if (!strcmp(mo->button.text, path + prefixlen))
|
||||
break;
|
||||
if (!mo)
|
||||
{
|
||||
MC_AddConsoleCommand(m, 5*8, y, path+prefixlen, va("menu_download \"%s/\"", path));
|
||||
y += 8;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
c = MC_AddCustom(m, 0, y, p);
|
||||
c->draw = MD_Draw;
|
||||
c->key = MD_Key;
|
||||
c->common.width = 320;
|
||||
c->common.height = 8;
|
||||
y += 8;
|
||||
}
|
||||
}
|
||||
|
||||
y+=4;
|
||||
MC_AddCommand(m, 0, y, " Back", MD_PopMenu);
|
||||
y+=8;
|
||||
MC_AddCommand(m, 0, y, " Apply", MD_ApplyDownloads);
|
||||
/*
|
||||
for (pn = 1, p = availablepackages; p && pn < info->firstpackagenum ; p=p->next, pn++)
|
||||
|
||||
m->
|
||||
|
||||
if (lastpathlen != p->name - p->fullname || strncmp(p->fullname, lastpath, lastpathlen))
|
||||
{
|
||||
lastpathlen = p->name - p->fullname;
|
||||
lastpath = p->fullname;
|
||||
|
||||
|
||||
if (!lastpathlen)
|
||||
Draw_FunStringLen(x+40, y, "/", 1);
|
||||
else
|
||||
Draw_FunStringLen(x+40, y, p->fullname, lastpathlen);
|
||||
y+=8;
|
||||
}
|
||||
Draw_Character (x, y, 128);
|
||||
Draw_Character (x+8, y, 130);
|
||||
Draw_Character (x+16, y, 128);
|
||||
Draw_Character (x+24, y, 130);
|
||||
|
||||
//if you want it
|
||||
if (p->flags&DPF_WANTTOINSTALL)
|
||||
Draw_Character (x+4, y, 131);
|
||||
else
|
||||
Draw_Character (x+4, y, 129);
|
||||
|
||||
//if you have it already
|
||||
if (p->flags&(DPF_HAVEAVERSION | ((((int)(realtime*4))&1)?DPF_DOWNLOADING:0) ))
|
||||
Draw_Character (x+20, y, 131);
|
||||
else
|
||||
Draw_Character (x+20, y, 129);
|
||||
|
||||
if (pn == info->highlightednum)
|
||||
Draw_Alt_String(x+48, y, p->name);
|
||||
else
|
||||
Draw_String(x+48, y, p->name);
|
||||
|
||||
if (p->flags & DPF_DISPLAYVERSION)
|
||||
{
|
||||
Draw_String(x+48+strlen(p->name)*8, y, va(" (%i.%i)", p->version/1000, p->version%1000));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void M_Download_UpdateStatus(struct menu_s *m)
|
||||
{
|
||||
dlmenu_t *info = m->data;
|
||||
int i;
|
||||
|
||||
while (!cls.downloadmethod && (info->parsedsourcenum==-1 || info->parsedsourcenum < numdownloadablelists))
|
||||
{ //done downloading
|
||||
char basename[64];
|
||||
|
||||
info->parsedsourcenum++;
|
||||
|
||||
if (info->parsedsourcenum < numdownloadablelists)
|
||||
{
|
||||
if (!downloadablelistreceived[info->parsedsourcenum])
|
||||
{
|
||||
sprintf(basename, "dlinfo_%i.inf", info->parsedsourcenum);
|
||||
if (!HTTP_CL_Get(downloadablelist[info->parsedsourcenum], basename, dlnotification))
|
||||
Con_Printf("Could not contact server\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = 0; i < numdownloadablelists; i++)
|
||||
{
|
||||
if (!downloadablelistreceived[i])
|
||||
{
|
||||
// Draw_String(x+8, y+8, "Waiting for package list");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!availablepackages)
|
||||
{
|
||||
// Draw_String(x+8, y+8, "Could not obtain a package list");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!info->populated)
|
||||
{
|
||||
info->populated = true;
|
||||
M_AddItemsToDownloadMenu(m);
|
||||
}
|
||||
}
|
||||
/*
|
||||
static void M_Download_Draw (int x, int y, struct menucustom_s *c, struct menu_s *m)
|
||||
{
|
||||
int pn;
|
||||
|
@ -265,24 +540,8 @@ static void M_Download_Draw (int x, int y, struct menucustom_s *c, struct menu_s
|
|||
package_t *p;
|
||||
dlmenu_t *info = m->data;
|
||||
|
||||
if (!cls.downloadmethod && (info->parsedsourcenum==-1 || downloadablelist[info->parsedsourcenum]))
|
||||
{ //done downloading
|
||||
char basename[64];
|
||||
int i;
|
||||
|
||||
info->parsedsourcenum++;
|
||||
|
||||
if (downloadablelist[info->parsedsourcenum])
|
||||
{
|
||||
sprintf(basename, "dlinfo_%i.inf", info->parsedsourcenum);
|
||||
if (!HTTP_CL_Get(downloadablelist[info->parsedsourcenum], basename, dlnotification))
|
||||
Con_Printf("Could not contact server\n");
|
||||
}
|
||||
}
|
||||
if (!availablepackages)
|
||||
{
|
||||
Draw_String(x+8, y+8, "Could not obtain a package list");
|
||||
return;
|
||||
}
|
||||
|
||||
y+=8;
|
||||
Draw_Alt_String(x+4, y, "I H");
|
||||
|
@ -333,9 +592,10 @@ static void M_Download_Draw (int x, int y, struct menucustom_s *c, struct menu_s
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
static void Menu_Download_Got(char *fname, qboolean successful)
|
||||
{
|
||||
char *ext;
|
||||
package_t *p;
|
||||
int dlnum = atoi(fname+3);
|
||||
|
||||
|
@ -344,7 +604,7 @@ static void Menu_Download_Got(char *fname, qboolean successful)
|
|||
if (p->dlnum == dlnum)
|
||||
{
|
||||
char *destname;
|
||||
char *diskname = va("%s/%s", com_gamedir, fname);
|
||||
char *diskname = fname;
|
||||
|
||||
if (!successful)
|
||||
{
|
||||
|
@ -353,11 +613,6 @@ static void Menu_Download_Got(char *fname, qboolean successful)
|
|||
return;
|
||||
}
|
||||
|
||||
if (*p->gamedir)
|
||||
destname = va("%s/%s", p->gamedir, p->dest);
|
||||
else
|
||||
destname = va("%s", p->dest);
|
||||
|
||||
if (!(p->flags & DPF_DOWNLOADING))
|
||||
{
|
||||
Con_Printf("menu_download: We're not downloading %s, apparently\n", p->dest);
|
||||
|
@ -366,11 +621,21 @@ static void Menu_Download_Got(char *fname, qboolean successful)
|
|||
|
||||
p->flags &= ~DPF_DOWNLOADING;
|
||||
|
||||
ext = COM_FileExtension(p->dest);
|
||||
if (!stricmp(ext, "pak") || !stricmp(ext, "pk3"))
|
||||
FS_UnloadPackFiles(); //we reload them after
|
||||
|
||||
if (!FS_Rename2(diskname, destname, FS_GAME, *p->gamedir?FS_BASE:FS_GAME))
|
||||
if (*p->gamedir)
|
||||
destname = va("%s/%s", p->gamedir, p->dest);
|
||||
else
|
||||
destname = va("%s", p->dest);
|
||||
|
||||
if (!FS_Remove(destname, *p->gamedir?FS_BASE:FS_GAME))
|
||||
Con_Printf("Deleted old %s\n", destname);
|
||||
if (FS_Rename2(diskname, destname, FS_GAME, *p->gamedir?FS_BASE:FS_GAME))
|
||||
{
|
||||
Con_Printf("Couldn't rename %s to %s. Removed instead.\nPerhaps you already have it\n", diskname, destname);
|
||||
unlink(diskname);
|
||||
Con_Printf("Couldn't rename %s to %s. Removed instead.\n", diskname, destname);
|
||||
FS_Remove (diskname, FS_GAME);
|
||||
return;
|
||||
}
|
||||
Con_Printf("Downloaded %s (to %s)\n", p->name, destname);
|
||||
|
@ -378,14 +643,16 @@ static void Menu_Download_Got(char *fname, qboolean successful)
|
|||
|
||||
WriteInstalledPackages();
|
||||
|
||||
FS_ReloadPackFiles();
|
||||
ext = COM_FileExtension(p->dest);
|
||||
if (!stricmp(ext, "pak") || !stricmp(ext, "pk3"))
|
||||
FS_ReloadPackFiles();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Con_Printf("menu_download: Can't figure out where %s came from\n", fname);
|
||||
}
|
||||
|
||||
/*
|
||||
static qboolean M_Download_Key (struct menucustom_s *c, struct menu_s *m, int key)
|
||||
{
|
||||
char *temp;
|
||||
|
@ -476,9 +743,10 @@ static qboolean M_Download_Key (struct menucustom_s *c, struct menu_s *m, int ke
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
*/
|
||||
void Menu_DownloadStuff_f (void)
|
||||
{
|
||||
int i;
|
||||
menu_t *menu;
|
||||
dlmenu_t *info;
|
||||
|
||||
|
@ -488,12 +756,21 @@ void Menu_DownloadStuff_f (void)
|
|||
menu = M_CreateMenu(sizeof(dlmenu_t));
|
||||
info = menu->data;
|
||||
|
||||
menu->event = M_Download_UpdateStatus;
|
||||
/*
|
||||
menu->selecteditem = (menuoption_t *)(info->list = MC_AddCustom(menu, 0, 32, NULL));
|
||||
info->list->draw = M_Download_Draw;
|
||||
info->list->key = M_Download_Key;
|
||||
|
||||
*/
|
||||
info->parsedsourcenum = -1;
|
||||
|
||||
Q_strncpyz(info->pathprefix, Cmd_Argv(1), sizeof(info->pathprefix));
|
||||
if (!*info->pathprefix)
|
||||
{
|
||||
for (i = 0; i < numdownloadablelists; i++)
|
||||
downloadablelistreceived[i] = 0;
|
||||
}
|
||||
|
||||
MC_AddWhiteText(menu, 24, 8, "Downloads", false);
|
||||
MC_AddWhiteText(menu, 0, 16, "Probably buggy, press escape now and avoid this place!", false);
|
||||
MC_AddWhiteText(menu, 16, 24, "\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\37", false);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue