diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/gameui.cpp | 62 | ||||
-rw-r--r-- | src/client/gameui.h | 9 |
2 files changed, 67 insertions, 4 deletions
diff --git a/src/client/gameui.cpp b/src/client/gameui.cpp index 8a8a091c6..924336165 100644 --- a/src/client/gameui.cpp +++ b/src/client/gameui.cpp @@ -20,12 +20,14 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "gameui.h" #include <irrlicht_changes/static_text.h> +#include <gettext.h> #include "gui/mainmenumanager.h" #include "util/pointedthing.h" #include "client.h" #include "clientmap.h" #include "fontengine.h" #include "nodedef.h" +#include "profiler.h" #include "renderingengine.h" #include "version.h" @@ -64,6 +66,13 @@ void GameUI::init() 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); + + // Profiler text (size is updated when text is updated) + m_guitext_profiler = gui::StaticText::add(guienv, L"<Profiler>", + core::rect<s32>(0, 0, 0, 0), false, false, guiroot); + m_guitext_profiler->setBackgroundColor(video::SColor(120, 0, 0, 0)); + m_guitext_profiler->setVisible(false); + m_guitext_profiler->setWordWrap(true); } void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_control, @@ -188,6 +197,13 @@ void GameUI::showMinimap(bool show) m_flags.show_minimap = show; } +void GameUI::showTranslatedStatusText(const char *str) +{ + const wchar_t *wmsg = wgettext(str); + showStatusText(wmsg); + delete[] wmsg; +} + void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count, u32 profiler_current_page) { @@ -214,3 +230,49 @@ void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count, m_guitext_chat->setVisible(m_flags.show_chat && recent_chat_count != 0 && profiler_current_page == 0); } + +void GameUI::updateProfiler(u32 profiler_current_page, u32 profiler_max_page) +{ + if (profiler_current_page != 0) { + std::ostringstream os(std::ios_base::binary); + g_profiler->printPage(os, profiler_current_page, + profiler_max_page); + + std::wstring text = translate_string(utf8_to_wide(os.str())); + setStaticText(m_guitext_profiler, text.c_str()); + + s32 w = g_fontengine->getTextWidth(text); + + if (w < 400) + w = 400; + + unsigned text_height = g_fontengine->getTextHeight(); + + core::position2di upper_left, lower_right; + + upper_left.X = 6; + upper_left.Y = (text_height + 5) * 2; + lower_right.X = 12 + w; + lower_right.Y = upper_left.Y + (text_height + 1) * MAX_PROFILER_TEXT_ROWS; + + s32 screen_height = RenderingEngine::get_video_driver()->getScreenSize().Height; + + if (lower_right.Y > screen_height * 2 / 3) + lower_right.Y = screen_height * 2 / 3; + + m_guitext_profiler->setRelativePosition(core::rect<s32>(upper_left, lower_right)); + } + + m_guitext_profiler->setVisible(profiler_current_page != 0); + + if (profiler_current_page != 0) { + wchar_t buf[255]; + const wchar_t* str = wgettext("Profiler shown (page %d of %d)"); + swprintf(buf, sizeof(buf) / sizeof(wchar_t), str, + profiler_current_page, profiler_max_page); + delete[] str; + showStatusText(buf); + } else { + showTranslatedStatusText("Profiler hidden"); + } +} diff --git a/src/client/gameui.h b/src/client/gameui.h index d1838f628..b090f5cb0 100644 --- a/src/client/gameui.h +++ b/src/client/gameui.h @@ -71,15 +71,18 @@ public: m_statustext = str; m_statustext_time = 0.0f; } + void showTranslatedStatusText(const char *str); inline void clearStatusText() { m_statustext.clear(); } void setChatText(const EnrichedString &chat_text, u32 recent_chat_count, u32 profiler_current_page); + void updateProfiler(u32 profiler_current_page, u32 profiler_max_page); + private: Flags m_flags; - gui::IGUIStaticText *m_guitext = nullptr; // First line of debug text + gui::IGUIStaticText *m_guitext = nullptr; // First line of debug text gui::IGUIStaticText *m_guitext2 = nullptr; // Second line of debug text gui::IGUIStaticText *m_guitext_info = nullptr; // At the middle of the screen @@ -90,7 +93,5 @@ private: float m_statustext_time = 0.0f; gui::IGUIStaticText *m_guitext_chat; // Chat text - - // @TODO future move - // gui::IGUIStaticText *m_guitext_profiler; // Profiler text + gui::IGUIStaticText *m_guitext_profiler; // Profiler text }; |