1 #include "cmd-io/cmd-macro.h"
2 #include "cmd-io/cmd-gameoption.h"
3 #include "cmd-io/macro-util.h"
4 #include "game-option/input-options.h"
5 #include "io/files-util.h"
6 #include "io/input-key-acceptor.h"
7 #include "io/read-pref-file.h"
8 #include "main/sound-of-music.h"
9 #include "term/term-color-types.h"
10 #include "util/angband-files.h"
11 #include "util/string-processor.h"
12 #include "view/display-messages.h"
15 * @brief マクロ情報をprefファイルに保存する /
19 static void macro_dump(FILE **fpp, concptr fname)
21 static concptr mark = "Macro Dump";
23 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
24 if (!open_auto_dump(fpp, buf, mark)) return;
26 auto_dump_printf(*fpp, _("\n# 自動マクロセーブ\n\n", "\n# Automatic macro dump\n\n"));
28 for (int i = 0; i < macro__num; i++)
30 ascii_to_text(buf, macro__act[i]);
31 auto_dump_printf(*fpp, "A:%s\n", buf);
32 ascii_to_text(buf, macro__pat[i]);
33 auto_dump_printf(*fpp, "P:%s\n", buf);
34 auto_dump_printf(*fpp, "\n");
37 close_auto_dump(fpp, mark);
42 * @brief マクロのトリガーキーを取得する /
43 * Hack -- ask for a "trigger" (see below)
44 * @param buf キー表記を保管するバッファ
48 * Note the complex use of the "inkey()" function from "util.c".
50 * Note that both "flush()" calls are extremely important.
53 static void do_cmd_macro_aux(char *buf)
70 ascii_to_text(tmp, buf);
71 Term_addstr(-1, TERM_WHITE, tmp);
76 * @brief マクロのキー表記からアスキーコードを得てターミナルに表示する /
77 * Hack -- ask for a keymap "trigger" (see below)
78 * @param buf キー表記を取得するバッファ
82 * Note that both "flush()" calls are extremely important. This may
83 * no longer be true, since "util.c" is much simpler now.
86 static void do_cmd_macro_aux_keymap(char *buf)
92 ascii_to_text(tmp, buf);
93 Term_addstr(-1, TERM_WHITE, tmp);
99 * @brief キーマップをprefファイルにダンプする /
100 * Hack -- append all keymaps to the given file
101 * @param fname ファイルネーム
105 static errr keymap_dump(concptr fname)
107 FILE *auto_dump_stream;
108 static concptr mark = "Keymap Dump";
112 if (rogue_like_commands)
114 mode = KEYMAP_MODE_ROGUE;
118 mode = KEYMAP_MODE_ORIG;
121 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
122 if (!open_auto_dump(&auto_dump_stream, buf, mark)) return -1;
124 auto_dump_printf(auto_dump_stream, _("\n# 自動キー配置セーブ\n\n", "\n# Automatic keymap dump\n\n"));
125 for (int i = 0; i < 256; i++)
128 act = keymap_act[mode][i];
133 ascii_to_text(key, buf);
134 ascii_to_text(buf, act);
135 auto_dump_printf(auto_dump_stream, "A:%s\n", buf);
136 auto_dump_printf(auto_dump_stream, "C:%d:%s\n", mode, key);
139 close_auto_dump(&auto_dump_stream, mark);
145 * @brief マクロを設定するコマンドのメインルーチン /
146 * Interact with "macros"
150 * Note that the macro "action" must be defined before the trigger.
152 * Could use some helpful instructions on this page.
155 void do_cmd_macros(player_type *creature_ptr, void(*process_autopick_file_command)(char*))
159 FILE *auto_dump_stream;
160 BIT_FLAGS mode = rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG;
165 prt(_("[ マクロの設定 ]", "Interact with Macros"), 2, 0);
166 prt(_("マクロ行動が(もしあれば)下に表示されます:", "Current action (if any) shown below:"), 20, 0);
167 ascii_to_text(buf, macro__buf);
170 prt(_("(1) ユーザー設定ファイルのロード", "(1) Load a user pref file"), 4, 5);
171 prt(_("(2) ファイルにマクロを追加", "(2) Append macros to a file"), 5, 5);
172 prt(_("(3) マクロの確認", "(3) Query a macro"), 6, 5);
173 prt(_("(4) マクロの作成", "(4) Create a macro"), 7, 5);
174 prt(_("(5) マクロの削除", "(5) Remove a macro"), 8, 5);
175 prt(_("(6) ファイルにキー配置を追加", "(6) Append keymaps to a file"), 9, 5);
176 prt(_("(7) キー配置の確認", "(7) Query a keymap"), 10, 5);
177 prt(_("(8) キー配置の作成", "(8) Create a keymap"), 11, 5);
178 prt(_("(9) キー配置の削除", "(9) Remove a keymap"), 12, 5);
179 prt(_("(0) マクロ行動の入力", "(0) Enter a new action"), 13, 5);
181 prt(_("コマンド: ", "Command: "), 16, 0);
183 if (i == ESCAPE) break;
187 prt(_("コマンド: ユーザー設定ファイルのロード", "Command: Load a user pref file"), 16, 0);
188 prt(_("ファイル: ", "File: "), 18, 0);
189 sprintf(tmp, "%s.prf", creature_ptr->base_name);
190 if (!askfor(tmp, 80)) continue;
192 errr err = process_pref_file(creature_ptr, tmp, process_autopick_file_command);
194 msg_format(_("標準の設定ファイル'%s'を読み込みました。", "Loaded default '%s'."), tmp);
196 msg_format(_("'%s'の読み込みに失敗しました!", "Failed to load '%s'!"), tmp);
198 msg_format(_("'%s'を読み込みました。", "Loaded '%s'."), tmp);
202 prt(_("コマンド: マクロをファイルに追加する", "Command: Append macros to a file"), 16, 0);
203 prt(_("ファイル: ", "File: "), 18, 0);
204 sprintf(tmp, "%s.prf", creature_ptr->base_name);
205 if (!askfor(tmp, 80)) continue;
207 macro_dump(&auto_dump_stream, tmp);
208 msg_print(_("マクロを追加しました。", "Appended macros."));
212 prt(_("コマンド: マクロの確認", "Command: Query a macro"), 16, 0);
213 prt(_("トリガーキー: ", "Trigger: "), 18, 0);
214 do_cmd_macro_aux(buf);
215 int k = macro_find_exact(buf);
218 msg_print(_("そのキーにはマクロは定義されていません。", "Found no macro."));
222 strcpy(macro__buf, macro__act[k]);
223 ascii_to_text(buf, macro__buf);
225 msg_print(_("マクロを確認しました。", "Found a macro."));
230 prt(_("コマンド: マクロの作成", "Command: Create a macro"), 16, 0);
231 prt(_("トリガーキー: ", "Trigger: "), 18, 0);
232 do_cmd_macro_aux(buf);
234 c_prt(TERM_L_RED, _("カーソルキーの左右でカーソル位置を移動。BackspaceかDeleteで一文字削除。",
235 "Press Left/Right arrow keys to move cursor. Backspace/Delete to delete a char."), 22, 0);
236 prt(_("マクロ行動: ", "Action: "), 20, 0);
237 ascii_to_text(tmp, macro__buf);
240 text_to_ascii(macro__buf, tmp);
241 macro_add(buf, macro__buf);
242 msg_print(_("マクロを追加しました。", "Added a macro."));
247 prt(_("コマンド: マクロの削除", "Command: Remove a macro"), 16, 0);
248 prt(_("トリガーキー: ", "Trigger: "), 18, 0);
249 do_cmd_macro_aux(buf);
251 msg_print(_("マクロを削除しました。", "Removed a macro."));
255 prt(_("コマンド: キー配置をファイルに追加する", "Command: Append keymaps to a file"), 16, 0);
256 prt(_("ファイル: ", "File: "), 18, 0);
257 sprintf(tmp, "%s.prf", creature_ptr->base_name);
258 if (!askfor(tmp, 80)) continue;
260 (void)keymap_dump(tmp);
261 msg_print(_("キー配置を追加しました。", "Appended keymaps."));
265 prt(_("コマンド: キー配置の確認", "Command: Query a keymap"), 16, 0);
266 prt(_("押すキー: ", "Keypress: "), 18, 0);
267 do_cmd_macro_aux_keymap(buf);
268 concptr act = keymap_act[mode][(byte)(buf[0])];
271 msg_print(_("キー配置は定義されていません。", "Found no keymap."));
275 strcpy(macro__buf, act);
276 ascii_to_text(buf, macro__buf);
278 msg_print(_("キー配置を確認しました。", "Found a keymap."));
283 prt(_("コマンド: キー配置の作成", "Command: Create a keymap"), 16, 0);
284 prt(_("押すキー: ", "Keypress: "), 18, 0);
285 do_cmd_macro_aux_keymap(buf);
287 c_prt(TERM_L_RED, _("カーソルキーの左右でカーソル位置を移動。BackspaceかDeleteで一文字削除。",
288 "Press Left/Right arrow keys to move cursor. Backspace/Delete to delete a char."), 22, 0);
289 prt(_("行動: ", "Action: "), 20, 0);
290 ascii_to_text(tmp, macro__buf);
293 text_to_ascii(macro__buf, tmp);
294 string_free(keymap_act[mode][(byte)(buf[0])]);
295 keymap_act[mode][(byte)(buf[0])] = string_make(macro__buf);
296 msg_print(_("キー配置を追加しました。", "Added a keymap."));
301 prt(_("コマンド: キー配置の削除", "Command: Remove a keymap"), 16, 0);
302 prt(_("押すキー: ", "Keypress: "), 18, 0);
303 do_cmd_macro_aux_keymap(buf);
304 string_free(keymap_act[mode][(byte)(buf[0])]);
305 keymap_act[mode][(byte)(buf[0])] = NULL;
306 msg_print(_("キー配置を削除しました。", "Removed a keymap."));
310 prt(_("コマンド: マクロ行動の入力", "Command: Enter a new action"), 16, 0);
312 c_prt(TERM_L_RED, _("カーソルキーの左右でカーソル位置を移動。BackspaceかDeleteで一文字削除。",
313 "Press Left/Right arrow keys to move cursor. Backspace/Delete to delete a char."), 22, 0);
314 prt(_("マクロ行動: ", "Action: "), 20, 0);
316 if (!askfor(buf, 80)) continue;
318 text_to_ascii(macro__buf, buf);