diff --git a/doc/fixes37.0 b/doc/fixes37.0 index a5579a86c..d0d6e975f 100644 --- a/doc/fixes37.0 +++ b/doc/fixes37.0 @@ -1,4 +1,4 @@ -NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.292 $ $NHDT-Date: 1598831076 2020/08/30 23:44:36 $ +NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.293 $ $NHDT-Date: 1598852985 2020/08/31 05:49:45 $ General Fixes and Modified Features ----------------------------------- @@ -393,6 +393,7 @@ Qt: tombstone showed newly constructed date instead of the value set up at Qt: menu choices All, None, Invert were setting, unsetting, or toggling menu entry checkboxes internally but didn't redraw the menu to show that Qt: fix the F1/F2/Tab macro keys to not require that number_pad be On +Qt: unhighlight highlighted message (last one issued) after player has seen it Qt+QSX: 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" diff --git a/win/Qt/qt_bind.cpp b/win/Qt/qt_bind.cpp index 7e849b77b..e6492aaea 100644 --- a/win/Qt/qt_bind.cpp +++ b/win/Qt/qt_bind.cpp @@ -471,7 +471,7 @@ void NetHackQtBind::qt_raw_print_bold(const char *str) int NetHackQtBind::qt_nhgetch() { if (main) - main->fadeHighlighting(); + main->fadeHighlighting(true); // Process events until a key arrives. // @@ -479,19 +479,28 @@ int NetHackQtBind::qt_nhgetch() qApp->exec(); } + // after getting a key rather than before + if (main) + main->fadeHighlighting(false); + return keybuffer.GetAscii(); } int NetHackQtBind::qt_nh_poskey(int *x, int *y, int *mod) { if (main) - main->fadeHighlighting(); + main->fadeHighlighting(true); // Process events until a key or map-click arrives. // while (keybuffer.Empty() && clickbuffer.Empty()) { qApp->exec(); } + + // after getting a key or click rather than before + if (main) + main->fadeHighlighting(false); + if (!keybuffer.Empty()) { return keybuffer.GetAscii(); } else { diff --git a/win/Qt/qt_main.cpp b/win/Qt/qt_main.cpp index ca32f1e4a..e57a1a8e1 100644 --- a/win/Qt/qt_main.cpp +++ b/win/Qt/qt_main.cpp @@ -751,7 +751,7 @@ NetHackQtMainWindow::NetHackQtMainWindow(NetHackQtKeyBuffer& ks) : the application menu instead of the help menu; we'll add it to the latter now and have two ways to access it; without the leading underscore (or some other spelling variation such as - "'bout"), this one would get interceptd too and then evidently + "'bout"), this one would get intercepted too and then evidently be discarded as a duplicate */ help->addSeparator(); help->addAction("_About_Qt_NetHack_", this, SLOT(doAbout(bool))); @@ -1042,10 +1042,16 @@ void NetHackQtMainWindow::updateInventory() } } -void NetHackQtMainWindow::fadeHighlighting() +void NetHackQtMainWindow::fadeHighlighting(bool before_key) { - if (status) { - status->fadeHighlighting(); + if (before_key) { + // status highlighting fades at start of turn + if (status) + status->fadeHighlighting(); + } else { + // message highlighting fades after user has given input + if (message && message->hilit_mesgs()) + message->unhighlight_mesgs(); } } diff --git a/win/Qt/qt_main.h b/win/Qt/qt_main.h index f043c619f..fbec9fb63 100644 --- a/win/Qt/qt_main.h +++ b/win/Qt/qt_main.h @@ -47,7 +47,7 @@ public: void RemoveWindow(NetHackQtWindow* window); void updateInventory(); - void fadeHighlighting(); + void fadeHighlighting(bool before_key); // this is unconditional in case qt_main.h comes before qt_set.h void resizePaperDoll(bool); // ENHANCED_PAPERDOLL diff --git a/win/Qt/qt_map.cpp b/win/Qt/qt_map.cpp index eb497da86..2e507e691 100644 --- a/win/Qt/qt_map.cpp +++ b/win/Qt/qt_map.cpp @@ -582,12 +582,16 @@ void NetHackQtMapWindow2::clearMessages() void NetHackQtMapWindow2::putMessage(int attr UNUSED, const QString& text) { - if ( !messages.isEmpty() ) + if (!messages.isEmpty()) messages += "\n"; messages += QString(text).replace(QChar(0x200B), ""); - QFontMetrics fm = fontMetrics(); #if 0 - messages_rect = fm.boundingRect(viewport.contentsX(),viewport.contentsY(),viewport.width(),0, Qt::TextWordWrap|Qt::AlignTop|Qt::AlignLeft|Qt::TextDontClip, messages); + QFontMetrics fm = fontMetrics(); + messages_rect = fm.boundingRect(viewport.contentsX(), viewport.contentsY(), + viewport.width(), 0, + (Qt::TextWordWrap | Qt::AlignTop + | Qt::AlignLeft | Qt::TextDontClip), + messages); update(messages_rect); #endif } diff --git a/win/Qt/qt_msg.cpp b/win/Qt/qt_msg.cpp index aee2ea135..dcb643efb 100644 --- a/win/Qt/qt_msg.cpp +++ b/win/Qt/qt_msg.cpp @@ -74,6 +74,9 @@ void NetHackQtMessageWindow::ClearMessages() void NetHackQtMessageWindow::Display(bool block UNUSED) { + // + // FIXME: support for 'block' is necessary for MSGTYPE=stop + // if (changed) { list->repaint(); changed=false; @@ -88,8 +91,9 @@ const char * NetHackQtMessageWindow::GetStr(bool init) QListWidgetItem *item = list->item(currgetmsg++); if (item) { QString str = item->text(); - //raw_printf("getstr[%i]='%s'", currgetmsg, str.toLatin1().constData()); - return str.toLatin1().constData(); + const char *result = str.toLatin1().constData(); + //raw_printf("getstr[%d]='%s'", currgetmsg, result); + return result; } return NULL; } @@ -114,31 +118,52 @@ void NetHackQtMessageWindow::PutStr(int attr, const QString& text) font.setWeight((attr == ATR_BOLD) ? QFont::Bold : QFont::Normal); item->setFont(font); - QColor fg = item->foreground().color(); - QColor bg = item->background().color(); - if (attr == ATR_DIM) - { - fg.setAlpha(fg.alpha() / 2); + if (attr == ATR_DIM || attr == ATR_INVERSE) { + QColor fg = item->foreground().color(); + QColor bg = item->background().color(); + if (attr == ATR_DIM) { + fg.setAlpha(fg.alpha() / 2); + new_fgbg = true; + } + if (attr == ATR_INVERSE) { + QColor swap; + swap = fg; fg = bg; bg = swap; + } + item->setForeground(fg); + item->setBackground(bg); } - if (attr == ATR_INVERSE) - { - QColor swap; - swap = fg; fg = bg; bg = swap; - } - item->setForeground(fg); - item->setBackground(bg); + // ATR_BLINK not supported #endif - // ATR_BLINK not supported if (list->count() >= (int) ::iflags.msg_history) delete list->item(0); list->addItem(text2); // Force scrollbar to bottom - list->setCurrentRow(list->count()-1); + list->setCurrentRow(list->count() - 1); - if ( map ) + if (map) map->putMessage(attr, text2); } +// are there any highlighted messages? +bool NetHackQtMessageWindow::hilit_mesgs() +{ + // PutStr() uses setCurrentRow() to select the last message line; + // being selected causes that line to be highlighted. + // + // We could/should keep track of whether anything is currently + // highlighted instead of just assuming that last message still is. + if (list && list->count()) + return true; + return false; +} + +// unhighlight any highlighted messages +void NetHackQtMessageWindow::unhighlight_mesgs() +{ + if (list) + list->clearSelection(); +} + } // namespace nethack_qt_ diff --git a/win/Qt/qt_msg.h b/win/Qt/qt_msg.h index 08c029b9b..1aa2b94c8 100644 --- a/win/Qt/qt_msg.h +++ b/win/Qt/qt_msg.h @@ -30,6 +30,9 @@ public: void setMap(NetHackQtMapWindow2*); + bool hilit_mesgs(); + void unhighlight_mesgs(); + private: QListWidget* list; bool changed;