#U567: lootiing counts (from <Someone>)

This commit is contained in:
nethack.allison
2003-07-31 11:11:17 +00:00
parent a4a5e8d8dd
commit 31a2c8cefa

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);
@@ -1418,20 +1418,23 @@ char mswin_yn_function(const char *question, const char *choices,
} }
if (choices) { if (choices) {
char *cb, choicebuf[QBUFSZ]; char *cb, choicebuf[QBUFSZ];
Strcpy(choicebuf, choices);
if ((cb = index(choicebuf, '\033')) != 0) { allow_num = (index(choices, '#') != 0);
/* anything beyond <esc> is hidden */
*cb = '\0'; Strcpy(choicebuf, choices);
} if ((cb = index(choicebuf, '\033')) != 0) {
sprintf(message, "%s [%s] ", question, choicebuf); /* anything beyond <esc> is hidden */
if (def) sprintf(eos(message), "(%c) ", def); *cb = '\0';
/* escape maps to 'q' or 'n' or default, in that order */ }
yn_esc_map = (index(choices, 'q') ? 'q' : sprintf(message, "%s [%s] ", question, choicebuf);
(index(choices, 'n') ? 'n' : def)); if (def) sprintf(eos(message), "(%c) ", def);
/* escape maps to 'q' or 'n' or default, in that order */
yn_esc_map = (index(choices, 'q') ? 'q' :
(index(choices, 'n') ? 'n' : def));
} else { } else {
Strcpy(message, question); Strcpy(message, question);
Strcat(message, " "); Strcat(message, " ");
} }
createcaret = 1; createcaret = 1;
@@ -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;
ShowCaret(mswin_hwnd_from_winid(WIN_MESSAGE)); do {
ch=mswin_nhgetch(); ShowCaret(mswin_hwnd_from_winid(WIN_MESSAGE));
if (choices) ch=mswin_nhgetch();
ch = lowc(ch); HideCaret(mswin_hwnd_from_winid(WIN_MESSAGE));
HideCaret(mswin_hwnd_from_winid(WIN_MESSAGE)); if (choices) ch = lowc(ch);
if (ch=='\033') { else break; /* If choices is NULL, all possible inputs are accepted and returned. */
result=yn_esc_map;
} else if (choices && !index(choices,ch)) { digit_ok = allow_num && digit(ch);
/* FYI: ch==-115 is for KP_ENTER */ if (ch=='\033') {
if (def && (ch==' ' || ch=='\r' || ch=='\n' || ch==-115)) { if (index(choices, 'q'))
result=def; ch = 'q';
} else if( index(choices, '#') && isdigit(ch) ) { else if (index(choices, 'n'))
yn_number = ch; ch = 'n';
result = '#'; else
} else { ch = def;
mswin_nhbell(); break;
/* and try again... */ } else if (index(quitchars, ch)) {
} ch = def;
} else { break;
result=ch; } else if (!index(choices, ch) && !digit_ok) {
} mswin_nhbell();
} ch = (char)0;
/* 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 {
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;
} }
/* /*