From 1240589615918547fab96a8b9315a66d068e712e Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 20 Aug 2015 22:41:22 +0300 Subject: Add support for reading iconColors palette field from items. --- src/resources/db/itemdb.cpp | 16 ++++++++++---- src/resources/iteminfo.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++ src/resources/iteminfo.h | 21 ++++++++++++++++-- 3 files changed, 84 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp index 2f593e551..784a0e619 100644 --- a/src/resources/db/itemdb.cpp +++ b/src/resources/db/itemdb.cpp @@ -319,12 +319,19 @@ void ItemDB::loadXmlFile(const std::string &fileName, int &tagNum) node, "maxFloorOffset", mapTileSize, 0, mapTileSize); std::string useButton = XML::langProperty(node, "useButton", ""); std::string useButton2 = XML::langProperty(node, "useButton2", ""); - std::string colors; - colors = XML::getProperty(node, "colors", ""); + std::string colors = XML::getProperty(node, "colors", ""); + std::string iconColors = XML::getProperty(node, "iconColors", ""); + if (iconColors.empty()) + iconColors = colors; // check for empty hair palete - if (colors.empty() && id <= -1 && id > -100) - colors = "hair"; + if (id <= -1 && id > -100) + { + if (colors.empty()) + colors = "hair"; + if (iconColors.empty()) + iconColors = "hair"; + } std::string tags[3]; tags[0] = XML::getProperty(node, "tag", @@ -425,6 +432,7 @@ void ItemDB::loadXmlFile(const std::string &fileName, int &tagNum) itemInfo->setDrawAfter(-1, parseSpriteName(drawAfter)); itemInfo->setDrawPriority(-1, drawPriority); itemInfo->setColorsList(colors); + itemInfo->setIconColorsList(iconColors); itemInfo->setMaxFloorOffset(maxFloorOffset); itemInfo->setPickupCursor(XML::getProperty( node, "pickupCursor", "pickup")); diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index ade20ef0b..56b2e1fe0 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -60,7 +60,9 @@ ItemInfo::ItemInfo() : mSounds(), mTags(), mColorsList(nullptr), + mIconColorsList(nullptr), mColorsListName(), + mIconColorsListName(), mCardColor(ItemColor_zero), mHitEffectId(-1), mCriticalHitEffectId(-1), @@ -202,6 +204,20 @@ void ItemInfo::setColorsList(const std::string &name) } } +void ItemInfo::setIconColorsList(const std::string &name) +{ + if (name.empty()) + { + mIconColorsList = nullptr; + mIconColorsListName.clear(); + } + else + { + mIconColorsList = ColorDB::getColorsList(name); + mIconColorsListName = name; + } +} + std::string ItemInfo::getDyeColorsString(const ItemColor color) const { if (!mColorsList || mColorsListName.empty()) @@ -215,6 +231,19 @@ std::string ItemInfo::getDyeColorsString(const ItemColor color) const return it->second.color; } +std::string ItemInfo::getDyeIconColorsString(const ItemColor color) const +{ + if (!mIconColorsList || mIconColorsListName.empty()) + return ""; + + const std::map ::const_iterator + it = mIconColorsList->find(color); + if (it == mIconColorsList->end()) + return ""; + + return it->second.color; +} + const std::string ItemInfo::getDescription(const ItemColor color) const { return replaceColors(mDescription, color); @@ -393,3 +422,27 @@ std::string ItemInfo::getColor(const ItemColor idx) const return std::string(); return it->second.color; } + +std::string ItemInfo::getIconColorName(const ItemColor idx) const +{ + if (!mIconColorsList) + return std::string(); + + const std::map ::const_iterator + it = mIconColorsList->find(idx); + if (it == mIconColorsList->end()) + return std::string(); + return it->second.name; +} + +std::string ItemInfo::getIconColor(const ItemColor idx) const +{ + if (!mIconColorsList) + return std::string(); + + const std::map ::const_iterator + it = mIconColorsList->find(idx); + if (it == mIconColorsList->end()) + return std::string(); + return it->second.color; +} diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 27191f92e..c022b650a 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -245,13 +245,22 @@ class ItemInfo final const SpriteToItemMap *getSpriteToItemReplaceMap(const int directions) const A_WARN_UNUSED; - std::string getDyeColorsString(const ItemColor color) const A_WARN_UNUSED; + std::string getDyeColorsString(const ItemColor color) + const A_WARN_UNUSED; + + std::string getDyeIconColorsString(const ItemColor color) + const A_WARN_UNUSED; void setColorsList(const std::string &name); + void setIconColorsList(const std::string &name); + bool isHaveColors() const A_WARN_UNUSED { return !mColorsListName.empty(); } + bool isHaveIconColors() const A_WARN_UNUSED + { return !mIconColorsListName.empty(); } + const std::string replaceColors(std::string str, const ItemColor color) const A_WARN_UNUSED; @@ -274,10 +283,16 @@ class ItemInfo final int getColorsSize() const { return mColorsList ? static_cast(mColorsList->size()) : 0; } - std::string getColorName(const ItemColor idx) const; + int getIconColorsSize() const + { return mIconColorsList ? static_cast(mIconColorsList->size()) + : 0; } + std::string getColorName(const ItemColor idx) const; std::string getColor(const ItemColor idx) const; + std::string getIconColorName(const ItemColor idx) const; + std::string getIconColor(const ItemColor idx) const; + int mDrawBefore[10]; int mDrawAfter[10]; int mDrawPriority[10]; @@ -325,7 +340,9 @@ class ItemInfo final std::map mSounds; std::map mTags; const std::map *mColorsList; + const std::map *mIconColorsList; std::string mColorsListName; + std::string mIconColorsListName; ItemColor mCardColor; int mHitEffectId; int mCriticalHitEffectId; -- cgit v1.2.3-70-g09d2