From b6c0775f1bc3d75dabca1cbfe684acfa9d64436a Mon Sep 17 00:00:00 2001 From: sonoftunk Date: Sun, 6 Nov 2022 09:58:31 -0500 Subject: [PATCH] Auto scroll Check Tracker windows to current area --- .../randomizer/randomizer_check_objects.cpp | 20 ++++++++++++++ .../randomizer/randomizer_check_objects.h | 2 ++ .../randomizer/randomizer_item_tracker.cpp | 27 +++++++++++++++---- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/randomizer_check_objects.cpp b/soh/soh/Enhancements/randomizer/randomizer_check_objects.cpp index 2a7a08e80..8a53ad783 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_check_objects.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_check_objects.cpp @@ -894,6 +894,26 @@ std::map RandomizerCheckObjects::GetAllR return rcObjects; } +std::map rcAreaBySceneID = {}; +std::map RandomizerCheckObjects::GetAllRCAreaBySceneID() { + //memoize on first request + if (rcAreaBySceneID.size() == 0) { + for (auto& [randomizerCheck, rcObject] : rcObjects) { + rcAreaBySceneID[rcObject.sceneId] = rcObject.rcArea; + } + } + return rcAreaBySceneID; +} + +RandomizerCheckArea RandomizerCheckObjects::GetRCAreaBySceneID(SceneID sceneId) { + std::map areas = GetAllRCAreaBySceneID(); + auto areaIt = areas.find(sceneId); + if (areaIt == areas.end()) + return RCAREA_INVALID; + else + return areaIt->second; +} + void RandomizerCheckObjects::UpdateImGuiVisibility() { for (auto& [randomizerCheck, locationIt] : rcObjects) { locationIt.visibleInImgui = ( diff --git a/soh/soh/Enhancements/randomizer/randomizer_check_objects.h b/soh/soh/Enhancements/randomizer/randomizer_check_objects.h index d3d127b1b..b15bf4a3d 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_check_objects.h +++ b/soh/soh/Enhancements/randomizer/randomizer_check_objects.h @@ -92,5 +92,7 @@ namespace RandomizerCheckObjects { std::string GetRCAreaName(RandomizerCheckArea area); std::map GetAllRCObjects(); std::map> GetAllRCObjectsByArea(); + std::map GetAllRCAreaBySceneID(); + RandomizerCheckArea GetRCAreaBySceneID(SceneID sceneId); void UpdateImGuiVisibility(); } diff --git a/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp b/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp index fb584310c..3b8d5639f 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp @@ -700,8 +700,8 @@ bool HasItemBeenCollected(RandomizerCheckObject obj) { return false; } +RandomizerCheckArea lastArea = RCAREA_INVALID; void DrawLocations() { - RandomizerCheckObjects::UpdateImGuiVisibility(); if (ImGui::BeginTable("tableRandoChecks", 2, ImGuiTableFlags_BordersH | ImGuiTableFlags_BordersV)) { ImGui::TableSetupColumn("To Check", ImGuiTableColumnFlags_WidthStretch, 200.0f); @@ -716,6 +716,10 @@ void DrawLocations() { locationSearch.Draw(); bool lastItemFound = false; + bool doAreaScroll = false; + RandomizerCheckArea currentArea = RCAREA_INVALID; + if (gGlobalCtx != nullptr) + currentArea = RandomizerCheckObjects::GetRCAreaBySceneID((SceneID)gGlobalCtx->sceneNum); ImGui::BeginChild("ChildToCheckLocations", ImVec2(0, -8)); for (auto& [rcArea, rcObjects] : RandomizerCheckObjects::GetAllRCObjectsByArea()) { @@ -725,6 +729,7 @@ void DrawLocations() { locationSearch.PassFilter(locationIt.second.rcSpoilerName.c_str())) { hasItems = true; + doAreaScroll = (currentArea != RCAREA_INVALID && currentArea != lastArea && currentArea == rcArea); break; } } @@ -732,6 +737,10 @@ void DrawLocations() { if (hasItems) { ImGui::SetNextItemOpen(true, ImGuiCond_Once); if (ImGui::TreeNode(RandomizerCheckObjects::GetRCAreaName(rcArea).c_str())) { + if (doAreaScroll) { + ImGui::SetScrollHereY(0.0f); + doAreaScroll = false; + } for (auto& locationIt : rcObjects) { // If the location has its scene flag set if (HasItemBeenCollected(locationIt.second)) { // && checkedLocations.find(locationIt.rc) != checkedLocations.end()) { @@ -786,21 +795,27 @@ void DrawLocations() { ImGui::EndChild(); // COLUMN 2 - CHECKED LOCATIONS + doAreaScroll = false; ImGui::TableNextColumn(); ImGui::BeginChild("ChildCheckedLocations", ImVec2(0, -8)); - for (auto& areaIt : RandomizerCheckObjects::GetAllRCObjectsByArea()) { + for (auto& [rcArea, rcObjects] : RandomizerCheckObjects::GetAllRCObjectsByArea()) { bool hasItems = false; - for (auto& locationIt : areaIt.second) { + for (auto& locationIt : rcObjects) { if (locationIt.second.visibleInImgui && checkedLocations.count(locationIt.second.rc)) { hasItems = true; + doAreaScroll = (currentArea != RCAREA_INVALID && currentArea != lastArea && currentArea == rcArea); break; } } if (hasItems) { ImGui::SetNextItemOpen(true, ImGuiCond_Once); - if (ImGui::TreeNode(RandomizerCheckObjects::GetRCAreaName(areaIt.first).c_str())) { - for (auto& locationIt : areaIt.second) { + if (ImGui::TreeNode(RandomizerCheckObjects::GetRCAreaName(rcArea).c_str())) { + if (doAreaScroll) { + ImGui::SetScrollHereY(0.0f); + doAreaScroll = false; + } + for (auto& locationIt : rcObjects) { auto elfound = checkedLocations.find(locationIt.second.rc); if (locationIt.second.visibleInImgui && elfound != checkedLocations.end()) { // If the location has its scene flag set @@ -832,6 +847,8 @@ void DrawLocations() { } ImGui::EndChild(); ImGui::EndTable(); + + lastArea = currentArea; } }