From e8d1d367ed7925305cbb26268c1e9ed0c51fd95f Mon Sep 17 00:00:00 2001 From: Malkierian Date: Thu, 24 Apr 2025 21:00:51 -0700 Subject: [PATCH] Add presets sidebar, proof of concept row-based listing. --- soh/soh/Enhancements/Presets/Presets.cpp | 221 ++++++++++++++++++++++- soh/soh/Enhancements/Presets/Presets.h | 2 - soh/soh/SohGui/UIWidgets.cpp | 8 +- soh/soh/SohGui/UIWidgets.hpp | 9 +- 4 files changed, 226 insertions(+), 14 deletions(-) diff --git a/soh/soh/Enhancements/Presets/Presets.cpp b/soh/soh/Enhancements/Presets/Presets.cpp index cef3f8362..4f4e14ddd 100644 --- a/soh/soh/Enhancements/Presets/Presets.cpp +++ b/soh/soh/Enhancements/Presets/Presets.cpp @@ -8,12 +8,29 @@ #include "soh/SohGui/SohMenu.h" #include "soh/SohGui/SohGui.hpp" -std::string FormatLocations(std::vector locs) { - std::string locString = ""; - for (auto loc : locs) { - locString += std::to_string(loc) + ","; - } - return locString; +namespace SohGui { +extern std::shared_ptr mSohMenu; +} + +void BlankButton() { + ImGui::PushStyleColor(ImGuiCol_Button, {0, 0, 0, 0}); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, {0, 0, 0, 0}); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, {0, 0, 0, 0}); + ImGui::PushStyleColor(ImGuiCol_Border, {0, 0, 0, 0}); + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(8.0f, 8.0f)); + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 5.0f); +} + +void PresetCheckboxStyle(const ImVec4& color) { + ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(color.x, color.y, color.z, 1.0f)); + ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ImVec4(color.x, color.y, color.z, 0.8f)); + ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImVec4(color.x, color.y, color.z, 0.6f)); + ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.0f, 0.0f, 0.0f, 0.3f)); + ImGui::PushStyleColor(ImGuiCol_CheckMark, ImVec4(1.0f, 1.0f, 1.0f, 0.7f)); + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(6.0f, 6.0f)); + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 5.0f); } void applyPreset(std::vector entries) { @@ -80,3 +97,195 @@ void DrawPresetSelector(PresetType presetTypeId) { } UIWidgets::PopStyleButton(); } + +enum PresetSection { + PRESET_SECTION_SETTINGS, + PRESET_SECTION_ENHANCEMENTS, + PRESET_SECTION_AUDIO, + PRESET_SECTION_COSMETICS, + PRESET_SECTION_RANDOMIZER, + PRESET_SECTION_TRACKERS, +}; + +struct PresetInfo { + std::unordered_map settings; + std::unordered_map enhancements; + std::unordered_map audio; + std::unordered_map cosmetics; + std::unordered_map rando; + std::unordered_map trackers; + + bool applySettings = true, applyEnhancements = true, applyAudio = true, applyCosmetics = true, applyRando = true, applyTrackers = true; +}; + +static std::unordered_map presets = { + { "Vanilla Plus", { + {}, + {{"DpadEquips", 1}}, + {}, + {}, + {}, + {}, + }} +}; + +void PresetsCustomWidget(WidgetInfo& info) { + UIWidgets::PushStyleTabs(THEME_COLOR); + ImGui::PushFont(OTRGlobals::Instance->fontMonoLargest); + if (ImGui::BeginTable("PresetWidgetTable", 9)) { + ImGui::TableSetupColumn("Name"); + ImGui::TableSetupColumn("Settings"); + ImGui::TableSetupColumn("Enhancements"); + ImGui::TableSetupColumn("Audio"); + ImGui::TableSetupColumn("Cosmetics"); + ImGui::TableSetupColumn("Randomizer"); + ImGui::TableSetupColumn("Trackers"); + ImGui::TableSetupColumn("Apply", ImGuiTableColumnFlags_WidthFixed, ImGui::CalcTextSize("Delete").x + ImGui::GetStyle().FramePadding.x * 2); + ImGui::TableSetupColumn("Delete", ImGuiTableColumnFlags_WidthFixed, ImGui::CalcTextSize("Delete").x + ImGui::GetStyle().FramePadding.x * 2); + BlankButton(); + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::TableNextColumn(); + ImGui::Button((ICON_FA_COG + std::string("##") + "headersettings").c_str()); + UIWidgets::Tooltip("Settings"); + ImGui::TableNextColumn(); + ImGui::Button((ICON_FA_PLUS_CIRCLE + std::string("##") + "headerenhancements").c_str()); + UIWidgets::Tooltip("Enhancements"); + ImGui::TableNextColumn(); + ImGui::Button((ICON_FA_MUSIC + std::string("##") + "headeraudio").c_str()); + UIWidgets::Tooltip("Audio"); + ImGui::TableNextColumn(); + ImGui::Button((ICON_FA_PAINT_BRUSH + std::string("##") + "headercosmetics").c_str()); + UIWidgets::Tooltip("Cosmetics"); + ImGui::TableNextColumn(); + ImGui::Button((ICON_FA_RANDOM + std::string("##") + "headerrando").c_str()); + UIWidgets::Tooltip("Randomizer"); + ImGui::TableNextColumn(); + ImGui::Button((ICON_FA_MAP + std::string("##") + "headertrackers").c_str()); + UIWidgets::Tooltip("Trackers"); + UIWidgets::PopStyleButton(); + + UIWidgets::CheckboxOptions checkboxOptions; + checkboxOptions.DefaultValue(true).Padding({ 10.0f, 6.0f }).Color(THEME_COLOR); + + for (auto [name, info] : presets) { + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::AlignTextToFramePadding(); + ImGui::Text(name.c_str()); + ImGui::TableNextColumn(); + ImGui::AlignTextToFramePadding(); + if (info.settings.empty()) { + ImGui::PushStyleColor(ImGuiCol_Text, { 1.0f, 0.0f, 0.0f, 0.7f }); + BlankButton(); + ImGui::BeginDisabled(); + ImGui::Button((ICON_FA_TIMES + std::string("##") + name + "settings").c_str()); + ImGui::EndDisabled(); + UIWidgets::PopStyleButton(); + ImGui::PopStyleColor(); + } + else { + UIWidgets::Checkbox(("##" + name + "settings").c_str(), &info.applySettings, UIWidgets::CheckboxOptions().DefaultValue(true)); + } + ImGui::TableNextColumn(); + ImGui::AlignTextToFramePadding(); + if (info.enhancements.empty()) { + ImGui::PushStyleColor(ImGuiCol_Text, { 1.0f, 0.0f, 0.0f, 0.7f }); + BlankButton(); + ImGui::BeginDisabled(); + ImGui::Button((ICON_FA_TIMES + std::string("##") + name + "enhancements").c_str()); + ImGui::EndDisabled(); + UIWidgets::PopStyleButton(); + ImGui::PopStyleColor(); + } + else { + checkboxOptions.DefaultValue(info.applyEnhancements); + ImGui::PushFont(OTRGlobals::Instance->fontMono); + UIWidgets::Checkbox(("##" + name + "enhancements").c_str(), &info.applyEnhancements, checkboxOptions); + ImGui::PopFont(); + } + ImGui::TableNextColumn(); + ImGui::AlignTextToFramePadding(); + if (info.audio.empty()) { + ImGui::PushStyleColor(ImGuiCol_Text, { 1.0f, 0.0f, 0.0f, 0.7f }); + BlankButton(); + ImGui::BeginDisabled(); + ImGui::Button((ICON_FA_TIMES + std::string("##") + name + "audio").c_str()); + ImGui::EndDisabled(); + UIWidgets::PopStyleButton(); + ImGui::PopStyleColor(); + } + else { + UIWidgets::Checkbox(("##" + name + "audio").c_str(), &info.applyAudio, UIWidgets::CheckboxOptions().DefaultValue(true)); + } + ImGui::TableNextColumn(); + ImGui::AlignTextToFramePadding(); + if (info.cosmetics.empty()) { + ImGui::PushStyleColor(ImGuiCol_Text, { 1.0f, 0.0f, 0.0f, 0.7f }); + BlankButton(); + ImGui::BeginDisabled(); + ImGui::Button((ICON_FA_TIMES + std::string("##") + name + "cosmetics").c_str()); + ImGui::EndDisabled(); + UIWidgets::PopStyleButton(); + ImGui::PopStyleColor(); + } + else { + UIWidgets::Checkbox(("##" + name + "cosmetics").c_str(), &info.applyCosmetics, UIWidgets::CheckboxOptions().DefaultValue(true)); + } + ImGui::TableNextColumn(); + ImGui::AlignTextToFramePadding(); + if (info.rando.empty()) { + ImGui::PushStyleColor(ImGuiCol_Text, { 1.0f, 0.0f, 0.0f, 0.7f }); + BlankButton(); + ImGui::BeginDisabled(); + ImGui::Button((ICON_FA_TIMES + std::string("##") + name + "rando").c_str()); + ImGui::EndDisabled(); + UIWidgets::PopStyleButton(); + ImGui::PopStyleColor(); + } + else { + UIWidgets::Checkbox(("##" + name + "rando").c_str(), &info.applyRando, UIWidgets::CheckboxOptions().DefaultValue(true)); + } + ImGui::TableNextColumn(); + ImGui::AlignTextToFramePadding(); + if (info.trackers.empty()) { + ImGui::PushStyleColor(ImGuiCol_Text, { 1.0f, 0.0f, 0.0f, 0.7f }); + BlankButton(); + ImGui::BeginDisabled(); + ImGui::Button((ICON_FA_TIMES + std::string("##") + name + "trackers").c_str()); + ImGui::EndDisabled(); + UIWidgets::PopStyleButton(); + ImGui::PopStyleColor(); + } + else { + UIWidgets::Checkbox(("##" + name + "trackers").c_str(), &info.applyTrackers, UIWidgets::CheckboxOptions().DefaultValue(true)); + } + ImGui::TableNextColumn(); + UIWidgets::PushStyleButton(THEME_COLOR); + if (UIWidgets::Button(("Apply##" + name).c_str())) { + + } + UIWidgets::PopStyleButton(); + ImGui::TableNextColumn(); + UIWidgets::PushStyleButton(THEME_COLOR); + if (UIWidgets::Button(("Delete##" + name).c_str())) { + presets.erase(name); + } + UIWidgets::PopStyleButton(); + } + + ImGui::EndTable(); + } + ImGui::PopFont(); + UIWidgets::PopStyleTabs(); +} + +void RegisterPresetsWidgets() { + SohGui::mSohMenu->AddSidebarEntry("Settings", "Presets", 1); + WidgetPath path = { "Settings", "Presets", SECTION_COLUMN_1 }; + SohGui::mSohMenu->AddWidget(path, "PresetsWidget", WIDGET_CUSTOM) + .CustomFunction(PresetsCustomWidget); +} + +//static RegisterMenuUpdateFunc updateFunc(UpdateResolutionVars, "Settings", "General"); +static RegisterMenuInitFunc initFunc(RegisterPresetsWidgets); diff --git a/soh/soh/Enhancements/Presets/Presets.h b/soh/soh/Enhancements/Presets/Presets.h index 898bc9cc9..5a12e9afa 100644 --- a/soh/soh/Enhancements/Presets/Presets.h +++ b/soh/soh/Enhancements/Presets/Presets.h @@ -38,8 +38,6 @@ typedef struct PresetEntry { std::variant value; } PresetEntry; -std::string FormatLocations(std::vector locs); - void DrawPresetSelector(PresetType presetType); void clearCvars(std::vector cvarsToClear); void applyPreset(std::vector entries); diff --git a/soh/soh/SohGui/UIWidgets.cpp b/soh/soh/SohGui/UIWidgets.cpp index 3c4e91147..21b2beaeb 100644 --- a/soh/soh/SohGui/UIWidgets.cpp +++ b/soh/soh/SohGui/UIWidgets.cpp @@ -204,19 +204,19 @@ bool WindowButton(const char* label, const char* cvarName, std::shared_ptr windowPtr, const WindowButtonOptions& options = {}); -void PushStyleCheckbox(const ImVec4& color); -void PushStyleCheckbox(Colors color = Colors::LightBlue); +void PushStyleCheckbox(const ImVec4& color, ImVec2 padding = ImVec2(10.0f, 6.0f)); +void PushStyleCheckbox(Colors color = Colors::LightBlue, ImVec2 padding = ImVec2(10.0f, 6.0f)); void PopStyleCheckbox(); void RenderText(ImVec2 pos, const char* text, const char* text_end, bool hide_text_after_hash); bool Checkbox(const char* label, bool* v, const CheckboxOptions& options = {});