From 86a963caca9604ad57904e9acd9bef7c46ca47d8 Mon Sep 17 00:00:00 2001 From: TeTpaAka Date: Thu, 14 May 2015 15:54:54 +0200 Subject: Add get and set functions for the nametag color --- doc/lua_api.txt | 6 ++++++ src/content_cao.cpp | 8 +++++++- src/content_cao.h | 1 + src/content_sao.cpp | 24 +++++++++++++++++++++- src/content_sao.h | 5 +++++ src/genericobject.cpp | 9 +++++++++ src/genericobject.h | 3 +++ src/script/lua_api/l_object.cpp | 44 +++++++++++++++++++++++++++++++++++++++++ src/script/lua_api/l_object.h | 6 ++++++ 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<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); -- cgit v1.2.3