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:
@@ -20,6 +20,7 @@
|
||||
// varying number of icons (one or more, each paired with...)
|
||||
// corresponding text (Alignment plus zero or more status conditions
|
||||
// including Hunger if not "normal" and encumbrance if not "normal")
|
||||
// and version description (text only) right justified (when enabled)
|
||||
//
|
||||
// The hitpoint bar spans the width of the status window when enabled.
|
||||
// Title and location are centered.
|
||||
@@ -64,6 +65,10 @@
|
||||
// Hungry similar but with a slightly concave belly, Weak either a
|
||||
// collapsing figure or a much larger concavity or both, Fainting/
|
||||
// Fainted a fully collapsed figure.
|
||||
// If 'version' is being shown but gets squeezed by the cumulative width
|
||||
// of conditions, the default clipping shows the center portion of the
|
||||
// text string with beginning and end omitted. We want to force the
|
||||
// end of the string to be shown with only the beginning omitted.
|
||||
//
|
||||
// TODO:
|
||||
// If/when status conditions become too wide for the status window, scale
|
||||
@@ -138,6 +143,7 @@ NetHackQtStatusWindow::NetHackQtStatusWindow() :
|
||||
lev(this,"Lev"), // 'other' conditions
|
||||
fly(this,"Fly"),
|
||||
ride(this,"Ride"),
|
||||
vers(this,""), // optional, right justified after 'conditions'
|
||||
hline1(this), // separators
|
||||
hline2(this),
|
||||
hline3(this),
|
||||
@@ -149,7 +155,8 @@ NetHackQtStatusWindow::NetHackQtStatusWindow() :
|
||||
alreadyfullhp(false),
|
||||
was_polyd(false),
|
||||
had_exp(false),
|
||||
had_score(false)
|
||||
had_score(false),
|
||||
prev_versinfo(0U)
|
||||
{
|
||||
if (!qt_compact_mode) {
|
||||
int w = NetHackQtBind::mainWidget()->width();
|
||||
@@ -195,6 +202,8 @@ NetHackQtStatusWindow::NetHackQtStatusWindow() :
|
||||
p_fly = QPixmap(fly_xpm);
|
||||
p_ride = QPixmap(ride_xpm);
|
||||
|
||||
p_vers = QPixmap(blank_xpm); // same all-background pixmap as blank2
|
||||
|
||||
str.setIcon(p_str, "strength");
|
||||
dex.setIcon(p_dex, "dexterity");
|
||||
con.setIcon(p_con, "constitution");
|
||||
@@ -221,6 +230,8 @@ NetHackQtStatusWindow::NetHackQtStatusWindow() :
|
||||
fly.setIcon(p_fly, "flying");
|
||||
ride.setIcon(p_ride, "riding");
|
||||
|
||||
vers.setIcon(p_vers); // used to align text-only version with conditions
|
||||
|
||||
// separator lines
|
||||
#if __cplusplus >= 202002L
|
||||
hline1.setFrameStyle(static_cast<int>(QFrame::HLine)
|
||||
@@ -251,7 +262,7 @@ NetHackQtStatusWindow::NetHackQtStatusWindow() :
|
||||
vline2.setLineWidth(1);
|
||||
vline2.hide(); // padding to keep row 2 aligned with row 1, never shown
|
||||
|
||||
// set up last but shown first (above name) via layout below */
|
||||
// when 'hitpointbar' is On, the bar gets drawn above name/title
|
||||
QHBoxLayout *hpbar = InitHitpointBar();
|
||||
|
||||
// 'statuslines' takes a value of 2 or 3; we use 3 as a request to put
|
||||
@@ -342,7 +353,15 @@ NetHackQtStatusWindow::NetHackQtStatusWindow() :
|
||||
condbox->addWidget(&lev);
|
||||
condbox->addWidget(&fly);
|
||||
condbox->addWidget(&ride);
|
||||
condbox->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
condbox->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
// left justify conditions, whether 'vers' is present or absent
|
||||
int stretch = 0;
|
||||
condbox->addStretch(++stretch); // stretch==1
|
||||
// to right justify 'vers', use bigger stretch than condbox separator
|
||||
condbox->addWidget(&vers, ++stretch, // stretch==2
|
||||
// text is below a blank icon, so bottom-aligned with the rest
|
||||
// of the line with its text centered within that bottom area
|
||||
Qt::AlignRight | Qt::AlignVCenter);
|
||||
vbox->addLayout(condbox);
|
||||
setLayout(vbox);
|
||||
#endif
|
||||
@@ -396,6 +415,7 @@ void NetHackQtStatusWindow::doUpdate()
|
||||
lev.setFont(normal);
|
||||
fly.setFont(normal);
|
||||
ride.setFont(normal);
|
||||
vers.setFont(normal); // shouldn't need small font
|
||||
|
||||
updateStats();
|
||||
}
|
||||
@@ -496,6 +516,11 @@ void NetHackQtStatusWindow::resizeEvent(QResizeEvent*)
|
||||
lev.setGeometry(x,y,iw,lh); x+=iw;
|
||||
fly.setGeometry(x,y,iw,lh); x+=iw;
|
||||
ride.setGeometry(x,y,iw,lh); x+=iw;
|
||||
#if 0
|
||||
// [not fully implemented; this big chunk of code is no longer used]
|
||||
//X = [get version, set font, measure width of version string]
|
||||
vers.setGeometry(width() - X, y, width(), lh); x=width();
|
||||
#endif
|
||||
x=0; y+=lh;
|
||||
#else
|
||||
// This is clumsy. But QLayout objects are proving balky.
|
||||
@@ -540,6 +565,7 @@ void NetHackQtStatusWindow::fadeHighlighting()
|
||||
|
||||
//time.dissipateHighlight();
|
||||
score.dissipateHighlight();
|
||||
//vers.dissipateHighlight(); // never gets highlighted
|
||||
|
||||
hunger.dissipateHighlight();
|
||||
encumber.dissipateHighlight();
|
||||
@@ -813,6 +839,21 @@ void NetHackQtStatusWindow::updateStats()
|
||||
if (Flying) ++k, fly.show(); else fly.hide();
|
||||
if (u.usteed) ++k, ride.show(); else ride.hide();
|
||||
|
||||
// version is optional; displayed to the right of conditions when present
|
||||
if (::flags.showvers) {
|
||||
// the value only changes if user modifies the 'versinfo' option
|
||||
if (::flags.versinfo != prev_versinfo) {
|
||||
char vbuf[80], *cvers = status_version(vbuf, sizeof vbuf, FALSE);
|
||||
vers.setLabel(QString(cvers));
|
||||
// FIXME: this shouldn't be necessary but without hide() before
|
||||
// forthcoming show(), the new value isn't appearing
|
||||
if (!vers.isHidden()) vers.hide();
|
||||
prev_versinfo = ::flags.versinfo;
|
||||
}
|
||||
++k, vers.show();
|
||||
} else
|
||||
vers.hide();
|
||||
|
||||
if (Upolyd) {
|
||||
buf = nh_capitalize_words(pmname(&mons[u.umonnum],
|
||||
::flags.female ? FEMALE : MALE));
|
||||
@@ -929,6 +970,7 @@ void NetHackQtStatusWindow::updateStats()
|
||||
} else {
|
||||
time.setLabel("");
|
||||
}
|
||||
|
||||
#ifdef SCORE_ON_BOTL
|
||||
int score_toggled = !had_score ^ !::flags.showscore;
|
||||
if (::flags.showscore) {
|
||||
@@ -1023,6 +1065,9 @@ void NetHackQtStatusWindow::updateStats()
|
||||
fly.setCompareMode(NeitherIsBetter);
|
||||
ride.highlightWhenChanging();
|
||||
ride.setCompareMode(NeitherIsBetter);
|
||||
// not a true status condition; doesn't change (unless 'showvers'
|
||||
// gets toggled or 'versinfo' is modified) so doesn't get highlighted
|
||||
vers.setCompareMode(NoCompare);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user