Skip to content

Commit

Permalink
Ensures the sidebar search gets added if on at boot.
Browse files Browse the repository at this point in the history
Searches the sidebar entries to find an entry with a label that matches the searchSidebarEntry label to delete when disabling sidebar search, just in case something goes wrong and it's not actually where it's supposed to be (sidebarSearchIndex).
  • Loading branch information
Malkierian committed Oct 5, 2024
1 parent d393359 commit 3b3cf8d
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions mm/2s2h/BenGui/SearchableMenuItems.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ void FreeLookPitchMinMax() {
CVarSetFloat("gEnhancements.Camera.FreeLook.MinPitch", std::min(maxY, minY));
}

void InsertSidebarSearch() {
menuEntries[0].sidebarEntries.insert(menuEntries[0].sidebarEntries.begin() + searchSidebarIndex,
searchSidebarEntry);
CVarSetInteger(menuEntries[0].sidebarCvar, CVarGetInteger(menuEntries[0].sidebarCvar, 0) + 1);
}

void AddSettings() {
// General Settings
settingsSidebar.push_back(
Expand Down Expand Up @@ -448,12 +454,18 @@ void AddSettings() {
{},
[](widgetInfo& info) {
if (CVarGetInteger("gSettings.SidebarSearch", 0)) {
menuEntries[0].sidebarEntries.insert(menuEntries[0].sidebarEntries.begin() + searchSidebarIndex,
searchSidebarEntry);
CVarSetInteger(menuEntries[0].sidebarCvar, CVarGetInteger(menuEntries[0].sidebarCvar, 0) + 1);
InsertSidebarSearch();
} else {
menuEntries[0].sidebarEntries.erase(menuEntries[0].sidebarEntries.begin() + searchSidebarIndex);
CVarSetInteger(menuEntries[0].sidebarCvar, CVarGetInteger(menuEntries[0].sidebarCvar, 0) - 1);
std::erase_if(menuEntries[0].sidebarEntries, [](SidebarEntry entry) {
return strncmp(entry.label.c_str(), searchSidebarEntry.label.c_str(), 5) == 0;
});
int32_t sidebarVal = CVarGetInteger(menuEntries[0].sidebarCvar, 0);
if (sidebarVal < menuEntries.size()) {
sidebarVal -= 1;
} else {
sidebarVal = menuEntries.size() - 1;
}
CVarSetInteger(menuEntries[0].sidebarCvar, sidebarVal);
}
} },
{ "Search Input Autofocus", "gSettings.SearchAutofocus",
Expand Down Expand Up @@ -680,6 +692,10 @@ void AddSettings() {
"Enables the separate Input Editor window.",
WIDGET_WINDOW_BUTTON,
{ .size = UIWidgets::Sizes::Inline, .windowName = "2S2H Input Editor" } } } } });

if (CVarGetInteger("gSettings.SidebarSearch", 0)) {
settingsSidebar.insert(settingsSidebar.begin() + searchSidebarIndex, searchSidebarEntry);
}
}
int32_t motionBlurStrength;

Expand Down

0 comments on commit 3b3cf8d

Please sign in to comment.