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

Function cond_menu

src/botl.c:1375–1454  ·  view source on GitHub ↗

display a menu of all available status condition options and let player toggled them on or off; returns True iff any changes are made */

Source from the content-addressed store, hash-verified

1373/* display a menu of all available status condition options and let player
1374 toggled them on or off; returns True iff any changes are made */
1375boolean
1376cond_menu(void)
1377{
1378 static const char *const menutitle[2] = {
1379 "alphabetically", "by ranking"
1380 };
1381 int i, res, idx = 0;
1382 int sequence[CONDITION_COUNT];
1383 winid tmpwin;
1384 anything any;
1385 menu_item *picks = (menu_item *) 0;
1386 char mbuf[QBUFSZ];
1387 boolean showmenu = TRUE;
1388 int clr = NO_COLOR;
1389 boolean changed = FALSE;
1390
1391 do {
1392 for (i = 0; i < CONDITION_COUNT; ++i) {
1393 sequence[i] = i;
1394 }
1395 qsort((genericptr_t) sequence, CONDITION_COUNT,
1396 sizeof sequence[0],
1397 (gc.condmenu_sortorder) ? cond_cmp : menualpha_cmp);
1398
1399 tmpwin = create_nhwindow(NHW_MENU);
1400 start_menu(tmpwin, MENU_BEHAVE_STANDARD);
1401
1402 any = cg.zeroany;
1403 any.a_int = 1;
1404 Sprintf(mbuf, "change sort order from \"%s\" to \"%s\"",
1405 menutitle[gc.condmenu_sortorder],
1406 menutitle[1 - gc.condmenu_sortorder]);
1407 add_menu(tmpwin, &nul_glyphinfo, &any, 'S', 0, ATR_NONE,
1408 clr, mbuf, MENU_ITEMFLAGS_SKIPINVERT);
1409 any = cg.zeroany;
1410 Sprintf(mbuf, "sorted %s", menutitle[gc.condmenu_sortorder]);
1411 add_menu_heading(tmpwin, mbuf);
1412 for (i = 0; i < SIZE(condtests); i++) {
1413 idx = sequence[i];
1414 Sprintf(mbuf, "cond_%-14s", condtests[idx].useroption);
1415 any = cg.zeroany;
1416 any.a_int = idx + 2; /* avoid zero and the sort change pick */
1417 condtests[idx].choice = FALSE;
1418 add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, ATR_NONE, clr, mbuf,
1419 condtests[idx].enabled
1420 ? MENU_ITEMFLAGS_SELECTED : MENU_ITEMFLAGS_NONE);
1421 }
1422
1423 end_menu(tmpwin, "Choose status conditions to toggle");
1424
1425 res = select_menu(tmpwin, PICK_ANY, &picks);
1426 destroy_nhwindow(tmpwin);
1427 showmenu = FALSE;
1428 if (res > 0) {
1429 for (i = 0; i < res; i++) {
1430 idx = picks[i].item.a_int;
1431 if (idx == 1) {
1432 /* sort change requested */

Callers 2

pfxfn_cond_Function · 0.85
optfn_o_status_condFunction · 0.85

Calls 4

qsortFunction · 0.85
add_menuFunction · 0.85
add_menu_headingFunction · 0.85
select_menuFunction · 0.85

Tested by

no test coverage detected