summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-04-04 22:08:55 +0300
committerAndrei Karas <akaras@inbox.ru>2013-04-04 22:08:55 +0300
commit4ad3a8e89e64ce3ae845d2786dd433ab2682393e (patch)
tree80234ae2e147686b822bd2579f9cbc0756aa2f90
parent5066c50c2869d3f8b13138947eaa3f52accc5ad0 (diff)
downloadmv-4ad3a8e89e64ce3ae845d2786dd433ab2682393e.tar.gz
mv-4ad3a8e89e64ce3ae845d2786dd433ab2682393e.tar.bz2
mv-4ad3a8e89e64ce3ae845d2786dd433ab2682393e.tar.xz
mv-4ad3a8e89e64ce3ae845d2786dd433ab2682393e.zip
Add support for animated emotes.
Not particles but really animated emotes. First frame used as icon.
-rw-r--r--src/animatedsprite.cpp7
-rw-r--r--src/animatedsprite.h2
-rw-r--r--src/being.cpp50
-rw-r--r--src/being.h11
-rw-r--r--src/resources/emotedb.cpp9
-rw-r--r--src/resources/emotedb.h2
6 files changed, 56 insertions, 25 deletions
diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp
index 8bc324535..0842186fc 100644
--- a/src/animatedsprite.cpp
+++ b/src/animatedsprite.cpp
@@ -88,6 +88,13 @@ AnimatedSprite *AnimatedSprite::delayedLoad(const std::string &filename,
return as;
}
+AnimatedSprite *AnimatedSprite::clone(const AnimatedSprite *const anim)
+{
+ if (!anim)
+ return nullptr;
+ return new AnimatedSprite(anim->mSprite);
+}
+
AnimatedSprite::~AnimatedSprite()
{
if (mSprite)
diff --git a/src/animatedsprite.h b/src/animatedsprite.h
index a58098245..054fcdb68 100644
--- a/src/animatedsprite.h
+++ b/src/animatedsprite.h
@@ -60,6 +60,8 @@ class AnimatedSprite final : public Sprite
const int variant = 0)
A_WARN_UNUSED;
+ static AnimatedSprite *clone(const AnimatedSprite *const anim);
+
virtual ~AnimatedSprite();
bool reset() override;
diff --git a/src/being.cpp b/src/being.cpp
index bb2a6e95e..4e26e84a6 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -202,7 +202,7 @@ Being::Being(const int id, const Type type, const uint16_t subtype,
ActorSprite(id),
mInfo(BeingInfo::unknown),
mActionTime(0),
- mEmotion(0),
+ mEmotionSprite(nullptr),
mEmotionTime(0),
mSpeechTime(0),
mAttackSpeed(350),
@@ -211,6 +211,7 @@ Being::Being(const int id, const Type type, const uint16_t subtype,
mDirection(DOWN),
mDirectionDelayed(0),
mSpriteDirection(DIRECTION_DOWN),
+ mSpriteAction(SpriteAction::STAND),
mDispName(nullptr),
mShowName(false),
mEquippedWeapon(nullptr),
@@ -1195,7 +1196,10 @@ void Being::setAction(const Action &action, const int attackId)
if (currentAction != SpriteAction::INVALID)
{
+ mSpriteAction = currentAction;
play(currentAction);
+ if (mEmotionSprite)
+ mEmotionSprite->play(currentAction);
mAction = action;
}
@@ -1247,6 +1251,8 @@ void Being::setDirection(const uint8_t direction)
mSpriteDirection = static_cast<uint8_t>(dir);
CompoundSprite::setSpriteDirection(dir);
+ if (mEmotionSprite)
+ mEmotionSprite->setSpriteDirection(dir);
recalcSpritesOrder();
}
@@ -1319,6 +1325,9 @@ void Being::logic()
mText = nullptr;
}
+ if (mEmotionSprite)
+ mEmotionSprite->update(tick_time * MILLISECONDS_IN_A_TICK);
+
int frameCount = static_cast<int>(getFrameCount());
#ifdef MANASERV_SUPPORT
if ((Net::getNetworkType() == ServerInfo::MANASERV) && (mAction != DEAD))
@@ -1457,11 +1466,14 @@ void Being::logic()
static_cast<float>(mY * 32 + 32 + getYOffset()));
}
- if (mEmotion != 0)
+ if (mEmotionSprite)
{
mEmotionTime--;
if (mEmotionTime == 0)
- mEmotion = 0;
+ {
+ delete mEmotionSprite;
+ mEmotionSprite = nullptr;
+ }
}
ActorSprite::logic();
@@ -1483,22 +1495,12 @@ void Being::logic()
void Being::drawEmotion(Graphics *const graphics, const int offsetX,
const int offsetY)
{
- if (!mEmotion)
+ if (!mEmotionSprite)
return;
const int px = getPixelX() - offsetX - 16;
const int py = getPixelY() - offsetY - 64 - 32;
- const int emotionIndex = mEmotion - 1;
-
- if (emotionIndex >= 0 && emotionIndex <= EmoteDB::getLast())
- {
- const AnimatedSprite *const sprite = EmoteDB::getAnimation2(
- emotionIndex, true);
- if (sprite)
- sprite->draw(graphics, px, py);
- else
- mEmotion = 0;
- }
+ mEmotionSprite->draw(graphics, px, py);
}
void Being::drawSpeech(const int offsetX, const int offsetY)
@@ -2721,8 +2723,22 @@ void Being::setEmote(const uint8_t emotion, const int emote_time)
}
else
{
- mEmotion = emotion;
- mEmotionTime = emote_time;
+ const int emotionIndex = emotion - 1;
+ if (emotionIndex >= 0 && emotionIndex <= EmoteDB::getLast())
+ mEmotionSprite = EmoteDB::getClone(emotionIndex, true);
+
+ if (mEmotionSprite)
+ {
+ mEmotionTime = emote_time;
+ mEmotionSprite->play(mSpriteAction);
+ mEmotionSprite->setSpriteDirection(static_cast<SpriteDirection>(
+ mSpriteDirection));
+ }
+ else
+ {
+ mEmotionTime = 0;
+ }
+
}
}
diff --git a/src/being.h b/src/being.h
index 2757ea06c..88fcae859 100644
--- a/src/being.h
+++ b/src/being.h
@@ -600,13 +600,6 @@ class Being : public ActorSprite, public ConfigListener
void setState(const uint8_t state);
- /**
- * Get the current Emoticon type displayed above
- * the being.
- */
- int getEmotion() const A_WARN_UNUSED
- { return mEmotion; }
-
virtual void drawSprites(Graphics *const graphics,
int posX, int posY) const override;
@@ -891,8 +884,9 @@ class Being : public ActorSprite, public ConfigListener
int mActionTime; /**< Time spent in current action */
- int mEmotion; /**< Currently showing emotion */
+ AnimatedSprite *mEmotionSprite;
int mEmotionTime; /**< Time until emotion disappears */
+
/** Time until the last speech sentence disappears */
int mSpeechTime;
@@ -905,6 +899,7 @@ class Being : public ActorSprite, public ConfigListener
uint8_t mDirectionDelayed; /**< Facing direction */
uint8_t mSpriteDirection; /**< Facing direction */
+ std::string mSpriteAction;
std::string mName; /**< Name of character */
std::string mRaceName;
std::string mPartyName;
diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp
index 7e923c034..0492cb848 100644
--- a/src/resources/emotedb.cpp
+++ b/src/resources/emotedb.cpp
@@ -237,6 +237,15 @@ const AnimatedSprite *EmoteDB::getAnimation2(int id, const bool allowNull)
return getAnimation(id, allowNull);
}
+AnimatedSprite *EmoteDB::getClone(int id, const bool allowNull)
+{
+ const AnimatedSprite *const sprite = getAnimation2(id, allowNull);
+ if (sprite)
+ return AnimatedSprite::clone(sprite);
+
+ return nullptr;
+}
+
const EmoteSprite *EmoteDB::getSprite(const int id, const bool allowNull)
{
const EmoteInfo *const info = get(id, allowNull);
diff --git a/src/resources/emotedb.h b/src/resources/emotedb.h
index c747042d5..3e4cd7789 100644
--- a/src/resources/emotedb.h
+++ b/src/resources/emotedb.h
@@ -77,6 +77,8 @@ namespace EmoteDB
const bool allowNull = false)
A_WARN_UNUSED;
+ AnimatedSprite *getClone(int id, const bool allowNull);
+
const EmoteSprite *getSprite(const int id, const bool allowNull = false)
A_WARN_UNUSED;