From badba244423ba8fccb246afaa8b1dd0c1448b370 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 25 Jul 2011 21:44:28 +0300 Subject: Reorders sprites now depend on player direction. --- src/resources/itemdb.cpp | 34 ++++++++++++++++--- src/resources/iteminfo.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++---- src/resources/iteminfo.h | 26 ++++++--------- 3 files changed, 117 insertions(+), 26 deletions(-) (limited to 'src/resources') 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 &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 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, [direction] SpriteToItemMap *mSpriteToItemReplaceMap[9]; -- cgit v1.2.3-60-g2f50