shows menu of known spells, with options to sort them. return FALSE on cancel, TRUE otherwise. spell_no is set to the internal spl_book index, if any selected */
| 2072 | return FALSE on cancel, TRUE otherwise. |
| 2073 | spell_no is set to the internal spl_book index, if any selected */ |
| 2074 | staticfn boolean |
| 2075 | dospellmenu( |
| 2076 | const char *prompt, |
| 2077 | int splaction, /* SPELLMENU_CAST, SPELLMENU_VIEW, SPELLMENU_DUMP or |
| 2078 | * svs.spl_book[] index */ |
| 2079 | int *spell_no) |
| 2080 | { |
| 2081 | winid tmpwin; |
| 2082 | int i, n, how, splnum; |
| 2083 | char buf[BUFSZ], retentionbuf[24], sep; |
| 2084 | const char *fmt; |
| 2085 | menu_item *selected; |
| 2086 | anything any; |
| 2087 | int clr = NO_COLOR; |
| 2088 | |
| 2089 | tmpwin = create_nhwindow(NHW_MENU); |
| 2090 | start_menu(tmpwin, MENU_BEHAVE_STANDARD); |
| 2091 | any = cg.zeroany; /* zero out all bits */ |
| 2092 | |
| 2093 | /* |
| 2094 | * The correct spacing of the columns when not using |
| 2095 | * tab separation depends on the following: |
| 2096 | * (1) that the font is monospaced, and |
| 2097 | * (2) that selection letters are prepended to the |
| 2098 | * given string and are of the form "a - ". |
| 2099 | * For SPELLMENU_DUMP, (2) is untrue, so four spaces |
| 2100 | * need to be subtracted. |
| 2101 | */ |
| 2102 | if (!iflags.menu_tab_sep) { |
| 2103 | Sprintf(buf, "%s%-20s Level %-12s Fail Retention", |
| 2104 | splaction == SPELLMENU_DUMP ? "" : " ", |
| 2105 | "Name", |
| 2106 | "Category"); |
| 2107 | fmt = "%-20s %2d %-12s %3d%% %9s"; |
| 2108 | sep = ' '; |
| 2109 | } else { |
| 2110 | Sprintf(buf, "Name\tLevel\tCategory\tFail\tRetention"); |
| 2111 | fmt = "%s\t%-d\t%s\t%-d%%\t%s"; |
| 2112 | sep = '\t'; |
| 2113 | } |
| 2114 | if (wizard) |
| 2115 | Sprintf(eos(buf), "%c%6s", sep, "turns"); |
| 2116 | |
| 2117 | add_menu_heading(tmpwin, buf); |
| 2118 | for (i = 0; i < MAXSPELL && spellid(i) != NO_SPELL; i++) { |
| 2119 | splnum = !gs.spl_orderindx ? i : gs.spl_orderindx[i]; |
| 2120 | Sprintf(buf, fmt, spellname(splnum), spellev(splnum), |
| 2121 | spelltypemnemonic(spell_skilltype(spellid(splnum))), |
| 2122 | 100 - percent_success(splnum), |
| 2123 | spellretention(splnum, retentionbuf)); |
| 2124 | if (wizard) |
| 2125 | Sprintf(eos(buf), "%c%6d", sep, spellknow(i)); |
| 2126 | |
| 2127 | any.a_int = splnum + 1; /* must be non-zero */ |
| 2128 | add_menu(tmpwin, &nul_glyphinfo, &any, spellet(splnum), 0, |
| 2129 | ATR_NONE, clr, buf, |
| 2130 | (splnum == splaction) |
| 2131 | ? MENU_ITEMFLAGS_SELECTED : MENU_ITEMFLAGS_NONE); |
no test coverage detected