1 #include "cmd-visual/cmd-visuals.h"
2 #include "cmd-visual/cmd-draw.h"
3 #include "core/asking-player.h"
4 #include "core/visuals-reseter.h"
5 #include "flavor/flavor-describer.h"
6 #include "flavor/object-flavor-types.h"
7 #include "flavor/object-flavor.h"
8 #include "game-option/special-options.h"
9 #include "grid/feature.h"
10 #include "io/files-util.h"
11 #include "io/input-key-acceptor.h"
12 #include "io/read-pref-file.h"
13 #include "knowledge/knowledge-features.h"
14 #include "knowledge/knowledge-items.h"
15 #include "knowledge/knowledge-monsters.h"
16 #include "knowledge/lighting-level-table.h"
17 #include "main/sound-of-music.h"
18 #include "monster-race/monster-race.h"
19 #include "system/baseitem-info.h"
20 #include "system/item-entity.h"
21 #include "system/monster-race-info.h"
22 #include "system/player-type-definition.h"
23 #include "system/terrain-type-definition.h"
24 #include "term/screen-processor.h"
25 #include "term/term-color-types.h"
26 #include "term/z-form.h"
27 #include "util/angband-files.h"
28 #include "util/int-char-converter.h"
29 #include "view/display-messages.h"
33 * @brief キャラクタのビジュアルIDを変更する際の対象指定
34 * @param i 指定対象となるキャラクタコード
35 * @param initial_visual_id 指定されたビジュアルID
36 * @param max ビジュアルIDの最大数
40 static std::optional<T> input_new_visual_id(int i, T initial_visual_id, int max)
43 const auto new_visual_id = input_value_int("Input new number", 0, max - 1, initial_visual_id);
44 if (!new_visual_id.has_value()) {
48 return static_cast<T>(new_visual_id.value());
52 return static_cast<T>((initial_visual_id + max - 1) % max);
55 return static_cast<T>((initial_visual_id + 1) % max);
59 * @brief キャラクタの変更メニュー表示
60 * @param choice_msg 選択メッセージ
62 static void print_visuals_menu(concptr choice_msg)
64 prt(_("[ 画面表示の設定 ]", "Interact with Visuals"), 1, 0);
65 prt(_("(0) ユーザー設定ファイルのロード", "(0) Load a user pref file"), 3, 5);
66 prt(_("(1) モンスターの 色/文字 をファイルに書き出す", "(1) Dump monster attr/chars"), 4, 5);
67 prt(_("(2) アイテムの 色/文字 をファイルに書き出す", "(2) Dump object attr/chars"), 5, 5);
68 prt(_("(3) 地形の 色/文字 をファイルに書き出す", "(3) Dump feature attr/chars"), 6, 5);
69 prt(_("(4) モンスターの 色/文字 を変更する (数値操作)", "(4) Change monster attr/chars (numeric operation)"), 7, 5);
70 prt(_("(5) アイテムの 色/文字 を変更する (数値操作)", "(5) Change object attr/chars (numeric operation)"), 8, 5);
71 prt(_("(6) 地形の 色/文字 を変更する (数値操作)", "(6) Change feature attr/chars (numeric operation)"), 9, 5);
72 prt(_("(7) モンスターの 色/文字 を変更する (シンボルエディタ)", "(7) Change monster attr/chars (visual mode)"), 10, 5);
73 prt(_("(8) アイテムの 色/文字 を変更する (シンボルエディタ)", "(8) Change object attr/chars (visual mode)"), 11, 5);
74 prt(_("(9) 地形の 色/文字 を変更する (シンボルエディタ)", "(9) Change feature attr/chars (visual mode)"), 12, 5);
75 prt(_("(R) 画面表示方法の初期化", "(R) Reset visuals"), 13, 5);
76 prt(format(_("コマンド: %s", "Command: %s"), choice_msg ? choice_msg : _("", "")), 15, 0);
80 * Interact with "visuals"
82 void do_cmd_visuals(PlayerType *player_ptr)
84 FILE *auto_dump_stream;
86 bool need_redraw = false;
87 concptr empty_symbol = "<< ? >>";
89 empty_symbol = "<< ?? >>";
95 print_visuals_menu(nullptr);
103 prt(_("コマンド: ユーザー設定ファイルのロード", "Command: Load a user pref file"), 15, 0);
104 prt(_("ファイル: ", "File: "), 17, 0);
105 strnfmt(tmp, sizeof(tmp), "%s.prf", player_ptr->base_name);
106 if (!askfor(tmp, 70)) {
110 (void)process_pref_file(player_ptr, tmp, true);
115 prt(_("コマンド: モンスターの[色/文字]をファイルに書き出します", "Command: Dump monster attr/chars"), 15, 0);
116 prt(_("ファイル: ", "File: "), 17, 0);
117 strnfmt(tmp, sizeof(tmp), "%s.prf", player_ptr->base_name);
118 if (!askfor(tmp, 70)) {
122 const auto &path = path_build(ANGBAND_DIR_USER, tmp);
123 constexpr auto mark = "Monster attr/chars";
124 if (!open_auto_dump(&auto_dump_stream, path, mark)) {
128 auto_dump_printf(auto_dump_stream, _("\n# モンスターの[色/文字]の設定\n\n", "\n# Monster attr/char definitions\n\n"));
129 for (const auto &[monrace_id, monrace] : monraces_info) {
130 auto_dump_printf(auto_dump_stream, "# %s\n", monrace.name.data());
131 auto_dump_printf(auto_dump_stream, "R:%d:0x%02X/0x%02X\n\n", enum2i(monrace_id), monrace.x_attr, monrace.x_char);
134 close_auto_dump(&auto_dump_stream, mark);
135 msg_print(_("モンスターの[色/文字]をファイルに書き出しました。", "Dumped monster attr/chars."));
139 prt(_("コマンド: アイテムの[色/文字]をファイルに書き出します", "Command: Dump object attr/chars"), 15, 0);
140 prt(_("ファイル: ", "File: "), 17, 0);
141 strnfmt(tmp, sizeof(tmp), "%s.prf", player_ptr->base_name);
142 if (!askfor(tmp, 70)) {
146 const auto &path = path_build(ANGBAND_DIR_USER, tmp);
147 constexpr auto mark = "Object attr/chars";
148 if (!open_auto_dump(&auto_dump_stream, path, mark)) {
152 auto_dump_printf(auto_dump_stream, _("\n# アイテムの[色/文字]の設定\n\n", "\n# Object attr/char definitions\n\n"));
153 for (const auto &baseitem : baseitems_info) {
154 if (baseitem.name.empty()) {
158 std::string item_name;
159 if (baseitem.flavor == 0) {
160 item_name = strip_name(baseitem.idx);
163 dummy.prep(baseitem.idx);
164 item_name = describe_flavor(player_ptr, &dummy, OD_FORCE_FLAVOR);
167 auto_dump_printf(auto_dump_stream, "# %s\n", item_name.data());
168 auto_dump_printf(auto_dump_stream, "K:%d:0x%02X/0x%02X\n\n", (int)baseitem.idx, (byte)(baseitem.x_attr), (byte)(baseitem.x_char));
171 close_auto_dump(&auto_dump_stream, mark);
172 msg_print(_("アイテムの[色/文字]をファイルに書き出しました。", "Dumped object attr/chars."));
176 prt(_("コマンド: 地形の[色/文字]をファイルに書き出します", "Command: Dump feature attr/chars"), 15, 0);
177 prt(_("ファイル: ", "File: "), 17, 0);
178 strnfmt(tmp, sizeof(tmp), "%s.prf", player_ptr->base_name);
179 if (!askfor(tmp, 70)) {
183 const auto &path = path_build(ANGBAND_DIR_USER, tmp);
184 constexpr auto mark = "Feature attr/chars";
185 if (!open_auto_dump(&auto_dump_stream, path, mark)) {
189 auto_dump_printf(auto_dump_stream, _("\n# 地形の[色/文字]の設定\n\n", "\n# Feature attr/char definitions\n\n"));
190 for (const auto &f_ref : terrains_info) {
191 if (f_ref.name.empty()) {
194 if (f_ref.mimic != f_ref.idx) {
198 auto_dump_printf(auto_dump_stream, "# %s\n", (f_ref.name.data()));
199 auto_dump_printf(auto_dump_stream, "F:%d:0x%02X/0x%02X:0x%02X/0x%02X:0x%02X/0x%02X\n\n", f_ref.idx, (byte)(f_ref.x_attr[F_LIT_STANDARD]),
200 (byte)(f_ref.x_char[F_LIT_STANDARD]), (byte)(f_ref.x_attr[F_LIT_LITE]), (byte)(f_ref.x_char[F_LIT_LITE]),
201 (byte)(f_ref.x_attr[F_LIT_DARK]), (byte)(f_ref.x_char[F_LIT_DARK]));
204 close_auto_dump(&auto_dump_stream, mark);
205 msg_print(_("地形の[色/文字]をファイルに書き出しました。", "Dumped feature attr/chars."));
210 static auto choice_msg = _("モンスターの[色/文字]を変更します", "Change monster attr/chars");
211 static auto monrace_id = monraces_info.begin()->second.idx;
212 prt(format(_("コマンド: %s", "Command: %s"), choice_msg), 15, 0);
214 auto *r_ptr = &monraces_info[monrace_id];
216 TERM_COLOR da = r_ptr->d_attr;
217 byte dc = r_ptr->d_char;
218 TERM_COLOR ca = r_ptr->x_attr;
219 byte cc = r_ptr->x_char;
221 term_putstr(5, 17, -1, TERM_WHITE, format(_("モンスター = %d, 名前 = %-40.40s", "Monster = %d, Name = %-40.40s"), enum2i(monrace_id), r_ptr->name.data()));
222 term_putstr(10, 19, -1, TERM_WHITE, format(_("初期値 色 / 文字 = %3u / %3u", "Default attr/char = %3u / %3u"), da, dc));
223 term_putstr(40, 19, -1, TERM_WHITE, empty_symbol);
224 term_queue_bigchar(43, 19, da, dc, 0, 0);
225 term_putstr(10, 20, -1, TERM_WHITE, format(_("現在値 色 / 文字 = %3u / %3u", "Current attr/char = %3u / %3u"), ca, cc));
226 term_putstr(40, 20, -1, TERM_WHITE, empty_symbol);
227 term_queue_bigchar(43, 20, ca, cc, 0, 0);
228 term_putstr(0, 22, -1, TERM_WHITE, _("コマンド (n/N/^N/a/A/^A/c/C/^C/v/V/^V): ", "Command (n/N/^N/a/A/^A/c/C/^C/v/V/^V): "));
235 c = 'a' + i - KTRL('A');
236 } else if (isupper(i)) {
244 const auto new_monrace_id_opt = input_new_visual_id(i, num, static_cast<short>(monraces_info.size()));
245 if (!new_monrace_id_opt.has_value()) {
249 const auto new_monrace_id = new_monrace_id_opt.value();
250 monrace_id = i2enum<MonsterRaceId>(new_monrace_id);
251 num = new_monrace_id;
255 const auto visual_id = input_new_visual_id(i, r_ptr->x_attr, 256);
256 if (!visual_id.has_value()) {
260 r_ptr->x_attr = visual_id.value();
265 const auto visual_id = input_new_visual_id(i, r_ptr->x_char, 256);
266 if (!visual_id.has_value()) {
270 r_ptr->x_char = visual_id.value();
275 do_cmd_knowledge_monsters(player_ptr, &need_redraw, true, monrace_id);
277 print_visuals_menu(choice_msg);
285 static auto choice_msg = _("アイテムの[色/文字]を変更します", "Change object attr/chars");
286 static short bi_id = 0;
287 prt(format(_("コマンド: %s", "Command: %s"), choice_msg), 15, 0);
289 auto &baseitem = baseitems_info[bi_id];
291 TERM_COLOR da = baseitem.d_attr;
292 auto dc = baseitem.d_char;
293 TERM_COLOR ca = baseitem.x_attr;
294 auto cc = baseitem.x_char;
296 term_putstr(5, 17, -1, TERM_WHITE,
298 _("アイテム = %d, 名前 = %-40.40s", "Object = %d, Name = %-40.40s"), bi_id, (!baseitem.flavor ? baseitem.name : baseitem.flavor_name).data()));
299 term_putstr(10, 19, -1, TERM_WHITE, format(_("初期値 色 / 文字 = %3d / %3d", "Default attr/char = %3d / %3d"), da, dc));
300 term_putstr(40, 19, -1, TERM_WHITE, empty_symbol);
301 term_queue_bigchar(43, 19, da, dc, 0, 0);
302 term_putstr(10, 20, -1, TERM_WHITE, format(_("現在値 色 / 文字 = %3d / %3d", "Current attr/char = %3d / %3d"), ca, cc));
303 term_putstr(40, 20, -1, TERM_WHITE, empty_symbol);
304 term_queue_bigchar(43, 20, ca, cc, 0, 0);
305 term_putstr(0, 22, -1, TERM_WHITE, _("コマンド (n/N/^N/a/A/^A/c/C/^C/v/V/^V): ", "Command (n/N/^N/a/A/^A/c/C/^C/v/V/^V): "));
313 c = 'a' + i - KTRL('A');
314 } else if (isupper(i)) {
322 std::optional<short> new_baseitem_id(std::nullopt);
323 const auto previous_bi_id = bi_id;
325 new_baseitem_id = input_new_visual_id(i, bi_id, static_cast<short>(baseitems_info.size()));
326 if (!new_baseitem_id.has_value()) {
327 bi_id = previous_bi_id;
331 bi_id = new_baseitem_id.value();
332 if (!baseitems_info[bi_id].name.empty()) {
340 const auto visual_id = input_new_visual_id(i, baseitem.x_attr, 256);
341 if (!visual_id.has_value()) {
345 baseitem.x_attr = visual_id.value();
350 const auto visual_id = input_new_visual_id(i, baseitem.x_char, 256);
351 if (!visual_id.has_value()) {
355 baseitem.x_char = visual_id.value();
360 do_cmd_knowledge_objects(player_ptr, &need_redraw, true, bi_id);
362 print_visuals_menu(choice_msg);
370 static auto choice_msg = _("地形の[色/文字]を変更します", "Change feature attr/chars");
371 static short terrain_id = 0;
372 static short lighting_level = F_LIT_STANDARD;
373 prt(format(_("コマンド: %s", "Command: %s"), choice_msg), 15, 0);
375 auto *f_ptr = &terrains_info[terrain_id];
377 TERM_COLOR da = f_ptr->d_attr[lighting_level];
378 byte dc = f_ptr->d_char[lighting_level];
379 TERM_COLOR ca = f_ptr->x_attr[lighting_level];
380 byte cc = f_ptr->x_char[lighting_level];
383 term_putstr(5, 17, -1, TERM_WHITE,
384 format(_("地形 = %d, 名前 = %s, 明度 = %s", "Terrain = %d, Name = %s, Lighting = %s"), terrain_id, (f_ptr->name.data()),
385 lighting_level_str[lighting_level]));
386 term_putstr(10, 19, -1, TERM_WHITE, format(_("初期値 色 / 文字 = %3d / %3d", "Default attr/char = %3d / %3d"), da, dc));
387 term_putstr(40, 19, -1, TERM_WHITE, empty_symbol);
388 term_queue_bigchar(43, 19, da, dc, 0, 0);
389 term_putstr(10, 20, -1, TERM_WHITE, format(_("現在値 色 / 文字 = %3d / %3d", "Current attr/char = %3d / %3d"), ca, cc));
390 term_putstr(40, 20, -1, TERM_WHITE, empty_symbol);
391 term_queue_bigchar(43, 20, ca, cc, 0, 0);
392 term_putstr(0, 22, -1, TERM_WHITE,
393 _("コマンド (n/N/^N/a/A/^A/c/C/^C/l/L/^L/d/D/^D/v/V/^V): ", "Command (n/N/^N/a/A/^A/c/C/^C/l/L/^L/d/D/^D/v/V/^V): "));
401 c = 'a' + i - KTRL('A');
402 } else if (isupper(i)) {
410 std::optional<short> new_terrain_id(std::nullopt);
411 const auto previous_terrain_id = terrain_id;
413 new_terrain_id = input_new_visual_id(i, terrain_id, static_cast<short>(terrains_info.size()));
414 if (!new_terrain_id.has_value()) {
415 terrain_id = previous_terrain_id;
419 terrain_id = new_terrain_id.value();
420 if (!terrains_info[terrain_id].name.empty() && (terrains_info[terrain_id].mimic == terrain_id)) {
428 const auto visual_id = input_new_visual_id(i, f_ptr->x_attr[lighting_level], 256);
429 if (!visual_id.has_value()) {
433 f_ptr->x_attr[lighting_level] = visual_id.value();
438 const auto visual_id = input_new_visual_id(i, f_ptr->x_char[lighting_level], 256);
439 if (!visual_id.has_value()) {
443 f_ptr->x_char[lighting_level] = visual_id.value();
448 const auto visual_id = input_new_visual_id(i, lighting_level, F_LIT_MAX);
449 if (!visual_id.has_value()) {
453 lighting_level = visual_id.value();
457 apply_default_feat_lighting(f_ptr->x_attr, f_ptr->x_char);
461 do_cmd_knowledge_features(&need_redraw, true, terrain_id, &lighting_level);
463 print_visuals_menu(choice_msg);
471 do_cmd_knowledge_monsters(player_ptr, &need_redraw, true);
474 do_cmd_knowledge_objects(player_ptr, &need_redraw, true, -1);
477 IDX lighting_level = F_LIT_STANDARD;
478 do_cmd_knowledge_features(&need_redraw, true, -1, &lighting_level);
483 reset_visuals(player_ptr);
484 msg_print(_("画面上の[色/文字]を初期値にリセットしました。", "Visual attr/char tables reset."));
497 do_cmd_redraw(player_ptr);