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.)
This commit is contained in:
PatR
2020-12-07 01:05:37 -08:00
parent 13359648dd
commit 123b6c38a6
2 changed files with 20 additions and 11 deletions
+9 -2
View File
@@ -790,10 +790,17 @@ void NetHackQtBind::qt_getlin(const char *prompt, char *line)
NetHackQtBind::qt_clear_nhwindow(WIN_MESSAGE); NetHackQtBind::qt_clear_nhwindow(WIN_MESSAGE);
} }
// User has typed '#' to begin entering an extended command; core calls us.
int NetHackQtBind::qt_get_ext_cmd() int NetHackQtBind::qt_get_ext_cmd()
{ {
NetHackQtExtCmdRequestor requestor(mainWidget()); NetHackQtExtCmdRequestor *xcmd;
return requestor.get(); int result;
do {
xcmd = new NetHackQtExtCmdRequestor(mainWidget());
result = xcmd->get();
delete xcmd;
} while (result == xcmdNoMatch);
return result;
} }
void NetHackQtBind::qt_number_pad(int) void NetHackQtBind::qt_number_pad(int)
+11 -9
View File
@@ -55,11 +55,10 @@
// [cmd_N] are buttons labelled with command names; clicking returns the // [cmd_N] are buttons labelled with command names; clicking returns the
// index for the name. // index for the name.
// //
// Changing filter or layout returns 0 to caller who then calls us again // Changing filter or layout returns xcmdNoMatch to qt_get_ext_cmd() which
// (current filter and layout are kept in qt_settings so persist); // 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. // 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 // Current grid size with SHELL and SUSPEND enabled is 13x9 for all
// commands, 13x7 for normal mode commands, and 7x4 (when by-column) or // commands, 13x7 for normal mode commands, and 7x4 (when by-column) or
// 4x7 (if by-row) for wizard mode commands. Column counts are hardcoded // 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 // entry 0 is a no-op; don't bother displaying it in the command grid
if (indx == 0 && !strcmp("#", extcmdlist[indx].ef_txt)) if (indx == 0 && !strcmp("#", extcmdlist[indx].ef_txt))
return false; 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 // some commands might have been compiled-out; don't show them
if ((extcmdlist[indx].flags & CMD_NOT_AVAILABLE) != 0) if ((extcmdlist[indx].flags & CMD_NOT_AVAILABLE) != 0)
return false; return false;
@@ -327,8 +329,8 @@ NetHackQtExtCmdRequestor::NetHackQtExtCmdRequestor(QWidget *parent) :
int NetHackQtExtCmdRequestor::Button(int butnum) int NetHackQtExtCmdRequestor::Button(int butnum)
{ {
// 0..3 are control buttons, 4..N+3 are choice buttons. // 0..3 are control buttons, 4..N+3 are choice buttons.
// Widget return value is -1 for cancel (via reject), // Widget return value is -1 for cancel (via reject), xcmdNoMatch
// 0 for filter, layout, reset (via accept if circumstances warrant), // for filter, layout, reset (via accept if circumstances warrant),
// 1..N for command choices (choice 0 is '#' and it isn't shown as // 1..N for command choices (choice 0 is '#' and it isn't shown as
// a candidate since picking it is not useful). // a candidate since picking it is not useful).
switch (butnum) { switch (butnum) {
@@ -419,11 +421,11 @@ void NetHackQtExtCmdRequestor::Retry()
// remember the current settings; they'll persist until changed again // remember the current settings; they'll persist until changed again
qt_settings->updateXcmd(byRow, set); 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; // 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(xcmdNoMatch);
setResult(0);
accept(); accept();
/*NOTREACHED*/
} }
#define Ctrl(c) (0x1f & (c)) /* ASCII */ #define Ctrl(c) (0x1f & (c)) /* ASCII */