]> granicus.if.org Git - nethack/commitdiff
Qt extended command "rest"
authorPatR <rankin@nethack.org>
Mon, 12 Apr 2021 00:53:57 +0000 (17:53 -0700)
committerPatR <rankin@nethack.org>
Mon, 12 Apr 2021 00:53:57 +0000 (17:53 -0700)
When Qt's extended command selection dialog is set for all commands
or all normal mode commands, it displays the "#wait" command as
"wait (rest)".  Picking by mouse is straightforward; the extra text
on the button has no effect.  Picking by typing "#wa" will choose it;
there aren't any other choices matching that so the player never gets
as far as typing 'i'.  This change allows the player to type "#rest"
as an alternate way to choose it.  "#re" matches some other stuff
and the choice is left pending, adding 's' makes it unique but not
explicitly chosen (so still possible to back up), then adding 't'
chooses it.  The core never knows the difference.

win/Qt/qt_xcmd.cpp

index 245d98bd75cc0a2bde6268b74c5952e4be12fdd5..c737a1a289126c97a3e8c2254a746b9c3aa505b4 100644 (file)
@@ -442,6 +442,9 @@ void NetHackQtExtCmdRequestor::Retry()
 // Player who prefers something else can cope by using ESC instead.
 #define KILL_CHAR Ctrl('u')
 
+// used by keyPressEvent() and enableButtons()
+static const QString &rest = "rest"; // informal synonym for "wait"
+
 // Receive the next character of typed input
 void NetHackQtExtCmdRequestor::keyPressEvent(QKeyEvent *event)
 {
@@ -508,10 +511,13 @@ void NetHackQtExtCmdRequestor::keyPressEvent(QKeyEvent *event)
                 uc = tolower(uc);
             promptstr += QChar(uc); // add new char to typed text
         }
-       QString typedstr = promptstr.mid(1); // skip the '#'
-       unsigned matches = 0;
-       unsigned matchindx = 0;
-       for (unsigned i = 0; extcmdlist[i].ef_txt; ++i) {
+        QString typedstr = promptstr.mid(1); // skip the '#'
+        if (typedstr == rest)
+            typedstr = "wait";
+        std::size_t len = typedstr.size();
+        unsigned matches = 0;
+        unsigned matchindx = 0;
+        for (unsigned i = 0; extcmdlist[i].ef_txt; ++i) {
             if (!interesting_command(i, set))
                 continue;
             const QString &cmdtxt = QString(extcmdlist[i].ef_txt);
@@ -537,9 +543,10 @@ void NetHackQtExtCmdRequestor::keyPressEvent(QKeyEvent *event)
         } else if (checkexact) {
             // <return> or <space> without a pending exact match; cancel
             reject();
-        } else if (matches >= 2) {
+        } else if (matches >= 2
+                   || promptstr.midRef(1, len) == rest.leftRef(len)) {
             // update the text-so-far
-           prompt->setText(promptstr);
+            prompt->setText(promptstr);
         } else if (saveexactmatchindx != xcmdNoMatch) {
             // had a pending exact match but typed something other than
             // <return> which didn't yield another match; prompt string
@@ -579,7 +586,10 @@ void NetHackQtExtCmdRequestor::enableButtons()
     // remaining buttons were widened to take the space.  Now the grid is
     // forced to have fixed layout (via stretch settings in constructor).
     for (auto b = buttons.begin(); b != buttons.end(); ++b) {
-        bool showit = ((*b)->text().left(len) == typedstr);
+        const QString &buttext = (*b)->text();
+        bool showit = (buttext.left(len) == typedstr
+                       || (buttext.contains("(rest)")
+                           && typedstr == rest.left(len)));
         (*b)->setVisible(showit);
     }
 }