GUI: user presets, part 1

This commit is contained in:
tildearrow 2024-04-09 19:29:42 -05:00
parent ce4432175d
commit 6d8e6a9a55
3 changed files with 66 additions and 15 deletions

View file

@ -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;

View file

@ -2526,8 +2526,7 @@ class FurnaceGUI {
FurnaceGUIExportTypes curExportType;
// user presets window
int selectedUserPreset;
std::vector<int> selectedUserPresetSub;
std::vector<int> selectedUserPreset;
std::vector<String> randomDemoSong;
@ -2612,7 +2611,8 @@ class FurnaceGUI {
void sampleListItem(int index, int dir, int asset);
void drawSysDefs(std::vector<FurnaceGUISysDef>& category, bool& accepted, std::vector<int>& sysDefStack);
void printPresets(std::vector<FurnaceGUISysDef>& items, int depth);
void printPresets(std::vector<FurnaceGUISysDef>& items, size_t depth, std::vector<int>& depthStack);
FurnaceGUISysDef* selectPreset(std::vector<FurnaceGUISysDef>& items);
void toggleMobileUI(bool enable, bool force=false);

View file

@ -21,7 +21,9 @@
#include "../baseutils.h"
#include "../fileutils.h"
#include <fmt/printf.h>
#include "IconsFontAwesome4.h"
#include <imgui.h>
#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<FurnaceGUISysDef>& items, int depth) {
void FurnaceGUI::printPresets(std::vector<FurnaceGUISysDef>& items, size_t depth, std::vector<int>& 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<FurnaceGUISysDef>& items) {
FurnaceGUISysDef* ret=NULL;
for (size_t i=0; i<selectedUserPreset.size(); i++) {
if (selectedUserPreset[i]<0 || selectedUserPreset[i]>(int)items.size()) return NULL;
ret=&items[selectedUserPreset[i]];
if (i<selectedUserPreset.size()-1) {
items=ret->subDefs;
}
}
return ret;
}
void FurnaceGUI::drawUserPresets() {
if (nextWindow==GUI_WINDOW_USER_PRESETS) {
userPresetsOpen=true;
@ -3425,7 +3464,7 @@ void FurnaceGUI::drawUserPresets() {
}
}
//std::vector<int> depthStack;
std::vector<int> 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();