change program_state.getting_a_command

to program_state.input_state

Rename program_state.getting_a_command and give it an int value
instead of treating it as boolean.  Start using to it for Qt to
suppress commands initiated from the drop down menus in the title bar
if nethack isn't expecting to get a command from the user.  Those menu
choices inject extended command text into the input stream and should
be avoided when entering text or waiting for a menu to be dismissed.

These menus would be better if they grayed out unavailable choices
when pulled down instead of accepting any choice and then treating
that no good.  I'm not going to try to figure out to do that with Qt.
And this workaround for the menus doesn't have any affect on the
toolbar buttons below the title bar.  Those execute core commands
directly and when I tried to use jacket routines instead, the tool bar
stopped showing up so I've given up.

This won't fix the reported problem of getting stuck in a loop.
This commit is contained in:
PatR
2023-04-06 01:56:08 -07:00
parent 4927527493
commit 0d31bb8c88
6 changed files with 68 additions and 22 deletions

View File

@@ -459,7 +459,8 @@ aboutMsg()
char *p, vbuf[BUFSZ];
/* nethack's getversionstring() includes a final period
but we're using it mid-sentence so strip period off */
if ((p = strrchr(::getversionstring(vbuf, sizeof vbuf), '.')) != 0 && *(p + 1) == '\0')
if ((p = strrchr(::getversionstring(vbuf, sizeof vbuf), '.')) != 0
&& *(p + 1) == '\0')
*p = '\0';
/* it's also long; break it into two pieces */
(void) strsubst(vbuf, " - ", "\n- ");
@@ -1001,8 +1002,30 @@ public:
};
#endif
/* used by doMenuItem() and for the toolbar buttons */
bool NetHackQtMainWindow::ok_for_command()
{
/*
* If the core expects text to be entered (perhaps typing in a wish,
* assigning a name to something, or answering a y/n prompt), or a
* map position or a direction is being picked, don't accept commands
* from the toolbar.
*
* FIXME: it would be much better to gray-out inapplicable entries
* when popping up a command menu instead of needing this.
*/
if (::gp.program_state.input_state != commandInp) {
NetHackQtBind::qt_nhbell();
// possibly call doKeys("\033"); here?
return false;
}
return true;
}
void NetHackQtMainWindow::doMenuItem(QAction *action)
{
if (!ok_for_command())
return;
/* this converts meta characters to '?'; menu processing has been
changed to send multi-character "#abc" instead (already needed
for commands that didn't have either a regular keystroke or a