From: Hourier Date: Sun, 26 Apr 2020 03:06:14 +0000 (+0900) Subject: [Refactor] #39964 Separated cmd-autopick.c/h from autopick.c/h X-Git-Url: http://git.osdn.net/view?p=hengband%2Fhengband.git;a=commitdiff_plain;h=1f4f37b4725112ce4768012c9761366347741f97 [Refactor] #39964 Separated cmd-autopick.c/h from autopick.c/h --- diff --git a/Hengband_vcs2017/Hengband/Hengband.vcxproj b/Hengband_vcs2017/Hengband/Hengband.vcxproj index ed4591327..0fa918549 100644 --- a/Hengband_vcs2017/Hengband/Hengband.vcxproj +++ b/Hengband_vcs2017/Hengband/Hengband.vcxproj @@ -170,6 +170,7 @@ + @@ -333,6 +334,7 @@ + diff --git a/Hengband_vcs2017/Hengband/Hengband.vcxproj.filters b/Hengband_vcs2017/Hengband/Hengband.vcxproj.filters index 9b5f37efa..732c137b6 100644 --- a/Hengband_vcs2017/Hengband/Hengband.vcxproj.filters +++ b/Hengband_vcs2017/Hengband/Hengband.vcxproj.filters @@ -691,6 +691,9 @@ autopick + + cmd + @@ -1385,6 +1388,9 @@ autopick + + cmd + diff --git a/src/Makefile.am b/src/Makefile.am index 0cc3de28e..6a56aefc1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -189,6 +189,7 @@ hengband_SOURCES = \ knowledge/knowledge-self.c knowledge/knowledge-self.h \ knowledge/knowledge-quests.c knowledge/knowledge-quests.h \ \ + cmd/cmd-autopick.c cmd/cmd-autopick.c \ cmd/dump-util.c cmd/dump-util.h cmd/feeling-table.c cmd/feeling-table.h \ cmd/monster-group-table.c cmd/monster-group-table.h \ cmd/diary-subtitle-table.c cmd/diary-subtitle-table.h \ diff --git a/src/autopick/autopick.c b/src/autopick/autopick.c index 2df26fe86..5ee6f2383 100644 --- a/src/autopick/autopick.c +++ b/src/autopick/autopick.c @@ -13,41 +13,14 @@ #include "angband.h" #include "util.h" -#include "autopick/autopick-commands-table.h" -#include "autopick/autopick-dirty-flags.h" -#include "autopick/autopick-flags-table.h" -#include "autopick/autopick-initializer.h" -#include "autopick/autopick-key-flag-process.h" #include "autopick/autopick-menu-data-table.h" #include "autopick/autopick-methods-table.h" #include "autopick/autopick-destroyer.h" -#include "autopick/autopick-entry.h" -#include "autopick/autopick-reader-writer.h" #include "autopick/autopick-finder.h" -#include "autopick/autopick-drawer.h" -#include "autopick/autopick-searcher.h" -#include "autopick/autopick-inserter-killer.h" -#include "autopick/autopick-registry.h" -#include "autopick/autopick-command-menu.h" -#include "autopick/autopick-editor-util.h" -#include "autopick/autopick-editor-command.h" -#include "gameterm.h" #include "autopick/autopick.h" -#include "core/show-file.h" -#include "cmd/cmd-save.h" -#include "io/read-pref-file.h" - -#include "mind.h" - -#include "market/store.h" #include "player-move.h" -#include "player-class.h" -#include "view/display-player.h" // 暫定。後で消す. #include "object-flavor.h" -#include "world.h" -#include "view/display-main-window.h" // 暫定。後で消す. - /* * Auto-destroy marked item */ @@ -170,197 +143,3 @@ void autopick_pickup_items(player_type* player_ptr, grid_type *g_ptr) py_pickup_aux(player_ptr, this_o_idx); } } - - -/* - * Check special key code and get a movement command id - */ -static int analyze_move_key(text_body_type *tb, int skey) -{ - int com_id; - if (!(skey & SKEY_MASK)) return 0; - - switch (skey & ~SKEY_MOD_MASK) - { - case SKEY_DOWN: com_id = EC_DOWN; break; - case SKEY_LEFT: com_id = EC_LEFT; break; - case SKEY_RIGHT: com_id = EC_RIGHT; break; - case SKEY_UP: com_id = EC_UP; break; - case SKEY_PGUP: com_id = EC_PGUP; break; - case SKEY_PGDOWN: com_id = EC_PGDOWN; break; - case SKEY_TOP: com_id = EC_TOP; break; - case SKEY_BOTTOM: com_id = EC_BOTTOM; break; - default: - return 0; - } - - if (!(skey & SKEY_MOD_SHIFT)) - { - /* - * Un-shifted cursor keys cancells - * selection created by shift+cursor. - */ - if (tb->mark & MARK_BY_SHIFT) - { - tb->mark = 0; - tb->dirty_flags |= DIRTY_ALL; - } - - return com_id; - } - - if (tb->mark) return com_id; - - int len = strlen(tb->lines_list[tb->cy]); - tb->mark = MARK_MARK | MARK_BY_SHIFT; - tb->my = tb->cy; - tb->mx = tb->cx; - if (tb->cx > len) tb->mx = len; - - if (com_id == EC_UP || com_id == EC_DOWN) - { - tb->dirty_flags |= DIRTY_ALL; - } - else - { - tb->dirty_line = tb->cy; - } - - return com_id; -} - -/* - * In-game editor of Object Auto-picker/Destoryer - * @param player_ptr プレーヤーへの参照ポインタ - */ -void do_cmd_edit_autopick(player_type *player_ptr) -{ - static int cx_save = 0; - static int cy_save = 0; - autopick_type an_entry, *entry = &an_entry; - char buf[MAX_LINELEN]; - int i; - int key = -1; - static s32b old_autosave_turn = 0L; - byte quit = 0; - - text_body_type text_body; - text_body_type *tb = &text_body; - tb->changed = FALSE; - tb->cx = cx_save; - tb->cy = cy_save; - tb->upper = tb->left = 0; - tb->mark = 0; - tb->mx = tb->my = 0; - tb->old_cy = tb->old_upper = tb->old_left = -1; - tb->old_wid = tb->old_hgt = -1; - tb->old_com_id = 0; - - tb->yank = NULL; - tb->search_o_ptr = NULL; - tb->search_str = NULL; - tb->last_destroyed = NULL; - tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION; - tb->dirty_line = -1; - tb->filename_mode = PT_DEFAULT; - - if (current_world_ptr->game_turn < old_autosave_turn) - { - while (old_autosave_turn > current_world_ptr->game_turn) old_autosave_turn -= TURNS_PER_TICK * TOWN_DAWN; - } - - if (current_world_ptr->game_turn > old_autosave_turn + 100L) - { - do_cmd_save_game(player_ptr, TRUE); - old_autosave_turn = current_world_ptr->game_turn; - } - - update_playtime(); - init_autopick(); - if (autopick_last_destroyed_object.k_idx) - { - autopick_entry_from_object(player_ptr, entry, &autopick_last_destroyed_object); - tb->last_destroyed = autopick_line_from_entry_kill(entry); - } - - tb->lines_list = read_pickpref_text_lines(player_ptr, &tb->filename_mode); - for (i = 0; i < tb->cy; i++) - { - if (!tb->lines_list[i]) - { - tb->cy = tb->cx = 0; - break; - } - } - - screen_save(); - while (!quit) - { - int com_id = 0; - draw_text_editor(player_ptr, tb); - prt(_("(^Q:終了 ^W:セーブして終了, ESC:メニュー, その他:入力)", - "(^Q:Quit, ^W:Save&Quit, ESC:Menu, Other:Input text)"), 0, 0); - if (!tb->mark) - { - prt(format("(%d,%d)", tb->cx, tb->cy), 0, 60); - } - else - { - prt(format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60); - } - - Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1); - tb->dirty_flags = 0; - tb->dirty_line = -1; - tb->old_cy = tb->cy; - tb->old_upper = tb->upper; - tb->old_left = tb->left; - tb->old_wid = tb->wid; - tb->old_hgt = tb->hgt; - - key = inkey_special(TRUE); - - if (key & SKEY_MASK) - { - com_id = analyze_move_key(tb, key); - } - else if (key == ESCAPE) - { - com_id = do_command_menu(0, 0); - tb->dirty_flags |= DIRTY_SCREEN; - } - else if (!iscntrl((unsigned char)key)) - { - if (tb->mark) - { - tb->mark = 0; - tb->dirty_flags |= DIRTY_ALL; - } - - insert_single_letter(tb, key); - continue; - } - else - { - com_id = get_com_id((char)key); - } - - if (com_id) quit = do_editor_command(player_ptr, tb, com_id); - } - - screen_load(); - strcpy(buf, pickpref_filename(player_ptr, tb->filename_mode)); - - if (quit == QUIT_AND_SAVE) - write_text_lines(buf, tb->lines_list); - - free_text_lines(tb->lines_list); - string_free(tb->search_str); - string_free(tb->last_destroyed); - kill_yank_chain(tb); - - process_autopick_file(player_ptr, buf); - current_world_ptr->start_time = (u32b)time(NULL); - cx_save = tb->cx; - cy_save = tb->cy; -} diff --git a/src/autopick/autopick.h b/src/autopick/autopick.h index 3fb2fbf68..cc580cf8c 100644 --- a/src/autopick/autopick.h +++ b/src/autopick/autopick.h @@ -5,4 +5,3 @@ extern void autopick_alter_item(player_type *player_ptr, INVENTORY_IDX item, bool destroy); extern void autopick_delayed_alter(player_type *player_ptr); extern void autopick_pickup_items(player_type *player_ptr, grid_type *g_ptr); -extern void do_cmd_edit_autopick(player_type *player_ptr); diff --git a/src/cmd/cmd-autopick.c b/src/cmd/cmd-autopick.c new file mode 100644 index 000000000..0f8e214de --- /dev/null +++ b/src/cmd/cmd-autopick.c @@ -0,0 +1,210 @@ +#include "angband.h" +#include "cmd/cmd-autopick.h" +#include "cmd/cmd-save.h" +#include "autopick/autopick-util.h" +#include "autopick/autopick-commands-table.h" +#include "autopick/autopick-dirty-flags.h" +#include "autopick/autopick-initializer.h" +#include "autopick/autopick-entry.h" +#include "autopick/autopick-drawer.h" +#include "autopick/autopick-reader-writer.h" +#include "autopick/autopick-command-menu.h" +#include "autopick/autopick-editor-command.h" +#include "autopick/autopick-editor-util.h" +#include "autopick/autopick-inserter-killer.h" +#include "io/read-pref-file.h" +#include "world.h" +#include "view/display-main-window.h" // 暫定。後で消す. + +/* + * Check special key code and get a movement command id + */ +static int analyze_move_key(text_body_type *tb, int skey) +{ + int com_id; + if (!(skey & SKEY_MASK)) return 0; + + switch (skey & ~SKEY_MOD_MASK) + { + case SKEY_DOWN: com_id = EC_DOWN; break; + case SKEY_LEFT: com_id = EC_LEFT; break; + case SKEY_RIGHT: com_id = EC_RIGHT; break; + case SKEY_UP: com_id = EC_UP; break; + case SKEY_PGUP: com_id = EC_PGUP; break; + case SKEY_PGDOWN: com_id = EC_PGDOWN; break; + case SKEY_TOP: com_id = EC_TOP; break; + case SKEY_BOTTOM: com_id = EC_BOTTOM; break; + default: + return 0; + } + + if (!(skey & SKEY_MOD_SHIFT)) + { + /* + * Un-shifted cursor keys cancells + * selection created by shift+cursor. + */ + if (tb->mark & MARK_BY_SHIFT) + { + tb->mark = 0; + tb->dirty_flags |= DIRTY_ALL; + } + + return com_id; + } + + if (tb->mark) return com_id; + + int len = strlen(tb->lines_list[tb->cy]); + tb->mark = MARK_MARK | MARK_BY_SHIFT; + tb->my = tb->cy; + tb->mx = tb->cx; + if (tb->cx > len) tb->mx = len; + + if (com_id == EC_UP || com_id == EC_DOWN) + { + tb->dirty_flags |= DIRTY_ALL; + } + else + { + tb->dirty_line = tb->cy; + } + + return com_id; +} + +/* + * In-game editor of Object Auto-picker/Destoryer + * @param player_ptr プレーヤーへの参照ポインタ + */ +void do_cmd_edit_autopick(player_type *player_ptr) +{ + static int cx_save = 0; + static int cy_save = 0; + autopick_type an_entry, *entry = &an_entry; + char buf[MAX_LINELEN]; + int i; + int key = -1; + static s32b old_autosave_turn = 0L; + byte quit = 0; + + text_body_type text_body; + text_body_type *tb = &text_body; + tb->changed = FALSE; + tb->cx = cx_save; + tb->cy = cy_save; + tb->upper = tb->left = 0; + tb->mark = 0; + tb->mx = tb->my = 0; + tb->old_cy = tb->old_upper = tb->old_left = -1; + tb->old_wid = tb->old_hgt = -1; + tb->old_com_id = 0; + + tb->yank = NULL; + tb->search_o_ptr = NULL; + tb->search_str = NULL; + tb->last_destroyed = NULL; + tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION; + tb->dirty_line = -1; + tb->filename_mode = PT_DEFAULT; + + if (current_world_ptr->game_turn < old_autosave_turn) + { + while (old_autosave_turn > current_world_ptr->game_turn) old_autosave_turn -= TURNS_PER_TICK * TOWN_DAWN; + } + + if (current_world_ptr->game_turn > old_autosave_turn + 100L) + { + do_cmd_save_game(player_ptr, TRUE); + old_autosave_turn = current_world_ptr->game_turn; + } + + update_playtime(); + init_autopick(); + if (autopick_last_destroyed_object.k_idx) + { + autopick_entry_from_object(player_ptr, entry, &autopick_last_destroyed_object); + tb->last_destroyed = autopick_line_from_entry_kill(entry); + } + + tb->lines_list = read_pickpref_text_lines(player_ptr, &tb->filename_mode); + for (i = 0; i < tb->cy; i++) + { + if (!tb->lines_list[i]) + { + tb->cy = tb->cx = 0; + break; + } + } + + screen_save(); + while (!quit) + { + int com_id = 0; + draw_text_editor(player_ptr, tb); + prt(_("(^Q:終了 ^W:セーブして終了, ESC:メニュー, その他:入力)", + "(^Q:Quit, ^W:Save&Quit, ESC:Menu, Other:Input text)"), 0, 0); + if (!tb->mark) + { + prt(format("(%d,%d)", tb->cx, tb->cy), 0, 60); + } + else + { + prt(format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60); + } + + Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1); + tb->dirty_flags = 0; + tb->dirty_line = -1; + tb->old_cy = tb->cy; + tb->old_upper = tb->upper; + tb->old_left = tb->left; + tb->old_wid = tb->wid; + tb->old_hgt = tb->hgt; + + key = inkey_special(TRUE); + + if (key & SKEY_MASK) + { + com_id = analyze_move_key(tb, key); + } + else if (key == ESCAPE) + { + com_id = do_command_menu(0, 0); + tb->dirty_flags |= DIRTY_SCREEN; + } + else if (!iscntrl((unsigned char)key)) + { + if (tb->mark) + { + tb->mark = 0; + tb->dirty_flags |= DIRTY_ALL; + } + + insert_single_letter(tb, key); + continue; + } + else + { + com_id = get_com_id((char)key); + } + + if (com_id) quit = do_editor_command(player_ptr, tb, com_id); + } + + screen_load(); + strcpy(buf, pickpref_filename(player_ptr, tb->filename_mode)); + + if (quit == QUIT_AND_SAVE) + write_text_lines(buf, tb->lines_list); + + free_text_lines(tb->lines_list); + string_free(tb->search_str); + string_free(tb->last_destroyed); + kill_yank_chain(tb); + + process_autopick_file(player_ptr, buf); + current_world_ptr->start_time = (u32b)time(NULL); + cx_save = tb->cx; + cy_save = tb->cy; +} diff --git a/src/cmd/cmd-autopick.h b/src/cmd/cmd-autopick.h new file mode 100644 index 000000000..fb26d9cdf --- /dev/null +++ b/src/cmd/cmd-autopick.h @@ -0,0 +1,3 @@ +#pragma once + +void do_cmd_edit_autopick(player_type *player_ptr); diff --git a/src/cmd/cmd-gameoption.c b/src/cmd/cmd-gameoption.c index d58db9050..3d390ae2c 100644 --- a/src/cmd/cmd-gameoption.c +++ b/src/cmd/cmd-gameoption.c @@ -3,6 +3,7 @@ #include "autopick/autopick.h" #include "io/write-diary.h" #include "cmd/cmd-gameoption.h" +#include "cmd/cmd-autopick.h" #include "gameterm.h" #include "view/display-main-window.h" #include "cmd/cmd-dump.h" diff --git a/src/core.c b/src/core.c index 421a22b04..f3ca01e18 100644 --- a/src/core.c +++ b/src/core.c @@ -26,6 +26,7 @@ #include "market/building.h" #include "io/write-diary.h" #include "cmd/cmd-activate.h" +#include "cmd/cmd-autopick.h" #include "cmd/cmd-diary.h" #include "cmd/cmd-draw.h" #include "cmd/cmd-dump.h"