2 * todo get_string_for_search() は長い、要分割
8 #include "autopick/autopick-finder.h"
9 #include "autopick/autopick-dirty-flags.h"
10 #include "autopick/autopick-entry.h"
11 #include "autopick/autopick-matcher.h"
12 #include "core/show-file.h"
13 #include "flavor/flavor-describer.h"
14 #include "flavor/object-flavor-types.h"
15 #include "floor/floor-object.h"
16 #include "io/input-key-acceptor.h"
17 #include "main/sound-of-music.h"
18 #include "object/item-use-flags.h"
19 #include "term/screen-processor.h"
20 #include "term/term-color-types.h"
21 #include "util/int-char-converter.h"
22 #include "util/string-processor.h"
25 * @brief 与えられたアイテムが自動拾いのリストに登録されているかどうかを検索する
26 * @param player_ptr プレーヤーへの参照ポインタ
28 * @return 自動拾いのリストに登録されていたらその登録番号、なかったら-1
30 * A function for Auto-picker/destroyer
31 * Examine whether the object matches to the list of keywords or not.
33 int find_autopick_list(player_type *player_ptr, object_type *o_ptr)
35 GAME_TEXT o_name[MAX_NLEN];
36 if (o_ptr->tval == TV_GOLD)
39 describe_flavor(player_ptr, o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
41 for (int i = 0; i < max_autopick; i++) {
42 autopick_type *entry = &autopick_list[i];
43 if (is_autopick_match(player_ptr, o_ptr, entry, o_name))
51 * Choose an item for search
53 bool get_object_for_search(player_type *player_ptr, object_type **o_handle, concptr *search_strp)
55 concptr q = _("どのアイテムを検索しますか? ", "Enter which item? ");
56 concptr s = _("アイテムを持っていない。", "You have nothing to enter.");
58 o_ptr = choose_object(player_ptr, NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP, 0);
63 string_free(*search_strp);
64 char buf[MAX_NLEN + 20];
65 describe_flavor(player_ptr, buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
66 *search_strp = string_make(format("<%s>", buf));
71 * Prepare for search by destroyed object
73 bool get_destroyed_object_for_search(player_type *player_ptr, object_type **o_handle, concptr *search_strp)
75 if (!autopick_last_destroyed_object.k_idx)
78 *o_handle = &autopick_last_destroyed_object;
79 string_free(*search_strp);
80 char buf[MAX_NLEN + 20];
81 describe_flavor(player_ptr, buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
82 *search_strp = string_make(format("<%s>", buf));
87 * Choose an item or string for search
89 byte get_string_for_search(player_type *player_ptr, object_type **o_handle, concptr *search_strp)
93 * TERM_YELLOW : Overwrite mode
94 * TERM_WHITE : Insert mode
96 byte color = TERM_YELLOW;
97 char buf[MAX_NLEN + 20];
99 char prompt[] = _("検索(^I:持ち物 ^L:破壊された物): ", "Search key(^I:inven ^L:destroyed): ");
100 int col = sizeof(prompt) - 1;
102 strcpy(buf, *search_strp);
107 color = TERM_L_GREEN;
113 term_erase(col, 0, 255);
114 term_putstr(col, 0, -1, color, buf);
115 term_gotoxy(col + pos, 0);
117 int skey = inkey_special(TRUE);
127 int next_pos = i + 1;
146 if ('\0' == buf[pos])
150 if (iskanji(buf[pos]))
170 return (back ? -1 : 1);
171 string_free(*search_strp);
172 *search_strp = string_make(buf);
174 return (back ? -1 : 1);
177 return get_object_for_search(player_ptr, o_handle, search_strp);
180 if (get_destroyed_object_for_search(player_ptr, o_handle, search_strp))
191 int next_pos = i + 1;
210 if (buf[pos] == '\0')
215 if (iskanji(buf[pos]))
219 while ('\0' != (buf[dst++] = buf[src++]))
228 if (skey & SKEY_MASK)
232 if (color != TERM_WHITE) {
233 if (color == TERM_L_GREEN) {
235 string_free(*search_strp);
243 strcpy(tmp, buf + pos);
259 if (pos < len && (isprint(c) || iskana(c)))
261 if (pos < len && isprint(c))
270 angband_strcat(buf, tmp, len + 1);
276 if (*o_handle == NULL || color == TERM_L_GREEN)
281 string_free(*search_strp);
287 * Search next line matches for o_ptr
289 void search_for_object(player_type *player_ptr, text_body_type *tb, object_type *o_ptr, bool forward)
291 autopick_type an_entry, *entry = &an_entry;
292 GAME_TEXT o_name[MAX_NLEN];
293 int bypassed_cy = -1;
295 describe_flavor(player_ptr, o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
301 if (!tb->lines_list[++i])
308 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE))
311 match = is_autopick_match(player_ptr, o_ptr, entry, o_name);
312 autopick_free_entry(entry);
316 if (tb->states[i] & LSTAT_BYPASS) {
317 if (bypassed_cy == -1)
324 if (bypassed_cy != -1) {
325 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
331 if (bypassed_cy == -1) {
332 tb->dirty_flags |= DIRTY_NOT_FOUND;
337 tb->cy = bypassed_cy;
338 tb->dirty_flags |= DIRTY_INACTIVE;
342 * Search next line matches to the string
344 void search_for_string(text_body_type *tb, concptr search_str, bool forward)
346 int bypassed_cy = -1;
353 if (!tb->lines_list[++i])
360 pos = angband_strstr(tb->lines_list[i], search_str);
364 if ((tb->states[i] & LSTAT_BYPASS) && !(tb->states[i] & LSTAT_EXPRESSION)) {
365 if (bypassed_cy == -1) {
367 bypassed_cx = (int)(pos - tb->lines_list[i]);
373 tb->cx = (int)(pos - tb->lines_list[i]);
376 if (bypassed_cy != -1) {
377 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
383 if (bypassed_cy == -1) {
384 tb->dirty_flags |= DIRTY_NOT_FOUND;
388 tb->cx = bypassed_cx;
389 tb->cy = bypassed_cy;
390 tb->dirty_flags |= DIRTY_INACTIVE;