summaryrefslogtreecommitdiff
path: root/src/localplayer.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/localplayer.cpp
parent9baedc27191c82bbf1fedee2a7e738bc5b267c0e (diff)
downloadmana-client-f269d5a68e6a22676c49961c7529b9c00dc90649.tar.gz
mana-client-f269d5a68e6a22676c49961c7529b9c00dc90649.tar.bz2
mana-client-f269d5a68e6a22676c49961c7529b9c00dc90649.tar.xz
mana-client-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/localplayer.cpp')
-rw-r--r--src/localplayer.cpp58
1 files changed, 5 insertions, 53 deletions
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));