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

Function choose_classes_menu

src/windows.c:1643–1761  ·  view source on GitHub ↗

* This is a somewhat generic menu for taking a list of NetHack style * class choices and presenting them via a description * rather than the traditional NetHack characters. * (Benefits users whose first exposure to NetHack is via tiles). * * prompt * The title at the top of the menu. * * category: 0 = monster class * 1 = object class * * way * FALSE = PIC

Source from the content-addressed store, hash-verified

1641 * Returns number selected.
1642 */
1643int
1644choose_classes_menu(const char *prompt,
1645 int category,
1646 boolean way,
1647 char *class_list,
1648 char *class_select)
1649{
1650 menu_item *pick_list = (menu_item *) 0;
1651 winid win;
1652 anything any;
1653 char buf[BUFSZ];
1654 const char *text = 0;
1655 boolean selected;
1656 int ret, i, n, next_accelerator, accelerator = 0;
1657 int clr = NO_COLOR;
1658
1659 if (!class_list || !class_select)
1660 return 0;
1661 next_accelerator = 'a';
1662 any = cg.zeroany;
1663 win = create_nhwindow(NHW_MENU);
1664 start_menu(win, MENU_BEHAVE_STANDARD);
1665 while (*class_list) {
1666 int idx;
1667
1668 selected = FALSE;
1669 switch (category) {
1670 case 0:
1671 idx = def_char_to_monclass(*class_list);
1672 if (!IndexOk(idx, def_monsyms)) {
1673 panic("choose_classes_menu: invalid monclass '%c'",
1674 *class_list);
1675 /*NOTREACHED*/
1676 }
1677 text = def_monsyms[idx].explain;
1678 accelerator = *class_list;
1679 Sprintf(buf, "%s", text);
1680 break;
1681 case 1:
1682 idx = def_char_to_objclass(*class_list);
1683 if (!IndexOk(idx, def_oc_syms)) {
1684 panic("choose_classes_menu: invalid objclass '%c'",
1685 *class_list);
1686 /*NOTREACHED*/
1687 }
1688 text = def_oc_syms[idx].explain;
1689 accelerator = next_accelerator;
1690 Sprintf(buf, "%c %s", *class_list, text);
1691 break;
1692 default:
1693 panic("choose_classes_menu: invalid category %d", category);
1694 /*NOTREACHED*/
1695 }
1696 if (way && *class_select) { /* Selections there already */
1697 if (strchr(class_select, *class_list)) {
1698 selected = TRUE;
1699 }
1700 }

Callers 1

optfn_pickup_typesFunction · 0.85

Calls 7

def_char_to_monclassFunction · 0.85
def_char_to_objclassFunction · 0.85
add_menuFunction · 0.85
add_menu_strFunction · 0.85
select_menuFunction · 0.85
eosFunction · 0.85
panicFunction · 0.50

Tested by

no test coverage detected