From f6e348a03e14d2e7d91774802f3a4153333d20cb Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 21 Jun 2016 16:15:33 +0300 Subject: Improve Being::setSpriteColor. --- src/being/being.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 5 deletions(-) (limited to 'src/being/being.cpp') diff --git a/src/being/being.cpp b/src/being/being.cpp index fae5224b6..dea303af5 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -2995,12 +2995,66 @@ void Being::setHairColorSpriteID(const unsigned int slot, void Being::setSpriteColor(const unsigned int slot, const std::string &restrict color) restrict2 { + if (!charServerHandler || slot >= charServerHandler->maxSprite()) + return; + + if (slot >= CAST_U32(mSprites.size())) + ensureSize(slot + 1); + + if (slot >= CAST_U32(mSlots.size())) + mSlots.resize(slot + 1, BeingSlot()); + + // disabled for now, because it may broke replace/reorder sprites logic +// if (slot && mSlots[slot].spriteId == id) +// return; + BeingSlot &beingSlot = mSlots[slot]; - setSpriteCards(slot, - beingSlot.spriteId, - color, - ItemColor_one, - beingSlot.cardsId); + const int id = beingSlot.spriteId; + + // id = 0 means unequip + if (id == 0) + { + } + else + { + const ItemInfo &info = ItemDB::get(id); + const std::string &restrict filename = info.getSprite( + mGender, mSubType); + int lastTime = 0; + int startTime = 0; + AnimatedSprite *restrict equipmentSprite = nullptr; + + if (!filename.empty()) + { + equipmentSprite = AnimatedSprite::delayedLoad( + paths.getStringValue("sprites").append( + combineDye(filename, color))); + } + + if (equipmentSprite) + { + equipmentSprite->setSpriteDirection(getSpriteDirection()); + startTime = getStartTime(); + lastTime = getLastTime(); + } + + CompoundSprite::setSprite(slot, equipmentSprite); + + setAction(mAction, 0); + if (equipmentSprite) + { + if (lastTime > 0) + { + equipmentSprite->setLastTime(startTime); + equipmentSprite->update(lastTime); + } + } + } + + beingSlot.color = color; + beingSlot.colorId = ItemColor_one; + if (beingEquipmentWindow) + beingEquipmentWindow->updateBeing(this); } void Being::setHairStyle(const unsigned int slot, -- cgit v1.2.3-70-g09d2