]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/client/camera.cpp
Remove unused ITextSceneNode header (#11476)
[dragonfireclient.git] / src / client / camera.cpp
index 9a08254b42e450953ffaec8d705b25ebb9b7a018..2629a63590e4f3ad805d694d13cf15f607aa4c6d 100644 (file)
@@ -43,11 +43,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #define WIELDMESH_AMPLITUDE_X 7.0f
 #define WIELDMESH_AMPLITUDE_Y 10.0f
 
-Camera::Camera(MapDrawControl &draw_control, Client *client):
+Camera::Camera(MapDrawControl &draw_control, Client *client, RenderingEngine *rendering_engine):
        m_draw_control(draw_control),
        m_client(client)
 {
-       scene::ISceneManager *smgr = RenderingEngine::get_scene_manager();
+       auto smgr = rendering_engine->get_scene_manager();
        // note: making the camera node a child of the player node
        // would lead to unexpected behaviour, so we don't do that.
        m_playernode = smgr->addEmptySceneNode(smgr->getRootSceneNode());
@@ -79,6 +79,7 @@ Camera::Camera(MapDrawControl &draw_control, Client *client):
        m_cache_fov                 = std::fmax(g_settings->getFloat("fov"), 45.0f);
        m_arm_inertia               = g_settings->getBool("arm_inertia");
        m_nametags.clear();
+       m_show_nametag_backgrounds  = g_settings->getBool("show_nametag_backgrounds");
 }
 
 Camera::~Camera()
@@ -540,7 +541,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r
        m_curr_fov_degrees = rangelim(m_curr_fov_degrees, 1.0f, 160.0f);
 
        // FOV and aspect ratio
-       const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize();
+       const v2u32 &window_size = RenderingEngine::getWindowSize();
        m_aspect = (f32) window_size.X / (f32) window_size.Y;
        m_fov_y = m_curr_fov_degrees * M_PI / 180.0;
        // Increase vertical FOV on lower aspect ratios (<16:10)
@@ -663,7 +664,7 @@ void Camera::wield(const ItemStack &item)
 void Camera::drawWieldedTool(irr::core::matrix4* translation)
 {
        // Clear Z buffer so that the wielded tool stays in front of world geometry
-       m_wieldmgr->getVideoDriver()->clearZBuffer();
+       m_wieldmgr->getVideoDriver()->clearBuffers(video::ECBF_DEPTH);
 
        // Draw the wielded node (in a separate scene manager)
        scene::ICameraSceneNode* cam = m_wieldmgr->getActiveCamera();
@@ -696,18 +697,14 @@ void Camera::drawNametags()
        v2u32 screensize = driver->getScreenSize();
 
        for (const Nametag *nametag : m_nametags) {
-               if (nametag->nametag_color.getAlpha() == 0) {
-                       // Enforce hiding nametag,
-                       // because if freetype is enabled, a grey
-                       // shadow can remain.
-                       continue;
-               }
-               v3f pos = nametag->parent_node->getAbsolutePosition() + nametag->nametag_pos * BS;
+               // Nametags are hidden in GenericCAO::updateNametag()
+
+               v3f pos = nametag->parent_node->getAbsolutePosition() + nametag->pos * BS;
                f32 transformed_pos[4] = { pos.X, pos.Y, pos.Z, 1.0f };
                trans.multiplyWith1x4Matrix(transformed_pos);
                if (transformed_pos[3] > 0) {
                        std::wstring nametag_colorless =
-                               unescape_translate(utf8_to_wide(nametag->nametag_text));
+                               unescape_translate(utf8_to_wide(nametag->text));
                        core::dimension2d<u32> textsize = font->getDimension(
                                nametag_colorless.c_str());
                        f32 zDiv = transformed_pos[3] == 0.0f ? 1.0f :
@@ -720,26 +717,22 @@ void Camera::drawNametags()
                        core::rect<s32> size(0, 0, textsize.Width, textsize.Height);
                        core::rect<s32> bg_size(-2, 0, textsize.Width+2, textsize.Height);
 
-                       video::SColor textColor = nametag->nametag_color;
-
-                       bool darkBackground = textColor.getLuminance() > 186;
-                       video::SColor backgroundColor = darkBackground
-                                       ? video::SColor(50, 50, 50, 50)
-                                       : video::SColor(50, 255, 255, 255);
-                       driver->draw2DRectangle(backgroundColor, bg_size + screen_pos);
+                       auto bgcolor = nametag->getBgColor(m_show_nametag_backgrounds);
+                       if (bgcolor.getAlpha() != 0)
+                               driver->draw2DRectangle(bgcolor, bg_size + screen_pos);
 
                        font->draw(
-                               translate_string(utf8_to_wide(nametag->nametag_text)).c_str(),
-                               size + screen_pos, textColor);
+                               translate_string(utf8_to_wide(nametag->text)).c_str(),
+                               size + screen_pos, nametag->textcolor);
                }
        }
 }
 
 Nametag *Camera::addNametag(scene::ISceneNode *parent_node,
-               const std::string &nametag_text, video::SColor nametag_color,
-               const v3f &pos)
+               const std::string &text, video::SColor textcolor,
+               Optional<video::SColor> bgcolor, const v3f &pos)
 {
-       Nametag *nametag = new Nametag(parent_node, nametag_text, nametag_color, pos);
+       Nametag *nametag = new Nametag(parent_node, text, textcolor, bgcolor, pos);
        m_nametags.push_back(nametag);
        return nametag;
 }