summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChuck Miller <shadowmil@gmail.com>2010-11-03 23:50:35 -0400
committerChuck Miller <shadowmil@gmail.com>2010-11-07 23:26:37 -0500
commitc81b3c269e39700be94fd9e2629b0bdfb0d093f8 (patch)
treec4dbca3f9dbb288151fec3171089e12295d33e04
parent671a465fa2c9469bde36b78c49e84bd0325c4cf1 (diff)
downloadMana-c81b3c269e39700be94fd9e2629b0bdfb0d093f8.tar.gz
Mana-c81b3c269e39700be94fd9e2629b0bdfb0d093f8.tar.bz2
Mana-c81b3c269e39700be94fd9e2629b0bdfb0d093f8.tar.xz
Mana-c81b3c269e39700be94fd9e2629b0bdfb0d093f8.zip
Convert the emote system to use particles
Reviewed-by: Jared Adams
-rw-r--r--src/being.cpp21
-rw-r--r--src/being.h23
-rw-r--r--src/gui/emotepopup.cpp4
-rw-r--r--src/gui/emotepopup.h4
-rw-r--r--src/gui/viewport.cpp1
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.cpp6
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.h5
-rw-r--r--src/net/tmwa/beinghandler.cpp9
-rw-r--r--src/playerrelations.cpp29
-rw-r--r--src/resources/emotedb.cpp111
-rw-r--r--src/resources/emotedb.h21
11 files changed, 75 insertions, 159 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 585e7352..95f2ecdd 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -80,7 +80,6 @@ Being::Being(int id, Type type, int subtype, Map *map):
ActorSprite(id),
mInfo(BeingInfo::Unknown),
mActionTime(0),
- mEmotion(0), mEmotionTime(0),
mSpeechTime(0),
mAttackType(1),
mAttackSpeed(350),
@@ -869,13 +868,6 @@ void Being::logic()
mY * 32 + 32 + getYOffset());
}
- if (mEmotion != 0)
- {
- mEmotionTime--;
- if (mEmotionTime == 0)
- mEmotion = 0;
- }
-
ActorSprite::logic();
int frameCount = getFrameCount();
@@ -891,19 +883,6 @@ void Being::logic()
}
}
-void Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY)
-{
- if (!mEmotion)
- 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())
- EmoteDB::getAnimation(emotionIndex)->draw(graphics, px, py);
-}
-
void Being::drawSpeech(int offsetX, int offsetY)
{
const int px = getPixelX() - offsetX;
diff --git a/src/being.h b/src/being.h
index 0d1816f9..94790f5f 100644
--- a/src/being.h
+++ b/src/being.h
@@ -322,11 +322,6 @@ class Being : public ActorSprite, public ConfigListener, public Mana::Listener
*/
void drawSpeech(int offsetX, int offsetY);
- /**
- * Draws the emotion picture above the being.
- */
- void drawEmotion(Graphics *graphics, int offsetX, int offsetY);
-
Uint16 getSubType() const { return mSubType; }
/**
@@ -444,22 +439,6 @@ class Being : public ActorSprite, public ConfigListener, public Mana::Listener
*/
const Path &getPath() const { return mPath; }
- /**
- * Set the Emoticon type and time displayed above
- * the being.
- */
- void setEmote(Uint8 emotion, Uint8 emote_time)
- {
- mEmotion = emotion;
- mEmotionTime = emote_time;
- }
-
- /**
- * Get the current Emoticon type displayed above
- * the being.
- */
- Uint8 getEmotion() const { return mEmotion; }
-
static void load();
virtual void optionChanged(const std::string &value);
@@ -527,8 +506,6 @@ class Being : public ActorSprite, public ConfigListener, public Mana::Listener
int mActionTime; /**< Time spent in current action */
- int mEmotion; /**< Currently showing emotion */
- int mEmotionTime; /**< Time until emotion disappears */
/** Time until the last speech sentence disappears */
int mSpeechTime;
diff --git a/src/gui/emotepopup.cpp b/src/gui/emotepopup.cpp
index f9dc8e0f..bd40a932 100644
--- a/src/gui/emotepopup.cpp
+++ b/src/gui/emotepopup.cpp
@@ -22,7 +22,7 @@
#include "gui/emotepopup.h"
-#include "animatedsprite.h"
+#include "imagesprite.h"
#include "configuration.h"
#include "emoteshortcut.h"
#include "graphics.h"
@@ -53,7 +53,7 @@ EmotePopup::EmotePopup():
// Setup emote sprites
for (int i = 0; i <= EmoteDB::getLast(); ++i)
{
- mEmotes.push_back(EmoteDB::getAnimation(i));
+ mEmotes.push_back(EmoteDB::get(i)->sprite);
}
mSelectionImage = Theme::getImageFromTheme("selection.png");
diff --git a/src/gui/emotepopup.h b/src/gui/emotepopup.h
index 62a3f24a..d2cabc44 100644
--- a/src/gui/emotepopup.h
+++ b/src/gui/emotepopup.h
@@ -30,7 +30,7 @@
#include <list>
#include <vector>
-class AnimatedSprite;
+class ImageSprite;
class Image;
namespace gcn {
@@ -105,7 +105,7 @@ class EmotePopup : public Popup
*/
void distributeValueChangedEvent();
- std::vector<const AnimatedSprite*> mEmotes;
+ std::vector<const ImageSprite*> mEmotes;
Image *mSelectionImage;
int mSelectedEmoteIndex;
int mHoveredEmoteIndex;
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 368eef17..06dbd43e 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -215,7 +215,6 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
Being *b = static_cast<Being*>(*it);
b->drawSpeech((int) mPixelViewX, (int) mPixelViewY);
- b->drawEmotion(graphics, (int) mPixelViewX, (int) mPixelViewY);
}
if (miniStatusWindow)
diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp
index 7a24c464..f7a6ca2b 100644
--- a/src/gui/widgets/emoteshortcutcontainer.cpp
+++ b/src/gui/widgets/emoteshortcutcontainer.cpp
@@ -20,11 +20,11 @@
#include "gui/widgets/emoteshortcutcontainer.h"
-#include "animatedsprite.h"
#include "configuration.h"
#include "emoteshortcut.h"
#include "graphics.h"
#include "inventory.h"
+#include "imagesprite.h"
#include "item.h"
#include "itemshortcut.h"
#include "keyboardconfig.h"
@@ -56,7 +56,7 @@ EmoteShortcutContainer::EmoteShortcutContainer():
// Setup emote sprites
for (int i = 0; i <= EmoteDB::getLast(); i++)
{
- mEmoteImg.push_back(EmoteDB::getAnimation(i));
+ mEmoteImg.push_back(EmoteDB::get(i)->sprite);
}
mMaxItems = EmoteDB::getLast() < MAX_ITEMS ? EmoteDB::getLast() : MAX_ITEMS;
@@ -106,7 +106,7 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics)
if (mEmoteMoved)
{
// Draw the emote image being dragged by the cursor.
- const AnimatedSprite* sprite = mEmoteImg[mEmoteMoved - 1];
+ const ImageSprite* sprite = mEmoteImg[mEmoteMoved - 1];
if (sprite)
{
const int tPosX = mCursorPosX - (sprite->getWidth() / 2);
diff --git a/src/gui/widgets/emoteshortcutcontainer.h b/src/gui/widgets/emoteshortcutcontainer.h
index e90612b4..c3fb9d14 100644
--- a/src/gui/widgets/emoteshortcutcontainer.h
+++ b/src/gui/widgets/emoteshortcutcontainer.h
@@ -25,8 +25,7 @@
#include <vector>
-class AnimatedSprite;
-class Image;
+class ImageSprite;
/**
* An emote shortcut container. Used to quickly use emoticons.
@@ -67,7 +66,7 @@ class EmoteShortcutContainer : public ShortcutContainer
void mouseReleased(gcn::MouseEvent &event);
private:
- std::vector<const AnimatedSprite*> mEmoteImg;
+ std::vector<const ImageSprite*> mEmoteImg;
bool mEmoteClicked;
int mEmoteMoved;
diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp
index d6ba816b..61491692 100644
--- a/src/net/tmwa/beinghandler.cpp
+++ b/src/net/tmwa/beinghandler.cpp
@@ -34,13 +34,12 @@
#include "net/tmwa/protocol.h"
#include "resources/colordb.h"
+#include "resources/emotedb.h"
#include <iostream>
namespace TmwAthena {
-const int EMOTION_TIME = 150; /**< Duration of emotion icon */
-
BeingHandler::BeingHandler(bool enableSync):
mSync(enableSync)
{
@@ -376,9 +375,9 @@ void BeingHandler::handleMessage(Net::MessageIn &msg)
if (player_relations.hasPermission(dstBeing, PlayerRelation::EMOTE))
{
- // only set emote if one doesnt already exist
- if (!dstBeing->getEmotion())
- dstBeing->setEmote(msg.readInt8(), EMOTION_TIME);
+ const int fx = EmoteDB::get(msg.readInt8())->effect;
+ //TODO: figure out why the -1 is needed
+ effectManager->trigger(fx - 1, dstBeing);
}
break;
diff --git a/src/playerrelations.cpp b/src/playerrelations.cpp
index f5d3d01b..8b6e6255 100644
--- a/src/playerrelations.cpp
+++ b/src/playerrelations.cpp
@@ -37,8 +37,6 @@
#define NAME "name" // constant for xml serialisation
#define RELATION "relation" // constant for xml serialisation
-#define IGNORE_EMOTE_TIME 100
-
// (De)serialisation class
class PlayerConfSerialiser : public ConfigurationListManager<std::pair<std::string, PlayerRelation *>,
std::map<std::string, PlayerRelation *> *>
@@ -349,38 +347,11 @@ public:
}
};
-class PIS_emote : public PlayerIgnoreStrategy
-{
-public:
- PIS_emote(int emote_nr, const std::string &description, const std::string &shortname) :
- mEmotion(emote_nr)
- {
- mDescription = description;
- mShortName = shortname;
- }
-
- virtual void ignore(Being *being, unsigned int flags)
- {
- being->setEmote(mEmotion, IGNORE_EMOTE_TIME);
- }
-private:
- int mEmotion;
-};
-
-
-
std::vector<PlayerIgnoreStrategy *> *
PlayerRelationsManager::getPlayerIgnoreStrategies()
{
if (mIgnoreStrategies.size() == 0)
{
- // not initialised yet?
- mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE,
- _("Floating '...' bubble"),
- PLAYER_IGNORE_STRATEGY_EMOTE0));
- mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1,
- _("Floating bubble"),
- "emote1"));
mIgnoreStrategies.push_back(new PIS_nothing());
mIgnoreStrategies.push_back(new PIS_dotdotdot());
mIgnoreStrategies.push_back(new PIS_blinkname());
diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp
index bd8a8e38..f48798b8 100644
--- a/src/resources/emotedb.cpp
+++ b/src/resources/emotedb.cpp
@@ -20,16 +20,20 @@
#include "resources/emotedb.h"
-#include "animatedsprite.h"
+#include "configuration.h"
#include "log.h"
+#include "imagesprite.h"
+
+#include "resources/resourcemanager.h"
+#include "resources/image.h"
+#include "resources/imageset.h"
#include "utils/xml.h"
-#include "configuration.h"
namespace
{
- EmoteInfos mEmoteInfos;
- EmoteInfo mUnknown;
+ Emotes mEmotes;
+ Emote mUnknown;
bool mLoaded = false;
int mLastEmote = 0;
}
@@ -39,13 +43,12 @@ void EmoteDB::load()
if (mLoaded)
unload();
- mLastEmote = 0;
+ mUnknown.name = "unknown";
+ mUnknown.effect = 0;
+ mUnknown.sprite = new ImageSprite(
+ ResourceManager::getInstance()->getImage("graphics/sprites/error.png"));
- EmoteSprite *unknownSprite = new EmoteSprite;
- unknownSprite->sprite = AnimatedSprite::load(
- paths.getStringValue("spriteErrorFile"));
- unknownSprite->name = "unknown";
- mUnknown.sprites.push_back(unknownSprite);
+ mLastEmote = 0;
logger->log("Initializing emote database...");
@@ -71,27 +74,46 @@ void EmoteDB::load()
continue;
}
- EmoteInfo *currentInfo = new EmoteInfo;
+ Emote *currentEmote = new Emote;
+
+ currentEmote->name = XML::getProperty(emoteNode, "name", "unknown");
+ currentEmote->effect = XML::getProperty(emoteNode, "effectid", -1);
- for_each_xml_child_node(spriteNode, emoteNode)
+ if (currentEmote->effect == -1)
{
- if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
- {
- EmoteSprite *currentSprite = new EmoteSprite;
- std::string file = paths.getStringValue("sprites")
- + (std::string) (const char*)
- spriteNode->xmlChildrenNode->content;
- currentSprite->sprite = AnimatedSprite::load(file,
- XML::getProperty(spriteNode, "variant", 0));
- currentInfo->sprites.push_back(currentSprite);
- }
- else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx"))
- {
- std::string particlefx = (const char*) spriteNode->xmlChildrenNode->content;
- currentInfo->particles.push_back(particlefx);
- }
+ logger->log("Emote Database: Warning: Emote with no attached effect!");
+ delete currentEmote;
+ continue;
}
- mEmoteInfos[id] = currentInfo;
+
+ const std::string imageName = XML::getProperty(emoteNode, "image", "");
+ const int width = XML::getProperty(emoteNode, "width", 0);
+ const int height = XML::getProperty(emoteNode, "height", 0);
+
+ if (imageName.empty() || !(width > 0) || !(height > 0))
+ {
+ logger->log("Emote Database: Warning: Emote with bad imageset values");
+ delete currentEmote;
+ continue;
+ }
+
+ ImageSet *is = ResourceManager::getInstance()->getImageSet(imageName,
+ width,
+ height);
+ if (!is || !(is->size() > 0))
+ {
+ logger->log("Emote Database: Error loading imageset");
+ delete is;
+ delete currentEmote;
+ continue;
+ }
+ else
+ {
+ // For now we just use the first image in the animation
+ currentEmote->sprite = new ImageSprite(is->get(0));
+ }
+
+ mEmotes[id] = currentEmote;
if (id > mLastEmote)
mLastEmote = id;
}
@@ -101,36 +123,19 @@ void EmoteDB::load()
void EmoteDB::unload()
{
- for (EmoteInfos::const_iterator i = mEmoteInfos.begin();
- i != mEmoteInfos.end();
- i++)
+ Emotes::iterator i;
+ for (i = mEmotes.begin(); i != mEmotes.end(); i++)
{
- while (!i->second->sprites.empty())
- {
- delete i->second->sprites.front()->sprite;
- delete i->second->sprites.front();
- i->second->sprites.pop_front();
- }
delete i->second;
}
-
- mEmoteInfos.clear();
-
- while (!mUnknown.sprites.empty())
- {
- delete mUnknown.sprites.front()->sprite;
- delete mUnknown.sprites.front();
- mUnknown.sprites.pop_front();
- }
-
mLoaded = false;
}
-const EmoteInfo *EmoteDB::get(int id)
+const Emote *EmoteDB::get(int id)
{
- EmoteInfos::const_iterator i = mEmoteInfos.find(id);
+ Emotes::const_iterator i = mEmotes.find(id);
- if (i == mEmoteInfos.end())
+ if (i == mEmotes.end())
{
logger->log("EmoteDB: Warning, unknown emote ID %d requested", id);
return &mUnknown;
@@ -141,12 +146,6 @@ const EmoteInfo *EmoteDB::get(int id)
}
}
-const AnimatedSprite *EmoteDB::getAnimation(int id)
-{
- const EmoteInfo *info = get(id);
- return info->sprites.front()->sprite;
-}
-
const int &EmoteDB::getLast()
{
return mLastEmote;
diff --git a/src/resources/emotedb.h b/src/resources/emotedb.h
index 3d80ce8f..a2887a74 100644
--- a/src/resources/emotedb.h
+++ b/src/resources/emotedb.h
@@ -25,21 +25,16 @@
#include <map>
#include <string>
-class AnimatedSprite;
+class ImageSprite;
-struct EmoteSprite
+struct Emote
{
- const AnimatedSprite *sprite;
std::string name;
+ ImageSprite *sprite;
+ int effect;
};
-struct EmoteInfo
-{
- std::list<EmoteSprite*> sprites;
- std::list<std::string> particles;
-};
-
-typedef std::map<int, EmoteInfo*> EmoteInfos;
+typedef std::map<int, Emote*> Emotes;
/**
* Emote information database.
@@ -50,13 +45,11 @@ namespace EmoteDB
void unload();
- const EmoteInfo *get(int id);
-
- const AnimatedSprite *getAnimation(int id);
+ const Emote *get(int id);
const int &getLast();
- typedef EmoteInfos::iterator EmoteInfosIterator;
+ typedef Emotes::iterator EmotesIterator;
}
#endif