2 * todo get_string_for_search()
\82Í
\92·
\82¢
\81A
\97v
\95ª
\8a\84
3 * @brief
\8e©
\93®
\8fE
\82¢
\82Ì
\8c\9f\8dõ
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 "inventory/player-inventory.h"
14 #include "io/input-key-acceptor.h"
15 #include "main/sound-of-music.h"
16 #include "object/item-use-flags.h"
17 #include "object/object-flavor.h"
18 #include "term/screen-processor.h"
19 #include "term/term-color-types.h"
20 #include "util/int-char-converter.h"
21 #include "util/string-processor.h"
24 * @brief
\97^
\82¦
\82ç
\82ê
\82½
\83A
\83C
\83e
\83\80\82ª
\8e©
\93®
\8fE
\82¢
\82Ì
\83\8a\83X
\83g
\82É
\93o
\98^
\82³
\82ê
\82Ä
\82¢
\82é
\82©
\82Ç
\82¤
\82©
\82ð
\8c\9f\8dõ
\82·
\82é
25 * @param player_ptr
\83v
\83\8c\81[
\83\84\81[
\82Ö
\82Ì
\8eQ
\8fÆ
\83|
\83C
\83\93\83^
26 * @o_ptr
\83A
\83C
\83e
\83\80\82Ö
\82Ì
\8eQ
\8fÆ
\83|
\83C
\83\93\83^
27 * @return
\8e©
\93®
\8fE
\82¢
\82Ì
\83\8a\83X
\83g
\82É
\93o
\98^
\82³
\82ê
\82Ä
\82¢
\82½
\82ç
\82»
\82Ì
\93o
\98^
\94Ô
\8d\86\81A
\82È
\82©
\82Á
\82½
\82ç-1
29 * A function for Auto-picker/destroyer
30 * Examine whether the object matches to the list of keywords or not.
32 int find_autopick_list(player_type *player_ptr, object_type *o_ptr)
34 GAME_TEXT o_name[MAX_NLEN];
35 if (o_ptr->tval == TV_GOLD) return -1;
37 object_desc(player_ptr, o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
39 for (int i = 0; i < max_autopick; i++)
41 autopick_type *entry = &autopick_list[i];
42 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 = _("
\82Ç
\82Ì
\83A
\83C
\83e
\83\80\82ð
\8c\9f\8dõ
\82µ
\82Ü
\82·
\82©? ", "Enter which item? ");
56 concptr s = _("
\83A
\83C
\83e
\83\80\82ð
\8e\9d\82Á
\82Ä
\82¢
\82È
\82¢
\81B", "You have nothing to enter.");
58 o_ptr = choose_object(player_ptr, NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP, 0);
59 if (!o_ptr) return FALSE;
62 string_free(*search_strp);
63 char buf[MAX_NLEN + 20];
64 object_desc(player_ptr, buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
65 *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) return FALSE;
77 *o_handle = &autopick_last_destroyed_object;
78 string_free(*search_strp);
79 char buf[MAX_NLEN + 20];
80 object_desc(player_ptr, buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
81 *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[] = _("
\8c\9f\8dõ(^I:
\8e\9d\82¿
\95¨ ^L:
\94j
\89ó
\82³
\82ê
\82½
\95¨): ", "Search key(^I:inven ^L:destroyed): ");
100 int col = sizeof(prompt) - 1;
101 if (*search_strp) strcpy(buf, *search_strp);
104 if (*o_handle) color = TERM_L_GREEN;
111 Term_erase(col, 0, 255);
112 Term_putstr(col, 0, -1, color, buf);
113 Term_gotoxy(col + pos, 0);
115 int skey = inkey_special(TRUE);
127 int next_pos = i + 1;
130 if (iskanji(buf[i])) next_pos++;
132 if (next_pos >= pos) break;
144 if ('\0' == buf[pos]) break;
147 if (iskanji(buf[pos])) pos += 2;
164 if (*o_handle) return (back ? -1 : 1);
165 string_free(*search_strp);
166 *search_strp = string_make(buf);
168 return (back ? -1 : 1);
171 return get_object_for_search(player_ptr, o_handle, search_strp);
174 if (get_destroyed_object_for_search(player_ptr, o_handle, search_strp))
186 int next_pos = i + 1;
188 if (iskanji(buf[i])) next_pos++;
190 if (next_pos >= pos) break;
204 if (buf[pos] == '\0') break;
208 if (iskanji(buf[pos])) src++;
211 while ('\0' != (buf[dst++] = buf[src++]));
220 if (skey & SKEY_MASK) break;
223 if (color != TERM_WHITE)
225 if (color == TERM_L_GREEN)
228 string_free(*search_strp);
236 strcpy(tmp, buf + pos);
257 if (pos < len && (isprint(c) || iskana(c)))
259 if (pos < len && isprint(c))
270 angband_strcat(buf, tmp, len + 1);
276 if (*o_handle == NULL || color == TERM_L_GREEN) continue;
280 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 object_desc(player_ptr, o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
303 if (!tb->lines_list[++i]) break;
310 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
312 match = is_autopick_match(player_ptr, o_ptr, entry, o_name);
313 autopick_free_entry(entry);
314 if (!match) continue;
316 if (tb->states[i] & LSTAT_BYPASS)
318 if (bypassed_cy == -1) bypassed_cy = i;
324 if (bypassed_cy != -1)
326 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
332 if (bypassed_cy == -1)
334 tb->dirty_flags |= DIRTY_NOT_FOUND;
339 tb->cy = bypassed_cy;
340 tb->dirty_flags |= DIRTY_INACTIVE;
345 * Search next line matches to the string
347 void search_for_string(text_body_type *tb, concptr search_str, bool forward)
349 int bypassed_cy = -1;
358 if (!tb->lines_list[++i]) break;
365 pos = angband_strstr(tb->lines_list[i], search_str);
368 if ((tb->states[i] & LSTAT_BYPASS) &&
369 !(tb->states[i] & LSTAT_EXPRESSION))
371 if (bypassed_cy == -1)
374 bypassed_cx = (int)(pos - tb->lines_list[i]);
380 tb->cx = (int)(pos - tb->lines_list[i]);
383 if (bypassed_cy != -1)
385 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
391 if (bypassed_cy == -1)
393 tb->dirty_flags |= DIRTY_NOT_FOUND;
397 tb->cx = bypassed_cx;
398 tb->cy = bypassed_cy;
399 tb->dirty_flags |= DIRTY_INACTIVE;