From 389126528886855f11e4ec2b70e2429b3ed18b85 Mon Sep 17 00:00:00 2001 From: ac_stef Date: Mon, 15 Sep 2008 20:23:28 +0000 Subject: [PATCH] menu description line init fix git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2638 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/menus.cpp | 15 ++++++++++----- source/src/protos.h | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/source/src/menus.cpp b/source/src/menus.cpp index 1cb46067..2f19aa5f 100644 --- a/source/src/menus.cpp +++ b/source/src/menus.cpp @@ -149,7 +149,6 @@ struct mitemmanual : mitem virtual void focus(bool on) { - if(on && desc && curmenu) curmenu->footer = desc; if(on && hoveraction) execute(hoveraction); } @@ -164,6 +163,7 @@ struct mitemmanual : mitem pop("arg1"); } } + virtual const char *getdesc() { return desc; } }; struct mitemtext : mitemmanual @@ -463,6 +463,7 @@ void *addmenu(const char *name, const char *title, bool allowinput, void (__cdec menu.mdl = NULL; menu.allowinput = allowinput; menu.inited = false; + menu.hasdesc = false; menu.hotkeys = hotkeys; menu.refreshfunc = refreshfunc; menu.initaction = NULL; @@ -481,6 +482,7 @@ void menumanual(void *menu, int n, char *text, char *action, color *bgcolor, con { gmenu &m = *(gmenu *)menu; if(!n) m.items.deletecontentsp(); + if(desc) m.hasdesc = true; m.items.add(new mitemmanual(&m, text, action, NULL, bgcolor, desc)); } @@ -580,7 +582,7 @@ bool menukey(int code, bool isdown, int unicode) int n = curmenu->items.length(), menusel = curmenu->menusel; if(isdown) { - int pagesize = MAXMENU - (curmenu->header ? 2 : 0) - (curmenu->footer ? 2 : 0); + int pagesize = MAXMENU - (curmenu->header ? 2 : 0) - (curmenu->footer || curmenu->hasdesc ? 2 : 0); switch(code) { @@ -731,7 +733,7 @@ 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), + int hitems = (header ? 2 : 0) + (footer || curmenu->hasdesc? 2 : 0), pagesize = MAXMENU - hitems, offset = menusel - (menusel%pagesize), mdisp = min(items.length(), pagesize), @@ -772,10 +774,13 @@ void gmenu::render() y += step; } if(title) text_endcolumns(); - if(footer) + if(footer || hasdesc) { y += ((mdisp-cdisp)+1)*step; - draw_text(footer, x, y); + if(!hasdesc) + draw_text(footer, x, y); + else if(items.inrange(menusel) && items[menusel]->getdesc()) + draw_text(items[menusel]->getdesc(), x, y); } } diff --git a/source/src/protos.h b/source/src/protos.h index 010ed456..b71f8537 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -120,6 +120,7 @@ struct mitem virtual void focus(bool on) { } virtual void key(int code, bool isdown, int unicode) { } virtual void init() {} + virtual const char *getdesc() { return NULL; } bool isselection(); void renderbg(int x, int y, int w, color *c); static color gray, white, whitepulse; @@ -142,7 +143,7 @@ struct gmenu vector items; int mwidth; int menusel; - bool allowinput, inited, hotkeys, forwardkeys; + bool allowinput, inited, hotkeys, forwardkeys, hasdesc; void (__cdecl *refreshfunc)(void *, bool); char *initaction;