summaryrefslogtreecommitdiff
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
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
-rw-r--r--data/graphics/CMakeLists.txt9
-rw-r--r--data/graphics/Makefile.am8
-rw-r--r--data/graphics/gui/CMakeLists.txt6
-rw-r--r--data/graphics/gui/Makefile.am6
-rw-r--r--data/graphics/target-cursor-in-range-l.png (renamed from data/graphics/gui/target-cursor-blue-l.png)bin23803 -> 23803 bytes
-rw-r--r--data/graphics/target-cursor-in-range-m.png (renamed from data/graphics/gui/target-cursor-blue-m.png)bin18439 -> 18439 bytes
-rw-r--r--data/graphics/target-cursor-in-range-s.png (renamed from data/graphics/gui/target-cursor-blue-s.png)bin8353 -> 8353 bytes
-rw-r--r--data/graphics/target-cursor-normal-l.png (renamed from data/graphics/gui/target-cursor-red-l.png)bin25586 -> 25586 bytes
-rw-r--r--data/graphics/target-cursor-normal-m.png (renamed from data/graphics/gui/target-cursor-red-m.png)bin17950 -> 17950 bytes
-rw-r--r--data/graphics/target-cursor-normal-s.png (renamed from data/graphics/gui/target-cursor-red-s.png)bin8361 -> 8361 bytes
-rw-r--r--src/actorsprite.cpp121
-rw-r--r--src/actorsprite.h34
-rw-r--r--src/client.cpp23
-rw-r--r--src/game.cpp2
-rw-r--r--src/localplayer.cpp58
-rw-r--r--src/localplayer.h16
16 files changed, 187 insertions, 96 deletions
diff --git a/data/graphics/CMakeLists.txt b/data/graphics/CMakeLists.txt
index 58d75523..d7e78c30 100644
--- a/data/graphics/CMakeLists.txt
+++ b/data/graphics/CMakeLists.txt
@@ -1,2 +1,11 @@
ADD_SUBDIRECTORY(gui)
ADD_SUBDIRECTORY(images)
+
+SET (FILES
+ target-cursor-in-range-l.png
+ target-cursor-in-range-m.png
+ target-cursor-in-range-s.png
+ target-cursor-normal-l.png
+ target-cursor-normal-m.png
+ target-cursor-normal-s.png
+ ) \ No newline at end of file
diff --git a/data/graphics/Makefile.am b/data/graphics/Makefile.am
index e0003154..babe2b96 100644
--- a/data/graphics/Makefile.am
+++ b/data/graphics/Makefile.am
@@ -2,3 +2,11 @@
EXTRA_DIST = CMakeLists.txt
SUBDIRS = gui images
+
+EXTRA_DIST = \
+ target-cursor-in-range-l.png \
+ target-cursor-in-range-m.png \
+ target-cursor-in-range-s.png \
+ target-cursor-normal-l.png \
+ target-cursor-normal-m.png \
+ target-cursor-normal-s.png \ No newline at end of file
diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt
index fc825139..9943fb0f 100644
--- a/data/graphics/gui/CMakeLists.txt
+++ b/data/graphics/gui/CMakeLists.txt
@@ -31,12 +31,6 @@ SET (FILES
tab.png
tab_hilight.png
tabselected.png
- target-cursor-blue-l.png
- target-cursor-blue-m.png
- target-cursor-blue-s.png
- target-cursor-red-l.png
- target-cursor-red-m.png
- target-cursor-red-s.png
unknown-item.png
vscroll_down_default.png
vscroll_down_highlight.png
diff --git a/data/graphics/gui/Makefile.am b/data/graphics/gui/Makefile.am
index 6d04666a..04f957b7 100644
--- a/data/graphics/gui/Makefile.am
+++ b/data/graphics/gui/Makefile.am
@@ -35,12 +35,6 @@ gui_DATA = \
tab.png \
tab_hilight.png \
tabselected.png \
- target-cursor-blue-l.png \
- target-cursor-blue-m.png \
- target-cursor-blue-s.png \
- target-cursor-red-l.png \
- target-cursor-red-m.png \
- target-cursor-red-s.png \
unknown-item.png \
vscroll_down_default.png \
vscroll_down_highlight.png \
diff --git a/data/graphics/gui/target-cursor-blue-l.png b/data/graphics/target-cursor-in-range-l.png
index 77cdf4b6..77cdf4b6 100644
--- a/data/graphics/gui/target-cursor-blue-l.png
+++ b/data/graphics/target-cursor-in-range-l.png
Binary files differ
diff --git a/data/graphics/gui/target-cursor-blue-m.png b/data/graphics/target-cursor-in-range-m.png
index c0107357..c0107357 100644
--- a/data/graphics/gui/target-cursor-blue-m.png
+++ b/data/graphics/target-cursor-in-range-m.png
Binary files differ
diff --git a/data/graphics/gui/target-cursor-blue-s.png b/data/graphics/target-cursor-in-range-s.png
index 3e81c75d..3e81c75d 100644
--- a/data/graphics/gui/target-cursor-blue-s.png
+++ b/data/graphics/target-cursor-in-range-s.png
Binary files differ
diff --git a/data/graphics/gui/target-cursor-red-l.png b/data/graphics/target-cursor-normal-l.png
index 76d2101b..76d2101b 100644
--- a/data/graphics/gui/target-cursor-red-l.png
+++ b/data/graphics/target-cursor-normal-l.png
Binary files differ
diff --git a/data/graphics/gui/target-cursor-red-m.png b/data/graphics/target-cursor-normal-m.png
index e2ab79c2..e2ab79c2 100644
--- a/data/graphics/gui/target-cursor-red-m.png
+++ b/data/graphics/target-cursor-normal-m.png
Binary files differ
diff --git a/data/graphics/gui/target-cursor-red-s.png b/data/graphics/target-cursor-normal-s.png
index 09195f44..09195f44 100644
--- a/data/graphics/gui/target-cursor-red-s.png
+++ b/data/graphics/target-cursor-normal-s.png
Binary files differ
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;
+}
diff --git a/src/actorsprite.h b/src/actorsprite.h
index b5c402eb..a56be125 100644
--- a/src/actorsprite.h
+++ b/src/actorsprite.h
@@ -53,6 +53,14 @@ public:
NUM_TC
};
+ enum TargetCursorType
+ {
+ TCT_NONE = -1,
+ TCT_NORMAL = 0,
+ TCT_IN_RANGE,
+ NUM_TCT
+ };
+
ActorSprite(int id);
~ActorSprite();
@@ -73,6 +81,8 @@ public:
virtual void logic();
+ static void actorLogic();
+
void setMap(Map* map);
/**
@@ -95,7 +105,7 @@ public:
/**
* Sets the target animation for this actor.
*/
- void setTargetAnimation(SimpleAnimation *animation);
+ void setTargetType(TargetCursorType type);
/**
* Untargets the actor.
@@ -140,6 +150,10 @@ public:
virtual float getAlpha() const
{ return CompoundSprite::getAlpha(); }
+ static void load();
+
+ static void unload();
+
protected:
/**
* Trigger visual effect, with components
@@ -185,6 +199,24 @@ private:
/** Reset particle status effects on next redraw? */
bool mMustResetParticles;
+ /** Load the target cursors into memory */
+ static void initTargetCursor();
+
+ /** Remove the target cursors from memory */
+ static void cleanupTargetCursors();
+
+ /**
+ * Helper function for loading target cursors
+ */
+ static void loadTargetCursor(const std::string &filename,
+ int width, int height, int type, int size);
+
+ /** Images of the target cursor. */
+ static ImageSet *targetCursorImages[NUM_TCT][NUM_TC];
+
+ /** Animated target cursors. */
+ static SimpleAnimation *targetCursor[NUM_TCT][NUM_TC];
+
/** Target cursor being used */
SimpleAnimation *mUsedTargetCursor;
};
diff --git a/src/client.cpp b/src/client.cpp
index afc1ae1d..137210b1 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -446,14 +446,6 @@ Client::~Client()
// Shutdown sound
sound.close();
- // Unload XML databases
- ColorDB::unload();
- EmoteDB::unload();
- ItemDB::unload();
- MonsterDB::unload();
- NPCDB::unload();
- StatusEffect::unload();
-
ResourceManager::deleteInstance();
SDL_FreeSurface(mIcon);
@@ -594,6 +586,19 @@ int Client::exec()
{
delete game;
game = 0;
+
+ if (mState != STATE_CHANGE_MAP)
+ {
+ // Unload XML databases
+ ColorDB::unload();
+ EmoteDB::unload();
+ ItemDB::unload();
+ MonsterDB::unload();
+ NPCDB::unload();
+ StatusEffect::unload();
+
+ ActorSprite::unload();
+ }
}
mOldState = mState;
@@ -748,6 +753,8 @@ int Client::exec()
StatusEffect::load();
Units::loadUnits();
+ ActorSprite::load();
+
mDesktop->reloadWallpaper();
mState = STATE_GET_CHARACTERS;
diff --git a/src/game.cpp b/src/game.cpp
index 74997b90..b75d3cdf 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -21,6 +21,7 @@
#include "game.h"
+#include "actorsprite.h"
#include "beingmanager.h"
#include "channelmanager.h"
#include "client.h"
@@ -334,6 +335,7 @@ void Game::logic()
handleInput();
// Handle all necessary game logic
+ ActorSprite::actorLogic();
beingManager->logic();
floorItemManager->logic();
particleEngine->update();
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 19ddec51..9796b2ac 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -116,8 +116,6 @@ LocalPlayer::LocalPlayer(int id, int subtype):
mTextColor = &Theme::getThemeColor(Theme::PLAYER);
mNameColor = &userPalette->getColor(UserPalette::SELF);
- initTargetCursor();
-
config.addListener("showownname", this);
setShowName(config.getValue("showownname", 1));
}
@@ -127,14 +125,6 @@ LocalPlayer::~LocalPlayer()
delete mInventory;
config.removeListener("showownname", this);
-
- for (int i = Being::TC_SMALL; i < Being::NUM_TC; i++)
- {
- delete mTargetCursor[0][i];
- delete mTargetCursor[1][i];
- mTargetCursorImages[0][i]->decRef();
- mTargetCursorImages[1][i]->decRef();
- }
}
void LocalPlayer::logic()
@@ -200,8 +190,7 @@ void LocalPlayer::logic()
if (mTarget->getType() == Being::NPC)
{
// NPCs are always in range
- mTarget->setTargetAnimation(
- mTargetCursor[0][mTarget->getTargetCursorSize()]);
+ mTarget->setTargetType(TCT_IN_RANGE);
}
else
{
@@ -217,10 +206,10 @@ void LocalPlayer::logic()
abs(mTarget->getTileY() - getTileY());
const int attackRange = getAttackRange();
- const int inRange = rangeX > attackRange || rangeY > attackRange
- ? 1 : 0;
- mTarget->setTargetAnimation(
- mTargetCursor[inRange][mTarget->getTargetCursorSize()]);
+ const TargetCursorType targetType = rangeX > attackRange ||
+ rangeY > attackRange ?
+ TCT_NORMAL : TCT_IN_RANGE;
+ mTarget->setTargetType(targetType);
if (!mTarget->isAlive())
stopAttack();
@@ -1374,43 +1363,6 @@ void LocalPlayer::handleStatusEffect(StatusEffect *effect, int effectId)
}
}
-void LocalPlayer::initTargetCursor()
-{
- // Load target cursors
- loadTargetCursor("target-cursor-blue-s.png", 44, 35, false, TC_SMALL);
- loadTargetCursor("target-cursor-red-s.png", 44, 35, true, TC_SMALL);
- loadTargetCursor("target-cursor-blue-m.png", 62, 44, false, TC_MEDIUM);
- loadTargetCursor("target-cursor-red-m.png", 62, 44, true, TC_MEDIUM);
- loadTargetCursor("target-cursor-blue-l.png", 82, 60, false, TC_LARGE);
- loadTargetCursor("target-cursor-red-l.png", 82, 60, true, TC_LARGE);
-}
-
-void LocalPlayer::loadTargetCursor(const std::string &filename,
- int width, int height,
- bool outRange, TargetCursorSize size)
-{
- assert(size > -1);
- assert(size < 3);
-
- ImageSet *currentImageSet = Theme::getImageSetFromTheme(filename,
- width, height);
- Animation *anim = new Animation;
-
- for (unsigned int i = 0; i < currentImageSet->size(); ++i)
- {
- anim->addFrame(currentImageSet->get(i), 75,
- (16 - (currentImageSet->getWidth() / 2)),
- (16 - (currentImageSet->getHeight() / 2)));
- }
-
- SimpleAnimation *currentCursor = new SimpleAnimation(anim);
-
- const int index = outRange ? 1 : 0;
-
- mTargetCursorImages[index][size] = currentImageSet;
- mTargetCursor[index][size] = currentCursor;
-}
-
void LocalPlayer::addMessageToQueue(const std::string &message, int color)
{
mMessages.push_back(MessagePair(message, color));
diff --git a/src/localplayer.h b/src/localplayer.h
index 2c06dfb5..38212a60 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -479,22 +479,6 @@ class LocalPlayer : public Player
int mLocalWalkTime; /**< Timestamp used to control keyboard walk
messages flooding */
- /** Load the target cursors into memory */
- void initTargetCursor();
-
- /**
- * Helper function for loading target cursors
- */
- void loadTargetCursor(const std::string &filename,
- int width, int height,
- bool outRange, Being::TargetCursorSize size);
-
- /** Images of the target cursor. */
- ImageSet *mTargetCursorImages[2][NUM_TC];
-
- /** Animated target cursors. */
- SimpleAnimation *mTargetCursor[2][NUM_TC];
-
typedef std::pair<std::string, int> MessagePair;
/** Queued exp messages*/
std::list<MessagePair> mMessages;