automatic mapmodel menus

auto-generate mapmodel menus depending on the actually available models
in the current map config.

Also fixes memory leak in "newmenu".

DOCREF mapmodelname mapmodelbyname mapmodelchanged
This commit is contained in:
ac-stef
2015-04-12 18:09:36 +02:00
parent f511889731
commit 57a0d286c1
3 changed files with 309 additions and 280 deletions
+25 -20
View File
@@ -813,25 +813,29 @@ struct mitemcheckbox : mitem
void *addmenu(const char *name, const char *title, bool allowinput, void (__cdecl *refreshfunc)(void *, bool), bool (__cdecl *keyfunc)(void *, int, bool, int), bool hotkeys, bool forwardkeys)
{
name = newstring(name);
gmenu &menu = menus[name];
menu.name = name;
menu.title = title;
menu.header = menu.footer = NULL;
menu.menusel = 0;
menu.mdl = NULL;
menu.allowinput = allowinput;
menu.inited = false;
menu.hotkeys = hotkeys;
menu.refreshfunc = refreshfunc;
menu.keyfunc = keyfunc;
menu.initaction = NULL;
menu.usefont = NULL;
menu.allowblink = false;
menu.dirlist = NULL;
menu.forwardkeys = forwardkeys;
lastmenu = &menu;
return &menu;
gmenu *m = menus.access(name);
if(!m)
{
name = newstring(name);
m = &menus[name];
m->name = name;
m->initaction = NULL;
m->header = m->footer = NULL;
}
m->title = title;
m->menusel = 0;
m->mdl = NULL;
m->allowinput = allowinput;
m->inited = false;
m->hotkeys = hotkeys;
m->refreshfunc = refreshfunc;
m->keyfunc = keyfunc;
m->usefont = NULL;
m->allowblink = false;
m->dirlist = NULL;
m->forwardkeys = forwardkeys;
lastmenu = m;
return m;
}
void newmenu(char *name, int *hotkeys, int *forwardkeys)
@@ -1199,9 +1203,10 @@ void rendermenumdl()
glScalef(1, -1, 1);
bool isplayermodel = !strncmp(m.mdl, "playermodels", strlen("playermodels"));
bool isweapon = !strncmp(m.mdl, "weapons", strlen("weapons"));
vec pos;
if(isplayermodel) pos = vec(2.0f, 1.2f, -0.4f);
if(!isweapon) pos = vec(2.0f, 1.2f, -0.4f);
else pos = vec(2.0f, 0, 1.7f);
float yaw = 1.0f;
+12
View File
@@ -86,6 +86,8 @@ void mdlcachelimit(int *limit)
COMMAND(mdlcachelimit, "i");
VAR(mapmodelchanged, 0, 0, 1);
vector<mapmodelinfo> mapmodels;
void mapmodel(int *rad, int *h, int *zoff, char *snap, char *name)
@@ -96,11 +98,13 @@ void mapmodel(int *rad, int *h, int *zoff, char *snap, char *name)
mmi.zoff = *zoff;
mmi.m = NULL;
formatstring(mmi.name)("mapmodels/%s", name);
mapmodelchanged = 1;
}
void mapmodelreset()
{
if(execcontext==IEXC_MAPCFG) mapmodels.shrink(0);
mapmodelchanged = 1;
}
mapmodelinfo &getmminfo(int i) { return mapmodels.inrange(i) ? mapmodels[i] : *(mapmodelinfo *)0; }
@@ -108,6 +112,14 @@ mapmodelinfo &getmminfo(int i) { return mapmodels.inrange(i) ? mapmodels[i] : *(
COMMAND(mapmodel, "iiiss");
COMMAND(mapmodelreset, "");
COMMANDF(mapmodelname, "i", (int *idx) { result(mapmodels.inrange(*idx) ? mapmodels[*idx].name : ""); });
COMMANDF(mapmodelbyname, "s", (char *name)
{
string res = "";
loopv(mapmodels) if(!strcmp(name, mapmodels[i].name)) concatformatstring(res, "%s%d", *res ? " " : "", i);
result(res);
});
hashtable<const char *, model *> mdllookup;
hashtable<const char *, char> mdlnotfound;