aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_object.cpp
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2021-02-17 19:51:28 +0000
committerGitHub <noreply@github.com>2021-02-17 19:51:28 +0000
commitf85e9ab9254e2ae4ac13170f9edea00fb8d931a2 (patch)
tree43fa19520c7f744f798de0ed8bcbb8e01c82e327 /src/script/lua_api/l_object.cpp
parenta8f6befd398cb8f962f3bb1fab092d6355bfe015 (diff)
downloadminetest-f85e9ab9254e2ae4ac13170f9edea00fb8d931a2.tar.gz
minetest-f85e9ab9254e2ae4ac13170f9edea00fb8d931a2.tar.bz2
minetest-f85e9ab9254e2ae4ac13170f9edea00fb8d931a2.zip
Add nametag background setting and object property (#10937)
Diffstat (limited to 'src/script/lua_api/l_object.cpp')
-rw-r--r--src/script/lua_api/l_object.cpp29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index 07aa3f7c9..8ae99b929 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -737,6 +737,18 @@ int ObjectRef::l_set_nametag_attributes(lua_State *L)
}
lua_pop(L, 1);
+ lua_getfield(L, -1, "bgcolor");
+ if (!lua_isnil(L, -1)) {
+ if (lua_toboolean(L, -1)) {
+ video::SColor color;
+ if (read_color(L, -1, &color))
+ prop->nametag_bgcolor = color;
+ } else {
+ prop->nametag_bgcolor = nullopt;
+ }
+ }
+ lua_pop(L, 1);
+
std::string nametag = getstringfield_default(L, 2, "text", "");
prop->nametag = nametag;
@@ -758,13 +770,24 @@ int ObjectRef::l_get_nametag_attributes(lua_State *L)
if (!prop)
return 0;
- video::SColor color = prop->nametag_color;
-
lua_newtable(L);
- push_ARGB8(L, color);
+
+ push_ARGB8(L, prop->nametag_color);
lua_setfield(L, -2, "color");
+
+ if (prop->nametag_bgcolor) {
+ push_ARGB8(L, prop->nametag_bgcolor.value());
+ lua_setfield(L, -2, "bgcolor");
+ } else {
+ lua_pushboolean(L, false);
+ lua_setfield(L, -2, "bgcolor");
+ }
+
lua_pushstring(L, prop->nametag.c_str());
lua_setfield(L, -2, "text");
+
+
+
return 1;
}