firstrun script, new menu items, lanconnect fix
git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@1512 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
+427
-189
@@ -8,16 +8,12 @@ gmenu *curmenu = NULL, *lastmenu = NULL;
|
||||
|
||||
vector<gmenu *> menustack;
|
||||
|
||||
|
||||
void menuset(void *m)
|
||||
{
|
||||
if(curmenu==m) return;
|
||||
curmenu = (gmenu *)m;
|
||||
if(curmenu)
|
||||
{
|
||||
curmenu->inited = false;
|
||||
if(curmenu->allowinput) player1->stopmoving();
|
||||
else curmenu->menusel = 0;
|
||||
}
|
||||
if(curmenu) curmenu->close();
|
||||
if((curmenu = (gmenu *)m)) curmenu->open();
|
||||
}
|
||||
|
||||
void showmenu(char *name)
|
||||
@@ -32,6 +28,28 @@ void showmenu(char *name)
|
||||
menuset(m);
|
||||
}
|
||||
|
||||
void menuselect(void *menu, int sel)
|
||||
{
|
||||
gmenu &m = *(gmenu *)menu;
|
||||
|
||||
if(sel<0) sel = m.items.length()>0 ? m.items.length()-1 : 0;
|
||||
else if(sel>=m.items.length()) sel = 0;
|
||||
|
||||
if(m.items.inrange(sel))
|
||||
{
|
||||
int oldsel = m.menusel;
|
||||
m.menusel = sel;
|
||||
if(m.allowinput)
|
||||
{
|
||||
if(sel!=oldsel)
|
||||
{
|
||||
m.items[oldsel]->focus(false);
|
||||
m.items[sel]->focus(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void drawarrow(int dir, int x, int y, int size, float r = 1.0f, float g = 1.0f, float b = 1.0f)
|
||||
{
|
||||
glDisable(GL_BLEND);
|
||||
@@ -49,13 +67,6 @@ void drawarrow(int dir, int x, int y, int size, float r = 1.0f, float g = 1.0f,
|
||||
glEnable(GL_BLEND);
|
||||
}
|
||||
|
||||
void drawmenubg(int x1, int y1, int x2, int y2, bool border)
|
||||
{
|
||||
static Texture *tex = NULL;
|
||||
if(!tex) tex = textureload("packages/textures/makke/menu.jpg");
|
||||
blendbox(x1, y1, x2, y2, border, tex->id);
|
||||
}
|
||||
|
||||
#define MAXMENU 34
|
||||
|
||||
bool menuvisible()
|
||||
@@ -69,68 +80,433 @@ bool menuvisible()
|
||||
}
|
||||
|
||||
void rendermenu()
|
||||
{
|
||||
{
|
||||
setscope(false);
|
||||
|
||||
gmenu &m = *curmenu;
|
||||
if(m.refreshfunc)
|
||||
{
|
||||
(*m.refreshfunc)(curmenu, !m.inited);
|
||||
m.inited = true;
|
||||
if(m.menusel>=m.items.length()) m.menusel = max(m.items.length()-1, 0);
|
||||
}
|
||||
const char *title = m.title;
|
||||
if(!title) { static string buf; s_sprintf(buf)("[ %s menu ]", m.name); title = buf; }
|
||||
int hitems = (m.header ? 2 : 0) + (m.footer ? 2 : 0),
|
||||
m.refresh();
|
||||
m.render();
|
||||
}
|
||||
|
||||
|
||||
void gmenu::refresh()
|
||||
{
|
||||
if(!refreshfunc) return;
|
||||
(*refreshfunc)(this, !inited);
|
||||
inited = true;
|
||||
if(menusel>=items.length()) menusel = max(items.length()-1, 0);
|
||||
}
|
||||
|
||||
void gmenu::open()
|
||||
{
|
||||
inited = false;
|
||||
if(allowinput) player1->stopmoving();
|
||||
else menusel = 0;
|
||||
if(items.inrange(menusel)) items[menusel]->focus(true);
|
||||
loopv(items) items[i]->init();
|
||||
}
|
||||
|
||||
void gmenu::close()
|
||||
{
|
||||
if(items.inrange(menusel)) items[menusel]->focus(false);
|
||||
}
|
||||
|
||||
void gmenu::render()
|
||||
{
|
||||
const char *t = title;
|
||||
if(!t) { static string buf; s_sprintf(buf)("[ %s menu ]", name); t = buf; }
|
||||
int hitems = (header ? 2 : 0) + (footer ? 2 : 0),
|
||||
pagesize = MAXMENU - hitems,
|
||||
offset = m.menusel - (m.menusel%pagesize),
|
||||
mdisp = min(m.items.length(), pagesize),
|
||||
cdisp = min(m.items.length()-offset, pagesize);
|
||||
if(m.title) text_startcolumns();
|
||||
offset = menusel - (menusel%pagesize),
|
||||
mdisp = min(items.length(), pagesize),
|
||||
cdisp = min(items.length()-offset, pagesize);
|
||||
if(title) text_startcolumns();
|
||||
int w = 0;
|
||||
loopv(m.items)
|
||||
loopv(items)
|
||||
{
|
||||
int x = text_width(m.items[i].text);
|
||||
int x = items[i]->width();
|
||||
if(x>w) w = x;
|
||||
}
|
||||
int tw = text_width(title);
|
||||
int tw = text_width(t);
|
||||
if(tw>w) w = tw;
|
||||
if(m.header)
|
||||
if(header)
|
||||
{
|
||||
int hw = text_width(m.header);
|
||||
int hw = text_width(header);
|
||||
if(hw>w) w = hw;
|
||||
}
|
||||
|
||||
int step = (FONTH*5)/4;
|
||||
int h = (mdisp+hitems+2)*step;
|
||||
int y = (2*VIRTH-h)/2;
|
||||
int x = (2*VIRTW-w)/2;
|
||||
drawmenubg(x-FONTH*3/2, y-FONTH, x+w+FONTH*3/2, y+h+FONTH, true);
|
||||
renderbg(x-FONTH*3/2, y-FONTH, x+w+FONTH*3/2, y+h+FONTH, true);
|
||||
if(offset>0) drawarrow(1, x+w+FONTH*3/2-FONTH*5/6, y-FONTH*5/6, FONTH*2/3);
|
||||
if(offset+pagesize<m.items.length()) drawarrow(0, x+w+FONTH*3/2-FONTH*5/6, y+h+FONTH/6, FONTH*2/3);
|
||||
if(m.header)
|
||||
if(offset+pagesize<items.length()) drawarrow(0, x+w+FONTH*3/2-FONTH*5/6, y+h+FONTH/6, FONTH*2/3);
|
||||
if(header)
|
||||
{
|
||||
draw_text(m.header, x, y);
|
||||
draw_text(header, x, y);
|
||||
y += step*2;
|
||||
}
|
||||
draw_text(title, x, y);
|
||||
draw_text(t, x, y);
|
||||
y += step*2;
|
||||
if(m.allowinput)
|
||||
{
|
||||
int bh = y+(m.menusel%pagesize)*step;
|
||||
blendbox(x-FONTH, bh-FONTH/6, x+w+FONTH, bh+FONTH+FONTH/6, false);
|
||||
}
|
||||
loopj(cdisp)
|
||||
{
|
||||
color *c = m.items[offset+j].bgcolor;
|
||||
if(c) blendbox(x-FONTH, y-FONTH/6, x+w+FONTH, y+FONTH+FONTH/6, false, -1, c);
|
||||
draw_text(m.items[offset+j].text, x, y);
|
||||
items[offset+j]->render(x, y, w);
|
||||
y += step;
|
||||
}
|
||||
if(m.title) text_endcolumns();
|
||||
if(m.footer)
|
||||
if(title) text_endcolumns();
|
||||
if(footer)
|
||||
{
|
||||
y += ((mdisp-cdisp)+1)*step;
|
||||
draw_text(m.footer, x, y);
|
||||
draw_text(footer, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
void gmenu::renderbg(int x1, int y1, int x2, int y2, bool border)
|
||||
{
|
||||
static Texture *tex = NULL;
|
||||
if(!tex) tex = textureload("packages/textures/makke/menu.jpg");
|
||||
blendbox(x1, y1, x2, y2, border, tex->id);
|
||||
}
|
||||
|
||||
void mitem::render(int x, int y, int w)
|
||||
{
|
||||
if(bgcolor) renderbg(x, y, w);
|
||||
else if(isselection()) blendbox(x-FONTH, y-FONTH/6, x+w+FONTH, y+FONTH+FONTH/6, false);
|
||||
}
|
||||
|
||||
void mitem::renderbg(int x, int y, int w) { blendbox(x-FONTH, y-FONTH/6, x+w+FONTH, y+FONTH+FONTH/6, false, -1, bgcolor); };
|
||||
|
||||
bool mitem::isselection() { return parent->items.inrange(parent->menusel) && parent->items[parent->menusel]==this; }
|
||||
|
||||
// text item
|
||||
|
||||
struct mitemtext : mitem
|
||||
{
|
||||
char *text, *action, *hoveraction;
|
||||
|
||||
mitemtext(gmenu *parent, char *text, char *action, char *hoveraction, color *bgcolor) : mitem(parent, bgcolor), text(text), action(action), hoveraction(hoveraction) {}
|
||||
virtual ~mitemtext()
|
||||
{
|
||||
DELETEA(text);
|
||||
DELETEA(action);
|
||||
DELETEA(hoveraction);
|
||||
}
|
||||
|
||||
virtual int width() { return text_width(text); }
|
||||
|
||||
virtual void render(int x, int y, int w)
|
||||
{
|
||||
mitem::render(x, y, w);
|
||||
draw_text(text, x, y);
|
||||
}
|
||||
|
||||
virtual void focus(bool on)
|
||||
{
|
||||
if(on && hoveraction) execute(hoveraction);
|
||||
}
|
||||
|
||||
virtual void select()
|
||||
{
|
||||
if(action)
|
||||
{
|
||||
menustack.add(curmenu);
|
||||
menuset(NULL);
|
||||
execute(action);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// text input item
|
||||
|
||||
struct mitemtextinput : mitemtext
|
||||
{
|
||||
textinputbuffer input;
|
||||
char *defaultvalueexp;
|
||||
|
||||
mitemtextinput(gmenu *parent, char *text, char *value, char *action, char *hoveraction, color *bgcolor) : mitemtext(parent, text, action, hoveraction, bgcolor), defaultvalueexp(value)
|
||||
{
|
||||
s_strcpy(input.buf, value);
|
||||
};
|
||||
|
||||
virtual ~mitemtextinput() { }
|
||||
|
||||
virtual void select() { focus(false); focus(true); } // fixme
|
||||
|
||||
virtual int width() { return text_width(input.buf) + text_width(text); }
|
||||
|
||||
virtual void render(int x, int y, int w)
|
||||
{
|
||||
bool selection = isselection();
|
||||
int tw = text_width(text);
|
||||
if(selection) blendbox(x+tw, y-FONTH/6, x+w+FONTH, y+FONTH+FONTH/6, false);
|
||||
draw_text(text, x, y);
|
||||
int offset = text_width(input.buf, input.pos>=0 ? input.pos : -1);
|
||||
if(selection) blendbox(x+tw+offset, y, x+tw+offset+char_width(input.pos>=0 ? input.buf[input.pos] : '_'), y+FONTH, true);
|
||||
draw_text(input.buf, x+tw, y);
|
||||
}
|
||||
|
||||
virtual void focus(bool on)
|
||||
{
|
||||
SDL_EnableUNICODE(on);
|
||||
if(!strlen(input.buf)) setdefaultvalue();
|
||||
if(action)
|
||||
{
|
||||
alias("arg1", on ? "1" : "0");
|
||||
alias("arg2", input.buf);
|
||||
execute(action);
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool key(int code, bool isdown, int unicode)
|
||||
{
|
||||
input.key(code, isdown, unicode);
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void init()
|
||||
{
|
||||
setdefaultvalue();
|
||||
}
|
||||
|
||||
void setdefaultvalue()
|
||||
{
|
||||
const char *p = defaultvalueexp;
|
||||
s_strcpy(input.buf, parseword(p));
|
||||
}
|
||||
};
|
||||
|
||||
// slider item
|
||||
|
||||
struct mitemslider : mitem
|
||||
{
|
||||
int min_, max_, step, value;
|
||||
char *text, *valueexp, *display, *action;
|
||||
|
||||
mitemslider(gmenu *parent, char *text, int min_, int max_, int step, char *value, char *display, char *action, color *bgcolor) : mitem(parent, bgcolor), min_(min_), max_(max_), step(step), text(text), valueexp(value), value(min_), display(display), action(action)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~mitemslider()
|
||||
{
|
||||
DELETEA(text);
|
||||
DELETEA(valueexp);
|
||||
DELETEA(display);
|
||||
DELETEA(action);
|
||||
}
|
||||
|
||||
virtual int width() { return text_width(text) + 600; } // fixme
|
||||
|
||||
virtual void focus(bool on)
|
||||
{
|
||||
if(action)
|
||||
{
|
||||
alias("arg1", on ? "1" : "0");
|
||||
alias("arg2", "0");
|
||||
setvaluealias();
|
||||
execute(action);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void render(int x, int y, int w)
|
||||
{
|
||||
static color white1(0.2f, 0.2f, 0.2f), white2(1.0f, 1.0f, 1.0f);
|
||||
int range = max_-min_;
|
||||
int cval = value-min_;
|
||||
|
||||
int tw = text_width(text);
|
||||
if(isselection()) blendbox(x+tw, y-FONTH/6, x+w+FONTH, y+FONTH+FONTH/6, false);
|
||||
draw_text(text, x, y);
|
||||
|
||||
string v;
|
||||
if(display) // extract display name from list
|
||||
{
|
||||
string disp, val;
|
||||
s_strcpy(disp, display);
|
||||
itoa(val, cval);
|
||||
at(disp, val); // pass to script 'at' cmd
|
||||
s_strcpy(v, getalias("s")); // grab result
|
||||
}
|
||||
else itoa(v, value);
|
||||
int vw = text_width(v);
|
||||
draw_text(v, x+w-vw, y);
|
||||
|
||||
blendbox(x+tw+FONTH, y+FONTH/3, x+w, y+FONTH*2/3, false, -1, &white1);
|
||||
|
||||
int sliderwidth = (x+w)-(x+tw+FONTH);
|
||||
int offset = cval/(float)range*sliderwidth;
|
||||
blendbox(x+tw+offset+FONTH, y, x+tw+offset+FONTH*1.2f, y+FONTH, false, -1, &white2);
|
||||
}
|
||||
|
||||
virtual bool key(int code, bool isdown, int unicode)
|
||||
{
|
||||
if(code == SDLK_LEFT) slide(false);
|
||||
else if(code == SDLK_RIGHT) slide(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void init()
|
||||
{
|
||||
const char *p = valueexp;
|
||||
char *v = parseword(p);
|
||||
if(v) value = min(max_, max(min_, atoi(v)));
|
||||
}
|
||||
|
||||
void slide(bool right)
|
||||
{
|
||||
if(action)
|
||||
{
|
||||
value += right ? step : -step;
|
||||
value = min(max_, max(min_, value));
|
||||
alias("arg1", "-1");
|
||||
alias("arg2", right ? "1" : "-1");
|
||||
setvaluealias();
|
||||
execute(action);
|
||||
}
|
||||
}
|
||||
|
||||
void setvaluealias()
|
||||
{
|
||||
string v;
|
||||
itoa(v, value);
|
||||
alias("arg3", v);
|
||||
}
|
||||
};
|
||||
|
||||
// console iface
|
||||
|
||||
void *addmenu(const char *name, const char *title, bool allowinput, void (__cdecl *refreshfunc)(void *, bool))
|
||||
{
|
||||
name = newstring(name);
|
||||
gmenu &menu = menus[name];
|
||||
menu.name = name;
|
||||
menu.title = title ? newstring(title) : NULL;
|
||||
menu.header = menu.footer = NULL;
|
||||
menu.menusel = 0;
|
||||
menu.mdl = NULL;
|
||||
menu.allowinput = allowinput;
|
||||
menu.inited = false;
|
||||
menu.refreshfunc = refreshfunc;
|
||||
lastmenu = &menu;
|
||||
return &menu;
|
||||
}
|
||||
|
||||
void newmenu(char *name)
|
||||
{
|
||||
addmenu(name);
|
||||
}
|
||||
|
||||
void menumanual(void *menu, int n, char *text, char *action, color *bgcolor)
|
||||
{
|
||||
gmenu &m = *(gmenu *)menu;
|
||||
if(!n) m.items.setsize(0);
|
||||
m.items.add(new mitemtext(&m, text, action, NULL, bgcolor));
|
||||
}
|
||||
|
||||
void menuheader(void *menu, char *header, char *footer)
|
||||
{
|
||||
gmenu &m = *(gmenu *)menu;
|
||||
m.header = header && header[0] ? header : NULL;
|
||||
m.footer = footer && footer[0] ? footer : NULL;
|
||||
}
|
||||
|
||||
void menuitem(char *text, char *action, char *hoveraction)
|
||||
{
|
||||
if(!lastmenu) return;
|
||||
char *t = newstring(text);
|
||||
lastmenu->items.add(new mitemtext(lastmenu, t, action[0] ? newstring(action) : t, hoveraction[0] ? newstring(hoveraction) : NULL, NULL));
|
||||
}
|
||||
|
||||
void menuitemtextinput(char *text, char *value, char *action, char *hoveraction)
|
||||
{
|
||||
if(!lastmenu || !text || !value) return;
|
||||
lastmenu->items.add(new mitemtextinput(lastmenu, newstring(text), newstring(value), action[0] ? newstring(action) : NULL, hoveraction[0] ? newstring(hoveraction) : NULL, NULL));
|
||||
}
|
||||
|
||||
void menuitemslider(char *text, char *min_, char *max_, char *value, char *step, char *display, char *action)
|
||||
{
|
||||
if(!lastmenu) return;
|
||||
lastmenu->items.add(new mitemslider(lastmenu, newstring(text), atoi(min_), atoi(max_), atoi(step), value[0] ? newstring(value) : NULL, display[0] ? newstring(display) : NULL, action[0] ? newstring(action) : NULL, NULL));
|
||||
}
|
||||
|
||||
void menumdl(char *mdl, char *anim, char *rotspeed, char *scale)
|
||||
{
|
||||
if(!lastmenu || !mdl || !anim) return;
|
||||
gmenu &menu = *lastmenu;
|
||||
menu.mdl = newstring(mdl);
|
||||
menu.anim = findanim(anim)|ANIM_LOOP;
|
||||
menu.rotspeed = max(0, min(atoi(rotspeed), 100));
|
||||
menu.scale = max(0, min(atoi(scale), 100));
|
||||
}
|
||||
|
||||
void chmenumdl(char *menu, char *mdl, char *anim, char *rotspeed, char *scale)
|
||||
{
|
||||
if(!menu || !mdl || !menus.access(menu)) return;
|
||||
gmenu &m = menus[menu];
|
||||
DELETEA(m.mdl);
|
||||
m.mdl = newstring(mdl);
|
||||
m.anim = findanim(anim)|ANIM_LOOP;
|
||||
m.rotspeed = max(0, min(atoi(rotspeed), 100));
|
||||
m.scale = max(0, min(atoi(scale), 100));
|
||||
}
|
||||
|
||||
COMMAND(menuitem, ARG_3STR);
|
||||
COMMAND(menuitemtextinput, ARG_4STR);
|
||||
COMMAND(menuitemslider, ARG_7STR);
|
||||
COMMAND(showmenu, ARG_1STR);
|
||||
COMMAND(newmenu, ARG_1STR);
|
||||
COMMAND(menumdl, ARG_5STR);
|
||||
COMMAND(chmenumdl, ARG_6STR);
|
||||
|
||||
bool menukey(int code, bool isdown, int unicode)
|
||||
{
|
||||
if(!curmenu) return false;
|
||||
int n = curmenu->items.length(), menusel = curmenu->menusel;
|
||||
if(isdown)
|
||||
{
|
||||
int pagesize = MAXMENU - (curmenu->header ? 2 : 0) - (curmenu->footer ? 2 : 0);
|
||||
|
||||
switch(code)
|
||||
{
|
||||
case SDLK_PAGEUP: menusel -= pagesize; break;
|
||||
case SDLK_PAGEDOWN:
|
||||
if(menusel+pagesize>=n && menusel/pagesize!=(n-1)/pagesize) menusel = n-1;
|
||||
else menusel += pagesize;
|
||||
break;
|
||||
case SDLK_ESCAPE:
|
||||
case -3:
|
||||
menuset(menustack.empty() ? NULL : menustack.pop());
|
||||
return true;
|
||||
break;
|
||||
case SDLK_UP:
|
||||
case -4:
|
||||
menusel--;
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
case -5:
|
||||
menusel++;
|
||||
break;
|
||||
default:
|
||||
{
|
||||
if(!curmenu->allowinput) return false;
|
||||
mitem &m = *curmenu->items[menusel];
|
||||
return m.key(code, isdown, unicode);
|
||||
}
|
||||
}
|
||||
|
||||
menuselect(curmenu, menusel);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!curmenu->allowinput) return false;
|
||||
mitem &m = *curmenu->items[menusel];
|
||||
if(code==SDLK_RETURN || code==-1 || code==-2)
|
||||
{
|
||||
if(!curmenu->items.inrange(menusel)) { menuset(NULL); return true; }
|
||||
m.select();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,142 +541,4 @@ void rendermenumdl()
|
||||
rendermodel(isplayermodel ? (char *)"playermodels" : m.mdl, m.anim, tex, 0, pos, yaw, 0, 0, 0, NULL, isplayermodel ? (char*)"weapons/subgun/world" : NULL, m.scale ? m.scale/25.0f : 1.0f);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void *addmenu(const char *name, const char *title, bool allowinput, void (__cdecl *refreshfunc)(void *, bool))
|
||||
{
|
||||
name = newstring(name);
|
||||
gmenu &menu = menus[name];
|
||||
menu.name = name;
|
||||
menu.title = title ? newstring(title) : NULL;
|
||||
menu.header = menu.footer = NULL;
|
||||
menu.menusel = 0;
|
||||
menu.mdl = NULL;
|
||||
menu.allowinput = allowinput;
|
||||
menu.inited = false;
|
||||
menu.refreshfunc = refreshfunc;
|
||||
lastmenu = &menu;
|
||||
return &menu;
|
||||
}
|
||||
|
||||
void newmenu(char *name)
|
||||
{
|
||||
addmenu(name);
|
||||
}
|
||||
|
||||
void menumanual(void *menu, int n, char *text, char *action, color *bgcolor)
|
||||
{
|
||||
gmenu &m = *(gmenu *)menu;
|
||||
if(!n) m.items.setsize(0);
|
||||
mitem &mitem = m.items.add();
|
||||
mitem.text = text;
|
||||
mitem.action = action;
|
||||
mitem.hoveraction = NULL;
|
||||
mitem.bgcolor = bgcolor;
|
||||
}
|
||||
|
||||
void menuheader(void *menu, char *header, char *footer)
|
||||
{
|
||||
gmenu &m = *(gmenu *)menu;
|
||||
m.header = header && header[0] ? header : NULL;
|
||||
m.footer = footer && footer[0] ? footer : NULL;
|
||||
}
|
||||
|
||||
void menuitem(char *text, char *action, char *hoveraction)
|
||||
{
|
||||
if(!lastmenu) return;
|
||||
gmenu &menu = *lastmenu;
|
||||
mitem &mi = menu.items.add();
|
||||
mi.text = newstring(text);
|
||||
mi.action = action[0] ? newstring(action) : mi.text;
|
||||
mi.hoveraction = hoveraction[0] ? newstring(hoveraction) : NULL;
|
||||
mi.bgcolor = NULL;
|
||||
}
|
||||
|
||||
void menumdl(char *mdl, char *anim, char *rotspeed, char *scale)
|
||||
{
|
||||
if(!lastmenu || !mdl || !anim) return;
|
||||
gmenu &menu = *lastmenu;
|
||||
menu.mdl = newstring(mdl);
|
||||
menu.anim = findanim(anim)|ANIM_LOOP;
|
||||
menu.rotspeed = max(0, min(atoi(rotspeed), 100));
|
||||
menu.scale = max(0, min(atoi(scale), 100));
|
||||
}
|
||||
|
||||
void chmenumdl(char *menu, char *mdl, char *anim, char *rotspeed, char *scale)
|
||||
{
|
||||
if(!menu || !mdl || !menus.access(menu)) return;
|
||||
gmenu &m = menus[menu];
|
||||
DELETEA(m.mdl);
|
||||
m.mdl = newstring(mdl);
|
||||
m.anim = findanim(anim)|ANIM_LOOP;
|
||||
m.rotspeed = max(0, min(atoi(rotspeed), 100));
|
||||
m.scale = max(0, min(atoi(scale), 100));
|
||||
}
|
||||
|
||||
COMMAND(menuitem, ARG_3STR);
|
||||
COMMAND(showmenu, ARG_1STR);
|
||||
COMMAND(newmenu, ARG_1STR);
|
||||
COMMAND(menumdl, ARG_5STR);
|
||||
COMMAND(chmenumdl, ARG_6STR);
|
||||
|
||||
void menuselect(void *menu, int sel)
|
||||
{
|
||||
gmenu &m = *(gmenu *)menu;
|
||||
|
||||
if(sel<0) sel = m.items.length()>0 ? m.items.length()-1 : 0;
|
||||
else if(sel>=m.items.length()) sel = 0;
|
||||
|
||||
if(m.items.inrange(sel))
|
||||
{
|
||||
int oldsel = m.menusel;
|
||||
m.menusel = sel;
|
||||
if(m.allowinput)
|
||||
{
|
||||
char *haction = m.items[sel].hoveraction;
|
||||
if(sel!=oldsel && haction) execute(haction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool menukey(int code, bool isdown)
|
||||
{
|
||||
if(!curmenu) return false;
|
||||
int n = curmenu->items.length(), menusel = curmenu->menusel;
|
||||
if(isdown)
|
||||
{
|
||||
int pagesize = MAXMENU - (curmenu->header ? 2 : 0) - (curmenu->footer ? 2 : 0);
|
||||
if(code==SDLK_PAGEUP) menusel -= pagesize;
|
||||
else if(code==SDLK_PAGEDOWN)
|
||||
{
|
||||
if(menusel+pagesize>=n && menusel/pagesize!=(n-1)/pagesize) menusel = n-1;
|
||||
else menusel += pagesize;
|
||||
}
|
||||
else if(!curmenu->allowinput) return false;
|
||||
|
||||
setscope(false);
|
||||
|
||||
if(code==SDLK_ESCAPE || code==-3)
|
||||
{
|
||||
menuset(menustack.empty() ? NULL : menustack.pop());
|
||||
return true;
|
||||
}
|
||||
else if(code==SDLK_UP || code==-4) menusel--;
|
||||
else if(code==SDLK_DOWN || code==-5) menusel++;
|
||||
|
||||
menuselect(curmenu, menusel);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!curmenu->allowinput) return false;
|
||||
if(code==SDLK_RETURN || code==-1 || code==-2)
|
||||
{
|
||||
if(!curmenu->items.inrange(menusel)) { menuset(NULL); return true; }
|
||||
char *action = curmenu->items[menusel].action;
|
||||
menustack.add(curmenu);
|
||||
menuset(NULL);
|
||||
if(action) execute(action);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user