#U567: lootiing counts (from <Someone>)

This commit is contained in:
nethack.allison
2003-07-31 11:11:17 +00:00
parent a4a5e8d8dd
commit 31a2c8cefa
+61 -16
View File
@@ -1393,12 +1393,12 @@ char yn_function(const char *ques, const char *choices, char default)
char mswin_yn_function(const char *question, const char *choices, char mswin_yn_function(const char *question, const char *choices,
CHAR_P def) CHAR_P def)
{ {
int result=-1;
char ch; char ch;
char yn_esc_map='\033'; char yn_esc_map='\033';
char message[BUFSZ]; char message[BUFSZ];
char res_ch[2]; char res_ch[2];
int createcaret; int createcaret;
boolean digit_ok, allow_num;
logDebug("mswin_yn_function(%s, %s, %d)\n", question, choices, def); logDebug("mswin_yn_function(%s, %s, %d)\n", question, choices, def);
@@ -1419,6 +1419,9 @@ char mswin_yn_function(const char *question, const char *choices,
if (choices) { if (choices) {
char *cb, choicebuf[QBUFSZ]; char *cb, choicebuf[QBUFSZ];
allow_num = (index(choices, '#') != 0);
Strcpy(choicebuf, choices); Strcpy(choicebuf, choices);
if ((cb = index(choicebuf, '\033')) != 0) { if ((cb = index(choicebuf, '\033')) != 0) {
/* anything beyond <esc> is hidden */ /* anything beyond <esc> is hidden */
@@ -1442,41 +1445,83 @@ char mswin_yn_function(const char *question, const char *choices,
mswin_putstr(WIN_MESSAGE, ATR_BOLD, message); mswin_putstr(WIN_MESSAGE, ATR_BOLD, message);
/* Only here if main window is not present */ /* Only here if main window is not present */
while (result<0) { ch = 0;
do {
ShowCaret(mswin_hwnd_from_winid(WIN_MESSAGE)); ShowCaret(mswin_hwnd_from_winid(WIN_MESSAGE));
ch=mswin_nhgetch(); ch=mswin_nhgetch();
if (choices)
ch = lowc(ch);
HideCaret(mswin_hwnd_from_winid(WIN_MESSAGE)); HideCaret(mswin_hwnd_from_winid(WIN_MESSAGE));
if (choices) ch = lowc(ch);
else break; /* If choices is NULL, all possible inputs are accepted and returned. */
digit_ok = allow_num && digit(ch);
if (ch=='\033') { if (ch=='\033') {
result=yn_esc_map; if (index(choices, 'q'))
} else if (choices && !index(choices,ch)) { ch = 'q';
/* FYI: ch==-115 is for KP_ENTER */ else if (index(choices, 'n'))
if (def && (ch==' ' || ch=='\r' || ch=='\n' || ch==-115)) { ch = 'n';
result=def; else
} else if( index(choices, '#') && isdigit(ch) ) { ch = def;
yn_number = ch; break;
result = '#'; } else if (index(quitchars, ch)) {
} else { ch = def;
break;
} else if (!index(choices, ch) && !digit_ok) {
mswin_nhbell(); mswin_nhbell();
ch = (char)0;
/* and try again... */ /* and try again... */
} else if (ch == '#' || digit_ok) {
char z, digit_string[2];
int n_len = 0;
long value = 0;
mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, ("#"), 1); n_len++;
digit_string[1] = '\0';
if (ch != '#') {
digit_string[0] = ch;
mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, digit_string, 1); n_len++;
value = ch - '0';
ch = '#';
} }
do { /* loop until we get a non-digit */
z = lowc(readchar());
if (digit(z)) {
value = (10 * value) + (z - '0');
if (value < 0) break; /* overflow: try again */
digit_string[0] = z;
mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, digit_string, 1);
n_len++;
} else if (z == 'y' || index(quitchars, z)) {
if (z == '\033') value = -1; /* abort */
z = '\n'; /* break */
} else if (z == '\b') {
if (n_len <= 1) { value = -1; break; }
else { value /= 10; mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, digit_string, -1); n_len--; }
} else { } else {
result=ch; value = -1; /* abort */
mswin_nhbell();
break;
}
} while (z != '\n');
if (value > 0) yn_number = value;
else if (value == 0) ch = 'n'; /* 0 => "no" */
else { /* remove number from top line, then try again */
mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, digit_string, -n_len); n_len = 0;
ch = (char)0;
} }
} }
} while( !ch );
createcaret = 0; createcaret = 0;
SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE),
WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_CARET, (LPARAM)&createcaret ); WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_CARET, (LPARAM)&createcaret );
/* display selection in the message window */ /* display selection in the message window */
if( isprint(ch) ) { if( isprint(ch) && ch!='#' ) {
res_ch[0] = ch; res_ch[0] = ch;
res_ch[1] = '\x0'; res_ch[1] = '\x0';
mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, res_ch, 1); mswin_putstr_ex(WIN_MESSAGE, ATR_BOLD, res_ch, 1);
} }
return result; return ch;
} }
/* /*