Skip to content

Commit 02f82ec

Browse files
committedJan 5, 2018
GameUI refactor (part 6/X): Move Game::guitext_profiler & showStatusTextSimple to GameUI class
Other enhancements: * Move showStatusTextSimple to GameUI class & rename to showTranslatedStatusText
1 parent 326b0fa commit 02f82ec

File tree

3 files changed

+109
-116
lines changed

3 files changed

+109
-116
lines changed
 

‎src/client/gameui.cpp

+62
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2020

2121
#include "gameui.h"
2222
#include <irrlicht_changes/static_text.h>
23+
#include <gettext.h>
2324
#include "gui/mainmenumanager.h"
2425
#include "util/pointedthing.h"
2526
#include "client.h"
2627
#include "clientmap.h"
2728
#include "fontengine.h"
2829
#include "nodedef.h"
30+
#include "profiler.h"
2931
#include "renderingengine.h"
3032
#include "version.h"
3133

@@ -64,6 +66,13 @@ void GameUI::init()
6466
m_guitext_chat = gui::StaticText::add(guienv, L"", core::rect<s32>(0, 0, 0, 0),
6567
//false, false); // Disable word wrap as of now
6668
false, true, guiroot);
69+
70+
// Profiler text (size is updated when text is updated)
71+
m_guitext_profiler = gui::StaticText::add(guienv, L"<Profiler>",
72+
core::rect<s32>(0, 0, 0, 0), false, false, guiroot);
73+
m_guitext_profiler->setBackgroundColor(video::SColor(120, 0, 0, 0));
74+
m_guitext_profiler->setVisible(false);
75+
m_guitext_profiler->setWordWrap(true);
6776
}
6877

6978
void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_control,
@@ -188,6 +197,13 @@ void GameUI::showMinimap(bool show)
188197
m_flags.show_minimap = show;
189198
}
190199

200+
void GameUI::showTranslatedStatusText(const char *str)
201+
{
202+
const wchar_t *wmsg = wgettext(str);
203+
showStatusText(wmsg);
204+
delete[] wmsg;
205+
}
206+
191207
void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count,
192208
u32 profiler_current_page)
193209
{
@@ -214,3 +230,49 @@ void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count,
214230
m_guitext_chat->setVisible(m_flags.show_chat &&
215231
recent_chat_count != 0 && profiler_current_page == 0);
216232
}
233+
234+
void GameUI::updateProfiler(u32 profiler_current_page, u32 profiler_max_page)
235+
{
236+
if (profiler_current_page != 0) {
237+
std::ostringstream os(std::ios_base::binary);
238+
g_profiler->printPage(os, profiler_current_page,
239+
profiler_max_page);
240+
241+
std::wstring text = translate_string(utf8_to_wide(os.str()));
242+
setStaticText(m_guitext_profiler, text.c_str());
243+
244+
s32 w = g_fontengine->getTextWidth(text);
245+
246+
if (w < 400)
247+
w = 400;
248+
249+
unsigned text_height = g_fontengine->getTextHeight();
250+
251+
core::position2di upper_left, lower_right;
252+
253+
upper_left.X = 6;
254+
upper_left.Y = (text_height + 5) * 2;
255+
lower_right.X = 12 + w;
256+
lower_right.Y = upper_left.Y + (text_height + 1) * MAX_PROFILER_TEXT_ROWS;
257+
258+
s32 screen_height = RenderingEngine::get_video_driver()->getScreenSize().Height;
259+
260+
if (lower_right.Y > screen_height * 2 / 3)
261+
lower_right.Y = screen_height * 2 / 3;
262+
263+
m_guitext_profiler->setRelativePosition(core::rect<s32>(upper_left, lower_right));
264+
}
265+
266+
m_guitext_profiler->setVisible(profiler_current_page != 0);
267+
268+
if (profiler_current_page != 0) {
269+
wchar_t buf[255];
270+
const wchar_t* str = wgettext("Profiler shown (page %d of %d)");
271+
swprintf(buf, sizeof(buf) / sizeof(wchar_t), str,
272+
profiler_current_page, profiler_max_page);
273+
delete[] str;
274+
showStatusText(buf);
275+
} else {
276+
showTranslatedStatusText("Profiler hidden");
277+
}
278+
}

‎src/client/gameui.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,18 @@ class GameUI
7171
m_statustext = str;
7272
m_statustext_time = 0.0f;
7373
}
74+
void showTranslatedStatusText(const char *str);
7475
inline void clearStatusText() { m_statustext.clear(); }
7576

7677
void setChatText(const EnrichedString &chat_text, u32 recent_chat_count,
7778
u32 profiler_current_page);
7879

80+
void updateProfiler(u32 profiler_current_page, u32 profiler_max_page);
81+
7982
private:
8083
Flags m_flags;
8184

82-
gui::IGUIStaticText *m_guitext = nullptr; // First line of debug text
85+
gui::IGUIStaticText *m_guitext = nullptr; // First line of debug text
8386
gui::IGUIStaticText *m_guitext2 = nullptr; // Second line of debug text
8487

8588
gui::IGUIStaticText *m_guitext_info = nullptr; // At the middle of the screen
@@ -90,7 +93,5 @@ class GameUI
9093
float m_statustext_time = 0.0f;
9194

9295
gui::IGUIStaticText *m_guitext_chat; // Chat text
93-
94-
// @TODO future move
95-
// gui::IGUIStaticText *m_guitext_profiler; // Profiler text
96+
gui::IGUIStaticText *m_guitext_profiler; // Profiler text
9697
};

0 commit comments

Comments
 (0)