1 #include "core/asking-player.h"
2 #include "cmd-io/macro-util.h"
3 #include "core/stuff-handler.h"
4 #include "game-option/input-options.h"
5 #include "io/command-repeater.h"
6 #include "io/input-key-acceptor.h"
7 #include "io/input-key-requester.h" // todo 相互依存している、後で何とかする.
8 #include "main/sound-of-music.h"
9 #include "term/screen-processor.h"
10 #include "term/term-color-types.h"
11 #include "util/int-char-converter.h"
12 #include "view/display-messages.h"
15 * Get some string input at the cursor location.
16 * Assume the buffer is initialized to a default string.
18 * The default buffer is in Overwrite mode and displayed in yellow at
19 * first. Normal chars clear the yellow text and append the char in
22 * LEFT (^B) and RIGHT (^F) movement keys move the cursor position.
23 * If the text is still displayed in yellow (Overwite mode), it will
24 * turns into white (Insert mode) when cursor moves.
26 * DELETE (^D) deletes a char at the cursor position.
27 * BACKSPACE (^H) deletes a char at the left of cursor position.
28 * ESCAPE clears the buffer and the window and returns FALSE.
29 * RETURN accepts the current buffer contents and returns TRUE.
31 bool askfor_aux(char *buf, int len, bool numpad_cursor)
35 * TERM_YELLOW : Overwrite mode
36 * TERM_WHITE : Insert mode
38 byte color = TERM_YELLOW;
44 if ((x < 0) || (x >= 80))
53 Term_erase(x, y, len);
54 Term_putstr(x, y, -1, color, buf);
56 Term_gotoxy(x + pos, y);
57 int skey = inkey_special(numpad_cursor);
90 if (iskanji(buf[pos]))
113 int next_pos = i + 1;
131 if ('\0' == buf[pos])
135 if (iskanji(buf[pos]))
140 while ('\0' != (buf[dst++] = buf[src++]))
147 if (skey & SKEY_MASK)
151 if (color == TERM_YELLOW) {
156 strcpy(tmp, buf + pos);
171 if (pos < len && (isprint(c) || iskana(c)))
173 if (pos < len && isprint(c))
183 angband_strcat(buf, tmp, len + 1);
192 * Get some string input at the cursor location.
194 * Allow to use numpad keys as cursor keys.
196 bool askfor(char *buf, int len) { return askfor_aux(buf, len, TRUE); }
199 * Get a string from the user
201 * The "prompt" should take the form "Prompt: "
203 * Note that the initial contents of the string is used as
204 * the default response, so be sure to "clear" it if needed.
206 * We clear the input, and return FALSE, on "ESCAPE".
208 bool get_string(concptr prompt, char *buf, int len)
213 res = askfor(buf, len);
219 * Verify something with the user
221 * The "prompt" should take the form "Query? "
223 * Note that "[y/n]" is appended to the prompt.
225 bool get_check(concptr prompt) { return get_check_strict(p_ptr, prompt, 0); }
228 * Verify something with the user strictly
230 * mode & CHECK_OKAY_CANCEL : force user to answer 'O'kay or 'C'ancel
231 * mode & CHECK_NO_ESCAPE : don't allow ESCAPE key
232 * mode & CHECK_NO_HISTORY : no message_add
233 * mode & CHECK_DEFAULT_Y : accept any key as y, except n and Esc.
235 bool get_check_strict(player_type *player_ptr, concptr prompt, BIT_FLAGS mode)
239 player_ptr->window |= PW_MESSAGE;
240 handle_stuff(player_ptr);
245 if (!rogue_like_commands)
246 mode &= ~CHECK_OKAY_CANCEL;
248 if (mode & CHECK_OKAY_CANCEL) {
249 angband_strcpy(buf, prompt, sizeof(buf) - 15);
250 strcat(buf, "[(O)k/(C)ancel]");
251 } else if (mode & CHECK_DEFAULT_Y) {
252 angband_strcpy(buf, prompt, sizeof(buf) - 5);
253 strcat(buf, "[Y/n]");
255 angband_strcpy(buf, prompt, sizeof(buf) - 5);
256 strcat(buf, "[y/n]");
260 if (!(mode & CHECK_NO_HISTORY) && player_ptr->playing) {
262 player_ptr->window |= (PW_MESSAGE);
263 handle_stuff(player_ptr);
270 if (!(mode & CHECK_NO_ESCAPE)) {
277 if (mode & CHECK_OKAY_CANCEL) {
278 if (i == 'o' || i == 'O') {
281 } else if (i == 'c' || i == 'C') {
286 if (i == 'y' || i == 'Y') {
289 } else if (i == 'n' || i == 'N') {
295 if (mode & CHECK_DEFAULT_Y) {
308 * Prompts for a keypress
310 * The "prompt" should take the form "Command: "
312 * Returns TRUE unless the character is "Escape"
314 bool get_com(concptr prompt, char *command, bool z_escape)
318 if (get_com_no_macros)
319 *command = (char)inkey_special(FALSE);
324 if (*command == ESCAPE)
326 if (z_escape && ((*command == 'z') || (*command == 'Z')))
333 * Request a "quantity" from the user
335 * Hack -- allow "command_arg" to specify a quantity
337 QUANTITY get_quantity(concptr prompt, QUANTITY max)
354 bool result = repeat_pull(&code);
355 amt = (QUANTITY)code;
356 if ((max != 1) && result) {
366 sprintf(tmp, _("いくつですか (1-%d): ", "Quantity (1-%d): "), max);
373 sprintf(buf, "%d", amt);
377 * Don't allow to use numpad as cursor key.
379 res = askfor_aux(buf, 6, FALSE);
385 amt = (COMMAND_CODE)atoi(buf);
393 repeat_push((COMMAND_CODE)amt);
399 * Pause for user response
401 void pause_line(int row)
404 put_str(_("[ 何かキーを押して下さい ]", "[Press any key to continue]"), row, _(26, 23));