Fix hypertext in the mainmenu (#13731)

This commit is contained in:
rubenwardy 2023-08-13 13:28:33 +01:00 committed by GitHub
parent 526c5f2348
commit 137e4ce866
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 20 deletions

@ -1670,8 +1670,6 @@ void GUIFormSpecMenu::parseField(parserData* data, const std::string &element,
void GUIFormSpecMenu::parseHyperText(parserData *data, const std::string &element) void GUIFormSpecMenu::parseHyperText(parserData *data, const std::string &element)
{ {
MY_CHECKCLIENT("hypertext");
std::vector<std::string> parts; std::vector<std::string> parts;
if (!precheckElement("hypertext", element, 4, 4, parts)) if (!precheckElement("hypertext", element, 4, 4, parts))
return; return;

@ -600,8 +600,7 @@ u32 ParsedText::parseTag(const wchar_t *text, u32 cursor)
TextDrawer::TextDrawer(const wchar_t *text, Client *client, TextDrawer::TextDrawer(const wchar_t *text, Client *client,
gui::IGUIEnvironment *environment, ISimpleTextureSource *tsrc) : gui::IGUIEnvironment *environment, ISimpleTextureSource *tsrc) :
m_text(text), m_text(text), m_client(client), m_tsrc(tsrc), m_guienv(environment)
m_client(client), m_environment(environment)
{ {
// Size all elements // Size all elements
for (auto &p : m_text.m_paragraphs) { 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) { if (e.type == ParsedText::ELEMENT_IMAGE) {
video::ITexture *texture = video::ITexture *texture =
m_client->getTextureSource()-> m_tsrc->
getTexture(stringw_to_utf8(e.text)); getTexture(stringw_to_utf8(e.text));
if (texture) if (texture)
dim = texture->getOriginalSize(); dim = texture->getOriginalSize();
@ -914,7 +913,7 @@ void TextDrawer::place(const core::rect<s32> &dest_rect)
void TextDrawer::draw(const core::rect<s32> &clip_rect, void TextDrawer::draw(const core::rect<s32> &clip_rect,
const core::position2d<s32> &dest_offset) const core::position2d<s32> &dest_offset)
{ {
irr::video::IVideoDriver *driver = m_environment->getVideoDriver(); irr::video::IVideoDriver *driver = m_guienv->getVideoDriver();
core::position2d<s32> offset = dest_offset; core::position2d<s32> offset = dest_offset;
offset.Y += m_voffset; offset.Y += m_voffset;
@ -958,10 +957,10 @@ void TextDrawer::draw(const core::rect<s32> &clip_rect,
case ParsedText::ELEMENT_IMAGE: { case ParsedText::ELEMENT_IMAGE: {
video::ITexture *texture = video::ITexture *texture =
m_client->getTextureSource()->getTexture( m_tsrc->getTexture(
stringw_to_utf8(el.text)); stringw_to_utf8(el.text));
if (texture != 0) if (texture != 0)
m_environment->getVideoDriver()->draw2DImage( m_guienv->getVideoDriver()->draw2DImage(
texture, rect, texture, rect,
irr::core::rect<s32>( irr::core::rect<s32>(
core::position2d<s32>(0, 0), core::position2d<s32>(0, 0),
@ -970,15 +969,15 @@ void TextDrawer::draw(const core::rect<s32> &clip_rect,
} break; } break;
case ParsedText::ELEMENT_ITEM: { case ParsedText::ELEMENT_ITEM: {
IItemDefManager *idef = m_client->idef(); if (m_client) {
ItemStack item; IItemDefManager *idef = m_client->idef();
item.deSerialize(stringw_to_utf8(el.text), idef); ItemStack item;
item.deSerialize(stringw_to_utf8(el.text), idef);
drawItemStack( drawItemStack(m_guienv->getVideoDriver(),
m_environment->getVideoDriver(), g_fontengine->getFont(), item, rect, &clip_rect, m_client,
g_fontengine->getFont(), item, rect, &clip_rect, IT_ROT_OTHER, el.angle, el.rotation);
m_client, IT_ROT_OTHER, el.angle, el.rotation }
);
} break; } break;
} }
} }
@ -993,7 +992,7 @@ GUIHyperText::GUIHyperText(const wchar_t *text, IGUIEnvironment *environment,
IGUIElement *parent, s32 id, const core::rect<s32> &rectangle, IGUIElement *parent, s32 id, const core::rect<s32> &rectangle,
Client *client, ISimpleTextureSource *tsrc) : Client *client, ISimpleTextureSource *tsrc) :
IGUIElement(EGUIET_ELEMENT, environment, parent, id, rectangle), 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) m_drawer(text, client, environment, tsrc), m_text_scrollpos(0, 0)
{ {

@ -188,8 +188,9 @@ protected:
}; };
ParsedText m_text; ParsedText m_text;
Client *m_client; Client *m_client; ///< null in the mainmenu
gui::IGUIEnvironment *m_environment; ISimpleTextureSource *m_tsrc;
gui::IGUIEnvironment *m_guienv;
s32 m_height; s32 m_height;
s32 m_voffset; s32 m_voffset;
std::vector<RectWithMargin> m_floating; std::vector<RectWithMargin> m_floating;
@ -216,7 +217,7 @@ public:
protected: protected:
// GUI members // GUI members
Client *m_client; ISimpleTextureSource *m_tsrc;
GUIScrollBar *m_vscrollbar; GUIScrollBar *m_vscrollbar;
TextDrawer m_drawer; TextDrawer m_drawer;