From fc845d355f7c431199fdd2e57d17221e84441e77 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 17 Sep 2023 01:37:01 +0200 Subject: [PATCH] CConsole: Fix reset hack and optimize Don't update the view once we already found the 'active' object, or if we are at the park position (-1). This fixes the hack of having to have CConsole::m_bSuggestMoved to be true all the time. --- r5dev/gameui/IConsole.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/r5dev/gameui/IConsole.cpp b/r5dev/gameui/IConsole.cpp index 67830a2d..81574deb 100644 --- a/r5dev/gameui/IConsole.cpp +++ b/r5dev/gameui/IConsole.cpp @@ -395,6 +395,8 @@ void CConsole::SuggestPanel(void) ImGui::Begin("##suggest", nullptr, m_nSuggestFlags); ImGui::PushAllowKeyboardFocus(false); + bool bViewChanged = false; + for (size_t i = 0, ns = m_vSuggest.size(); i < ns; i++) { const CSuggest& suggest = m_vSuggest[i]; @@ -464,13 +466,11 @@ void CConsole::SuggestPanel(void) ImGui::PopID(); // Update the suggest position - if (m_bSuggestMoved) + if (m_bSuggestMoved && !bViewChanged) { ImGuiWindow* const pWindow = ImGui::GetCurrentWindow(); ImRect imRect = ImGui::GetCurrentContext()->LastItemData.Rect; - bool bChanged = false; - if (bIsIndexActive) // Bring the 'active' element into view { // Reset to keep flag in display. @@ -481,7 +481,7 @@ void CConsole::SuggestPanel(void) imRect.Min.y += 1; imRect.Max.y -= 1; - bChanged = true; + bViewChanged = true; } else if (m_nSuggestPos == -1) // Reset position; -1 = no active element. { @@ -490,18 +490,21 @@ void CConsole::SuggestPanel(void) imRect.Min.y = 0; imRect.Max.y = 0; - bChanged = true; + bViewChanged = true; } - if (bChanged) + if (bViewChanged) { ImGui::ScrollToRect(pWindow, imRect); } - - m_bSuggestMoved = true; } } + if (bViewChanged) + { + m_bSuggestMoved = false; + } + ImGui::PopAllowKeyboardFocus(); ImGui::End(); } @@ -587,6 +590,7 @@ bool CConsole::AutoComplete(void) void CConsole::ResetAutoComplete(void) { m_bSuggestActive = false; + m_bSuggestMoved = true; m_nSuggestPos = -1; }