new 'showvers' option
Add options 'showvers' (boolean) and 'versinfo' (numeric mask) to show nethack's version on the status lines during play. It won't be particularly interesting to ordinary players but should be useful when making screenshots or video to be streamed, or for someone who switches between git branches or between nethack and variants. I worked on this several months back but it was combined with unfinished changes to 'hitpointbar'. I've separated it out so that it can be put into use. When enabled, one or more components of "<name> <branch> <version>" will be shown right justified after status conditions. At present the default is "<branch>" if that is available and overall status isn't 'released', or "<version>" if 'released' or if branch isn't available. That might need some refinement. It works as intended for tty and curses, although some abbreviation mechanism would be useful if/when the program resorts to abbreviating status conditions to make things narrow enough to fit. For X11, it works ok for fancy_status:True (the default, controlled via NetHack.ad settings) but is messed up for tty-style status. The text is positioned correctly but there are gaps in it, making it appear garbled, similar to what I saw when I tried and failed to implement statuslines:3 for X11. [It might be due to having empty condition widgets be 1 pixel wide instead of being totally removed but I don't think the situation is that simple.] For Qt, if the text needs to be truncated in order to fit, the center portion of the string will be shown, discarding parts from the left and right. That ought to discard from left and retain rightmost portion instead. For win32|mswin|Win GUI, no attempt to support it has been included. Things should be ok when 'showvers' is left as False (the default) but I don't know what will happen if that gets toggled to True. At a minimum, the version info won't be right justified. The information, or at least some of it, is displayed in the game window's title bar so there isn't any pressing need to add it to status, but toggling the option will need to behave sensibly if it doesn't already.
This commit is contained in:
@@ -251,12 +251,12 @@ draw_horizontal(boolean border)
|
||||
/* almost all fields already come with a leading space;
|
||||
"xspace" indicates places where we'll generate an extra one */
|
||||
static const enum statusfields
|
||||
twolineorder[3][15] = {
|
||||
twolineorder[3][16] = {
|
||||
{ BL_TITLE,
|
||||
/*xspace*/ BL_STR, BL_DX, BL_CO, BL_IN, BL_WI, BL_CH,
|
||||
/*xspace*/ BL_ALIGN,
|
||||
/*xspace*/ BL_SCORE,
|
||||
BL_FLUSH, blPAD, blPAD, blPAD, blPAD, blPAD },
|
||||
BL_FLUSH, blPAD, blPAD, blPAD, blPAD, blPAD, blPAD },
|
||||
{ BL_LEVELDESC,
|
||||
/*xspace*/ BL_GOLD,
|
||||
/*xspace*/ BL_HP, BL_HPMAX,
|
||||
@@ -264,16 +264,16 @@ draw_horizontal(boolean border)
|
||||
/*xspace*/ BL_AC,
|
||||
/*xspace*/ BL_XP, BL_EXP, BL_HD,
|
||||
/*xspace*/ BL_TIME,
|
||||
/*xspace*/ BL_HUNGER, BL_CAP, BL_CONDITION,
|
||||
/*xspace*/ BL_HUNGER, BL_CAP, BL_CONDITION, BL_VERS,
|
||||
BL_FLUSH },
|
||||
{ BL_FLUSH, blPAD, blPAD, blPAD, blPAD, blPAD, blPAD, blPAD,
|
||||
blPAD, blPAD, blPAD, blPAD, blPAD, blPAD, blPAD }
|
||||
blPAD, blPAD, blPAD, blPAD, blPAD, blPAD, blPAD, blPAD }
|
||||
},
|
||||
threelineorder[3][15] = { /* moves align to line 2, leveldesc+ to 3 */
|
||||
threelineorder[3][16] = { /* moves align to line 2, leveldesc+ to 3 */
|
||||
{ BL_TITLE,
|
||||
/*xspace*/ BL_STR, BL_DX, BL_CO, BL_IN, BL_WI, BL_CH,
|
||||
/*xspace*/ BL_SCORE,
|
||||
BL_FLUSH, blPAD, blPAD, blPAD, blPAD, blPAD, blPAD },
|
||||
BL_FLUSH, blPAD, blPAD, blPAD, blPAD, blPAD, blPAD, blPAD },
|
||||
{ BL_ALIGN,
|
||||
/*xspace*/ BL_GOLD,
|
||||
/*xspace*/ BL_HP, BL_HPMAX,
|
||||
@@ -281,14 +281,15 @@ draw_horizontal(boolean border)
|
||||
/*xspace*/ BL_AC,
|
||||
/*xspace*/ BL_XP, BL_EXP, BL_HD,
|
||||
/*xspace*/ BL_HUNGER, BL_CAP,
|
||||
BL_FLUSH, blPAD, blPAD },
|
||||
BL_FLUSH, blPAD, blPAD, blPAD },
|
||||
{ BL_LEVELDESC,
|
||||
/*xspace*/ BL_TIME,
|
||||
/*xspecial*/ BL_CONDITION,
|
||||
/*xspecial*/ BL_VERS,
|
||||
BL_FLUSH, blPAD, blPAD, blPAD, blPAD, blPAD, blPAD, blPAD,
|
||||
blPAD, blPAD, blPAD, blPAD }
|
||||
};
|
||||
const enum statusfields (*fieldorder)[15];
|
||||
const enum statusfields (*fieldorder)[16];
|
||||
coordxy spacing[MAXBLSTATS], valline[MAXBLSTATS];
|
||||
enum statusfields fld, prev_fld;
|
||||
char *text, *p, cbuf[BUFSZ], ebuf[STATVAL_WIDTH];
|
||||
@@ -297,11 +298,11 @@ draw_horizontal(boolean border)
|
||||
char sbuf[STATVAL_WIDTH];
|
||||
#endif
|
||||
int i, j, number_of_lines,
|
||||
cap_and_hunger, exp_points, sho_score,
|
||||
cap_and_hunger, exp_points, sho_score, sho_vers,
|
||||
/* both height and width get their values set,
|
||||
* but only width gets used in this function */
|
||||
height UNUSED, width, w, xtra, clen, x, y, t, ex, ey,
|
||||
condstart = 0, conddummy = 0;
|
||||
condstart = 0, conddummy = 0, versstart = 0;
|
||||
#ifdef STATUS_HILITES
|
||||
int coloridx = NO_COLOR, attrmask = 0;
|
||||
#endif /* STATUS_HILITES */
|
||||
@@ -357,6 +358,10 @@ draw_horizontal(boolean border)
|
||||
exp_points = (flags.showexp ? 1 : 0);
|
||||
/* don't bother conditionalizing this; always 0 for !SCORE_ON_BOTL */
|
||||
sho_score = (status_activefields[BL_SCORE] != 0);
|
||||
sho_vers = (status_activefields[BL_VERS] != 0);
|
||||
versstart = sho_vers ? (width - (int) strlen(status_vals[BL_VERS])
|
||||
+ (border ? 1 : 0))
|
||||
: 0;
|
||||
|
||||
/* simplify testing which fields reside on which lines; assume line #0 */
|
||||
(void) memset((genericptr_t) valline, 0, sizeof valline);
|
||||
@@ -423,6 +428,8 @@ draw_horizontal(boolean border)
|
||||
text = cbuf; /* for 'w += strlen(text)' below */
|
||||
spacing[fld] = (cap_and_hunger == 0);
|
||||
break;
|
||||
case BL_VERS:
|
||||
spacing[fld] = 1;
|
||||
case BL_STR:
|
||||
case BL_HP:
|
||||
case BL_ENE:
|
||||
@@ -573,6 +580,11 @@ draw_horizontal(boolean border)
|
||||
|
||||
} else if (fld != BL_CONDITION) {
|
||||
/* regular field, including title if no hitpointbar */
|
||||
if (fld == BL_VERS) {
|
||||
getyx(win, y, x);
|
||||
if (x < versstart)
|
||||
wmove(win, y, versstart); /* right justify */
|
||||
}
|
||||
#ifdef STATUS_HILITES
|
||||
coloridx = curses_status_colors[fld]; /* includes attribute */
|
||||
if (iflags.hilite_delta && coloridx != NO_COLOR) {
|
||||
@@ -615,6 +627,14 @@ draw_horizontal(boolean border)
|
||||
y = j + (border ? 1 : 0);
|
||||
/* cbuf[] was populated above; clen is its length */
|
||||
if (number_of_lines == 3) {
|
||||
int vlen = (sho_vers
|
||||
&& fieldorder[j][i + 1] == BL_VERS)
|
||||
? ((int) strlen(status_vals[BL_VERS])
|
||||
+ spacing[BL_VERS])
|
||||
: 0;
|
||||
|
||||
clen += vlen; /* when aligning conditions, treat
|
||||
* version as if an added condition */
|
||||
/*
|
||||
* For 3-line status, align conditions with hunger
|
||||
* (or where it would have been, when not shown),
|
||||
@@ -632,6 +652,7 @@ draw_horizontal(boolean border)
|
||||
else
|
||||
wmove(win, y, width + (border ? 1 : 0) - clen);
|
||||
}
|
||||
clen -= vlen;
|
||||
}
|
||||
/* 'asis' was set up by first curs_stat_conds() call
|
||||
above; True means that none of the conditions
|
||||
@@ -663,31 +684,34 @@ draw_vertical(boolean border)
|
||||
removed if we need to shrink to fit within height limit (very rare) */
|
||||
static const enum statusfields fieldorder[] = {
|
||||
BL_TITLE, /* might be overlaid by hitpoint bar */
|
||||
/* 4:blank */
|
||||
/* 5:blank */
|
||||
BL_HP, BL_HPMAX,
|
||||
BL_ENE, BL_ENEMAX,
|
||||
BL_AC,
|
||||
/* 3:blank */
|
||||
/* 4:blank */
|
||||
BL_LEVELDESC,
|
||||
BL_ALIGN,
|
||||
BL_XP, BL_EXP, BL_HD,
|
||||
BL_GOLD,
|
||||
/* 2:blank (but only if time or score or both enabled) */
|
||||
/* 3:blank (but only if time or score or both enabled) */
|
||||
BL_TIME,
|
||||
BL_SCORE,
|
||||
/* 1:blank */
|
||||
/* 2:blank */
|
||||
BL_STR, BL_DX, BL_CO, BL_IN, BL_WI, BL_CH,
|
||||
/* 5:blank (if any of hunger, encumbrance, or conditions appear) */
|
||||
/* 6:blank (if any of hunger, encumbrance, or conditions appear) */
|
||||
BL_HUNGER, BL_CAP, /* these two are shown on same line */
|
||||
BL_CONDITION, /* shown three per line so may take up to four lines */
|
||||
/* 1:blank (bottom justified) */
|
||||
BL_VERS,
|
||||
BL_FLUSH
|
||||
};
|
||||
static const enum statusfields shrinkorder[] = {
|
||||
BL_STR, BL_SCORE, BL_TIME, BL_LEVELDESC, BL_HP,
|
||||
BL_VERS, BL_STR, BL_SCORE, BL_TIME, BL_LEVELDESC, BL_HP,
|
||||
BL_CONDITION, BL_CAP, BL_HUNGER
|
||||
};
|
||||
coordxy spacing[MAXBLSTATS];
|
||||
int i, fld, cap_and_hunger, time_and_score, cond_count, per_line;
|
||||
int i, fld, cap_and_hunger, time_and_score, cond_count,
|
||||
sho_vers, per_line;
|
||||
char *text;
|
||||
#ifdef STATUS_HILITES
|
||||
char *p = 0, savedch = '\0';
|
||||
@@ -729,6 +753,7 @@ draw_vertical(boolean border)
|
||||
++cond_count;
|
||||
}
|
||||
per_line = 2; /* will be changed to 3 if status becomes too tall */
|
||||
sho_vers = (status_activefields[BL_VERS] ? 1 : 0);
|
||||
|
||||
/* count how many lines we'll need; we normally space several groups of
|
||||
fields with blank lines but might need to compress some of those out */
|
||||
@@ -753,7 +778,7 @@ draw_vertical(boolean border)
|
||||
/* unlike hunger+cap, score is shown on separate line from time;
|
||||
needs time+score separator if time is inactive */
|
||||
spacing[fld] = (time_and_score == 2) ? 2
|
||||
: (time_and_score & 1) ? 1 : 0;
|
||||
: (time_and_score == 3) ? 1 : 0;
|
||||
break;
|
||||
case BL_HUNGER:
|
||||
/* separated from characteristics unless blank */
|
||||
@@ -773,6 +798,9 @@ draw_vertical(boolean border)
|
||||
if (cond_count > per_line)
|
||||
height_needed += (cond_count - 1) / per_line;
|
||||
break;
|
||||
case BL_VERS:
|
||||
spacing[fld] = sho_vers ? 2 : 0;
|
||||
break;
|
||||
case BL_XP:
|
||||
case BL_HD:
|
||||
default:
|
||||
@@ -785,9 +813,9 @@ draw_vertical(boolean border)
|
||||
if (height_needed > height) {
|
||||
/* if there are a lot of status conditions, compress them first */
|
||||
if (per_line == 2 && cond_count > per_line) {
|
||||
height_needed -= (cond_count - 1) / per_line;
|
||||
per_line = 3;
|
||||
height_needed += (cond_count - 1) / per_line;
|
||||
height_needed -= (cond_count - 1) / per_line;
|
||||
per_line = 3;
|
||||
height_needed += (cond_count - 1) / per_line;
|
||||
}
|
||||
if (height_needed > height) {
|
||||
for (i = 0; i < SIZE(shrinkorder); ++i) {
|
||||
@@ -802,7 +830,7 @@ draw_vertical(boolean border)
|
||||
#ifdef SCORE_ON_BOTL
|
||||
/* with all optional fields and every status condition (12 out
|
||||
of the 13 since two are mutually exclusive) active, we need
|
||||
21 non-blank lines; curses_create_main_windows() used to
|
||||
22 non-blank lines; curses_create_main_windows() used to
|
||||
require 24 lines or more in order to enable vertical status,
|
||||
but that has been relaxed to 20 so height_needed might still
|
||||
be too high after suppressing all the blank lines */
|
||||
@@ -810,11 +838,18 @@ draw_vertical(boolean border)
|
||||
height_needed -= spacing[BL_SCORE];
|
||||
spacing[BL_SCORE] = 0;
|
||||
time_and_score &= ~2;
|
||||
/* height_needed isn't used beyond here but we keep it accurate */
|
||||
nhUse(height_needed);
|
||||
}
|
||||
#endif
|
||||
} else if (height_needed < height) {
|
||||
if (sho_vers) {
|
||||
/* bottom justify 'version' */
|
||||
spacing[BL_VERS] += height - height_needed; /* 2 + (h - h') */
|
||||
height_needed = height;
|
||||
}
|
||||
}
|
||||
/* height_needed isn't used beyond here but was updated (for BL_SCORE
|
||||
or BL_VERS) to keep it accurate in case that changes someday */
|
||||
nhUse(height_needed);
|
||||
|
||||
if (border)
|
||||
x++, y++;
|
||||
@@ -828,9 +863,8 @@ draw_vertical(boolean border)
|
||||
continue;
|
||||
|
||||
if (spacing[fld]) {
|
||||
wmove(win, y++, x); /* move to next line */
|
||||
if (spacing[fld] == 2)
|
||||
wmove(win, y++, x); /* skip a line */
|
||||
y += spacing[fld];
|
||||
wmove(win, y - 1, x); /* move to next (or further) line */
|
||||
}
|
||||
|
||||
if (fld == BL_TITLE && iflags.wc2_hitpointbar) {
|
||||
@@ -903,7 +937,7 @@ draw_vertical(boolean border)
|
||||
} else {
|
||||
/* status conditions */
|
||||
if (cond_count) {
|
||||
/* output active conditions; usually two per line, but
|
||||
/* output active conditions; usually two per line, but if
|
||||
window isn't tall enough, it's increased to three per line;
|
||||
cursor is already positioned where they should start */
|
||||
curs_stat_conds(1, per_line, &x, &y,
|
||||
@@ -987,7 +1021,7 @@ DISABLE_WARNING_FORMAT_NONLITERAL
|
||||
static void
|
||||
curs_stat_conds(
|
||||
int vert_cond, /* 0 => horizontal, 1 => vertical */
|
||||
int per_line, /* for vertical number of conditions per line */
|
||||
int per_line, /* for vertical, number of conditions per line */
|
||||
int *x, int *y, /* real for vertical, ignored otherwise */
|
||||
char *condbuf, /* optional output; collect string of conds */
|
||||
boolean *nohilite) /* optional output; indicates whether -*/
|
||||
@@ -1087,7 +1121,7 @@ curs_stat_conds(
|
||||
}
|
||||
#endif /* STATUS_HILITES */
|
||||
/* if that was #3 of 3 advance to next line */
|
||||
if (do_vert && (++vert_cond % per_line) == 1)
|
||||
if (do_vert && cond_bits && (++vert_cond % per_line) == 1)
|
||||
wmove(win, (*y)++, *x);
|
||||
} /* if cond_bits & bitmask */
|
||||
} /* for i */
|
||||
@@ -1189,6 +1223,7 @@ curs_vert_status_vals(int win_width)
|
||||
Sprintf(leadingspace, "%*s",
|
||||
(hp_width + 3) - fld_width, " ");
|
||||
/*FALLTHRU*/
|
||||
case BL_VERS:
|
||||
case BL_EXP:
|
||||
case BL_HUNGER:
|
||||
case BL_CAP:
|
||||
@@ -1202,6 +1237,17 @@ curs_vert_status_vals(int win_width)
|
||||
Sprintf(status_vals_long[fldidx], "%*.*s: %s%s",
|
||||
-lbl_width, lbl_width, lbl, leadingspace, text);
|
||||
*status_vals_long[fldidx] = highc(*status_vals_long[fldidx]);
|
||||
} else if (fldidx == BL_VERS && *text) {
|
||||
int txtlen = (int) strlen(text);
|
||||
|
||||
/* right justify without "Version :" prefix; if longer than
|
||||
width, keep only the *end* of the value */
|
||||
if (txtlen >= win_width)
|
||||
Strcpy(status_vals_long[BL_VERS],
|
||||
eos((char *) text) - win_width);
|
||||
else
|
||||
Sprintf(status_vals_long[BL_VERS],
|
||||
"%*s%s", win_width - txtlen, " ", text);
|
||||
} else if ((fldidx == BL_HUNGER || fldidx == BL_CAP) && *text) {
|
||||
/* hunger and enbumbrance are shown side-by-side in
|
||||
a 26 character or wider window; if leading space is
|
||||
|
||||
Reference in New Issue
Block a user