diff --git a/src/client/camera.cpp b/src/client/camera.cpp index 922b588001..f3e6d504c9 100644 --- a/src/client/camera.cpp +++ b/src/client/camera.cpp @@ -635,7 +635,9 @@ void Camera::drawNametags() // the user's font size preference... const u32 default_font_size = 16; // ...by multiplying this in. - const float font_size_mult = g_fontengine->getFontSize(FM_Unspecified) / (float)default_font_size; + const f32 font_size_mult = g_fontengine->getFontSize(FM_Unspecified) / (float)default_font_size; + // Minimum distance until z-scaled nametags actually become smaller + const f32 minimum_d = 1.0f * BS; video::IVideoDriver *driver = RenderingEngine::get_video_driver(); v2u32 screensize = driver->getScreenSize(); @@ -654,8 +656,10 @@ void Camera::drawNametags() // Higher default since nametag should be reasonably visible // even at distance. u32 base_size = nametag->textsize.value_or(default_font_size * 4); + f32 adjusted_d = std::max(transformed_pos[3] - minimum_d, 0.0f); + f32 adjusted_zDiv = adjusted_d == 0.0f ? 1.0f : (1.0f / adjusted_d); font_size = myround(font_size_mult * - rangelim(base_size * BS * zDiv, 0, base_size)); + rangelim(base_size * BS * adjusted_zDiv, 0, base_size)); } else { font_size = myround(font_size_mult * nametag->textsize.value_or(default_font_size)); } diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index bdb6888335..cd53781ab5 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -582,20 +582,16 @@ void push_object_properties(lua_State *L, const ObjectProperties *prop) lua_setfield(L, -2, "nametag"); push_ARGB8(L, prop->nametag_color); lua_setfield(L, -2, "nametag_color"); - if (prop->nametag_bgcolor) { + if (prop->nametag_bgcolor) push_ARGB8(L, prop->nametag_bgcolor.value()); - lua_setfield(L, -2, "nametag_bgcolor"); - } else { + else lua_pushboolean(L, false); - lua_setfield(L, -2, "nametag_bgcolor"); - } - if (prop->nametag_fontsize) { + lua_setfield(L, -2, "nametag_bgcolor"); + if (prop->nametag_fontsize) lua_pushinteger(L, prop->nametag_fontsize.value()); - lua_setfield(L, -2, "nametag_fontsize"); - } else { + else lua_pushboolean(L, false); - lua_setfield(L, -2, "nametag_fontsize"); - } + lua_setfield(L, -2, "nametag_fontsize"); lua_pushboolean(L, prop->nametag_scale_z); lua_setfield(L, -2, "nametag_scale_z"); lua_pushlstring(L, prop->infotext.c_str(), prop->infotext.size());