tty perm_invent option handling

The code for toggling perm_invent when windowtype=="tty" was inserted
into the middle of several switch cases that share 'need_redraw' so
was getting executed for various other options such as 'use_inverse'
that precede it in the list of cases.  It was also continuing on to
general feedback for boolean options, reporting "'perm_invent option
toggled on" even if it failed and the option stayed off.
This commit is contained in:
PatR
2022-06-20 16:18:50 -07:00
parent 58b41ccdae
commit 305967add4
2 changed files with 38 additions and 21 deletions
+21 -4
View File
@@ -4403,6 +4403,27 @@ optfn_boolean(int optidx, int req, boolean negated, char *opts, char *op)
} }
} }
break; break;
case opt_perm_invent:
#ifdef TTY_PERM_INVENT
/* if attempting to enable perm_invent fails, say so and return
before "'perm_invent' option toggled on" would be given below;
tty_perm_invent_toggled() and routines it calls don't check
iflags.perm_invent so it doesn't matter that 'SET IT HERE'
hasn't been executed yet */
if (WINDOWPORT("tty") && !negated) {
tty_perm_invent_toggled(!negated);
if (g.tty_invent_win == WIN_ERR) {
/* FIXME: there is some confusion between this and
tty_create_nhwindow(NHW_TTYINVENT) over when this
should be done */
set_option_mod_status("perm_invent", set_gameview);
if (!g.opt_initial)
config_error_add("Enabling perm_invent failed");
return optn_silenterr;
}
}
#endif
} }
/* this dates from when 'O' prompted for a line of options text /* this dates from when 'O' prompted for a line of options text
rather than use a menu to control access to which options can rather than use a menu to control access to which options can
@@ -4471,10 +4492,6 @@ optfn_boolean(int optidx, int req, boolean negated, char *opts, char *op)
case opt_use_inverse: case opt_use_inverse:
case opt_hilite_pile: case opt_hilite_pile:
case opt_perm_invent: case opt_perm_invent:
#ifdef TTY_PERM_INVENT
if (WINDOWPORT("tty"))
tty_perm_invent_toggled(negated);
#endif
case opt_ascii_map: case opt_ascii_map:
case opt_tiled_map: case opt_tiled_map:
g.opt_need_redraw = TRUE; g.opt_need_redraw = TRUE;
+17 -17
View File
@@ -1630,12 +1630,12 @@ tty_create_nhwindow(int type)
raw_printf("tty perm_invent could not be enabled."); raw_printf("tty perm_invent could not be enabled.");
if (newwin->rows < tty_pi_minrow) if (newwin->rows < tty_pi_minrow)
raw_printf( raw_printf(
"tty perm_invent requires %d rows, your terminal has %d.", "tty perm_invent requires %d rows, your terminal has %d.",
(iflags.wc2_statuslines > 2) ? 54 : 53, (iflags.wc2_statuslines > 2) ? 54 : 53,
ttyDisplay->rows); ttyDisplay->rows);
else else
raw_printf( raw_printf(
"tty perm_invent requires %d columns, your terminal has %d.", "tty perm_invent requires %d columns, your terminal has %d.",
tty_pi_mincol, ttyDisplay->cols); tty_pi_mincol, ttyDisplay->cols);
} }
set_option_mod_status("perm_invent", set_gameview); set_option_mod_status("perm_invent", set_gameview);
@@ -2902,7 +2902,7 @@ tty_putstr(winid window, int attr, const char *str)
return; return;
if (cw->type != NHW_MESSAGE if (cw->type != NHW_MESSAGE
#ifdef TTY_PERM_INVENT #ifdef TTY_PERM_INVENT
&& window != g.tty_invent_win && window != g.tty_invent_win
#endif #endif
) )
str = compress_str(str); str = compress_str(str);
@@ -3484,12 +3484,11 @@ x x x
} }
for (pass = 0; pass < 2; ++pass) { for (pass = 0; pass < 2; ++pass) {
for (row = 1; row < (cw->maxrow - 1); ++row) { /* row below top border */ for (row = 1; row < (cw->maxrow - 1); ++row) { /* row below top border */
for (col = (pass for (col = (pass ? bordercol[border_middle] + 1
? bordercol[border_middle] + 1 : bordercol[border_left] + 1);
: bordercol[border_left] + 1); col < (pass ? bordercol[border_right]
col < (pass : bordercol[border_middle]);
? bordercol[border_right] ++col) {
: bordercol[border_middle]); ++col) {
cell = &cw->cells[row][col]; cell = &cw->cells[row][col];
if (obj && *text && ccnt < (bordercol[border_middle] - 1)) { if (obj && *text && ccnt < (bordercol[border_middle] - 1)) {
if (cell->content.ttychar != *text) if (cell->content.ttychar != *text)
@@ -3605,7 +3604,8 @@ x x x
if (row == 0) { if (row == 0) {
if (col == bordercol[border_left]) if (col == bordercol[border_left])
glyph = cmap_to_glyph(S_tlcorn); glyph = cmap_to_glyph(S_tlcorn);
else if ((col > bordercol[border_left] && col < bordercol[border_middle]) else if ((col > bordercol[border_left]
&& col < bordercol[border_middle])
|| (col > bordercol[border_middle] || (col > bordercol[border_middle]
&& col < bordercol[border_right])) && col < bordercol[border_right]))
glyph = cmap_to_glyph(S_hwall); glyph = cmap_to_glyph(S_hwall);
@@ -3616,7 +3616,8 @@ x x x
} else if (row == (cw->maxrow - 1)) { } else if (row == (cw->maxrow - 1)) {
if (col == bordercol[border_left]) if (col == bordercol[border_left])
glyph = cmap_to_glyph(S_blcorn); glyph = cmap_to_glyph(S_blcorn);
else if ((col > bordercol[border_left] && col < bordercol[border_middle]) else if ((col > bordercol[border_left]
&& col < bordercol[border_middle])
|| (col > bordercol[border_middle] || (col > bordercol[border_middle]
&& col < bordercol[border_right])) && col < bordercol[border_right]))
glyph = cmap_to_glyph(S_hwall); glyph = cmap_to_glyph(S_hwall);
@@ -3656,14 +3657,13 @@ void
tty_perm_invent_toggled(boolean negated) tty_perm_invent_toggled(boolean negated)
{ {
if (negated) { if (negated) {
destroy_nhwindow(g.tty_invent_win), g.tty_invent_win = WIN_ERR; if (g.tty_invent_win != WIN_ERR)
destroy_nhwindow(g.tty_invent_win), g.tty_invent_win = WIN_ERR;
done_box_init = FALSE; done_box_init = FALSE;
} else { } else {
if (WINDOWPORT("tty")) { g.tty_invent_win = create_nhwindow(NHW_TTYINVENT);
g.tty_invent_win = create_nhwindow(NHW_TTYINVENT); if (g.tty_invent_win != WIN_ERR)
if (g.tty_invent_win != WIN_ERR) display_nhwindow(g.tty_invent_win, FALSE);
display_nhwindow(g.tty_invent_win, FALSE);
}
} }
} }
#endif #endif