From 137e4ce8667af7eb1edefd9754f758e430551a40 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sun, 13 Aug 2023 13:28:33 +0100 Subject: [PATCH] Fix hypertext in the mainmenu (#13731) --- src/gui/guiFormSpecMenu.cpp | 2 -- src/gui/guiHyperText.cpp | 29 ++++++++++++++--------------- src/gui/guiHyperText.h | 7 ++++--- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index cea84fd80..afc6d09db 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -1670,8 +1670,6 @@ void GUIFormSpecMenu::parseField(parserData* data, const std::string &element, void GUIFormSpecMenu::parseHyperText(parserData *data, const std::string &element) { - MY_CHECKCLIENT("hypertext"); - std::vector parts; if (!precheckElement("hypertext", element, 4, 4, parts)) return; diff --git a/src/gui/guiHyperText.cpp b/src/gui/guiHyperText.cpp index c2241c944..c2461b29b 100644 --- a/src/gui/guiHyperText.cpp +++ b/src/gui/guiHyperText.cpp @@ -600,8 +600,7 @@ u32 ParsedText::parseTag(const wchar_t *text, u32 cursor) TextDrawer::TextDrawer(const wchar_t *text, Client *client, gui::IGUIEnvironment *environment, ISimpleTextureSource *tsrc) : - m_text(text), - m_client(client), m_environment(environment) + m_text(text), m_client(client), m_tsrc(tsrc), m_guienv(environment) { // Size all elements for (auto &p : m_text.m_paragraphs) { @@ -632,7 +631,7 @@ TextDrawer::TextDrawer(const wchar_t *text, Client *client, if (e.type == ParsedText::ELEMENT_IMAGE) { video::ITexture *texture = - m_client->getTextureSource()-> + m_tsrc-> getTexture(stringw_to_utf8(e.text)); if (texture) dim = texture->getOriginalSize(); @@ -914,7 +913,7 @@ void TextDrawer::place(const core::rect &dest_rect) void TextDrawer::draw(const core::rect &clip_rect, const core::position2d &dest_offset) { - irr::video::IVideoDriver *driver = m_environment->getVideoDriver(); + irr::video::IVideoDriver *driver = m_guienv->getVideoDriver(); core::position2d offset = dest_offset; offset.Y += m_voffset; @@ -958,10 +957,10 @@ void TextDrawer::draw(const core::rect &clip_rect, case ParsedText::ELEMENT_IMAGE: { video::ITexture *texture = - m_client->getTextureSource()->getTexture( + m_tsrc->getTexture( stringw_to_utf8(el.text)); if (texture != 0) - m_environment->getVideoDriver()->draw2DImage( + m_guienv->getVideoDriver()->draw2DImage( texture, rect, irr::core::rect( core::position2d(0, 0), @@ -970,15 +969,15 @@ void TextDrawer::draw(const core::rect &clip_rect, } break; case ParsedText::ELEMENT_ITEM: { - IItemDefManager *idef = m_client->idef(); - ItemStack item; - item.deSerialize(stringw_to_utf8(el.text), idef); + if (m_client) { + IItemDefManager *idef = m_client->idef(); + ItemStack item; + item.deSerialize(stringw_to_utf8(el.text), idef); - drawItemStack( - m_environment->getVideoDriver(), - g_fontengine->getFont(), item, rect, &clip_rect, - m_client, IT_ROT_OTHER, el.angle, el.rotation - ); + drawItemStack(m_guienv->getVideoDriver(), + g_fontengine->getFont(), item, rect, &clip_rect, m_client, + IT_ROT_OTHER, el.angle, el.rotation); + } } break; } } @@ -993,7 +992,7 @@ GUIHyperText::GUIHyperText(const wchar_t *text, IGUIEnvironment *environment, IGUIElement *parent, s32 id, const core::rect &rectangle, Client *client, ISimpleTextureSource *tsrc) : IGUIElement(EGUIET_ELEMENT, environment, parent, id, rectangle), - m_client(client), m_vscrollbar(nullptr), + m_tsrc(tsrc), m_vscrollbar(nullptr), m_drawer(text, client, environment, tsrc), m_text_scrollpos(0, 0) { diff --git a/src/gui/guiHyperText.h b/src/gui/guiHyperText.h index 04c664df5..0616a37ce 100644 --- a/src/gui/guiHyperText.h +++ b/src/gui/guiHyperText.h @@ -188,8 +188,9 @@ protected: }; ParsedText m_text; - Client *m_client; - gui::IGUIEnvironment *m_environment; + Client *m_client; ///< null in the mainmenu + ISimpleTextureSource *m_tsrc; + gui::IGUIEnvironment *m_guienv; s32 m_height; s32 m_voffset; std::vector m_floating; @@ -216,7 +217,7 @@ public: protected: // GUI members - Client *m_client; + ISimpleTextureSource *m_tsrc; GUIScrollBar *m_vscrollbar; TextDrawer m_drawer;