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/show-file.h"
20 #include "game-option/input-options.h"
21 #include "term/term-color-types.h"
25 * @param player_ptr プレーヤーへの参照ポインタ
27 * @param com_id エディタ内で打ったコマンド
29 * @details Execute a single editor command
31 ape_quittance do_editor_command(player_type *player_ptr, text_body_type *tb, int com_id)
39 if (!get_check(_("全ての変更を破棄してから終了します。よろしいですか? ",
40 "Discard all changes and quit. Are you sure? "))) break;
43 return APE_QUIT_WITHOUT_SAVE;
46 return APE_QUIT_AND_SAVE;
49 if (!get_check(_("全ての変更を破棄して元の状態に戻します。よろしいですか? ",
50 "Discard all changes and revert to original file. Are you sure? "))) break;
52 free_text_lines(tb->lines_list);
53 tb->lines_list = read_pickpref_text_lines(player_ptr, &tb->filename_mode);
54 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
62 (void)show_file(player_ptr, TRUE, _("jeditor.txt", "editor.txt"), NULL, 0, 0);
63 tb->dirty_flags |= DIRTY_SCREEN;
71 tb->dirty_flags |= DIRTY_ALL;
74 insert_return_code(tb);
77 tb->dirty_flags |= DIRTY_ALL;
89 len = strlen(tb->lines_list[tb->cy]);
90 if (len < tb->cx) tb->cx = len;
92 for (i = 0; tb->lines_list[tb->cy][i]; i++)
94 if (iskanji(tb->lines_list[tb->cy][i]))
109 tb->cx = strlen(tb->lines_list[tb->cy]);
116 if (!tb->lines_list[tb->cy + 1])
118 if (!add_empty_line(tb)) break;
125 if (tb->cy > 0) tb->cy--;
130 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
133 int len = strlen(tb->lines_list[tb->cy]);
137 if (!tb->lines_list[tb->cy + 1])
139 if (!add_empty_line(tb)) break;
152 tb->cx = strlen(tb->lines_list[tb->cy]);
155 while (0 < tb->cy && tb->upper <= tb->cy)
158 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
163 while (tb->cy < tb->upper + tb->hgt)
165 if (!tb->lines_list[tb->cy + 1])
167 if (!add_empty_line(tb)) break;
181 if (!tb->lines_list[tb->cy + 1])
183 if (!add_empty_line(tb)) break;
193 copy_text_to_yank(tb);
194 if (tb->my == tb->cy)
196 int bx1 = MIN(tb->mx, tb->cx);
197 int bx2 = MAX(tb->mx, tb->cx);
198 int len = strlen(tb->lines_list[tb->cy]);
199 if (bx2 > len) bx2 = len;
201 kill_line_segment(tb, tb->cy, bx1, bx2, TRUE);
206 int by1 = MIN(tb->my, tb->cy);
207 int by2 = MAX(tb->my, tb->cy);
209 for (int y = by2; y >= by1; y--)
211 int len = strlen(tb->lines_list[y]);
213 kill_line_segment(tb, y, 0, len, TRUE);
221 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)
236 tb->cy = MAX(tb->cy, tb->my);
237 if (!tb->lines_list[tb->cy + 1])
239 if (!add_empty_line(tb)) break;
246 tb->cx = MAX(tb->cx, tb->mx);
247 if (!tb->lines_list[tb->cy][tb->cx])
249 if (!tb->lines_list[tb->cy + 1])
251 if (!add_empty_line(tb)) break;
262 chain_str_type *chain = tb->yank;
263 int len = strlen(tb->lines_list[tb->cy]);
265 if (tb->cx > len) tb->cx = len;
270 tb->dirty_flags |= DIRTY_ALL;
275 concptr yank_str = chain->s;
276 char buf[MAX_LINELEN];
278 char rest[MAX_LINELEN], *rest_ptr = rest;
279 for (i = 0; i < tb->cx; i++)
280 buf[i] = tb->lines_list[tb->cy][i];
282 strcpy(rest, &(tb->lines_list[tb->cy][i]));
283 while (*yank_str && i < MAX_LINELEN - 1)
285 buf[i++] = *yank_str++;
290 if (chain || tb->yank_eol)
292 insert_return_code(tb);
293 string_free(tb->lines_list[tb->cy]);
294 tb->lines_list[tb->cy] = string_make(buf);
301 tb->cx = strlen(buf);
302 while (*rest_ptr && i < MAX_LINELEN - 1)
304 buf[i++] = *rest_ptr++;
308 string_free(tb->lines_list[tb->cy]);
309 tb->lines_list[tb->cy] = string_make(buf);
313 tb->dirty_flags |= DIRTY_ALL;
314 tb->dirty_flags |= DIRTY_EXPRESSION;
323 tb->dirty_flags |= DIRTY_ALL;
327 tb->mark = MARK_MARK;
328 if (com_id == tb->old_com_id)
336 tb->dirty_flags |= DIRTY_ALL;
340 int len = strlen(tb->lines_list[tb->cy]);
344 if (tb->cx > len) tb->mx = len;
349 int len = strlen(tb->lines_list[tb->cy]);
350 if (tb->cx > len) tb->cx = len;
355 tb->dirty_flags |= DIRTY_ALL;
358 if (tb->old_com_id != com_id)
366 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
367 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
368 tb->dirty_line = tb->cy;
372 if (tb->yank_eol) add_str_to_yank(tb, "");
375 do_editor_command(player_ptr, tb, EC_DELETE_CHAR);
383 tb->dirty_flags |= DIRTY_ALL;
387 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
390 int len = strlen(tb->lines_list[tb->cy]);
393 do_editor_command(player_ptr, tb, EC_BACKSPACE);
397 if (tb->lines_list[tb->cy + 1])
408 do_editor_command(player_ptr, tb, EC_BACKSPACE);
414 char buf[MAX_LINELEN];
418 tb->dirty_flags |= DIRTY_ALL;
421 len = strlen(tb->lines_list[tb->cy]);
422 if (len < tb->cx) tb->cx = len;
426 if (tb->cy == 0) break;
427 tb->cx = strlen(tb->lines_list[tb->cy - 1]);
428 strcpy(buf, tb->lines_list[tb->cy - 1]);
429 strcat(buf, tb->lines_list[tb->cy]);
430 string_free(tb->lines_list[tb->cy - 1]);
431 string_free(tb->lines_list[tb->cy]);
432 tb->lines_list[tb->cy - 1] = string_make(buf);
434 for (i = tb->cy; tb->lines_list[i + 1]; i++)
435 tb->lines_list[i] = tb->lines_list[i + 1];
437 tb->lines_list[i] = NULL;
439 tb->dirty_flags |= DIRTY_ALL;
440 tb->dirty_flags |= DIRTY_EXPRESSION;
445 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
449 if (iskanji(tb->lines_list[tb->cy][i]))
450 buf[j++] = tb->lines_list[tb->cy][i++];
452 buf[j++] = tb->lines_list[tb->cy][i];
461 for (; tb->lines_list[tb->cy][i]; i++)
463 buf[j++] = tb->lines_list[tb->cy][i];
467 string_free(tb->lines_list[tb->cy]);
468 tb->lines_list[tb->cy] = string_make(buf);
469 tb->dirty_line = tb->cy;
470 check_expression_line(tb, tb->cy);
477 tb->dirty_flags |= DIRTY_SCREEN;
478 search_dir = get_string_for_search(player_ptr, &tb->search_o_ptr, &tb->search_str);
480 if (!search_dir) break;
482 if (search_dir == 1) do_editor_command(player_ptr, tb, EC_SEARCH_FORW);
483 else do_editor_command(player_ptr, tb, EC_SEARCH_BACK);
488 if (tb->search_o_ptr)
490 search_for_object(player_ptr, tb, tb->search_o_ptr, TRUE);
494 if (tb->search_str && tb->search_str[0])
496 search_for_string(tb, tb->search_str, TRUE);
500 tb->dirty_flags |= DIRTY_NO_SEARCH;
505 if (tb->search_o_ptr)
507 search_for_object(player_ptr, tb, tb->search_o_ptr, FALSE);
511 if (tb->search_str && tb->search_str[0])
513 search_for_string(tb, tb->search_str, FALSE);
517 tb->dirty_flags |= DIRTY_NO_SEARCH;
522 tb->dirty_flags |= DIRTY_SCREEN;
524 if (!get_object_for_search(player_ptr, &tb->search_o_ptr, &tb->search_str)) break;
526 do_editor_command(player_ptr, tb, EC_SEARCH_FORW);
529 case EC_SEARCH_DESTROYED:
531 if (!get_destroyed_object_for_search(player_ptr, &tb->search_o_ptr, &tb->search_str))
533 tb->dirty_flags |= DIRTY_NO_SEARCH;
537 do_editor_command(player_ptr, tb, EC_SEARCH_FORW);
540 case EC_INSERT_OBJECT:
542 autopick_type an_entry, *entry = &an_entry;
543 if (!entry_from_choosed_object(player_ptr, entry))
545 tb->dirty_flags |= DIRTY_SCREEN;
550 insert_return_code(tb);
551 string_free(tb->lines_list[tb->cy]);
552 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
553 tb->dirty_flags |= DIRTY_SCREEN;
556 case EC_INSERT_DESTROYED:
558 if (!tb->last_destroyed) break;
561 insert_return_code(tb);
562 string_free(tb->lines_list[tb->cy]);
563 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
564 tb->dirty_flags |= DIRTY_ALL;
568 case EC_INSERT_BLOCK:
571 sprintf(expression, "?:[AND [EQU $RACE %s] [EQU $CLASS %s] [GEQ $LEVEL %02d]]",
573 rp_ptr->E_title, cp_ptr->E_title,
575 rp_ptr->title, cp_ptr->title,
579 insert_return_code(tb);
580 string_free(tb->lines_list[tb->cy]);
581 tb->lines_list[tb->cy] = string_make(expression);
583 insert_return_code(tb);
584 string_free(tb->lines_list[tb->cy]);
585 tb->lines_list[tb->cy] = string_make("?:1");
586 tb->dirty_flags |= DIRTY_ALL;
590 case EC_INSERT_MACRO:
592 draw_text_editor(player_ptr, tb);
593 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
594 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, _("P:<トリガーキー>: ", "P:<Trigger key>: "));
595 if (!insert_macro_line(tb)) break;
598 tb->dirty_flags |= DIRTY_ALL;
602 case EC_INSERT_KEYMAP:
604 draw_text_editor(player_ptr, tb);
605 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
606 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW,
607 format(_("C:%d:<コマンドキー>: ", "C:%d:<Keypress>: "), (rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG)));
609 if (!insert_keymap_line(tb)) break;
612 tb->dirty_flags |= DIRTY_ALL;
617 toggle_command_letter(tb, DO_AUTOPICK);
620 toggle_command_letter(tb, DO_AUTODESTROY);
623 toggle_command_letter(tb, DONT_AUTOPICK);
626 toggle_command_letter(tb, DO_QUERY_AUTOPICK);
629 toggle_command_letter(tb, DO_DISPLAY);
632 toggle_keyword(tb, FLG_UNAWARE);
634 case EC_IK_UNIDENTIFIED:
635 toggle_keyword(tb, FLG_UNIDENTIFIED);
637 case EC_IK_IDENTIFIED:
638 toggle_keyword(tb, FLG_IDENTIFIED);
640 case EC_IK_STAR_IDENTIFIED:
641 toggle_keyword(tb, FLG_STAR_IDENTIFIED);
644 toggle_keyword(tb, FLG_WEAPONS);
646 case EC_KK_FAVORITE_WEAPONS:
647 toggle_keyword(tb, FLG_FAVORITE_WEAPONS);
650 toggle_keyword(tb, FLG_ARMORS);
653 toggle_keyword(tb, FLG_MISSILES);
656 toggle_keyword(tb, FLG_DEVICES);
659 toggle_keyword(tb, FLG_LIGHTS);
662 toggle_keyword(tb, FLG_JUNKS);
665 toggle_keyword(tb, FLG_CORPSES);
667 case EC_KK_SPELLBOOKS:
668 toggle_keyword(tb, FLG_SPELLBOOKS);
671 toggle_keyword(tb, FLG_SHIELDS);
674 toggle_keyword(tb, FLG_BOWS);
677 toggle_keyword(tb, FLG_RINGS);
680 toggle_keyword(tb, FLG_AMULETS);
683 toggle_keyword(tb, FLG_SUITS);
686 toggle_keyword(tb, FLG_CLOAKS);
689 toggle_keyword(tb, FLG_HELMS);
692 toggle_keyword(tb, FLG_GLOVES);
695 toggle_keyword(tb, FLG_BOOTS);
697 case EC_OK_COLLECTING:
698 toggle_keyword(tb, FLG_COLLECTING);
701 toggle_keyword(tb, FLG_BOOSTED);
703 case EC_OK_MORE_DICE:
704 toggle_keyword(tb, FLG_MORE_DICE);
706 case EC_OK_MORE_BONUS:
707 toggle_keyword(tb, FLG_MORE_BONUS);
709 case EC_OK_WORTHLESS:
710 toggle_keyword(tb, FLG_WORTHLESS);
713 toggle_keyword(tb, FLG_ARTIFACT);
716 toggle_keyword(tb, FLG_EGO);
719 toggle_keyword(tb, FLG_GOOD);
722 toggle_keyword(tb, FLG_NAMELESS);
725 toggle_keyword(tb, FLG_AVERAGE);
728 toggle_keyword(tb, FLG_RARE);
731 toggle_keyword(tb, FLG_COMMON);
734 toggle_keyword(tb, FLG_WANTED);
737 toggle_keyword(tb, FLG_UNIQUE);
740 toggle_keyword(tb, FLG_HUMAN);
742 case EC_OK_UNREADABLE:
743 toggle_keyword(tb, FLG_UNREADABLE);
744 add_keyword(tb, FLG_SPELLBOOKS);
747 toggle_keyword(tb, FLG_REALM1);
748 add_keyword(tb, FLG_SPELLBOOKS);
751 toggle_keyword(tb, FLG_REALM2);
752 add_keyword(tb, FLG_SPELLBOOKS);
755 toggle_keyword(tb, FLG_FIRST);
756 add_keyword(tb, FLG_SPELLBOOKS);
759 toggle_keyword(tb, FLG_SECOND);
760 add_keyword(tb, FLG_SPELLBOOKS);
763 toggle_keyword(tb, FLG_THIRD);
764 add_keyword(tb, FLG_SPELLBOOKS);
767 toggle_keyword(tb, FLG_FOURTH);
768 add_keyword(tb, FLG_SPELLBOOKS);
772 tb->old_com_id = com_id;