2 * @brief 自動拾いエディタを表示させる
7 #include "autopick/autopick-drawer.h"
8 #include "autopick/autopick-describer.h"
9 #include "autopick/autopick-dirty-flags.h"
10 #include "autopick/autopick-entry.h"
11 #include "io/pref-file-expressor.h"
12 #include "term/term-color-types.h"
14 #define DESCRIPT_HGT 3
16 static void process_dirty_expression(player_type *player_ptr, text_body_type *tb)
18 if ((tb->dirty_flags & DIRTY_EXPRESSION) == 0) return;
21 for (int y = 0; tb->lines_list[y]; y++)
23 concptr s = tb->lines_list[y];
25 tb->states[y] = state;
27 if (*s++ != '?') continue;
28 if (*s++ != ':') continue;
30 if (streq(s, "$AUTOREGISTER"))
31 state |= LSTAT_AUTOREGISTER;
33 int s_len = strlen(s);
34 ss = (char *)string_make(s);
38 concptr v = process_pref_file_expr(player_ptr, &ss, &f);
39 if (streq(v, "0")) state |= LSTAT_BYPASS;
40 else state &= ~LSTAT_BYPASS;
42 C_KILL(s_keep, s_len + 1, char);
43 tb->states[y] = state | LSTAT_EXPRESSION;
46 tb->dirty_flags |= DIRTY_ALL;
53 void draw_text_editor(player_type *player_ptr, text_body_type *tb)
57 Term_get_size(&tb->wid, &tb->hgt);
60 * Top line (-1), description line (-3), separator (-1)
63 tb->hgt -= 2 + DESCRIPT_HGT;
66 /* Don't let cursor at second byte of kanji */
67 for (int i = 0; tb->lines_list[tb->cy][i]; i++)
68 if (iskanji(tb->lines_list[tb->cy][i]))
74 * Move to a correct position in the
83 if (tb->cy < tb->upper || tb->upper + tb->hgt <= tb->cy)
84 tb->upper = tb->cy - (tb->hgt) / 2;
87 if ((tb->cx < tb->left + 10 && tb->left > 0) || tb->left + tb->wid - 5 <= tb->cx)
88 tb->left = tb->cx - (tb->wid) * 2 / 3;
92 if (tb->old_wid != tb->wid || tb->old_hgt != tb->hgt)
93 tb->dirty_flags |= DIRTY_SCREEN;
94 else if (tb->old_upper != tb->upper || tb->old_left != tb->left)
95 tb->dirty_flags |= DIRTY_ALL;
97 if (tb->dirty_flags & DIRTY_SCREEN)
99 tb->dirty_flags |= (DIRTY_ALL | DIRTY_MODE);
103 if (tb->dirty_flags & DIRTY_MODE)
105 char buf[MAX_LINELEN];
106 int sepa_length = tb->wid;
108 for (; j < sepa_length; j++)
111 Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
114 process_dirty_expression(player_ptr, tb);
117 tb->dirty_flags |= DIRTY_ALL;
119 by1 = MIN(tb->my, tb->cy);
120 by2 = MAX(tb->my, tb->cy);
124 for (i = 0; i < tb->hgt; i++)
129 int y = tb->upper + i;
131 if (!(tb->dirty_flags & DIRTY_ALL) && (tb->dirty_line != y))
134 msg = tb->lines_list[y];
137 for (int j = 0; *msg; msg++, j++)
139 if (j == tb->left) break;
154 Term_erase(0, i + 1, tb->wid);
155 if (tb->states[y] & LSTAT_AUTOREGISTER)
161 if (tb->states[y] & LSTAT_BYPASS) color = TERM_SLATE;
162 else color = TERM_WHITE;
165 if (!tb->mark || (y < by1 || by2 < y))
167 Term_putstr(leftcol, i + 1, tb->wid - 1, color, msg);
171 Term_putstr(leftcol, i + 1, tb->wid - 1, TERM_YELLOW, msg);
175 int x0 = leftcol + tb->left;
176 int len = strlen(tb->lines_list[tb->cy]);
177 int bx1 = MIN(tb->mx, tb->cx);
178 int bx2 = MAX(tb->mx, tb->cx);
180 if (bx2 > len) bx2 = len;
182 Term_gotoxy(leftcol, i + 1);
183 if (x0 < bx1) Term_addstr(bx1 - x0, color, msg);
184 if (x0 < bx2) Term_addstr(bx2 - bx1, TERM_YELLOW, msg + (bx1 - x0));
185 Term_addstr(-1, color, msg + (bx2 - x0));
189 for (; i < tb->hgt; i++)
191 Term_erase(0, i + 1, tb->wid);
194 bool is_dirty_diary = (tb->dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND | DIRTY_NO_SEARCH)) != 0;
195 bool is_updated = tb->old_cy != tb->cy || is_dirty_diary || tb->dirty_line == tb->cy;
196 if (!is_updated) return;
198 autopick_type an_entry, *entry = &an_entry;
199 concptr str1 = NULL, str2 = NULL;
200 for (int j = 0; j < DESCRIPT_HGT; j++)
202 Term_erase(0, tb->hgt + 2 + j, tb->wid);
205 if (tb->dirty_flags & DIRTY_NOT_FOUND)
207 str1 = format(_("パターンが見つかりません: %s", "Pattern not found: %s"), tb->search_str);
209 else if (tb->dirty_flags & DIRTY_SKIP_INACTIVE)
211 str1 = format(_("無効状態の行をスキップしました。(%sを検索中)",
212 "Some inactive lines are skipped. (Searching %s)"), tb->search_str);
214 else if (tb->dirty_flags & DIRTY_INACTIVE)
216 str1 = format(_("無効状態の行だけが見付かりました。(%sを検索中)",
217 "Found only an inactive line. (Searching %s)"), tb->search_str);
219 else if (tb->dirty_flags & DIRTY_NO_SEARCH)
221 str1 = _("検索するパターンがありません(^S で検索)。", "No pattern to search. (Press ^S to search.)");
223 else if (tb->lines_list[tb->cy][0] == '#')
225 str1 = _("この行はコメントです。", "This line is a comment.");
227 else if (tb->lines_list[tb->cy][0] && tb->lines_list[tb->cy][1] == ':')
229 switch (tb->lines_list[tb->cy][0])
232 str1 = _("この行は条件分岐式です。", "This line is a Conditional Expression.");
235 str1 = _("この行はマクロの実行内容を定義します。", "This line defines a Macro action.");
238 str1 = _("この行はマクロのトリガー・キーを定義します。", "This line defines a Macro trigger key.");
241 str1 = _("この行はキー配置を定義します。", "This line defines a Keymap.");
245 switch (tb->lines_list[tb->cy][0])
248 if (tb->states[tb->cy] & LSTAT_BYPASS)
250 str2 = _("現在の式の値は「偽(=0)」です。", "The expression is 'False'(=0) currently.");
254 str2 = _("現在の式の値は「真(=1)」です。", "The expression is 'True'(=1) currently.");
259 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
261 str2 = _("この行は後で削除されます。", "This line will be delete later.");
264 else if (tb->states[tb->cy] & LSTAT_BYPASS)
266 str2 = _("この行は現在は無効な状態です。", "This line is bypassed currently.");
271 else if (autopick_new_entry(entry, tb->lines_list[tb->cy], FALSE))
273 char buf[MAX_LINELEN];
274 char temp[MAX_LINELEN];
277 describe_autopick(buf, entry);
279 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
281 strcat(buf, _("この行は後で削除されます。", " This line will be delete later."));
284 if (tb->states[tb->cy] & LSTAT_BYPASS)
286 strcat(buf, _("この行は現在は無効な状態です。", " This line is bypassed currently."));
289 roff_to_buf(buf, 81, temp, sizeof(temp));
291 for (int j = 0; j < 3; j++)
297 prt(t, tb->hgt + 1 + 1 + j, 0);
302 autopick_free_entry(entry);
305 if (str1) prt(str1, tb->hgt + 1 + 1, 0);
306 if (str2) prt(str2, tb->hgt + 1 + 2, 0);