1 #include "core/asking-player.h"
2 #include "cmd-io/macro-util.h"
3 #include "core/stuff-handler.h"
4 #include "core/window-redrawer.h"
5 #include "game-option/input-options.h"
6 #include "io/command-repeater.h"
7 #include "io/input-key-acceptor.h"
8 #include "io/input-key-requester.h" // todo 相互依存している、後で何とかする.
9 #include "main/sound-of-music.h"
10 #include "term/screen-processor.h"
11 #include "term/term-color-types.h"
12 #include "util/int-char-converter.h"
13 #include "util/string-processor.h"
14 #include "view/display-messages.h"
17 * Get some string input at the cursor location.
18 * Assume the buffer is initialized to a default string.
20 * The default buffer is in Overwrite mode and displayed in yellow at
21 * first. Normal chars clear the yellow text and append the char in
24 * LEFT (^B) and RIGHT (^F) movement keys move the cursor position.
25 * If the text is still displayed in yellow (Overwite mode), it will
26 * turns into white (Insert mode) when cursor moves.
28 * DELETE (^D) deletes a char at the cursor position.
29 * BACKSPACE (^H) deletes a char at the left of cursor position.
30 * ESCAPE clears the buffer and the window and returns FALSE.
31 * RETURN accepts the current buffer contents and returns TRUE.
33 bool askfor_aux(char *buf, int len, bool numpad_cursor)
37 * TERM_YELLOW : Overwrite mode
38 * TERM_WHITE : Insert mode
40 byte color = TERM_YELLOW;
46 if ((x < 0) || (x >= 80))
55 term_erase(x, y, len);
56 term_putstr(x, y, -1, color, buf);
58 term_gotoxy(x + pos, y);
59 int skey = inkey_special(numpad_cursor);
92 if (iskanji(buf[pos]))
115 int next_pos = i + 1;
133 if ('\0' == buf[pos])
137 if (iskanji(buf[pos]))
142 while ('\0' != (buf[dst++] = buf[src++]))
149 if (skey & SKEY_MASK)
153 if (color == TERM_YELLOW) {
158 strcpy(tmp, buf + pos);
173 if (pos < len && (isprint(c) || iskana(c)))
175 if (pos < len && isprint(c))
185 angband_strcat(buf, tmp, len + 1);
194 * Get some string input at the cursor location.
196 * Allow to use numpad keys as cursor keys.
198 bool askfor(char *buf, int len) { return askfor_aux(buf, len, TRUE); }
201 * Get a string from the user
203 * The "prompt" should take the form "Prompt: "
205 * Note that the initial contents of the string is used as
206 * the default response, so be sure to "clear" it if needed.
208 * We clear the input, and return FALSE, on "ESCAPE".
210 bool get_string(concptr prompt, char *buf, int len)
215 res = askfor(buf, len);
221 * Verify something with the user
223 * The "prompt" should take the form "Query? "
225 * Note that "[y/n]" is appended to the prompt.
227 bool get_check(concptr prompt) { return get_check_strict(p_ptr, prompt, 0); }
230 * Verify something with the user strictly
232 * mode & CHECK_OKAY_CANCEL : force user to answer 'O'kay or 'C'ancel
233 * mode & CHECK_NO_ESCAPE : don't allow ESCAPE key
234 * mode & CHECK_NO_HISTORY : no message_add
235 * mode & CHECK_DEFAULT_Y : accept any key as y, except n and Esc.
237 bool get_check_strict(player_type *player_ptr, concptr prompt, BIT_FLAGS mode)
241 player_ptr->window |= PW_MESSAGE;
242 handle_stuff(player_ptr);
247 if (!rogue_like_commands)
248 mode &= ~CHECK_OKAY_CANCEL;
250 if (mode & CHECK_OKAY_CANCEL) {
251 angband_strcpy(buf, prompt, sizeof(buf) - 15);
252 strcat(buf, "[(O)k/(C)ancel]");
253 } else if (mode & CHECK_DEFAULT_Y) {
254 angband_strcpy(buf, prompt, sizeof(buf) - 5);
255 strcat(buf, "[Y/n]");
257 angband_strcpy(buf, prompt, sizeof(buf) - 5);
258 strcat(buf, "[y/n]");
262 if (!(mode & CHECK_NO_HISTORY) && player_ptr->playing) {
264 player_ptr->window |= (PW_MESSAGE);
265 handle_stuff(player_ptr);
272 if (!(mode & CHECK_NO_ESCAPE)) {
279 if (mode & CHECK_OKAY_CANCEL) {
280 if (i == 'o' || i == 'O') {
283 } else if (i == 'c' || i == 'C') {
288 if (i == 'y' || i == 'Y') {
291 } else if (i == 'n' || i == 'N') {
297 if (mode & CHECK_DEFAULT_Y) {
310 * Prompts for a keypress
312 * The "prompt" should take the form "Command: "
314 * Returns TRUE unless the character is "Escape"
316 bool get_com(concptr prompt, char *command, bool z_escape)
320 if (get_com_no_macros)
321 *command = (char)inkey_special(FALSE);
326 if (*command == ESCAPE)
328 if (z_escape && ((*command == 'z') || (*command == 'Z')))
335 * Request a "quantity" from the user
337 * Hack -- allow "command_arg" to specify a quantity
339 QUANTITY get_quantity(concptr prompt, QUANTITY max)
356 bool result = repeat_pull(&code);
357 amt = (QUANTITY)code;
358 if ((max != 1) && result) {
368 sprintf(tmp, _("いくつですか (1-%d): ", "Quantity (1-%d): "), max);
375 sprintf(buf, "%d", amt);
379 * Don't allow to use numpad as cursor key.
381 res = askfor_aux(buf, 6, FALSE);
387 amt = (COMMAND_CODE)atoi(buf);
395 repeat_push((COMMAND_CODE)amt);
401 * Pause for user response
403 void pause_line(int row)
406 put_str(_("[ 何かキーを押して下さい ]", "[Press any key to continue]"), row, _(26, 23));