OSDN Git Service

[Refactor] struct player_type を class PlayerType に置換。
[hengbandforosx/hengbandosx.git] / src / cmd-io / cmd-diary.cpp
1 #include "cmd-io/cmd-diary.h"
2 #include "cmd-io/diary-subtitle-table.h"
3 #include "core/asking-player.h"
4 #include "core/show-file.h"
5 #include "game-option/play-record-options.h"
6 #include "io/record-play-movie.h"
7 #include "io/files-util.h"
8 #include "io/input-key-acceptor.h"
9 #include "io/write-diary.h"
10 #include "main/sound-of-music.h"
11 #include "player-base/player-class.h"
12 #include "player/player-personality.h"
13 #include "system/player-type-definition.h"
14 #include "term/screen-processor.h"
15 #include "util/angband-files.h"
16 #include "util/int-char-converter.h"
17 #include "view/display-messages.h"
18 #include "world/world.h"
19
20 /*!
21  * @brief 日記のタイトル表記と内容出力
22  * @param player_ptr プレイヤーへの参照ポインタ
23  */
24 static void display_diary(PlayerType *player_ptr)
25 {
26     char diary_title[256];
27     GAME_TEXT file_name[MAX_NLEN];
28     char buf[1024];
29     char tmp[80];
30     sprintf(file_name, _("playrecord-%s.txt", "playrec-%s.txt"), savefile_base);
31     path_build(buf, sizeof(buf), ANGBAND_DIR_USER, file_name);
32
33     if (player_ptr->pclass == PlayerClassType::WARRIOR || player_ptr->pclass == PlayerClassType::MONK || player_ptr->pclass == PlayerClassType::SAMURAI
34         || player_ptr->pclass == PlayerClassType::BERSERKER)
35         strcpy(tmp, subtitle[randint0(MAX_SUBTITLE - 1)]);
36     else if (PlayerClass(player_ptr).is_wizard())
37         strcpy(tmp, subtitle[randint0(MAX_SUBTITLE - 1) + 1]);
38     else
39         strcpy(tmp, subtitle[randint0(MAX_SUBTITLE - 2) + 1]);
40
41 #ifdef JP
42     sprintf(diary_title, "「%s%s%sの伝説 -%s-」", ap_ptr->title, ap_ptr->no ? "の" : "", player_ptr->name, tmp);
43 #else
44     sprintf(diary_title, "Legend of %s %s '%s'", ap_ptr->title, player_ptr->name, tmp);
45 #endif
46
47     (void)show_file(player_ptr, false, buf, diary_title, -1, 0);
48 }
49
50 /*!
51  * @brief 日記に任意の内容を表記するコマンドのメインルーチン /
52  */
53 static void add_diary_note(PlayerType *player_ptr)
54 {
55     char tmp[80] = "\0";
56     char bunshou[80] = "\0";
57     if (get_string(_("内容: ", "diary note: "), tmp, 79)) {
58         strcpy(bunshou, tmp);
59         exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, bunshou);
60     }
61 }
62
63 /*!
64  * @brief 最後に取得したアイテムの情報を日記に追加するメインルーチン /
65  */
66 static void do_cmd_last_get(PlayerType *player_ptr)
67 {
68     if (record_o_name[0] == '\0')
69         return;
70
71     char buf[256];
72     sprintf(buf, _("%sの入手を記録します。", "Do you really want to record getting %s? "), record_o_name);
73     if (!get_check(buf))
74         return;
75
76     GAME_TURN turn_tmp = w_ptr->game_turn;
77     w_ptr->game_turn = record_turn;
78     sprintf(buf, _("%sを手に入れた。", "discover %s."), record_o_name);
79     exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, buf);
80     w_ptr->game_turn = turn_tmp;
81 }
82
83 /*!
84  * @brief ファイル中の全日記記録を消去する /
85  */
86 static void do_cmd_erase_diary(void)
87 {
88     GAME_TEXT file_name[MAX_NLEN];
89     char buf[256];
90     FILE *fff = nullptr;
91
92     if (!get_check(_("本当に記録を消去しますか?", "Do you really want to delete all your records? ")))
93         return;
94     sprintf(file_name, _("playrecord-%s.txt", "playrec-%s.txt"), savefile_base);
95     path_build(buf, sizeof(buf), ANGBAND_DIR_USER, file_name);
96     fd_kill(buf);
97
98     fff = angband_fopen(buf, "w");
99     if (fff) {
100         angband_fclose(fff);
101         msg_format(_("記録を消去しました。", "deleted record."));
102     } else {
103         msg_format(_("%s の消去に失敗しました。", "failed to delete %s."), buf);
104     }
105
106     msg_print(nullptr);
107 }
108
109 /*!
110  * @brief 日記コマンド
111  * @param crerature_ptr プレイヤーへの参照ポインタ
112  */
113 void do_cmd_diary(PlayerType *player_ptr)
114 {
115     screen_save();
116     while (true) {
117         term_clear();
118         prt(_("[ 記録の設定 ]", "[ Play Record ]"), 2, 0);
119         prt(_("(1) 記録を見る", "(1) Display your record"), 4, 5);
120         prt(_("(2) 文章を記録する", "(2) Add record"), 5, 5);
121         prt(_("(3) 直前に入手又は鑑定したものを記録する", "(3) Record the last item you got or identified"), 6, 5);
122         prt(_("(4) 記録を消去する", "(4) Delete your record"), 7, 5);
123         prt(_("(R) プレイ動画を記録する/中止する", "(R) Record playing movie / or stop it"), 9, 5);
124         prt(_("コマンド:", "Command: "), 18, 0);
125         int i = inkey();
126         if (i == ESCAPE)
127             break;
128
129         switch (i) {
130         case '1':
131             display_diary(player_ptr);
132             break;
133         case '2':
134             add_diary_note(player_ptr);
135             break;
136         case '3':
137             do_cmd_last_get(player_ptr);
138             break;
139         case '4':
140             do_cmd_erase_diary();
141             break;
142         case 'r':
143         case 'R':
144             screen_load();
145             prepare_movie_hooks(player_ptr);
146             return;
147         default:
148             bell();
149         }
150
151         msg_erase();
152     }
153
154     screen_load();
155 }