summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/being.h14
-rw-r--r--src/gui/viewport.cpp74
-rw-r--r--src/gui/viewport.h21
-rw-r--r--src/monster.cpp6
-rw-r--r--src/monster.h3
-rw-r--r--src/resources/monsterdb.cpp21
-rw-r--r--src/resources/monsterinfo.h11
7 files changed, 118 insertions, 32 deletions
diff --git a/src/being.h b/src/being.h
index a1f59c91..cdae05dc 100644
--- a/src/being.h
+++ b/src/being.h
@@ -93,6 +93,13 @@ class Being : public Sprite
VECTOREND_SPRITE
};
+ enum TargetCursorSize {
+ TC_SMALL = 0,
+ TC_MEDIUM,
+ TC_LARGE,
+ NUM_TC
+ };
+
/**
* Directions, to be used as bitmask values
@@ -362,6 +369,13 @@ class Being : public Sprite
virtual int
getHeight() const;
+ /**
+ * Returns the required size of a target cursor for this being
+ */
+ virtual Being::TargetCursorSize
+ getTargetCursorSize() const
+ { return TC_MEDIUM; }
+
std::auto_ptr<Equipment> mEquipment;
/**
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 3def2055..17b072cf 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -68,37 +68,63 @@ Viewport::Viewport():
mPopupMenu = new PopupMenu();
// Load target cursors
+ loadTargetCursor("graphics/gui/target-cursor-blue-s.png", 32, 25,
+ false, Being::TC_SMALL);
+ loadTargetCursor("graphics/gui/target-cursor-red-s.png", 32, 25,
+ true, Being::TC_SMALL);
+ loadTargetCursor("graphics/gui/target-cursor-blue-m.png", 44, 35,
+ false, Being::TC_MEDIUM);
+ loadTargetCursor("graphics/gui/target-cursor-red-m.png", 44, 35,
+ true, Being::TC_MEDIUM);
+ loadTargetCursor("graphics/gui/target-cursor-blue-l.png", 57, 45,
+ false, Being::TC_LARGE);
+ loadTargetCursor("graphics/gui/target-cursor-red-l.png", 57, 45,
+ 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();
- mInRangeImages = resman->getImageSet(
- "graphics/gui/target-cursor-blue.png", 44, 35);
- mOutRangeImages = resman->getImageSet(
- "graphics/gui/target-cursor-red.png", 44, 35);
- Animation *animInRange = new Animation();
- Animation *animOutRange = new Animation();
-
- for (unsigned int i = 0; i < mInRangeImages->size(); ++i)
+
+ currentImageSet = resman->getImageSet(filename, width, height);
+ Animation *anim = new Animation();
+ for (unsigned int i = 0; i < currentImageSet->size(); ++i)
{
- animInRange->addFrame(mInRangeImages->get(i), 75, 0, 0);
+ anim->addFrame(currentImageSet->get(i), 75, 0, 0);
}
+ currentCursor = new SimpleAnimation(anim);
- for (unsigned int j = 0; j < mOutRangeImages->size(); ++j)
+ if (outRange)
{
- animOutRange->addFrame(mOutRangeImages->get(j), 75, 0, 0);
+ mOutRangeImages[size] = currentImageSet;
+ mTargetCursorOutRange[size] = currentCursor;
+ }
+ else {
+ mInRangeImages[size] = currentImageSet;
+ mTargetCursorInRange[size] = currentCursor;
}
-
- mTargetCursorInRange = new SimpleAnimation(animInRange);
- mTargetCursorOutRange = new SimpleAnimation(animOutRange);
}
Viewport::~Viewport()
{
delete mPopupMenu;
- delete mTargetCursorInRange;
- delete mTargetCursorOutRange;
+ delete[] mTargetCursorInRange;
+ delete[] mTargetCursorOutRange;
- mInRangeImages->decRef();
- mOutRangeImages->decRef();
+ for (int i = Being::TC_SMALL; i < Being::NUM_TC; i++)
+ {
+ mInRangeImages[i]->decRef();
+ mOutRangeImages[i]->decRef();
+ }
}
void
@@ -262,8 +288,11 @@ Viewport::logic()
mWalkTime = player_node->mWalkTime;
}
- mTargetCursorInRange->update(10);
- mTargetCursorOutRange->update(10);
+ for(int i = 0; i < 3; i++)
+ {
+ mTargetCursorInRange[i]->update(10);
+ mTargetCursorOutRange[i]->update(10);
+ }
}
void
@@ -281,13 +310,14 @@ Viewport::drawTargetCursor(Graphics *graphics)
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->getCurrentImage();
+ targetCursor = mTargetCursorOutRange[cursorSize]->getCurrentImage();
}
else {
- targetCursor = mTargetCursorInRange->getCurrentImage();
+ targetCursor = mTargetCursorInRange[cursorSize]->getCurrentImage();
}
// Draw the target cursor at the correct position
diff --git a/src/gui/viewport.h b/src/gui/viewport.h
index 84efeff3..a0f69407 100644
--- a/src/gui/viewport.h
+++ b/src/gui/viewport.h
@@ -29,9 +29,9 @@
#include "windowcontainer.h"
#include "../configlistener.h"
+#include "../being.h"
class Map;
-class Being;
class FloorItem;
class ImageSet;
class Item;
@@ -142,6 +142,13 @@ class Viewport : public WindowContainer, public gcn::MouseListener,
void showPopup(int x, int y, Being *being);
/**
+ * 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
@@ -164,14 +171,10 @@ class Viewport : public WindowContainer, public gcn::MouseListener,
int mCameraY; /**< Current viewpoint in tiles. */
bool mShowDebugPath; /**< Show a path from player to pointer. */
- ImageSet *mInRangeImages; /**< Images of in range target cursor. */
- ImageSet *mOutRangeImages; /**< Images of out of range target cursor.*/
-
- /** Animated in range target cursor. */
- SimpleAnimation *mTargetCursorInRange;
-
- /** Animated out of range target cursor. */
- SimpleAnimation *mTargetCursorOutRange;
+ ImageSet *mInRangeImages[Being::NUM_TC]; /**< Images of in range target cursor. */
+ ImageSet *mOutRangeImages[Being::NUM_TC]; /**< Images of out of range target cursor.*/
+ SimpleAnimation *mTargetCursorInRange[Being::NUM_TC]; /**< Animated in range target cursor. */
+ SimpleAnimation *mTargetCursorOutRange[Being::NUM_TC];/**< Animated out of range target cursor. */
bool mPlayerFollowMouse;
int mWalkTime;
diff --git a/src/monster.cpp b/src/monster.cpp
index c20e12d0..687fe625 100644
--- a/src/monster.cpp
+++ b/src/monster.cpp
@@ -103,6 +103,12 @@ Monster::handleAttack(Being *victim, int damage)
sound.playSfx(mi.getSound((damage > 0) ? EVENT_HIT : EVENT_MISS));
}
+Being::TargetCursorSize
+Monster::getTargetCursorSize() const
+{
+ return getInfo().getTargetCursorSize();
+}
+
const MonsterInfo&
Monster::getInfo() const
{
diff --git a/src/monster.h b/src/monster.h
index 0e0e1af5..4a24068f 100644
--- a/src/monster.h
+++ b/src/monster.h
@@ -39,6 +39,9 @@ class Monster : public Being
virtual Type getType() const;
+ virtual TargetCursorSize
+ getTargetCursorSize() const;
+
/**
* Handles an attack of another being by this monster. Plays a hit or
* miss sound when appropriate.
diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp
index ac3ac3bc..89afc549 100644
--- a/src/resources/monsterdb.cpp
+++ b/src/resources/monsterdb.cpp
@@ -83,6 +83,27 @@ MonsterDB::load()
currentInfo->setName (XML::getProperty(monsterNode, "name", "unnamed"));
+ std::string targetCursor;
+ targetCursor = XML::getProperty(monsterNode, "targetCursor", "medium");
+ if (targetCursor == "small")
+ {
+ currentInfo->setTargetCursorSize(Being::TC_SMALL);
+ }
+ else if (targetCursor == "medium")
+ {
+ currentInfo->setTargetCursorSize(Being::TC_MEDIUM);
+ }
+ else if (targetCursor == "large")
+ {
+ currentInfo->setTargetCursorSize(Being::TC_LARGE);
+ }
+ else
+ {
+ logger->log("MonsterDB: Unknown target cursor type \"%s\" for %s - using medium sized one",
+ targetCursor.c_str(), currentInfo->getName().c_str());
+ currentInfo->setTargetCursorSize(Being::TC_MEDIUM);
+ }
+
//iterate <sprite>s and <sound>s
for_each_xml_child_node(spriteNode, monsterNode)
{
diff --git a/src/resources/monsterinfo.h b/src/resources/monsterinfo.h
index b65237da..5a820659 100644
--- a/src/resources/monsterinfo.h
+++ b/src/resources/monsterinfo.h
@@ -28,6 +28,8 @@
#include <string>
#include <vector>
+#include "../being.h"
+
enum SoundEvent
{
@@ -63,6 +65,10 @@ class MonsterInfo
setSprite(std::string filename) { mSprite = filename; }
void
+ setTargetCursorSize(Being::TargetCursorSize targetCursorSize)
+ { mTargetCursorSize = targetCursorSize; }
+
+ void
addSound(SoundEvent event, std::string filename);
const std::string&
@@ -71,13 +77,16 @@ class MonsterInfo
const std::string&
getSprite() const { return mSprite; }
+ const Being::TargetCursorSize
+ getTargetCursorSize() const { return mTargetCursorSize; }
+
std::string
getSound(SoundEvent event) const;
private:
std::string mName;
std::string mSprite;
-
+ Being::TargetCursorSize mTargetCursorSize;
std::map<SoundEvent, std::vector<std::string>* > mSounds;
};