summaryrefslogtreecommitdiff
path: root/src/being/being.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-06-21 16:15:33 +0300
committerAndrei Karas <akaras@inbox.ru>2016-06-21 16:15:33 +0300
commitf6e348a03e14d2e7d91774802f3a4153333d20cb (patch)
tree37dab64a05444203436e8307b4252a16b93cb795 /src/being/being.cpp
parent58a6cd09e9dad44565b939599fa24c5d82011820 (diff)
downloadplus-f6e348a03e14d2e7d91774802f3a4153333d20cb.tar.gz
plus-f6e348a03e14d2e7d91774802f3a4153333d20cb.tar.bz2
plus-f6e348a03e14d2e7d91774802f3a4153333d20cb.tar.xz
plus-f6e348a03e14d2e7d91774802f3a4153333d20cb.zip
Improve Being::setSpriteColor.
Diffstat (limited to 'src/being/being.cpp')
-rw-r--r--src/being/being.cpp64
1 files changed, 59 insertions, 5 deletions
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,