summaryrefslogtreecommitdiff
path: root/src/client/gameui.cpp
diff options
context:
space:
mode:
authorLoic Blot <loic.blot@unix-experience.fr>2018-01-04 23:04:40 +0100
committerLoïc Blot <nerzhul@users.noreply.github.com>2018-01-05 20:59:30 +0100
commit326b0faa5e0bee62ee3100f345c021cee020f2dd (patch)
treed3a4875e98e0698184297b3d1231857a68363c72 /src/client/gameui.cpp
parentfe510d90c15d9bec3a8c1dafc7b1730b11a9f6bd (diff)
downloadminetest-326b0faa5e0bee62ee3100f345c021cee020f2dd.tar.gz
minetest-326b0faa5e0bee62ee3100f345c021cee020f2dd.tar.bz2
minetest-326b0faa5e0bee62ee3100f345c021cee020f2dd.zip
GameUI refactor (part 5/X): Move Game::guitext_chat to GameUI class
Other enhancements: * Move update_profiler_gui to Game class * Move updateChat to Game class
Diffstat (limited to 'src/client/gameui.cpp')
-rw-r--r--src/client/gameui.cpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/client/gameui.cpp b/src/client/gameui.cpp
index 7955dea59..8a8a091c6 100644
--- a/src/client/gameui.cpp
+++ b/src/client/gameui.cpp
@@ -58,8 +58,12 @@ void GameUI::init()
// Status text (displays info when showing and hiding GUI stuff, etc.)
m_guitext_status = gui::StaticText::add(guienv, L"<Status>",
core::rect<s32>(0, 0, 0, 0), false, false, guiroot);
-
m_guitext_status->setVisible(false);
+
+ // Chat text
+ m_guitext_chat = gui::StaticText::add(guienv, L"", core::rect<s32>(0, 0, 0, 0),
+ //false, false); // Disable word wrap as of now
+ false, true, guiroot);
}
void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_control,
@@ -183,3 +187,30 @@ void GameUI::showMinimap(bool show)
{
m_flags.show_minimap = show;
}
+
+void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count,
+ u32 profiler_current_page)
+{
+ setStaticText(m_guitext_chat, chat_text);
+
+ // Update gui element size and position
+ s32 chat_y = 5;
+
+ if (m_flags.show_debug)
+ chat_y += 2 * g_fontengine->getLineHeight();
+
+ // first pass to calculate height of text to be set
+ const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize();
+ s32 width = std::min(g_fontengine->getTextWidth(chat_text.c_str()) + 10,
+ window_size.X - 20);
+ m_guitext_chat->setRelativePosition(core::rect<s32>(10, chat_y, width,
+ chat_y + window_size.Y));
+
+ // now use real height of text and adjust rect according to this size
+ m_guitext_chat->setRelativePosition(core::rect<s32>(10, chat_y, width,
+ chat_y + m_guitext_chat->getTextHeight()));
+
+ // Don't show chat if disabled or empty or profiler is enabled
+ m_guitext_chat->setVisible(m_flags.show_chat &&
+ recent_chat_count != 0 && profiler_current_page == 0);
+}