diff options
author | Loic Blot <loic.blot@unix-experience.fr> | 2018-01-04 23:58:46 +0100 |
---|---|---|
committer | Loïc Blot <nerzhul@users.noreply.github.com> | 2018-01-05 20:59:30 +0100 |
commit | f40f4143dfbbaadaabcdbd5243412d389a9d29fb (patch) | |
tree | 40008c66ba49779cfddabc3c7a16e58c0e801f09 /src/client | |
parent | 02f82eca0b20a4e998e1541413e64766db5d12b0 (diff) | |
download | minetest-f40f4143dfbbaadaabcdbd5243412d389a9d29fb.tar.gz minetest-f40f4143dfbbaadaabcdbd5243412d389a9d29fb.tar.bz2 minetest-f40f4143dfbbaadaabcdbd5243412d389a9d29fb.zip |
GameUI refactor (part 7/7): Finish to include profiler things to GameUI
Other changes:
* Add GameUI clarification comment
* Move force_fog_off & disable_camera_update flags from GameUI to Game, it's not UI related
* Properly init GameUI::Flags
* Move toggleChat toggleHud & toggleProfiler to GameUI
* Add gameui.cpp to LINT whitelist
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/gameui.cpp | 44 | ||||
-rw-r--r-- | src/client/gameui.h | 34 |
2 files changed, 57 insertions, 21 deletions
diff --git a/src/client/gameui.cpp b/src/client/gameui.cpp index 924336165..6f6d2c2a8 100644 --- a/src/client/gameui.cpp +++ b/src/client/gameui.cpp @@ -204,8 +204,7 @@ void GameUI::showTranslatedStatusText(const char *str) delete[] wmsg; } -void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count, - u32 profiler_current_page) +void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count) { setStaticText(m_guitext_chat, chat_text); @@ -228,15 +227,14 @@ void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count, // 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); + recent_chat_count != 0 && m_profiler_current_page == 0); } -void GameUI::updateProfiler(u32 profiler_current_page, u32 profiler_max_page) +void GameUI::updateProfiler() { - if (profiler_current_page != 0) { + if (m_profiler_current_page != 0) { std::ostringstream os(std::ios_base::binary); - g_profiler->printPage(os, profiler_current_page, - profiler_max_page); + g_profiler->printPage(os, m_profiler_current_page, m_profiler_max_page); std::wstring text = translate_string(utf8_to_wide(os.str())); setStaticText(m_guitext_profiler, text.c_str()); @@ -263,13 +261,39 @@ void GameUI::updateProfiler(u32 profiler_current_page, u32 profiler_max_page) m_guitext_profiler->setRelativePosition(core::rect<s32>(upper_left, lower_right)); } - m_guitext_profiler->setVisible(profiler_current_page != 0); + m_guitext_profiler->setVisible(m_profiler_current_page != 0); +} + +void GameUI::toggleChat() +{ + m_flags.show_chat = !m_flags.show_chat; + if (m_flags.show_chat) + showTranslatedStatusText("Chat shown"); + else + showTranslatedStatusText("Chat hidden"); +} + +void GameUI::toggleHud() +{ + m_flags.show_hud = !m_flags.show_hud; + if (m_flags.show_hud) + showTranslatedStatusText("HUD shown"); + else + showTranslatedStatusText("HUD hidden"); +} + +void GameUI::toggleProfiler() +{ + m_profiler_current_page = (m_profiler_current_page + 1) % (m_profiler_max_page + 1); + + // FIXME: This updates the profiler with incomplete values + updateProfiler(); - if (profiler_current_page != 0) { + if (m_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); + m_profiler_current_page, m_profiler_max_page); delete[] str; showStatusText(buf); } else { diff --git a/src/client/gameui.h b/src/client/gameui.h index b090f5cb0..ebb7842c4 100644 --- a/src/client/gameui.h +++ b/src/client/gameui.h @@ -29,6 +29,14 @@ using namespace irr; class Client; struct MapDrawControl; +/* + * This object intend to contain the core UI elements + * It includes: + * - status texts + * - debug texts + * - chat texts + * - hud flags + */ class GameUI { // Temporary between coding time to move things here @@ -44,13 +52,11 @@ public: // Flags that can, or may, change during main game loop struct Flags { - bool show_chat; - bool show_hud; - bool show_minimap; - bool force_fog_off; - bool show_debug; - bool show_profiler_graph; - bool disable_camera_update; + bool show_chat = true; + bool show_hud = true; + bool show_minimap = true; + bool show_debug = true; + bool show_profiler_graph = true; }; void init(); @@ -74,15 +80,18 @@ public: 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 setChatText(const EnrichedString &chat_text, u32 recent_chat_count); + + void updateProfiler(); - void updateProfiler(u32 profiler_current_page, u32 profiler_max_page); + void toggleChat(); + void toggleHud(); + void toggleProfiler(); 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 @@ -93,5 +102,8 @@ private: float m_statustext_time = 0.0f; gui::IGUIStaticText *m_guitext_chat; // Chat text + gui::IGUIStaticText *m_guitext_profiler; // Profiler text + u8 m_profiler_current_page = 0; + const u8 m_profiler_max_page = 3; }; |