From 6f534e981198f2205bf74a6a4aa836c173772d24 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 23 Nov 2024 00:09:21 +0100 Subject: [PATCH] ImGui: readjust and fix imgui keybind configuration In commit f5f14c153f0115af7a0ac5fe3b4be98b3816be84, a change was made to switch the default keys to pgup and pgdown. It appears however that these keys were used for the chat window. The defaults have been adjusted to (backtick and f10) for console, and (insert and f11) for the browser. There was also a bug in ImGuiConfig::Save() where it double nested the keyvalues, this has also been fixed. The keyvalue file now parser properly. The option panel in the console has been slightly reworked to also show the secondary binding options for both the console als browser allowing the user to change both the primary and secondary for both windows without having to manually edit the files. --- src/gameui/IConsole.cpp | 47 +++++++++++++++++---- src/thirdparty/imgui/misc/imgui_utility.cpp | 23 +++++----- src/thirdparty/imgui/misc/imgui_utility.h | 12 ++++-- 3 files changed, 58 insertions(+), 24 deletions(-) diff --git a/src/gameui/IConsole.cpp b/src/gameui/IConsole.cpp index f1b41e7b..9cc83038 100644 --- a/src/gameui/IConsole.cpp +++ b/src/gameui/IConsole.cpp @@ -353,37 +353,66 @@ void CConsole::DrawOptionsPanel(void) ImGui::Checkbox("Auto-scroll", &m_colorTextLogger.m_bAutoScroll); ImGui::SameLine(); - ImGui::PushItemWidth(100); + ImGui::Spacing(); + ImGui::SameLine(); - ImGui::PopItemWidth(); - - if (ImGui::SmallButton("Clear")) + if (ImGui::SmallButton("Clear Text")) { ClearLog(); } + ImGui::SameLine(); + ImGui::Spacing(); ImGui::SameLine(); // Copies all logged text to the clip board - if (ImGui::SmallButton("Copy")) + if (ImGui::SmallButton("Copy Text")) { AUTO_LOCK(m_colorTextLoggerMutex); m_colorTextLogger.Copy(true); } - ImGui::Text("Console hotkey:"); + ImGui::Text("Console HotKey:"); ImGui::SameLine(); - if (ImGui::Hotkey("##ToggleConsole", &g_ImGuiConfig.m_ConsoleConfig.m_nBind0, ImVec2(80, 80))) + int selected = g_ImGuiConfig.m_ConsoleConfig.m_nBind0; + + if (ImGui::Hotkey("##ToggleConsolePrimary", &selected, ImVec2(80, 80)) && + !g_ImGuiConfig.KeyUsed(selected)) { + g_ImGuiConfig.m_ConsoleConfig.m_nBind0 = selected; g_ImGuiConfig.Save(); } - ImGui::Text("Browser hotkey:"); + ImGui::SameLine(); + selected = g_ImGuiConfig.m_ConsoleConfig.m_nBind1; + + if (ImGui::Hotkey("##ToggleConsoleSecondary", &selected, ImVec2(80, 80)) && + !g_ImGuiConfig.KeyUsed(selected)) + { + g_ImGuiConfig.m_ConsoleConfig.m_nBind1 = selected; + g_ImGuiConfig.Save(); + } + + ImGui::Text("Browser HotKey:"); ImGui::SameLine(); - if (ImGui::Hotkey("##ToggleBrowser", &g_ImGuiConfig.m_BrowserConfig.m_nBind0, ImVec2(80, 80))) + selected = g_ImGuiConfig.m_BrowserConfig.m_nBind0; + + if (ImGui::Hotkey("##ToggleBrowserPrimary", &selected, ImVec2(80, 80)) && + !g_ImGuiConfig.KeyUsed(selected)) { + g_ImGuiConfig.m_BrowserConfig.m_nBind0 = selected; + g_ImGuiConfig.Save(); + } + + ImGui::SameLine(); + selected = g_ImGuiConfig.m_BrowserConfig.m_nBind1; + + if (ImGui::Hotkey("##ToggleBrowserSecondary", &selected, ImVec2(80, 80)) && + !g_ImGuiConfig.KeyUsed(selected)) + { + g_ImGuiConfig.m_BrowserConfig.m_nBind1 = selected; g_ImGuiConfig.Save(); } diff --git a/src/thirdparty/imgui/misc/imgui_utility.cpp b/src/thirdparty/imgui/misc/imgui_utility.cpp index c8c988e2..546c76c5 100644 --- a/src/thirdparty/imgui/misc/imgui_utility.cpp +++ b/src/thirdparty/imgui/misc/imgui_utility.cpp @@ -28,15 +28,15 @@ void ImGuiConfig::Load() KeyValues* pConsoleKV = pKeyMapKV->FindKey(GAME_CONSOLE_KEY); if (pConsoleKV) { - m_ConsoleConfig.m_nBind0 = pConsoleKV->GetInt("$bindDef", VK_OEM_3); - m_ConsoleConfig.m_nBind1 = pConsoleKV->GetInt("$bindExt", VK_INSERT); - } + m_ConsoleConfig.m_nBind0 = pConsoleKV->GetInt("$primaryKey", VK_OEM_3); + m_ConsoleConfig.m_nBind1 = pConsoleKV->GetInt("$secondaryKey", VK_F10); + } KeyValues* pBrowserKV = pKeyMapKV->FindKey(GAME_BROWSER_KEY); if (pBrowserKV) { - m_BrowserConfig.m_nBind0 = pBrowserKV->GetInt("$bindDef", VK_F10); - m_BrowserConfig.m_nBind1 = pBrowserKV->GetInt("$bindExt", VK_HOME); + m_BrowserConfig.m_nBind0 = pBrowserKV->GetInt("$primaryKey", VK_INSERT); + m_BrowserConfig.m_nBind1 = pBrowserKV->GetInt("$secondaryKey", VK_F11); } pKeyMapKV->DeleteThis(); @@ -50,15 +50,14 @@ void ImGuiConfig::Save() FileSystem()->CreateDirHierarchy(SDK_USER_CFG_PATH, "PLATFORM"); // Create directory, so ImGui can load/save 'layout.ini'. KeyValues kv("KeyMap"); - KeyValues* pKeyMapKV = kv.FindKey("KeyMap", true); - KeyValues* pConsoleKV = pKeyMapKV->FindKey(GAME_CONSOLE_KEY, true); - pConsoleKV->SetInt("$bindDef", m_ConsoleConfig.m_nBind0); - pConsoleKV->SetInt("$bindExt", m_ConsoleConfig.m_nBind1); + KeyValues* pConsoleKV = kv.FindKey(GAME_CONSOLE_KEY, true); + pConsoleKV->SetInt("$primaryKey", m_ConsoleConfig.m_nBind0); + pConsoleKV->SetInt("$secondaryKey", m_ConsoleConfig.m_nBind1); - KeyValues* pBrowserKV = pKeyMapKV->FindKey(GAME_BROWSER_KEY, true); - pBrowserKV->SetInt("$bindDef", m_BrowserConfig.m_nBind0); - pBrowserKV->SetInt("$bindExt", m_BrowserConfig.m_nBind1); + KeyValues* pBrowserKV = kv.FindKey(GAME_BROWSER_KEY, true); + pBrowserKV->SetInt("$primaryKey", m_BrowserConfig.m_nBind0); + pBrowserKV->SetInt("$secondaryKey", m_BrowserConfig.m_nBind1); CUtlBuffer uBuf(0i64, 0, CUtlBuffer::TEXT_BUFFER); diff --git a/src/thirdparty/imgui/misc/imgui_utility.h b/src/thirdparty/imgui/misc/imgui_utility.h index a85377e4..1386532c 100644 --- a/src/thirdparty/imgui/misc/imgui_utility.h +++ b/src/thirdparty/imgui/misc/imgui_utility.h @@ -9,18 +9,24 @@ public: struct { int m_nBind0 = VK_OEM_3; - int m_nBind1 = VK_PRIOR; + int m_nBind1 = VK_F10; } m_ConsoleConfig; struct { - int m_nBind0 = VK_F10; - int m_nBind1 = VK_NEXT; + int m_nBind0 = VK_INSERT; + int m_nBind1 = VK_F11; } m_BrowserConfig; void Load(); void Save(); ImGuiStyle_t InitStyle() const; + + inline bool KeyUsed(const int key) const + { + return (key == m_ConsoleConfig.m_nBind0 || key == m_ConsoleConfig.m_nBind1) + || (key == m_BrowserConfig.m_nBind0 || key == m_BrowserConfig.m_nBind1); + }; }; extern ImGuiConfig g_ImGuiConfig;