diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-07-14 23:42:09 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-07-14 23:42:09 +0300 |
commit | 4761556e5e4cf8471ab65c65c2b3fd4003ac5ba0 (patch) | |
tree | 2115d5af0ecc1d041e292be30105716b68419fb7 /src/gui/popups | |
parent | fc23b24f67b5c8dc6744df01fbb9b05aee93a70c (diff) | |
download | mv-4761556e5e4cf8471ab65c65c2b3fd4003ac5ba0.tar.gz mv-4761556e5e4cf8471ab65c65c2b3fd4003ac5ba0.tar.bz2 mv-4761556e5e4cf8471ab65c65c2b3fd4003ac5ba0.tar.xz mv-4761556e5e4cf8471ab65c65c2b3fd4003ac5ba0.zip |
In item popup show attached cards to item.
Diffstat (limited to 'src/gui/popups')
-rw-r--r-- | src/gui/popups/itempopup.cpp | 70 | ||||
-rw-r--r-- | src/gui/popups/itempopup.h | 6 |
2 files changed, 64 insertions, 12 deletions
diff --git a/src/gui/popups/itempopup.cpp b/src/gui/popups/itempopup.cpp index 1c38e9eec..2374f693b 100644 --- a/src/gui/popups/itempopup.cpp +++ b/src/gui/popups/itempopup.cpp @@ -53,35 +53,42 @@ ItemPopup::ItemPopup() : mItemDesc(new TextBox(this)), mItemEffect(new TextBox(this)), mItemWeight(new TextBox(this)), + mItemCards(new TextBox(this)), mItemType(ItemType::UNUSABLE), mIcon(new Icon(this, nullptr)), mLastName(), mLastId(0), mLastColor(1) { - // Item Name + // Item name mItemName->setFont(boldFont); mItemName->setPosition(0, 0); const int fontHeight = getFont()->getHeight(); - // Item Description + // Item description mItemDesc->setEditable(false); mItemDesc->setPosition(0, fontHeight); mItemDesc->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP), getThemeColor(ThemeColorId::POPUP_OUTLINE)); - // Item Effect + // Item effect mItemEffect->setEditable(false); mItemEffect->setPosition(0, 2 * fontHeight); mItemEffect->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP), getThemeColor(ThemeColorId::POPUP_OUTLINE)); - // Item Weight + // Item weight mItemWeight->setEditable(false); mItemWeight->setPosition(0, 3 * fontHeight); mItemWeight->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP), getThemeColor(ThemeColorId::POPUP_OUTLINE)); + + // Item cards + mItemCards->setEditable(false); + mItemCards->setPosition(0, 4 * fontHeight); + mItemCards->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP), + getThemeColor(ThemeColorId::POPUP_OUTLINE)); } void ItemPopup::postInit() @@ -91,6 +98,7 @@ void ItemPopup::postInit() add(mItemDesc); add(mItemEffect); add(mItemWeight); + add(mItemCards); add(mIcon); addMouseListener(this); @@ -106,13 +114,18 @@ ItemPopup::~ItemPopup() } } -void ItemPopup::setItem(const Item *const item, const bool showImage) +void ItemPopup::setItem(const Item *const item, + const bool showImage) { if (!item) return; const ItemInfo &ii = item->getInfo(); - setItem(ii, item->getColor(), showImage, item->getId()); + setItem(ii, + item->getColor(), + showImage, + item->getId(), + item->getCards()); if (item->getRefine() > 0) { mLastName = ii.getName(); @@ -139,8 +152,11 @@ void ItemPopup::setItem(const Item *const item, const bool showImage) } } -void ItemPopup::setItem(const ItemInfo &item, const unsigned char color, - const bool showImage, int id) +void ItemPopup::setItem(const ItemInfo &item, + const unsigned char color, + const bool showImage, + int id, + const int *const cards) { if (!mIcon || (item.getName() == mLastName && color == mLastColor && id == mLastId)) @@ -203,6 +219,7 @@ void ItemPopup::setItem(const ItemInfo &item, const unsigned char color, // TRANSLATORS: popup label mItemWeight->setTextWrapped(strprintf(_("Weight: %s"), Units::formatWeight(item.getWeight()).c_str()), 196); + mItemCards->setTextWrapped(getCardsString(cards), 196); int minWidth = mItemName->getWidth() + space; @@ -214,29 +231,60 @@ void ItemPopup::setItem(const ItemInfo &item, const unsigned char color, minWidth = mItemEffect->getMinWidth(); if (mItemWeight->getMinWidth() > minWidth) minWidth = mItemWeight->getMinWidth(); + if (mItemCards->getMinWidth() > minWidth) + minWidth = mItemCards->getMinWidth(); const int numRowsDesc = mItemDesc->getNumberOfRows(); const int numRowsEffect = mItemEffect->getNumberOfRows(); const int numRowsWeight = mItemWeight->getNumberOfRows(); + const int numRowsCards = mItemCards->getNumberOfRows(); const int height = getFont()->getHeight(); if (item.getEffect().empty()) { - setContentSize(minWidth, (numRowsDesc + 2 + numRowsWeight) * height); + setContentSize(minWidth, + (numRowsDesc + 2 + numRowsWeight + numRowsCards) * height); mItemWeight->setPosition(0, (numRowsDesc + 2) * height); + mItemCards->setPosition(0, (numRowsDesc + numRowsWeight + 2) * height); } else { setContentSize(minWidth, (numRowsDesc + numRowsEffect + 2 - + numRowsWeight) * height); + + numRowsWeight + numRowsCards) * height); + mItemEffect->setPosition(0, (numRowsDesc + 2) * height); mItemWeight->setPosition(0, (numRowsDesc + numRowsEffect + 2) * height); - mItemEffect->setPosition(0, (numRowsDesc + 2) * height); + mItemCards->setPosition(0, (numRowsDesc + numRowsEffect + + numRowsWeight + 2) * height); } mItemDesc->setPosition(0, 2 * height); } +std::string ItemPopup::getCardsString(const int *const cards) +{ + if (!cards) + return std::string(); + + std::string label; + + for (int f = 0; f < maxCards; f ++) + { + const int id = cards[f]; + if (id) + { + if (!label.empty()) + label.append(" / "); + const ItemInfo &info = ItemDB::get(id); + label.append(info.getName()); + } + } + if (label.empty()) + return label; + // TRANSLATORS: popup label + return _("Cards: ") + label; +} + #define caseSetColor(name1, name2) \ case name1: \ { \ diff --git a/src/gui/popups/itempopup.h b/src/gui/popups/itempopup.h index 4c63ff785..6072bc90c 100644 --- a/src/gui/popups/itempopup.h +++ b/src/gui/popups/itempopup.h @@ -60,7 +60,8 @@ class ItemPopup final : public Popup void setItem(const ItemInfo &item, const unsigned char color, const bool showImage, - int id); + int id, + const int *const cards); void setItem(const Item *const item, const bool showImage); @@ -68,10 +69,13 @@ class ItemPopup final : public Popup void mouseMoved(MouseEvent &event) override final; private: + std::string getCardsString(const int *const cards); + Label *mItemName; TextBox *mItemDesc; TextBox *mItemEffect; TextBox *mItemWeight; + TextBox *mItemCards; ItemType::Type mItemType; Icon *mIcon; std::string mLastName; |