MCPcopy Create free account
hub / github.com/NetHack/NetHack / handler_autounlock

Function handler_autounlock

src/options.c:5623–5672  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5621}
5622
5623staticfn int
5624handler_autounlock(int optidx)
5625{
5626 winid tmpwin;
5627 anything any;
5628 boolean chngd;
5629 unsigned oldflags = flags.autounlock;
5630 const char *optname = allopt[optidx].name;
5631 char buf[BUFSZ], sep = iflags.menu_tab_sep ? '\t' : ' ';
5632 menu_item *window_pick = (menu_item *) 0;
5633 int i, n, presel, res = optn_ok;
5634 int clr = NO_COLOR;
5635
5636 tmpwin = create_nhwindow(NHW_MENU);
5637 start_menu(tmpwin, MENU_BEHAVE_STANDARD);
5638 any = cg.zeroany;
5639 for (i = 0; i < SIZE(unlocktypes); ++i) {
5640 Sprintf(buf, "%-10.10s%c%.40s",
5641 unlocktypes[i][0], sep, unlocktypes[i][1]);
5642 presel = (flags.autounlock & (1 << i));
5643 any.a_int = i + 1;
5644 add_menu(tmpwin, &nul_glyphinfo, &any, *unlocktypes[i][0], 0,
5645 ATR_NONE, clr, buf,
5646 (presel ? MENU_ITEMFLAGS_SELECTED : MENU_ITEMFLAGS_NONE));
5647 }
5648 Sprintf(buf, "Select '%.20s' actions:", optname);
5649 end_menu(tmpwin, buf);
5650 n = select_menu(tmpwin, PICK_ANY, &window_pick);
5651 if (n > 0) {
5652 unsigned newflags = 0;
5653
5654 for (i = 0; i < n; ++i)
5655 newflags |= (1 << (window_pick[i].item.a_int - 1));
5656 flags.autounlock = newflags;
5657 free((genericptr_t) window_pick);
5658 } else if (n == 0) { /* nothing was picked but menu wasn't cancelled */
5659 /* something that was preselected got unselected, leaving nothing;
5660 treat that as picking 'none' (even though 'none' is no longer
5661 among the choices) */
5662 flags.autounlock = 0;
5663 }
5664 destroy_nhwindow(tmpwin);
5665 chngd = (flags.autounlock != oldflags);
5666 if ((chngd || flags.verbose) && give_opt_msg) {
5667 optfn_autounlock(optidx, get_val, FALSE, buf, (char *) NULL);
5668 pline("'%s' %s '%s'.", optname,
5669 chngd ? "changed to" : "is still", buf);
5670 }
5671 return res;
5672}
5673
5674staticfn int
5675handler_disclose(void)

Callers 1

optfn_autounlockFunction · 0.85

Calls 4

add_menuFunction · 0.85
select_menuFunction · 0.85
optfn_autounlockFunction · 0.85
plineFunction · 0.70

Tested by

no test coverage detected