filter randomizer checks in tracker (#4021)

* filter randomizer checks in tracker

Co-authored-by: Michael Stergianis <michael.stergianis@gmail.com>

* Adds an option to hide empty areas

Co-authored-by: Jamie Klassen <jamie@tenkeylabs.com>
Signed-off-by: Michael Stergianis <michael.stergianis@gmail.com>

* Removes extra whitespace

Co-authored-by: Jamie Klassen <jamie@tenkeylabs.com>
Signed-off-by: Michael Stergianis <michael.stergianis@gmail.com>

* Changes gCheckTrackerHideFilteredAreas to default to true

Refactors the for loop in shouldHideArea

Signed-off-by: Michael Stergianis <michael.stergianis@gmail.com>

* Addresses PR feedback

* https://github.com/HarbourMasters/Shipwright/pull/4021#discussion_r1538377614
* https://github.com/HarbourMasters/Shipwright/pull/4021#discussion_r1538381310

Co-authored-by: Jamie Klassen <jamie@tenkeylabs.com>
Signed-off-by: Michael Stergianis <michael.stergianis@gmail.com>

* Updates config variable to gTrackers.CheckTracker.HideFilteredAreas

Signed-off-by: Michael Stergianis <michael.stergianis@gmail.com>

* Adds check visibility guard to shouldHideArea

Refactors rcObject to check in passesTextFilter

Signed-off-by: Michael Stergianis <michael.stergianis@gmail.com>

---------

Signed-off-by: Michael Stergianis <michael.stergianis@gmail.com>
Co-authored-by: Michael Stergianis <michael.stergianis@gmail.com>
This commit is contained in:
Jamie Klassen 2024-04-20 10:27:13 -04:00 committed by GitHub
parent 3e32d05173
commit 2aa2092c27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -33,9 +33,9 @@ using json = nlohmann::json;
void to_json(json& j, const RandomizerCheckTrackerData& rctd) { void to_json(json& j, const RandomizerCheckTrackerData& rctd) {
j = json { j = json {
{ "status", rctd.status == RCSHOW_COLLECTED ? RCSHOW_SAVED : rctd.status }, { "status", rctd.status == RCSHOW_COLLECTED ? RCSHOW_SAVED : rctd.status },
{ "skipped", rctd.skipped }, { "skipped", rctd.skipped },
{ "price", rctd.price }, { "price", rctd.price },
{ "hintItem", rctd.hintItem }}; { "hintItem", rctd.hintItem }};
} }
@ -133,6 +133,8 @@ RandomizerCheckArea previousArea = RCAREA_INVALID;
RandomizerCheckArea currentArea = RCAREA_INVALID; RandomizerCheckArea currentArea = RCAREA_INVALID;
OSContPad* trackerButtonsPressed; OSContPad* trackerButtonsPressed;
bool passesTextFilter(ImGuiTextFilter& checkSearch, const RandomizerCheckObject rcObject);
bool shouldHideArea(ImGuiTextFilter& checkSearch, std::map<RandomizerCheckArea, std::vector<RandomizerCheckObject>> checksByArea, const RandomizerCheckArea rcArea);
void BeginFloatWindows(std::string UniqueName, bool& open, ImGuiWindowFlags flags = 0); void BeginFloatWindows(std::string UniqueName, bool& open, ImGuiWindowFlags flags = 0);
bool CompareChecks(RandomizerCheckObject, RandomizerCheckObject); bool CompareChecks(RandomizerCheckObject, RandomizerCheckObject);
bool CheckByArea(RandomizerCheckArea); bool CheckByArea(RandomizerCheckArea);
@ -513,7 +515,7 @@ void CheckTrackerLoadGame(int32_t fileNum) {
break; break;
} }
RandomizerCheckObject linksPocket = { RC_LINKS_POCKET, RCVORMQ_BOTH, RCTYPE_LINKS_POCKET, startingArea, ACTOR_ID_MAX, SCENE_ID_MAX, 0x00, GI_NONE, false, "Link's Pocket", "Link's Pocket" }; RandomizerCheckObject linksPocket = { RC_LINKS_POCKET, RCVORMQ_BOTH, RCTYPE_LINKS_POCKET, startingArea, ACTOR_ID_MAX, SCENE_ID_MAX, 0x00, GI_NONE, false, "Link's Pocket", "Link's Pocket" };
checksByArea.find(startingArea)->second.push_back(linksPocket); checksByArea.find(startingArea)->second.push_back(linksPocket);
areaChecksGotten[startingArea]++; areaChecksGotten[startingArea]++;
areaCheckTotals[startingArea]++; areaCheckTotals[startingArea]++;
@ -692,7 +694,7 @@ void CheckTrackerFlagSet(int16_t flagType, int32_t flag) {
break; break;
case FLAG_EVENT_CHECK_INF: case FLAG_EVENT_CHECK_INF:
if ((flag == EVENTCHKINF_CARPENTERS_FREE(0) || flag == EVENTCHKINF_CARPENTERS_FREE(1) || if ((flag == EVENTCHKINF_CARPENTERS_FREE(0) || flag == EVENTCHKINF_CARPENTERS_FREE(1) ||
flag == EVENTCHKINF_CARPENTERS_FREE(2) || flag == EVENTCHKINF_CARPENTERS_FREE(3)) flag == EVENTCHKINF_CARPENTERS_FREE(2) || flag == EVENTCHKINF_CARPENTERS_FREE(3))
&& GET_EVENTCHKINF_CARPENTERS_FREE_ALL()) { && GET_EVENTCHKINF_CARPENTERS_FREE_ALL()) {
SetCheckCollected(RC_GF_GERUDO_MEMBERSHIP_CARD); SetCheckCollected(RC_GF_GERUDO_MEMBERSHIP_CARD);
return; return;
@ -851,12 +853,12 @@ void SetAreaSpoiled(RandomizerCheckArea rcArea) {
void UpdateCheck(uint32_t check, RandomizerCheckTrackerData data) { void UpdateCheck(uint32_t check, RandomizerCheckTrackerData data) {
auto area = RandomizerCheckObjects::GetAllRCObjects().find(static_cast<RandomizerCheck>(check))->second.rcArea; auto area = RandomizerCheckObjects::GetAllRCObjects().find(static_cast<RandomizerCheck>(check))->second.rcArea;
if ((!gSaveContext.checkTrackerData[check].skipped && data.skipped) || if ((!gSaveContext.checkTrackerData[check].skipped && data.skipped) ||
((gSaveContext.checkTrackerData[check].status != RCSHOW_COLLECTED && gSaveContext.checkTrackerData[check].status != RCSHOW_SAVED) && ((gSaveContext.checkTrackerData[check].status != RCSHOW_COLLECTED && gSaveContext.checkTrackerData[check].status != RCSHOW_SAVED) &&
(data.status == RCSHOW_COLLECTED || data.status == RCSHOW_SAVED))) { (data.status == RCSHOW_COLLECTED || data.status == RCSHOW_SAVED))) {
areaChecksGotten[area]++; areaChecksGotten[area]++;
} else if ((gSaveContext.checkTrackerData[check].skipped && !data.skipped) || } else if ((gSaveContext.checkTrackerData[check].skipped && !data.skipped) ||
((gSaveContext.checkTrackerData[check].status == RCSHOW_COLLECTED || gSaveContext.checkTrackerData[check].status == RCSHOW_SAVED) && ((gSaveContext.checkTrackerData[check].status == RCSHOW_COLLECTED || gSaveContext.checkTrackerData[check].status == RCSHOW_SAVED) &&
(data.status != RCSHOW_COLLECTED && data.status != RCSHOW_SAVED))) { (data.status != RCSHOW_COLLECTED && data.status != RCSHOW_SAVED))) {
areaChecksGotten[area]--; areaChecksGotten[area]--;
} }
@ -927,6 +929,14 @@ void CheckTrackerWindow::DrawElement() {
optExpandAll = false; optExpandAll = false;
optCollapseAll = true; optCollapseAll = true;
} }
ImGui::SameLine();
static ImGuiTextFilter checkSearch;
if (ImGui::Button("Clear")) {
checkSearch.Clear();
}
UIWidgets::Tooltip("Clear the search field");
checkSearch.Draw();
UIWidgets::PaddedSeparator(); UIWidgets::PaddedSeparator();
//Checks Section Lead-in //Checks Section Lead-in
@ -973,10 +983,9 @@ void CheckTrackerWindow::DrawElement() {
previousShowHidden = showHidden; previousShowHidden = showHidden;
doAreaScroll = true; doAreaScroll = true;
} }
if (!showHidden && ( if (shouldHideArea(checkSearch, checksByArea, rcArea) ||
hideComplete && thisAreaFullyChecked || (!showHidden && ((hideComplete && thisAreaFullyChecked) || (hideIncomplete && !thisAreaFullyChecked)))
hideIncomplete && !thisAreaFullyChecked ) {
)) {
doDraw = false; doDraw = false;
} else { } else {
//Get the colour for the area //Get the colour for the area
@ -1035,11 +1044,14 @@ void CheckTrackerWindow::DrawElement() {
ImGui::SetScrollHereY(0.0f); ImGui::SetScrollHereY(0.0f);
doAreaScroll = false; doAreaScroll = false;
} }
for (auto rco : objs) {
if (IsVisibleInCheckTracker(rco) && doDraw && isThisAreaSpoiled) { for (auto rcObject : objs) {
DrawLocation(rco); if (IsVisibleInCheckTracker(rcObject) && passesTextFilter(checkSearch, rcObject) && doDraw &&
isThisAreaSpoiled) {
DrawLocation(rcObject);
} }
} }
if (doDraw) { if (doDraw) {
ImGui::TreePop(); ImGui::TreePop();
} }
@ -1055,6 +1067,28 @@ void CheckTrackerWindow::DrawElement() {
} }
} }
bool shouldHideArea(ImGuiTextFilter& checkSearch, std::map<RandomizerCheckArea, std::vector<RandomizerCheckObject>> checksByArea, RandomizerCheckArea rcArea) {
bool shouldHideFilteredAreas = CVarGetInteger("gTrackers.CheckTracker.HideFilteredAreas", 1);
if (!shouldHideFilteredAreas) {
return false;
}
for (auto check : checksByArea[rcArea]) {
if (IsVisibleInCheckTracker(check) && passesTextFilter(checkSearch, check)) {
return false;
}
}
return true;
}
bool passesTextFilter(ImGuiTextFilter& checkSearch, RandomizerCheckObject check) {
return (
checkSearch.PassFilter(RandomizerCheckObjects::GetRCAreaName(check.rcArea).c_str()) ||
checkSearch.PassFilter(check.rcShortName.c_str())
);
}
// Windowing stuff // Windowing stuff
void BeginFloatWindows(std::string UniqueName, bool& open, ImGuiWindowFlags flags) { void BeginFloatWindows(std::string UniqueName, bool& open, ImGuiWindowFlags flags) {
ImGuiWindowFlags windowFlags = flags; ImGuiWindowFlags windowFlags = flags;
@ -1326,7 +1360,7 @@ bool IsHeartPiece(GetItemID giid) {
} }
void DrawLocation(RandomizerCheckObject rcObj) { void DrawLocation(RandomizerCheckObject rcObj) {
Color_RGBA8 mainColor; Color_RGBA8 mainColor;
Color_RGBA8 extraColor; Color_RGBA8 extraColor;
std::string txt; std::string txt;
bool showHidden = CVarGetInteger("gCheckTrackerOptionShowHidden", 0); bool showHidden = CVarGetInteger("gCheckTrackerOptionShowHidden", 0);
@ -1376,13 +1410,13 @@ void DrawLocation(RandomizerCheckObject rcObj) {
CVarGetColor("gCheckTrackerUncheckedMainColor", Color_Main_Default); CVarGetColor("gCheckTrackerUncheckedMainColor", Color_Main_Default);
extraColor = CVarGetColor("gCheckTrackerUncheckedExtraColor", Color_Unchecked_Extra_Default); extraColor = CVarGetColor("gCheckTrackerUncheckedExtraColor", Color_Unchecked_Extra_Default);
} }
//Main Text //Main Text
txt = rcObj.rcShortName; txt = rcObj.rcShortName;
if (lastLocationChecked == rcObj.rc) { if (lastLocationChecked == rcObj.rc) {
txt = "* " + txt; txt = "* " + txt;
} }
// Draw button - for Skipped/Seen/Scummed/Unchecked only // Draw button - for Skipped/Seen/Scummed/Unchecked only
if (status == RCSHOW_UNCHECKED || status == RCSHOW_SEEN || status == RCSHOW_IDENTIFIED || status == RCSHOW_SCUMMED || skipped) { if (status == RCSHOW_UNCHECKED || status == RCSHOW_SEEN || status == RCSHOW_IDENTIFIED || status == RCSHOW_SCUMMED || skipped) {
if (UIWidgets::StateButton(std::to_string(rcObj.rc).c_str(), skipped ? ICON_FA_PLUS : ICON_FA_TIMES)) { if (UIWidgets::StateButton(std::to_string(rcObj.rc).c_str(), skipped ? ICON_FA_PLUS : ICON_FA_TIMES)) {
@ -1487,13 +1521,13 @@ void RainbowTick() {
if (CVarGetInteger((cvar + "RBM").c_str(), 0) == 0) { if (CVarGetInteger((cvar + "RBM").c_str(), 0) == 0) {
continue; continue;
} }
Color_RGBA8 newColor; Color_RGBA8 newColor;
newColor.r = sin(freqHue + 0) * 127 + 128; newColor.r = sin(freqHue + 0) * 127 + 128;
newColor.g = sin(freqHue + (2 * M_PI / 3)) * 127 + 128; newColor.g = sin(freqHue + (2 * M_PI / 3)) * 127 + 128;
newColor.b = sin(freqHue + (4 * M_PI / 3)) * 127 + 128; newColor.b = sin(freqHue + (4 * M_PI / 3)) * 127 + 128;
newColor.a = 255; newColor.a = 255;
CVarSetColor(cvar.c_str(), newColor); CVarSetColor(cvar.c_str(), newColor);
} }
@ -1530,7 +1564,7 @@ void ImGuiDrawTwoColorPickerSection(const char* text, const char* cvarMainName,
main_color = CVarGetColor(cvarMainName, main_default_color); main_color = CVarGetColor(cvarMainName, main_default_color);
}; };
ImGui::PopItemWidth(); ImGui::PopItemWidth();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::AlignTextToFramePadding(); ImGui::AlignTextToFramePadding();
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x); ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x);
@ -1604,6 +1638,11 @@ void CheckTrackerSettingsWindow::DrawElement() {
} }
UIWidgets::Tooltip("If enabled, will show GS locations in the tracker regardless of tokensanity settings."); UIWidgets::Tooltip("If enabled, will show GS locations in the tracker regardless of tokensanity settings.");
// Filtering settings
UIWidgets::PaddedSeparator();
UIWidgets::EnhancementCheckbox("Filter Empty Areas", "gTrackers.CheckTracker.HideFilteredAreas", false, "", UIWidgets::CheckboxGraphics::Checkmark, true);
UIWidgets::Tooltip("If enabled, will hide area headers that have no locations matching filter");
ImGui::TableNextColumn(); ImGui::TableNextColumn();
CheckTracker::ImGuiDrawTwoColorPickerSection("Area Incomplete", "gCheckTrackerAreaMainIncompleteColor", "gCheckTrackerAreaExtraIncompleteColor", Color_Area_Incomplete_Main, Color_Area_Incomplete_Extra, Color_Main_Default, Color_Area_Incomplete_Extra_Default, "gCheckTrackerAreaIncompleteHide", ""); CheckTracker::ImGuiDrawTwoColorPickerSection("Area Incomplete", "gCheckTrackerAreaMainIncompleteColor", "gCheckTrackerAreaExtraIncompleteColor", Color_Area_Incomplete_Main, Color_Area_Incomplete_Extra, Color_Main_Default, Color_Area_Incomplete_Extra_Default, "gCheckTrackerAreaIncompleteHide", "");