@@ -79,6 +79,7 @@ Camera::Camera(MapDrawControl &draw_control, Client *client):
7979 m_cache_fov = std::fmax (g_settings->getFloat (" fov" ), 45 .0f );
8080 m_arm_inertia = g_settings->getBool (" arm_inertia" );
8181 m_nametags.clear ();
82+ m_show_nametag_backgrounds = g_settings->getBool (" show_nametag_backgrounds" );
8283}
8384
8485Camera::~Camera ()
@@ -696,18 +697,14 @@ void Camera::drawNametags()
696697 v2u32 screensize = driver->getScreenSize ();
697698
698699 for (const Nametag *nametag : m_nametags) {
699- if (nametag->nametag_color .getAlpha () == 0 ) {
700- // Enforce hiding nametag,
701- // because if freetype is enabled, a grey
702- // shadow can remain.
703- continue ;
704- }
705- v3f pos = nametag->parent_node ->getAbsolutePosition () + nametag->nametag_pos * BS;
700+ // Nametags are hidden in GenericCAO::updateNametag()
701+
702+ v3f pos = nametag->parent_node ->getAbsolutePosition () + nametag->pos * BS;
706703 f32 transformed_pos[4 ] = { pos.X , pos.Y , pos.Z , 1 .0f };
707704 trans.multiplyWith1x4Matrix (transformed_pos);
708705 if (transformed_pos[3 ] > 0 ) {
709706 std::wstring nametag_colorless =
710- unescape_translate (utf8_to_wide (nametag->nametag_text ));
707+ unescape_translate (utf8_to_wide (nametag->text ));
711708 core::dimension2d<u32 > textsize = font->getDimension (
712709 nametag_colorless.c_str ());
713710 f32 zDiv = transformed_pos[3 ] == 0 .0f ? 1 .0f :
@@ -720,26 +717,22 @@ void Camera::drawNametags()
720717 core::rect<s32> size (0 , 0 , textsize.Width , textsize.Height );
721718 core::rect<s32> bg_size (-2 , 0 , textsize.Width +2 , textsize.Height );
722719
723- video::SColor textColor = nametag->nametag_color ;
724-
725- bool darkBackground = textColor.getLuminance () > 186 ;
726- video::SColor backgroundColor = darkBackground
727- ? video::SColor (50 , 50 , 50 , 50 )
728- : video::SColor (50 , 255 , 255 , 255 );
729- driver->draw2DRectangle (backgroundColor, bg_size + screen_pos);
720+ auto bgcolor = nametag->getBgColor (m_show_nametag_backgrounds);
721+ if (bgcolor.getAlpha () != 0 )
722+ driver->draw2DRectangle (bgcolor, bg_size + screen_pos);
730723
731724 font->draw (
732- translate_string (utf8_to_wide (nametag->nametag_text )).c_str (),
733- size + screen_pos, textColor );
725+ translate_string (utf8_to_wide (nametag->text )).c_str (),
726+ size + screen_pos, nametag-> textcolor );
734727 }
735728 }
736729}
737730
738731Nametag *Camera::addNametag (scene::ISceneNode *parent_node,
739- const std::string &nametag_text , video::SColor nametag_color ,
740- const v3f &pos)
732+ const std::string &text , video::SColor textcolor ,
733+ Optional<video::SColor> bgcolor, const v3f &pos)
741734{
742- Nametag *nametag = new Nametag (parent_node, nametag_text, nametag_color , pos);
735+ Nametag *nametag = new Nametag (parent_node, text, textcolor, bgcolor , pos);
743736 m_nametags.push_back (nametag);
744737 return nametag;
745738}
0 commit comments