diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/camera.cpp | 23 | ||||
-rw-r--r-- | src/client/camera.h | 33 | ||||
-rw-r--r-- | src/client/content_cao.cpp | 6 | ||||
-rw-r--r-- | src/client/content_cao.h | 2 | ||||
-rw-r--r-- | src/client/hud.cpp | 2 |
5 files changed, 57 insertions, 9 deletions
diff --git a/src/client/camera.cpp b/src/client/camera.cpp index 3afd45c55..854d9eae8 100644 --- a/src/client/camera.cpp +++ b/src/client/camera.cpp @@ -35,6 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/numeric.h" #include "constants.h" #include "fontengine.h" +#include "guiscalingfilter.h" #include "script/scripting_client.h" #define CAMERA_OFFSET_STEP 200 @@ -715,7 +716,7 @@ void Camera::drawNametags() screen_pos.Y = screensize.Y * (0.5 - transformed_pos[1] * zDiv * 0.5) - textsize.Height / 2; core::rect<s32> size(0, 0, textsize.Width, textsize.Height); - core::rect<s32> bg_size(-2, 0, textsize.Width+2, textsize.Height); + core::rect<s32> bg_size(-2, 0, std::max(textsize.Width+2, (u32) nametag->images_dim.Width), textsize.Height + nametag->images_dim.Height); auto bgcolor = nametag->getBgColor(m_show_nametag_backgrounds); if (bgcolor.getAlpha() != 0) @@ -724,15 +725,29 @@ void Camera::drawNametags() font->draw( translate_string(utf8_to_wide(nametag->text)).c_str(), size + screen_pos, nametag->textcolor); + + v2s32 image_pos(screen_pos); + image_pos.Y += textsize.Height; + + const video::SColor color(255, 255, 255, 255); + const video::SColor colors[] = {color, color, color, color}; + + for (video::ITexture *texture : nametag->images) { + core::dimension2di imgsize(texture->getOriginalSize()); + core::rect<s32> rect(core::position2d<s32>(0, 0), imgsize); + draw2DImageFilterScaled(driver, texture, rect + image_pos, rect, NULL, colors, true); + image_pos += core::dimension2di(imgsize.Width, 0); + } + } } } - Nametag *Camera::addNametag(scene::ISceneNode *parent_node, const std::string &text, video::SColor textcolor, - Optional<video::SColor> bgcolor, const v3f &pos) + Optional<video::SColor> bgcolor, const v3f &pos, + const std::vector<std::string> &images) { - Nametag *nametag = new Nametag(parent_node, text, textcolor, bgcolor, pos); + Nametag *nametag = new Nametag(parent_node, text, textcolor, bgcolor, pos, m_client->tsrc(), images); m_nametags.push_back(nametag); return nametag; } diff --git a/src/client/camera.h b/src/client/camera.h index 6fd8d9aa7..c162df515 100644 --- a/src/client/camera.h +++ b/src/client/camera.h @@ -39,18 +39,44 @@ struct Nametag video::SColor textcolor; Optional<video::SColor> bgcolor; v3f pos; + ITextureSource *texture_source; + std::vector<video::ITexture *> images; + core::dimension2di images_dim; Nametag(scene::ISceneNode *a_parent_node, const std::string &text, const video::SColor &textcolor, const Optional<video::SColor> &bgcolor, - const v3f &pos): + const v3f &pos, + ITextureSource *tsrc, + const std::vector<std::string> &image_names): parent_node(a_parent_node), text(text), textcolor(textcolor), bgcolor(bgcolor), - pos(pos) + pos(pos), + texture_source(tsrc), + images(), + images_dim(0, 0) { + setImages(image_names); + } + + void setImages(const std::vector<std::string> &image_names) + { + images.clear(); + images_dim = core::dimension2di(0, 0); + + for (const std::string &image_name : image_names) { + video::ITexture *texture = texture_source->getTexture(image_name); + core::dimension2di imgsize(texture->getOriginalSize()); + + images_dim.Width += imgsize.Width; + if (images_dim.Height < imgsize.Height) + images_dim.Height = imgsize.Height; + + images.push_back(texture); + } } video::SColor getBgColor(bool use_fallback) const @@ -185,7 +211,8 @@ public: Nametag *addNametag(scene::ISceneNode *parent_node, const std::string &text, video::SColor textcolor, - Optional<video::SColor> bgcolor, const v3f &pos); + Optional<video::SColor> bgcolor, const v3f &pos, + const std::vector<std::string> &image_names); void removeNametag(Nametag *nametag); diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index ea034f629..84d200a73 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -962,13 +962,14 @@ void GenericCAO::updateNametag() // Add nametag m_nametag = m_client->getCamera()->addNametag(node, m_prop.nametag, m_prop.nametag_color, - m_prop.nametag_bgcolor, pos); + m_prop.nametag_bgcolor, pos, nametag_images); } else { // Update nametag m_nametag->text = m_prop.nametag; m_nametag->textcolor = m_prop.nametag_color; m_nametag->bgcolor = m_prop.nametag_bgcolor; m_nametag->pos = pos; + m_nametag->setImages(nametag_images); } } @@ -1863,6 +1864,9 @@ void GenericCAO::processMessage(const std::string &data) // Same as 'ObjectRef::l_remove' if (!m_is_player) clearChildAttachments(); + } else { + if (m_client->modsLoaded()) + m_client->getScript()->on_object_hp_change(m_id); } } else if (cmd == AO_CMD_UPDATE_ARMOR_GROUPS) { m_armor_groups.clear(); diff --git a/src/client/content_cao.h b/src/client/content_cao.h index 360c30995..450023d19 100644 --- a/src/client/content_cao.h +++ b/src/client/content_cao.h @@ -318,4 +318,6 @@ public: void setProperties(ObjectProperties newprops); void updateMeshCulling(); + + std::vector<std::string> nametag_images = {}; }; diff --git a/src/client/hud.cpp b/src/client/hud.cpp index 74c1828e3..5971948fd 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -149,7 +149,7 @@ void Hud::drawItem(const ItemStack &item, const core::rect<s32>& rect, bool selected) { if (selected) { - /* draw hihlighting around selected item */ + /* draw highlighting around selected item */ if (use_hotbar_selected_image) { core::rect<s32> imgrect2 = rect; imgrect2.UpperLeftCorner.X -= (m_padding*2); |