Qt status window icon alignment
When the game windows were initialized, the anhk icon for alignment was centered relative to Lawful/Neutral/Chaotic label but during the first status update it noticeably shifted left. Non-blank hunger or encumbrance states could change from centered to left justified when they were present and the icon was replaced. Oddly, resetting the 'centered' attribute for the widget wasn't sufficient to fix this. Running the resize code for that widget did. Another case of trial and error to make things work the way they ought. Also, don't highlight a change in alignment or dungeon location as "got worse" if the internal numeric value went down instead of up; always highlight as "got better" for those two fields. There ought to be a third choice for just "changed" but that would have been more complicated.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.330 $ $NHDT-Date: 1602716771 2020/10/14 23:06:11 $
|
||||
NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.332 $ $NHDT-Date: 1602958104 2020/10/17 18:08:24 $
|
||||
|
||||
General Fixes and Modified Features
|
||||
-----------------------------------
|
||||
@@ -443,6 +443,9 @@ Qt: for menu search, don't require clicking on the search target popup before
|
||||
Qt: rest ("Zz") button on the toolbar only worked when 'rest_on_space' was On
|
||||
(core issue, not Qt's fault)
|
||||
Qt: rename toolbar button "Get" and action menu choice "Get" to "Pick up"
|
||||
Qt: status icons for alignment|hunger|encumbrance which started out centered
|
||||
relative to the label text below them would shift to being left
|
||||
justified when status got updated
|
||||
Qt+OSX: fix control key
|
||||
Qt+OSX: rename menu entry "nethack->Preferences..." for invoking nethack's
|
||||
'O' command to "Game->Run-time options" and entry "Game->Qt settings"
|
||||
|
||||
@@ -52,15 +52,16 @@ void NetHackQtLabelledIcon::setLabel(const QString& t, bool lower)
|
||||
if (!label) {
|
||||
label=new QLabel(this);
|
||||
label->setFont(font());
|
||||
resizeEvent(0);
|
||||
}
|
||||
if (label->text() != t) {
|
||||
label->setText(t);
|
||||
highlight(lower==low_is_good ? hl_good : hl_bad);
|
||||
ForceResize();
|
||||
highlight((lower == low_is_good) ? hl_good : hl_bad);
|
||||
}
|
||||
}
|
||||
|
||||
void NetHackQtLabelledIcon::setLabel(const QString& t, long v, long cv, const QString& tail)
|
||||
void NetHackQtLabelledIcon::setLabel(const QString& t, long v, long cv,
|
||||
const QString& tail)
|
||||
{
|
||||
QString buf;
|
||||
if (v==NoNum) {
|
||||
@@ -72,16 +73,19 @@ void NetHackQtLabelledIcon::setLabel(const QString& t, long v, long cv, const QS
|
||||
prev_value=cv;
|
||||
}
|
||||
|
||||
void NetHackQtLabelledIcon::setLabel(const QString& t, long v, const QString& tail)
|
||||
void NetHackQtLabelledIcon::setLabel(const QString& t, long v,
|
||||
const QString& tail)
|
||||
{
|
||||
setLabel(t,v,v,tail);
|
||||
}
|
||||
|
||||
void NetHackQtLabelledIcon::setIcon(const QPixmap& i)
|
||||
{
|
||||
if (icon) icon->setPixmap(i);
|
||||
else { icon=new QLabel(this); icon->setPixmap(i); resizeEvent(0); }
|
||||
icon->resize(i.width(),i.height());
|
||||
if (!icon)
|
||||
icon = new QLabel(this);
|
||||
icon->setPixmap(i);
|
||||
ForceResize();
|
||||
icon->resize(i.width(), i.height());
|
||||
}
|
||||
|
||||
void NetHackQtLabelledIcon::setFont(const QFont& f)
|
||||
@@ -171,6 +175,13 @@ void NetHackQtLabelledIcon::unhighlight()
|
||||
}
|
||||
}
|
||||
|
||||
// used when label (most status fields) or pixmap (alignment, hunger,
|
||||
// encumbrance) changes value
|
||||
void NetHackQtLabelledIcon::ForceResize()
|
||||
{
|
||||
this->resizeEvent((QResizeEvent *) NULL);
|
||||
}
|
||||
|
||||
void NetHackQtLabelledIcon::resizeEvent(QResizeEvent*)
|
||||
{
|
||||
setAlignments();
|
||||
|
||||
@@ -24,6 +24,7 @@ public:
|
||||
void highlightWhenChanging();
|
||||
void lowIsGood();
|
||||
void dissipateHighlight();
|
||||
void ForceResize();
|
||||
|
||||
virtual void show();
|
||||
virtual QSize sizeHint() const;
|
||||
|
||||
@@ -344,7 +344,7 @@ void NetHackQtStatusWindow::resizeEvent(QResizeEvent*)
|
||||
/*
|
||||
* Set all widget values to a null string. This is used after all spacings
|
||||
* have been calculated so that when the window is popped up we don't get all
|
||||
* kinds of funny values being displayed.
|
||||
* kinds of funny values being displayed. [Actually it isn't used at all.]
|
||||
*/
|
||||
void NetHackQtStatusWindow::nullOut()
|
||||
{
|
||||
@@ -436,6 +436,7 @@ void NetHackQtStatusWindow::updateStats()
|
||||
} else {
|
||||
hunger.setIcon(u.uhs ? p_hungry : p_satiated);
|
||||
hunger.setLabel(hung);
|
||||
hunger.ForceResize();
|
||||
hunger.show();
|
||||
}
|
||||
const char *enc = enc_stat[near_capacity()];
|
||||
@@ -444,6 +445,7 @@ void NetHackQtStatusWindow::updateStats()
|
||||
} else {
|
||||
encumber.setIcon(p_encumber[near_capacity() - 1]);
|
||||
encumber.setLabel(enc);
|
||||
encumber.ForceResize();
|
||||
encumber.show();
|
||||
}
|
||||
if (Stoned) stoned.show(); else stoned.hide();
|
||||
@@ -468,6 +470,7 @@ void NetHackQtStatusWindow::updateStats()
|
||||
if (Stunned) stunned.show(); else stunned.hide();
|
||||
if (Confusion) confused.show(); else confused.hide();
|
||||
if (Hallucination) hallu.show(); else hallu.hide();
|
||||
// [pr - Why is blind handled differently from other on/off conditions?]
|
||||
if (Blind) {
|
||||
blind.setLabel("Blind");
|
||||
blind.show();
|
||||
@@ -490,12 +493,13 @@ void NetHackQtStatusWindow::updateStats()
|
||||
name.setLabel(buf2, NetHackQtLabelledIcon::NoNum, u.ulevel);
|
||||
|
||||
char buf3[BUFSZ];
|
||||
if (describe_level(buf3)) {
|
||||
dlevel.setLabel(buf3,true);
|
||||
} else {
|
||||
buf.sprintf("%s, level ", g.dungeons[u.uz.dnum].dname);
|
||||
dlevel.setLabel(buf,(long)::depth(&u.uz));
|
||||
if (!describe_level(buf3)) {
|
||||
Sprintf(buf3, "%s, level %d",
|
||||
g.dungeons[u.uz.dnum].dname, ::depth(&u.uz));
|
||||
}
|
||||
// false: always highlight as 'change for the better' regardless of
|
||||
// new depth compared to old
|
||||
dlevel.setLabel(buf3, false);
|
||||
|
||||
gold.setLabel("Au:", money_cnt(g.invent));
|
||||
|
||||
@@ -521,13 +525,14 @@ void NetHackQtStatusWindow::updateStats()
|
||||
}
|
||||
buf.sprintf("/%d", u.uenmax);
|
||||
power.setLabel("Pow:", u.uen, buf);
|
||||
ac.setLabel("AC:",(long)u.uac);
|
||||
ac.setLabel("AC:", (long) u.uac);
|
||||
//if (::flags.showexp) {
|
||||
// exp.setLabel("Exp:", (long) u.uexp);
|
||||
//} else {
|
||||
// 'exp' now only used to pad the line that Xp/Exp is displayed on
|
||||
// 'exp' is now only used to pad the line that Xp/Exp is displayed on
|
||||
exp.setLabel("");
|
||||
//}
|
||||
text = NULL;
|
||||
if (u.ualign.type==A_CHAOTIC) {
|
||||
align.setIcon(p_chaotic);
|
||||
text = "Chaotic";
|
||||
@@ -538,7 +543,14 @@ void NetHackQtStatusWindow::updateStats()
|
||||
align.setIcon(p_lawful);
|
||||
text = "Lawful";
|
||||
}
|
||||
align.setLabel(text);
|
||||
if (text) {
|
||||
// false: don't highlight as 'became lower' even if the internal
|
||||
// numeric value is becoming lower (N -> C, L -> N || C)
|
||||
align.setLabel(text, false);
|
||||
// without this, the ankh pixmap shifts from centered to left
|
||||
// justified relative to the label text for some unknown reason...
|
||||
align.ForceResize();
|
||||
}
|
||||
|
||||
if (::flags.time)
|
||||
time.setLabel("Time:", (long) g.moves);
|
||||
|
||||
Reference in New Issue
Block a user