void closemenu(const char *name) { gmenu *m; if(!name) { if(curmenu) curmenu->close(); while(!menustack.empty()) { m = menustack.pop(); if(m) m->close(); } curmenu = NULL; return; } m = menus.access(name); if(!m) return; if(curmenu==m) menuset(menustack.empty() ? NULL : menustack.pop(), false); else loopv(menustack) { if(menustack[i]==m) { menustack.remove(i); return; } } }
virtual void select() { if(action && action[0]) { gmenu *oldmenu = curmenu; push("arg1", text); setcontext("menu", curmenu->name); int result = execute(action); resetcontext(); pop("arg1"); if(result >= 0 && oldmenu == curmenu) { menuset(NULL, false); menustack.shrink(0); } } }
void showmenu(const char *name, bool top) { if(!name) { curmenu = NULL; return; } gmenu *m = menus.access(name); if(!m) return; if(!top && curmenu) { if(curmenu==m) return; loopv(menustack) if(menustack[i]==m) return; menustack.insert(0, m); return; } menuset(m); }
void showscores(bool on) { scoreson = on; menuset(((int)on)-1); };
bool menukey(int code, bool isdown, int unicode, SDLMod mod) { if(!curmenu) return false; int n = curmenu->items.length(), menusel = curmenu->menusel; if(isdown) { bool hasdesc = false; loopv(curmenu->items) if(curmenu->items[i]->getdesc()) { hasdesc = true; break;} //int pagesize = MAXMENU - (curmenu->header ? 2 : 0) - (curmenu->footer || hasdesc ? 2 : 0); // FIXME: footer-length int pagesize = MAXMENU - (curmenu->header ? 2 : 0) - (curmenu->footer ? (curmenu->footlen?(curmenu->footlen+1):2) : (hasdesc ? 2 : 0)); // FIXME: footer-length if(curmenu->items.inrange(menusel)) { mitem *m = curmenu->items[menusel]; if(m->type == mitem::TYPE_KEYINPUT && ((mitemkeyinput *)m)->capture && code != SDLK_ESCAPE) { m->key(code, isdown, unicode); return true; } } 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 SDL_AC_BUTTON_RIGHT: if(!curmenu->allowinput) return false; menuset(menustack.empty() ? NULL : menustack.pop(), false); return true; break; case SDLK_UP: case SDL_AC_BUTTON_WHEELUP: if(iskeypressed(SDLK_LCTRL)) return menukey(SDLK_LEFT, isdown, 0); if(!curmenu->allowinput) return false; menusel--; break; case SDLK_DOWN: case SDL_AC_BUTTON_WHEELDOWN: if(iskeypressed(SDLK_LCTRL)) return menukey(SDLK_RIGHT, isdown, 0); if(!curmenu->allowinput) return false; menusel++; break; case SDLK_TAB: if(!curmenu->allowinput) return false; if(mod & KMOD_LSHIFT) menusel--; else menusel++; break; case SDLK_PRINT: curmenu->conprintmenu(); return true; case SDLK_F12: { extern void screenshot(const char *imagepath); if(!curmenu->allowinput) return false; screenshot(NULL); break; } case SDLK_1: case SDLK_2: case SDLK_3: case SDLK_4: case SDLK_5: case SDLK_6: case SDLK_7: case SDLK_8: case SDLK_9: if(curmenu->allowinput && curmenu->hotkeys) { int idx = code-SDLK_1; if(curmenu->items.inrange(idx)) { menuselect(curmenu, idx); mitem &m = *curmenu->items[idx]; m.select(); } return true; } default: { if(!curmenu->allowinput) return false; if(curmenu->keyfunc && (*curmenu->keyfunc)(curmenu, code, isdown, unicode)) return true; if(!curmenu->items.inrange(menusel)) return false; mitem &m = *curmenu->items[menusel]; m.key(code, isdown, unicode); return !curmenu->forwardkeys; } } if(!curmenu->hotkeys) menuselect(curmenu, menusel); return true; } else { if(!curmenu->allowinput || !curmenu->items.inrange(menusel)) return false;