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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user