diff options
-rw-r--r-- | src/animatedsprite.cpp | 21 | ||||
-rw-r--r-- | src/animatedsprite.h | 13 | ||||
-rw-r--r-- | src/being.cpp | 18 | ||||
-rw-r--r-- | src/being.h | 45 | ||||
-rw-r--r-- | src/flooritem.cpp | 15 | ||||
-rw-r--r-- | src/flooritem.h | 17 | ||||
-rw-r--r-- | src/map.cpp | 18 | ||||
-rw-r--r-- | src/monster.cpp | 2 | ||||
-rw-r--r-- | src/npc.h | 4 | ||||
-rw-r--r-- | src/particle.h | 10 | ||||
-rw-r--r-- | src/player.cpp | 5 | ||||
-rw-r--r-- | src/sprite.h | 16 |
12 files changed, 171 insertions, 13 deletions
diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 5a57b08c..1f8778e1 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -40,7 +40,8 @@ AnimatedSprite::AnimatedSprite(SpriteDef *sprite): mSprite(sprite), mAction(0), mAnimation(0), - mFrame(0) + mFrame(0), + mAlpha(1.0f) { assert(mSprite); @@ -142,9 +143,15 @@ bool AnimatedSprite::updateCurrentAnimation(unsigned int time) bool AnimatedSprite::draw(Graphics *graphics, int posX, int posY) const { - if (!mFrame || !mFrame->image) + if (!mFrame) return false; + if (!mFrame->image) + return false; + + if (mFrame->image->getAlpha() != mAlpha) + mFrame->image->setAlpha(mAlpha); + return graphics->drawImage(mFrame->image, posX + mFrame->offsetX, posY + mFrame->offsetY); @@ -172,10 +179,16 @@ void AnimatedSprite::setDirection(SpriteDirection direction) int AnimatedSprite::getWidth() const { - return mFrame ? mFrame->image->getWidth() : 0; + if (mFrame) + return mFrame->image ? mFrame->image->getWidth() : 0; + else + return 0; } int AnimatedSprite::getHeight() const { - return mFrame ? mFrame->image->getHeight() : 0; + if (mFrame) + return mFrame->image ? mFrame->image->getHeight() : 0; + else + return 0; } diff --git a/src/animatedsprite.h b/src/animatedsprite.h index fc7bdbbc..cdf88ceb 100644 --- a/src/animatedsprite.h +++ b/src/animatedsprite.h @@ -95,6 +95,18 @@ class AnimatedSprite */ void setDirection(SpriteDirection direction); + /** + * Sets the alpha value of the animated sprite + */ + void setAlpha(float alpha) + { mAlpha = alpha; } + + /** + * Returns the current alpha opacity of the animated sprite. + */ + virtual float getAlpha() const + { return mAlpha; } + private: bool updateCurrentAnimation(unsigned int dt); @@ -108,6 +120,7 @@ class AnimatedSprite Action *mAction; /**< The currently active action. */ Animation *mAnimation; /**< The currently active animation. */ Frame *mFrame; /**< The currently active frame. */ + float mAlpha; /**< The alpha opacity used to draw */ }; #endif diff --git a/src/being.cpp b/src/being.cpp index 37ae2200..32a3b5c3 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -82,6 +82,8 @@ Being::Being(int id, int job, Map *map): mEquippedWeapon(NULL), mText(0), mStunMode(0), + mAlpha(1.0f), + mNumberOfLayers(0), mStatusParticleEffects(&mStunParticleEffects, false), mChildParticleEffects(&mStatusParticleEffects, false), mMustResetParticles(false), @@ -605,7 +607,11 @@ void Being::draw(Graphics *graphics, int offsetX, int offsetY) const for (SpriteConstIterator it = mSprites.begin(); it != mSprites.end(); it++) if (*it) + { + if ((*it)->getAlpha() != mAlpha) + (*it)->setAlpha(mAlpha); (*it)->draw(graphics, px, py); + } } void Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY) @@ -910,3 +916,15 @@ void Being::load() mNumberOfHairstyles = hairstyles; } + +void Being::_updateNumberOfLayers() +{ + SpriteConstIterator si = mSprites.begin(); + mNumberOfLayers = 0; + while (si != mSprites.end()) + { + if (*si) + mNumberOfLayers++; + si++; + } +} diff --git a/src/being.h b/src/being.h index ad7f3459..1f9ada92 100644 --- a/src/being.h +++ b/src/being.h @@ -215,14 +215,29 @@ class Being : public Sprite, public ConfigListener */ virtual void setName(const std::string &name); - const bool getShowName() const { return mShowName; } + const bool getShowName() const + { return mShowName; } virtual void setShowName(bool doShowName); /** * Get the number of hairstyles implemented */ - static int getNumOfHairstyles() { return mNumberOfHairstyles; } + static int getNumOfHairstyles() + { return mNumberOfHairstyles; } + + /** + * Get the number of layers used to draw the being + */ + int getNumberOfLayers() const + { return mNumberOfLayers; } + + /** + * Set the number of layers used to draw the being + */ + void setNumberOfLayers(int numberOfLayers) + { mNumberOfLayers = numberOfLayers; } + #ifdef EATHENA_SUPPORT /** @@ -311,16 +326,30 @@ class Being : public Sprite, public ConfigListener virtual void draw(Graphics *graphics, int offsetX, int offsetY) const; /** + * Set the alpha opacity used to draw the being. + */ + virtual void setAlpha(float alpha) + { mAlpha = alpha; } + + /** + * Returns the current alpha opacity of the Being. + */ + virtual float getAlpha() const + { return mAlpha; } + + /** * Returns the X coordinate in pixels. */ - int getPixelX() const { return mPx; } + int getPixelX() const + { return mPx; } /** * Returns the Y coordinate in pixels. * * @see Sprite::getPixelY() */ - int getPixelY() const { return mPy; } + int getPixelY() const + { return mPy; } #ifdef EATHENA_SUPPORT /** @@ -526,6 +555,14 @@ class Being : public Sprite, public ConfigListener typedef Sprites::iterator SpriteIterator; typedef Sprites::const_iterator SpriteConstIterator; Sprites mSprites; + float mAlpha; /**< Alpha opacity to draw the sprite */ + + /** Stores the number of layers used to draw the being */ + int mNumberOfLayers; + + /** This method counts reliably the sprite layers currently used */ + void _updateNumberOfLayers(); + ParticleList mStunParticleEffects; ParticleVector mStatusParticleEffects; ParticleList mChildParticleEffects; diff --git a/src/flooritem.cpp b/src/flooritem.cpp index 9376dd73..b2f6376b 100644 --- a/src/flooritem.cpp +++ b/src/flooritem.cpp @@ -35,7 +35,8 @@ FloorItem::FloorItem(int id, mId(id), mX(x), mY(y), - mMap(map) + mMap(map), + mAlpha(1.0f) { // Create a corresponding item instance mItem = new Item(itemId); @@ -64,7 +65,13 @@ Item *FloorItem::getItem() const void FloorItem::draw(Graphics *graphics, int offsetX, int offsetY) const { - graphics->drawImage(mItem->getImage(), - mX * 32 + offsetX, - mY * 32 + offsetY); + if (mItem) + { + if (mAlpha != mItem->getImage()->getAlpha()) + mItem->getImage()->setAlpha(mAlpha); + + graphics->drawImage(mItem->getImage(), + mX * 32 + offsetX, + mY * 32 + offsetY); + } } diff --git a/src/flooritem.h b/src/flooritem.h index 61e88a70..a4c18547 100644 --- a/src/flooritem.h +++ b/src/flooritem.h @@ -94,12 +94,29 @@ class FloorItem : public Sprite */ void draw(Graphics *graphics, int offsetX, int offsetY) const; + /** + * Sets the alpha value of the floor item + */ + void setAlpha(float alpha) + { mAlpha = alpha; } + + /** + * Returns the current alpha opacity of the floor item. + */ + virtual float getAlpha() const + { return mAlpha; } + + /** We consider flooritems (at least for now) to be one layer-sprites */ + virtual int getNumberOfLayers() const + { return 1; } + private: int mId; int mX, mY; Item *mItem; MapSprite mMapSprite; Map *mMap; + float mAlpha; }; #endif diff --git a/src/map.cpp b/src/map.cpp index 5f6433c2..1a869e61 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -285,6 +285,24 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY) mSprites); } + // Draws beings with a lower opacity to make them visible + // even when covered by a wall or some other elements... + MapSprites::const_iterator si = mSprites.begin(); + while (si != mSprites.end()) + { + if (*si) + // For now, just draw sprites with only one layer. + { + if ((*si)->getNumberOfLayers() == 1) + { + (*si)->setAlpha(0.3f); + (*si)->draw(graphics, -scrollX, -scrollY); + (*si)->setAlpha(1.0f); + } + } + si++; + } + drawOverlay(graphics, scrollX, scrollY, (int) config.getValue("OverlayDetail", 2)); } diff --git a/src/monster.cpp b/src/monster.cpp index cc2285fe..9683e5df 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -45,12 +45,14 @@ Monster::Monster(int id, int job, Map *map): { std::string file = "graphics/sprites/" + *i; mSprites.push_back(AnimatedSprite::load(file)); + setNumberOfLayers(getNumberOfLayers() + 1); } // Ensure that something is shown if (mSprites.size() == 0) { mSprites.push_back(AnimatedSprite::load("graphics/sprites/error.xml")); + setNumberOfLayers(getNumberOfLayers() + 1); } if (mParticleEffects) @@ -53,6 +53,10 @@ class NPC : public Player static bool isTalking; + /** We consider NPCs (at least for now) to be one layer-sprites */ + virtual int getNumberOfLayers() const + { return 1; } + protected: /** * Gets the way a monster blocks pathfinding for other objects diff --git a/src/particle.h b/src/particle.h index 4f92b5cd..c3e7692c 100644 --- a/src/particle.h +++ b/src/particle.h @@ -171,6 +171,12 @@ class Particle : public Sprite { mAlpha = alpha; } /** + * Returns the current alpha opacity of the particle. + */ + virtual float getAlpha() const + { return mAlpha; } + + /** * Sets the sprite iterator of the particle on the current map to make * it easier to remove the particle from the map when it is destroyed. */ @@ -258,6 +264,10 @@ class Particle : public Sprite void disableAutoDelete() { mAutoDelete = false; } + /** We consider particles (at least for now) to be one layer-sprites */ + virtual int getNumberOfLayers() const + { return 1; } + protected: bool mAlive; /**< Is the particle supposed to be drawn and updated?*/ Vector mPos; /**< Position in pixels relative to map. */ diff --git a/src/player.cpp b/src/player.cpp index 288c565d..d252f7a0 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -184,7 +184,8 @@ void Player::setSprite(unsigned int slot, int id, const std::string &color) if (equipmentSprite) equipmentSprite->setDirection(getSpriteDirection()); - delete mSprites[slot]; + if (mSprites[slot]) + delete mSprites[slot]; mSprites[slot] = equipmentSprite; @@ -196,6 +197,8 @@ void Player::setSprite(unsigned int slot, int id, const std::string &color) mSpriteIDs[slot] = id; mSpriteColors[slot] = color; + + _updateNumberOfLayers(); } void Player::setSpriteID(unsigned int slot, int id) diff --git a/src/sprite.h b/src/sprite.h index a6384e94..b56c30aa 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -64,6 +64,22 @@ class Sprite * Returns the pixel Y coordinate of the sprite. */ virtual int getPixelY() const = 0; + + /** + * Returns the number of Image layers used to draw the sprite. + */ + virtual int getNumberOfLayers() const + { return 0; } + + /** + * Returns the current alpha value used to draw the sprite. + */ + virtual float getAlpha() const = 0; + + /** + * Sets the alpha value used to draw the sprite. + */ + virtual void setAlpha(float alpha) = 0; }; #endif |