summaryrefslogtreecommitdiff
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
parent862e8f821789014b6167f37976b80694d6d310e3 (diff)
downloadmanaverse-e465ecdf0c7f867a62236a5a0945a85f35eee039.tar.gz
manaverse-e465ecdf0c7f867a62236a5a0945a85f35eee039.tar.bz2
manaverse-e465ecdf0c7f867a62236a5a0945a85f35eee039.tar.xz
manaverse-e465ecdf0c7f867a62236a5a0945a85f35eee039.zip
Show item options in item popups.
-rw-r--r--src/gui/popups/itempopup.cpp67
-rw-r--r--src/gui/popups/itempopup.h8
-rw-r--r--src/gui/widgets/itemlinkhandler.cpp3
-rw-r--r--src/resources/db/itemdb.cpp8
-rw-r--r--src/resources/db/itemoptiondb.cpp9
-rw-r--r--src/resources/db/itemoptiondb.h2
6 files changed, 90 insertions, 7 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);
diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp
index 77ff5b269..94c9b14b8 100644
--- a/src/resources/db/itemdb.cpp
+++ b/src/resources/db/itemdb.cpp
@@ -46,6 +46,8 @@
#include "utils/dtor.h"
#include "utils/stringmap.h"
+#include "utils/translation/podict.h"
+
#include "debug.h"
namespace
@@ -127,6 +129,9 @@ static void readFields(std::string &effect,
XmlNodeConstPtr node,
const ItemFieldDb::FieldInfos &fields)
{
+ if (!translator)
+ return;
+
FOR_EACH (ItemFieldDb::FieldInfos::const_iterator, it, fields)
{
const std::string fieldName = (*it).first;
@@ -141,7 +146,8 @@ static void readFields(std::string &effect,
effect.append(" / ");
if (field->sign && isDigit(value))
value = "+" + value;
- effect.append(strprintf(gettext(field->description.c_str()),
+ const std::string format = translator->getStr(field->description);
+ effect.append(strprintf(format.c_str(),
value.c_str()));
}
}
diff --git a/src/resources/db/itemoptiondb.cpp b/src/resources/db/itemoptiondb.cpp
index becdf7406..504199bfc 100644
--- a/src/resources/db/itemoptiondb.cpp
+++ b/src/resources/db/itemoptiondb.cpp
@@ -36,6 +36,7 @@
namespace
{
ItemOptionDb::OptionInfos mOptions;
+ const std::vector<ItemFieldType*> mEmptyOption;
bool mLoaded = false;
} // namespace
@@ -141,3 +142,11 @@ void ItemOptionDb::unload()
mOptions.clear();
mLoaded = false;
}
+
+const std::vector<ItemFieldType*> &ItemOptionDb::getFields(const int id)
+{
+ OptionInfos::const_iterator it = mOptions.find(id);
+ if (it == mOptions.end())
+ return mEmptyOption;
+ return (*it).second;
+}
diff --git a/src/resources/db/itemoptiondb.h b/src/resources/db/itemoptiondb.h
index 6c7fb898f..9e088c76f 100644
--- a/src/resources/db/itemoptiondb.h
+++ b/src/resources/db/itemoptiondb.h
@@ -40,6 +40,8 @@ namespace ItemOptionDb
void loadXmlFile(const std::string &fileName,
const SkipError skipError);
+ const std::vector<ItemFieldType*> &getFields(const int id);
+
typedef std::map<int, std::vector<ItemFieldType*> > OptionInfos;
} // namespace ItemOptionDb