diff --git a/src/client/game.cpp b/src/client/game.cpp index aa89d1727..94729fb97 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -2297,7 +2297,7 @@ void Game::toggleMinimap(bool shift_pressed) u32 hud_flags = client->getEnv().getLocalPlayer()->hud_flags; if (!(hud_flags & HUD_FLAG_MINIMAP_VISIBLE)) { - m_game_ui->m_flags.show_minimap = false; + m_game_ui->showMinimap(false); } else { // If radar is disabled, try to find a non radar mode or fall back to 0 @@ -2306,8 +2306,7 @@ void Game::toggleMinimap(bool shift_pressed) mapper->getModeDef().type == MINIMAP_TYPE_RADAR) mapper->nextMode(); - m_game_ui->m_flags.show_minimap = mapper->getModeDef().type != - MINIMAP_TYPE_OFF; + m_game_ui->showMinimap(mapper->getModeDef().type != MINIMAP_TYPE_OFF); } // <-- // End of 'not so satifying code' @@ -2357,6 +2356,9 @@ void Game::toggleDebug() m_game_ui->showTranslatedStatusText("Debug info and profiler graph hidden"); } } + + // Update the chat text as it may need changing because of rounded screens + m_game_ui->m_chat_text_needs_update = true; } diff --git a/src/client/gameui.cpp b/src/client/gameui.cpp index 074591dee..64b57e581 100644 --- a/src/client/gameui.cpp +++ b/src/client/gameui.cpp @@ -124,20 +124,20 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_ << (draw_control->range_all ? "All" : itos(draw_control->wanted_range)) << std::setprecision(2) << " | RTT: " << (client->getRTT() * 1000.0f) << "ms"; - } else { - os << std::setprecision(1) << std::fixed - << "X: " << (player_position.X / BS) - << ", Y: " << (player_position.Y / BS) - << ", Z: " << (player_position.Z / BS); - } - m_guitext->setText(utf8_to_wide(os.str()).c_str()); + } else if (m_flags.show_minimap) { + os << std::setprecision(1) << std::fixed + << "X: " << (player_position.X / BS) + << ", Y: " << (player_position.Y / BS) + << ", Z: " << (player_position.Z / BS); + } + m_guitext->setText(utf8_to_wide(os.str()).c_str()); - m_guitext->setRelativePosition(core::rect( - 5 + client->getRoundScreen(), 5, - screensize.X, 5 + g_fontengine->getTextHeight())); + m_guitext->setRelativePosition(core::rect( + 5 + client->getRoundScreen(), 5, + screensize.X, 5 + g_fontengine->getTextHeight())); // Finally set the guitext visible depending on the flag - m_guitext->setVisible(m_flags.show_hud); + m_guitext->setVisible(m_flags.show_hud && (m_flags.show_debug || m_flags.show_minimap)); if (m_flags.show_debug) { std::ostringstream os(std::ios_base::binary); @@ -209,6 +209,30 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_ m_guitext_status->enableOverrideColor(true); } + // Update chat text + if (m_chat_text_needs_update) { + m_chat_text_needs_update = false; + if ((!m_flags.show_hud || (!m_flags.show_debug && !m_flags.show_minimap)) && + client->getRoundScreen() > 0) { + // Cache the space count + if (!m_space_count) { + // Use spaces to shift the text + const u32 spwidth = g_fontengine->getFont()->getDimension(L" ").Width; + // Divide and round up + m_space_count = (client->getRoundScreen() + spwidth - 1) / spwidth; + } + + EnrichedString padded_chat_text; + for (int i = 0; i < m_space_count; i++) + padded_chat_text.addCharNoColor(L' '); + + padded_chat_text += m_chat_text; + setStaticText(m_guitext_chat, padded_chat_text); + } else { + setStaticText(m_guitext_chat, m_chat_text); + } + } + // Hide chat when console is visible m_guitext_chat->setVisible(isChatVisible() && !chat_console->isVisible()); } @@ -221,6 +245,7 @@ void GameUI::initFlags() void GameUI::showMinimap(bool show) { + m_chat_text_needs_update = m_chat_text_needs_update || show != m_flags.show_minimap; m_flags.show_minimap = show; } @@ -233,18 +258,22 @@ void GameUI::showTranslatedStatusText(const char *str) void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count) { - setStaticText(m_guitext_chat, chat_text); - + m_chat_text = chat_text; + m_chat_text_needs_update = true; m_recent_chat_count = recent_chat_count; } void GameUI::updateChatSize() { // Update gui element size and position - s32 chat_y = 5 + g_fontengine->getLineHeight();; + s32 chat_y = 5; - if (m_flags.show_debug) - chat_y += g_fontengine->getLineHeight(); + if (m_flags.show_hud) { + if (m_flags.show_debug) + chat_y += g_fontengine->getLineHeight() * 2; + else if (m_flags.show_minimap) + chat_y += g_fontengine->getLineHeight(); + } const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize(); @@ -302,6 +331,7 @@ void GameUI::toggleHud() showTranslatedStatusText("HUD shown"); else showTranslatedStatusText("HUD hidden"); + m_chat_text_needs_update = true; } void GameUI::toggleProfiler() diff --git a/src/client/gameui.h b/src/client/gameui.h index 9eaa679c4..ecd9713d7 100644 --- a/src/client/gameui.h +++ b/src/client/gameui.h @@ -121,6 +121,9 @@ private: video::SColor m_statustext_initial_color; gui::IGUIStaticText *m_guitext_chat = nullptr; // Chat text + EnrichedString m_chat_text; + bool m_chat_text_needs_update = false; + int m_space_count = 0; u32 m_recent_chat_count = 0; core::rect m_current_chat_size{0, 0, 0, 0};