From dd3ea66fa2422f19fefec5539583e8122fbd98fe Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Fri, 28 May 2021 09:18:18 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Split=20getTextColor(bool)?= =?UTF-8?q?=20into=202=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a bit more readable than using a bool argument. --- Source/control.cpp | 2 +- Source/inv.cpp | 2 +- Source/items.cpp | 2 +- Source/items.h | 11 ++++++++--- Source/qol/itemlabels.cpp | 2 +- Source/stores.cpp | 16 ++++++++-------- 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index b6de147d5..2844f7bed 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -1156,7 +1156,7 @@ void DrawInfoBox(const CelOutputBuffer &out) strcpy(infostr, myPlayer.HoldItem._iIName); else strcpy(infostr, myPlayer.HoldItem._iName); - infoclr = myPlayer.HoldItem.getTextColor(true); + infoclr = myPlayer.HoldItem.getTextColor(); } } else { if (pcursitem != -1) diff --git a/Source/inv.cpp b/Source/inv.cpp index f8c118ac9..5b6054cd7 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -2001,7 +2001,7 @@ char CheckInvHLight() int nGold = pi->_ivalue; strcpy(infostr, fmt::format(ngettext("{:d} gold piece", "{:d} gold pieces", nGold), nGold).c_str()); } else { - infoclr = pi->getTextColor(true); + infoclr = pi->getTextColor(); if (pi->_iIdentified) { strcpy(infostr, pi->_iIName); PrintItemDetails(pi); diff --git a/Source/items.cpp b/Source/items.cpp index 101084fc0..79d564df9 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -3028,7 +3028,7 @@ void GetItemStr(int i) else strcpy(infostr, items[i]._iName); - infoclr = items[i].getTextColor(true); + infoclr = items[i].getTextColor(); } else { int nGold = items[i]._ivalue; strcpy(infostr, fmt::format(ngettext("{:d} gold piece", "{:d} gold pieces", nGold), nGold).c_str()); diff --git a/Source/items.h b/Source/items.h index a3314efb9..14b4f6b87 100644 --- a/Source/items.h +++ b/Source/items.h @@ -351,10 +351,8 @@ struct ItemStruct { } } - UiFlags getTextColor(bool skipStatCheck = false) const + UiFlags getTextColor() const { - if (!skipStatCheck && !_iStatFlag) - return UIS_RED; switch (_iMagical) { case ITEM_QUALITY_MAGIC: return UIS_BLUE; @@ -364,6 +362,13 @@ struct ItemStruct { return UIS_SILVER; } } + + UiFlags getTextColorWithStatCheck() const + { + if (!_iStatFlag) + return UIS_RED; + return getTextColor(); + } }; struct ItemGetRecordStruct { diff --git a/Source/qol/itemlabels.cpp b/Source/qol/itemlabels.cpp index 673157e6b..82f87fe5f 100644 --- a/Source/qol/itemlabels.cpp +++ b/Source/qol/itemlabels.cpp @@ -156,7 +156,7 @@ void DrawItemNameLabels(const CelOutputBuffer &out) FillRect(out, label.pos.x, label.pos.y - height + marginY, label.width, height, PAL8_BLUE + 6); else DrawHalfTransparentRectTo(out, label.pos.x, label.pos.y - height + marginY, label.width, height); - DrawString(out, label.text.c_str(), { label.pos.x + marginX, label.pos.y, label.width, height }, itm.getTextColor(true)); + DrawString(out, label.text.c_str(), { label.pos.x + marginX, label.pos.y, label.width, height }, itm.getTextColor()); } labelQueue.clear(); } diff --git a/Source/stores.cpp b/Source/stores.cpp index 8254e197b..4654c0de5 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -234,7 +234,7 @@ void S_ScrollSBuy(int idx) for (int l = 5; l < 20; l += 4) { if (!smithitem[idx].isEmpty()) { - uint16_t iclr = smithitem[idx].getTextColor(); + uint16_t iclr = smithitem[idx].getTextColorWithStatCheck(); if (smithitem[idx]._iMagical != 0) { AddSText(20, l, smithitem[idx]._iIName, iclr, true); @@ -292,7 +292,7 @@ void S_ScrollSPBuy(int boughtitems) for (int l = 5; l < 20 && idx < SMITH_PREMIUM_ITEMS; l += 4) { if (!premiumitems[idx].isEmpty()) { - uint16_t iclr = premiumitems[idx].getTextColor(); + uint16_t iclr = premiumitems[idx].getTextColorWithStatCheck(); AddSText(20, l, premiumitems[idx]._iIName, iclr, true); AddSTextVal(l, premiumitems[idx]._iIvalue); PrintStoreItem(&premiumitems[idx], l + 1, iclr); @@ -382,7 +382,7 @@ void S_ScrollSSell(int idx) if (idx >= storenumh) break; if (!storehold[idx].isEmpty()) { - uint16_t iclr = storehold[idx].getTextColor(); + uint16_t iclr = storehold[idx].getTextColorWithStatCheck(); if (storehold[idx]._iMagical != 0 && storehold[idx]._iIdentified) { AddSText(20, l, storehold[idx]._iIName, iclr, true); @@ -605,7 +605,7 @@ void S_ScrollWBuy(int idx) for (int l = 5; l < 20; l += 4) { if (!witchitem[idx].isEmpty()) { - uint16_t iclr = witchitem[idx].getTextColor(); + uint16_t iclr = witchitem[idx].getTextColorWithStatCheck(); if (witchitem[idx]._iMagical != 0) { AddSText(20, l, witchitem[idx]._iIName, iclr, true); @@ -858,7 +858,7 @@ void S_StartConfirm() auto &item = plr[myplr].HoldItem; - uint16_t iclr = item.getTextColor(); + uint16_t iclr = item.getTextColorWithStatCheck(); bool idprint = item._iMagical != ITEM_QUALITY_NORMAL; @@ -943,7 +943,7 @@ void S_StartBBoy() AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSLine(3); AddSLine(21); - uint16_t iclr = boyitem.getTextColor(); + uint16_t iclr = boyitem.getTextColorWithStatCheck(); if (boyitem._iMagical != ITEM_QUALITY_NORMAL) AddSText(20, 10, boyitem._iIName, iclr, true); @@ -994,7 +994,7 @@ void S_ScrollHBuy(int idx) stextup = 5; for (l = 5; l < 20; l += 4) { if (!healitem[idx].isEmpty()) { - uint16_t iclr = healitem[idx].getTextColor(); + uint16_t iclr = healitem[idx].getTextColorWithStatCheck(); AddSText(20, l, healitem[idx]._iName, iclr, true); AddSTextVal(l, healitem[idx]._iIvalue); @@ -1167,7 +1167,7 @@ void S_StartIdShow() auto &item = plr[myplr].HoldItem; - uint16_t iclr = item.getTextColor(); + uint16_t iclr = item.getTextColorWithStatCheck(); AddSText(0, 7, _("This item is:"), UIS_SILVER | UIS_CENTER, false); AddSText(20, 11, item._iIName, iclr, false);