summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-04-21 20:36:23 +0300
committerAndrei Karas <akaras@inbox.ru>2017-04-21 20:37:02 +0300
commite465ecdf0c7f867a62236a5a0945a85f35eee039 (patch)
tree7bc97c683d542f11a1f5b069e77cf70f552d14fe /src/gui
parent862e8f821789014b6167f37976b80694d6d310e3 (diff)
downloadmv-e465ecdf0c7f867a62236a5a0945a85f35eee039.tar.gz
mv-e465ecdf0c7f867a62236a5a0945a85f35eee039.tar.bz2
mv-e465ecdf0c7f867a62236a5a0945a85f35eee039.tar.xz
mv-e465ecdf0c7f867a62236a5a0945a85f35eee039.zip
Show item options in item popups.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/popups/itempopup.cpp67
-rw-r--r--src/gui/popups/itempopup.h8
-rw-r--r--src/gui/widgets/itemlinkhandler.cpp3
3 files changed, 72 insertions, 6 deletions
diff --git a/src/gui/popups/itempopup.cpp b/src/gui/popups/itempopup.cpp
index 9d88c57ff..7d58161c3 100644
--- a/src/gui/popups/itempopup.cpp
+++ b/src/gui/popups/itempopup.cpp
@@ -38,17 +38,22 @@
#include "resources/iteminfo.h"
+#include "resources/db/itemoptiondb.h"
#include "resources/db/unitsdb.h"
#include "resources/image/image.h"
#include "resources/item/item.h"
+#include "resources/item/itemfieldtype.h"
+#include "resources/item/itemoptionslist.h"
#include "resources/loaders/imageloader.h"
#include "net/beinghandler.h"
#include "net/serverfeatures.h"
+#include "utils/translation/podict.h"
+
#include "debug.h"
ItemPopup *itemPopup = nullptr;
@@ -60,6 +65,7 @@ ItemPopup::ItemPopup() :
mItemEffect(new TextBox(this)),
mItemWeight(new TextBox(this)),
mItemCards(new TextBox(this)),
+ mItemOptions(new TextBox(this)),
mItemType(ItemDbType::UNUSABLE),
mIcon(new Icon(this, nullptr)),
mLastName(),
@@ -95,6 +101,12 @@ ItemPopup::ItemPopup() :
mItemCards->setPosition(0, 4 * fontHeight);
mItemCards->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP),
getThemeColor(ThemeColorId::POPUP_OUTLINE));
+
+ // Item options
+ mItemOptions->setEditable(false);
+ mItemOptions->setPosition(0, 5 * fontHeight);
+ mItemOptions->setForegroundColorAll(getThemeColor(ThemeColorId::POPUP),
+ getThemeColor(ThemeColorId::POPUP_OUTLINE));
}
void ItemPopup::postInit()
@@ -105,6 +117,7 @@ void ItemPopup::postInit()
add(mItemEffect);
add(mItemWeight);
add(mItemCards);
+ add(mItemOptions);
add(mIcon);
addMouseListener(this);
@@ -131,7 +144,8 @@ void ItemPopup::setItem(const Item *const item,
item->getColor(),
showImage,
item->getId(),
- item->getCards());
+ item->getCards(),
+ item->getOptions());
if (item->getRefine() > 0)
{
mLastName = ii.getName();
@@ -162,7 +176,8 @@ void ItemPopup::setItem(const ItemInfo &item,
const ItemColor color,
const bool showImage,
int id,
- const int *const cards)
+ const int *const cards,
+ const ItemOptionsList *const options)
{
if (!mIcon || (item.getName() == mLastName && color == mLastColor
&& id == mLastId))
@@ -226,6 +241,7 @@ void ItemPopup::setItem(const ItemInfo &item,
mItemWeight->setTextWrapped(strprintf(_("Weight: %s"),
UnitsDb::formatWeight(item.getWeight()).c_str()), 196);
mItemCards->setTextWrapped(getCardsString(cards), 196);
+ mItemOptions->setTextWrapped(getOptionsString(options), 196);
int minWidth = mItemName->getWidth() + space;
@@ -239,29 +255,37 @@ void ItemPopup::setItem(const ItemInfo &item,
minWidth = mItemWeight->getMinWidth();
if (mItemCards->getMinWidth() > minWidth)
minWidth = mItemCards->getMinWidth();
+ if (mItemOptions->getMinWidth() > minWidth)
+ minWidth = mItemOptions->getMinWidth();
const int numRowsDesc = mItemDesc->getNumberOfRows();
const int numRowsEffect = mItemEffect->getNumberOfRows();
const int numRowsWeight = mItemWeight->getNumberOfRows();
const int numRowsCards = mItemCards->getNumberOfRows();
+ const int numRowsOptions = mItemOptions->getNumberOfRows();
const int height = getFont()->getHeight();
if (item.getEffect().empty())
{
setContentSize(minWidth,
- (numRowsDesc + 2 + numRowsWeight + numRowsCards) * height);
+ (numRowsDesc + 2 + numRowsWeight + numRowsCards + numRowsOptions) *
+ height);
mItemWeight->setPosition(0, (numRowsDesc + 2) * height);
mItemCards->setPosition(0, (numRowsDesc + numRowsWeight + 2) * height);
+ mItemOptions->setPosition(0,
+ (numRowsDesc + numRowsWeight + numRowsCards + 2) * height);
}
else
{
setContentSize(minWidth, (numRowsDesc + numRowsEffect + 2
- + numRowsWeight + numRowsCards) * height);
+ + numRowsWeight + numRowsCards + numRowsOptions) * height);
mItemEffect->setPosition(0, (numRowsDesc + 2) * height);
mItemWeight->setPosition(0, (numRowsDesc + numRowsEffect + 2)
* height);
mItemCards->setPosition(0, (numRowsDesc + numRowsEffect
+ numRowsWeight + 2) * height);
+ mItemOptions->setPosition(0, (numRowsDesc + numRowsEffect
+ + numRowsWeight + numRowsCards + 2) * height);
}
mItemDesc->setPosition(0, 2 * height);
@@ -319,6 +343,41 @@ std::string ItemPopup::getCardsString(const int *const cards)
}
}
+std::string ItemPopup::getOptionsString(const ItemOptionsList *const options)
+{
+ if (options == nullptr || translator == nullptr)
+ return std::string();
+ const size_t sz = options->size();
+ std::string effect;
+ for (size_t f = 0; f < sz; f ++)
+ {
+ const ItemOption &option = options->get(f);
+ if (option.index == 0)
+ continue;
+ const std::vector<ItemFieldType*> &fields = ItemOptionDb::getFields(
+ option.index);
+ if (fields.empty())
+ continue;
+ const std::string valueStr = toString(option.value);
+ FOR_EACH (std::vector<ItemFieldType*>::const_iterator, it, fields)
+ {
+ const ItemFieldType *const field = *it;
+ std::string value = valueStr;
+ if (!effect.empty())
+ effect.append(" / ");
+ if (field->sign && value[0] != '-')
+ value = "+" + value;
+ const std::string format = translator->getStr(field->description);
+ effect.append(strprintf(format.c_str(),
+ value.c_str()));
+ }
+ }
+ if (effect.empty())
+ return effect;
+ // TRANSLATORS: popup label
+ return _("Options: ") + effect;
+}
+
#define caseSetColor(name1, name2) \
case name1: \
{ \
diff --git a/src/gui/popups/itempopup.h b/src/gui/popups/itempopup.h
index 0ba6c4406..de552eca7 100644
--- a/src/gui/popups/itempopup.h
+++ b/src/gui/popups/itempopup.h
@@ -36,6 +36,8 @@ class ItemInfo;
class Label;
class TextBox;
+struct ItemOptionsList;
+
/**
* A popup that displays information about an item.
*/
@@ -63,7 +65,8 @@ class ItemPopup final : public Popup
const ItemColor color,
const bool showImage,
int id,
- const int *const cards);
+ const int *const cards,
+ const ItemOptionsList *const options);
void setItem(const Item *const item,
const bool showImage);
@@ -75,11 +78,14 @@ class ItemPopup final : public Popup
private:
std::string getCardsString(const int *const cards);
+ std::string getOptionsString(const ItemOptionsList *const options);
+
Label *mItemName A_NONNULLPOINTER;
TextBox *mItemDesc A_NONNULLPOINTER;
TextBox *mItemEffect A_NONNULLPOINTER;
TextBox *mItemWeight A_NONNULLPOINTER;
TextBox *mItemCards A_NONNULLPOINTER;
+ TextBox *mItemOptions A_NONNULLPOINTER;
ItemDbTypeT mItemType;
Icon *mIcon A_NONNULLPOINTER;
std::string mLastName;
diff --git a/src/gui/widgets/itemlinkhandler.cpp b/src/gui/widgets/itemlinkhandler.cpp
index b2e4a89c9..90a26a4a0 100644
--- a/src/gui/widgets/itemlinkhandler.cpp
+++ b/src/gui/widgets/itemlinkhandler.cpp
@@ -154,7 +154,8 @@ void ItemLinkHandler::handleItemLink(const std::string &link)
ItemColorManager::getColorFromCards(&str[0]);
const ItemInfo &itemInfo = ItemDB::get(id);
- itemPopup->setItem(itemInfo, color, true, -1, &str[0]);
+ // +++ need add support for options.
+ itemPopup->setItem(itemInfo, color, true, -1, &str[0], nullptr);
if (itemPopup->isPopupVisible())
{
itemPopup->setVisible(Visible_false);