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))
31 auto_dump_printf(*fpp, _("\n# 自動マクロセーブ\n\n", "\n# Automatic macro dump\n\n"));
33 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);
45 * @brief マクロのトリガーキーを取得する /
46 * Hack -- ask for a "trigger" (see below)
47 * @param buf キー表記を保管するバッファ
50 * Note the complex use of the "inkey()" function from "util.c".
52 * Note that both "flush()" calls are extremely important.
55 static void do_cmd_macro_aux(char *buf)
71 ascii_to_text(tmp, buf);
72 term_addstr(-1, TERM_WHITE, tmp);
76 * @brief マクロのキー表記からアスキーコードを得てターミナルに表示する /
77 * Hack -- ask for a keymap "trigger" (see below)
78 * @param buf キー表記を取得するバッファ
81 * Note that both "flush()" calls are extremely important. This may
82 * no longer be true, since "util.c" is much simpler now.
85 static void do_cmd_macro_aux_keymap(char *buf)
91 ascii_to_text(tmp, buf);
92 term_addstr(-1, TERM_WHITE, tmp);
97 * @brief キーマップをprefファイルにダンプする /
98 * Hack -- append all keymaps to the given file
99 * @param fname ファイルネーム
103 static errr keymap_dump(concptr fname)
105 FILE *auto_dump_stream;
106 static concptr mark = "Keymap Dump";
110 if (rogue_like_commands) {
111 mode = KEYMAP_MODE_ROGUE;
113 mode = KEYMAP_MODE_ORIG;
116 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
117 if (!open_auto_dump(&auto_dump_stream, buf, mark))
120 auto_dump_printf(auto_dump_stream, _("\n# 自動キー配置セーブ\n\n", "\n# Automatic keymap dump\n\n"));
121 for (int i = 0; i < 256; i++) {
123 act = keymap_act[mode][i];
129 ascii_to_text(key, buf);
130 ascii_to_text(buf, act);
131 auto_dump_printf(auto_dump_stream, "A:%s\n", buf);
132 auto_dump_printf(auto_dump_stream, "C:%d:%s\n", mode, key);
135 close_auto_dump(&auto_dump_stream, mark);
140 * @brief マクロを設定するコマンドのメインルーチン /
141 * Interact with "macros"
144 * Note that the macro "action" must be defined before the trigger.
146 * Could use some helpful instructions on this page.
149 void do_cmd_macros(player_type *creature_ptr)
153 FILE *auto_dump_stream;
154 BIT_FLAGS mode = rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG;
158 prt(_("[ マクロの設定 ]", "Interact with Macros"), 2, 0);
159 prt(_("マクロ行動が(もしあれば)下に表示されます:", "Current action (if any) shown below:"), 20, 0);
160 ascii_to_text(buf, macro__buf);
163 prt(_("(1) ユーザー設定ファイルのロード", "(1) Load a user pref file"), 4, 5);
164 prt(_("(2) ファイルにマクロを追加", "(2) Append macros to a file"), 5, 5);
165 prt(_("(3) マクロの確認", "(3) Query a macro"), 6, 5);
166 prt(_("(4) マクロの作成", "(4) Create a macro"), 7, 5);
167 prt(_("(5) マクロの削除", "(5) Remove a macro"), 8, 5);
168 prt(_("(6) ファイルにキー配置を追加", "(6) Append keymaps to a file"), 9, 5);
169 prt(_("(7) キー配置の確認", "(7) Query a keymap"), 10, 5);
170 prt(_("(8) キー配置の作成", "(8) Create a keymap"), 11, 5);
171 prt(_("(9) キー配置の削除", "(9) Remove a keymap"), 12, 5);
172 prt(_("(0) マクロ行動の入力", "(0) Enter a new action"), 13, 5);
174 prt(_("コマンド: ", "Command: "), 16, 0);
180 prt(_("コマンド: ユーザー設定ファイルのロード", "Command: Load a user pref file"), 16, 0);
181 prt(_("ファイル: ", "File: "), 18, 0);
182 sprintf(tmp, "%s.prf", creature_ptr->base_name);
183 if (!askfor(tmp, 80))
186 errr err = process_pref_file(creature_ptr, tmp);
188 msg_format(_("標準の設定ファイル'%s'を読み込みました。", "Loaded default '%s'."), tmp);
190 msg_format(_("'%s'の読み込みに失敗しました!", "Failed to load '%s'!"), tmp);
192 msg_format(_("'%s'を読み込みました。", "Loaded '%s'."), tmp);
193 } else if (i == '2') {
194 prt(_("コマンド: マクロをファイルに追加する", "Command: Append macros to a file"), 16, 0);
195 prt(_("ファイル: ", "File: "), 18, 0);
196 sprintf(tmp, "%s.prf", creature_ptr->base_name);
197 if (!askfor(tmp, 80))
200 macro_dump(&auto_dump_stream, tmp);
201 msg_print(_("マクロを追加しました。", "Appended macros."));
202 } else if (i == '3') {
203 prt(_("コマンド: マクロの確認", "Command: Query a macro"), 16, 0);
204 prt(_("トリガーキー: ", "Trigger: "), 18, 0);
205 do_cmd_macro_aux(buf);
206 int k = macro_find_exact(buf);
208 msg_print(_("そのキーにはマクロは定義されていません。", "Found no macro."));
210 strcpy(macro__buf, macro__act[k]);
211 ascii_to_text(buf, macro__buf);
213 msg_print(_("マクロを確認しました。", "Found a macro."));
215 } else if (i == '4') {
216 prt(_("コマンド: マクロの作成", "Command: Create a macro"), 16, 0);
217 prt(_("トリガーキー: ", "Trigger: "), 18, 0);
218 do_cmd_macro_aux(buf);
221 _("カーソルキーの左右でカーソル位置を移動。BackspaceかDeleteで一文字削除。",
222 "Press Left/Right arrow keys to move cursor. Backspace/Delete to delete a char."),
224 prt(_("マクロ行動: ", "Action: "), 20, 0);
225 ascii_to_text(tmp, macro__buf);
226 if (askfor(tmp, 80)) {
227 text_to_ascii(macro__buf, tmp);
228 macro_add(buf, macro__buf);
229 msg_print(_("マクロを追加しました。", "Added a macro."));
231 } else if (i == '5') {
232 prt(_("コマンド: マクロの削除", "Command: Remove a macro"), 16, 0);
233 prt(_("トリガーキー: ", "Trigger: "), 18, 0);
234 do_cmd_macro_aux(buf);
236 msg_print(_("マクロを削除しました。", "Removed a macro."));
237 } else if (i == '6') {
238 prt(_("コマンド: キー配置をファイルに追加する", "Command: Append keymaps to a file"), 16, 0);
239 prt(_("ファイル: ", "File: "), 18, 0);
240 sprintf(tmp, "%s.prf", creature_ptr->base_name);
241 if (!askfor(tmp, 80))
244 (void)keymap_dump(tmp);
245 msg_print(_("キー配置を追加しました。", "Appended keymaps."));
246 } else if (i == '7') {
247 prt(_("コマンド: キー配置の確認", "Command: Query a keymap"), 16, 0);
248 prt(_("押すキー: ", "Keypress: "), 18, 0);
249 do_cmd_macro_aux_keymap(buf);
250 concptr act = keymap_act[mode][(byte)(buf[0])];
252 msg_print(_("キー配置は定義されていません。", "Found no keymap."));
254 strcpy(macro__buf, act);
255 ascii_to_text(buf, macro__buf);
257 msg_print(_("キー配置を確認しました。", "Found a keymap."));
259 } else if (i == '8') {
260 prt(_("コマンド: キー配置の作成", "Command: Create a keymap"), 16, 0);
261 prt(_("押すキー: ", "Keypress: "), 18, 0);
262 do_cmd_macro_aux_keymap(buf);
265 _("カーソルキーの左右でカーソル位置を移動。BackspaceかDeleteで一文字削除。",
266 "Press Left/Right arrow keys to move cursor. Backspace/Delete to delete a char."),
268 prt(_("行動: ", "Action: "), 20, 0);
269 ascii_to_text(tmp, macro__buf);
270 if (askfor(tmp, 80)) {
271 text_to_ascii(macro__buf, tmp);
272 string_free(keymap_act[mode][(byte)(buf[0])]);
273 keymap_act[mode][(byte)(buf[0])] = string_make(macro__buf);
274 msg_print(_("キー配置を追加しました。", "Added a keymap."));
276 } else if (i == '9') {
277 prt(_("コマンド: キー配置の削除", "Command: Remove a keymap"), 16, 0);
278 prt(_("押すキー: ", "Keypress: "), 18, 0);
279 do_cmd_macro_aux_keymap(buf);
280 string_free(keymap_act[mode][(byte)(buf[0])]);
281 keymap_act[mode][(byte)(buf[0])] = NULL;
282 msg_print(_("キー配置を削除しました。", "Removed a keymap."));
283 } else if (i == '0') {
284 prt(_("コマンド: マクロ行動の入力", "Command: Enter a new action"), 16, 0);
287 _("カーソルキーの左右でカーソル位置を移動。BackspaceかDeleteで一文字削除。",
288 "Press Left/Right arrow keys to move cursor. Backspace/Delete to delete a char."),
290 prt(_("マクロ行動: ", "Action: "), 20, 0);
292 if (!askfor(buf, 80))
295 text_to_ascii(macro__buf, buf);