summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-01-31 15:36:56 +0300
committerAndrei Karas <akaras@inbox.ru>2013-01-31 21:56:05 +0300
commit3a54cf61c4ea127a16ca11c515906a5f419b97df (patch)
tree7b330747d4357c95791f578eeda0356c8649e614
parent741630d53aa385f192edb40ac27b00844285eac8 (diff)
downloadmanaplus-3a54cf61c4ea127a16ca11c515906a5f419b97df.tar.gz
manaplus-3a54cf61c4ea127a16ca11c515906a5f419b97df.tar.bz2
manaplus-3a54cf61c4ea127a16ca11c515906a5f419b97df.tar.xz
manaplus-3a54cf61c4ea127a16ca11c515906a5f419b97df.zip
Add default avatars support for npcs.
-rw-r--r--src/gui/npcdialog.cpp9
-rw-r--r--src/resources/beinginfo.cpp3
-rw-r--r--src/resources/beinginfo.h7
-rw-r--r--src/resources/npcdb.cpp10
-rw-r--r--src/resources/npcdb.h4
5 files changed, 32 insertions, 1 deletions
diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp
index fa4162f81..df534c8e0 100644
--- a/src/gui/npcdialog.cpp
+++ b/src/gui/npcdialog.cpp
@@ -22,6 +22,7 @@
#include "gui/npcdialog.h"
+#include "actorspritemanager.h"
#include "being.h"
#include "configuration.h"
#include "client.h"
@@ -42,6 +43,7 @@
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/textbox.h"
+#include "resources/npcdb.h"
#include "resources/resourcemanager.h"
#include "net/net.h"
@@ -166,6 +168,13 @@ NpcDialog::NpcDialog(const int npcId) :
enableVisibleSound(true);
sound.playGuiSound(SOUND_SHOW_WINDOW);
+ if (actorSpriteManager)
+ {
+ const Being *const being = actorSpriteManager->findBeing(mNpcId);
+ if (being)
+ showAvatar(NPCDB::getAvatarFor(being->getSubType()));
+ }
+
config.addListener("logNpcInGui", this);
}
diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp
index c5c36b209..905d28921 100644
--- a/src/resources/beinginfo.cpp
+++ b/src/resources/beinginfo.cpp
@@ -48,7 +48,8 @@ BeingInfo::BeingInfo() :
mStaticMaxHP(false),
mTargetSelection(true),
mSortOffsetY(0),
- mDeadSortOffsetY(31)
+ mDeadSortOffsetY(31),
+ mAvatarId(0)
{
SpriteDisplay display;
display.sprites.push_back(SpriteReference::Empty);
diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h
index 0e544a3b6..f1b978543 100644
--- a/src/resources/beinginfo.h
+++ b/src/resources/beinginfo.h
@@ -187,6 +187,12 @@ class BeingInfo final
void setDeadSortOffsetY(const int n)
{ mDeadSortOffsetY = n; }
+ uint16_t getAvatarId() const A_WARN_UNUSED
+ { return mAvatarId; }
+
+ void setAvatarId(const uint16_t id)
+ { mAvatarId = id; }
+
static void init();
static void clear();
@@ -207,6 +213,7 @@ class BeingInfo final
bool mTargetSelection;
int mSortOffsetY;
int mDeadSortOffsetY;
+ uint16_t mAvatarId;
};
typedef std::map<int, BeingInfo*> BeingInfos;
diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp
index 07549eb03..f8e1e2340 100644
--- a/src/resources/npcdb.cpp
+++ b/src/resources/npcdb.cpp
@@ -95,6 +95,8 @@ void NPCDB::load()
currentInfo->setDeadSortOffsetY(XML::getProperty(npcNode,
"deadSortOffsetY", 31));
+ currentInfo->setAvatarId(XML::getProperty(npcNode, "avatar", 0));
+
SpriteDisplay display;
for_each_xml_child_node(spriteNode, npcNode)
{
@@ -148,3 +150,11 @@ BeingInfo *NPCDB::get(const int id)
return i->second;
}
}
+
+uint16_t NPCDB::getAvatarFor(const int id)
+{
+ BeingInfo *const info = get(id);
+ if (!info)
+ return 0;
+ return info->getAvatarId();
+}
diff --git a/src/resources/npcdb.h b/src/resources/npcdb.h
index 8f3d5650c..61641eaec 100644
--- a/src/resources/npcdb.h
+++ b/src/resources/npcdb.h
@@ -23,6 +23,8 @@
#ifndef NPC_DB_H
#define NPC_DB_H
+#include <stdint.h>
+
#include "localconsts.h"
class BeingInfo;
@@ -37,6 +39,8 @@ namespace NPCDB
void unload();
BeingInfo *get(const int id) A_WARN_UNUSED;
+
+ uint16_t getAvatarFor(const int id);
}
#endif