diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-08-20 22:41:22 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-08-20 22:41:22 +0300 |
commit | 1240589615918547fab96a8b9315a66d068e712e (patch) | |
tree | 4e361d32b965973e28a70d4c6b8c352fb2cb0a61 | |
parent | f23abf81cd21907117bf4edf0d814d8bef950e13 (diff) | |
download | manaverse-1240589615918547fab96a8b9315a66d068e712e.tar.gz manaverse-1240589615918547fab96a8b9315a66d068e712e.tar.bz2 manaverse-1240589615918547fab96a8b9315a66d068e712e.tar.xz manaverse-1240589615918547fab96a8b9315a66d068e712e.zip |
Add support for reading iconColors palette field from items.
-rw-r--r-- | src/resources/db/itemdb.cpp | 16 | ||||
-rw-r--r-- | src/resources/iteminfo.cpp | 53 | ||||
-rw-r--r-- | src/resources/iteminfo.h | 21 |
3 files changed, 84 insertions, 6 deletions
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 <ItemColor, ColorDB::ItemColorData>::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 <ItemColor, ColorDB::ItemColorData>::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 <ItemColor, ColorDB::ItemColorData>::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<int>(mColorsList->size()) : 0; } - std::string getColorName(const ItemColor idx) const; + int getIconColorsSize() const + { return mIconColorsList ? static_cast<int>(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 <ItemSoundEvent::Type, SoundInfoVect> mSounds; std::map <int, int> mTags; const std::map <ItemColor, ColorDB::ItemColorData> *mColorsList; + const std::map <ItemColor, ColorDB::ItemColorData> *mIconColorsList; std::string mColorsListName; + std::string mIconColorsListName; ItemColor mCardColor; int mHitEffectId; int mCriticalHitEffectId; |