ensure condition menu always starts the same way even under "play again"

This commit is contained in:
nhmall
2020-02-20 20:36:37 -05:00
parent 3bc346868e
commit 86f5e73ef3
3 changed files with 8 additions and 5 deletions
+1
View File
@@ -667,6 +667,7 @@ struct instance_globals {
#endif #endif
unsigned long cond_hilites[BL_ATTCLR_MAX]; unsigned long cond_hilites[BL_ATTCLR_MAX];
int now_or_before_idx; /* 0..1 for array[2][] first index */ int now_or_before_idx; /* 0..1 for array[2][] first index */
int condmenu_sortorder;
/* cmd.c */ /* cmd.c */
struct cmd Cmd; /* flag.h */ struct cmd Cmd; /* flag.h */
+6 -5
View File
@@ -963,6 +963,7 @@ boolean negated;
if (!addr) { if (!addr) {
/* special: indicates a request to init so /* special: indicates a request to init so
set the choice values to match the defaults */ set the choice values to match the defaults */
g.condmenu_sortorder = 0;
for (i = 0; i < CONDITION_COUNT; ++i) { for (i = 0; i < CONDITION_COUNT; ++i) {
cond_idx[i] = i; cond_idx[i] = i;
condtests[i].choice = condtests[i].enabled; condtests[i].choice = condtests[i].enabled;
@@ -1031,7 +1032,6 @@ char *opts;
void void
cond_menu(VOID_ARGS) cond_menu(VOID_ARGS)
{ {
static int sortorder = 0;
static const char *menutitle[2] = { "alphabetically", "by ranking"}; static const char *menutitle[2] = { "alphabetically", "by ranking"};
int i, res, idx = 0; int i, res, idx = 0;
int sequence[CONDITION_COUNT]; int sequence[CONDITION_COUNT];
@@ -1047,7 +1047,7 @@ cond_menu(VOID_ARGS)
} }
qsort((genericptr_t) sequence, CONDITION_COUNT, qsort((genericptr_t) sequence, CONDITION_COUNT,
sizeof sequence[0], sizeof sequence[0],
(sortorder) ? cond_cmp : menualpha_cmp); (g.condmenu_sortorder) ? cond_cmp : menualpha_cmp);
tmpwin = create_nhwindow(NHW_MENU); tmpwin = create_nhwindow(NHW_MENU);
start_menu(tmpwin, MENU_BEHAVE_STANDARD); start_menu(tmpwin, MENU_BEHAVE_STANDARD);
@@ -1055,11 +1055,12 @@ cond_menu(VOID_ARGS)
any = cg.zeroany; any = cg.zeroany;
any.a_int = 1; any.a_int = 1;
Sprintf(mbuf, "change sort order from \"%s\" to \"%s\"", Sprintf(mbuf, "change sort order from \"%s\" to \"%s\"",
menutitle[sortorder], menutitle[1 - sortorder]); menutitle[g.condmenu_sortorder],
menutitle[1 - g.condmenu_sortorder]);
add_menu(tmpwin, NO_GLYPH, &any, 'S', 0, ATR_NONE, mbuf, add_menu(tmpwin, NO_GLYPH, &any, 'S', 0, ATR_NONE, mbuf,
MENU_ITEMFLAGS_NONE); MENU_ITEMFLAGS_NONE);
any = cg.zeroany; any = cg.zeroany;
Sprintf(mbuf, "sorted %s", menutitle[sortorder]); Sprintf(mbuf, "sorted %s", menutitle[g.condmenu_sortorder]);
add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, mbuf, add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, mbuf,
MENU_ITEMFLAGS_NONE); MENU_ITEMFLAGS_NONE);
for (i = 0; i < SIZE(condtests); i++) { for (i = 0; i < SIZE(condtests); i++) {
@@ -1084,7 +1085,7 @@ cond_menu(VOID_ARGS)
idx = picks[i].item.a_int; idx = picks[i].item.a_int;
if (idx == 1) { if (idx == 1) {
/* sort change requested */ /* sort change requested */
sortorder = 1 - sortorder; g.condmenu_sortorder = 1 - g.condmenu_sortorder;
showmenu = TRUE; showmenu = TRUE;
break; /* for loop */ break; /* for loop */
} else { } else {
+1
View File
@@ -235,6 +235,7 @@ const struct instance_globals g_init = {
#endif #endif
UNDEFINED_VALUES, /* cond_hilites */ UNDEFINED_VALUES, /* cond_hilites */
0, /* now_or_before_idx */ 0, /* now_or_before_idx */
0, /* condmenu_sortorder */
/* cmd.c */ /* cmd.c */
UNDEFINED_VALUES, /* Cmd */ UNDEFINED_VALUES, /* Cmd */