Presets displayed in a combobox issues
-
Hi everyone. I'm newbie here.
I got a combobox displaying the presets in presets folder, its working fine, but there are two problems:
1 - The whole directory name + preset name is shown in the combobox instead of just the preset name.
2 - When I save a new preset, It will only be shown in the combobox if I hit 'Compile' again.
Does anyone have a clue of how can I fix this behavior?
Code I have for this Combobox so far:
const var Presets = Content.getComponent("Presets");
var menuItems = [];const var x = Engine.getUserPresetList();
for (i in x)
menuItems.insert(-1, i);menuItems = menuItems.join("\n");
Presets.set("items", menuItems);inline function onPresetsControl(component, value)
{
Engine.loadUserPreset(Presets.getItemText() + ".preset");
};Content.getComponent("Presets").setControlCallback(onPresetsControl);
-
@drey
I wrote like this// The Engine.loadUserPreset need a "relative path" or "file object" // I used the relative path for loading the presets const var Presets = Content.getComponent("Presets"); reg presetPaths = []; reg presetNames = []; const presetList = Engine.getUserPresetList(); for (p in presetList) { presetPaths.push(p); // here I save the relative path to the preset presetNames.push(p.substring(p.lastIndexOf("/")+1, p.length)); // and here the preset name } // Here I take only the names of the presets and put them in the combobox Presets.set("items", presetNames.join("\n")); inline function onPresetsControl(component, value) { // since the combobox value range starts with 1, not 0, I need to subtract the value with 1 Engine.loadUserPreset(presetPaths[value-1]+".preset"); }; Content.getComponent("Presets").setControlCallback(onPresetsControl);
-
@drey said in Presets displayed in a combobox issues:
2 - When I save a new preset, It will only be shown in the combobox if I hit 'Compile' again.
If you have the name of the saved preset, you can just find the indexOf that name in the presetName list and use it for setting the value to the combobox
Oh and when you have saved a new preset, you have to update the presetList so it will be present in the list -
@ulrik Thanks a lot man, I really appreciate it! Super helpful, it works now
-
@ulrik This is super useful! Thanks.
Anyone please note the combo box will have to have "saveInPreset" switched OFF,
otherwise there's a loop loading the preset as onPresetsControl fires every time a preset is loaded.