add some flexibility to TTY_PERM_INVENT

Allow perm_invent to be enabled with 1 less line when statuslines==2
by not reserving a line for statuslines==3.  If the player changes
that from 2 to 3, the perm_invent window is torn down and repositioned
one line lower if that will fit.  If it won't fit, it won't reenable.

Temporarily(?) allow perminv_mode==InUse to be enabled with room for
only 8 lines instead of requiring 15.  It will use more than 8 if are
more rows.

8 happens to be the amount (via 1+21+3+(1+8+1)) that will fit within
35 lines which is the biggest I can make fit on may laptop without
switching to a smaller font.  Switching is a nuisance, worse than that
for the font tiny enough to fit the full perm_invent.

ToDo:  if in-use won't fit in the number of lines allotted, switch to
two columns before resorting to ignoring the excess.

Maybe:  allow fewer lines for full perm_invent too and use the '|'
command to scroll them.  Might be too clumsy to be worthwhile.
This commit is contained in:
PatR
2023-12-04 13:20:25 -08:00
parent d52049a5d3
commit 2d8ba944e1

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 wintty.c $NHDT-Date: 1700385095 2023/11/19 09:11:35 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.365 $ */ /* NetHack 3.7 wintty.c $NHDT-Date: 1701723543 2023/12/04 20:59:03 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.369 $ */
/* Copyright (c) David Cohrs, 1991 */ /* Copyright (c) David Cohrs, 1991 */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -233,9 +233,9 @@ static const char *compress_str(const char *);
#ifndef STATUS_HILITES #ifndef STATUS_HILITES
static void tty_putsym(winid, int, int, char); static void tty_putsym(winid, int, int, char);
#endif #endif
#ifdef STATUS_HILITES
#define MAX_STATUS_ROWS 3 #define MAX_STATUS_ROWS 3
#define StatusRows() ((iflags.wc2_statuslines <= 2) ? 2 : MAX_STATUS_ROWS) #define StatusRows() ((iflags.wc2_statuslines <= 2) ? 2 : MAX_STATUS_ROWS)
#ifdef STATUS_HILITES
static boolean check_fields(boolean forcefields, int sz[MAX_STATUS_ROWS]); static boolean check_fields(boolean forcefields, int sz[MAX_STATUS_ROWS]);
static void render_status(void); static void render_status(void);
static void tty_putstatusfield(const char *, int, int); static void tty_putstatusfield(const char *, int, int);
@@ -516,7 +516,7 @@ tty_init_nhwindows(int *argcp UNUSED, char **argv UNUSED)
/* options aren't processed yet so wc2_statuslines might be 0; /* options aren't processed yet so wc2_statuslines might be 0;
make sure that it has a reasonable value during tty setup */ make sure that it has a reasonable value during tty setup */
iflags.wc2_statuslines = (iflags.wc2_statuslines < 3) ? 2 : 3; iflags.wc2_statuslines = StatusRows(); /* 2 or 3; 0 => 2 */
/* /*
* Remember tty modes, to be restored on exit. * Remember tty modes, to be restored on exit.
* *
@@ -596,7 +596,10 @@ tty_init_nhwindows(int *argcp UNUSED, char **argv UNUSED)
void void
tty_preference_update(const char *pref) tty_preference_update(const char *pref)
{ {
if (!strcmp(pref, "statuslines") && iflags.window_inited) { boolean newstatuslines = (!strcmp(pref, "statuslines")
&& iflags.window_inited);
if (newstatuslines) {
new_status_window(); new_status_window();
newclipping(u.ux, u.uy); newclipping(u.ux, u.uy);
} }
@@ -617,6 +620,13 @@ tty_preference_update(const char *pref)
if (WIN_INVEN != WIN_ERR) if (WIN_INVEN != WIN_ERR)
tty_invent_box_glyph_init(wins[WIN_INVEN]); tty_invent_box_glyph_init(wins[WIN_INVEN]);
} }
/* if newstatuslines has been toggled between 2 and 3 or vice versa
then we want to reposition the perm_invent window to match */
if (newstatuslines && WIN_INVEN != WIN_ERR) {
perm_invent_toggled(TRUE); /*TEMP?*/
tty_destroy_nhwindow(WIN_INVEN), WIN_INVEN = WIN_ERR;
perm_invent_toggled(FALSE); /*TEMP?*/
}
#endif #endif
return; return;
} }
@@ -2426,7 +2436,7 @@ tty_display_file(
#endif #endif
) { ) {
/* attempt to scroll text below map window if there's room */ /* attempt to scroll text below map window if there's room */
wins[datawin]->offy = wins[WIN_STATUS]->offy + 3; wins[datawin]->offy = wins[WIN_STATUS]->offy + StatusRows();
if ((int) wins[datawin]->offy + 12 > (int) ttyDisplay->rows) if ((int) wins[datawin]->offy + 12 > (int) ttyDisplay->rows)
wins[datawin]->offy = 0; wins[datawin]->offy = 0;
} }
@@ -2816,7 +2826,7 @@ tty_ctrl_nhwindow(winid window UNUSED, int request, win_request_info *wri)
wri->tocore = zero_tocore; wri->tocore = zero_tocore;
tty_ok = assesstty(ttyinvmode, &offx, &offy, &rows, &cols, &maxcol, tty_ok = assesstty(ttyinvmode, &offx, &offy, &rows, &cols, &maxcol,
&minrow, &maxrow); &minrow, &maxrow);
wri->tocore.needrows = (int) (minrow + 1 + ROWNO + 3); wri->tocore.needrows = (int) (minrow + 1 + ROWNO + StatusRows());
wri->tocore.needcols = (int) tty_perminv_mincol; wri->tocore.needcols = (int) tty_perminv_mincol;
wri->tocore.haverows = (int) ttyDisplay->rows; wri->tocore.haverows = (int) ttyDisplay->rows;
wri->tocore.havecols = (int) ttyDisplay->cols; wri->tocore.havecols = (int) ttyDisplay->cols;
@@ -2890,7 +2900,7 @@ ttyinv_create_window(int newid, struct WinDesc *newwin)
pline("%s.", "tty perm_invent could not be enabled"); pline("%s.", "tty perm_invent could not be enabled");
pline("tty perm_invent needs a terminal that is at least %dx%d, " pline("tty perm_invent needs a terminal that is at least %dx%d, "
"yours is %dx%d.", "yours is %dx%d.",
(int) (minrow + 1 + ROWNO + 3), tty_perminv_mincol, (int) (minrow + 1 + ROWNO + StatusRows()), tty_perminv_mincol,
ttyDisplay->rows, ttyDisplay->cols); ttyDisplay->rows, ttyDisplay->cols);
tty_wait_synch(); tty_wait_synch();
set_option_mod_status("perm_invent", set_gameview); set_option_mod_status("perm_invent", set_gameview);
@@ -2901,7 +2911,7 @@ ttyinv_create_window(int newid, struct WinDesc *newwin)
/* /*
* Terminal/window/screen is big enough. * Terminal/window/screen is big enough.
*/ */
newwin->maxrow = minrow; /*newwin->maxrow = minrow;*/
newwin->maxcol = newwin->cols; newwin->maxcol = newwin->cols;
/* establish the borders */ /* establish the borders */
bordercol[border_left] = 0; bordercol[border_left] = 0;
@@ -2995,9 +3005,12 @@ ttyinv_add_menu(
char invbuf[BUFSZ]; char invbuf[BUFSZ];
const char *text; const char *text;
boolean show_gold = (ttyinvmode & InvShowGold) != 0, boolean show_gold = (ttyinvmode & InvShowGold) != 0,
inuse_only = (ttyinvmode & InvInUse) != 0,
ignore = FALSE; ignore = FALSE;
int row, side, slot, int row, side, slot,
rows_per_side = (!show_gold ? 26 : 27); rows_per_side = (inuse_only ? (cw->maxrow - 2)
: !show_gold ? 26
: 27);
if (!gp.program_state.in_moveloop) if (!gp.program_state.in_moveloop)
return; return;
@@ -3210,27 +3223,32 @@ assesstty(
short *offx, short *offy, long *rows, long *cols, short *offx, short *offy, long *rows, long *cols,
long *maxcol, long *minrow, long *maxrow) long *maxcol, long *minrow, long *maxrow)
{ {
boolean show_gold = (invmode & InvShowGold) != 0, boolean inuse_only = (invmode & InvInUse) != 0,
inuse_only = (invmode & InvInUse) != 0; show_gold = (invmode & InvShowGold) != 0 && !inuse_only;
*offx = 0; *offx = 0;
/* topline + map rows + status lines */ /* topline + map rows + status lines */
*offy = 1 + ROWNO + 3; /* 3: + 2 + (iflags.wc2_statuslines > 2) */ *offy = 1 + ROWNO + StatusRows(); /* 1 + 21 + (2 or 3) */
*rows = (ttyDisplay->rows - (*offy)); *rows = (ttyDisplay->rows - *offy);
*cols = ttyDisplay->cols; *cols = ttyDisplay->cols;
*minrow = tty_perminv_minrow; *minrow = tty_perminv_minrow;
if (show_gold) if (show_gold)
*minrow += 1; *minrow += 1;
#define SMALL_INUSE_WINDOW
#ifdef SMALL_INUSE_WINDOW
#undef SMALL_INUSE_WINDOW
/* simplify testing by not requiring a small font to have enough room */
if (inuse_only)
*minrow = 1 + 8 + 1;
#else
/* "normal" max for items in use would be 3 weapon + 7 armor + 4 /* "normal" max for items in use would be 3 weapon + 7 armor + 4
accessories == 14, but being punished and picking up the ball will accessories == 14, but lit lamps/candles and attached leashes are
add 1, and some quest artifacts have an an #invoke property that's also included; if hero ends up with more than 15 in-use items,
tracked via obj->owornmask so could add more; also, lit lamps/candles some will be left out */
and attached leashes are included; if hero ends up with more than
15 in-use items, some will be left out */
if (inuse_only) if (inuse_only)
*minrow = 1 + 15 + 1; /* top border + 15 lines + bottom border */ *minrow = 1 + 15 + 1; /* top border + 15 lines + bottom border */
*maxrow = *minrow; /* FIXME: inuse_only should be able to use more #endif
* than the minimum if extra lines are available */ *maxrow = *rows;
*maxcol = *cols; *maxcol = *cols;
return !(*rows < *minrow || *cols < tty_perminv_mincol); return !(*rows < *minrow || *cols < tty_perminv_mincol);
} }