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 "system/player-type-definition.h"
11 #include "term/screen-processor.h"
12 #include "term/term-color-types.h"
13 #include "util/int-char-converter.h"
14 #include "util/string-processor.h"
15 #include "view/display-messages.h"
18 * Get some string input at the cursor location.
19 * Assume the buffer is initialized to a default string.
21 * The default buffer is in Overwrite mode and displayed in yellow at
22 * first. Normal chars clear the yellow text and append the char in
25 * LEFT (^B) and RIGHT (^F) movement keys move the cursor position.
26 * If the text is still displayed in yellow (Overwite mode), it will
27 * turns into white (Insert mode) when cursor moves.
29 * DELETE (^D) deletes a char at the cursor position.
30 * BACKSPACE (^H) deletes a char at the left of cursor position.
31 * ESCAPE clears the buffer and the window and returns FALSE.
32 * RETURN accepts the current buffer contents and returns TRUE.
34 bool askfor_aux(char *buf, int len, bool numpad_cursor)
38 * TERM_YELLOW : Overwrite mode
39 * TERM_WHITE : Insert mode
41 byte color = TERM_YELLOW;
47 if ((x < 0) || (x >= 80))
56 term_erase(x, y, len);
57 term_putstr(x, y, -1, color, buf);
59 term_gotoxy(x + pos, y);
60 int skey = inkey_special(numpad_cursor);
93 if (iskanji(buf[pos]))
116 int next_pos = i + 1;
134 if ('\0' == buf[pos])
138 if (iskanji(buf[pos]))
143 while ('\0' != (buf[dst++] = buf[src++]))
150 if (skey & SKEY_MASK)
154 if (color == TERM_YELLOW) {
159 strcpy(tmp, buf + pos);
174 if (pos < len && (isprint(c) || iskana(c)))
176 if (pos < len && isprint(c))
186 angband_strcat(buf, tmp, len + 1);
195 * Get some string input at the cursor location.
197 * Allow to use numpad keys as cursor keys.
199 bool askfor(char *buf, int len) { return askfor_aux(buf, len, true); }
202 * Get a string from the user
204 * The "prompt" should take the form "Prompt: "
206 * Note that the initial contents of the string is used as
207 * the default response, so be sure to "clear" it if needed.
209 * We clear the input, and return FALSE, on "ESCAPE".
211 bool get_string(concptr prompt, char *buf, int len)
216 res = askfor(buf, len);
222 * Verify something with the user
224 * The "prompt" should take the form "Query? "
226 * Note that "[y/n]" is appended to the prompt.
228 bool get_check(concptr prompt) { return get_check_strict(p_ptr, prompt, 0); }
231 * Verify something with the user strictly
233 * mode & CHECK_OKAY_CANCEL : force user to answer 'O'kay or 'C'ancel
234 * mode & CHECK_NO_ESCAPE : don't allow ESCAPE key
235 * mode & CHECK_NO_HISTORY : no message_add
236 * mode & CHECK_DEFAULT_Y : accept any key as y, except n and Esc.
238 bool get_check_strict(player_type *player_ptr, concptr prompt, BIT_FLAGS mode)
241 if (!rogue_like_commands)
242 mode &= ~CHECK_OKAY_CANCEL;
244 if (mode & CHECK_OKAY_CANCEL) {
245 angband_strcpy(buf, prompt, sizeof(buf) - 15);
246 strcat(buf, "[(O)k/(C)ancel]");
247 } else if (mode & CHECK_DEFAULT_Y) {
248 angband_strcpy(buf, prompt, sizeof(buf) - 5);
249 strcat(buf, "[Y/n]");
251 angband_strcpy(buf, prompt, sizeof(buf) - 5);
252 strcat(buf, "[y/n]");
256 player_ptr->window_flags |= PW_MESSAGE;
257 handle_stuff(player_ptr);
264 if (!(mode & CHECK_NO_HISTORY) && player_ptr->playing) {
266 player_ptr->window_flags |= (PW_MESSAGE);
267 handle_stuff(player_ptr);
274 if (!(mode & CHECK_NO_ESCAPE)) {
281 if (mode & CHECK_OKAY_CANCEL) {
282 if (i == 'o' || i == 'O') {
285 } else if (i == 'c' || i == 'C') {
290 if (i == 'y' || i == 'Y') {
293 } else if (i == 'n' || i == 'N') {
299 if (mode & CHECK_DEFAULT_Y) {
312 * Prompts for a keypress
314 * The "prompt" should take the form "Command: "
316 * Returns TRUE unless the character is "Escape"
318 bool get_com(concptr prompt, char *command, bool z_escape)
322 if (get_com_no_macros)
323 *command = (char)inkey_special(false);
328 if (*command == ESCAPE)
330 if (z_escape && ((*command == 'z') || (*command == 'Z')))
337 * Request a "quantity" from the user
339 * Hack -- allow "command_arg" to specify a quantity
341 QUANTITY get_quantity(concptr prompt, QUANTITY max)
358 bool result = repeat_pull(&code);
359 amt = (QUANTITY)code;
360 if ((max != 1) && result) {
370 sprintf(tmp, _("いくつですか (1-%d): ", "Quantity (1-%d): "), max);
377 sprintf(buf, "%d", amt);
381 * Don't allow to use numpad as cursor key.
383 res = askfor_aux(buf, 6, false);
389 amt = (COMMAND_CODE)atoi(buf);
397 repeat_push((COMMAND_CODE)amt);
403 * Pause for user response
405 void pause_line(int row)
408 put_str(_("[ 何かキーを押して下さい ]", "[Press any key to continue]"), row, _(26, 23));