1 #include "cmd-io/cmd-autopick.h"
2 #include "autopick/autopick-command-menu.h"
3 #include "autopick/autopick-commands-table.h"
4 #include "autopick/autopick-dirty-flags.h"
5 #include "autopick/autopick-drawer.h"
6 #include "autopick/autopick-editor-command.h"
7 #include "autopick/autopick-editor-util.h"
8 #include "autopick/autopick-entry.h"
9 #include "autopick/autopick-initializer.h"
10 #include "autopick/autopick-inserter-killer.h"
11 #include "autopick/autopick-pref-processor.h"
12 #include "autopick/autopick-reader-writer.h"
13 #include "autopick/autopick-util.h"
14 #include "cmd-io/cmd-save.h"
15 #include "io/input-key-acceptor.h"
16 #include "io/read-pref-file.h"
17 #include "system/item-entity.h"
18 #include "term/screen-processor.h"
19 #include "util/int-char-converter.h"
20 #include "world/world.h"
23 * Check special key code and get a movement command id
25 static int analyze_move_key(text_body_type *tb, int skey)
28 if (!(skey & SKEY_MASK)) {
32 switch (skey & ~SKEY_MOD_MASK) {
61 if (!(skey & SKEY_MOD_SHIFT)) {
63 * Un-shifted cursor keys cancells
64 * selection created by shift+cursor.
66 if (tb->mark & MARK_BY_SHIFT) {
68 tb->dirty_flags |= DIRTY_ALL;
78 int len = strlen(tb->lines_list[tb->cy]);
79 tb->mark = MARK_MARK | MARK_BY_SHIFT;
86 if (com_id == EC_UP || com_id == EC_DOWN) {
87 tb->dirty_flags |= DIRTY_ALL;
89 tb->dirty_line = tb->cy;
96 * In-game editor of Object Auto-picker/Destoryer
97 * @param player_ptr プレイヤーへの参照ポインタ
99 void do_cmd_edit_autopick(PlayerType *player_ptr)
101 static int cx_save = 0;
102 static int cy_save = 0;
103 autopick_type an_entry, *entry = &an_entry;
106 static int32_t old_autosave_turn = 0L;
107 ape_quittance quit = APE_QUIT;
109 text_body_type text_body;
110 text_body_type *tb = &text_body;
114 tb->upper = tb->left = 0;
117 tb->old_cy = tb->old_upper = tb->old_left = -1;
118 tb->old_wid = tb->old_hgt = -1;
122 tb->search_o_ptr = nullptr;
123 tb->search_str = nullptr;
124 tb->last_destroyed = nullptr;
125 tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
127 tb->filename_mode = PT_DEFAULT;
129 if (w_ptr->game_turn < old_autosave_turn) {
130 while (old_autosave_turn > w_ptr->game_turn) {
131 old_autosave_turn -= TURNS_PER_TICK * TOWN_DAWN;
135 if (w_ptr->game_turn > old_autosave_turn + 100L) {
136 do_cmd_save_game(player_ptr, true);
137 old_autosave_turn = w_ptr->game_turn;
142 if (autopick_last_destroyed_object.is_valid()) {
143 autopick_entry_from_object(player_ptr, entry, &autopick_last_destroyed_object);
144 tb->last_destroyed = autopick_line_from_entry(*entry);
147 tb->lines_list = read_pickpref_text_lines(player_ptr, &tb->filename_mode);
148 for (i = 0; i < tb->cy; i++) {
149 if (!tb->lines_list[i]) {
155 TermCenteredOffsetSetter tcos(std::nullopt, std::nullopt);
158 while (quit == APE_QUIT) {
160 draw_text_editor(player_ptr, tb);
161 prt(_("(^Q:終了 ^W:セーブして終了, ESC:メニュー, その他:入力)",
162 "(^Q:Quit, ^W:Save&Quit, ESC:Menu, Other:Input text)"),
165 prt(format("(%d,%d)", tb->cx, tb->cy), 0, 60);
167 prt(format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60);
170 term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1);
174 tb->old_upper = tb->upper;
175 tb->old_left = tb->left;
176 tb->old_wid = tb->wid;
177 tb->old_hgt = tb->hgt;
179 key = inkey_special(true);
181 if (key & SKEY_MASK) {
182 com_id = analyze_move_key(tb, key);
183 } else if (key == ESCAPE) {
184 com_id = do_command_menu(0, 0);
185 tb->dirty_flags |= DIRTY_SCREEN;
186 } else if (!iscntrl((unsigned char)key)) {
189 tb->dirty_flags |= DIRTY_ALL;
192 insert_single_letter(tb, key);
195 com_id = get_com_id((char)key);
199 quit = do_editor_command(player_ptr, tb, com_id);
204 const auto filename = pickpref_filename(player_ptr, tb->filename_mode);
206 if (quit == APE_QUIT_AND_SAVE) {
207 write_text_lines(filename, tb->lines_list);
210 free_text_lines(tb->lines_list);
211 string_free(tb->search_str);
212 string_free(tb->last_destroyed);
215 process_autopick_file(player_ptr, filename);
216 w_ptr->start_time = (uint32_t)time(nullptr);