From 39b7bb5d75ce9eefd94574cea2b5032c392e7aad Mon Sep 17 00:00:00 2001 From: Delta <46466697+DeltaGW2@users.noreply.github.com> Date: Wed, 10 Apr 2024 22:09:27 +0200 Subject: [PATCH 1/2] collapsible kb categories + localise modal --- src/GUI/Widgets/Options/COptionsWindow.cpp | 49 ++++++++++++---------- src/Keybinds/KeybindHandler.cpp | 6 ++- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/GUI/Widgets/Options/COptionsWindow.cpp b/src/GUI/Widgets/Options/COptionsWindow.cpp index 4eb538c..3d96b9c 100644 --- a/src/GUI/Widgets/Options/COptionsWindow.cpp +++ b/src/GUI/Widgets/Options/COptionsWindow.cpp @@ -435,46 +435,51 @@ namespace GUI } for (std::string cat : categories) { - ImGui::TextDisabled(cat.c_str()); - if (ImGui::BeginTable(("table_keybinds##" + cat).c_str(), 3, ImGuiTableFlags_BordersInnerH)) + if (ImGui::CollapsingHeader(cat != "(null)" ? cat.c_str() : "Inactive", ImGuiTreeNodeFlags_DefaultOpen)) { - for (auto& [identifier, keybind] : Keybinds::Registry) + if (ImGui::BeginTable(("table_keybinds##" + cat).c_str(), 3, ImGuiTableFlags_BordersInnerH)) { - if (Loader::GetOwner(keybind.Handler) != cat) { continue; } - - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); - ImGui::Text(Language.Translate(identifier.c_str())); - - ImGui::TableSetColumnIndex(1); - if (ImGui::Button((keybind.Bind.ToString(true) + "##" + identifier).c_str(), ImVec2(kbButtonWidth, 0.0f))) + for (auto& [identifier, keybind] : Keybinds::Registry) { - CurrentlyEditing = identifier; - openEditor = true; + if (Loader::GetOwner(keybind.Handler) != cat) { continue; } + + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + ImGui::Text(Language.Translate(identifier.c_str())); + + ImGui::TableSetColumnIndex(1); + if (ImGui::Button((keybind.Bind.ToString(true) + "##" + identifier).c_str(), ImVec2(kbButtonWidth, 0.0f))) + { + CurrentlyEditing = identifier; + openEditor = true; + } + + ImGui::TableSetColumnIndex(2); + if (keybind.Handler == nullptr) + { + ImGui::TextDisabled(Language.Translate("((000061))")); + } } - ImGui::TableSetColumnIndex(2); - if (keybind.Handler == nullptr) - { - ImGui::TextDisabled(Language.Translate("((000061))")); - } + ImGui::EndTable(); } - - ImGui::EndTable(); } } } Keybinds::Mutex.unlock(); + std::string kbModalTitle = Language.Translate("((000062))"); + kbModalTitle.append(Language.Translate(CurrentlyEditing.c_str())); + if (openEditor) { openEditor = false; - ImGui::OpenPopup((Language.Translate("((000062))") + CurrentlyEditing).c_str(), ImGuiPopupFlags_AnyPopupLevel); + ImGui::OpenPopup(kbModalTitle.c_str(), ImGuiPopupFlags_AnyPopupLevel); } ImVec2 center(Renderer::Width * 0.5f, Renderer::Height * 0.5f); ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); - if (ImGui::BeginPopupModal((Language.Translate("((000062))") + CurrentlyEditing).c_str(), NULL, WindowFlags_Default)) + if (ImGui::BeginPopupModal(kbModalTitle.c_str(), NULL, WindowFlags_Default)) { Keybinds::IsSettingKeybind = true; if (Keybinds::CurrentKeybind == Keybind{}) diff --git a/src/Keybinds/KeybindHandler.cpp b/src/Keybinds/KeybindHandler.cpp index 540678e..be085ac 100644 --- a/src/Keybinds/KeybindHandler.cpp +++ b/src/Keybinds/KeybindHandler.cpp @@ -331,9 +331,11 @@ namespace Keybinds if (res != aIdentifier && res != "") { return; } - const std::lock_guard lock(Mutex); + { + const std::lock_guard lock(Mutex); - Registry[aIdentifier].Bind = aKeybind; + Registry[aIdentifier].Bind = aKeybind; + } Save(); } From b1a8d8943e173ba15ae5a879d1fd9a0ba6cb7d5f Mon Sep 17 00:00:00 2001 From: Delta <46466697+DeltaGW2@users.noreply.github.com> Date: Wed, 10 Apr 2024 22:22:43 +0200 Subject: [PATCH 2/2] delete stale keybinds --- src/GUI/Widgets/Options/COptionsWindow.cpp | 15 +++++++++++++++ src/Keybinds/KeybindHandler.cpp | 6 ++++++ src/Keybinds/KeybindHandler.h | 9 ++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/GUI/Widgets/Options/COptionsWindow.cpp b/src/GUI/Widgets/Options/COptionsWindow.cpp index 3d96b9c..4458dcf 100644 --- a/src/GUI/Widgets/Options/COptionsWindow.cpp +++ b/src/GUI/Widgets/Options/COptionsWindow.cpp @@ -416,6 +416,8 @@ namespace GUI float kbButtonWidth = ImGui::CalcTextSize("XXXXXXXXXXXXXXXXXXXXXXXX").x; bool openEditor = false; + bool deleteStaleBind = false; + std::string staleBindIdentifier; Keybinds::Mutex.lock(); { @@ -457,6 +459,12 @@ namespace GUI ImGui::TableSetColumnIndex(2); if (keybind.Handler == nullptr) { + if (ImGui::SmallButton(("X##" + identifier).c_str())) + { + deleteStaleBind = true; + staleBindIdentifier = identifier; + } + ImGui::SameLine(); ImGui::TextDisabled(Language.Translate("((000061))")); } } @@ -468,6 +476,13 @@ namespace GUI } Keybinds::Mutex.unlock(); + if (deleteStaleBind && !staleBindIdentifier.empty()) + { + Keybinds::Delete(staleBindIdentifier); + deleteStaleBind = false; + staleBindIdentifier.clear(); + } + std::string kbModalTitle = Language.Translate("((000062))"); kbModalTitle.append(Language.Translate(CurrentlyEditing.c_str())); diff --git a/src/Keybinds/KeybindHandler.cpp b/src/Keybinds/KeybindHandler.cpp index be085ac..822ed66 100644 --- a/src/Keybinds/KeybindHandler.cpp +++ b/src/Keybinds/KeybindHandler.cpp @@ -358,6 +358,12 @@ namespace Keybinds return called; } + void Delete(std::string aIdentifier) + { + const std::lock_guard lock(Mutex); + Registry.erase(aIdentifier); + } + int Verify(void* aStartAddress, void* aEndAddress) { int refCounter = 0; diff --git a/src/Keybinds/KeybindHandler.h b/src/Keybinds/KeybindHandler.h index 70b7922..f255bd8 100644 --- a/src/Keybinds/KeybindHandler.h +++ b/src/Keybinds/KeybindHandler.h @@ -115,10 +115,17 @@ namespace Keybinds ///---------------------------------------------------------------------------------------------------- /// Invoke: - /// Invokes the action on the corresponding keybind handler. Returns true if the keybind was dispatched. + /// Invokes the action on the corresponding keybind handler. + /// Returns true if the keybind was dispatched. ///---------------------------------------------------------------------------------------------------- bool Invoke(std::string aIdentifier); + ///---------------------------------------------------------------------------------------------------- + /// Deletes: + /// Deletes a keybind entirely. + ///---------------------------------------------------------------------------------------------------- + void Delete(std::string aIdentifier); + ///---------------------------------------------------------------------------------------------------- /// Verify: /// Removes all KeybindHandlers that are within the provided address space.