MCPcopy Index your code
hub / github.com/NetHack/NetHack / restore_menu

Function restore_menu

src/restore.c:1535–1618  ·  view source on GitHub ↗

put up a menu listing each character from this player's saved games; returns 1: use svp.plname[], 0: new game, -1: quit */

Source from the content-addressed store, hash-verified

1533/* put up a menu listing each character from this player's saved games;
1534 returns 1: use svp.plname[], 0: new game, -1: quit */
1535int
1536restore_menu(
1537 winid bannerwin) /* if not WIN_ERR, clear window
1538 * and show copyright in menu */
1539{
1540 winid tmpwin;
1541 anything any;
1542 char **saved, *next, mode, menutext[BUFSZ];
1543 boolean all_normal;
1544 menu_item *chosen_game = (menu_item *) 0;
1545 int k, clet, ch = 0; /* ch: 0 => new game */
1546 int clr = NO_COLOR;
1547
1548 *svp.plname = '\0';
1549 saved = get_saved_games(); /* array of character names */
1550 if (saved && *saved) {
1551 tmpwin = create_nhwindow(NHW_MENU);
1552 start_menu(tmpwin, MENU_BEHAVE_STANDARD);
1553 any = cg.zeroany; /* no selection */
1554 if (bannerwin != WIN_ERR) {
1555 /* for tty; erase copyright notice and redo it in the menu */
1556 clear_nhwindow(bannerwin);
1557 /* COPYRIGHT_BANNER_[ABCD] */
1558 for (k = 1; k <= 4; ++k)
1559 add_menu_str(tmpwin, copyright_banner_line(k));
1560 add_menu_str(tmpwin, "");
1561 }
1562 add_menu_str(tmpwin, "Select one of your saved games");
1563 /* if all the save files have a playmode of '-' then we'll just list
1564 their character name-role-race-gend-algn values, but if any are
1565 'X' or 'D', we'll list playmode along with name-role-&c values
1566 for every entry; first, figure out if they're all normal play */
1567 for (all_normal = TRUE, k = 0; all_normal && saved[k]; ++k) {
1568 next = saved[k];
1569 mode = next[PL_NSIZ_PLUS - 1]; /* fixed last char, beyond '\0' */
1570 if (mode != '-')
1571 all_normal = FALSE;
1572 }
1573 for (k = 0; saved[k]; ++k) {
1574 any.a_int = k + 1;
1575 next = saved[k];
1576 mode = next[PL_NSIZ_PLUS - 1];
1577 if (all_normal)
1578 Sprintf(menutext, "%.*s", PL_NSIZ_PLUS - 1, next);
1579 else
1580 Sprintf(menutext, "%c %.*s", mode, PL_NSIZ_PLUS - 1, next);
1581 add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, ATR_NONE, clr,
1582 menutext, MENU_ITEMFLAGS_SKIPMENUCOLORS);
1583 }
1584 clet = (k <= 'n' - 'a') ? 'n' /* new game */
1585 : (k <= 26 + 'N' - 'A') ? 'N' : 0;
1586 any.a_int = -1; /* not >= 0 */
1587 add_menu(tmpwin, &nul_glyphinfo, &any, clet, 'N', ATR_NONE, clr,
1588 "Start a new character", MENU_ITEMFLAGS_NONE);
1589 clet = (k + 1 <= 'q' - 'a' && clet == 'n') ? 'q' /* quit */
1590 : (k + 1 <= 26 + 'Q' - 'A' && clet == 'N') ? 'Q' : 0;
1591 any.a_int = -2;
1592 add_menu(tmpwin, &nul_glyphinfo, &any, clet, 'Q', ATR_NONE, clr,

Callers 3

tty_asknameFunction · 0.85
curses_asknameFunction · 0.85
X11_asknameFunction · 0.85

Calls 6

get_saved_gamesFunction · 0.85
add_menu_strFunction · 0.85
copyright_banner_lineFunction · 0.85
add_menuFunction · 0.85
select_menuFunction · 0.85
free_saved_gamesFunction · 0.85

Tested by

no test coverage detected