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;
}
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() {
for (auto& [randomizerCheck, locationIt] : rcObjects) {
locationIt.visibleInImgui = (

View File

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

View File

@ -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;
}
}