summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/being.cpp4
-rw-r--r--src/being.h10
-rw-r--r--src/gui/viewport.cpp95
-rw-r--r--src/gui/viewport.h24
-rw-r--r--src/localplayer.cpp99
-rw-r--r--src/localplayer.h25
6 files changed, 133 insertions, 124 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 519be4cc..c4569d4e 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -26,15 +26,15 @@
#include <cmath>
#include "animatedsprite.h"
+#include "configuration.h"
#include "equipment.h"
#include "game.h"
#include "graphics.h"
+#include "localplayer.h"
#include "log.h"
#include "map.h"
#include "particle.h"
#include "sound.h"
-#include "localplayer.h"
-#include "configuration.h"
#include "text.h"
#include "resources/resourcemanager.h"
diff --git a/src/being.h b/src/being.h
index cceebc3c..1eeeb9db 100644
--- a/src/being.h
+++ b/src/being.h
@@ -30,9 +30,9 @@
#include <SDL_types.h>
#include <vector>
-#include "sprite.h"
-#include "map.h"
#include "animatedsprite.h"
+#include "map.h"
+#include "sprite.h"
#include "gui/speechbubble.h"
@@ -48,7 +48,6 @@ class ItemInfo;
class Item;
class Map;
class Graphics;
-class ImageSet;
class Particle;
class SpeechBubble;
class Text;
@@ -362,8 +361,10 @@ class Being : public Sprite
*/
virtual void triggerEffect(int effectId) { internalTriggerEffect(effectId, false, true); }
- const std::auto_ptr<Equipment> mEquipment;
+ // Target cursor being used by the being
+ Image *mTargetCursor;
+ const std::auto_ptr<Equipment> mEquipment;
protected:
/**
@@ -392,6 +393,7 @@ class Being : public Sprite
std::string mName; /**< Name of character */
SpriteIterator mSpriteIterator;
bool mIsGM;
+ bool mTargeted;
bool mParticleEffects; /**< Whether to display particles or not */
/** Engine-related infos about weapon. */
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index f6361ef7..7f420e0a 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -74,65 +74,11 @@ Viewport::Viewport():
config.addListener("ScrollRadius", this);
mPopupMenu = new PopupMenu();
-
- // Load target cursors
- loadTargetCursor("graphics/gui/target-cursor-blue-s.png", 44, 35,
- false, Being::TC_SMALL);
- loadTargetCursor("graphics/gui/target-cursor-red-s.png", 44, 35,
- true, Being::TC_SMALL);
- loadTargetCursor("graphics/gui/target-cursor-blue-m.png", 62, 44,
- false, Being::TC_MEDIUM);
- loadTargetCursor("graphics/gui/target-cursor-red-m.png", 62, 44,
- true, Being::TC_MEDIUM);
- loadTargetCursor("graphics/gui/target-cursor-blue-l.png", 82, 60,
- false, Being::TC_LARGE);
- loadTargetCursor("graphics/gui/target-cursor-red-l.png", 82, 60,
- true, Being::TC_LARGE);
-}
-
-void
-Viewport::loadTargetCursor(std::string filename, int width, int height,
- bool outRange, Being::TargetCursorSize size)
-{
- assert(size > -1);
- assert(size < 3);
-
- ImageSet* currentImageSet;
- SimpleAnimation* currentCursor;
-
- ResourceManager *resman = ResourceManager::getInstance();
-
- currentImageSet = resman->getImageSet(filename, width, height);
- Animation *anim = new Animation();
- for (unsigned int i = 0; i < currentImageSet->size(); ++i)
- {
- anim->addFrame(currentImageSet->get(i), 75, 0, 0);
- }
- currentCursor = new SimpleAnimation(anim);
-
- if (outRange)
- {
- mOutRangeImages[size] = currentImageSet;
- mTargetCursorOutRange[size] = currentCursor;
- }
- else
- {
- mInRangeImages[size] = currentImageSet;
- mTargetCursorInRange[size] = currentCursor;
- }
}
Viewport::~Viewport()
{
delete mPopupMenu;
-
- for (int i = Being::TC_SMALL; i < Being::NUM_TC; i++)
- {
- delete mTargetCursorInRange[i];
- delete mTargetCursorOutRange[i];
- mInRangeImages[i]->decRef();
- mOutRangeImages[i]->decRef();
- }
}
void
@@ -228,7 +174,7 @@ Viewport::draw(gcn::Graphics *gcnGraphics)
if (mMap)
{
mMap->draw(graphics, (int) mPixelViewX, (int) mPixelViewY);
- drawTargetCursor(graphics); // TODO: Draw the cursor with the sprite
+ player_node->drawTargetCursor(graphics, (int) mPixelViewX, (int) mPixelViewY);
// Find a path from the player to the mouse, and draw it. This is for debug
@@ -291,45 +237,6 @@ void Viewport::logic()
mouseY / 32 + mTileViewY);
mWalkTime = player_node->mWalkTime;
}
-
- for (int i = Being::TC_SMALL; i < Being::NUM_TC; i++)
- {
- mTargetCursorInRange[i]->update(10);
- mTargetCursorOutRange[i]->update(10);
- }
-}
-
-void Viewport::drawTargetCursor(Graphics *graphics)
-{
- // Draw target marker if needed
- Being *target = player_node->getTarget();
- if (target)
- {
- // Calculate target circle position
-
- // Find whether target is in range
- int rangeX = abs(target->mX - player_node->mX);
- int rangeY = abs(target->mY - player_node->mY);
- int attackRange = player_node->getAttackRange();
-
- // Get the correct target cursors graphic
- Being::TargetCursorSize cursorSize = target->getTargetCursorSize();
- Image* targetCursor;
- if (rangeX > attackRange || rangeY > attackRange)
- {
- targetCursor = mTargetCursorOutRange[cursorSize]->getCurrentImage();
- }
- else
- {
- targetCursor = mTargetCursorInRange[cursorSize]->getCurrentImage();
- }
-
- // Draw the target cursor at the correct position
- int posX = target->getPixelX() + 16 - targetCursor->getWidth() / 2 - (int) mPixelViewX;
- int posY = target->getPixelY() + 16 - targetCursor->getHeight() / 2 - (int) mPixelViewY;
-
- graphics->drawImage(targetCursor, posX, posY);
- }
}
void Viewport::mousePressed(gcn::MouseEvent &event)
diff --git a/src/gui/viewport.h b/src/gui/viewport.h
index 70ac1bea..c7b3c0e7 100644
--- a/src/gui/viewport.h
+++ b/src/gui/viewport.h
@@ -38,7 +38,6 @@ class ImageSet;
class Item;
class PopupMenu;
class Graphics;
-class SimpleAnimation;
/**
* The viewport on the map. Displays the current map and handles mouse input
@@ -136,17 +135,6 @@ class Viewport : public WindowContainer, public gcn::MouseListener,
scrollBy(float x, float y) { mPixelViewX += x; mPixelViewY += y; }
private:
- /**
- * Helper function for loading target cursors
- */
- void loadTargetCursor(std::string filename, int width, int height,
- bool outRange, Being::TargetCursorSize size);
-
- /**
- * Draws range based target cursor
- */
- void drawTargetCursor(Graphics *graphics);
-
Map *mMap; /**< The current map. */
int mScrollRadius;
@@ -159,18 +147,6 @@ class Viewport : public WindowContainer, public gcn::MouseListener,
int mTileViewY; /**< Current viewpoint in tiles. */
bool mShowDebugPath; /**< Show a path from player to pointer. */
- /** Images of in range target cursor. */
- ImageSet *mInRangeImages[Being::NUM_TC];
-
- /** Images of out of range target cursor. */
- ImageSet *mOutRangeImages[Being::NUM_TC];
-
- /** Animated in range target cursor. */
- SimpleAnimation *mTargetCursorInRange[Being::NUM_TC];
-
- /** Animated out of range target cursor. */
- SimpleAnimation *mTargetCursorOutRange[Being::NUM_TC];
-
bool mPlayerFollowMouse;
int mWalkTime;
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 66d37ddf..4cdaf03c 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -20,6 +20,7 @@
*
* $Id$
*/
+#include <cassert>
#include "localplayer.h"
@@ -38,6 +39,9 @@
#include "net/messageout.h"
#include "net/protocol.h"
+#include "resources/resourcemanager.h"
+#include "resources/imageset.h"
+
#include "utils/tostring.h"
LocalPlayer *player_node = NULL;
@@ -54,12 +58,21 @@ LocalPlayer::LocalPlayer(Uint32 id, Uint16 job, Map *map):
mInventory(new Inventory(INVENTORY_SIZE)),
mStorage(new Inventory(STORAGE_SIZE))
{
+ initTargetCursor();
}
LocalPlayer::~LocalPlayer()
{
delete mInventory;
delete mStorage;
+
+ for (int i = Being::TC_SMALL; i < Being::NUM_TC; i++)
+ {
+ delete mTargetCursorInRange[i];
+ delete mTargetCursorOutRange[i];
+ mInRangeImages[i]->decRef();
+ mOutRangeImages[i]->decRef();
+ }
}
void LocalPlayer::logic()
@@ -104,6 +117,12 @@ void LocalPlayer::logic()
mLastAction = -1;
}
+ for (int i = Being::TC_SMALL; i < Being::NUM_TC; i++)
+ {
+ player_node->mTargetCursorInRange[i]->update(10);
+ player_node->mTargetCursorOutRange[i]->update(10);
+ }
+
Being::logic();
}
@@ -494,3 +513,83 @@ void LocalPlayer::setGotoTarget(Being *target)
mGoingToTarget = true;
setDestination(target->mX, target->mY);
}
+
+void LocalPlayer::initTargetCursor()
+{
+ // Load target cursors
+ loadTargetCursor("graphics/gui/target-cursor-blue-s.png", 44, 35,
+ false, TC_SMALL);
+ loadTargetCursor("graphics/gui/target-cursor-red-s.png", 44, 35,
+ true, TC_SMALL);
+ loadTargetCursor("graphics/gui/target-cursor-blue-m.png", 62, 44,
+ false, TC_MEDIUM);
+ loadTargetCursor("graphics/gui/target-cursor-red-m.png", 62, 44,
+ true, TC_MEDIUM);
+ loadTargetCursor("graphics/gui/target-cursor-blue-l.png", 82, 60,
+ false, TC_LARGE);
+ loadTargetCursor("graphics/gui/target-cursor-red-l.png", 82, 60,
+ true, TC_LARGE);
+}
+
+void LocalPlayer::loadTargetCursor(std::string filename, int width, int height,
+ bool outRange, TargetCursorSize size)
+{
+ assert(size > -1);
+ assert(size < 3);
+
+ ImageSet* currentImageSet;
+ SimpleAnimation* currentCursor;
+
+ ResourceManager *resman = ResourceManager::getInstance();
+
+ currentImageSet = resman->getImageSet(filename, width, height);
+ Animation *anim = new Animation();
+ for (unsigned int i = 0; i < currentImageSet->size(); ++i)
+ {
+ anim->addFrame(currentImageSet->get(i), 75, 0, 0);
+ }
+ currentCursor = new SimpleAnimation(anim);
+
+ if (outRange)
+ {
+ mOutRangeImages[size] = currentImageSet;
+ mTargetCursorOutRange[size] = currentCursor;
+ }
+ else
+ {
+ mInRangeImages[size] = currentImageSet;
+ mTargetCursorInRange[size] = currentCursor;
+ }
+}
+
+void LocalPlayer::drawTargetCursor(Graphics *graphics, int offsetX, int offsetY)
+{
+ // Draw target marker if needed
+ if (mTarget)
+ {
+ // Calculate target circle position
+
+ // Find whether target is in range
+ int rangeX = abs(mTarget->mX - mX);
+ int rangeY = abs(mTarget->mY - mY);
+ int attackRange = getAttackRange();
+
+ // Get the correct target cursors graphic
+ TargetCursorSize cursorSize = mTarget->getTargetCursorSize();
+
+ if (rangeX > attackRange || rangeY > attackRange)
+ {
+ mTarget->mTargetCursor = mTargetCursorOutRange[cursorSize]->getCurrentImage();
+ }
+ else
+ {
+ mTarget->mTargetCursor = mTargetCursorInRange[cursorSize]->getCurrentImage();
+ }
+
+ // Draw the target cursor at the correct position
+ int posX = mTarget->getPixelX() + 16 - mTarget->mTargetCursor->getWidth() / 2 - offsetX;
+ int posY = mTarget->getPixelY() + 16 - mTarget->mTargetCursor->getHeight() / 2 - offsetY;
+
+ graphics->drawImage(mTarget->mTargetCursor, posX, posY);
+ }
+}
diff --git a/src/localplayer.h b/src/localplayer.h
index 757c70eb..c0627378 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -25,6 +25,7 @@
#define _TMW_LOCALPLAYER_H
#include "player.h"
+#include "simpleanimation.h"
// TODO move into some sane place...
#define MAX_SLOT 2
@@ -33,6 +34,7 @@
#define STORAGE_SIZE 301
class FloorItem;
+class ImageSet;
class Inventory;
class Item;
class Network;
@@ -214,6 +216,14 @@ class LocalPlayer : public Player
float mLastAttackTime; /**< Used to synchronize the charge dialog */
+ void drawTargetCursor(Graphics *graphics, int offsetX, int offsetY);
+
+ /** Animated in range target cursor. */
+ SimpleAnimation *mTargetCursorInRange[NUM_TC];
+
+ /** Animated out of range target cursor. */
+ SimpleAnimation *mTargetCursorOutRange[NUM_TC];
+
protected:
void walk(unsigned char dir);
@@ -233,6 +243,21 @@ class LocalPlayer : public Player
Inventory *mInventory;
Inventory *mStorage;
+
+ /**
+ * Helper function for loading target cursors
+ */
+ void loadTargetCursor(std::string filename, int width, int height,
+ bool outRange, Being::TargetCursorSize size);
+
+ /** Images of in range target cursor. */
+ ImageSet *mInRangeImages[NUM_TC];
+
+ /** Images of out of range target cursor. */
+ ImageSet *mOutRangeImages[NUM_TC];
+
+ // Load the target cursors into memory
+ void initTargetCursor();
};
extern LocalPlayer *player_node;