2 * todo これ単体で750行を超えているので要分割
3 * @brief 自動拾いエディタ画面でキーを押した時の挙動一式
8 #include "autopick/autopick-editor-command.h"
9 #include "autopick/autopick-commands-table.h"
10 #include "autopick/autopick-dirty-flags.h"
11 #include "autopick/autopick-drawer.h"
12 #include "autopick/autopick-editor-util.h"
13 #include "autopick/autopick-entry.h"
14 #include "autopick/autopick-finder.h"
15 #include "autopick/autopick-flags-table.h"
16 #include "autopick/autopick-inserter-killer.h"
17 #include "autopick/autopick-methods-table.h"
18 #include "autopick/autopick-reader-writer.h"
19 #include "core/asking-player.h"
20 #include "core/show-file.h"
21 #include "game-option/input-options.h"
22 #include "game-option/keymap-directory-getter.h"
23 #include "player/player-class.h"
24 #include "player/player-race.h"
25 #include "term/term-color-types.h"
29 * @param player_ptr プレーヤーへの参照ポインタ
31 * @param com_id エディタ内で打ったコマンド
33 * @details Execute a single editor command
35 ape_quittance do_editor_command(player_type *player_ptr, text_body_type *tb, int com_id)
43 if (!get_check(_("全ての変更を破棄してから終了します。よろしいですか? ",
44 "Discard all changes and quit. Are you sure? "))) break;
47 return APE_QUIT_WITHOUT_SAVE;
50 return APE_QUIT_AND_SAVE;
53 if (!get_check(_("全ての変更を破棄して元の状態に戻します。よろしいですか? ",
54 "Discard all changes and revert to original file. Are you sure? "))) break;
56 free_text_lines(tb->lines_list);
57 tb->lines_list = read_pickpref_text_lines(player_ptr, &tb->filename_mode);
58 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
66 (void)show_file(player_ptr, TRUE, _("jeditor.txt", "editor.txt"), NULL, 0, 0);
67 tb->dirty_flags |= DIRTY_SCREEN;
75 tb->dirty_flags |= DIRTY_ALL;
78 insert_return_code(tb);
81 tb->dirty_flags |= DIRTY_ALL;
93 len = strlen(tb->lines_list[tb->cy]);
94 if (len < tb->cx) tb->cx = len;
96 for (i = 0; tb->lines_list[tb->cy][i]; i++)
98 if (iskanji(tb->lines_list[tb->cy][i]))
113 tb->cx = strlen(tb->lines_list[tb->cy]);
120 if (!tb->lines_list[tb->cy + 1])
122 if (!add_empty_line(tb)) break;
129 if (tb->cy > 0) tb->cy--;
134 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
137 int len = strlen(tb->lines_list[tb->cy]);
141 if (!tb->lines_list[tb->cy + 1])
143 if (!add_empty_line(tb)) break;
156 tb->cx = strlen(tb->lines_list[tb->cy]);
159 while (0 < tb->cy && tb->upper <= tb->cy)
162 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
167 while (tb->cy < tb->upper + tb->hgt)
169 if (!tb->lines_list[tb->cy + 1])
171 if (!add_empty_line(tb)) break;
185 if (!tb->lines_list[tb->cy + 1])
187 if (!add_empty_line(tb)) break;
197 copy_text_to_yank(tb);
198 if (tb->my == tb->cy)
200 int bx1 = MIN(tb->mx, tb->cx);
201 int bx2 = MAX(tb->mx, tb->cx);
202 int len = strlen(tb->lines_list[tb->cy]);
203 if (bx2 > len) bx2 = len;
205 kill_line_segment(tb, tb->cy, bx1, bx2, TRUE);
210 int by1 = MIN(tb->my, tb->cy);
211 int by2 = MAX(tb->my, tb->cy);
213 for (int y = by2; y >= by1; y--)
215 int len = strlen(tb->lines_list[y]);
217 kill_line_segment(tb, y, 0, len, TRUE);
225 tb->dirty_flags |= DIRTY_ALL;
231 copy_text_to_yank(tb);
234 * Move cursor position to the end of the selection
236 * Pressing ^C ^V correctly duplicates the selection.
238 if (tb->my != tb->cy)
240 tb->cy = MAX(tb->cy, tb->my);
241 if (!tb->lines_list[tb->cy + 1])
243 if (!add_empty_line(tb)) break;
250 tb->cx = MAX(tb->cx, tb->mx);
251 if (!tb->lines_list[tb->cy][tb->cx])
253 if (!tb->lines_list[tb->cy + 1])
255 if (!add_empty_line(tb)) break;
266 chain_str_type *chain = tb->yank;
267 int len = strlen(tb->lines_list[tb->cy]);
269 if (tb->cx > len) tb->cx = len;
274 tb->dirty_flags |= DIRTY_ALL;
279 concptr yank_str = chain->s;
280 char buf[MAX_LINELEN];
282 char rest[MAX_LINELEN], *rest_ptr = rest;
283 for (i = 0; i < tb->cx; i++)
284 buf[i] = tb->lines_list[tb->cy][i];
286 strcpy(rest, &(tb->lines_list[tb->cy][i]));
287 while (*yank_str && i < MAX_LINELEN - 1)
289 buf[i++] = *yank_str++;
294 if (chain || tb->yank_eol)
296 insert_return_code(tb);
297 string_free(tb->lines_list[tb->cy]);
298 tb->lines_list[tb->cy] = string_make(buf);
305 tb->cx = strlen(buf);
306 while (*rest_ptr && i < MAX_LINELEN - 1)
308 buf[i++] = *rest_ptr++;
312 string_free(tb->lines_list[tb->cy]);
313 tb->lines_list[tb->cy] = string_make(buf);
317 tb->dirty_flags |= DIRTY_ALL;
318 tb->dirty_flags |= DIRTY_EXPRESSION;
327 tb->dirty_flags |= DIRTY_ALL;
331 tb->mark = MARK_MARK;
332 if (com_id == tb->old_com_id)
340 tb->dirty_flags |= DIRTY_ALL;
344 int len = strlen(tb->lines_list[tb->cy]);
348 if (tb->cx > len) tb->mx = len;
353 int len = strlen(tb->lines_list[tb->cy]);
354 if (tb->cx > len) tb->cx = len;
359 tb->dirty_flags |= DIRTY_ALL;
362 if (tb->old_com_id != com_id)
370 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
371 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
372 tb->dirty_line = tb->cy;
376 if (tb->yank_eol) add_str_to_yank(tb, "");
379 do_editor_command(player_ptr, tb, EC_DELETE_CHAR);
387 tb->dirty_flags |= DIRTY_ALL;
391 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
394 int len = strlen(tb->lines_list[tb->cy]);
397 do_editor_command(player_ptr, tb, EC_BACKSPACE);
401 if (tb->lines_list[tb->cy + 1])
412 do_editor_command(player_ptr, tb, EC_BACKSPACE);
418 char buf[MAX_LINELEN];
422 tb->dirty_flags |= DIRTY_ALL;
425 len = strlen(tb->lines_list[tb->cy]);
426 if (len < tb->cx) tb->cx = len;
430 if (tb->cy == 0) break;
431 tb->cx = strlen(tb->lines_list[tb->cy - 1]);
432 strcpy(buf, tb->lines_list[tb->cy - 1]);
433 strcat(buf, tb->lines_list[tb->cy]);
434 string_free(tb->lines_list[tb->cy - 1]);
435 string_free(tb->lines_list[tb->cy]);
436 tb->lines_list[tb->cy - 1] = string_make(buf);
438 for (i = tb->cy; tb->lines_list[i + 1]; i++)
439 tb->lines_list[i] = tb->lines_list[i + 1];
441 tb->lines_list[i] = NULL;
443 tb->dirty_flags |= DIRTY_ALL;
444 tb->dirty_flags |= DIRTY_EXPRESSION;
449 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
453 if (iskanji(tb->lines_list[tb->cy][i]))
454 buf[j++] = tb->lines_list[tb->cy][i++];
456 buf[j++] = tb->lines_list[tb->cy][i];
465 for (; tb->lines_list[tb->cy][i]; i++)
467 buf[j++] = tb->lines_list[tb->cy][i];
471 string_free(tb->lines_list[tb->cy]);
472 tb->lines_list[tb->cy] = string_make(buf);
473 tb->dirty_line = tb->cy;
474 check_expression_line(tb, tb->cy);
481 tb->dirty_flags |= DIRTY_SCREEN;
482 search_dir = get_string_for_search(player_ptr, &tb->search_o_ptr, &tb->search_str);
484 if (!search_dir) break;
486 if (search_dir == 1) do_editor_command(player_ptr, tb, EC_SEARCH_FORW);
487 else do_editor_command(player_ptr, tb, EC_SEARCH_BACK);
492 if (tb->search_o_ptr)
494 search_for_object(player_ptr, tb, tb->search_o_ptr, TRUE);
498 if (tb->search_str && tb->search_str[0])
500 search_for_string(tb, tb->search_str, TRUE);
504 tb->dirty_flags |= DIRTY_NO_SEARCH;
509 if (tb->search_o_ptr)
511 search_for_object(player_ptr, tb, tb->search_o_ptr, FALSE);
515 if (tb->search_str && tb->search_str[0])
517 search_for_string(tb, tb->search_str, FALSE);
521 tb->dirty_flags |= DIRTY_NO_SEARCH;
526 tb->dirty_flags |= DIRTY_SCREEN;
528 if (!get_object_for_search(player_ptr, &tb->search_o_ptr, &tb->search_str)) break;
530 do_editor_command(player_ptr, tb, EC_SEARCH_FORW);
533 case EC_SEARCH_DESTROYED:
535 if (!get_destroyed_object_for_search(player_ptr, &tb->search_o_ptr, &tb->search_str))
537 tb->dirty_flags |= DIRTY_NO_SEARCH;
541 do_editor_command(player_ptr, tb, EC_SEARCH_FORW);
544 case EC_INSERT_OBJECT:
546 autopick_type an_entry, *entry = &an_entry;
547 if (!entry_from_choosed_object(player_ptr, entry))
549 tb->dirty_flags |= DIRTY_SCREEN;
554 insert_return_code(tb);
555 string_free(tb->lines_list[tb->cy]);
556 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
557 tb->dirty_flags |= DIRTY_SCREEN;
560 case EC_INSERT_DESTROYED:
562 if (!tb->last_destroyed) break;
565 insert_return_code(tb);
566 string_free(tb->lines_list[tb->cy]);
567 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
568 tb->dirty_flags |= DIRTY_ALL;
572 case EC_INSERT_BLOCK:
575 sprintf(expression, "?:[AND [EQU $RACE %s] [EQU $CLASS %s] [GEQ $LEVEL %02d]]",
577 rp_ptr->E_title, cp_ptr->E_title,
579 rp_ptr->title, cp_ptr->title,
583 insert_return_code(tb);
584 string_free(tb->lines_list[tb->cy]);
585 tb->lines_list[tb->cy] = string_make(expression);
587 insert_return_code(tb);
588 string_free(tb->lines_list[tb->cy]);
589 tb->lines_list[tb->cy] = string_make("?:1");
590 tb->dirty_flags |= DIRTY_ALL;
594 case EC_INSERT_MACRO:
596 draw_text_editor(player_ptr, tb);
597 term_erase(0, tb->cy - tb->upper + 1, tb->wid);
598 term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, _("P:<トリガーキー>: ", "P:<Trigger key>: "));
599 if (!insert_macro_line(tb)) break;
602 tb->dirty_flags |= DIRTY_ALL;
606 case EC_INSERT_KEYMAP:
608 draw_text_editor(player_ptr, tb);
609 term_erase(0, tb->cy - tb->upper + 1, tb->wid);
610 term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW,
611 format(_("C:%d:<コマンドキー>: ", "C:%d:<Keypress>: "), (rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG)));
613 if (!insert_keymap_line(tb)) break;
616 tb->dirty_flags |= DIRTY_ALL;
621 toggle_command_letter(tb, DO_AUTOPICK);
624 toggle_command_letter(tb, DO_AUTODESTROY);
627 toggle_command_letter(tb, DONT_AUTOPICK);
630 toggle_command_letter(tb, DO_QUERY_AUTOPICK);
633 toggle_command_letter(tb, DO_DISPLAY);
636 toggle_keyword(tb, FLG_UNAWARE);
638 case EC_IK_UNIDENTIFIED:
639 toggle_keyword(tb, FLG_UNIDENTIFIED);
641 case EC_IK_IDENTIFIED:
642 toggle_keyword(tb, FLG_IDENTIFIED);
644 case EC_IK_STAR_IDENTIFIED:
645 toggle_keyword(tb, FLG_STAR_IDENTIFIED);
648 toggle_keyword(tb, FLG_WEAPONS);
650 case EC_KK_FAVORITE_WEAPONS:
651 toggle_keyword(tb, FLG_FAVORITE_WEAPONS);
654 toggle_keyword(tb, FLG_ARMORS);
657 toggle_keyword(tb, FLG_MISSILES);
660 toggle_keyword(tb, FLG_DEVICES);
663 toggle_keyword(tb, FLG_LIGHTS);
666 toggle_keyword(tb, FLG_JUNKS);
669 toggle_keyword(tb, FLG_CORPSES);
671 case EC_KK_SPELLBOOKS:
672 toggle_keyword(tb, FLG_SPELLBOOKS);
675 toggle_keyword(tb, FLG_SHIELDS);
678 toggle_keyword(tb, FLG_BOWS);
681 toggle_keyword(tb, FLG_RINGS);
684 toggle_keyword(tb, FLG_AMULETS);
687 toggle_keyword(tb, FLG_SUITS);
690 toggle_keyword(tb, FLG_CLOAKS);
693 toggle_keyword(tb, FLG_HELMS);
696 toggle_keyword(tb, FLG_GLOVES);
699 toggle_keyword(tb, FLG_BOOTS);
701 case EC_OK_COLLECTING:
702 toggle_keyword(tb, FLG_COLLECTING);
705 toggle_keyword(tb, FLG_BOOSTED);
707 case EC_OK_MORE_DICE:
708 toggle_keyword(tb, FLG_MORE_DICE);
710 case EC_OK_MORE_BONUS:
711 toggle_keyword(tb, FLG_MORE_BONUS);
713 case EC_OK_WORTHLESS:
714 toggle_keyword(tb, FLG_WORTHLESS);
717 toggle_keyword(tb, FLG_ARTIFACT);
720 toggle_keyword(tb, FLG_EGO);
723 toggle_keyword(tb, FLG_GOOD);
726 toggle_keyword(tb, FLG_NAMELESS);
729 toggle_keyword(tb, FLG_AVERAGE);
732 toggle_keyword(tb, FLG_RARE);
735 toggle_keyword(tb, FLG_COMMON);
738 toggle_keyword(tb, FLG_WANTED);
741 toggle_keyword(tb, FLG_UNIQUE);
744 toggle_keyword(tb, FLG_HUMAN);
746 case EC_OK_UNREADABLE:
747 toggle_keyword(tb, FLG_UNREADABLE);
748 add_keyword(tb, FLG_SPELLBOOKS);
751 toggle_keyword(tb, FLG_REALM1);
752 add_keyword(tb, FLG_SPELLBOOKS);
755 toggle_keyword(tb, FLG_REALM2);
756 add_keyword(tb, FLG_SPELLBOOKS);
759 toggle_keyword(tb, FLG_FIRST);
760 add_keyword(tb, FLG_SPELLBOOKS);
763 toggle_keyword(tb, FLG_SECOND);
764 add_keyword(tb, FLG_SPELLBOOKS);
767 toggle_keyword(tb, FLG_THIRD);
768 add_keyword(tb, FLG_SPELLBOOKS);
771 toggle_keyword(tb, FLG_FOURTH);
772 add_keyword(tb, FLG_SPELLBOOKS);
776 tb->old_com_id = com_id;