OSDN Git Service

[Refactor] #3286 Removed player-redraw-types.h
[hengbandforosx/hengbandosx.git] / src / cmd-io / cmd-gameoption.cpp
index e9cd45a..9100fff 100644 (file)
@@ -3,7 +3,6 @@
 #include "cmd-io/cmd-autopick.h"
 #include "cmd-io/cmd-dump.h"
 #include "core/asking-player.h"
-#include "core/player-redraw-types.h"
 #include "core/show-file.h"
 #include "core/window-redrawer.h"
 #include "floor/geometry.h"
 #include "main/sound-of-music.h"
 #include "system/game-option-types.h"
 #include "system/player-type-definition.h"
+#include "system/redrawing-flags-updater.h"
 #include "term/gameterm.h"
 #include "term/screen-processor.h"
 #include "term/term-color-types.h"
+#include "term/z-form.h"
 #include "util/bit-flags-calculator.h"
 #include "util/int-char-converter.h"
 #include "util/string-processor.h"
 
 #define OPT_NUM 15
 
-typedef struct {
+struct opts {
     char key;
     concptr name;
     int row;
-} opts;
+};
 
 static opts option_fields[OPT_NUM] = {
     { '1', _("    キー入力     オプション", "Input Options"), 3 },
@@ -93,20 +94,16 @@ static void do_cmd_options_autosave(PlayerType *player_ptr, concptr info)
 {
     char ch;
     int i, k = 0, n = 2;
-    char buf[80];
     term_clear();
     while (true) {
-        sprintf(buf,
-            _("%s ( リターンで次へ, y/n でセット, F で頻度を入力, ESC で決定 ) ", "%s (RET to advance, y/n to set, 'F' for frequency, ESC to accept) "), info);
-        prt(buf, 0, 0);
+        prt(format(_("%s ( リターンで次へ, y/n でセット, F で頻度を入力, ESC で決定 ) ", "%s (RET to advance, y/n to set, 'F' for frequency, ESC to accept) "), info), 0, 0);
         for (i = 0; i < n; i++) {
             byte a = TERM_WHITE;
-            if (i == k)
+            if (i == k) {
                 a = TERM_L_BLUE;
+            }
 
-            sprintf(
-                buf, "%-48s: %s (%s)", autosave_info[i].o_desc, (*autosave_info[i].o_var ? _("はい  ", "yes") : _("いいえ", "no ")), autosave_info[i].o_text);
-            c_prt(a, buf, i + 2, 0);
+            c_prt(a, format("%-48s: %s (%s)", autosave_info[i].o_desc, (*autosave_info[i].o_var ? _("はい  ", "yes") : _("いいえ", "no ")), autosave_info[i].o_text), i + 2, 0);
         }
 
         prt(format(_("自動セーブの頻度: %d ターン毎", "Timed autosave frequency: every %d turns"), autosave_freq), 5, 0);
@@ -191,8 +188,9 @@ static bool has_window_flag(int x, int y)
 static void set_window_flag(int x, int y)
 {
     auto flag = i2enum<window_redraw_type>(1UL << y);
-    if (any_bits(PW_ALL, flag))
+    if (any_bits(PW_ALL, flag)) {
         set_bits(window_flag[x], flag);
+    }
 }
 
 /*!
@@ -232,8 +230,9 @@ static void do_cmd_options_win(PlayerType *player_ptr)
         for (j = 0; j < 8; j++) {
             byte a = TERM_WHITE;
             concptr s = angband_term_name[j];
-            if (j == x)
+            if (j == x) {
                 a = TERM_L_BLUE;
+            }
 
             term_putstr(35 + j * 5 - strlen(s) / 2, 2 + j % 2, -1, a, s);
         }
@@ -241,21 +240,25 @@ static void do_cmd_options_win(PlayerType *player_ptr)
         for (i = 0; i < 16; i++) {
             byte a = TERM_WHITE;
             concptr str = window_flag_desc[i];
-            if (i == y)
+            if (i == y) {
                 a = TERM_L_BLUE;
+            }
 
-            if (!str)
+            if (!str) {
                 str = _("(未使用)", "(Unused option)");
+            }
 
             term_putstr(0, i + 5, -1, a, str);
             for (j = 0; j < 8; j++) {
                 char c = '.';
                 a = TERM_WHITE;
-                if ((i == y) && (j == x))
+                if ((i == y) && (j == x)) {
                     a = TERM_L_BLUE;
+                }
 
-                if (window_flag[j] & (1UL << i))
+                if (window_flag[j] & (1UL << i)) {
                     c = 'X';
+                }
 
                 term_putch(35 + j * 5, i + 5, a, c);
             }
@@ -273,13 +276,15 @@ static void do_cmd_options_win(PlayerType *player_ptr)
         case 'T':
             has_flag = has_window_flag(x, y);
             window_flag[x] = 0;
-            if (x > 0 && !has_flag)
+            if (x > 0 && !has_flag) {
                 set_window_flag(x, y);
+            }
             break;
         case 's':
         case 'S':
-            if (x == 0)
+            if (x == 0) {
                 break;
+            }
             window_flag[x] = 0;
             clear_window_flag(x, y);
             set_window_flag(x, y);
@@ -292,21 +297,24 @@ static void do_cmd_options_win(PlayerType *player_ptr)
             d = get_keymap_dir(ch);
             x = (x + ddx[d] + 8) % 8;
             y = (y + ddy[d] + 16) % 16;
-            if (!d)
+            if (!d) {
                 bell();
+            }
             break;
         }
     }
 
-    for (j = 0; j < 8; j++) {
-        term_type *old = Term;
-        if (!angband_term[j])
+    for (auto term_index = 0U; term_index < angband_terms.size(); ++term_index) {
+        term_type *old = game_term;
+        if (!angband_terms[term_index]) {
             continue;
+        }
 
-        if (window_flag[j] == old_flag[j])
+        if (window_flag[term_index] == old_flag[term_index]) {
             continue;
+        }
 
-        term_activate(angband_term[j]);
+        term_activate(angband_terms[term_index]);
         term_clear();
         term_fresh();
         term_activate(old);
@@ -324,9 +332,7 @@ static void do_cmd_options_cheat(PlayerType *player_ptr, concptr info)
     auto k = 0U;
     const auto n = cheat_info.size();
     while (true) {
-        char buf[80];
-        sprintf(buf, _("%s ( リターンで次へ, y/n でセット, ESC で決定 )", "%s (RET to advance, y/n to set, ESC to accept) "), info);
-        prt(buf, 0, 0);
+        prt(format(_("%s ( リターンで次へ, y/n でセット, ESC で決定 )", "%s (RET to advance, y/n to set, ESC to accept) "), info), 0, 0);
 
 #ifdef JP
         /* 詐欺オプションをうっかりいじってしまう人がいるようなので注意 */
@@ -341,8 +347,7 @@ static void do_cmd_options_cheat(PlayerType *player_ptr, concptr info)
                 a = TERM_L_BLUE;
             }
 
-            sprintf(buf, "%-48s: %s (%s)", cheat_info[i].o_desc, (*cheat_info[i].o_var ? _("はい  ", "yes") : _("いいえ", "no ")), cheat_info[i].o_text);
-            c_prt(enum2i(a), buf, i + 2, 0);
+            c_prt(enum2i(a), format("%-48s: %s (%s)", cheat_info[i].o_desc, (*cheat_info[i].o_var ? _("はい  ", "yes") : _("いいえ", "no ")), cheat_info[i].o_text), i + 2, 0);
         }
 
         move_cursor(k + 2, 50);
@@ -384,8 +389,7 @@ static void do_cmd_options_cheat(PlayerType *player_ptr, concptr info)
             k = (k + 1) % n;
             break;
         case '?':
-            strnfmt(buf, sizeof(buf), _("joption.txt#%s", "option.txt#%s"), cheat_info[k].o_text);
-            (void)show_file(player_ptr, true, buf, nullptr, 0, 0);
+            (void)show_file(player_ptr, true, std::string(_("joption.txt#", "option.txt#")).append(cheat_info[k].o_text).data(), nullptr, 0, 0);
             term_clear();
             break;
         default:
@@ -424,34 +428,40 @@ void extract_option_vars(void)
  */
 void do_cmd_options(PlayerType *player_ptr)
 {
+    TermCenteredOffsetSetter tcos(MAIN_TERM_MIN_COLS, MAIN_TERM_MIN_ROWS);
+
     char k;
     int d, skey;
     TERM_LEN i, y = 0;
     screen_save();
     while (true) {
         int n = OPT_NUM;
-        if (!w_ptr->noscore && !allow_debug_opts)
+        if (!w_ptr->noscore && !allow_debug_opts) {
             n--;
+        }
 
         term_clear();
         prt(_("[ オプションの設定 ]", "Game options"), 1, 0);
         while (true) {
             for (i = 0; i < n; i++) {
                 byte a = TERM_WHITE;
-                if (i == y)
+                if (i == y) {
                     a = TERM_L_BLUE;
+                }
                 term_putstr(5, option_fields[i].row, -1, a, format("(%c) %s", toupper(option_fields[i].key), option_fields[i].name));
             }
 
             prt(_("<方向>で移動, Enterで決定, ESCでキャンセル, ?でヘルプ: ", "Move to <dir>, Select to Enter, Cancel to ESC, ? to help: "), 21, 0);
             skey = inkey_special(true);
-            if (!(skey & SKEY_MASK))
+            if (!(skey & SKEY_MASK)) {
                 k = (char)skey;
-            else
+            } else {
                 k = 0;
+            }
 
-            if (k == ESCAPE)
+            if (k == ESCAPE) {
                 break;
+            }
 
             if (angband_strchr("\n\r ", k)) {
                 k = option_fields[y].key;
@@ -459,28 +469,35 @@ void do_cmd_options(PlayerType *player_ptr)
             }
 
             for (i = 0; i < n; i++) {
-                if (tolower(k) == option_fields[i].key)
+                if (tolower(k) == option_fields[i].key) {
                     break;
+                }
             }
 
-            if (i < n)
+            if (i < n) {
                 break;
+            }
 
-            if (k == '?')
+            if (k == '?') {
                 break;
+            }
 
             d = 0;
-            if (skey == SKEY_UP)
+            if (skey == SKEY_UP) {
                 d = 8;
-            if (skey == SKEY_DOWN)
+            }
+            if (skey == SKEY_DOWN) {
                 d = 2;
+            }
             y = (y + ddy[d] + n) % n;
-            if (!d)
+            if (!d) {
                 bell();
+            }
         }
 
-        if (k == ESCAPE)
+        if (k == ESCAPE) {
             break;
+        }
 
         switch (k) {
         case '1': {
@@ -516,7 +533,7 @@ void do_cmd_options(PlayerType *player_ptr)
         case 'b': {
             do_cmd_options_aux(player_ptr, OPT_PAGE_BIRTH,
                 (!w_ptr->wizard || !allow_debug_opts) ? _("初期オプション(参照のみ)", "Birth Options(browse only)")
-                                                                  : _("初期オプション((*)はスコアに影響)", "Birth Options ((*)) affect score"));
+                                                      : _("初期オプション((*)はスコアに影響)", "Birth Options ((*)) affect score"));
             break;
         }
         case 'C':
@@ -561,15 +578,16 @@ void do_cmd_options(PlayerType *player_ptr)
                 prt(format(_("現在の低ヒットポイント警告: %d0%%", "Current hitpoint warning: %d0%%"), hitpoint_warn), 22, 0);
                 prt(_("低ヒットポイント警告 (0-9) ESCで決定: ", "Hitpoint Warning (0-9 or ESC to accept): "), 20, 0);
                 k = inkey();
-                if (k == ESCAPE)
+                if (k == ESCAPE) {
                     break;
-                else if (k == '?') {
+                else if (k == '?') {
                     (void)show_file(player_ptr, true, _("joption.txt#Hitpoint", "option.txt#Hitpoint"), nullptr, 0, 0);
                     term_clear();
-                } else if (isdigit(k))
+                } else if (isdigit(k)) {
                     hitpoint_warn = D2I(k);
-                else
+                } else {
                     bell();
+                }
             }
 
             break;
@@ -582,15 +600,16 @@ void do_cmd_options(PlayerType *player_ptr)
                 prt(format(_("現在の低魔力色閾値: %d0%%", "Current mana color threshold: %d0%%"), mana_warn), 22, 0);
                 prt(_("低魔力閾値 (0-9) ESCで決定: ", "Mana color Threshold (0-9 or ESC to accept): "), 20, 0);
                 k = inkey();
-                if (k == ESCAPE)
+                if (k == ESCAPE) {
                     break;
-                else if (k == '?') {
+                else if (k == '?') {
                     (void)show_file(player_ptr, true, _("joption.txt#Manapoint", "option.txt#Manapoint"), nullptr, 0, 0);
                     term_clear();
-                } else if (isdigit(k))
+                } else if (isdigit(k)) {
                     mana_warn = D2I(k);
-                else
+                } else {
                     bell();
+                }
             }
 
             break;
@@ -609,7 +628,7 @@ void do_cmd_options(PlayerType *player_ptr)
     }
 
     screen_load();
-    player_ptr->redraw |= (PR_EQUIPPY);
+    RedrawingFlagsUpdater::get_instance().set_flag(MainWindowRedrawingFlag::EQUIPPY);
 }
 
 /*!
@@ -622,51 +641,56 @@ void do_cmd_options_aux(PlayerType *player_ptr, game_option_types page, concptr
 {
     char ch;
     int i, k = 0, n = 0, l;
-    int opt[24];
-    char buf[80];
+    int opt[MAIN_TERM_MIN_ROWS];
     bool browse_only = (page == OPT_PAGE_BIRTH) && w_ptr->character_generated && (!w_ptr->wizard || !allow_debug_opts);
 
-    for (i = 0; i < 24; i++)
+    for (i = 0; i < MAIN_TERM_MIN_ROWS; i++) {
         opt[i] = 0;
+    }
 
     for (i = 0; option_info[i].o_desc; i++) {
-        if (option_info[i].o_page == page)
+        if (option_info[i].o_page == page) {
             opt[n++] = i;
+        }
     }
 
     term_clear();
     while (true) {
         DIRECTION dir;
-        sprintf(buf, _("%s (リターン:次, %sESC:終了, ?:ヘルプ) ", "%s (RET:next, %s, ?:help) "), info,
-            browse_only ? _("", "ESC:exit") : _("y/n:変更, ", "y/n:change, ESC:accept"));
-        prt(buf, 0, 0);
-        if (page == OPT_PAGE_AUTODESTROY)
-            c_prt(TERM_YELLOW, _("以下のオプションは、簡易自動破壊を使用するときのみ有効", "Following options will protect items from easy auto-destroyer."), 6,
-                _(6, 3));
+        constexpr auto command = _("%s (リターン:次, %sESC:終了, ?:ヘルプ) ", "%s (RET:next, %s, ?:help) ");
+        prt(format(command, info, browse_only ? _("", "ESC:exit") : _("y/n:変更, ", "y/n:change, ESC:accept")), 0, 0);
+        if (page == OPT_PAGE_AUTODESTROY) {
+            constexpr auto mes = _("以下のオプションは、簡易自動破壊を使用するときのみ有効", "Following options will protect items from easy auto-destroyer.");
+            c_prt(TERM_YELLOW, mes, 6, _(6, 3));
+        }
 
         for (i = 0; i < n; i++) {
             byte a = TERM_WHITE;
-            if (i == k)
+            if (i == k) {
                 a = TERM_L_BLUE;
+            }
 
-            sprintf(buf, "%-48s: %s (%.19s)", option_info[opt[i]].o_desc, (*option_info[opt[i]].o_var ? _("はい  ", "yes") : _("いいえ", "no ")),
+            std::string label = format("%-48s: %s (%.19s)", option_info[opt[i]].o_desc, (*option_info[opt[i]].o_var ? _("はい  ", "yes") : _("いいえ", "no ")),
                 option_info[opt[i]].o_text);
-            if ((page == OPT_PAGE_AUTODESTROY) && i > 2)
-                c_prt(a, buf, i + 5, 0);
-            else
-                c_prt(a, buf, i + 2, 0);
+            if ((page == OPT_PAGE_AUTODESTROY) && i > 2) {
+                c_prt(a, label, i + 5, 0);
+            } else {
+                c_prt(a, label, i + 2, 0);
+            }
         }
 
-        if ((page == OPT_PAGE_AUTODESTROY) && (k > 2))
+        if ((page == OPT_PAGE_AUTODESTROY) && (k > 2)) {
             l = 3;
-        else
+        } else {
             l = 0;
+        }
 
         move_cursor(k + 2 + l, 50);
         ch = inkey();
         dir = get_keymap_dir(ch);
-        if ((dir == 2) || (dir == 4) || (dir == 6) || (dir == 8))
+        if ((dir == 2) || (dir == 4) || (dir == 6) || (dir == 8)) {
             ch = I2D(dir);
+        }
 
         switch (ch) {
         case ESCAPE: {
@@ -687,8 +711,9 @@ void do_cmd_options_aux(PlayerType *player_ptr, game_option_types page, concptr
         case 'y':
         case 'Y':
         case '6': {
-            if (browse_only)
+            if (browse_only) {
                 break;
+            }
             (*option_info[opt[k]].o_var) = true;
             k = (k + 1) % n;
             break;
@@ -696,21 +721,22 @@ void do_cmd_options_aux(PlayerType *player_ptr, game_option_types page, concptr
         case 'n':
         case 'N':
         case '4': {
-            if (browse_only)
+            if (browse_only) {
                 break;
+            }
             (*option_info[opt[k]].o_var) = false;
             k = (k + 1) % n;
             break;
         }
         case 't':
         case 'T': {
-            if (!browse_only)
+            if (!browse_only) {
                 (*option_info[opt[k]].o_var) = !(*option_info[opt[k]].o_var);
+            }
             break;
         }
         case '?': {
-            strnfmt(buf, sizeof(buf), _("joption.txt#%s", "option.txt#%s"), option_info[opt[k]].o_text);
-            (void)show_file(player_ptr, true, buf, nullptr, 0, 0);
+            (void)show_file(player_ptr, true, std::string(_("joption.txt#", "option.txt#")).append(option_info[opt[k]].o_text).data(), nullptr, 0, 0);
             term_clear();
             break;
         }