]> granicus.if.org Git - nethack/commitdiff
Qt prompt responses in message window
authorPatR <rankin@nethack.org>
Mon, 31 Aug 2020 07:30:36 +0000 (00:30 -0700)
committerPatR <rankin@nethack.org>
Mon, 31 Aug 2020 07:30:36 +0000 (00:30 -0700)
When Qt issues a prompt string in the message window, update it
with the player's response once that has been obtained.

doc/fixes37.0
win/Qt/qt_bind.cpp
win/Qt/qt_msg.cpp
win/Qt/qt_msg.h

index d0d6e975f8bb1c77a9218d798c9c592424c4b443..b28eb8afcd7c1007b2382183d726e50cc8ca839f 100644 (file)
@@ -1,4 +1,4 @@
-NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.293 $ $NHDT-Date: 1598852985 2020/08/31 05:49:45 $
+NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.294 $ $NHDT-Date: 1598859031 2020/08/31 07:30:31 $
 
 General Fixes and Modified Features
 -----------------------------------
@@ -394,6 +394,8 @@ 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: update message window's last message with player's response if it's a
+       prompt string for a single-character of input (ynaq or invent letter)
 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"
index e6492aaea9f1ceaa6d1afaf6532cdd2d3a3e3016..76028c65a101812b00d283c86e7214aec781d3ad 100644 (file)
@@ -524,7 +524,8 @@ int NetHackQtBind::qt_doprev_message()
     return 0;
 }
 
-char NetHackQtBind::qt_yn_function(const char *question_, const char *choices, CHAR_P def)
+char NetHackQtBind::qt_yn_function(const char *question_,
+                                   const char *choices, CHAR_P def)
 {
     QString question(QString::fromLatin1(question_));
     QString message;
@@ -548,6 +549,8 @@ char NetHackQtBind::qt_yn_function(const char *question_, const char *choices, C
        // Similar to X11 windowport `slow' feature.
 
        int result = -1;
+        char cbuf[40];
+        cbuf[0] = '\0';
 
 #ifdef USE_POPUPS
         if (choices) {
@@ -575,21 +578,34 @@ char NetHackQtBind::qt_yn_function(const char *question_, const char *choices, C
        NetHackQtBind::qt_putstr(WIN_MESSAGE, ATR_BOLD, message);
 
        while (result < 0) {
+            cbuf[0] = '\0';
            char ch=NetHackQtBind::qt_nhgetch();
            if (ch=='\033') {
                result=yn_esc_map;
+                Strcpy(cbuf, "ESC");
            } else if (choices && !strchr(choices,ch)) {
                if (def && (ch==' ' || ch=='\r' || ch=='\n')) {
                    result=def;
+                    Strcpy(cbuf, visctrl(def));
                } else {
                    NetHackQtBind::qt_nhbell();
                    // and try again...
                }
            } else {
                result=ch;
+                Strcpy(cbuf, (ch == ' ') ? "SPC" : visctrl(ch));
            }
        }
 
+        // if answer was supplied via popup, it will already be appended
+        // to the prompt, so included above, and cbuf[] will be empty
+        if (cbuf[0]) {
+            NetHackQtWindow *window = id_to_window[WIN_MESSAGE];
+            NetHackQtMessageWindow *mesgwin
+                = static_cast <NetHackQtMessageWindow *> (window);
+            mesgwin->AddToStr(cbuf);
+        }
+
        NetHackQtBind::qt_clear_nhwindow(WIN_MESSAGE);
 
        return result;
index dcb643efb692d10a3c879cff294504dc2f74ef88..abde5c179e35d5be39d716b3a9ba82fda9f1fc8b 100644 (file)
@@ -62,7 +62,10 @@ void NetHackQtMessageWindow::Scroll(int dx UNUSED, int dy UNUSED)
 
 void NetHackQtMessageWindow::Clear()
 {
-    if ( map )
+    if (list)
+        NetHackQtMessageWindow::unhighlight_mesgs();
+
+    if (map)
        map->clearMessages();
 }
 
@@ -146,6 +149,16 @@ void NetHackQtMessageWindow::PutStr(int attr, const QString& text)
        map->putMessage(attr, text2);
 }
 
+// append the user's answer to a prompt message
+void NetHackQtMessageWindow::AddToStr(const char *answer)
+{
+    if (list) {
+        QListWidgetItem *item = list->currentItem();
+        if (item)
+            item->setText(item->text() + QString(" %1").arg(answer));
+    }
+}
+
 // are there any highlighted messages?
 bool NetHackQtMessageWindow::hilit_mesgs()
 {
index 1aa2b94c8a056db745c73b47acbb5560fad16840..c3cd4275c687e78158cad8f902a23ea80e2e2501 100644 (file)
@@ -32,6 +32,8 @@ public:
 
         bool hilit_mesgs();
         void unhighlight_mesgs();
+        // for adding the answer for yn() to its prompt string
+        void AddToStr(const char *answerbuf);
 
 private:
        QListWidget* list;