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

Function spellsortmenu

src/spell.c:1975–2017  ·  view source on GitHub ↗

called if the [sort spells] entry in the view spells menu gets chosen */

Source from the content-addressed store, hash-verified

1973
1974/* called if the [sort spells] entry in the view spells menu gets chosen */
1975staticfn boolean
1976spellsortmenu(void)
1977{
1978 winid tmpwin;
1979 menu_item *selected;
1980 anything any;
1981 char let;
1982 int i, n, choice;
1983 int clr = NO_COLOR;
1984
1985 tmpwin = create_nhwindow(NHW_MENU);
1986 start_menu(tmpwin, MENU_BEHAVE_STANDARD);
1987 any = cg.zeroany; /* zero out all bits */
1988
1989 for (i = 0; i < SIZE(spl_sortchoices); i++) {
1990 if (i == SORTRETAINORDER) {
1991 let = 'z'; /* assumes fewer than 26 sort choices... */
1992 /* separate final choice from others with a blank line */
1993 add_menu_str(tmpwin, "");
1994 } else {
1995 let = 'a' + i;
1996 }
1997 any.a_int = i + 1;
1998 add_menu(tmpwin, &nul_glyphinfo, &any, let, 0,
1999 ATR_NONE, clr, spl_sortchoices[i],
2000 (i == gs.spl_sortmode) ? MENU_ITEMFLAGS_SELECTED
2001 : MENU_ITEMFLAGS_NONE);
2002 }
2003 end_menu(tmpwin, "View known spells list sorted");
2004
2005 n = select_menu(tmpwin, PICK_ONE, &selected);
2006 destroy_nhwindow(tmpwin);
2007 if (n > 0) {
2008 choice = selected[0].item.a_int - 1;
2009 /* skip preselected entry if we have more than one item chosen */
2010 if (n > 1 && choice == gs.spl_sortmode)
2011 choice = selected[1].item.a_int - 1;
2012 free((genericptr_t) selected);
2013 gs.spl_sortmode = choice;
2014 return TRUE;
2015 }
2016 return FALSE;
2017}
2018
2019/* the #showspells command -- view known spells */
2020int

Callers 1

dovspellFunction · 0.85

Calls 3

add_menu_strFunction · 0.85
add_menuFunction · 0.85
select_menuFunction · 0.85

Tested by

no test coverage detected