aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/lua_api.txt6
-rw-r--r--src/content_cao.cpp8
-rw-r--r--src/content_cao.h1
-rw-r--r--src/content_sao.cpp24
-rw-r--r--src/content_sao.h5
-rw-r--r--src/genericobject.cpp9
-rw-r--r--src/genericobject.h3
-rw-r--r--src/script/lua_api/l_object.cpp44
-rw-r--r--src/script/lua_api/l_object.h6
9 files changed, 104 insertions, 2 deletions
diff --git a/doc/lua_api.txt b/doc/lua_api.txt
index 5a1d49d03..4c0baa5bc 100644
--- a/doc/lua_api.txt
+++ b/doc/lua_api.txt
@@ -2482,6 +2482,12 @@ This is basically a reference to a C++ `ServerActiveObject`
* `set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})`: defines offset value for camera per player
* in first person view
* in third person view (max. values `{x=-10/10,y=-10,15,z=-5/5}`)
+* `get_nametag_color()`
+ * returns the color of the nametag as table
+ * { a = 0...255, r = 0...255, g = 0...255, b = 0...255 }
+* `set_nametag_color(color)`
+ * sets the color of the nametag
+ * `color`: { a = 0...255, r = 0...255, g = 0...255, b = 0...255 }
### `InvRef`
An `InvRef` is a reference to an inventory.
diff --git a/src/content_cao.cpp b/src/content_cao.cpp
index a8b107b49..5bf4d8e9c 100644
--- a/src/content_cao.cpp
+++ b/src/content_cao.cpp
@@ -552,6 +552,7 @@ GenericCAO::GenericCAO(IGameDef *gamedef, ClientEnvironment *env):
m_animated_meshnode(NULL),
m_wield_meshnode(NULL),
m_spritenode(NULL),
+ m_nametag_color(video::SColor(255, 255, 255, 255)),
m_textnode(NULL),
m_position(v3f(0,10*BS,0)),
m_velocity(v3f(0,0,0)),
@@ -962,7 +963,7 @@ void GenericCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
gui::IGUIEnvironment* gui = irr->getGUIEnvironment();
std::wstring wname = narrow_to_wide(m_name);
m_textnode = smgr->addTextSceneNode(gui->getSkin()->getFont(),
- wname.c_str(), video::SColor(255,255,255,255), node);
+ wname.c_str(), m_nametag_color, node);
m_textnode->grab();
m_textnode->setPosition(v3f(0, BS*1.1, 0));
}
@@ -1714,6 +1715,11 @@ void GenericCAO::processMessage(const std::string &data)
int rating = readS16(is);
m_armor_groups[name] = rating;
}
+ } else if (cmd == GENERIC_CMD_SET_NAMETAG_COLOR) {
+ m_nametag_color = readARGB8(is);
+ if (m_textnode != NULL) {
+ m_textnode->setTextColor(m_nametag_color);
+ }
}
}
diff --git a/src/content_cao.h b/src/content_cao.h
index 31ccd04d4..36245bd3b 100644
--- a/src/content_cao.h
+++ b/src/content_cao.h
@@ -71,6 +71,7 @@ private:
scene::IAnimatedMeshSceneNode *m_animated_meshnode;
WieldMeshSceneNode *m_wield_meshnode;
scene::IBillboardSceneNode *m_spritenode;
+ video::SColor m_nametag_color;
scene::ITextSceneNode* m_textnode;
v3f m_position;
v3f m_velocity;
diff --git a/src/content_sao.cpp b/src/content_sao.cpp
index 51f074f7c..0aae7bbc2 100644
--- a/src/content_sao.cpp
+++ b/src/content_sao.cpp
@@ -715,6 +715,8 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
m_bone_position_sent(false),
m_attachment_parent_id(0),
m_attachment_sent(false),
+ m_nametag_color(video::SColor(255, 255, 255, 255)),
+ m_nametag_sent(false),
// public
m_physics_override_speed(1),
m_physics_override_jump(1),
@@ -801,7 +803,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
writeF1000(os, m_player->getYaw());
writeS16(os, getHP());
- writeU8(os, 5 + m_bone_position.size()); // number of messages stuffed in here
+ writeU8(os, 6 + m_bone_position.size()); // number of messages stuffed in here
os<<serializeLongString(getPropertyPacket()); // message 1
os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
os<<serializeLongString(gob_cmd_update_animation(m_animation_range, m_animation_speed, m_animation_blend)); // 3
@@ -812,6 +814,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
os<<serializeLongString(gob_cmd_update_physics_override(m_physics_override_speed,
m_physics_override_jump, m_physics_override_gravity, m_physics_override_sneak,
m_physics_override_sneak_glitch)); // 5
+ os << serializeLongString(gob_cmd_set_nametag_color(m_nametag_color)); // 6
}
else
{
@@ -965,6 +968,14 @@ void PlayerSAO::step(float dtime, bool send_recommended)
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push(aom);
}
+
+ if (m_nametag_sent == false) {
+ m_nametag_sent = true;
+ std::string str = gob_cmd_set_nametag_color(m_nametag_color);
+ // create message and add to list
+ ActiveObjectMessage aom(getId(), true, str);
+ m_messages_out.push(aom);
+ }
}
void PlayerSAO::setBasePosition(const v3f &position)
@@ -1144,6 +1155,17 @@ void PlayerSAO::notifyObjectPropertiesModified()
m_properties_sent = false;
}
+void PlayerSAO::setNametagColor(video::SColor color)
+{
+ m_nametag_color = color;
+ m_nametag_sent = false;
+}
+
+video::SColor PlayerSAO::getNametagColor()
+{
+ return m_nametag_color;
+}
+
Inventory* PlayerSAO::getInventory()
{
return m_inventory;
diff --git a/src/content_sao.h b/src/content_sao.h
index cc372ff55..4a8c70e16 100644
--- a/src/content_sao.h
+++ b/src/content_sao.h
@@ -197,6 +197,8 @@ public:
void setAttachment(int parent_id, std::string bone, v3f position, v3f rotation);
ObjectProperties* accessObjectProperties();
void notifyObjectPropertiesModified();
+ void setNametagColor(video::SColor color);
+ video::SColor getNametagColor();
/*
Inventory interface
@@ -313,6 +315,9 @@ private:
v3f m_attachment_rotation;
bool m_attachment_sent;
+ video::SColor m_nametag_color;
+ bool m_nametag_sent;
+
public:
float m_physics_override_speed;
float m_physics_override_jump;
diff --git a/src/genericobject.cpp b/src/genericobject.cpp
index 9a1b9d8d0..1f4f59e92 100644
--- a/src/genericobject.cpp
+++ b/src/genericobject.cpp
@@ -170,3 +170,12 @@ std::string gob_cmd_update_attachment(int parent_id, std::string bone, v3f posit
return os.str();
}
+std::string gob_cmd_set_nametag_color(video::SColor color)
+{
+ std::ostringstream os(std::ios::binary);
+ // command
+ writeU8(os, GENERIC_CMD_SET_NAMETAG_COLOR);
+ // parameters
+ writeARGB8(os, color);
+ return os.str();
+}
diff --git a/src/genericobject.h b/src/genericobject.h
index 29e5e29cb..854950d27 100644
--- a/src/genericobject.h
+++ b/src/genericobject.h
@@ -34,6 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define GENERIC_CMD_SET_BONE_POSITION 7
#define GENERIC_CMD_SET_ATTACHMENT 8
#define GENERIC_CMD_SET_PHYSICS_OVERRIDE 9
+#define GENERIC_CMD_SET_NAMETAG_COLOR 10
#include "object_properties.h"
std::string gob_cmd_set_properties(const ObjectProperties &prop);
@@ -72,5 +73,7 @@ std::string gob_cmd_update_bone_position(std::string bone, v3f position, v3f rot
std::string gob_cmd_update_attachment(int parent_id, std::string bone, v3f position, v3f rotation);
+std::string gob_cmd_set_nametag_color(video::SColor color);
+
#endif
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index d913019b1..c639a4834 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -1274,6 +1274,48 @@ int ObjectRef::l_override_day_night_ratio(lua_State *L)
return 1;
}
+// set_nametag_color(self, color)
+int ObjectRef::l_set_nametag_color(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ ObjectRef *ref = checkobject(L, 1);
+ PlayerSAO *playersao = getplayersao(ref);
+ if (playersao == NULL)
+ return 0;
+
+ video::SColor color(255,255,255,255);
+ if (!lua_isnil(L, 2))
+ color = readARGB8(L, 2);
+ playersao->setNametagColor(color);
+
+ lua_pushboolean(L, true);
+ return 1;
+}
+
+// get_nametag_color(self)
+int ObjectRef::l_get_nametag_color(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ ObjectRef *ref = checkobject(L, 1);
+ PlayerSAO *playersao = getplayersao(ref);
+ if (playersao == NULL)
+ return 0;
+
+ video::SColor color = playersao->getNametagColor();
+
+ lua_newtable(L);
+ lua_pushnumber(L, color.getAlpha());
+ lua_setfield(L, -2, "a");
+ lua_pushnumber(L, color.getRed());
+ lua_setfield(L, -2, "r");
+ lua_pushnumber(L, color.getGreen());
+ lua_setfield(L, -2, "g");
+ lua_pushnumber(L, color.getBlue());
+ lua_setfield(L, -2, "b");
+
+ return 1;
+}
+
ObjectRef::ObjectRef(ServerActiveObject *object):
m_object(object)
{
@@ -1396,5 +1438,7 @@ const luaL_reg ObjectRef::methods[] = {
luamethod(ObjectRef, override_day_night_ratio),
luamethod(ObjectRef, set_local_animation),
luamethod(ObjectRef, set_eye_offset),
+ luamethod(ObjectRef, set_nametag_color),
+ luamethod(ObjectRef, get_nametag_color),
{0,0}
};
diff --git a/src/script/lua_api/l_object.h b/src/script/lua_api/l_object.h
index daf91ce56..1f2931f29 100644
--- a/src/script/lua_api/l_object.h
+++ b/src/script/lua_api/l_object.h
@@ -240,6 +240,12 @@ private:
// set_eye_offset(self, v3f first pv, v3f third pv)
static int l_set_eye_offset(lua_State *L);
+ // set_nametag_color(self, color)
+ static int l_set_nametag_color(lua_State *L);
+
+ // get_nametag_color(self)
+ static int l_get_nametag_color(lua_State *L);
+
public:
ObjectRef(ServerActiveObject *object);