summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/popups/itempopup.cpp70
-rw-r--r--src/gui/popups/itempopup.h6
-rw-r--r--src/gui/widgets/itemlinkhandler.cpp2
3 files changed, 65 insertions, 13 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;
diff --git a/src/gui/widgets/itemlinkhandler.cpp b/src/gui/widgets/itemlinkhandler.cpp
index 40ec08c33..5a11103d9 100644
--- a/src/gui/widgets/itemlinkhandler.cpp
+++ b/src/gui/widgets/itemlinkhandler.cpp
@@ -118,7 +118,7 @@ void ItemLinkHandler::handleLink(const std::string &link, MouseEvent *event)
if (id > 0)
{
const ItemInfo &itemInfo = ItemDB::get(id);
- itemPopup->setItem(itemInfo, color, true, -1);
+ itemPopup->setItem(itemInfo, color, true, -1, nullptr);
if (itemPopup->isPopupVisible())
{
itemPopup->setVisible(Visible_false);