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 "view/display-messages.h"
14 * Get some string input at the cursor location.
15 * Assume the buffer is initialized to a default string.
17 * The default buffer is in Overwrite mode and displayed in yellow at
18 * first. Normal chars clear the yellow text and append the char in
21 * LEFT (^B) and RIGHT (^F) movement keys move the cursor position.
22 * If the text is still displayed in yellow (Overwite mode), it will
23 * turns into white (Insert mode) when cursor moves.
25 * DELETE (^D) deletes a char at the cursor position.
26 * BACKSPACE (^H) deletes a char at the left of cursor position.
27 * ESCAPE clears the buffer and the window and returns FALSE.
28 * RETURN accepts the current buffer contents and returns TRUE.
30 bool askfor_aux(char *buf, int len, bool numpad_cursor)
34 * TERM_YELLOW : Overwrite mode
35 * TERM_WHITE : Insert mode
37 byte color = TERM_YELLOW;
43 if ((x < 0) || (x >= 80))
52 Term_erase(x, y, len);
53 Term_putstr(x, y, -1, color, buf);
55 Term_gotoxy(x + pos, y);
56 int skey = inkey_special(numpad_cursor);
89 if (iskanji(buf[pos]))
112 int next_pos = i + 1;
130 if ('\0' == buf[pos])
134 if (iskanji(buf[pos]))
139 while ('\0' != (buf[dst++] = buf[src++]))
146 if (skey & SKEY_MASK)
150 if (color == TERM_YELLOW) {
155 strcpy(tmp, buf + pos);
170 if (pos < len && (isprint(c) || iskana(c)))
172 if (pos < len && isprint(c))
182 angband_strcat(buf, tmp, len + 1);
191 * Get some string input at the cursor location.
193 * Allow to use numpad keys as cursor keys.
195 bool askfor(char *buf, int len) { return askfor_aux(buf, len, TRUE); }
198 * Get a string from the user
200 * The "prompt" should take the form "Prompt: "
202 * Note that the initial contents of the string is used as
203 * the default response, so be sure to "clear" it if needed.
205 * We clear the input, and return FALSE, on "ESCAPE".
207 bool get_string(concptr prompt, char *buf, int len)
212 res = askfor(buf, len);
218 * Verify something with the user
220 * The "prompt" should take the form "Query? "
222 * Note that "[y/n]" is appended to the prompt.
224 bool get_check(concptr prompt) { return get_check_strict(p_ptr, prompt, 0); }
227 * Verify something with the user strictly
229 * mode & CHECK_OKAY_CANCEL : force user to answer 'O'kay or 'C'ancel
230 * mode & CHECK_NO_ESCAPE : don't allow ESCAPE key
231 * mode & CHECK_NO_HISTORY : no message_add
232 * mode & CHECK_DEFAULT_Y : accept any key as y, except n and Esc.
234 bool get_check_strict(player_type *player_ptr, concptr prompt, BIT_FLAGS mode)
238 player_ptr->window |= PW_MESSAGE;
239 handle_stuff(player_ptr);
244 if (!rogue_like_commands)
245 mode &= ~CHECK_OKAY_CANCEL;
247 if (mode & CHECK_OKAY_CANCEL) {
248 angband_strcpy(buf, prompt, sizeof(buf) - 15);
249 strcat(buf, "[(O)k/(C)ancel]");
250 } else if (mode & CHECK_DEFAULT_Y) {
251 angband_strcpy(buf, prompt, sizeof(buf) - 5);
252 strcat(buf, "[Y/n]");
254 angband_strcpy(buf, prompt, sizeof(buf) - 5);
255 strcat(buf, "[y/n]");
259 if (!(mode & CHECK_NO_HISTORY) && player_ptr->playing) {
261 player_ptr->window |= (PW_MESSAGE);
262 handle_stuff(player_ptr);
269 if (!(mode & CHECK_NO_ESCAPE)) {
276 if (mode & CHECK_OKAY_CANCEL) {
277 if (i == 'o' || i == 'O') {
280 } else if (i == 'c' || i == 'C') {
285 if (i == 'y' || i == 'Y') {
288 } else if (i == 'n' || i == 'N') {
294 if (mode & CHECK_DEFAULT_Y) {
307 * Prompts for a keypress
309 * The "prompt" should take the form "Command: "
311 * Returns TRUE unless the character is "Escape"
313 bool get_com(concptr prompt, char *command, bool z_escape)
317 if (get_com_no_macros)
318 *command = (char)inkey_special(FALSE);
323 if (*command == ESCAPE)
325 if (z_escape && ((*command == 'z') || (*command == 'Z')))
332 * Request a "quantity" from the user
334 * Hack -- allow "command_arg" to specify a quantity
336 QUANTITY get_quantity(concptr prompt, QUANTITY max)
353 bool result = repeat_pull(&code);
354 amt = (QUANTITY)code;
355 if ((max != 1) && result) {
365 sprintf(tmp, _("いくつですか (1-%d): ", "Quantity (1-%d): "), max);
372 sprintf(buf, "%d", amt);
376 * Don't allow to use numpad as cursor key.
378 res = askfor_aux(buf, 6, FALSE);
384 amt = (COMMAND_CODE)atoi(buf);
392 repeat_push((COMMAND_CODE)amt);
398 * Pause for user response
400 void pause_line(int row)
403 put_str(_("[ 何かキーを押して下さい ]", "[Press any key to continue]"), row, _(26, 23));