summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/being.h5
-rw-r--r--src/player.cpp31
-rw-r--r--src/player.h6
3 files changed, 29 insertions, 13 deletions
diff --git a/src/being.h b/src/being.h
index a870ff0b..72c0d8b2 100644
--- a/src/being.h
+++ b/src/being.h
@@ -30,6 +30,7 @@
#include <string>
#include <vector>
+#include "configlistener.h"
#include "map.h"
#include "particlecontainer.h"
#include "position.h"
@@ -68,7 +69,7 @@ enum Gender
GENDER_UNSPECIFIED = 2
};
-class Being : public Sprite
+class Being : public Sprite, public ConfigListener
{
public:
enum Type
@@ -509,6 +510,8 @@ class Being : public Sprite
static void load();
+ void optionChanged(const std::string &value) {}
+
protected:
/**
* Sets the new path for this being.
diff --git a/src/player.cpp b/src/player.cpp
index 14a9c97f..abc01152 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -44,10 +44,12 @@ Player::Player(int id, int job, Map *map):
mIsGM(false),
mInParty(false)
{
+ config.addListener("visiblenames", this);
}
Player::~Player()
{
+ config.removeListener("visiblenames", this);
delete mName;
}
@@ -135,18 +137,6 @@ void Player::logic()
break;
}
- if (getType() == Being::PLAYER && player_node != this)
- {
- if (!config.getValue("visiblenames", 1) && mName)
- {
- delete mName;
- mName = NULL;
- }
- else if (config.getValue("visiblenames", 1) && !mName && !(getName().empty()))
- {
- setName(getName());
- }
- }
Being::logic();
}
#endif
@@ -296,3 +286,20 @@ void Player::setInParty(bool value)
{
mInParty = value;
}
+
+void Player::optionChanged(const std::string &value)
+{
+ if (value == "visiblenames" && getType() == Being::PLAYER && player_node != this)
+ {
+ bool value = config.getValue("visiblenames", 1);
+ if (!value && mName)
+ {
+ delete mName;
+ mName = NULL;
+ }
+ else if (value && !mName && !(getName().empty()))
+ {
+ setName(getName());
+ }
+ }
+}
diff --git a/src/player.h b/src/player.h
index dfcca310..07701528 100644
--- a/src/player.h
+++ b/src/player.h
@@ -135,6 +135,12 @@ class Player : public Being
virtual unsigned char getWalkMask() const
{ return 0x82; } // blocked by walls and monsters (bin 1000 0010)
+ /**
+ * Called when a option (set with config.addListener()) is changed
+ */
+
+ void optionChanged(const std::string &value);
+
protected:
/**
* Gets the way the monster blocks pathfinding for other objects.