Rename definegamename to setgamename and alter the "map" console command to show a listing of all available maps if no map name is given

git-svn-id: https://svn.eduke32.com/eduke32@987 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2008-08-17 11:07:28 +00:00
parent 63e5850a86
commit da6b206673
6 changed files with 65 additions and 7 deletions

View file

@ -43,6 +43,8 @@ char *OSD_GetFmt(char *ptr);
char *OSD_GetTextPtr(void); char *OSD_GetTextPtr(void);
char *OSD_GetFmtPtr(void); char *OSD_GetFmtPtr(void);
int OSD_GetCols(void);
// initializes things // initializes things
void OSD_Init(void); void OSD_Init(void);

View file

@ -194,6 +194,11 @@ char *OSD_GetFmt(char *ptr)
return (ptr - &osdtext[0] + &osdfmt[0]); return (ptr - &osdtext[0] + &osdfmt[0]);
} }
int OSD_GetCols(void)
{
return osdcols;
}
int OSD_GetTextMode(void) int OSD_GetTextMode(void)
{ {
return osdtextmode; return osdtextmode;

View file

@ -464,7 +464,7 @@ const char *keyw[] =
"loadmapstate", // 327 "loadmapstate", // 327
"clearmapstate", // 328 "clearmapstate", // 328
"scriptsize", // 329 "scriptsize", // 329
"definegamename", // 330 "setgamename", // 330
"cmenu", // 331 "cmenu", // 331
"gettimedate", // 332 "gettimedate", // 332
"activatecheat", // 333 "activatecheat", // 333
@ -4554,7 +4554,7 @@ repeatcase:
skill_names[j][i] = '\0'; skill_names[j][i] = '\0';
return 0; return 0;
case CON_DEFINEGAMENAME: case CON_SETGAMENAME:
{ {
char gamename[32]; char gamename[32];
scriptptr--; scriptptr--;

View file

@ -840,7 +840,7 @@ enum keywords
CON_LOADMAPSTATE, // 327 CON_LOADMAPSTATE, // 327
CON_CLEARMAPSTATE, // 328 CON_CLEARMAPSTATE, // 328
CON_SCRIPTSIZE, // 329 CON_SCRIPTSIZE, // 329
CON_DEFINEGAMENAME, // 330 CON_SETGAMENAME, // 330
CON_CMENU, // 331 CON_CMENU, // 331
CON_GETTIMEDATE, // 332 CON_GETTIMEDATE, // 332
CON_ACTIVATECHEAT, // 333 CON_ACTIVATECHEAT, // 333

View file

@ -169,12 +169,63 @@ static int osdcmd_changelevel(const osdfuncparm_t *parm)
return OSDCMD_OK; return OSDCMD_OK;
} }
static CACHE1D_FIND_REC *findfiles = NULL;
static int numfiles = 0;
static void clearfilenames(void)
{
klistfree(findfiles);
findfiles = NULL;
numfiles = 0;
}
static int getfilenames(char *path)
{
CACHE1D_FIND_REC *r;
clearfilenames();
findfiles = klistpath(path,"*.MAP",CACHE1D_FIND_FILE);
for (r = findfiles; r; r=r->next) numfiles++;
return(0);
}
static int osdcmd_map(const osdfuncparm_t *parm) static int osdcmd_map(const osdfuncparm_t *parm)
{ {
int i; int i;
CACHE1D_FIND_REC *r;
char filename[256]; char filename[256];
if (parm->numparms != 1) return OSDCMD_SHOWHELP; if (parm->numparms != 1)
{
int maxwidth = 0;
getfilenames("/");
for (r=findfiles; r!=NULL; r=r->next)
maxwidth = max((unsigned)maxwidth,Bstrlen(r->name));
if (maxwidth > 0)
{
int x = 0, count = 0;
maxwidth += 3;
OSD_Printf(OSDTEXT_RED "Map listing:\n");
for (r=findfiles; r!=NULL; r=r->next)
{
OSD_Printf("%-*s",maxwidth,r->name);
x += maxwidth;
count++;
if (x > OSD_GetCols() - maxwidth)
{
x = 0;
OSD_Printf("\n");
}
}
if (x) OSD_Printf("\n");
OSD_Printf(OSDTEXT_RED "Found %d maps\n",numfiles);
}
return OSDCMD_SHOWHELP;
}
#if 0 #if 0
if (numplayers > 1) if (numplayers > 1)
@ -1366,7 +1417,7 @@ int registerosdcommands(void)
else else
{ {
OSD_RegisterFunction("changelevel","changelevel <volume> <level>: warps to the given level", osdcmd_changelevel); OSD_RegisterFunction("changelevel","changelevel <volume> <level>: warps to the given level", osdcmd_changelevel);
OSD_RegisterFunction("map","map <mapfile>: loads the given user map", osdcmd_map); OSD_RegisterFunction("map","map <mapfile>: loads a map", osdcmd_map);
} }
OSD_RegisterFunction("addpath","addpath <path>: adds path to game filesystem", osdcmd_addpath); OSD_RegisterFunction("addpath","addpath <path>: adds path to game filesystem", osdcmd_addpath);

View file

@ -49,14 +49,14 @@ static int done = -1, mode = TAB_CONFIG;
static CACHE1D_FIND_REC *finddirs=NULL; static CACHE1D_FIND_REC *finddirs=NULL;
static int numdirs=0; static int numdirs=0;
void clearfilenames(void) static void clearfilenames(void)
{ {
klistfree(finddirs); klistfree(finddirs);
finddirs = NULL; finddirs = NULL;
numdirs = 0; numdirs = 0;
} }
int getfilenames(char *path) static int getfilenames(char *path)
{ {
CACHE1D_FIND_REC *r; CACHE1D_FIND_REC *r;