summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/beinginfo.cpp59
-rw-r--r--src/resources/beinginfo.h10
-rw-r--r--src/resources/monsterdb.cpp4
-rw-r--r--src/resources/npcdb.cpp4
4 files changed, 61 insertions, 16 deletions
diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp
index da65355a..e76cb8e3 100644
--- a/src/resources/beinginfo.cpp
+++ b/src/resources/beinginfo.cpp
@@ -26,42 +26,73 @@
#include "utils/gettext.h"
+#include <optional>
+
BeingInfo *BeingInfo::Unknown = new BeingInfo;
+static std::optional<ActorSprite::TargetCursorSize> targetCursorSizeFromString(const std::string &cursor)
+{
+ if (cursor == "small") return ActorSprite::TC_SMALL;
+ if (cursor == "medium") return ActorSprite::TC_MEDIUM;
+ if (cursor == "large") return ActorSprite::TC_LARGE;
+
+ return {};
+}
+
+static std::optional<Cursor> cursorFromString(const std::string &cursor)
+{
+ if (cursor == "pointer") return Cursor::POINTER;
+ if (cursor == "attack") return Cursor::FIGHT;
+ if (cursor == "pickup") return Cursor::PICKUP;
+ if (cursor == "talk") return Cursor::TALK;
+ if (cursor == "action") return Cursor::ACTION;
+ if (cursor == "left") return Cursor::LEFT;
+ if (cursor == "up") return Cursor::UP;
+ if (cursor == "right") return Cursor::RIGHT;
+ if (cursor == "down") return Cursor::DOWN;
+
+ return {};
+}
+
BeingInfo::BeingInfo():
mName(_("unnamed")),
- mWalkMask(Map::BLOCKMASK_WALL | Map::BLOCKMASK_CHARACTER
- | Map::BLOCKMASK_MONSTER)
+ mWalkMask(Map::BLOCKMASK_WALL | Map::BLOCKMASK_CHARACTER | Map::BLOCKMASK_MONSTER)
{
SpriteDisplay display;
SpriteReference errorSprite(paths.getStringValue("spriteErrorFile"), 0);
display.sprites.push_back(errorSprite);
- setDisplay(display);
+ setDisplay(std::move(display));
}
BeingInfo::~BeingInfo() = default;
void BeingInfo::setDisplay(SpriteDisplay display)
{
- mDisplay = display;
+ mDisplay = std::move(display);
}
void BeingInfo::setTargetCursorSize(const std::string &size)
{
- if (size == "small")
- setTargetCursorSize(ActorSprite::TC_SMALL);
- else if (size == "medium")
- setTargetCursorSize(ActorSprite::TC_MEDIUM);
- else if (size == "large")
- setTargetCursorSize(ActorSprite::TC_LARGE);
- else
+ const auto targetCursorSize = targetCursorSizeFromString(size);
+ if (!targetCursorSize)
+ {
+ logger->log("Unknown targetCursor value \"%s\" for %s",
+ size.c_str(), getName().c_str());
+ }
+ setTargetCursorSize(targetCursorSize.value_or(ActorSprite::TC_MEDIUM));
+}
+
+void BeingInfo::setHoverCursor(const std::string &cursorName)
+{
+ const auto cursor = cursorFromString(cursorName);
+ if (!cursor)
{
- logger->log("Unknown target cursor type \"%s\" for %s - using medium "
- "sized one", size.c_str(), getName().c_str());
- setTargetCursorSize(ActorSprite::TC_MEDIUM);
+ logger->log("Unknown hoverCursor value \"%s\" for %s",
+ cursorName.c_str(), getName().c_str());
}
+ setHoverCursor(cursor.value_or(Cursor::POINTER));
}
void BeingInfo::addSound(SoundEvent event, const std::string &filename)
diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h
index e2d11c93..a4736439 100644
--- a/src/resources/beinginfo.h
+++ b/src/resources/beinginfo.h
@@ -24,6 +24,7 @@
#include "actorsprite.h"
+#include "gui/gui.h"
#include "resources/spritedef.h"
#include <map>
@@ -81,6 +82,14 @@ class BeingInfo
ActorSprite::TargetCursorSize getTargetCursorSize() const
{ return mTargetCursorSize; }
+ void setHoverCursor(const std::string &cursorName);
+
+ void setHoverCursor(Cursor cursor)
+ { mHoverCursor = cursor; }
+
+ Cursor getHoverCursor() const
+ { return mHoverCursor; }
+
void addSound(SoundEvent event, const std::string &filename);
const std::string &getSound(SoundEvent event) const;
@@ -108,6 +117,7 @@ class BeingInfo
SpriteDisplay mDisplay;
std::string mName;
ActorSprite::TargetCursorSize mTargetCursorSize = ActorSprite::TC_MEDIUM;
+ Cursor mHoverCursor = Cursor::POINTER;
std::map<SoundEvent, std::vector<std::string>> mSounds;
std::map<int, Attack> mAttacks;
unsigned char mWalkMask;
diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp
index fa1ac5af..fc860958 100644
--- a/src/resources/monsterdb.cpp
+++ b/src/resources/monsterdb.cpp
@@ -79,6 +79,8 @@ void MonsterDB::readMonsterNode(xmlNodePtr node, const std::string &filename)
currentInfo->setTargetCursorSize(XML::getProperty(node,
"targetCursor", "medium"));
+ currentInfo->setHoverCursor(XML::getProperty(node, "hoverCursor", "attack"));
+
SpriteDisplay display;
//iterate <sprite>s and <sound>s
@@ -147,7 +149,7 @@ void MonsterDB::readMonsterNode(xmlNodePtr node, const std::string &filename)
(const char*) spriteNode->xmlChildrenNode->content);
}
}
- currentInfo->setDisplay(display);
+ currentInfo->setDisplay(std::move(display));
mMonsterInfos[XML::getProperty(node, "id", 0) + mMonsterIdOffset] = currentInfo;
}
diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp
index 6a0685d2..83d91b20 100644
--- a/src/resources/npcdb.cpp
+++ b/src/resources/npcdb.cpp
@@ -55,6 +55,8 @@ void NPCDB::readNPCNode(xmlNodePtr node, const std::string &filename)
currentInfo->setTargetCursorSize(XML::getProperty(node,
"targetCursor", "medium"));
+ currentInfo->setHoverCursor(XML::getProperty(node, "hoverCursor", "talk"));
+
SpriteDisplay display;
for_each_xml_child_node(spriteNode, node)
{
@@ -72,7 +74,7 @@ void NPCDB::readNPCNode(xmlNodePtr node, const std::string &filename)
}
}
- currentInfo->setDisplay(display);
+ currentInfo->setDisplay(std::move(display));
mNPCInfos[id] = currentInfo;
}