From 1a1a9e3aa87da5a9db918f7340e28cc9b300d04e Mon Sep 17 00:00:00 2001 From: flowtron Date: Sat, 7 Aug 2010 22:54:39 +0000 Subject: [PATCH] menu-dirlist fix (bug found by Gibstick) and menu-footer line-wrapping added git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@5558 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/menus.cpp | 66 ++++++++++++++++++++++++++++++++++++--- source/src/protos.h | 3 +- source/src/scoreboard.cpp | 5 +-- 3 files changed, 66 insertions(+), 8 deletions(-) diff --git a/source/src/menus.cpp b/source/src/menus.cpp index fa761f9a..cd6c4386 100644 --- a/source/src/menus.cpp +++ b/source/src/menus.cpp @@ -831,6 +831,15 @@ void menuheader(void *menu, char *header, char *footer) m.header = header && header[0] ? header : NULL; m.footer = footer && footer[0] ? footer : NULL; } +void lastmenu_header(char *header, char *footer) +{ + if(lastmenu) + { + menuheader(lastmenu, newstring(header), newstring(footer)); + } + else conoutf("no last menu to apply to"); +} +COMMANDN(menuheader, lastmenu_header, ARG_2STR); void menufont(void *menu, const char *usefont) { @@ -1004,8 +1013,8 @@ bool menukey(int code, bool isdown, int unicode, SDLMod mod) { 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); - + //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 switch(code) { case SDLK_PAGEUP: menusel -= pagesize; break; @@ -1192,7 +1201,18 @@ void gmenu::init() else if(!strcmp(dirlist->ext, "cgz") /*&& (fileexists(jpgname, "r") || findfile(jpgname, "r") != jpgname)*/) { //items.add(new mitemimage(this, newstring(jpgname), f, newstring(dirlist->action), NULL, NULL, d)); - defformatstring(fullname)("%s%s%s", dirlist->dir[0]?dirlist->dir:"", dirlist->dir[0]?"/":"", f); + int diroffset = 0; + if(dirlist->dir[0]) + { + unsigned int ddsl = strlen("packages/"); + if(strlen(dirlist->dir)>ddsl) + { + string prefix; + copystring(prefix, dirlist->dir, ddsl+1); + if(!strcmp(prefix,"packages/")) diroffset = ddsl; + } + } + defformatstring(fullname)("%s%s%s", dirlist->dir[0]?dirlist->dir+diroffset:"", dirlist->dir[0]?"/":"", f); defformatstring(caction)("map %s", fullname); defformatstring(title)("%s", d[0]!='\0'?d:f); items.add(new mitemmapload(this, newstring(fullname), newstring(title), newstring(caction), NULL, NULL, NULL)); @@ -1228,7 +1248,8 @@ void gmenu::render() if(x>w) w = x; } } - int hitems = (header ? 2 : 0) + (footer || hasdesc ? 2 : 0), + //int hitems = (header ? 2 : 0) + (footer || hasdesc ? 2 : 0), // FIXME: footer-length + int hitems = (header ? 2 : 0) + (footer ? (footlen?(footlen+1):2) : (hasdesc ? 2 : 0)), pagesize = MAXMENU - hitems, offset = menusel - (menusel%pagesize), mdisp = min(items.length(), pagesize), @@ -1266,9 +1287,44 @@ void gmenu::render() { y += ((mdisp-cdisp)+1)*step; if(!hasdesc) - draw_text(footer, x, y); + { + footlen = 0; + if(text_width(footer)>w) + { + int tflo = 0; + int cflw = 0; + unsigned int cflc = 0; + string pofl; + string bufl; + bool keepon = true; + while(keepon) + { + while(cflw=MAXSTRLEN) keepon = false; + cflc--; + cflw = 0; + formatstring(bufl)("%s", footer+tflo); + copystring(pofl, bufl, cflc-tflo); + draw_text(pofl, x, y); + y+=step; + tflo = cflc-1; + footlen++; + } + } + } + else draw_text(footer, x, y); + } else if(items.inrange(menusel) && items[menusel]->getdesc()) draw_text(items[menusel]->getdesc(), x, y); + } if(usefont) popfont(); // setfont("default"); } diff --git a/source/src/protos.h b/source/src/protos.h index 4c9f1157..4d749fd2 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -127,9 +127,10 @@ struct gmenu const char *mdl; int anim, rotspeed, scale; + int footlen; mdirlist *dirlist; - gmenu() : name(0), title(0), header(0), footer(0), initaction(0), usefont(0), mdl(0), dirlist(0) {} + gmenu() : name(0), title(0), header(0), footer(0), initaction(0), usefont(0), mdl(0), footlen(0), dirlist(0) {} virtual ~gmenu() { DELETEA(name); diff --git a/source/src/scoreboard.cpp b/source/src/scoreboard.cpp index 9cd83b52..78f8ae00 100644 --- a/source/src/scoreboard.cpp +++ b/source/src/scoreboard.cpp @@ -264,9 +264,10 @@ void renderscores(void *menu, bool init) // but we might want to consider wrapping the bottom-line to accomodate longer descriptions - to a limit. string text; filtertext(text, s->sdesc); - for(char *p = text; (p = strchr(p, '\"')); *p++ = ' '); - text[30] = '\0'; // serverbrowser has less room - +8 chars here - 2010AUG03 - seems it was too much, falling back to 30 (for now): TODO get real width of menu as reference-width. + //for(char *p = text; (p = strchr(p, '\"')); *p++ = ' '); + //text[30] = '\0'; // serverbrowser has less room - +8 chars here - 2010AUG03 - seems it was too much, falling back to 30 (for now): TODO get real width of menu as reference-width. FIXME: cutoff concatformatstring(serverline, "%s:%d %s", s->name, s->port, text); + //printf("SERVERLINE: %s\n", serverline); } }