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:
40
src/cmd.c
40
src/cmd.c
@@ -5209,7 +5209,7 @@ getdir(const char *s)
|
||||
}
|
||||
|
||||
retry:
|
||||
gp.program_state.getting_a_command = 1; /* arrow key support for curses */
|
||||
gp.program_state.input_state = getdirInp;
|
||||
if (gi.in_doagain || *readchar_queue)
|
||||
dirsym = readchar();
|
||||
else
|
||||
@@ -6219,7 +6219,7 @@ get_count(
|
||||
unsigned gc_flags) /* control flags: GC_SAVEHIST, GC_ECHOFIRST */
|
||||
{
|
||||
char qbuf[QBUFSZ];
|
||||
int key;
|
||||
int key, save_input_state = gp.program_state.input_state;
|
||||
long cnt = 0L, first = inkey ? (long) (inkey - '0') : 0L;
|
||||
boolean backspaced = FALSE, showzero = TRUE,
|
||||
/* should "Count: 123" go into message history? */
|
||||
@@ -6239,8 +6239,9 @@ get_count(
|
||||
key = inkey;
|
||||
inkey = '\0';
|
||||
} else {
|
||||
gp.program_state.getting_a_command = 1; /* readchar altmeta
|
||||
* compatibility */
|
||||
/* if readchar() has already been called in this loop, it will
|
||||
have reset input_state; put that back to its previous value */
|
||||
gp.program_state.input_state = save_input_state;
|
||||
key = readchar();
|
||||
}
|
||||
|
||||
@@ -6300,9 +6301,9 @@ parse(void)
|
||||
gc.context.move = TRUE; /* assume next command will take game time */
|
||||
flush_screen(1); /* Flush screen buffer. Put the cursor on the hero. */
|
||||
|
||||
gp.program_state.getting_a_command = 1; /* affects readchar() behavior for
|
||||
* ESC iff 'altmeta' option is On;
|
||||
* reset to 0 by readchar() */
|
||||
/* affects readchar() behavior for ESC iff 'altmeta' option is On;
|
||||
reset to 0 by readchar() */
|
||||
gp.program_state.input_state = commandInp;
|
||||
if (!gc.Cmd.num_pad || (foo = readchar()) == gc.Cmd.spkeys[NHKF_COUNT]) {
|
||||
foo = get_count((char *) 0, '\0', LARGEST_INT,
|
||||
&gc.command_count, GC_NOFLAGS);
|
||||
@@ -6400,8 +6401,10 @@ readchar_core(coordxy *x, coordxy *y, int *mod)
|
||||
{
|
||||
register int sym;
|
||||
|
||||
if (iflags.debug_fuzzer)
|
||||
return randomkey();
|
||||
if (iflags.debug_fuzzer) {
|
||||
sym = randomkey();
|
||||
goto readchar_done;
|
||||
}
|
||||
if (*readchar_queue)
|
||||
sym = *readchar_queue++;
|
||||
else if (gi.in_doagain)
|
||||
@@ -6431,9 +6434,11 @@ readchar_core(coordxy *x, coordxy *y, int *mod)
|
||||
sym = '\033';
|
||||
#ifdef ALTMETA
|
||||
} else if (sym == '\033' && iflags.altmeta
|
||||
&& gp.program_state.getting_a_command) {
|
||||
&& gp.program_state.input_state != otherInp) {
|
||||
/* iflags.altmeta: treat two character ``ESC c'' as single `M-c' but
|
||||
only when we're called by parse() [possibly via get_count()] */
|
||||
only when we're called by parse() [possibly via get_count()]
|
||||
or getpos() [to support Alt+digit] or getdir() [for arrow keys
|
||||
under curses] */
|
||||
sym = *readchar_queue ? *readchar_queue++ : pgetchar();
|
||||
if (sym == EOF || sym == 0)
|
||||
sym = '\033';
|
||||
@@ -6445,12 +6450,15 @@ readchar_core(coordxy *x, coordxy *y, int *mod)
|
||||
gc.clicklook_cc.x = gc.clicklook_cc.y = -1;
|
||||
click_to_cmd(*x, *y, *mod);
|
||||
}
|
||||
gp.program_state.getting_a_command = 0; /* next readchar() will be for an
|
||||
* ordinary char unless parse()
|
||||
* sets this back to 1 */
|
||||
|
||||
readchar_done:
|
||||
/* next readchar() will be for an ordinary char unless parse()
|
||||
sets this back to non-zero */
|
||||
gp.program_state.input_state = otherInp;
|
||||
return (char) sym;
|
||||
}
|
||||
|
||||
/* get a character */
|
||||
char
|
||||
readchar(void)
|
||||
{
|
||||
@@ -6462,11 +6470,13 @@ readchar(void)
|
||||
return ch;
|
||||
}
|
||||
|
||||
/* used by getpos() to accept mouse input as well as keyboard input */
|
||||
char
|
||||
readchar_poskey(coordxy *x, coordxy *y, int *mod)
|
||||
{
|
||||
char ch;
|
||||
|
||||
gp.program_state.input_state = getposInp;
|
||||
ch = readchar_core(x, y, mod);
|
||||
return ch;
|
||||
}
|
||||
@@ -6632,6 +6642,8 @@ yn_function(
|
||||
dumplogmsg(dumplog_buf);
|
||||
}
|
||||
#endif
|
||||
/* in case we're called via getdir() which sets input_state */
|
||||
gp.program_state.input_state = otherInp;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user