From 4c6bf58e036fcddb86eef8fdcff9510d1a039d53 Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Sun, 19 May 2024 14:04:46 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20#4111=20term=5Fadd=5Fbigch()=20?= =?utf8?q?=E3=81=AE=E5=BC=95=E6=95=B0=E3=82=92ColoredChar=20=E3=81=AB?= =?utf8?q?=E5=A4=89=E3=81=88=E3=80=81=E6=88=BB=E3=82=8A=E5=80=A4=E3=81=AF?= =?utf8?q?=E8=AA=B0=E3=82=82=E4=BD=BF=E3=81=A3=E3=81=A6=E3=81=84=E3=81=AA?= =?utf8?q?=E3=81=84=E3=81=AE=E3=81=A7void=20=E3=81=AB=E5=A4=89=E3=81=88?= =?utf8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/term/z-term.cpp | 19 +++++++++---------- src/term/z-term.h | 3 ++- src/view/display-lore.cpp | 10 +++++----- src/window/display-sub-windows.cpp | 28 ++++++++++++++-------------- src/window/main-window-util.cpp | 2 +- 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/term/z-term.cpp b/src/term/z-term.cpp index c36c02145..db856c1c5 100644 --- a/src/term/z-term.cpp +++ b/src/term/z-term.cpp @@ -14,6 +14,7 @@ #include "term/gameterm.h" #include "term/term-color-types.h" #include "term/z-virt.h" +#include "view/colored-char.h" /* Special flags in the attr data */ #define AF_BIGTILE2 0xf0 @@ -1473,38 +1474,36 @@ errr term_addch(TERM_COLOR a, char c) * Otherwise, queue a pair of attr/char for display at the current * cursor location, and advance the cursor to the right by two. */ -errr term_add_bigch(TERM_COLOR a, char c) +void term_add_bigch(const ColoredChar &cc) { if (!use_bigtile) { - return term_addch(a, c); + (void)term_addch(cc.color, cc.character); + return; } /* Handle "unusable" cursor */ if (game_term->scr->cu) { - return -1; + return; } /* Paranoia -- no illegal chars */ - if (!c) { - return -2; + if (!cc.has_character()) { + return; } /* Queue the given character for display */ - term_queue_bigchar(game_term->scr->cx, game_term->scr->cy, a, c, 0, 0); + term_queue_bigchar(game_term->scr->cx, game_term->scr->cy, cc.color, cc.character, 0, 0); /* Advance the cursor */ game_term->scr->cx += 2; /* Success */ if (game_term->scr->cx < game_term->wid) { - return 0; + return; } /* Note "Useless" cursor */ game_term->scr->cu = 1; - - /* Note "Useless" cursor */ - return 1; } /* diff --git a/src/term/z-term.h b/src/term/z-term.h index 7e7cb73b3..383df2d15 100644 --- a/src/term/z-term.h +++ b/src/term/z-term.h @@ -191,6 +191,7 @@ private: /**** Available Variables ****/ extern term_type *game_term; +class ColoredChar; errr term_user(int n); errr term_xtra(int n, int v); @@ -204,7 +205,7 @@ errr term_set_cursor(int v); errr term_gotoxy(TERM_LEN x, TERM_LEN y); errr term_draw(TERM_LEN x, TERM_LEN y, TERM_COLOR a, char c); errr term_addch(TERM_COLOR a, char c); -errr term_add_bigch(TERM_COLOR a, char c); +void term_add_bigch(const ColoredChar &cc); errr term_addstr(int n, TERM_COLOR a, std::string_view sv); errr term_putch(TERM_LEN x, TERM_LEN y, TERM_COLOR a, char c); errr term_putstr(TERM_LEN x, TERM_LEN y, int n, TERM_COLOR a, std::string_view sv); diff --git a/src/view/display-lore.cpp b/src/view/display-lore.cpp index 9c0faf611..9b2b100e3 100644 --- a/src/view/display-lore.cpp +++ b/src/view/display-lore.cpp @@ -23,6 +23,7 @@ #include "term/z-form.h" #include "util/bit-flags-calculator.h" #include "util/string-processor.h" +#include "view/colored-char.h" #include "view/display-messages.h" #include "world/world.h" @@ -39,11 +40,10 @@ void roff_top(MonsterRaceId r_idx) { auto *r_ptr = &monraces_info[r_idx]; - char c1 = r_ptr->d_char; - char c2 = r_ptr->x_char; - TERM_COLOR a1 = r_ptr->d_attr; + char c1 = r_ptr->d_char; TERM_COLOR a2 = r_ptr->x_attr; + char c2 = r_ptr->x_char; term_erase(0, 0); term_gotoxy(0, 0); @@ -64,11 +64,11 @@ void roff_top(MonsterRaceId r_idx) term_addstr(-1, TERM_WHITE, r_ptr->name); term_addstr(-1, TERM_WHITE, " ('"); - term_add_bigch(a1, c1); + term_add_bigch({ a1, c1 }); term_addstr(-1, TERM_WHITE, "')"); term_addstr(-1, TERM_WHITE, "/('"); - term_add_bigch(a2, c2); + term_add_bigch({ a2, c2 }); term_addstr(-1, TERM_WHITE, "'):"); } diff --git a/src/window/display-sub-windows.cpp b/src/window/display-sub-windows.cpp index 44ccee3ea..493c419b9 100644 --- a/src/window/display-sub-windows.cpp +++ b/src/window/display-sub-windows.cpp @@ -14,6 +14,7 @@ #include "mind/mind-sniper.h" #include "mind/mind-types.h" #include "monster-race/monster-race.h" +#include "monster-race/race-indice-types.h" #include "monster/monster-describer.h" #include "monster/monster-description-types.h" #include "object/item-tester-hooker.h" @@ -128,34 +129,33 @@ void fix_inventory(PlayerType *player_ptr) */ static void print_monster_line(TERM_LEN x, TERM_LEN y, MonsterEntity *m_ptr, int n_same, int n_awake) { - std::string buf; - MonsterRaceId r_idx = m_ptr->ap_r_idx; - auto *r_ptr = &monraces_info[r_idx]; - term_erase(0, y); term_gotoxy(x, y); - if (!r_ptr) { + const auto monrace_id = m_ptr->ap_r_idx; + if (monrace_id == MonsterRaceId::PLAYER) { return; } - if (r_ptr->kind_flags.has(MonsterKindType::UNIQUE)) { - buf = format(_("%3s(覚%2d)", "%3s(%2d)"), MonsterRace(r_idx).is_bounty(true) ? " W" : " U", n_awake); + + std::string buf; + const auto &monrace = monraces_info[monrace_id]; + if (monrace.kind_flags.has(MonsterKindType::UNIQUE)) { + buf = format(_("%3s(覚%2d)", "%3s(%2d)"), MonsterRace(monrace_id).is_bounty(true) ? " W" : " U", n_awake); } else { buf = format(_("%3d(覚%2d)", "%3d(%2d)"), n_same, n_awake); } - term_addstr(-1, TERM_WHITE, buf); + term_addstr(-1, TERM_WHITE, buf); term_addstr(-1, TERM_WHITE, " "); - term_add_bigch(r_ptr->x_attr, r_ptr->x_char); + term_add_bigch({ monrace.x_attr, monrace.x_char }); - if (r_ptr->r_tkills && m_ptr->mflag2.has_not(MonsterConstantFlagType::KAGE)) { - buf = format(" %2d", (int)r_ptr->level); + if (monrace.r_tkills && m_ptr->mflag2.has_not(MonsterConstantFlagType::KAGE)) { + buf = format(" %2d", monrace.level); } else { buf = " ??"; } term_addstr(-1, TERM_WHITE, buf); - - term_addstr(-1, TERM_WHITE, format(" %s ", r_ptr->name.data())); + term_addstr(-1, TERM_WHITE, format(" %s ", monrace.name.data())); } /*! @@ -232,7 +232,7 @@ static void print_pet_list_oneline(PlayerType *player_ptr, const MonsterEntity & } term_gotoxy(x + 13, y); - term_add_bigch(monrace.x_attr, monrace.x_char); + term_add_bigch({ monrace.x_attr, monrace.x_char }); term_addstr(-1, TERM_WHITE, " "); term_addstr(-1, TERM_WHITE, name); diff --git a/src/window/main-window-util.cpp b/src/window/main-window-util.cpp index a5bf55b2c..9ce7ef066 100644 --- a/src/window/main-window-util.cpp +++ b/src/window/main-window-util.cpp @@ -282,7 +282,7 @@ void display_map(PlayerType *player_ptr, int *cy, int *cx) } } - term_add_bigch(ta, tc); + term_add_bigch({ ta, tc }); } } -- 2.11.0