diff options
Diffstat (limited to 'src/client/gameui.cpp')
-rw-r--r-- | src/client/gameui.cpp | 156 |
1 files changed, 78 insertions, 78 deletions
diff --git a/src/client/gameui.cpp b/src/client/gameui.cpp index b72fcd999..a9057052e 100644 --- a/src/client/gameui.cpp +++ b/src/client/gameui.cpp @@ -34,7 +34,8 @@ with this program; if not, write to the Free Software Foundation, Inc., inline static const char *yawToDirectionString(int yaw) { - static const char *direction[4] = {"North +Z", "West -X", "South -Z", "East +X"}; + static const char *direction[4] = + {"North +Z", "West -X", "South -Z", "East +X"}; yaw = wrapDegrees_0_360(yaw); yaw = (yaw + 45) % 360 / 90; @@ -45,58 +46,56 @@ inline static const char *yawToDirectionString(int yaw) GameUI::GameUI() { if (guienv && guienv->getSkin()) - m_statustext_initial_color = - guienv->getSkin()->getColor(gui::EGDC_BUTTON_TEXT); + m_statustext_initial_color = guienv->getSkin()->getColor(gui::EGDC_BUTTON_TEXT); else m_statustext_initial_color = video::SColor(255, 0, 0, 0); + } void GameUI::init() { - m_guitext_coords = gui::StaticText::add( - guienv, L"", core::rect<s32>(0, 0, 0, 0), false, false, guiroot); - + m_guitext_coords = gui::StaticText::add(guienv, L"", core::rect<s32>(0, 0, 0, 0), false, + false, guiroot); + // First line of debug text m_guitext = gui::StaticText::add(guienv, utf8_to_wide(PROJECT_NAME_C).c_str(), - core::rect<s32>(0, 0, 0, 0), false, false, guiroot); + core::rect<s32>(0, 0, 0, 0), false, false, guiroot); // Second line of debug text - m_guitext2 = gui::StaticText::add( - guienv, L"", core::rect<s32>(0, 0, 0, 0), false, false, guiroot); + m_guitext2 = gui::StaticText::add(guienv, L"", core::rect<s32>(0, 0, 0, 0), false, + false, guiroot); // At the middle of the screen // Object infos are shown in this 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); + 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); + core::rect<s32>(0, 0, 0, 0), false, false, guiroot); m_guitext_status->setVisible(false); // Chat text 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); + //false, false); // Disable word wrap as of now + false, true, guiroot); u16 chat_font_size = g_settings->getU16("chat_font_size"); if (chat_font_size != 0) { - m_guitext_chat->setOverrideFont( - g_fontengine->getFont(chat_font_size, FM_Unspecified)); + m_guitext_chat->setOverrideFont(g_fontengine->getFont( + chat_font_size, FM_Unspecified)); } // 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); + core::rect<s32>(0, 0, 0, 0), false, false, guiroot); m_guitext_profiler->setOverrideFont(g_fontengine->getFont( - g_fontengine->getDefaultFontSize() * 0.9f, FM_Mono)); + g_fontengine->getDefaultFontSize() * 0.9f, FM_Mono)); m_guitext_profiler->setVisible(false); } void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_control, - const CameraOrientation &cam, const PointedThing &pointed_old, - const GUIChatConsole *chat_console, float dtime) + const CameraOrientation &cam, const PointedThing &pointed_old, + const GUIChatConsole *chat_console, float dtime) { LocalPlayer *player = client->getEnv().getLocalPlayer(); v3f player_position = player->getPosition(); @@ -106,15 +105,14 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_ if (show_coords) { std::ostringstream os(std::ios_base::binary); - os << std::setprecision(1) << std::fixed << (player_position.X / BS) - << ", " << (player_position.Y / BS) << ", " - << (player_position.Z / BS); + os << std::setprecision(1) << std::fixed + << (player_position.X / BS) + << ", " << (player_position.Y / BS) + << ", " << (player_position.Z / BS); setStaticText(m_guitext_coords, utf8_to_wide(os.str()).c_str()); - m_guitext_coords->setRelativePosition(core::rect<s32>(5, - screensize.Y - 5 - g_fontengine->getTextHeight(), - screensize.X, screensize.Y)); + m_guitext_coords->setRelativePosition(core::rect<s32>(5, screensize.Y - 5 - g_fontengine->getTextHeight(), screensize.X, screensize.Y)); } - + m_guitext_coords->setVisible(show_coords); if (m_flags.show_debug) { @@ -123,17 +121,23 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_ u16 fps = 1.0 / stats.dtime_jitter.avg; std::ostringstream os(std::ios_base::binary); - os << std::fixed << PROJECT_NAME_C " " << g_version_hash - << " | FPS: " << fps << std::setprecision(0) - << " | drawtime: " << drawtime_avg << "ms" << std::setprecision(1) - << " | dtime jitter: " << (stats.dtime_jitter.max_fraction * 100.0) - << "%" << std::setprecision(1) << " | view range: " - << (draw_control->range_all ? "All" : itos(draw_control->wanted_range)) - << std::setprecision(3) << " | RTT: " << client->getRTT() << "s"; + os << std::fixed + << PROJECT_NAME_C " " << g_version_hash + << " | FPS: " << fps + << std::setprecision(0) + << " | drawtime: " << drawtime_avg << "ms" + << std::setprecision(1) + << " | dtime jitter: " + << (stats.dtime_jitter.max_fraction * 100.0) << "%" + << std::setprecision(1) + << " | view range: " + << (draw_control->range_all ? "All" : itos(draw_control->wanted_range)) + << std::setprecision(3) + << " | RTT: " << client->getRTT() << "s"; setStaticText(m_guitext, utf8_to_wide(os.str()).c_str()); - m_guitext->setRelativePosition(core::rect<s32>( - 5, 5, screensize.X, 5 + g_fontengine->getTextHeight())); + m_guitext->setRelativePosition(core::rect<s32>(5, 5, screensize.X, + 5 + g_fontengine->getTextHeight())); } // Finally set the guitext visible depending on the flag @@ -141,31 +145,32 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_ if (m_flags.show_debug) { std::ostringstream os(std::ios_base::binary); - os << std::setprecision(1) << std::fixed << "pos: (" - << (player_position.X / BS) << ", " << (player_position.Y / BS) << ", " - << (player_position.Z / BS) - << ") | yaw: " << (wrapDegrees_0_360(cam.camera_yaw)) << "\xC2\xB0 " - << yawToDirectionString(cam.camera_yaw) - << " | pitch: " << (-wrapDegrees_180(cam.camera_pitch)) << "\xC2\xB0" - << " | seed: " << ((u64)client->getMapSeed()); + os << std::setprecision(1) << std::fixed + << "pos: (" << (player_position.X / BS) + << ", " << (player_position.Y / BS) + << ", " << (player_position.Z / BS) + << ") | yaw: " << (wrapDegrees_0_360(cam.camera_yaw)) << "\xC2\xB0 " + << yawToDirectionString(cam.camera_yaw) + << " | pitch: " << (-wrapDegrees_180(cam.camera_pitch)) << "\xC2\xB0" + << " | seed: " << ((u64)client->getMapSeed()); if (pointed_old.type == POINTEDTHING_NODE) { ClientMap &map = client->getEnv().getClientMap(); const NodeDefManager *nodedef = client->getNodeDefManager(); MapNode n = map.getNode(pointed_old.node_undersurface); - if (n.getContent() != CONTENT_IGNORE && - nodedef->get(n).name != "unknown") { + if (n.getContent() != CONTENT_IGNORE && nodedef->get(n).name != "unknown") { os << ", pointed: " << nodedef->get(n).name - << ", param2: " << (u64)n.getParam2(); + << ", param2: " << (u64) n.getParam2(); } } setStaticText(m_guitext2, utf8_to_wide(os.str()).c_str()); m_guitext2->setRelativePosition(core::rect<s32>(5, - 5 + g_fontengine->getTextHeight(), screensize.X, - 5 + g_fontengine->getTextHeight() * 2)); + 5 + g_fontengine->getTextHeight(), screensize.X, + 5 + g_fontengine->getTextHeight() * 2 + )); } m_guitext2->setVisible(m_flags.show_debug); @@ -188,22 +193,19 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_ m_guitext_status->setVisible(!m_statustext.empty()); if (!m_statustext.empty()) { - s32 status_width = m_guitext_status->getTextWidth(); + 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)); + m_guitext_status->setRelativePosition(core::rect<s32>(status_x , + status_y - status_height, status_x + status_width, status_y)); // Fade out video::SColor final_color = m_statustext_initial_color; final_color.setAlpha(0); - video::SColor fade_color = - m_statustext_initial_color.getInterpolated_quadratic( - m_statustext_initial_color, final_color, - m_statustext_time / statustext_time_max); + video::SColor fade_color = m_statustext_initial_color.getInterpolated_quadratic( + m_statustext_initial_color, final_color, m_statustext_time / statustext_time_max); m_guitext_status->setOverrideColor(fade_color); m_guitext_status->enableOverrideColor(true); } @@ -233,17 +235,18 @@ void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count) { // Update gui element size and position - + const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize(); - + s32 chat_y = window_size.Y - 150 - m_guitext_chat->getTextHeight(); if (m_flags.show_debug) chat_y += 2 * g_fontengine->getLineHeight(); - core::rect<s32> chat_size(10, chat_y, window_size.X - 20, 0); - chat_size.LowerRightCorner.Y = std::min( - (s32)window_size.Y, m_guitext_chat->getTextHeight() + chat_y); + core::rect<s32> chat_size(10, chat_y, + window_size.X - 20, 0); + chat_size.LowerRightCorner.Y = std::min((s32)window_size.Y, + m_guitext_chat->getTextHeight() + chat_y); m_guitext_chat->setRelativePosition(chat_size); setStaticText(m_guitext_chat, chat_text); @@ -255,27 +258,24 @@ void GameUI::updateProfiler() { if (m_profiler_current_page != 0) { std::ostringstream os(std::ios_base::binary); - os << " Profiler page " << (int)m_profiler_current_page - << ", elapsed: " << g_profiler->getElapsedMs() << " ms)" << std::endl; + os << " Profiler page " << (int)m_profiler_current_page << + ", elapsed: " << g_profiler->getElapsedMs() << " ms)" << std::endl; - int lines = g_profiler->print( - os, m_profiler_current_page, m_profiler_max_page); + int lines = g_profiler->print(os, m_profiler_current_page, m_profiler_max_page); ++lines; EnrichedString str(utf8_to_wide(os.str())); str.setBackground(video::SColor(120, 0, 0, 0)); setStaticText(m_guitext_profiler, str); - core::dimension2d<u32> size = - m_guitext_profiler->getOverrideFont()->getDimension( - str.c_str()); + core::dimension2d<u32> size = m_guitext_profiler->getOverrideFont()-> + getDimension(str.c_str()); core::position2di upper_left(6, 50); core::position2di lower_right = upper_left; lower_right.X += size.Width + 10; - lower_right.Y += size.Height; + lower_right.Y += size.Height; - m_guitext_profiler->setRelativePosition( - core::rect<s32>(upper_left, lower_right)); + m_guitext_profiler->setRelativePosition(core::rect<s32>(upper_left, lower_right)); } m_guitext_profiler->setVisible(m_profiler_current_page != 0); @@ -310,17 +310,16 @@ void GameUI::toggleHud() void GameUI::toggleProfiler() { - m_profiler_current_page = - (m_profiler_current_page + 1) % (m_profiler_max_page + 1); + m_profiler_current_page = (m_profiler_current_page + 1) % (m_profiler_max_page + 1); // FIXME: This updates the profiler with incomplete values updateProfiler(); 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, m_profiler_current_page, - m_profiler_max_page); + const wchar_t* str = wgettext("Profiler shown (page %d of %d)"); + swprintf(buf, sizeof(buf) / sizeof(wchar_t), str, + m_profiler_current_page, m_profiler_max_page); delete[] str; showStatusText(buf); } else { @@ -328,6 +327,7 @@ void GameUI::toggleProfiler() } } + void GameUI::deleteFormspec() { if (m_formspec) { |