Fix Sidebar Search (#796)
Some checks failed
generate-builds / generate-2ship-otr (push) Has been cancelled
generate-builds / build-macos (push) Has been cancelled
generate-builds / build-linux (push) Has been cancelled
generate-builds / build-windows (push) Has been cancelled

* Ensures the sidebar search gets added if on at boot.
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).

* ... clang...
This commit is contained in:
Malkierian 2024-10-05 09:54:23 -07:00 committed by GitHub
parent 69edc89292
commit da793a5bf2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -403,6 +403,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(
@ -447,12 +453,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",
@ -679,6 +691,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;