From 72416a6a1f75d56abfad0f486e57fd32579b3604 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Tue, 10 Sep 2019 15:11:26 +0200 Subject: Formspec: add hypertext element --- src/client/hud.cpp | 70 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 23 deletions(-) (limited to 'src/client/hud.cpp') diff --git a/src/client/hud.cpp b/src/client/hud.cpp index 291d03816..304a3ab16 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -608,23 +608,24 @@ void Hud::resizeHotbar() { struct MeshTimeInfo { u64 time; - scene::IMesh *mesh; + scene::IMesh *mesh = nullptr; }; -void drawItemStack(video::IVideoDriver *driver, +void drawItemStack( + video::IVideoDriver *driver, gui::IGUIFont *font, const ItemStack &item, const core::rect &rect, const core::rect *clip, Client *client, - ItemRotationKind rotation_kind) + ItemRotationKind rotation_kind, + const v3s16 &angle, + const v3s16 &rotation_speed) { static MeshTimeInfo rotation_time_infos[IT_ROT_NONE]; - static thread_local bool enable_animations = - g_settings->getBool("inventory_items_animations"); if (item.empty()) { - if (rotation_kind < IT_ROT_NONE) { + if (rotation_kind < IT_ROT_NONE && rotation_kind != IT_ROT_OTHER) { rotation_time_infos[rotation_kind].mesh = NULL; } return; @@ -639,7 +640,7 @@ void drawItemStack(video::IVideoDriver *driver, s32 delta = 0; if (rotation_kind < IT_ROT_NONE) { MeshTimeInfo &ti = rotation_time_infos[rotation_kind]; - if (mesh != ti.mesh) { + if (mesh != ti.mesh && rotation_kind != IT_ROT_OTHER) { ti.mesh = mesh; ti.time = porting::getTimeMs(); } else { @@ -677,9 +678,16 @@ void drawItemStack(video::IVideoDriver *driver, core::matrix4 matrix; matrix.makeIdentity(); + static thread_local bool enable_animations = + g_settings->getBool("inventory_items_animations"); + if (enable_animations) { - float timer_f = (float) delta / 5000.0; - matrix.setRotationDegrees(core::vector3df(0, 360 * timer_f, 0)); + float timer_f = (float) delta / 5000.f; + matrix.setRotationDegrees(v3f( + angle.X + rotation_speed.X * 3.60f * timer_f, + angle.Y + rotation_speed.Y * 3.60f * timer_f, + angle.Z + rotation_speed.Z * 3.60f * timer_f) + ); } driver->setTransform(video::ETS_WORLD, matrix); @@ -695,15 +703,18 @@ void drawItemStack(video::IVideoDriver *driver, // because these meshes are not buffered. assert(buf->getHardwareMappingHint_Vertex() == scene::EHM_NEVER); video::SColor c = basecolor; + if (imesh->buffer_colors.size() > j) { ItemPartColor *p = &imesh->buffer_colors[j]; if (p->override_base) c = p->color; } + if (imesh->needs_shading) colorizeMeshBuffer(buf, &c); else setMeshBufferColor(buf, c); + video::SMaterial &material = buf->getMaterial(); material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; material.Lighting = false; @@ -726,12 +737,12 @@ void drawItemStack(video::IVideoDriver *driver, } } - if(def.type == ITEM_TOOL && item.wear != 0) - { + if (def.type == ITEM_TOOL && item.wear != 0) { // Draw a progressbar - float barheight = rect.getHeight()/16; - float barpad_x = rect.getWidth()/16; - float barpad_y = rect.getHeight()/16; + float barheight = rect.getHeight() / 16; + float barpad_x = rect.getWidth() / 16; + float barpad_y = rect.getHeight() / 16; + core::rect progressrect( rect.UpperLeftCorner.X + barpad_x, rect.LowerRightCorner.Y - barpad_y - barheight, @@ -739,18 +750,19 @@ void drawItemStack(video::IVideoDriver *driver, rect.LowerRightCorner.Y - barpad_y); // Shrink progressrect by amount of tool damage - float wear = item.wear / 65535.0; + float wear = item.wear / 65535.0f; int progressmid = wear * progressrect.UpperLeftCorner.X + - (1-wear) * progressrect.LowerRightCorner.X; + (1 - wear) * progressrect.LowerRightCorner.X; // Compute progressbar color // wear = 0.0: green // wear = 0.5: yellow // wear = 1.0: red - video::SColor color(255,255,255,255); + video::SColor color(255, 255, 255, 255); int wear_i = MYMIN(std::floor(wear * 600), 511); wear_i = MYMIN(wear_i + 10, 511); + if (wear_i <= 255) color.set(255, wear_i, 255, 0); else @@ -760,18 +772,17 @@ void drawItemStack(video::IVideoDriver *driver, progressrect2.LowerRightCorner.X = progressmid; driver->draw2DRectangle(color, progressrect2, clip); - color = video::SColor(255,0,0,0); + color = video::SColor(255, 0, 0, 0); progressrect2 = progressrect; progressrect2.UpperLeftCorner.X = progressmid; driver->draw2DRectangle(color, progressrect2, clip); } - if(font != NULL && item.count >= 2) - { + if (font != NULL && item.count >= 2) { // Get the item count as a string std::string text = itos(item.count); v2u32 dim = font->getDimension(utf8_to_wide(text).c_str()); - v2s32 sdim(dim.X,dim.Y); + v2s32 sdim(dim.X, dim.Y); core::rect rect2( /*rect.UpperLeftCorner, @@ -780,10 +791,23 @@ void drawItemStack(video::IVideoDriver *driver, sdim ); - video::SColor bgcolor(128,0,0,0); + video::SColor bgcolor(128, 0, 0, 0); driver->draw2DRectangle(bgcolor, rect2, clip); - video::SColor color(255,255,255,255); + video::SColor color(255, 255, 255, 255); font->draw(text.c_str(), rect2, color, false, false, clip); } } + +void drawItemStack( + video::IVideoDriver *driver, + gui::IGUIFont *font, + const ItemStack &item, + const core::rect &rect, + const core::rect *clip, + Client *client, + ItemRotationKind rotation_kind) +{ + drawItemStack(driver, font, item, rect, clip, client, rotation_kind, + v3s16(0, 0, 0), v3s16(0, 100, 0)); +} -- cgit v1.2.3