diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-06-21 16:37:27 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-06-21 16:37:27 +0300 |
commit | e9b904692840a1e1f39b5e5b449fcc686d0441af (patch) | |
tree | 42a30cd3dcfa3c1ad360c18343828c054b59b9b5 /src | |
parent | f6e348a03e14d2e7d91774802f3a4153333d20cb (diff) | |
download | manaplus-e9b904692840a1e1f39b5e5b449fcc686d0441af.tar.gz manaplus-e9b904692840a1e1f39b5e5b449fcc686d0441af.tar.bz2 manaplus-e9b904692840a1e1f39b5e5b449fcc686d0441af.tar.xz manaplus-e9b904692840a1e1f39b5e5b449fcc686d0441af.zip |
Improve Being::setGender.
Diffstat (limited to 'src')
-rw-r--r-- | src/being/being.cpp | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/src/being/being.cpp b/src/being/being.cpp index dea303af5..08f1acddd 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -3253,23 +3253,61 @@ BeingCacheEntry* Being::getCacheEntry(const BeingId id) void Being::setGender(const GenderT gender) restrict2 { + if (!charServerHandler) + return; + if (gender != mGender) { mGender = gender; + const unsigned int sz = CAST_U32(mSlots.size()); + + if (sz > CAST_U32(mSprites.size())) + ensureSize(sz); + // Reload all subsprites for (unsigned int i = 0; - i < CAST_U32(mSlots.size()); + i < sz; i++) { BeingSlot &beingSlot = mSlots[i]; - if (beingSlot.spriteId != 0) + const int id = beingSlot.spriteId; + if (id != 0) { - setSpriteCards(i, - beingSlot.spriteId, - beingSlot.color, - ItemColor_one, - beingSlot.cardsId); + 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, beingSlot.color))); + } + + if (equipmentSprite) + { + equipmentSprite->setSpriteDirection(getSpriteDirection()); + startTime = getStartTime(); + lastTime = getLastTime(); + } + + CompoundSprite::setSprite(i, equipmentSprite); + setAction(mAction, 0); + if (equipmentSprite) + { + if (lastTime > 0) + { + equipmentSprite->setLastTime(startTime); + equipmentSprite->update(lastTime); + } + } + + if (beingEquipmentWindow) + beingEquipmentWindow->updateBeing(this); } } |