1 #include "cmd-io/cmd-macro.h"
2 #include "cmd-io/cmd-gameoption.h"
3 #include "cmd-io/macro-util.h"
4 #include "core/asking-player.h"
5 #include "game-option/input-options.h"
6 #include "io/files-util.h"
7 #include "io/input-key-acceptor.h"
8 #include "io/input-key-requester.h"
9 #include "io/read-pref-file.h"
10 #include "main/sound-of-music.h"
11 #include "system/player-type-definition.h"
12 #include "term/screen-processor.h"
13 #include "term/term-color-types.h"
14 #include "util/angband-files.h"
15 #include "util/int-char-converter.h"
16 #include "util/string-processor.h"
17 #include "view/display-messages.h"
20 * @brief マクロ情報をprefファイルに保存する /
23 static void macro_dump(FILE **fpp, concptr fname)
25 static concptr mark = "Macro Dump";
27 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
28 if (!open_auto_dump(fpp, buf, mark)) return;
30 auto_dump_printf(*fpp, _("\n# 自動マクロセーブ\n\n", "\n# Automatic macro dump\n\n"));
32 for (int i = 0; i < macro__num; i++)
34 ascii_to_text(buf, macro__act[i]);
35 auto_dump_printf(*fpp, "A:%s\n", buf);
36 ascii_to_text(buf, macro__pat[i]);
37 auto_dump_printf(*fpp, "P:%s\n", buf);
38 auto_dump_printf(*fpp, "\n");
41 close_auto_dump(fpp, mark);
46 * @brief マクロのトリガーキーを取得する /
47 * Hack -- ask for a "trigger" (see below)
48 * @param buf キー表記を保管するバッファ
51 * Note the complex use of the "inkey()" function from "util.c".
53 * Note that both "flush()" calls are extremely important.
56 static void do_cmd_macro_aux(char *buf)
73 ascii_to_text(tmp, buf);
74 term_addstr(-1, TERM_WHITE, tmp);
79 * @brief マクロのキー表記からアスキーコードを得てターミナルに表示する /
80 * Hack -- ask for a keymap "trigger" (see below)
81 * @param buf キー表記を取得するバッファ
84 * Note that both "flush()" calls are extremely important. This may
85 * no longer be true, since "util.c" is much simpler now.
88 static void do_cmd_macro_aux_keymap(char *buf)
94 ascii_to_text(tmp, buf);
95 term_addstr(-1, TERM_WHITE, tmp);
101 * @brief キーマップをprefファイルにダンプする /
102 * Hack -- append all keymaps to the given file
103 * @param fname ファイルネーム
107 static errr keymap_dump(concptr fname)
109 FILE *auto_dump_stream;
110 static concptr mark = "Keymap Dump";
114 if (rogue_like_commands)
116 mode = KEYMAP_MODE_ROGUE;
120 mode = KEYMAP_MODE_ORIG;
123 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
124 if (!open_auto_dump(&auto_dump_stream, buf, mark)) return -1;
126 auto_dump_printf(auto_dump_stream, _("\n# 自動キー配置セーブ\n\n", "\n# Automatic keymap dump\n\n"));
127 for (int i = 0; i < 256; i++)
130 act = keymap_act[mode][i];
135 ascii_to_text(key, buf);
136 ascii_to_text(buf, act);
137 auto_dump_printf(auto_dump_stream, "A:%s\n", buf);
138 auto_dump_printf(auto_dump_stream, "C:%d:%s\n", mode, key);
141 close_auto_dump(&auto_dump_stream, mark);
147 * @brief マクロを設定するコマンドのメインルーチン /
148 * Interact with "macros"
151 * Note that the macro "action" must be defined before the trigger.
153 * Could use some helpful instructions on this page.
156 void do_cmd_macros(player_type *creature_ptr)
160 FILE *auto_dump_stream;
161 BIT_FLAGS mode = rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG;
166 prt(_("[ マクロの設定 ]", "Interact with Macros"), 2, 0);
167 prt(_("マクロ行動が(もしあれば)下に表示されます:", "Current action (if any) shown below:"), 20, 0);
168 ascii_to_text(buf, macro__buf);
171 prt(_("(1) ユーザー設定ファイルのロード", "(1) Load a user pref file"), 4, 5);
172 prt(_("(2) ファイルにマクロを追加", "(2) Append macros to a file"), 5, 5);
173 prt(_("(3) マクロの確認", "(3) Query a macro"), 6, 5);
174 prt(_("(4) マクロの作成", "(4) Create a macro"), 7, 5);
175 prt(_("(5) マクロの削除", "(5) Remove a macro"), 8, 5);
176 prt(_("(6) ファイルにキー配置を追加", "(6) Append keymaps to a file"), 9, 5);
177 prt(_("(7) キー配置の確認", "(7) Query a keymap"), 10, 5);
178 prt(_("(8) キー配置の作成", "(8) Create a keymap"), 11, 5);
179 prt(_("(9) キー配置の削除", "(9) Remove a keymap"), 12, 5);
180 prt(_("(0) マクロ行動の入力", "(0) Enter a new action"), 13, 5);
182 prt(_("コマンド: ", "Command: "), 16, 0);
184 if (i == ESCAPE) break;
188 prt(_("コマンド: ユーザー設定ファイルのロード", "Command: Load a user pref file"), 16, 0);
189 prt(_("ファイル: ", "File: "), 18, 0);
190 sprintf(tmp, "%s.prf", creature_ptr->base_name);
191 if (!askfor(tmp, 80)) continue;
193 errr err = process_pref_file(creature_ptr, tmp);
195 msg_format(_("標準の設定ファイル'%s'を読み込みました。", "Loaded default '%s'."), tmp);
197 msg_format(_("'%s'の読み込みに失敗しました!", "Failed to load '%s'!"), tmp);
199 msg_format(_("'%s'を読み込みました。", "Loaded '%s'."), tmp);
203 prt(_("コマンド: マクロをファイルに追加する", "Command: Append macros to a file"), 16, 0);
204 prt(_("ファイル: ", "File: "), 18, 0);
205 sprintf(tmp, "%s.prf", creature_ptr->base_name);
206 if (!askfor(tmp, 80)) continue;
208 macro_dump(&auto_dump_stream, tmp);
209 msg_print(_("マクロを追加しました。", "Appended macros."));
213 prt(_("コマンド: マクロの確認", "Command: Query a macro"), 16, 0);
214 prt(_("トリガーキー: ", "Trigger: "), 18, 0);
215 do_cmd_macro_aux(buf);
216 int k = macro_find_exact(buf);
219 msg_print(_("そのキーにはマクロは定義されていません。", "Found no macro."));
223 strcpy(macro__buf, macro__act[k]);
224 ascii_to_text(buf, macro__buf);
226 msg_print(_("マクロを確認しました。", "Found a macro."));
231 prt(_("コマンド: マクロの作成", "Command: Create a macro"), 16, 0);
232 prt(_("トリガーキー: ", "Trigger: "), 18, 0);
233 do_cmd_macro_aux(buf);
235 c_prt(TERM_L_RED, _("カーソルキーの左右でカーソル位置を移動。BackspaceかDeleteで一文字削除。",
236 "Press Left/Right arrow keys to move cursor. Backspace/Delete to delete a char."), 22, 0);
237 prt(_("マクロ行動: ", "Action: "), 20, 0);
238 ascii_to_text(tmp, macro__buf);
241 text_to_ascii(macro__buf, tmp);
242 macro_add(buf, macro__buf);
243 msg_print(_("マクロを追加しました。", "Added a macro."));
248 prt(_("コマンド: マクロの削除", "Command: Remove a macro"), 16, 0);
249 prt(_("トリガーキー: ", "Trigger: "), 18, 0);
250 do_cmd_macro_aux(buf);
252 msg_print(_("マクロを削除しました。", "Removed a macro."));
256 prt(_("コマンド: キー配置をファイルに追加する", "Command: Append keymaps to a file"), 16, 0);
257 prt(_("ファイル: ", "File: "), 18, 0);
258 sprintf(tmp, "%s.prf", creature_ptr->base_name);
259 if (!askfor(tmp, 80)) continue;
261 (void)keymap_dump(tmp);
262 msg_print(_("キー配置を追加しました。", "Appended keymaps."));
266 prt(_("コマンド: キー配置の確認", "Command: Query a keymap"), 16, 0);
267 prt(_("押すキー: ", "Keypress: "), 18, 0);
268 do_cmd_macro_aux_keymap(buf);
269 concptr act = keymap_act[mode][(byte)(buf[0])];
272 msg_print(_("キー配置は定義されていません。", "Found no keymap."));
276 strcpy(macro__buf, act);
277 ascii_to_text(buf, macro__buf);
279 msg_print(_("キー配置を確認しました。", "Found a keymap."));
284 prt(_("コマンド: キー配置の作成", "Command: Create a keymap"), 16, 0);
285 prt(_("押すキー: ", "Keypress: "), 18, 0);
286 do_cmd_macro_aux_keymap(buf);
288 c_prt(TERM_L_RED, _("カーソルキーの左右でカーソル位置を移動。BackspaceかDeleteで一文字削除。",
289 "Press Left/Right arrow keys to move cursor. Backspace/Delete to delete a char."), 22, 0);
290 prt(_("行動: ", "Action: "), 20, 0);
291 ascii_to_text(tmp, macro__buf);
294 text_to_ascii(macro__buf, tmp);
295 string_free(keymap_act[mode][(byte)(buf[0])]);
296 keymap_act[mode][(byte)(buf[0])] = string_make(macro__buf);
297 msg_print(_("キー配置を追加しました。", "Added a keymap."));
302 prt(_("コマンド: キー配置の削除", "Command: Remove a keymap"), 16, 0);
303 prt(_("押すキー: ", "Keypress: "), 18, 0);
304 do_cmd_macro_aux_keymap(buf);
305 string_free(keymap_act[mode][(byte)(buf[0])]);
306 keymap_act[mode][(byte)(buf[0])] = NULL;
307 msg_print(_("キー配置を削除しました。", "Removed a keymap."));
311 prt(_("コマンド: マクロ行動の入力", "Command: Enter a new action"), 16, 0);
313 c_prt(TERM_L_RED, _("カーソルキーの左右でカーソル位置を移動。BackspaceかDeleteで一文字削除。",
314 "Press Left/Right arrow keys to move cursor. Backspace/Delete to delete a char."), 22, 0);
315 prt(_("マクロ行動: ", "Action: "), 20, 0);
317 if (!askfor(buf, 80)) continue;
319 text_to_ascii(macro__buf, buf);