From a2f656302cf75a4c91a335f2fed648b9c8bd1ea9 Mon Sep 17 00:00:00 2001 From: HarrySilan Date: Mon, 20 Jun 2022 23:04:49 +0800 Subject: [PATCH] Check All now leave checkmarks only on Search if used together --- .../user/cheat/teleport/CustomTeleports.cpp | 28 +++++++++++++++---- .../src/user/cheat/teleport/CustomTeleports.h | 1 + 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp b/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp index 8156165..1c86527 100644 --- a/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp +++ b/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp @@ -172,17 +172,27 @@ namespace cheat::feature std::sort(teleports.begin(), teleports.end(), [](const auto& a, const auto& b) {return doj::alphanum_less()(a.first, b.first); }); - bool allChecked = checkedIndices.size() == teleports.size() && !teleports.empty(); - ImGui::Checkbox("Check All", &allChecked); + bool allSearchChecked = std::includes(checkedIndices.begin(), checkedIndices.end() ,searchIndices.begin(), searchIndices.end()) && !searchIndices.empty(); + bool allChecked = (checkedIndices.size() == teleports.size() && !teleports.empty()) || allSearchChecked; + ImGui::Checkbox("All", &allChecked); if (ImGui::IsItemClicked()) { if (!teleports.empty()) { if (allChecked) { selectedIndex = -1; - checkedIndices.clear(); + if (!searchIndices.empty()) { + checkedIndices.erase(searchIndices.begin(), searchIndices.end()); + } + else { + checkedIndices.clear(); + } } else { - for (int i = 0; i < teleports.size(); i++) { - checkedIndices.insert(i); + if (!searchIndices.empty()) { + checkedIndices.insert(searchIndices.begin(), searchIndices.end()); + } + else { + for (int i = 0; i < teleports.size(); i++) + checkedIndices.insert(i); } } UpdateIndexName(); @@ -191,12 +201,19 @@ namespace cheat::feature ImGui::SameLine(); ImGui::InputText("Search", &search); unsigned int index = 0; + searchIndices.clear(); for (const auto& [teleportName, position] : teleports) { // find without case sensitivity if (search.empty() || std::search(teleportName.begin(), teleportName.end(), search.begin(), search.end(), [](char a, char b) { return std::tolower(a) == std::tolower(b); }) != teleportName.end()) { + // sets are sorted by default and does not allow duplicates + // which works in favor here. + if (!search.empty()) { + searchIndices.insert(index); + } + bool checked = std::any_of(checkedIndices.begin(), checkedIndices.end(), [&index](const auto& i) { return i == index; }); bool selected = index == selectedIndex; @@ -207,7 +224,6 @@ namespace cheat::feature checkedIndices.erase(index); } else { - // sets are sorted by default checkedIndices.insert(index); } } diff --git a/cheat-library/src/user/cheat/teleport/CustomTeleports.h b/cheat-library/src/user/cheat/teleport/CustomTeleports.h index e0f6db5..aba3865 100644 --- a/cheat-library/src/user/cheat/teleport/CustomTeleports.h +++ b/cheat-library/src/user/cheat/teleport/CustomTeleports.h @@ -25,6 +25,7 @@ namespace cheat::feature private: std::vector> teleports; std::set checkedIndices; + std::set searchIndices; bool selectedByClick = false; int selectedIndex = -1; std::string selectedIndexName;