OSDN Git Service

Merge branch 'master' of https://github.com/hengband/hengband
[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.data(), ap_ptr->no ? "の" : "", player_ptr->name, subtitle.data());
34 #else
35     const auto diary_title = format("Legend of %s %s '%s'", ap_ptr->title.data(), player_ptr->name, subtitle.data());
36 #endif
37
38     std::stringstream ss;
39     ss << _("playrecord-", "playrec-") << savefile_base.string() << ".txt";
40     const auto path = path_build(ANGBAND_DIR_USER, ss.str());
41     FileDisplayer(player_ptr->name).display(false, path.string(), -1, 0, diary_title);
42 }
43
44 /*!
45  * @brief 日記に任意の内容を表記するコマンドのメインルーチン /
46  */
47 static void add_diary_note(const FloorType &floor)
48 {
49     const auto input_str = input_string(_("内容: ", "diary note: "), 1000);
50     if (input_str) {
51         exe_write_diary(floor, DiaryKind::DESCRIPTION, 0, *input_str);
52     }
53 }
54
55 /*!
56  * @brief 最後に取得したアイテムの情報を日記に追加するメインルーチン /
57  */
58 static void do_cmd_last_get(const FloorType &floor)
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     auto &world = AngbandWorld::get_instance();
70     const auto turn_tmp = world.game_turn;
71     world.game_turn = record_turn;
72     const auto mes = format(_("%sを手に入れた。", "discover %s."), record_o_name);
73     exe_write_diary(floor, DiaryKind::DESCRIPTION, 0, mes);
74     world.game_turn = turn_tmp;
75 }
76
77 /*!
78  * @brief ファイル中の全日記記録を消去する /
79  */
80 static void do_cmd_erase_diary()
81 {
82     if (!input_check(_("本当に記録を消去しますか?", "Do you really want to delete all your records? "))) {
83         return;
84     }
85
86     std::stringstream ss;
87     ss << _("playrecord-", "playrec-") << savefile_base.string() << ".txt";
88     const auto path = path_build(ANGBAND_DIR_USER, ss.str());
89     fd_kill(path);
90
91     auto *fff = angband_fopen(path, FileOpenMode::WRITE);
92     if (fff) {
93         angband_fclose(fff);
94         msg_format(_("記録を消去しました。", "deleted record."));
95     } else {
96         const auto &filename = path.string();
97         msg_format(_("%s の消去に失敗しました。", "failed to delete %s."), filename.data());
98     }
99
100     msg_print(nullptr);
101 }
102
103 /*!
104  * @brief 日記コマンド
105  * @param crerature_ptr プレイヤーへの参照ポインタ
106  */
107 void do_cmd_diary(PlayerType *player_ptr)
108 {
109     screen_save();
110     TermCenteredOffsetSetter tcos(MAIN_TERM_MIN_COLS, MAIN_TERM_MIN_ROWS);
111     const auto &floor = *player_ptr->current_floor_ptr;
112     while (true) {
113         term_clear();
114         prt(_("[ 記録の設定 ]", "[ Play Record ]"), 2, 0);
115         prt(_("(1) 記録を見る", "(1) Display your record"), 4, 5);
116         prt(_("(2) 文章を記録する", "(2) Add record"), 5, 5);
117         prt(_("(3) 直前に入手又は鑑定したものを記録する", "(3) Record the last item you got or identified"), 6, 5);
118         prt(_("(4) 記録を消去する", "(4) Delete your record"), 7, 5);
119         prt(_("(R) プレイ動画を記録する/中止する", "(R) Record playing movie / or stop it"), 9, 5);
120         prt(_("コマンド:", "Command: "), 18, 0);
121         int i = inkey();
122         if (i == ESCAPE) {
123             break;
124         }
125
126         switch (i) {
127         case '1':
128             display_diary(player_ptr);
129             break;
130         case '2':
131             add_diary_note(floor);
132             break;
133         case '3':
134             do_cmd_last_get(floor);
135             break;
136         case '4':
137             do_cmd_erase_diary();
138             break;
139         case 'r':
140         case 'R':
141             screen_load();
142             prepare_movie_hooks(player_ptr);
143             return;
144         default:
145             bell();
146         }
147
148         msg_erase();
149     }
150
151     screen_load();
152 }