2 * @brief 自動拾いエディタ画面でキーを押した時の挙動一式
5 * @todo これ単体で700行を超えているので要分割
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 "autopick/autopick-util.h"
20 #include "core/asking-player.h"
21 #include "core/show-file.h"
22 #include "game-option/input-options.h"
23 #include "game-option/keymap-directory-getter.h"
24 #include "player-info/class-info.h"
25 #include "player-info/race-info.h"
26 #include "system/player-type-definition.h"
27 #include "term/term-color-types.h"
28 #include "term/z-form.h"
32 * @param player_ptr プレイヤーへの参照ポインタ
34 * @param com_id エディタ内で打ったコマンド
36 * @details Execute a single editor command
38 ape_quittance do_editor_command(PlayerType *player_ptr, text_body_type *tb, int com_id)
43 if (!get_check(_("全ての変更を破棄してから終了します。よろしいですか? ", "Discard all changes and quit. Are you sure? "))) {
48 return APE_QUIT_WITHOUT_SAVE;
51 return APE_QUIT_AND_SAVE;
53 if (!get_check(_("全ての変更を破棄して元の状態に戻します。よろしいですか? ", "Discard all changes and revert to original file. Are you sure? "))) {
57 free_text_lines(tb->lines_list);
58 tb->lines_list = read_pickpref_text_lines(player_ptr, &tb->filename_mode);
59 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
66 (void)show_file(player_ptr, true, _("jeditor.txt", "editor.txt"), 0, 0);
67 tb->dirty_flags |= DIRTY_SCREEN;
73 tb->dirty_flags |= DIRTY_ALL;
76 if (!insert_return_code(tb)) {
81 tb->dirty_flags |= DIRTY_ALL;
91 len = strlen(tb->lines_list[tb->cy]);
96 for (i = 0; tb->lines_list[tb->cy][i]; i++) {
97 if (iskanji(tb->lines_list[tb->cy][i])) {
106 } else if (tb->cy > 0) {
108 tb->cx = strlen(tb->lines_list[tb->cy]);
114 if (!tb->lines_list[tb->cy + 1]) {
115 if (!add_empty_line(tb)) {
130 if (iskanji(tb->lines_list[tb->cy][tb->cx])) {
135 int len = strlen(tb->lines_list[tb->cy]);
138 if (!tb->lines_list[tb->cy + 1]) {
139 if (!add_empty_line(tb)) {
154 tb->cx = strlen(tb->lines_list[tb->cy]);
157 while (0 < tb->cy && tb->upper <= tb->cy) {
161 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt) {
167 while (tb->cy < tb->upper + tb->hgt) {
168 if (!tb->lines_list[tb->cy + 1]) {
169 if (!add_empty_line(tb)) {
184 if (!tb->lines_list[tb->cy + 1]) {
185 if (!add_empty_line(tb)) {
196 copy_text_to_yank(tb);
197 if (tb->my == tb->cy) {
198 int bx1 = std::min(tb->mx, tb->cx);
199 int bx2 = std::max(tb->mx, tb->cx);
200 int len = strlen(tb->lines_list[tb->cy]);
205 kill_line_segment(tb, tb->cy, bx1, bx2, true);
208 int by1 = std::min(tb->my, tb->cy);
209 int by2 = std::max(tb->my, tb->cy);
211 for (int y = by2; y >= by1; y--) {
212 int len = strlen(tb->lines_list[y]);
214 kill_line_segment(tb, y, 0, len, true);
222 tb->dirty_flags |= DIRTY_ALL;
227 copy_text_to_yank(tb);
230 * Move cursor position to the end of the selection
232 * Pressing ^C ^V correctly duplicates the selection.
234 if (tb->my != tb->cy) {
235 tb->cy = std::max(tb->cy, tb->my);
236 if (!tb->lines_list[tb->cy + 1]) {
237 if (!add_empty_line(tb)) {
246 tb->cx = std::max(tb->cx, tb->mx);
247 if (!tb->lines_list[tb->cy][tb->cx]) {
248 if (!tb->lines_list[tb->cy + 1]) {
249 if (!add_empty_line(tb)) {
261 chain_str_type *chain = tb->yank;
262 int len = strlen(tb->lines_list[tb->cy]);
272 tb->dirty_flags |= DIRTY_ALL;
276 concptr yank_str = chain->s;
277 char buf[MAX_LINELEN];
279 char rest[MAX_LINELEN], *rest_ptr = rest;
280 for (i = 0; i < tb->cx; i++) {
281 buf[i] = tb->lines_list[tb->cy][i];
284 strcpy(rest, &(tb->lines_list[tb->cy][i]));
285 while (*yank_str && i < MAX_LINELEN - 1) {
286 buf[i++] = *yank_str++;
291 if (chain || tb->yank_eol) {
292 if (!insert_return_code(tb)) {
295 string_free(tb->lines_list[tb->cy]);
296 tb->lines_list[tb->cy] = string_make(buf);
303 tb->cx = strlen(buf);
304 while (*rest_ptr && i < MAX_LINELEN - 1) {
305 buf[i++] = *rest_ptr++;
309 string_free(tb->lines_list[tb->cy]);
310 tb->lines_list[tb->cy] = string_make(buf);
314 tb->dirty_flags |= DIRTY_ALL;
315 tb->dirty_flags |= DIRTY_EXPRESSION;
322 tb->dirty_flags |= DIRTY_ALL;
326 tb->mark = MARK_MARK;
327 if (com_id == tb->old_com_id) {
334 tb->dirty_flags |= DIRTY_ALL;
338 int len = strlen(tb->lines_list[tb->cy]);
348 int len = strlen(tb->lines_list[tb->cy]);
355 tb->dirty_flags |= DIRTY_ALL;
358 if (tb->old_com_id != com_id) {
364 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
365 kill_line_segment(tb, tb->cy, tb->cx, len, false);
366 tb->dirty_line = tb->cy;
371 add_str_to_yank(tb, "");
375 do_editor_command(player_ptr, tb, EC_DELETE_CHAR);
378 case EC_DELETE_CHAR: {
381 tb->dirty_flags |= DIRTY_ALL;
385 if (iskanji(tb->lines_list[tb->cy][tb->cx])) {
390 int len = strlen(tb->lines_list[tb->cy]);
392 do_editor_command(player_ptr, tb, EC_BACKSPACE);
396 if (tb->lines_list[tb->cy + 1]) {
404 do_editor_command(player_ptr, tb, EC_BACKSPACE);
409 char buf[MAX_LINELEN];
412 tb->dirty_flags |= DIRTY_ALL;
415 len = strlen(tb->lines_list[tb->cy]);
424 tb->cx = strlen(tb->lines_list[tb->cy - 1]);
425 strcpy(buf, tb->lines_list[tb->cy - 1]);
426 strcat(buf, tb->lines_list[tb->cy]);
427 string_free(tb->lines_list[tb->cy - 1]);
428 string_free(tb->lines_list[tb->cy]);
429 tb->lines_list[tb->cy - 1] = string_make(buf);
431 for (i = tb->cy; tb->lines_list[i + 1]; i++) {
432 tb->lines_list[i] = tb->lines_list[i + 1];
435 tb->lines_list[i] = nullptr;
437 tb->dirty_flags |= DIRTY_ALL;
438 tb->dirty_flags |= DIRTY_EXPRESSION;
443 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++) {
446 if (iskanji(tb->lines_list[tb->cy][i])) {
447 buf[j++] = tb->lines_list[tb->cy][i++];
450 buf[j++] = tb->lines_list[tb->cy][i];
458 for (; tb->lines_list[tb->cy][i]; i++) {
459 buf[j++] = tb->lines_list[tb->cy][i];
463 string_free(tb->lines_list[tb->cy]);
464 tb->lines_list[tb->cy] = string_make(buf);
465 tb->dirty_line = tb->cy;
466 check_expression_line(tb, tb->cy);
470 case EC_SEARCH_STR: {
472 tb->dirty_flags |= DIRTY_SCREEN;
473 search_dir = get_string_for_search(player_ptr, &tb->search_o_ptr, &tb->search_str);
479 if (search_dir == 1) {
480 do_editor_command(player_ptr, tb, EC_SEARCH_FORW);
482 do_editor_command(player_ptr, tb, EC_SEARCH_BACK);
488 if (tb->search_o_ptr) {
489 search_for_object(player_ptr, tb, tb->search_o_ptr, true);
493 if (tb->search_str && tb->search_str[0]) {
494 search_for_string(tb, tb->search_str, true);
498 tb->dirty_flags |= DIRTY_NO_SEARCH;
501 case EC_SEARCH_BACK: {
502 if (tb->search_o_ptr) {
503 search_for_object(player_ptr, tb, tb->search_o_ptr, false);
507 if (tb->search_str && tb->search_str[0]) {
508 search_for_string(tb, tb->search_str, false);
512 tb->dirty_flags |= DIRTY_NO_SEARCH;
515 case EC_SEARCH_OBJ: {
516 tb->dirty_flags |= DIRTY_SCREEN;
518 if (!get_object_for_search(player_ptr, &tb->search_o_ptr, &tb->search_str)) {
522 do_editor_command(player_ptr, tb, EC_SEARCH_FORW);
525 case EC_SEARCH_DESTROYED: {
526 if (!get_destroyed_object_for_search(player_ptr, &tb->search_o_ptr, &tb->search_str)) {
527 tb->dirty_flags |= DIRTY_NO_SEARCH;
531 do_editor_command(player_ptr, tb, EC_SEARCH_FORW);
534 case EC_INSERT_OBJECT: {
535 autopick_type an_entry, *entry = &an_entry;
536 if (!entry_from_choosed_object(player_ptr, entry)) {
537 tb->dirty_flags |= DIRTY_SCREEN;
542 if (!insert_return_code(tb)) {
545 string_free(tb->lines_list[tb->cy]);
546 tb->lines_list[tb->cy] = autopick_line_from_entry(*entry);
547 tb->dirty_flags |= DIRTY_SCREEN;
550 case EC_INSERT_DESTROYED: {
551 if (!tb->last_destroyed) {
556 if (!insert_return_code(tb)) {
559 string_free(tb->lines_list[tb->cy]);
560 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
561 tb->dirty_flags |= DIRTY_ALL;
565 case EC_INSERT_BLOCK: {
566 if (!can_insert_line(tb, 2)) {
570 strnfmt(expression, sizeof(expression), "?:[AND [EQU $RACE %s] [EQU $CLASS %s] [GEQ $LEVEL %02d]]",
572 rp_ptr->E_title, cp_ptr->E_title,
574 rp_ptr->title, cp_ptr->title,
578 insert_return_code(tb);
579 string_free(tb->lines_list[tb->cy]);
580 tb->lines_list[tb->cy] = string_make(expression);
582 insert_return_code(tb);
583 string_free(tb->lines_list[tb->cy]);
584 tb->lines_list[tb->cy] = string_make("?:1");
585 tb->dirty_flags |= DIRTY_ALL;
589 case EC_INSERT_MACRO: {
590 draw_text_editor(player_ptr, tb);
591 term_erase(0, tb->cy - tb->upper + 1, tb->wid);
592 term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, _("P:<トリガーキー>: ", "P:<Trigger key>: "));
593 if (!insert_macro_line(tb)) {
598 tb->dirty_flags |= DIRTY_ALL;
602 case EC_INSERT_KEYMAP: {
603 draw_text_editor(player_ptr, tb);
604 term_erase(0, tb->cy - tb->upper + 1, tb->wid);
605 term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW,
606 format(_("C:%d:<コマンドキー>: ", "C:%d:<Keypress>: "), (rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG)));
608 if (!insert_keymap_line(tb)) {
613 tb->dirty_flags |= DIRTY_ALL;
618 toggle_command_letter(tb, DO_AUTOPICK);
621 toggle_command_letter(tb, DO_AUTODESTROY);
624 toggle_command_letter(tb, DONT_AUTOPICK);
627 toggle_command_letter(tb, DO_QUERY_AUTOPICK);
630 toggle_command_letter(tb, DO_DISPLAY);
633 toggle_keyword(tb, FLG_UNAWARE);
635 case EC_IK_UNIDENTIFIED:
636 toggle_keyword(tb, FLG_UNIDENTIFIED);
638 case EC_IK_IDENTIFIED:
639 toggle_keyword(tb, FLG_IDENTIFIED);
641 case EC_IK_STAR_IDENTIFIED:
642 toggle_keyword(tb, FLG_STAR_IDENTIFIED);
645 toggle_keyword(tb, FLG_WEAPONS);
647 case EC_KK_FAVORITE_WEAPONS:
648 toggle_keyword(tb, FLG_FAVORITE_WEAPONS);
651 toggle_keyword(tb, FLG_ARMORS);
654 toggle_keyword(tb, FLG_MISSILES);
657 toggle_keyword(tb, FLG_DEVICES);
660 toggle_keyword(tb, FLG_LIGHTS);
663 toggle_keyword(tb, FLG_JUNKS);
666 toggle_keyword(tb, FLG_CORPSES);
668 case EC_KK_SPELLBOOKS:
669 toggle_keyword(tb, FLG_SPELLBOOKS);
672 toggle_keyword(tb, FLG_SHIELDS);
675 toggle_keyword(tb, FLG_BOWS);
678 toggle_keyword(tb, FLG_RINGS);
681 toggle_keyword(tb, FLG_AMULETS);
684 toggle_keyword(tb, FLG_SUITS);
687 toggle_keyword(tb, FLG_CLOAKS);
690 toggle_keyword(tb, FLG_HELMS);
693 toggle_keyword(tb, FLG_GLOVES);
696 toggle_keyword(tb, FLG_BOOTS);
698 case EC_OK_COLLECTING:
699 toggle_keyword(tb, FLG_COLLECTING);
702 toggle_keyword(tb, FLG_BOOSTED);
704 case EC_OK_MORE_DICE:
705 toggle_keyword(tb, FLG_MORE_DICE);
707 case EC_OK_MORE_BONUS:
708 toggle_keyword(tb, FLG_MORE_BONUS);
710 case EC_OK_WORTHLESS:
711 toggle_keyword(tb, FLG_WORTHLESS);
714 toggle_keyword(tb, FLG_ARTIFACT);
717 toggle_keyword(tb, FLG_EGO);
720 toggle_keyword(tb, FLG_GOOD);
723 toggle_keyword(tb, FLG_NAMELESS);
726 toggle_keyword(tb, FLG_AVERAGE);
729 toggle_keyword(tb, FLG_RARE);
732 toggle_keyword(tb, FLG_COMMON);
735 toggle_keyword(tb, FLG_WANTED);
738 toggle_keyword(tb, FLG_UNIQUE);
741 toggle_keyword(tb, FLG_HUMAN);
743 case EC_OK_UNREADABLE:
744 toggle_keyword(tb, FLG_UNREADABLE);
745 add_keyword(tb, FLG_SPELLBOOKS);
748 toggle_keyword(tb, FLG_REALM1);
749 add_keyword(tb, FLG_SPELLBOOKS);
752 toggle_keyword(tb, FLG_REALM2);
753 add_keyword(tb, FLG_SPELLBOOKS);
756 toggle_keyword(tb, FLG_FIRST);
757 add_keyword(tb, FLG_SPELLBOOKS);
760 toggle_keyword(tb, FLG_SECOND);
761 add_keyword(tb, FLG_SPELLBOOKS);
764 toggle_keyword(tb, FLG_THIRD);
765 add_keyword(tb, FLG_SPELLBOOKS);
768 toggle_keyword(tb, FLG_FOURTH);
769 add_keyword(tb, FLG_SPELLBOOKS);
773 tb->old_com_id = com_id;