2 * todo get_string_for_search() は長い、要分割
9 #include "autopick/autopick-util.h"
10 #include "autopick/autopick-searcher.h"
11 #include "autopick/autopick-dirty-flags.h"
12 #include "autopick/autopick-entry.h"
13 #include "autopick/autopick-matcher.h"
14 #include "object-flavor.h"
16 #include "player-inventory.h"
19 * Choose an item for search
21 bool get_object_for_search(player_type *player_ptr, object_type **o_handle, concptr *search_strp)
23 concptr q = _("どのアイテムを検索しますか? ", "Enter which item? ");
24 concptr s = _("アイテムを持っていない。", "You have nothing to enter.");
26 o_ptr = choose_object(player_ptr, NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP, 0);
27 if (!o_ptr) return FALSE;
30 string_free(*search_strp);
31 char buf[MAX_NLEN + 20];
32 object_desc(player_ptr, buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
33 *search_strp = string_make(format("<%s>", buf));
39 * Prepare for search by destroyed object
41 bool get_destroyed_object_for_search(player_type *player_ptr, object_type **o_handle, concptr *search_strp)
43 if (!autopick_last_destroyed_object.k_idx) return FALSE;
45 *o_handle = &autopick_last_destroyed_object;
46 string_free(*search_strp);
47 char buf[MAX_NLEN + 20];
48 object_desc(player_ptr, buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
49 *search_strp = string_make(format("<%s>", buf));
55 * Choose an item or string for search
57 byte get_string_for_search(player_type *player_ptr, object_type **o_handle, concptr *search_strp)
61 * TERM_YELLOW : Overwrite mode
62 * TERM_WHITE : Insert mode
64 byte color = TERM_YELLOW;
65 char buf[MAX_NLEN + 20];
67 char prompt[] = _("検索(^I:持ち物 ^L:破壊された物): ", "Search key(^I:inven ^L:destroyed): ");
68 int col = sizeof(prompt) - 1;
69 if (*search_strp) strcpy(buf, *search_strp);
72 if (*o_handle) color = TERM_L_GREEN;
79 Term_erase(col, 0, 255);
80 Term_putstr(col, 0, -1, color, buf);
81 Term_gotoxy(col + pos, 0);
83 int skey = inkey_special(TRUE);
98 if (iskanji(buf[i])) next_pos++;
100 if (next_pos >= pos) break;
112 if ('\0' == buf[pos]) break;
115 if (iskanji(buf[pos])) pos += 2;
132 if (*o_handle) return (back ? -1 : 1);
133 string_free(*search_strp);
134 *search_strp = string_make(buf);
136 return (back ? -1 : 1);
139 return get_object_for_search(player_ptr, o_handle, search_strp);
142 if (get_destroyed_object_for_search(player_ptr, o_handle, search_strp))
154 int next_pos = i + 1;
156 if (iskanji(buf[i])) next_pos++;
158 if (next_pos >= pos) break;
172 if (buf[pos] == '\0') break;
176 if (iskanji(buf[pos])) src++;
179 while ('\0' != (buf[dst++] = buf[src++]));
188 if (skey & SKEY_MASK) break;
191 if (color != TERM_WHITE)
193 if (color == TERM_L_GREEN)
196 string_free(*search_strp);
204 strcpy(tmp, buf + pos);
226 if (pos < len && (isprint(c) || iskana(c)))
228 if (pos < len && isprint(c))
240 my_strcat(buf, tmp, len + 1);
246 if (*o_handle == NULL || color == TERM_L_GREEN) continue;
250 string_free(*search_strp);
257 * Search next line matches for o_ptr
259 void search_for_object(player_type *player_ptr, text_body_type *tb, object_type *o_ptr, bool forward)
261 autopick_type an_entry, *entry = &an_entry;
262 GAME_TEXT o_name[MAX_NLEN];
263 int bypassed_cy = -1;
265 object_desc(player_ptr, o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
273 if (!tb->lines_list[++i]) break;
280 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
282 match = is_autopick_match(player_ptr, o_ptr, entry, o_name);
283 autopick_free_entry(entry);
284 if (!match) continue;
286 if (tb->states[i] & LSTAT_BYPASS)
288 if (bypassed_cy == -1) bypassed_cy = i;
294 if (bypassed_cy != -1)
296 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
302 if (bypassed_cy == -1)
304 tb->dirty_flags |= DIRTY_NOT_FOUND;
309 tb->cy = bypassed_cy;
310 tb->dirty_flags |= DIRTY_INACTIVE;
315 * Search next line matches to the string
317 void search_for_string(text_body_type *tb, concptr search_str, bool forward)
319 int bypassed_cy = -1;
328 if (!tb->lines_list[++i]) break;
335 pos = my_strstr(tb->lines_list[i], search_str);
338 if ((tb->states[i] & LSTAT_BYPASS) &&
339 !(tb->states[i] & LSTAT_EXPRESSION))
341 if (bypassed_cy == -1)
344 bypassed_cx = (int)(pos - tb->lines_list[i]);
350 tb->cx = (int)(pos - tb->lines_list[i]);
353 if (bypassed_cy != -1)
355 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
361 if (bypassed_cy == -1)
363 tb->dirty_flags |= DIRTY_NOT_FOUND;
367 tb->cx = bypassed_cx;
368 tb->cy = bypassed_cy;
369 tb->dirty_flags |= DIRTY_INACTIVE;