OSDN Git Service

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