From 123b6c38a6b0eb0022ae95f3e01b8d37a0f16b79 Mon Sep 17 00:00:00 2001 From: PatR Date: Mon, 7 Dec 2020 01:05:37 -0800 Subject: [PATCH] Qt extended commands: menu teardown and rebuild Change qt_get_ext_cmd() to handle calling the extended command selection menu again after player clicks on Filter/Layout/Reset instead of relying on the core to do that. (In order to change the menu, instead of attempting to reconfigure that on the fly it returns to caller and then puts up a new menu with different settings when called back. Initial checkin relied on the core for the call back; this maintains full control for that within the Qt interface code.) --- win/Qt/qt_bind.cpp | 11 +++++++++-- win/Qt/qt_xcmd.cpp | 20 +++++++++++--------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/win/Qt/qt_bind.cpp b/win/Qt/qt_bind.cpp index 7969fa5e8..f355bcd31 100644 --- a/win/Qt/qt_bind.cpp +++ b/win/Qt/qt_bind.cpp @@ -790,10 +790,17 @@ void NetHackQtBind::qt_getlin(const char *prompt, char *line) NetHackQtBind::qt_clear_nhwindow(WIN_MESSAGE); } +// User has typed '#' to begin entering an extended command; core calls us. int NetHackQtBind::qt_get_ext_cmd() { - NetHackQtExtCmdRequestor requestor(mainWidget()); - return requestor.get(); + NetHackQtExtCmdRequestor *xcmd; + int result; + do { + xcmd = new NetHackQtExtCmdRequestor(mainWidget()); + result = xcmd->get(); + delete xcmd; + } while (result == xcmdNoMatch); + return result; } void NetHackQtBind::qt_number_pad(int) diff --git a/win/Qt/qt_xcmd.cpp b/win/Qt/qt_xcmd.cpp index 283517beb..686ce0490 100644 --- a/win/Qt/qt_xcmd.cpp +++ b/win/Qt/qt_xcmd.cpp @@ -55,11 +55,10 @@ // [cmd_N] are buttons labelled with command names; clicking returns the // index for the name. // -// Changing filter or layout returns 0 to caller who then calls us again -// (current filter and layout are kept in qt_settings so persist); +// Changing filter or layout returns xcmdNoMatch to qt_get_ext_cmd() which +// then calls us again (current filter and layout are kept in qt_settings +// so persist, not just through return and call back but across games); // much simpler than reorganizing the button grid's contents on the fly. -// [TODO: perform '0 => retry' handling in qt_get_ext_cmd() rather than -// relying on the core to maintain that behavior.] // Current grid size with SHELL and SUSPEND enabled is 13x9 for all // commands, 13x7 for normal mode commands, and 7x4 (when by-column) or // 4x7 (if by-row) for wizard mode commands. Column counts are hardcoded @@ -120,6 +119,9 @@ interesting_command(unsigned indx, int cmds) // entry 0 is a no-op; don't bother displaying it in the command grid if (indx == 0 && !strcmp("#", extcmdlist[indx].ef_txt)) return false; + // treat '?' as both normal mode and debug mode + if (!strcmp("?", extcmdlist[indx].ef_txt)) + return true; // some commands might have been compiled-out; don't show them if ((extcmdlist[indx].flags & CMD_NOT_AVAILABLE) != 0) return false; @@ -327,8 +329,8 @@ NetHackQtExtCmdRequestor::NetHackQtExtCmdRequestor(QWidget *parent) : int NetHackQtExtCmdRequestor::Button(int butnum) { // 0..3 are control buttons, 4..N+3 are choice buttons. - // Widget return value is -1 for cancel (via reject), - // 0 for filter, layout, reset (via accept if circumstances warrant), + // Widget return value is -1 for cancel (via reject), xcmdNoMatch + // for filter, layout, reset (via accept if circumstances warrant), // 1..N for command choices (choice 0 is '#' and it isn't shown as // a candidate since picking it is not useful). switch (butnum) { @@ -419,11 +421,11 @@ void NetHackQtExtCmdRequestor::Retry() // remember the current settings; they'll persist until changed again qt_settings->updateXcmd(byRow, set); - // result 0 means that caller in core will call get_ext_cmd() again; + // return to qt_get_ext_cmd() and have it run ExtCmdRequestor again; // current selection grid will be torn down, then new one created; - // TODO: have qt_get_ext_cmd() handle it instead of relying on core - setResult(0); + setResult(xcmdNoMatch); accept(); + /*NOTREACHED*/ } #define Ctrl(c) (0x1f & (c)) /* ASCII */ -- 2.50.1