From 18094c505a125b6bb5b0c1f8dfd3befa37b7088b Mon Sep 17 00:00:00 2001 From: CodingJellyfish Date: Sun, 28 Apr 2024 13:25:20 +0800 Subject: [PATCH] Add resizing code for networking lobby --- src/guiengine/widgets/label_widget.hpp | 3 +- .../online/networking_lobby.cpp | 28 +++++++++++++++++++ .../online/networking_lobby.hpp | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/guiengine/widgets/label_widget.hpp b/src/guiengine/widgets/label_widget.hpp index 26cf1c2df..9f6a8c815 100644 --- a/src/guiengine/widgets/label_widget.hpp +++ b/src/guiengine/widgets/label_widget.hpp @@ -117,7 +117,8 @@ namespace GUIEngine void setScrollSpeed(float speed); // -------------------------------------------------------------------- - + float getScrollSpeed() const { return m_scroll_speed; } + // -------------------------------------------------------------------- /** * \brief Check if the current has been fully scrolled * \return true if the text has completely scrolled off diff --git a/src/states_screens/online/networking_lobby.cpp b/src/states_screens/online/networking_lobby.cpp index 6db6736da..cf26751d6 100644 --- a/src/states_screens/online/networking_lobby.cpp +++ b/src/states_screens/online/networking_lobby.cpp @@ -422,6 +422,34 @@ break_glyph_layouts: #endif } // addMoreServerInfo +// ---------------------------------------------------------------------------- +void NetworkingLobby::onResize() +{ + Screen::onResize(); + const unsigned box_width = m_text_bubble->getDimension().Width; + const float box_height = m_text_bubble->getDimension().Height; + gui::IGUIFont* font = GUIEngine::getFont(); + gui::breakGlyphLayouts(m_server_info, box_width, + font->getInverseShaping(), font->getScale()); + gui::eraseTopLargerThan(m_server_info, font->getHeightPerLine(), + box_height); + updateServerInfos(); + + int header_text_width = + GUIEngine::getTitleFont()->getDimension(m_header_text.c_str()).Width; + if ((m_header->m_w < header_text_width && m_header->getScrollSpeed() == 0.0f) || + (m_header->m_w >= header_text_width && m_header->getScrollSpeed() != 0.0f)) + { + m_header->getIrrlichtElement()->remove(); + GUIEngine::getGUIEnv()->setChildEnd(m_back_widget->getIrrlichtElement()); + m_header->setScrollSpeed(m_header->m_w < header_text_width ? 0.5f: 0.0f); + m_header->add(); + m_header->setText(m_header_text, true); + GUIEngine::getGUIEnv()->setChildEnd(NULL); + } + m_header_text_width = header_text_width; +} // onResize + // ---------------------------------------------------------------------------- void NetworkingLobby::updateServerInfos() { diff --git a/src/states_screens/online/networking_lobby.hpp b/src/states_screens/online/networking_lobby.hpp index 554023d50..9184ce9c8 100644 --- a/src/states_screens/online/networking_lobby.hpp +++ b/src/states_screens/online/networking_lobby.hpp @@ -149,6 +149,7 @@ public: void reloadServerInfos() { m_reload_server_info = true; } void setHeader(const core::stringw& header) { m_header_text = header; } void setAssignedPlayers(bool val) { m_assigned_players = val; } + virtual void onResize() OVERRIDE; }; // class NetworkingLobby #endif