From 18c2f16c138f4b40b4705507b46d24e1518e4705 Mon Sep 17 00:00:00 2001 From: TeTpaAka Date: Fri, 15 May 2015 21:46:56 +0200 Subject: [PATCH] Generalize core.get/set_nametag_color into core.get/set_nametag_attributes --- doc/lua_api.txt | 17 +++++++++++------ src/content_cao.cpp | 3 ++- src/content_sao.cpp | 4 ++-- src/genericobject.cpp | 5 +++-- src/genericobject.h | 4 ++-- src/script/lua_api/l_object.cpp | 21 ++++++++++++--------- src/script/lua_api/l_object.h | 8 ++++---- 7 files changed, 36 insertions(+), 26 deletions(-) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 8ade48b7b..0cc83bf69 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -2491,12 +2491,17 @@ 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 } +* `get_nametag_attributes()` + * returns a table with the attributes of the nametag of the player + * { + color = { a = 0...255, r = 0...255, g = 0...255, b = 0...255 } + } +* `set_nametag_attributes(attributes)` + * sets the attributes of the nametag of the player + * `attributes`: + { + 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 5bf4d8e9c..fe560a41a 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -1715,7 +1715,8 @@ void GenericCAO::processMessage(const std::string &data) int rating = readS16(is); m_armor_groups[name] = rating; } - } else if (cmd == GENERIC_CMD_SET_NAMETAG_COLOR) { + } else if (cmd == GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES) { + u8 version = readU8(is); // forward compatibility m_nametag_color = readARGB8(is); if (m_textnode != NULL) { m_textnode->setTextColor(m_nametag_color); diff --git a/src/content_sao.cpp b/src/content_sao.cpp index c7f4b60c7..1f7323c9c 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -814,7 +814,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version) os<getNametagColor(); + lua_getfield(L, 2, "color"); + if (!lua_isnil(L, -1)) + color = readARGB8(L, -1); playersao->setNametagColor(color); lua_pushboolean(L, true); return 1; } -// get_nametag_color(self) -int ObjectRef::l_get_nametag_color(lua_State *L) +// get_nametag_attributes(self) +int ObjectRef::l_get_nametag_attributes(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); @@ -1303,6 +1304,7 @@ int ObjectRef::l_get_nametag_color(lua_State *L) video::SColor color = playersao->getNametagColor(); + lua_newtable(L); lua_newtable(L); lua_pushnumber(L, color.getAlpha()); lua_setfield(L, -2, "a"); @@ -1312,6 +1314,7 @@ int ObjectRef::l_get_nametag_color(lua_State *L) lua_setfield(L, -2, "g"); lua_pushnumber(L, color.getBlue()); lua_setfield(L, -2, "b"); + lua_setfield(L, -2, "color"); return 1; } @@ -1438,7 +1441,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), + luamethod(ObjectRef, set_nametag_attributes), + luamethod(ObjectRef, get_nametag_attributes), {0,0} }; diff --git a/src/script/lua_api/l_object.h b/src/script/lua_api/l_object.h index 1f2931f29..af3ed5ef0 100644 --- a/src/script/lua_api/l_object.h +++ b/src/script/lua_api/l_object.h @@ -240,11 +240,11 @@ 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); + // set_nametag_attributes(self, attributes) + static int l_set_nametag_attributes(lua_State *L); - // get_nametag_color(self) - static int l_get_nametag_color(lua_State *L); + // get_nametag_attributes(self) + static int l_get_nametag_attributes(lua_State *L); public: ObjectRef(ServerActiveObject *object); -- 2.25.1