diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-07-25 21:44:28 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-07-25 22:18:16 +0300 |
commit | badba244423ba8fccb246afaa8b1dd0c1448b370 (patch) | |
tree | d2f72ed78b3a3c9be195a2b33036c207b551066f /src | |
parent | 24e2ae34bfc9e6b96b890893ece422170fb7d42f (diff) | |
download | manaplus-badba244423ba8fccb246afaa8b1dd0c1448b370.tar.gz manaplus-badba244423ba8fccb246afaa8b1dd0c1448b370.tar.bz2 manaplus-badba244423ba8fccb246afaa8b1dd0c1448b370.tar.xz manaplus-badba244423ba8fccb246afaa8b1dd0c1448b370.zip |
Reorders sprites now depend on player direction.
Diffstat (limited to 'src')
-rw-r--r-- | src/being.cpp | 18 | ||||
-rw-r--r-- | src/resources/itemdb.cpp | 34 | ||||
-rw-r--r-- | src/resources/iteminfo.cpp | 83 | ||||
-rw-r--r-- | src/resources/iteminfo.h | 26 |
4 files changed, 127 insertions, 34 deletions
diff --git a/src/being.cpp b/src/being.cpp index 904a59390..40c41cb64 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -2141,15 +2141,16 @@ void Being::recalcSpritesOrder() } } - if (info.getDrawBefore() > 0) + if (info.getDrawBefore(mSpriteDirection) > 0) { - int id2 = mSpriteIDs[info.getDrawBefore()]; + int id2 = mSpriteIDs[info.getDrawBefore(mSpriteDirection)]; std::map<int, int>::iterator orderIt = itemSlotRemap.find(id2); if (orderIt != itemSlotRemap.end()) { // logger->log("found duplicate (before)"); const ItemInfo &info2 = ItemDB::get(id2); - if (info.getDrawPriority() < info2.getDrawPriority()) + if (info.getDrawPriority(mSpriteDirection) + < info2.getDrawPriority(mSpriteDirection)) { // logger->log("old more priority"); continue; @@ -2161,18 +2162,19 @@ void Being::recalcSpritesOrder() } } - itemSlotRemap[id] = -info.getDrawBefore(); + itemSlotRemap[id] = -info.getDrawBefore(mSpriteDirection); // logger->log("item slot->slot %d %d->%d", id, slot, itemSlotRemap[id]); } - else if (info.getDrawAfter() > 0) + else if (info.getDrawAfter(mSpriteDirection) > 0) { - int id2 = mSpriteIDs[info.getDrawAfter()]; + int id2 = mSpriteIDs[info.getDrawAfter(mSpriteDirection)]; std::map<int, int>::iterator orderIt = itemSlotRemap.find(id2); if (orderIt != itemSlotRemap.end()) { // logger->log("found duplicate (after)"); const ItemInfo &info2 = ItemDB::get(id2); - if (info.getDrawPriority() < info2.getDrawPriority()) + if (info.getDrawPriority(mSpriteDirection) + < info2.getDrawPriority(mSpriteDirection)) { // logger->log("old more priority"); continue; @@ -2184,7 +2186,7 @@ void Being::recalcSpritesOrder() } } - itemSlotRemap[id] = info.getDrawAfter(); + itemSlotRemap[id] = info.getDrawAfter(mSpriteDirection); // logger->log("item slot->slot %d %d->%d", id, slot, itemSlotRemap[id]); } } diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 22728525c..2d14ba687 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -55,7 +55,9 @@ static void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node); static void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node); static void loadFloorSprite(SpriteDisplay *display, xmlNodePtr node); static void loadReplaceSprite(ItemInfo *itemInfo, xmlNodePtr replaceNode); -static int parseSpriteName(std::string &name); +static void loadOrderSprite(ItemInfo *itemInfo, xmlNodePtr node, + bool drawAfter); +static int parseSpriteName(std::string name); static int parseDirectionName(std::string name); static char const *const fields[][2] = @@ -293,9 +295,9 @@ void ItemDB::load() itemInfo->setMissileParticleFile(missileParticle); itemInfo->setHitEffectId(hitEffectId); itemInfo->setCriticalHitEffectId(criticalEffectId); - itemInfo->setDrawBefore(parseSpriteName(drawBefore)); - itemInfo->setDrawAfter(parseSpriteName(drawAfter)); - itemInfo->setDrawPriority(drawPriority); + itemInfo->setDrawBefore(-1, parseSpriteName(drawBefore)); + itemInfo->setDrawAfter(-1, parseSpriteName(drawAfter)); + itemInfo->setDrawPriority(-1, drawPriority); itemInfo->setColorsList(colors); std::string effect; @@ -346,6 +348,14 @@ void ItemDB::load() { loadReplaceSprite(itemInfo, itemChild); } + else if (xmlStrEqual(itemChild->name, BAD_CAST "drawAfter")) + { + loadOrderSprite(itemInfo, itemChild, true); + } + else if (xmlStrEqual(itemChild->name, BAD_CAST "drawBefore")) + { + loadOrderSprite(itemInfo, itemChild, false); + } } itemInfo->setDisplay(display); @@ -471,7 +481,7 @@ const std::map<int, ItemInfo*> &ItemDB::getItemInfos() return mItemInfos; } -int parseSpriteName(std::string &name) +int parseSpriteName(std::string name) { int id = -1; if (name == "shoes" || name == "boot" || name == "boots") @@ -632,3 +642,17 @@ void loadReplaceSprite(ItemInfo *itemInfo, xmlNodePtr replaceNode) } } } + +void loadOrderSprite(ItemInfo *itemInfo, xmlNodePtr node, bool drawAfter) +{ + int sprite = parseSpriteName(XML::getProperty(node, "name", "")); + int priority = XML::getProperty(node, "priority", 0); + + int direction = parseDirectionName(XML::getProperty( + node, "direction", "all")); + if (drawAfter) + itemInfo->setDrawAfter(direction, sprite); + else + itemInfo->setDrawBefore(direction, sprite); + itemInfo->setDrawPriority(direction, priority); +} diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index 5fc19014e..d496ffa75 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -39,9 +39,6 @@ ItemInfo::ItemInfo(ItemInfo &info) mWeight = info.mWeight; mView = info.mView; mId = info.mId; - mDrawBefore = info.mDrawBefore; - mDrawAfter = info.mDrawAfter; - mDrawPriority = info.mDrawPriority; mIsRemoveSprites = info.mIsRemoveSprites; mAttackAction = info.mAttackAction; mAttackRange = info.mAttackRange; @@ -50,7 +47,12 @@ ItemInfo::ItemInfo(ItemInfo &info) mHitEffectId = info.mHitEffectId; mCriticalHitEffectId = info.mCriticalHitEffectId; for (int f = 0; f < 9; f ++) + { mSpriteToItemReplaceMap[f] = 0; + mDrawBefore[f] = info.mDrawBefore[f]; + mDrawAfter[f] = info.mDrawAfter[f]; + mDrawPriority[f] = info.mDrawPriority[f]; + } } ItemInfo::ItemInfo() : @@ -58,9 +60,6 @@ ItemInfo::ItemInfo() : mWeight(0), mView(0), mId(0), - mDrawBefore(-1), - mDrawAfter(-1), - mDrawPriority(0), mIsRemoveSprites(false), mAttackAction(SpriteAction::INVALID), mAttackRange(0), @@ -70,7 +69,12 @@ ItemInfo::ItemInfo() : mCriticalHitEffectId(0) { for (int f = 0; f < 9; f ++) + { mSpriteToItemReplaceMap[f] = 0; + mDrawBefore[f] = -1; + mDrawAfter[f] = -1; + mDrawPriority[f] = 0; + } } ItemInfo::~ItemInfo() @@ -241,3 +245,70 @@ SpriteToItemMap *ItemInfo::getSpriteToItemReplaceMap(int direction) const return 0; } + +void ItemInfo::setSpriteOrder(int *ptr, int direction, int n, int def) +{ + if (direction == -1) + { + for (int f = 0; f < 9; f ++) + { + if (ptr[f] == def) + ptr[f] = n; + } + return; + } + if (direction < 0 || direction >= 9) + return; + + if (direction == DIRECTION_UP) + { + if (ptr[DIRECTION_UPLEFT] == def) + ptr[DIRECTION_UPLEFT] = n; + if (ptr[DIRECTION_UPRIGHT] == def) + ptr[DIRECTION_UPRIGHT] = n; + } + else if (direction == DIRECTION_DOWN) + { + if (ptr[DIRECTION_DOWNLEFT] == def) + ptr[DIRECTION_DOWNLEFT] = n; + if (ptr[DIRECTION_DOWNRIGHT] == def) + ptr[DIRECTION_DOWNRIGHT] = n; + } + ptr[direction] = n; +} + +void ItemInfo::setDrawBefore(int direction, int n) +{ + setSpriteOrder(&mDrawBefore[0], direction, n); +} + +void ItemInfo::setDrawAfter(int direction, int n) +{ + setSpriteOrder(&mDrawAfter[0], direction, n); +} + +void ItemInfo::setDrawPriority(int direction, int n) +{ + setSpriteOrder(&mDrawPriority[0], direction, n, 0); +} + +int ItemInfo::getDrawBefore(int direction) const +{ + if (direction < 0 || direction >= 9) + return -1; + return mDrawBefore[direction]; +} + +int ItemInfo::getDrawAfter(int direction) const +{ + if (direction < 0 || direction >= 9) + return -1; + return mDrawAfter[direction]; +} + +int ItemInfo::getDrawPriority(int direction) const +{ + if (direction < 0 || direction >= 9) + return 0; + return mDrawPriority[direction]; +} diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index b977a94ce..d8b8c7b0d 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -207,23 +207,19 @@ class ItemInfo const std::string &getSound(EquipmentSoundEvent event) const; - int getDrawBefore() const - { return mDrawBefore; } + int getDrawBefore(int direction) const; - void setDrawBefore(int n) - { mDrawBefore = n; } + void setDrawBefore(int direction, int n); - int getDrawAfter() const - { return mDrawAfter; } + int getDrawAfter(int direction) const; - void setDrawAfter(int n) - { mDrawAfter = n; } + void setDrawAfter(int direction, int n); - int getDrawPriority() const - { return mDrawPriority; } + int getDrawPriority(int direction) const; - void setDrawPriority(int n) - { mDrawPriority = n; } + void setDrawPriority(int direction, int n); + + void setSpriteOrder(int *ptr, int direction, int n, int def = -1); std::map<int, int> getTags() const { return mTags; } @@ -271,9 +267,9 @@ class ItemInfo int mWeight; /**< Weight in grams. */ int mView; /**< Item ID of how this item looks. */ int mId; /**< Item ID */ - int mDrawBefore; - int mDrawAfter; - int mDrawPriority; + int mDrawBefore[9]; + int mDrawAfter[9]; + int mDrawPriority[9]; bool mIsRemoveSprites; // sprite, <itemfrom, itemto> [direction] SpriteToItemMap *mSpriteToItemReplaceMap[9]; |