From fe34750f02cca85618be9a60d87acf43ed3a6dcf Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sat, 20 Jul 2024 02:14:13 +0200 Subject: [PATCH] :bulb: Added "Must restart game..." banner to Render Settings UI --- source/main/gui/panels/GUI_GameSettings.cpp | 37 +++++++++++++++++++-- source/main/gui/panels/GUI_GameSettings.h | 5 +++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/source/main/gui/panels/GUI_GameSettings.cpp b/source/main/gui/panels/GUI_GameSettings.cpp index 00c4e447a5..56a83ae475 100644 --- a/source/main/gui/panels/GUI_GameSettings.cpp +++ b/source/main/gui/panels/GUI_GameSettings.cpp @@ -38,6 +38,11 @@ void GameSettings::Draw() { const int flags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar; ImGui::SetNextWindowSize(ImVec2(670.f, 400.f), ImGuiCond_FirstUseEver); + if (m_bump_height != 0) + { + ImGui::SetNextWindowSize(m_window_size + ImVec2(0, m_bump_height)); + m_bump_height = 0.f; + } ImGui::SetNextWindowPosCenter(ImGuiCond_Appearing); bool keep_open = true; ImGui::Begin(_LC("GameSettings", "Game settings"), &keep_open, flags); @@ -101,6 +106,7 @@ void GameSettings::Draw() ImGui::EndTabBar(); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 4.f); + m_window_size = ImGui::GetWindowSize(); ImGui::End(); if (!keep_open) @@ -113,6 +119,19 @@ void GameSettings::DrawRenderSystemSettings() { ImGui::TextDisabled("%s", _LC("GameSettings", "Render system (changes require a restart)")); + if (m_render_must_restart) + { + std::string text = _LC("GameSettings", "You must restart the game to make changes effective."); + ImVec2 box_size = ImGui::CalcTextSize(text.c_str()) + ImGui::GetStyle().FramePadding * 2; + ImVec2 box_pos = ImGui::GetCursorPos() + ImVec2(ImGui::GetWindowContentRegionWidth() * 0.5f - box_size.x * 0.5f, 0.f); + ImGui::SetCursorPos(box_pos); + ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0.8f, 0.7f, 0.1f, 1.f)); + ImGui::BeginChildFrame(ImGuiID(123), box_size); + ImGui::TextColored(ImVec4(0.1f, 0.1f, 0.1f, 1.f), text.c_str()); + ImGui::EndChildFrame(); + ImGui::PopStyleColor(); // FrameBg + } + const auto ogre_root = App::GetAppContext()->GetOgreRoot(); const auto render_systems = ogre_root->getAvailableRenderers(); std::string render_system_names; @@ -152,10 +171,22 @@ void GameSettings::DrawRenderSystemSettings() int option_id = it != co.possibleValues.end() ? std::distance(co.possibleValues.begin(), it) : 0; if (ImGui::Combo(co.name.c_str(), &option_id, option_values.c_str())) { - rs->setConfigOption(co.name, co.possibleValues[option_id]); - if (rs->validateConfigOptions().empty()) + // Check the new value is different from the current one + if (co.currentValue != co.possibleValues[option_id]) { - ogre_root->saveConfig(); + // Set the new value to the render system + rs->setConfigOption(co.name, co.possibleValues[option_id]); + if (rs->validateConfigOptions().empty()) + { + ogre_root->saveConfig(); + + // Show the "Must restart game..." box, make the window bigger to accomodate it + if (!m_render_must_restart) + { + m_render_must_restart = true; + m_bump_height = ImGui::GetTextLineHeightWithSpacing() + ImGui::GetStyle().FramePadding.y * 2; + } + } } } } diff --git a/source/main/gui/panels/GUI_GameSettings.h b/source/main/gui/panels/GUI_GameSettings.h index 94bf4aa5c0..775e939594 100644 --- a/source/main/gui/panels/GUI_GameSettings.h +++ b/source/main/gui/panels/GUI_GameSettings.h @@ -44,6 +44,7 @@ class GameSettings // GUI state bool m_is_visible = false; + ImVec2 m_window_size = ImVec2(0, 0); // Buffers for text input boxes Str<1000> m_buf_diag_preset_terrain; @@ -62,6 +63,10 @@ class GameSettings std::string m_combo_items_water_mode; std::string m_combo_items_extcam_mode; std::string m_combo_items_input_grab; + + // Render settings + bool m_render_must_restart = false; + float m_bump_height = 0.0f; }; } // namespace GUI