From: nhmall Date: Mon, 20 Jun 2022 17:43:50 +0000 (-0400) Subject: keep perm_invent option X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8fca10029a9ef44998b4f19c9bf1156745ac53ef;p=nethack keep perm_invent option Make it apparent why tty perm_invent can't be set in-game if the terminal cannot support it. --- diff --git a/src/allmain.c b/src/allmain.c index 00aef7177..a39f5d216 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -636,7 +636,7 @@ display_gamewindows(void) start_menu(WIN_INVEN, 0U), end_menu(WIN_INVEN, (char *) 0); #ifdef TTY_PERM_INVENT - if (WINDOWPORT("tty")) { + if (WINDOWPORT("tty") && iflags.perm_invent) { g.tty_invent_win = create_nhwindow(NHW_TTYINVENT); } #endif diff --git a/src/options.c b/src/options.c index ec8886fcf..37281bb66 100644 --- a/src/options.c +++ b/src/options.c @@ -306,6 +306,7 @@ static int handle_add_list_remove(const char *, int); static void remove_autopickup_exception(struct autopickup_exception *); static int count_apes(void); static int count_cond(void); +static void enhance_menu_text(char *, size_t, int, boolean *, struct allopt_t *); static int handler_align_misc(int); static int handler_autounlock(int); @@ -7759,10 +7760,11 @@ doset(void) /* changing options via menu by Per Liboriussen */ else Sprintf(buf, fmtstr_doset_tab, name, *bool_p ? "true" : "false"); + if (pass == 0) + enhance_menu_text(buf, sizeof buf, pass, bool_p, &allopt[i]); add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, ATR_NONE, buf, MENU_ITEMFLAGS_NONE); } - any = cg.zeroany; add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, ATR_NONE, "", MENU_ITEMFLAGS_NONE); @@ -8895,6 +8897,30 @@ set_playmode(void) } /* don't need to do anything special for explore mode or normal play */ } +void +enhance_menu_text( + char *buf, + size_t sz, + int whichpass, + boolean *bool_p, + struct allopt_t *thisopt) +{ + size_t nowsz, availsz; + + if (!buf) + return; + nowsz = strlen(buf) + 1; + availsz = sz - nowsz; + +#ifdef TTY_PERM_INVENT + if (bool_p == &iflags.perm_invent && WINDOWPORT("tty")) { + if (thisopt->setwhere == set_gameview) + Snprintf(eos(buf), availsz, " *terminal size is too small"); + } +#endif + return; +} + #endif /* OPTION_LISTS_ONLY */ diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 72a465d7d..e1fe089e9 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -1623,31 +1623,27 @@ tty_create_nhwindow(int type) newwin->datlen = (short *) 0; newwin->cells = (struct tty_perminvent_cell **) 0; + if ((newwin->rows < tty_pi_minrow) || (newwin->cols < tty_pi_mincol)) { if (newwin->rows < tty_pi_minrow) { tty_destroy_nhwindow(newid); - if (iflags.perm_invent) { - raw_printf("tty perm_invent has been disabled."); - raw_printf( - "tty perm_invent requires %d rows, your terminal has %d.", - (iflags.wc2_statuslines > 2) ? 54 : 53, ttyDisplay->rows); - iflags.perm_invent = FALSE; - } - return WIN_ERR; - } else if (newwin->cols < tty_pi_mincol) { - tty_destroy_nhwindow(newid); - if (iflags.perm_invent) { - raw_printf("tty perm_invent has been disabled."); - raw_printf( - "tty perm_invent requires %d columns, your terminal has %d.", - tty_pi_mincol, ttyDisplay->cols); - iflags.perm_invent = FALSE; + if (!g.program_state.beyond_savefile_load) + raw_printf("tty perm_invent could not be enabled."); + if (newwin->rows < tty_pi_minrow) + raw_printf( + "tty perm_invent requires %d rows, your terminal has %d.", + (iflags.wc2_statuslines > 2) ? 54 : 53, + ttyDisplay->rows); + else + raw_printf( + "tty perm_invent requires %d columns, your terminal has %d.", + tty_pi_mincol, ttyDisplay->cols); } + set_option_mod_status("perm_invent", set_gameview); + iflags.perm_invent = FALSE; return WIN_ERR; } else { int r, c; - iflags.perm_invent = TRUE; - newwin->maxrow = tty_pi_minrow; newwin->maxcol = newwin->cols; /* establish the borders */