OSDN Git Service

Merge branch 'develop' into macos-develop
[hengbandforosx/hengbandosx.git] / src / cmd-io / cmd-diary.cpp
index 398c2ce..158a374 100644 (file)
@@ -1,21 +1,24 @@
-#include "cmd-io/cmd-diary.h"
-#include "cmd-io/diary-subtitle-table.h"
+#include "cmd-io/cmd-diary.h"
 #include "core/asking-player.h"
 #include "core/show-file.h"
 #include "game-option/play-record-options.h"
-#include "io/record-play-movie.h"
 #include "io/files-util.h"
 #include "io/input-key-acceptor.h"
+#include "io/record-play-movie.h"
 #include "io/write-diary.h"
 #include "main/sound-of-music.h"
 #include "player-base/player-class.h"
 #include "player/player-personality.h"
 #include "system/player-type-definition.h"
+#include "term/gameterm.h"
 #include "term/screen-processor.h"
+#include "term/z-form.h"
 #include "util/angband-files.h"
 #include "util/int-char-converter.h"
 #include "view/display-messages.h"
 #include "world/world.h"
+#include <sstream>
+#include <string>
 
 /*!
  * @brief 日記のタイトル表記と内容出力
  */
 static void display_diary(PlayerType *player_ptr)
 {
-    char diary_title[256];
-    GAME_TEXT file_name[MAX_NLEN];
-    char buf[1024];
-    char tmp[80];
-    sprintf(file_name, _("playrecord-%s.txt", "playrec-%s.txt"), savefile_base);
-    path_build(buf, sizeof(buf), ANGBAND_DIR_USER, file_name);
-
-    if (player_ptr->pclass == PlayerClassType::WARRIOR || player_ptr->pclass == PlayerClassType::MONK || player_ptr->pclass == PlayerClassType::SAMURAI
-        || player_ptr->pclass == PlayerClassType::BERSERKER)
-        strcpy(tmp, subtitle[randint0(MAX_SUBTITLE - 1)]);
-    else if (PlayerClass(player_ptr).is_wizard())
-        strcpy(tmp, subtitle[randint0(MAX_SUBTITLE - 1) + 1]);
-    else
-        strcpy(tmp, subtitle[randint0(MAX_SUBTITLE - 2) + 1]);
-
+    const auto subtitle_candidates = PlayerClass(player_ptr).get_subtitle_candidates();
+    const auto choice = Rand_external(subtitle_candidates.size());
+    const auto &subtitle = subtitle_candidates[choice];
 #ifdef JP
-    sprintf(diary_title, "「%s%s%sの伝説 -%s-」", ap_ptr->title, ap_ptr->no ? "の" : "", player_ptr->name, tmp);
+    const auto diary_title = format("「%s%s%sの伝説 -%s-」", ap_ptr->title, ap_ptr->no ? "の" : "", player_ptr->name, subtitle.data());
 #else
-    sprintf(diary_title, "Legend of %s %s '%s'", ap_ptr->title, player_ptr->name, tmp);
+    const auto diary_title = format("Legend of %s %s '%s'", ap_ptr->title, player_ptr->name, subtitle.data());
 #endif
 
-    (void)show_file(player_ptr, false, buf, diary_title, -1, 0);
+    std::stringstream ss;
+    ss << _("playrecord-", "playrec-") << savefile_base << ".txt";
+    const auto &path = path_build(ANGBAND_DIR_USER, ss.str());
+    (void)show_file(player_ptr, false, path.string(), -1, 0, diary_title);
 }
 
 /*!
@@ -52,11 +46,9 @@ static void display_diary(PlayerType *player_ptr)
  */
 static void add_diary_note(PlayerType *player_ptr)
 {
-    char tmp[80] = "\0";
-    char bunshou[80] = "\0";
-    if (get_string(_("内容: ", "diary note: "), tmp, 79)) {
-        strcpy(bunshou, tmp);
-        exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, bunshou);
+    const auto input_str = input_string(_("内容: ", "diary note: "), 1000);
+    if (input_str) {
+        exe_write_diary(player_ptr, DiaryKind::DESCRIPTION, 0, *input_str);
     }
 }
 
@@ -65,42 +57,43 @@ static void add_diary_note(PlayerType *player_ptr)
  */
 static void do_cmd_last_get(PlayerType *player_ptr)
 {
-    if (record_o_name[0] == '\0')
+    if (record_o_name[0] == '\0') {
         return;
+    }
 
-    char buf[256];
-    sprintf(buf, _("%sの入手を記録します。", "Do you really want to record getting %s? "), record_o_name);
-    if (!get_check(buf))
+    const auto record = format(_("%sの入手を記録します。", "Do you really want to record getting %s? "), record_o_name);
+    if (!input_check(record)) {
         return;
+    }
 
     GAME_TURN turn_tmp = w_ptr->game_turn;
     w_ptr->game_turn = record_turn;
-    sprintf(buf, _("%sを手に入れた。", "discover %s."), record_o_name);
-    exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, buf);
+    const auto mes = format(_("%sを手に入れた。", "discover %s."), record_o_name);
+    exe_write_diary(player_ptr, DiaryKind::DESCRIPTION, 0, mes);
     w_ptr->game_turn = turn_tmp;
 }
 
 /*!
  * @brief ファイル中の全日記記録を消去する /
  */
-static void do_cmd_erase_diary(void)
+static void do_cmd_erase_diary()
 {
-    GAME_TEXT file_name[MAX_NLEN];
-    char buf[256];
-    FILE *fff = nullptr;
-
-    if (!get_check(_("本当に記録を消去しますか?", "Do you really want to delete all your records? ")))
+    if (!input_check(_("本当に記録を消去しますか?", "Do you really want to delete all your records? "))) {
         return;
-    sprintf(file_name, _("playrecord-%s.txt", "playrec-%s.txt"), savefile_base);
-    path_build(buf, sizeof(buf), ANGBAND_DIR_USER, file_name);
-    fd_kill(buf);
+    }
+
+    std::stringstream ss;
+    ss << _("playrecord-", "playrec-") << savefile_base << ".txt";
+    const auto &path = path_build(ANGBAND_DIR_USER, ss.str());
+    fd_kill(path);
 
-    fff = angband_fopen(buf, "w");
+    auto *fff = angband_fopen(path, FileOpenMode::WRITE);
     if (fff) {
         angband_fclose(fff);
         msg_format(_("記録を消去しました。", "deleted record."));
     } else {
-        msg_format(_("%s の消去に失敗しました。", "failed to delete %s."), buf);
+        const auto &filename = path.string();
+        msg_format(_("%s の消去に失敗しました。", "failed to delete %s."), filename.data());
     }
 
     msg_print(nullptr);
@@ -113,6 +106,8 @@ static void do_cmd_erase_diary(void)
 void do_cmd_diary(PlayerType *player_ptr)
 {
     screen_save();
+    TermCenteredOffsetSetter tcos(MAIN_TERM_MIN_COLS, MAIN_TERM_MIN_ROWS);
+
     while (true) {
         term_clear();
         prt(_("[ 記録の設定 ]", "[ Play Record ]"), 2, 0);
@@ -123,8 +118,9 @@ void do_cmd_diary(PlayerType *player_ptr)
         prt(_("(R) プレイ動画を記録する/中止する", "(R) Record playing movie / or stop it"), 9, 5);
         prt(_("コマンド:", "Command: "), 18, 0);
         int i = inkey();
-        if (i == ESCAPE)
+        if (i == ESCAPE) {
             break;
+        }
 
         switch (i) {
         case '1':