Qt message [un]highlighting
The Qt interface highlights the last message issued (using a mechanism for selection, as if for copy+paste or similar operation) but it was staying highlighted until another message was eventually given. Having an old message seem to stick around is annoying and is particularly bad when the message is a prompt. If the player's answer doesn't cause a message to be shown then it seems as if the prompt is still pending. This removes the highlighting (by bulk unselecting) once the player gives another input keystroke or mouse click. It would be much better if the selecting/highlighting was for all messages issued since last time highlighting was cleared. Figuring out how to do that correctly is more effort than I want to expend.
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -30,6 +30,9 @@ public:
|
||||
|
||||
void setMap(NetHackQtMapWindow2*);
|
||||
|
||||
bool hilit_mesgs();
|
||||
void unhighlight_mesgs();
|
||||
|
||||
private:
|
||||
QListWidget* list;
|
||||
bool changed;
|
||||
|
||||
Reference in New Issue
Block a user