summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorDavid Athay <ko2fan@gmail.com>2007-03-19 16:52:44 +0000
committerDavid Athay <ko2fan@gmail.com>2007-03-19 16:52:44 +0000
commit3702c703ff49f7ca21c5fa6c789cab12cab282b9 (patch)
tree99760cf27b2cffed647d7ee765a7c1855dec7eb0 /src/gui
parenta6f43600f1a9e7b1f39ca0ea9068130b680e5a89 (diff)
downloadmana-client-3702c703ff49f7ca21c5fa6c789cab12cab282b9.tar.gz
mana-client-3702c703ff49f7ca21c5fa6c789cab12cab282b9.tar.bz2
mana-client-3702c703ff49f7ca21c5fa6c789cab12cab282b9.tar.xz
mana-client-3702c703ff49f7ca21c5fa6c789cab12cab282b9.zip
Added target cursor. Shows blue when target in range, and red when out of range.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/viewport.cpp61
-rw-r--r--src/gui/viewport.h7
2 files changed, 68 insertions, 0 deletions
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 513a7ee5..96f44068 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -28,6 +28,7 @@
#include "gui.h"
#include "popupmenu.h"
+#include "../simpleanimation.h"
#include "../beingmanager.h"
#include "../configuration.h"
#include "../flooritemmanager.h"
@@ -36,7 +37,10 @@
#include "../map.h"
#include "../npc.h"
+#include "../resources/animation.h"
#include "../resources/monsterdb.h"
+#include "../resources/resourcemanager.h"
+#include "../resources/spriteset.h"
#include "../utils/tostring.h"
@@ -60,11 +64,35 @@ Viewport::Viewport():
config.addListener("ScrollRadius", this);
mPopupMenu = new PopupMenu();
+
+ // Load target cursors.
+ ResourceManager *resman = ResourceManager::getInstance();
+ Animation *animInRange = new Animation();
+ //Load animation frames into a spriteset, with each frame being 44x35
+ Spriteset *ssInRange = resman->getSpriteset("graphics/gui/target-cursor-blue.png", 44, 35);
+ for(int i = 0; i < 8; ++i)
+ {
+ //Have a delay of 75
+ animInRange->addFrame(ssInRange->get(i),75,0,0);
+ }
+ mTargetCursorInRange = new SimpleAnimation(animInRange);
+ Animation *animOutRange = new Animation();
+ //Load animation frames into a spriteset, with each frame being 44x35
+ Spriteset *ssOutRange = resman->getSpriteset("graphics/gui/target-cursor-red.png", 44, 35);
+ for(int j = 0; j < 8; ++j)
+ {
+ //Have a delay of 75
+ animOutRange->addFrame(ssOutRange->get(j),75,0,0);
+ }
+ mTargetCursorOutRange = new SimpleAnimation(animOutRange);
}
Viewport::~Viewport()
{
delete mPopupMenu;
+
+ delete mTargetCursorInRange;
+ delete mTargetCursorOutRange;
}
void
@@ -217,6 +245,39 @@ Viewport::draw(gcn::Graphics *gcnGraphics)
{
int mobId = target->mJob - 1002;
mobName = MonsterDB::get(mobId).getName();
+
+ // Find whether target is in range
+ int rangex = target->mX - player_node->mX;
+ int rangey = target->mY - player_node->mY;
+ int attackRange = player_node->getAttackRange();
+
+ // If either is negative, convert to positive
+ if (rangex < 0)
+ {
+ rangex = -rangex;
+ }
+ if (rangey < 0)
+ {
+ rangey = -rangey;
+ }
+
+ // Draw the target cursor, which one depends if the target is in range
+ if (rangex > attackRange || rangey > attackRange)
+ {
+ // Update animation frame and then draw the next image
+ mTargetCursorOutRange->update(10);
+ graphics->drawImage(mTargetCursorOutRange->getCurrentImage(),
+ target->getPixelX() - (int) mViewX,
+ target->getPixelY() - (int) mViewY);
+ }
+ else
+ {
+ // Update animation frame and then draw the next image
+ mTargetCursorInRange->update(10);
+ graphics->drawImage(mTargetCursorInRange->getCurrentImage(),
+ target->getPixelX() - (int) mViewX,
+ target->getPixelY() - (int) mViewY);
+ }
graphics->drawText(mobName,
target->getPixelX() - (int) mViewX + 15,
diff --git a/src/gui/viewport.h b/src/gui/viewport.h
index f1cadd98..45863228 100644
--- a/src/gui/viewport.h
+++ b/src/gui/viewport.h
@@ -35,6 +35,7 @@ class Being;
class FloorItem;
class Item;
class PopupMenu;
+class SimpleAnimation;
/**
* The viewport on the map. Displays the current map and handles mouse input
@@ -148,6 +149,12 @@ class Viewport : public WindowContainer, public gcn::MouseListener,
int mCameraX; /**< Current viewpoint in tiles. */
int mCameraY; /**< Current viewpoint in tiles. */
bool mShowDebugPath; /**< Show a path from player to pointer. */
+
+ /**
+ * Target animated cursor.
+ */
+ SimpleAnimation *mTargetCursorInRange;
+ SimpleAnimation *mTargetCursorOutRange;
bool mPlayerFollowMouse;
int mWalkTime;