From 018d838eb902534907a07ae7f79f397884b7b3a3 Mon Sep 17 00:00:00 2001 From: PatR Date: Tue, 24 Nov 2020 09:45:55 -0800 Subject: [PATCH] today's Qt status update: non-standard conditions Qt's status highlighting was treating any change to hunger or to encumbrance as "worse" (shown in red). That's wrong if you go from weak to just hungry or from stressed to encumbered. Comparing satiated with other hunger states is tricky. I've ranked it between hungry and weak but that's fairly arbitrary. Also, change the highlighting when Lev, Fly, and Ride are new conditions from red to blue. --- win/Qt/qt_icon.cpp | 19 +++++++-------- win/Qt/qt_stat.cpp | 60 +++++++++++++++++++++++++++++++++++----------- win/Qt/qt_stat.h | 7 +++--- 3 files changed, 57 insertions(+), 29 deletions(-) diff --git a/win/Qt/qt_icon.cpp b/win/Qt/qt_icon.cpp index 4076fc65d..b8f0e694d 100644 --- a/win/Qt/qt_icon.cpp +++ b/win/Qt/qt_icon.cpp @@ -133,19 +133,16 @@ void NetHackQtLabelledIcon::setFont(const QFont& f) if (label) label->setFont(f); } -// [pr] this might no longer be needed; it seems to have been responsible -// for highlighting the blank space where an optional field like Score -// was just toggled off; we don't need or want that anymore... +// used to highlight status conditions going from Off (blank) to On as "Worse" void NetHackQtLabelledIcon::show() { - if ( -#if QT_VERSION >= 300 - isHidden() -#else - !isVisible() -#endif - && comp_mode != NoCompare) - highlight(hl_worse); + // Hunger and Encumbrance are worse when going from not shown + // to anything and they're set to SmallerIsBetter, so both + // BiggerIsBetter and SmallerIsBetter warrant hl_worse here. + // Fly, Lev, and Ride are set NeitherIsBetter so that when + // they appear they won't be classified as worse. + if (isHidden() && comp_mode != NoCompare) + highlight((comp_mode != NeitherIsBetter) ? hl_worse : hl_changd); QWidget::show(); } diff --git a/win/Qt/qt_stat.cpp b/win/Qt/qt_stat.cpp index dbd011d1e..88a6cfa8c 100644 --- a/win/Qt/qt_stat.cpp +++ b/win/Qt/qt_stat.cpp @@ -718,24 +718,45 @@ void NetHackQtStatusWindow::updateStats() boolean spreadout = (::iflags.wc2_statuslines != 2); int k = 0; // number of conditions shown - const char* hung=hu_stat[u.uhs]; + long qt_uhs = 0L; + const char *hung = hu_stat[u.uhs]; if (hung[0]==' ') { - hunger.hide(); + if (!hunger.isHidden()) { + hunger.setLabel("", NetHackQtLabelledIcon::NoNum, qt_uhs); + hunger.hide(); + } } else { + // satiated is worse (due to risk of death from overeating) + // than not-hungry and we'll treat it as also worse than hungry, + // but better than weak or fainting; the u.uhs enum values + // order them differently so we jump through a hoop + switch (u.uhs) { + case NOT_HUNGRY: qt_uhs = 0L; break; + case HUNGRY: qt_uhs = 1L; break; + case SATIATED: qt_uhs = 2L; break; + case WEAK: qt_uhs = 3L; break; + case FAINTING: qt_uhs = 4L; break; + default: qt_uhs = 5L; break; // fainted, starved + } hunger.setIcon(u.uhs ? p_hungry : p_satiated); - hunger.setLabel(hung); + hunger.setLabel(hung, NetHackQtLabelledIcon::NoNum, qt_uhs); hunger.ForceResize(); ++k, hunger.show(); } - const char *enc = enc_stat[near_capacity()]; + long encindx = (long) near_capacity(); + const char *enc = enc_stat[encindx]; if (enc[0]==' ' || !enc[0]) { - encumber.hide(); + if (!encumber.isHidden()) { + encumber.setLabel("", NetHackQtLabelledIcon::NoNum, encindx); + encumber.hide(); + } } else { - encumber.setIcon(p_encumber[near_capacity() - 1]); - encumber.setLabel(enc); + encumber.setIcon(p_encumber[encindx - 1]); + encumber.setLabel(enc, NetHackQtLabelledIcon::NoNum, encindx); encumber.ForceResize(); ++k, encumber.show(); } + if (Stoned) ++k, stoned.show(); else stoned.hide(); if (Slimed) ++k, slimed.show(); else slimed.hide(); if (Strangled) ++k, strngld.show(); else strngld.hide(); @@ -917,12 +938,13 @@ void NetHackQtStatusWindow::updateStats() if (first_set) { first_set=false; - was_polyd = Upolyd ? true : false; - had_exp = ::flags.showexp ? true : false; - had_score = ::flags.showscore ? true : false; - + /* + * Default compareMode is BiggerIsBetter: an increased value + * is an improvement. + */ name.highlightWhenChanging(); - dlevel.highlightWhenChanging(); dlevel.setCompareMode(NeitherIsBetter); + dlevel.highlightWhenChanging(); + dlevel.setCompareMode(NeitherIsBetter); str.highlightWhenChanging(); dex.highlightWhenChanging(); @@ -933,7 +955,8 @@ void NetHackQtStatusWindow::updateStats() hp.highlightWhenChanging(); power.highlightWhenChanging(); - ac.highlightWhenChanging(); ac.setCompareMode(SmallerIsBetter); + ac.highlightWhenChanging(); + ac.setCompareMode(SmallerIsBetter); level.highlightWhenChanging(); gold.highlightWhenChanging(); @@ -942,10 +965,13 @@ void NetHackQtStatusWindow::updateStats() //time.highlightWhenChanging(); time.setCompareMode(NeitherIsBetter); score.highlightWhenChanging(); - align.highlightWhenChanging(); align.setCompareMode(NeitherIsBetter); + align.highlightWhenChanging(); + align.setCompareMode(NeitherIsBetter); hunger.highlightWhenChanging(); + hunger.setCompareMode(SmallerIsBetter); encumber.highlightWhenChanging(); + encumber.setCompareMode(SmallerIsBetter); stoned.highlightWhenChanging(); slimed.highlightWhenChanging(); strngld.highlightWhenChanging(); @@ -956,9 +982,15 @@ void NetHackQtStatusWindow::updateStats() hallu.highlightWhenChanging(); blind.highlightWhenChanging(); deaf.highlightWhenChanging(); + // the default behavior is to highlight a newly shown condition + // as "worse" but that isn't appropriate for 'other' conds; + // NetHackQtLabelledIcon::show() uses NeitherIsBetter to handle it lev.highlightWhenChanging(); + lev.setCompareMode(NeitherIsBetter); fly.highlightWhenChanging(); + fly.setCompareMode(NeitherIsBetter); ride.highlightWhenChanging(); + ride.setCompareMode(NeitherIsBetter); } } diff --git a/win/Qt/qt_stat.h b/win/Qt/qt_stat.h index a24028569..c09fae6c4 100644 --- a/win/Qt/qt_stat.h +++ b/win/Qt/qt_stat.h @@ -135,14 +135,13 @@ private: QFrame vline2; // for statuslines:2, padding between Gold and Time int cursy; - bool first_set; bool alreadyfullhp; + + // for some fields, we need to know more than just "changed since + // last update"; there's no 'had_time' because Time isn't highlighted bool was_polyd; bool had_exp; - // Time isn't highlighted (due to constantly changing) so we don't - // keep track of whether it was On and is now Off or vice versa - //bool had_time; bool had_score; QHBoxLayout *InitHitpointBar();