summaryrefslogtreecommitdiff
path: root/src/actorsprite.cpp
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2010-05-09 14:31:43 -0600
committerJared Adams <jaxad0127@gmail.com>2010-05-09 15:09:56 -0600
commitf269d5a68e6a22676c49961c7529b9c00dc90649 (patch)
tree3ccce636203883c0009146099df9d4854cab2171 /src/actorsprite.cpp
parent9baedc27191c82bbf1fedee2a7e738bc5b267c0e (diff)
downloadMana-f269d5a68e6a22676c49961c7529b9c00dc90649.tar.gz
Mana-f269d5a68e6a22676c49961c7529b9c00dc90649.tar.bz2
Mana-f269d5a68e6a22676c49961c7529b9c00dc90649.tar.xz
Mana-f269d5a68e6a22676c49961c7529b9c00dc90649.zip
Move target cursor management into ActorSprite
This simplifies handling of target cursors, centralizing their logic into a single class, instead of two. Also make them more flexible and move the image files outside of the theme so servers can can control them and give them better names. Reviewed-by: Thorbjørn Lindeijer
Diffstat (limited to 'src/actorsprite.cpp')
-rw-r--r--src/actorsprite.cpp121
1 files changed, 115 insertions, 6 deletions
diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp
index ad703bc2..da81873f 100644
--- a/src/actorsprite.cpp
+++ b/src/actorsprite.cpp
@@ -34,10 +34,16 @@
#include "net/net.h"
#include "resources/image.h"
+#include "resources/imageset.h"
#include "resources/resourcemanager.h"
+#include <cassert>
+
#define EFFECTS_FILE "effects.xml"
+ImageSet *ActorSprite::targetCursorImages[2][NUM_TC];
+SimpleAnimation *ActorSprite::targetCursor[2][NUM_TC];
+
ActorSprite::ActorSprite(int id):
mId(id),
mStunMode(0),
@@ -83,9 +89,6 @@ bool ActorSprite::drawSpriteAt(Graphics *graphics, int x, int y) const
void ActorSprite::logic()
{
// Update sprite animations
- if (mUsedTargetCursor)
- mUsedTargetCursor->update(tick_time * MILLISECONDS_IN_A_TICK);
-
update(tick_time * MILLISECONDS_IN_A_TICK);
// Restart status/particle effects, if needed
@@ -105,6 +108,18 @@ void ActorSprite::logic()
mChildParticleEffects.moveTo(mPos.x, mPos.y);
}
+void ActorSprite::actorLogic()
+{
+ // Update sprite animations
+ for (int size = TC_SMALL; size < NUM_TC; size++)
+ {
+ for (int type = TCT_NORMAL; type < NUM_TCT; type++)
+ {
+ targetCursor[type][size]->update(tick_time * MILLISECONDS_IN_A_TICK);
+ }
+ }
+}
+
void ActorSprite::setMap(Map* map)
{
Actor::setMap(map);
@@ -119,10 +134,12 @@ void ActorSprite::controlParticle(Particle *particle)
mChildParticleEffects.addLocally(particle);
}
-void ActorSprite::setTargetAnimation(SimpleAnimation *animation)
+void ActorSprite::setTargetType(TargetCursorType type)
{
- mUsedTargetCursor = animation;
- mUsedTargetCursor->reset();
+ if (type == TCT_NONE)
+ untarget();
+ else
+ mUsedTargetCursor = targetCursor[type][getTargetCursorSize()];
}
struct EffectDescription {
@@ -324,3 +341,95 @@ void ActorSprite::setupSpriteDisplay(const SpriteDisplay &display,
mMustResetParticles = true;
}
+
+void ActorSprite::load()
+{
+ initTargetCursor();
+}
+
+void ActorSprite::unload()
+{
+ cleanupTargetCursors();
+}
+
+static const char *cursorType(int type)
+{
+ switch (type)
+ {
+ case ActorSprite::TCT_IN_RANGE:
+ return "in-range";
+ case ActorSprite::TCT_NORMAL:
+ return "normal";
+ default:
+ assert(false);
+ }
+}
+
+static const char *cursorSize(int size)
+{
+ switch (size)
+ {
+ case ActorSprite::TC_LARGE:
+ return "l";
+ case ActorSprite::TC_MEDIUM:
+ return "m";
+ case ActorSprite::TC_SMALL:
+ return "s";
+ default:
+ assert(false);
+ }
+}
+
+void ActorSprite::initTargetCursor()
+{
+ static std::string targetCursor = "graphics/target-cursor-%s-%s.png";
+ static int targetWidths[NUM_TC] = {44, 62, 82};
+ static int targetHeights[NUM_TC] = {35, 44, 60};
+
+ // Load target cursors
+ for (int size = TC_SMALL; size < NUM_TC; size++)
+ {
+ for (int type = TCT_NORMAL; type < NUM_TCT; type++)
+ {
+ loadTargetCursor(strprintf(targetCursor.c_str(), cursorType(type),
+ cursorSize(size)), targetWidths[size],
+ targetHeights[size], type, size);
+ }
+ }
+}
+
+void ActorSprite::cleanupTargetCursors()
+{
+ for (int size = TC_SMALL; size < NUM_TC; size++)
+ {
+ for (int type = TCT_NORMAL; type < NUM_TCT; type++)
+ {
+ delete targetCursor[type][size];
+ targetCursorImages[type][size]->decRef();
+ }
+ }
+}
+
+void ActorSprite::loadTargetCursor(const std::string &filename,
+ int width, int height, int type, int size)
+{
+ assert(size > -1);
+ assert(size < 3);
+
+ ResourceManager *resman = ResourceManager::getInstance();
+ ImageSet *currentImageSet = resman->getImageSet(filename, width, height);
+
+ Animation *anim = new Animation;
+
+ for (unsigned int i = 0; i < currentImageSet->size(); ++i)
+ {
+ anim->addFrame(currentImageSet->get(i), 750,
+ (16 - (currentImageSet->getWidth() / 2)),
+ (16 - (currentImageSet->getHeight() / 2)));
+ }
+
+ SimpleAnimation *currentCursor = new SimpleAnimation(anim);
+
+ targetCursorImages[type][size] = currentImageSet;
+ targetCursor[type][size] = currentCursor;
+}