From 0a18932056e2a72f41cdd14c831344ad80cfb35b Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 15 Jan 2009 19:48:00 -0700 Subject: Added emote database, which is loosely based off of the NPC database. Also changed all emotes to be animated sprites now, and to load from emotes.xml. This gives us a bit more flexibility to not only add more emotes in the future, but allowing them to be animated as well. NOTE: This commit, unlike the previous emote commits, breaks emotes if you don't have the xml file. This will be available on Aethyra soon, but is not rolled into an update at the moment. Signed-off-by: Ira Rice --- src/being.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/being.cpp') diff --git a/src/being.cpp b/src/being.cpp index 69da1182..883344d8 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -35,6 +35,7 @@ #include "sound.h" #include "text.h" +#include "resources/emotedb.h" #include "resources/imageset.h" #include "resources/itemdb.h" #include "resources/iteminfo.h" @@ -50,7 +51,7 @@ int Being::instances = 0; int Being::mNumberOfHairstyles = 1; -ImageSet *Being::emotionSet = NULL; +std::vector Being::emotionSet; static const int X_SPEECH_OFFSET = 18; static const int Y_SPEECH_OFFSET = 60; @@ -87,10 +88,18 @@ Being::Being(int id, int job, Map *map): if (instances == 0) { - // Load the emotion set - ResourceManager *rm = ResourceManager::getInstance(); - emotionSet = rm->getImageSet("graphics/sprites/emotions.png", 30, 32); - if (!emotionSet) logger->error(_("Unable to load emotions")); + // Setup emote sprites + for (int i = 0; i <= EmoteDB::getLast(); i++) + { + EmoteInfo info = EmoteDB::get(i); + + if (info.sprites != EmoteDB::getUnknown().sprites) + { + std::string file = "graphics/sprites/" + info.sprites.front()->sprite; + int variant = info.sprites.front()->variant; + emotionSet.push_back(AnimatedSprite::load(file, variant)); + } + } // Hairstyles are encoded as negative numbers. Count how far negative we can go. int hairstyles = 1; @@ -117,8 +126,7 @@ Being::~Being() if (instances == 0) { - emotionSet->decRef(); - emotionSet = NULL; + delete_all(emotionSet); } delete mSpeechBubble; @@ -448,8 +456,8 @@ void Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY) const int py = mPy + offsetY - 60; const int emotionIndex = mEmotion - 1; - if (emotionIndex >= 0 && emotionIndex < (int) emotionSet->size()) - graphics->drawImage(emotionSet->get(emotionIndex), px, py); + if (emotionIndex >= 0 && emotionIndex < EmoteDB::getLast()) + emotionSet[emotionIndex]->draw(graphics, px, py); } void Being::drawSpeech(Graphics *graphics, int offsetX, int offsetY) -- cgit v1.2.3-60-g2f50