@@ -20,12 +20,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
20
20
21
21
#include " gameui.h"
22
22
#include < irrlicht_changes/static_text.h>
23
+ #include < gettext.h>
23
24
#include " gui/mainmenumanager.h"
24
25
#include " util/pointedthing.h"
25
26
#include " client.h"
26
27
#include " clientmap.h"
27
28
#include " fontengine.h"
28
29
#include " nodedef.h"
30
+ #include " profiler.h"
29
31
#include " renderingengine.h"
30
32
#include " version.h"
31
33
@@ -64,6 +66,13 @@ void GameUI::init()
64
66
m_guitext_chat = gui::StaticText::add (guienv, L" " , core::rect<s32>(0 , 0 , 0 , 0 ),
65
67
// false, false); // Disable word wrap as of now
66
68
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 );
67
76
}
68
77
69
78
void GameUI::update (const RunStats &stats, Client *client, MapDrawControl *draw_control,
@@ -188,6 +197,13 @@ void GameUI::showMinimap(bool show)
188
197
m_flags.show_minimap = show;
189
198
}
190
199
200
+ void GameUI::showTranslatedStatusText (const char *str)
201
+ {
202
+ const wchar_t *wmsg = wgettext (str);
203
+ showStatusText (wmsg);
204
+ delete[] wmsg;
205
+ }
206
+
191
207
void GameUI::setChatText (const EnrichedString &chat_text, u32 recent_chat_count,
192
208
u32 profiler_current_page)
193
209
{
@@ -214,3 +230,49 @@ void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count,
214
230
m_guitext_chat->setVisible (m_flags.show_chat &&
215
231
recent_chat_count != 0 && profiler_current_page == 0 );
216
232
}
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
+ }
0 commit comments