allow persistent menu selections

menuselectionpersistent
  Enables persistent selections for the currently displayed menu and also
  restores a previously saved selection. Probably most efficient inside
  "menuinit". The position is restored during execution of this command,
  so the menu entry has to already exist and the alias with the last
  position has to be read from saved.cfg. In autmatically created menus
  it may be necessary to execute the command with a short delay (see
  examples in this commit).

DOCREF menuselectionpersistent
This commit is contained in:
ac-stef
2015-06-10 14:22:11 +02:00
parent bdf53a5ab8
commit d3cdec0708
4 changed files with 29 additions and 1 deletions
+5
View File
@@ -12,6 +12,7 @@ menuitem [Misc settings] [ showmenu Misc ]
menuitem [] -1
menuitem [Reset all settings] [ showmenu [Reset settings] ]
newmenu Weapons
menumdl weapons/assault/menu mapmodel 75 12
@@ -22,6 +23,7 @@ looplist [
shotgun "V-19 Combat Shotgun"
carbine "TMP-M&A Carbine"
] [ w desc ] [execute (format [menuitem [%2] [nextprimary %1 ; echo %2 selected] [chmenumdl Weapons weapons/%1/menu mapmodel 75 12] ] $w $desc) ]
menuinit menuselectionpersistent
newmenu CLA
@@ -290,12 +292,15 @@ menuitem [Change crosshair in edit mode... ] [ showmenu [Edit mo
newmenu Crosshairs
menudirlist "packages/crosshairs" png [ loadcrosshair default (concatword $arg1 .png) ] 1
menuinit [sleep 1 menuselectionpersistent]
newmenu [Scope crosshairs]
menudirlist "packages/crosshairs" png [ loadcrosshair scope (concatword $arg1 .png) ] 1
menuinit [sleep 1 menuselectionpersistent]
newmenu [Edit mode crosshairs]
menudirlist "packages/crosshairs" png [ loadcrosshair edit (concatword $arg1 .png) ] 1
menuinit [sleep 1 menuselectionpersistent]
newmenu [Alternate edit binds]
menuitem [Back] [ closecurmenu ]
+21
View File
@@ -133,6 +133,13 @@ void showmenu_(const char *name)
}
COMMANDN(showmenu, showmenu_, "s");
const char *persistentmenuselectionalias(const char *name)
{
static defformatstring(al)("__lastmenusel_%s", name);
filtertext(al, al, FTXT__ALIAS);
return al;
}
void menuselect(void *menu, int sel)
{
gmenu &m = *(gmenu *)menu;
@@ -151,6 +158,11 @@ void menuselect(void *menu, int sel)
if(m.items.inrange(oldsel)) m.items[oldsel]->focus(false);
m.items[sel]->focus(true);
audiomgr.playsound(S_MENUSELECT, SP_HIGHEST);
if(m.persistentselection)
{
defformatstring(val)("%d", sel);
alias(persistentmenuselectionalias(m.name), val);
}
}
}
}
@@ -886,6 +898,15 @@ void menuinitselection(int *line)
}
COMMAND(menuinitselection, "i");
void menuselectionpersistent()
{
if(!curmenu) return;
curmenu->persistentselection = true;
const char *val = getalias(persistentmenuselectionalias(curmenu->name));
if(val) menuselect(curmenu, ATOI(val));
}
COMMAND(menuselectionpersistent, "");
void menurenderoffset(int *xoff, int *yoff)
{
if(!lastmenu) return;
+1
View File
@@ -154,6 +154,7 @@ enum
#define FTXT_MAPNAME (1<<21)
#define FTXT_CROPWHITE (1<<22)
// character classes
#define FTXT__ALIAS (FTXT_NOWHITE | FTXT_NOCOLOR | FTXT_SAFECS | FTXT_MAPNAME)
#define FTXT__SERVDESC (FTXT_NOWHITE | FTXT_ALLOWBLANKS | FTXT_TABTOBLANK)
#define FTXT__MAPMSG (FTXT_NOWHITE | FTXT_ALLOWBLANKS | FTXT_TABTOBLANK)
#define FTXT__MAPNAME (FTXT_NOCOLOR | FTXT_MAPNAME | FTXT_TOLOWER)
+2 -1
View File
@@ -160,6 +160,7 @@ struct gmenu
char *initaction;
char *usefont;
bool allowblink;
bool persistentselection;
const char *mdl;
int anim, rotspeed, scale;
int footlen;
@@ -167,7 +168,7 @@ struct gmenu
char *previewtexture;
mdirlist *dirlist;
gmenu() : name(0), title(0), header(0), footer(0), initaction(0), usefont(0), allowblink(0), mdl(0), footlen(0), xoffs(0), yoffs(0), previewtexture(NULL), dirlist(0) {}
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), dirlist(0) {}
virtual ~gmenu()
{
DELETEA(name);