m_guitext_info = gui::StaticText::add(guienv, L"",
core::rect<s32>(0, 0, 400, g_fontengine->getTextHeight() * 5 + 5)
+ v2s32(100, 200), false, true, guiroot);
+
+ // 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);
}
void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_control,
- const CameraOrientation &cam, const PointedThing &pointed_old)
+ const CameraOrientation &cam, const PointedThing &pointed_old, float dtime)
{
v2u32 screensize = RenderingEngine::get_instance()->getWindowSize();
setStaticText(m_guitext_info, translate_string(m_infotext).c_str());
m_guitext_info->setVisible(m_flags.show_hud && g_menumgr.menuCount() == 0);
+
+ static const float statustext_time_max = 1.5f;
+
+ if (!m_statustext.empty()) {
+ m_statustext_time += dtime;
+
+ if (m_statustext_time >= statustext_time_max) {
+ clearStatusText();
+ m_statustext_time = 0.0f;
+ }
+ }
+
+ setStaticText(m_guitext_status, translate_string(m_statustext).c_str());
+ m_guitext_status->setVisible(!m_statustext.empty());
+
+ if (!m_statustext.empty()) {
+ s32 status_width = m_guitext_status->getTextWidth();
+ s32 status_height = m_guitext_status->getTextHeight();
+ s32 status_y = screensize.Y - 150;
+ s32 status_x = (screensize.X - status_width) / 2;
+
+ m_guitext_status->setRelativePosition(core::rect<s32>(status_x ,
+ status_y - status_height, status_x + status_width, status_y));
+
+ // Fade out
+ video::SColor initial_color(255, 0, 0, 0);
+
+ if (guienv->getSkin())
+ initial_color = guienv->getSkin()->getColor(gui::EGDC_BUTTON_TEXT);
+
+ video::SColor final_color = initial_color;
+ final_color.setAlpha(0);
+ video::SColor fade_color = initial_color.getInterpolated_quadratic(
+ initial_color, final_color,
+ pow(m_statustext_time / statustext_time_max, 2.0f));
+ m_guitext_status->setOverrideColor(fade_color);
+ m_guitext_status->enableOverrideColor(true);
+ }
}
void GameUI::initFlags()
float jump_timer;
float damage_flash;
float update_draw_list_timer;
- float statustext_time;
f32 fog_range;
const ToolCapabilities &playeritem_toolcap, f32 dtime);
void updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
const CameraOrientation &cam);
- void updateGui(const RunStats &stats, f32 dtime, const CameraOrientation &cam);
void updateProfilerGraphs(ProfilerGraph *graph);
// Misc
/* GUI stuff
*/
- gui::IGUIStaticText *guitext_status;
gui::IGUIStaticText *guitext_chat; // Chat text
gui::IGUIStaticText *guitext_profiler; // Profiler text
- std::wstring m_statustext;
-
KeyCache keycache;
IntervalLimiter profiler_interval;
{
m_game_ui->init();
- // Status text (displays info when showing and hiding GUI stuff, etc.)
- guitext_status = gui::StaticText::add(guienv,
- L"<Status>",
- core::rect<s32>(0, 0, 0, 0),
- false, false, guiroot);
- guitext_status->setVisible(false);
-
// Chat text
guitext_chat = gui::StaticText::add(
guienv,
showStatusTextSimple("Sound muted");
else
showStatusTextSimple("Sound unmuted");
- runData.statustext_time = 0;
} else if (wasKeyDown(KeyType::INC_VOLUME)) {
float new_volume = rangelim(g_settings->getFloat("sound_volume") + 0.1f, 0.0f, 1.0f);
wchar_t buf[100];
const wchar_t *str = wgettext("Volume changed to %d%%");
swprintf(buf, sizeof(buf) / sizeof(wchar_t), str, myround(new_volume * 100));
delete[] str;
- m_statustext = buf;
- runData.statustext_time = 0;
+ m_game_ui->showStatusText(buf);
} else if (wasKeyDown(KeyType::DEC_VOLUME)) {
float new_volume = rangelim(g_settings->getFloat("sound_volume") - 0.1f, 0.0f, 1.0f);
wchar_t buf[100];
const wchar_t *str = wgettext("Volume changed to %d%%");
swprintf(buf, sizeof(buf) / sizeof(wchar_t), str, myround(new_volume * 100));
delete[] str;
- m_statustext = buf;
- runData.statustext_time = 0;
+ m_game_ui->showStatusText(buf);
} else if (wasKeyDown(KeyType::CINEMATIC)) {
toggleCinematic();
} else if (wasKeyDown(KeyType::SCREENSHOT)) {
}
if (quicktune->hasMessage()) {
- m_statustext = utf8_to_wide(quicktune->getMessage());
- runData.statustext_time = 0.0f;
+ m_game_ui->showStatusText(utf8_to_wide(quicktune->getMessage()));
}
}
bool free_move = !g_settings->getBool("free_move");
g_settings->set("free_move", bool_to_cstr(free_move));
- runData.statustext_time = 0;
-
if (free_move) {
if (client->checkPrivilege("fly")) {
showStatusTextSimple("Fly mode enabled");
bool fast_move = !g_settings->getBool("fast_move");
g_settings->set("fast_move", bool_to_cstr(fast_move));
- runData.statustext_time = 0;
-
if (fast_move) {
if (client->checkPrivilege("fast")) {
showStatusTextSimple("Fast mode enabled");
bool noclip = !g_settings->getBool("noclip");
g_settings->set("noclip", bool_to_cstr(noclip));
- runData.statustext_time = 0;
if (noclip) {
if (client->checkPrivilege("noclip")) {
showStatusTextSimple("Noclip mode enabled");
bool cinematic = !g_settings->getBool("cinematic");
g_settings->set("cinematic", bool_to_cstr(cinematic));
- runData.statustext_time = 0;
if (cinematic)
showStatusTextSimple("Cinematic mode enabled");
else
bool autorun_enabled = !g_settings->getBool("continuous_forward");
g_settings->set("continuous_forward", bool_to_cstr(autorun_enabled));
- runData.statustext_time = 0;
if (autorun_enabled)
showStatusTextSimple("Automatic forwards enabled");
else
void Game::toggleChat()
{
m_game_ui->m_flags.show_chat = !m_game_ui->m_flags.show_chat;
- runData.statustext_time = 0;
if (m_game_ui->m_flags.show_chat)
showStatusTextSimple("Chat shown");
else
void Game::toggleHud()
{
m_game_ui->m_flags.show_hud = !m_game_ui->m_flags.show_hud;
- runData.statustext_time = 0;
if (m_game_ui->m_flags.show_hud)
showStatusTextSimple("HUD shown");
else
showStatusTextSimple("Minimap currently disabled by game or mod");
}
- runData.statustext_time = 0;
mapper->setMinimapMode(mode);
}
void Game::toggleFog()
{
m_game_ui->m_flags.force_fog_off = !m_game_ui->m_flags.force_fog_off;
- runData.statustext_time = 0;
- if (m_game_ui->m_flags.force_fog_off)
- showStatusTextSimple("Fog disabled");
- else
- showStatusTextSimple("Fog enabled");
+ if (m_game_ui->m_flags.force_fog_off)
+ showStatusTextSimple("Fog disabled");
+ else
+ showStatusTextSimple("Fog enabled");
}
showStatusTextSimple("Debug info and profiler graph hidden");
}
}
- runData.statustext_time = 0;
}
void Game::toggleUpdateCamera()
{
m_game_ui->m_flags.disable_camera_update = !m_game_ui->m_flags.disable_camera_update;
- runData.statustext_time = 0;
if (m_game_ui->m_flags.disable_camera_update)
showStatusTextSimple("Camera update disabled");
else
runData.profiler_current_page,
runData.profiler_max_page);
delete[] str;
- m_statustext = buf;
+ m_game_ui->showStatusText(buf);
} else {
showStatusTextSimple("Profiler hidden");
}
- runData.statustext_time = 0;
}
str = wgettext("Viewing range is at maximum: %d");
swprintf(buf, sizeof(buf) / sizeof(wchar_t), str, range_new);
delete[] str;
- m_statustext = buf;
+ m_game_ui->showStatusText(buf);
} else {
str = wgettext("Viewing range changed to %d");
swprintf(buf, sizeof(buf) / sizeof(wchar_t), str, range_new);
delete[] str;
- m_statustext = buf;
+ m_game_ui->showStatusText(buf);
}
g_settings->set("viewing_range", itos(range_new));
- runData.statustext_time = 0;
}
str = wgettext("Viewing range is at minimum: %d");
swprintf(buf, sizeof(buf) / sizeof(wchar_t), str, range_new);
delete[] str;
- m_statustext = buf;
+ m_game_ui->showStatusText(buf);
} else {
str = wgettext("Viewing range changed to %d");
swprintf(buf, sizeof(buf) / sizeof(wchar_t), str, range_new);
delete[] str;
- m_statustext = buf;
+ m_game_ui->showStatusText(buf);
}
g_settings->set("viewing_range", itos(range_new));
- runData.statustext_time = 0;
}
void Game::toggleFullViewRange()
{
draw_control->range_all = !draw_control->range_all;
- runData.statustext_time = 0;
if (draw_control->range_all)
showStatusTextSimple("Enabled unlimited viewing range");
else
runData.update_draw_list_last_cam_dir = camera_direction;
}
- updateGui(*stats, dtime, cam);
+ m_game_ui->update(*stats, client, draw_control, cam, runData.pointed_old, dtime);
/*
make sure menu is on top
g_profiler->graphAdd("mainloop_draw", stats->drawtime / 1000.0f);
}
-
-void Game::updateGui(const RunStats &stats, f32 dtime, const CameraOrientation &cam)
-{
- v2u32 screensize = RenderingEngine::get_instance()->getWindowSize();
-
- m_game_ui->update(stats, client, draw_control, cam, runData.pointed_old);
-
- float statustext_time_max = 1.5;
-
- if (!m_statustext.empty()) {
- runData.statustext_time += dtime;
-
- if (runData.statustext_time >= statustext_time_max) {
- m_statustext = L"";
- runData.statustext_time = 0;
- }
- }
-
- setStaticText(guitext_status, translate_string(m_statustext).c_str());
- guitext_status->setVisible(!m_statustext.empty());
-
- if (!m_statustext.empty()) {
- s32 status_width = guitext_status->getTextWidth();
- s32 status_height = guitext_status->getTextHeight();
- s32 status_y = screensize.Y - 150;
- s32 status_x = (screensize.X - status_width) / 2;
- core::rect<s32> rect(
- status_x , status_y - status_height,
- status_x + status_width, status_y
- );
- guitext_status->setRelativePosition(rect);
-
- // Fade out
- video::SColor initial_color(255, 0, 0, 0);
-
- if (guienv->getSkin())
- initial_color = guienv->getSkin()->getColor(gui::EGDC_BUTTON_TEXT);
-
- video::SColor final_color = initial_color;
- final_color.setAlpha(0);
- video::SColor fade_color = initial_color.getInterpolated_quadratic(
- initial_color, final_color,
- pow(runData.statustext_time / statustext_time_max, 2.0f));
- guitext_status->setOverrideColor(fade_color);
- guitext_status->enableOverrideColor(true);
- }
-}
-
-
/* Log times and stuff for visualization */
inline void Game::updateProfilerGraphs(ProfilerGraph *graph)
{
void Game::showStatusTextSimple(const char *msg)
{
const wchar_t *wmsg = wgettext(msg);
- m_statustext = wmsg;
+ m_game_ui->showStatusText(wmsg);
delete[] wmsg;
}