From 6d8e6a9a55d039e6956ad9743667bdb465b9b179 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Tue, 9 Apr 2024 19:29:42 -0500 Subject: [PATCH] GUI: user presets, part 1 --- src/gui/gui.cpp | 3 +- src/gui/gui.h | 6 ++-- src/gui/presets.cpp | 72 ++++++++++++++++++++++++++++++++++++++------- 3 files changed, 66 insertions(+), 15 deletions(-) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 5e214563b..2f1bb9a8e 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -7876,8 +7876,7 @@ FurnaceGUI::FurnaceGUI(): curTutorialStep(0), audioExportType(0), dmfExportVersion(0), - curExportType(GUI_EXPORT_NONE), - selectedUserPreset(-1) { + curExportType(GUI_EXPORT_NONE) { // value keys valueKeys[SDLK_0]=0; valueKeys[SDLK_1]=1; diff --git a/src/gui/gui.h b/src/gui/gui.h index ebd9660e0..f0d85190a 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -2526,8 +2526,7 @@ class FurnaceGUI { FurnaceGUIExportTypes curExportType; // user presets window - int selectedUserPreset; - std::vector selectedUserPresetSub; + std::vector selectedUserPreset; std::vector randomDemoSong; @@ -2612,7 +2611,8 @@ class FurnaceGUI { void sampleListItem(int index, int dir, int asset); void drawSysDefs(std::vector& category, bool& accepted, std::vector& sysDefStack); - void printPresets(std::vector& items, int depth); + void printPresets(std::vector& items, size_t depth, std::vector& depthStack); + FurnaceGUISysDef* selectPreset(std::vector& items); void toggleMobileUI(bool enable, bool force=false); diff --git a/src/gui/presets.cpp b/src/gui/presets.cpp index aa4f98b19..78d5286bb 100644 --- a/src/gui/presets.cpp +++ b/src/gui/presets.cpp @@ -21,7 +21,9 @@ #include "../baseutils.h" #include "../fileutils.h" #include +#include "IconsFontAwesome4.h" #include +#include "misc/cpp/imgui_stdlib.h" // add system configurations here. // every entry is written in the following format: @@ -3396,19 +3398,56 @@ bool FurnaceGUI::saveUserPresets(bool redundancy) { } // user presets management -void FurnaceGUI::printPresets(std::vector& items, int depth) { +void FurnaceGUI::printPresets(std::vector& items, size_t depth, std::vector& depthStack) { if (depth>0) ImGui::Indent(); + int index=0; for (FurnaceGUISysDef& i: items) { - if (ImGui::Selectable(i.name.c_str())) { - // TODO + bool isSelected=(selectedUserPreset.size()==(depth+1)); + if (isSelected) { + for (size_t j=0; j<=depth; j++) { + int item=-1; + if (j>=depthStack.size()) { + item=index; + } else { + item=depthStack[j]; + } + + if (selectedUserPreset[j]!=item) { + isSelected=false; + break; + } + } } + ImGui::PushID(index+1); + if (ImGui::Selectable(i.name.c_str(),isSelected)) { + selectedUserPreset=depthStack; + selectedUserPreset.push_back(index); + } + ImGui::PopID(); if (!i.subDefs.empty()) { - printPresets(i.subDefs,depth+1); + depthStack.push_back(index); + ImGui::PushID(index); + printPresets(i.subDefs,depth+1,depthStack); + ImGui::PopID(); + depthStack.pop_back(); } + index++; } if (depth>0) ImGui::Unindent(); } +FurnaceGUISysDef* FurnaceGUI::selectPreset(std::vector& items) { + FurnaceGUISysDef* ret=NULL; + for (size_t i=0; i(int)items.size()) return NULL; + ret=&items[selectedUserPreset[i]]; + if (isubDefs; + } + } + return ret; +} + void FurnaceGUI::drawUserPresets() { if (nextWindow==GUI_WINDOW_USER_PRESETS) { userPresetsOpen=true; @@ -3425,7 +3464,7 @@ void FurnaceGUI::drawUserPresets() { } } - //std::vector depthStack; + std::vector depthStack; if (userCategory==NULL) { ImGui::Text("Error! User category does not exist!"); @@ -3433,16 +3472,29 @@ void FurnaceGUI::drawUserPresets() { // preset list ImGui::TableNextRow(); ImGui::TableNextColumn(); - ImGui::Text("Presets..."); - printPresets(userCategory->systems,0); + if (ImGui::Button(ICON_FA_PLUS "##AddPreset")) { + userCategory->systems.push_back(FurnaceGUISysDef("New Preset",{})); + selectedUserPreset.clear(); + selectedUserPreset.push_back(userCategory->systems.size()-1); + } + printPresets(userCategory->systems,0,depthStack); // editor ImGui::TableNextColumn(); - if (selectedUserPreset<0 || selectedUserPreset>=(int)userCategory->systems.size()) { + if (selectedUserPreset.empty()) { ImGui::Text("select a preset"); } else { - - ImGui::Text("Edit..."); + FurnaceGUISysDef* preset=selectPreset(userCategory->systems); + + if (preset!=NULL) { + ImGui::AlignTextToFramePadding(); + ImGui::Text("Name"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + ImGui::InputText("##PName",&preset->name); + ImGui::Separator(); + ImGui::Text("the rest..."); + } } ImGui::EndTable();