Auto scroll Check Tracker windows to current area

This commit is contained in:
sonoftunk 2022-11-06 09:58:31 -05:00
parent dba5df9e2a
commit b6c0775f1b
3 changed files with 44 additions and 5 deletions

View File

@ -894,6 +894,26 @@ std::map<RandomizerCheck, RandomizerCheckObject> RandomizerCheckObjects::GetAllR
return rcObjects; return rcObjects;
} }
std::map<SceneID, RandomizerCheckArea> rcAreaBySceneID = {};
std::map<SceneID, RandomizerCheckArea> 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<SceneID, RandomizerCheckArea> areas = GetAllRCAreaBySceneID();
auto areaIt = areas.find(sceneId);
if (areaIt == areas.end())
return RCAREA_INVALID;
else
return areaIt->second;
}
void RandomizerCheckObjects::UpdateImGuiVisibility() { void RandomizerCheckObjects::UpdateImGuiVisibility() {
for (auto& [randomizerCheck, locationIt] : rcObjects) { for (auto& [randomizerCheck, locationIt] : rcObjects) {
locationIt.visibleInImgui = ( locationIt.visibleInImgui = (

View File

@ -92,5 +92,7 @@ namespace RandomizerCheckObjects {
std::string GetRCAreaName(RandomizerCheckArea area); std::string GetRCAreaName(RandomizerCheckArea area);
std::map<RandomizerCheck, RandomizerCheckObject> GetAllRCObjects(); std::map<RandomizerCheck, RandomizerCheckObject> GetAllRCObjects();
std::map<RandomizerCheckArea, std::map<RandomizerCheck, RandomizerCheckObject>> GetAllRCObjectsByArea(); std::map<RandomizerCheckArea, std::map<RandomizerCheck, RandomizerCheckObject>> GetAllRCObjectsByArea();
std::map<SceneID, RandomizerCheckArea> GetAllRCAreaBySceneID();
RandomizerCheckArea GetRCAreaBySceneID(SceneID sceneId);
void UpdateImGuiVisibility(); void UpdateImGuiVisibility();
} }

View File

@ -700,8 +700,8 @@ bool HasItemBeenCollected(RandomizerCheckObject obj) {
return false; return false;
} }
RandomizerCheckArea lastArea = RCAREA_INVALID;
void DrawLocations() { void DrawLocations() {
RandomizerCheckObjects::UpdateImGuiVisibility();
if (ImGui::BeginTable("tableRandoChecks", 2, ImGuiTableFlags_BordersH | ImGuiTableFlags_BordersV)) { if (ImGui::BeginTable("tableRandoChecks", 2, ImGuiTableFlags_BordersH | ImGuiTableFlags_BordersV)) {
ImGui::TableSetupColumn("To Check", ImGuiTableColumnFlags_WidthStretch, 200.0f); ImGui::TableSetupColumn("To Check", ImGuiTableColumnFlags_WidthStretch, 200.0f);
@ -716,6 +716,10 @@ void DrawLocations() {
locationSearch.Draw(); locationSearch.Draw();
bool lastItemFound = false; 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)); ImGui::BeginChild("ChildToCheckLocations", ImVec2(0, -8));
for (auto& [rcArea, rcObjects] : RandomizerCheckObjects::GetAllRCObjectsByArea()) { for (auto& [rcArea, rcObjects] : RandomizerCheckObjects::GetAllRCObjectsByArea()) {
@ -725,6 +729,7 @@ void DrawLocations() {
locationSearch.PassFilter(locationIt.second.rcSpoilerName.c_str())) { locationSearch.PassFilter(locationIt.second.rcSpoilerName.c_str())) {
hasItems = true; hasItems = true;
doAreaScroll = (currentArea != RCAREA_INVALID && currentArea != lastArea && currentArea == rcArea);
break; break;
} }
} }
@ -732,6 +737,10 @@ void DrawLocations() {
if (hasItems) { if (hasItems) {
ImGui::SetNextItemOpen(true, ImGuiCond_Once); ImGui::SetNextItemOpen(true, ImGuiCond_Once);
if (ImGui::TreeNode(RandomizerCheckObjects::GetRCAreaName(rcArea).c_str())) { if (ImGui::TreeNode(RandomizerCheckObjects::GetRCAreaName(rcArea).c_str())) {
if (doAreaScroll) {
ImGui::SetScrollHereY(0.0f);
doAreaScroll = false;
}
for (auto& locationIt : rcObjects) { for (auto& locationIt : rcObjects) {
// If the location has its scene flag set // If the location has its scene flag set
if (HasItemBeenCollected(locationIt.second)) { // && checkedLocations.find(locationIt.rc) != checkedLocations.end()) { if (HasItemBeenCollected(locationIt.second)) { // && checkedLocations.find(locationIt.rc) != checkedLocations.end()) {
@ -786,21 +795,27 @@ void DrawLocations() {
ImGui::EndChild(); ImGui::EndChild();
// COLUMN 2 - CHECKED LOCATIONS // COLUMN 2 - CHECKED LOCATIONS
doAreaScroll = false;
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::BeginChild("ChildCheckedLocations", ImVec2(0, -8)); ImGui::BeginChild("ChildCheckedLocations", ImVec2(0, -8));
for (auto& areaIt : RandomizerCheckObjects::GetAllRCObjectsByArea()) { for (auto& [rcArea, rcObjects] : RandomizerCheckObjects::GetAllRCObjectsByArea()) {
bool hasItems = false; bool hasItems = false;
for (auto& locationIt : areaIt.second) { for (auto& locationIt : rcObjects) {
if (locationIt.second.visibleInImgui && checkedLocations.count(locationIt.second.rc)) { if (locationIt.second.visibleInImgui && checkedLocations.count(locationIt.second.rc)) {
hasItems = true; hasItems = true;
doAreaScroll = (currentArea != RCAREA_INVALID && currentArea != lastArea && currentArea == rcArea);
break; break;
} }
} }
if (hasItems) { if (hasItems) {
ImGui::SetNextItemOpen(true, ImGuiCond_Once); ImGui::SetNextItemOpen(true, ImGuiCond_Once);
if (ImGui::TreeNode(RandomizerCheckObjects::GetRCAreaName(areaIt.first).c_str())) { if (ImGui::TreeNode(RandomizerCheckObjects::GetRCAreaName(rcArea).c_str())) {
for (auto& locationIt : areaIt.second) { if (doAreaScroll) {
ImGui::SetScrollHereY(0.0f);
doAreaScroll = false;
}
for (auto& locationIt : rcObjects) {
auto elfound = checkedLocations.find(locationIt.second.rc); auto elfound = checkedLocations.find(locationIt.second.rc);
if (locationIt.second.visibleInImgui && elfound != checkedLocations.end()) { if (locationIt.second.visibleInImgui && elfound != checkedLocations.end()) {
// If the location has its scene flag set // If the location has its scene flag set
@ -832,6 +847,8 @@ void DrawLocations() {
} }
ImGui::EndChild(); ImGui::EndChild();
ImGui::EndTable(); ImGui::EndTable();
lastArea = currentArea;
} }
} }