]> granicus.if.org Git - nethack/commitdiff
Qt extended command selection
authorPatR <rankin@nethack.org>
Sun, 11 Apr 2021 21:55:45 +0000 (14:55 -0700)
committerPatR <rankin@nethack.org>
Sun, 11 Apr 2021 21:55:45 +0000 (14:55 -0700)
Simplify extended command selection under Qt by allowing the
autocomplete subset be one of the choices for its [filter].  That's
the same subset as X11 uses, where #q is unambiguous for #quit
instead of competing with #quaff and #quiver.

Unlike under X11, the player can use [filter] to switch to the full
command set and get access to a few commands which have no useable
key and aren't flagged to autocomplete.  (Mostly obscure wizard mode
commands but #exploremode is in that situation.)

In normal and explore modes, the [filter] button just toggles between
two sets of commands (all normal mode commands vs autocomplete normal
mode commands).  In wizard mode there are four choices and you might
need to click on [filter] up to three times to step through to the
target one among four sets (all commands, all normal mode commands,
autocomplete commands for both normal and wizard, full subset of just
the wizard mode commands).

doc/fixes37.0
win/Qt/Qt-issues.txt
win/Qt/qt_xcmd.cpp
win/Qt/qt_xcmd.h

index 9609a930b10c5ecad4b70c38786c7c6112a8d6ad..1495a7ae07caefbfbb9ec43c171b05ee832e6622 100644 (file)
@@ -931,6 +931,10 @@ Qt: add Filter, Layout, and Reset buttons to the extended command selector;
        mode only"; Layout redisplays the grid of command buttons, toggling
        from down columns to across rows or vice versa; Reset puts both back
        to their default settings and clears any pending typed input
+Qt: [later] augment extended command selection dialog's Filter to add a
+       fourth subset, those commands which autocomplete when typed for tty,
+       typically commands with no keystroke or only meta character keystroke;
+       that makes Filter useful in normal mode (much shorter list of choices)
 tiles: male and female variations in monsters.txt; tested only with tile2bmp
        conversion utility so far; also supported by tilemap utility to
        generate tile.c
index a7418f984e1b22e2343b092d0c0b4de140507af4..c1c84c1768f5ce844b36b9a4892277b3f5311948 100644 (file)
@@ -59,4 +59,8 @@ The status window can't be resized while hitpointbar is active.
 Toggling it off, resizing as desired, then toggling it back on is a
 viable workaround.
 
+The 'toptenwin' option should probably be forced on, otherwise final
+high scores output gets sent to stdout and might not appear anywhere
+depending on how the program was launched.
+
 -----
index bd9aff6a10b541ba3939944ebe004c5776baf30c..245d98bd75cc0a2bde6268b74c5952e4be12fdd5 100644 (file)
@@ -5,9 +5,6 @@
 // qt_xcmd.cpp -- extended command widget
 //
 // TODO:
-//  Maybe extend filtering to be able to omit commands that can be invoked
-//    by a 'normal' keystroke (not Meta) with current key bindings, or to
-//    exclude commands which don't autocomplete to match '#?'.
 //  Either disable [Layout] when prompt has a partial response, or
 //    preserve that partial response across widget tear-down/rebuild.
 //  Maybe make the number of grid columns user settable?  Or a way to
 //   "#drop[type]", "#known[class]", "#takeoff[all]", "#version[short]");
 //   button is left justitied (prior to addition of the filter/layout/reset
 //   buttons, [Cancel] stretched all the way across the top of the widget);
-// [Filter] is grayed out when outside wizard mode; when in wizard mode,
-//   it cycles through "all commands", "normal mode commands only", and
-//   "wizard mode extra commands only"; [if it ever gets extended to do
-//   anything in normal play, it will need a more substantial interface
-//   than repeated clicks but those seem adequate for present wizard
-//   mode-only usage];
+// [Filter] toggles between normal and autocomplete when playing in normal
+//   or explore mode, cycles through "all", "normal", "autocomplete", and
+//   "wizard mode extra commands only" when playing in wizard mode; that's
+//   kind of clumsy but probably not important enough to implement a more
+//   sophisticated interface;
 // [Layout] toggles between displaying the command buttons down columns
 //   (as shown above) versus across rows ([cmd_1][cmd_2]...[cmd_9], &c);
 // [Reset] clears typed partial response, if any, and sets filtering back
@@ -111,11 +107,10 @@ extern uchar keyValue(QKeyEvent *key_event); // from qt_menu.cpp
 void centerOnMain(QWidget *);
 // end temporary
 
-static inline bool
+static /*inline*/ bool
 interesting_command(unsigned indx, int cmds)
 {
-    if (!WizardMode)
-        cmds = normal_cmds;
+    bool skip_wizard = !WizardMode || cmds == normal_cmds;
 
     // entry 0 is a no-op; don't bother displaying it in the command grid
     if (indx == 0 && !strcmp("#", extcmdlist[indx].ef_txt))
@@ -128,9 +123,15 @@ interesting_command(unsigned indx, int cmds)
         return false;
     // if picking from normal mode-only don't show wizard mode commands
     // or if picking from wizard mode-only don't show normal commands
-    if ((cmds == normal_cmds && (extcmdlist[indx].flags & WIZMODECMD) != 0)
+    if ((skip_wizard && (extcmdlist[indx].flags & WIZMODECMD) != 0)
      || (cmds == wizard_cmds && (extcmdlist[indx].flags & WIZMODECMD) == 0))
         return false;
+    // autocomplete subset is essentially the traditional set of extended
+    // commands; many can be invoked by Alt+char but not by ordinary char
+    // or Ctrl+char; [X11's extended command selection uses this subset]
+    if (cmds == autocomplete_cmds
+        && (extcmdlist[indx].flags & AUTOCOMPLETE) == 0)
+        return false;
     // if we've gotten here, this command isn't filtered away, so show it
     return true;
 }
@@ -144,8 +145,8 @@ NetHackQtExtCmdRequestor::NetHackQtExtCmdRequestor(QWidget *parent) :
     butoffset(0),
     exactmatchindx(xcmdNoMatch)
 {
-    if (!WizardMode)
-        set = normal_cmds; // {all,wizard}_cmds are wizard mode only
+    if (!WizardMode && set != normal_cmds)
+        set = autocomplete_cmds; // {all,wizard}_cmds are wizard mode only
 
     QVBoxLayout *xl = new QVBoxLayout(this);  // overall xcmd layout
     int butw = 50; // initial button width; will be increased if too small
@@ -169,6 +170,7 @@ NetHackQtExtCmdRequestor::NetHackQtExtCmdRequestor(QWidget *parent) :
     // Filter: change the [sub]set of commands that get shown;
     // presently only useful when running in wizard mode
     QPushButton *filter_btn = new QPushButton("Filter", this);
+#if 0   /* [later] normal vs autocomplete matters regardless of wizard mode */
     if (!WizardMode) { // nothing to filter if not in wizard mode
         filter_btn->setEnabled(false); // gray the [Filter] button out
 #if 0   /* This works but makes [Reset] seem to be redundant. */
@@ -178,6 +180,7 @@ NetHackQtExtCmdRequestor::NetHackQtExtCmdRequestor(QWidget *parent) :
         filter_btn->hide();
 #endif
     }
+#endif
     filter_btn->setMinimumSize(filter_btn->sizeHint());
     butw = std::max(butw, filter_btn->width());
     ctrls->addWidget(filter_btn);
@@ -199,14 +202,16 @@ NetHackQtExtCmdRequestor::NetHackQtExtCmdRequestor(QWidget *parent) :
     prompt->setFont(qt_settings->normalFixedFont());
 
     // grid title rather than overall popup title
-    const char *ctitle = ((set == all_cmds)
-                          ? "All extended commands"
+    const char *ctitle = ((set == all_cmds) // implies wizard mode
+                          ? "All commands"
                           : (set == normal_cmds)
-                            ? (WizardMode ? "Normal mode extended commands"
-                                          : "Extended commands")
-                            : (set == wizard_cmds)
-                              ? "Debug mode extended commands"
-                              : "(unknown)"); // won't happen
+                            ? (WizardMode ? "Normal mode commands"
+                                          : "Available commands")
+                            : (set == autocomplete_cmds)
+                              ? "Traditional extended commands"
+                              : (set == wizard_cmds)
+                                ? "Debug mode commands"
+                                : "(unknown)"); // won't happen
     const QString &qtitle = QString(ctitle);
     // rectangular grid to hold a button for each extended command name
     QGroupBox *grid = new QGroupBox(); /* new QGroupBox(title, this); */
@@ -264,14 +269,15 @@ NetHackQtExtCmdRequestor::NetHackQtExtCmdRequestor(QWidget *parent) :
 
     /* 'ncols' could be calculated to fit (or enable a vertical scrollbar
        when resulting 'nrows' is too big, if GroupBox supports that);
-       it used to be hardcoded 4 but after every command became accessible
+       it used to be hardcoded 4, but once every command became accessible
        as an extended command, that resulted in so many rows that some of
        the grid was chopped off at the bottom of the screen and the buttons
        in that portion were out of reach */
-    unsigned ncols = (set == all_cmds) ? 9
+    unsigned ncols = (set == all_cmds) ? 8
                      : (set == normal_cmds) ? 7
-                       : (set == wizard_cmds) ? (byRow ? 7 : 4)
-                         : 1; // can't happen
+                       : (set == autocomplete_cmds) ? (WizardMode ? 6 : 5)
+                         : (set == wizard_cmds) ? (byRow ? 6 : 5)
+                           : 1; // can't happen
     unsigned nrows = (ncmds + ncols - 1) / ncols;
     /*
      * Grid layout:  by-column is the default.  Can be toggled by clicking
@@ -367,13 +373,14 @@ void NetHackQtExtCmdRequestor::Cancel()
 // Respond to a click on the [Filter] button
 void NetHackQtExtCmdRequestor::Filter()
 {
-    // TEMP: step from one [sub]set to the next, then wrap back to the first.
-    if (++set > std::max(std::max(all_cmds, normal_cmds), wizard_cmds))
-        set = std::min(std::min(all_cmds, normal_cmds), wizard_cmds);
-
-    // TODO: put up a popup--dialog or maybe simple pick-one menu--that
-    //       has player choose between all_cmds, normal_cmds, wizard_cmds.
-    // Only meaningful for wizard mode so maybe the temp version suffices.
+    do {
+        if (++set > std::max(std::max(all_cmds, normal_cmds),
+                             std::max(autocomplete_cmds, wizard_cmds)))
+            set = std::min(std::min(all_cmds, normal_cmds),
+                           std::min(autocomplete_cmds, wizard_cmds));
+        if (WizardMode)
+            break;
+    } while (set != normal_cmds && set != autocomplete_cmds);
 
     if (set != qt_settings->xcmd_set) {
         Retry();
index 52df63a52c1e9a3023bb049bf12dea2fbd27793c..4820d2d4db282415b5817685a7b73f6998704511 100644 (file)
@@ -9,7 +9,13 @@
 
 namespace nethack_qt_ {
 
-enum xcmdSets { all_cmds = 0, normal_cmds = 1, wizard_cmds = 2 };
+// [Filter] setting; the X11 interface uses the autocomplete list
+enum xcmdSets {
+    all_cmds = 0,           // everything in extcmdlist[]
+    normal_cmds = 1,        // all non-wizard mode commands
+    autocomplete_cmds = 2,  // mostly commands which need Alt+char
+    wizard_cmds = 3         // commands only useable in wizard mode
+};
 enum xcmdMisc { xcmdNone = -10, xcmdNoMatch = 9999 };
 
 class NetHackQtExtCmdRequestor : public QDialog {