From 07d9ae608d353b7e97a437a06e0adecd6afa0978 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Sat, 1 Oct 2016 20:08:25 +0200 Subject: [PATCH] fix menuinitselection for dynamic menus If a menu is not (yet) big enough for the selection to be set, wait until the menu is opened and initialised - then try again. --- source/src/menus.cpp | 2 ++ source/src/protos.h | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/source/src/menus.cpp b/source/src/menus.cpp index fcd776cd..2b2cd959 100644 --- a/source/src/menus.cpp +++ b/source/src/menus.cpp @@ -939,6 +939,7 @@ void menuinitselection(int *line) { if(!lastmenu) return; if(lastmenu->items.inrange(*line)) lastmenu->menusel = *line; + else lastmenu->menuselinit = *line; } COMMAND(menuinitselection, "i"); @@ -1316,6 +1317,7 @@ void gmenu::open() execute(initaction); lastmenu = oldlastmenu; } + if(items.inrange(menuselinit)) { menusel = menuselinit; menuselinit = -1; } if(items.inrange(menusel)) items[menusel]->focus(true); init(); resetcontext(); diff --git a/source/src/protos.h b/source/src/protos.h index 1cb7d9f2..098b94a1 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -224,7 +224,7 @@ struct gmenu const char *name, *title, *header, *footer; vector items; int mwidth; - int menusel; + int menusel, menuselinit; bool allowinput, inited, hotkeys, forwardkeys; void (__cdecl *refreshfunc)(void *, bool); bool (__cdecl *keyfunc)(void *, int, bool, int); @@ -239,7 +239,7 @@ struct gmenu char *previewtexture, *previewtexturetitle; mdirlist *dirlist; - gmenu() : name(0), title(0), header(0), footer(0), initaction(0), usefont(0), allowblink(false), persistentselection(false), mdl(0), footlen(0), xoffs(0), yoffs(0), previewtexture(NULL), previewtexturetitle(NULL), dirlist(0) {} + gmenu() : name(0), title(0), header(0), footer(0), menuselinit(-1), initaction(0), usefont(0), allowblink(false), persistentselection(false), mdl(0), footlen(0), xoffs(0), yoffs(0), previewtexture(NULL), previewtexturetitle(NULL), dirlist(0) {} virtual ~gmenu() { DELETEA(name);