From 02677a3b9b3abefb84e24023697466c892c6ded4 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 31 May 2012 17:31:46 +0300 Subject: Add support for each hair style own palete. --- src/being.cpp | 8 ++++++++ src/being.h | 2 ++ src/gui/charcreatedialog.cpp | 2 +- src/net/ea/beinghandler.cpp | 4 +++- src/net/tmwa/beinghandler.cpp | 8 +++++--- src/net/tmwa/charserverhandler.cpp | 4 +++- src/resources/colordb.cpp | 25 ------------------------- src/resources/colordb.h | 2 -- src/resources/itemdb.cpp | 13 ++++++++++++- src/resources/iteminfo.h | 2 +- 10 files changed, 35 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index c58cc4696..8414d93a6 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -2656,6 +2656,14 @@ Gender Being::intToGender(int sex) } } +int Being::getSpriteID(int slot) +{ + if (slot < 0 || (unsigned)slot >= mSpriteIDs.size()) + return -1; + + return mSpriteIDs[slot]; +} + BeingEquipBackend::BeingEquipBackend(Being *being): mBeing(being) { diff --git a/src/being.h b/src/being.h index ee4efef0f..6337e30f1 100644 --- a/src/being.h +++ b/src/being.h @@ -780,6 +780,8 @@ class Being : public ActorSprite, public ConfigListener std::string getRaceName() { return mRaceName; } + int getSpriteID(int slot); + static int genderToInt(Gender sex); static Gender intToGender(int sex); diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index db6916a62..52e59f095 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -513,7 +513,7 @@ void CharCreateDialog::updateHair() mHairColorNameLabel->adjustSize(); mPlayer->setSprite(Net::getCharHandler()->hairSprite(), - mHairStyle * -1, ColorDB::getHairColor(mHairColor)); + mHairStyle * -1, item.getDyeColorsString(mHairColor)); } void CharCreateDialog::updateRace() diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index a773ef0b1..1e73f5670 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -50,6 +50,8 @@ #include "net/net.h" #include "resources/colordb.h" +#include "resources/itemdb.h" +#include "resources/iteminfo.h" #include @@ -264,7 +266,7 @@ void BeingHandler::processBeingVisibleOrMove(Net::MessageIn &msg, bool visible) dstBeing->setGender(Being::intToGender(gender)); // Set these after the gender, as the sprites may be gender-specific setSprite(dstBeing, EA_SPRITE_HAIR, hairStyle * -1, - ColorDB::getHairColor(hairColor)); + ItemDB::get(-hairStyle).getDyeColorsString(hairColor)); setSprite(dstBeing, EA_SPRITE_BOTTOMCLOTHES, headBottom); setSprite(dstBeing, EA_SPRITE_TOPCLOTHES, headMid); setSprite(dstBeing, EA_SPRITE_HAT, headTop); diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index 5eb02d299..61924f1f4 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -49,6 +49,8 @@ #include "net/tmwa/protocol.h" #include "resources/colordb.h" +#include "resources/itemdb.h" +#include "resources/iteminfo.h" #include @@ -325,8 +327,8 @@ void BeingHandler::processBeingChangeLook(Net::MessageIn &msg, bool look2) player_node->imitateOutfit(dstBeing, SPRITE_TOPCLOTHES); break; case 6: // eAthena LOOK_HAIR_COLOR - dstBeing->setSpriteColor(SPRITE_HAIR, - ColorDB::getHairColor(id)); + dstBeing->setSpriteColor(SPRITE_HAIR, ItemDB::get( + dstBeing->getSpriteID(SPRITE_HAIR)).getDyeColorsString(id)); break; case 7: // Clothes color // ignoring it @@ -540,7 +542,7 @@ void BeingHandler::processPlayerMoveUpdate(Net::MessageIn &msg, int msgType) //dstBeing->setSprite(SPRITE_MISC1, misc1); //dstBeing->setSprite(SPRITE_MISC2, misc2); dstBeing->setSprite(SPRITE_HAIR, hairStyle * -1, - ColorDB::getHairColor(hairColor)); + ItemDB::get(-hairStyle).getDyeColorsString(hairColor)); player_node->imitateOutfit(dstBeing); diff --git a/src/net/tmwa/charserverhandler.cpp b/src/net/tmwa/charserverhandler.cpp index 04274a70b..e18c33a5a 100644 --- a/src/net/tmwa/charserverhandler.cpp +++ b/src/net/tmwa/charserverhandler.cpp @@ -38,6 +38,8 @@ #include "net/tmwa/protocol.h" #include "resources/colordb.h" +#include "resources/itemdb.h" +#include "resources/iteminfo.h" #include "utils/dtor.h" @@ -214,7 +216,7 @@ void CharServerHandler::readPlayerData(Net::MessageIn &msg, int topClothes = msg.readInt16(); tempPlayer->setSprite(SPRITE_HAIR, hairStyle * -1, - ColorDB::getHairColor(msg.readInt16())); + ItemDB::get(-hairStyle).getDyeColorsString(msg.readInt16())); int misc2 = msg.readInt16(); tempPlayer->setName(msg.readString(24)); diff --git a/src/resources/colordb.cpp b/src/resources/colordb.cpp index 66c8de0a2..2b9a21500 100644 --- a/src/resources/colordb.cpp +++ b/src/resources/colordb.cpp @@ -155,31 +155,6 @@ void ColorDB::unload() mLoaded = false; } -std::string &ColorDB::getHairColor(int id) -{ - if (!mLoaded) - load(); - - ColorListsIterator it = mColorLists.find("hair"); - if (it == mColorLists.end()) - { - logger->log1("ColorDB: Error, hair colors list empty"); - return mFail; - } - - ColorIterator i = (*it).second.find(id); - - if (i == (*it).second.end()) - { - logger->log("ColorDB: Error, unknown dye ID# %d", id); - return mFail; - } - else - { - return i->second.color; - } -} - std::string &ColorDB::getHairColorName(int id) { if (!mLoaded) diff --git a/src/resources/colordb.h b/src/resources/colordb.h index ade4227f8..27ca6173a 100644 --- a/src/resources/colordb.h +++ b/src/resources/colordb.h @@ -68,8 +68,6 @@ namespace ColorDB */ void unload(); - std::string &getHairColor(int id); - std::string &getHairColorName(int id); int getHairSize(); diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 8d4cf8002..cf05a28f0 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -213,9 +213,20 @@ void ItemDB::load() // std::string removeSprite = XML::getProperty(node, "removeSprite", ""); std::string colors; if (serverVersion >= 1) + { colors = XML::getProperty(node, "colors", ""); + + // check for empty hair palete + if (colors.empty() && id <= -1 && id > -100) + colors = "hair"; + } else - colors = ""; + { + if (id <= -1 && id > -100) + colors = "hair"; + else + colors = ""; + } std::string tags[3]; tags[0] = XML::getProperty(node, "tag", diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 9d1f94954..33727b136 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -244,7 +244,7 @@ class ItemInfo SpriteToItemMap *getSpriteToItemReplaceMap(int directions) const; - std::string getDyeString(int color) const; +// std::string getDyeString(int color) const; std::string getDyeColorsString(int color) const; -- cgit v1.2.3-60-g2f50