Jump to content

Dynamic Settings-Dialog extensions


klepto2
 Share

Recommended Posts

I am currently working on the settings dialog for my Polyhaven browser. At first i wanted to use the defualt options dialog provided by the Editor itself, but for now this lacks some features and is not that easy to access. 

While you already can add your own options to the options dialog, you have no detailed enough control where these settings are stored. 

Lets take an example: 

I have a few settings for my extension and i want to have them stored this way:

program.settings.extensions.polyhaven.model.folder = "Models/Polyhaven"
program.settings.extensions.polyhaven.material.folder = "Materials/Polyhaven"
program.settings.extensions.polyhaven.hdri.folder =
    "Materials/Environment/Polyhaven"
program.settings.extensions.polyhaven.material.downloadSize = "2k"
program.settings.extensions.polyhaven.model.downloadSize = "4k"
program.settings.extensions.polyhaven.hdri.downloadSize = "4k"

program.settings.extensions.polyhaven.material.displacement = true
program.settings.extensions.polyhaven.material.displacement_settings = {}
program.settings.extensions.polyhaven.material.displacement_settings[1] = 0.025
program.settings.extensions.polyhaven.material.displacement_settings[2] =
    -0.0125

this works nicely, and the editor correctly saves and load them correctly. But they are of course not visible in the options dialog of the editor itself. 

with this small piece you can add options to the editors options dialog:

local opt = program.optionsdialog
opt:AddSetting("extensions", "Displacement", PROPERTY_BOOLEAN)

but this will just use "program.settings.extensions.displacement"  in the settings.json instead of the original intended path. 

So what are my requirements for a good settings dialog:

  • it should be as generic as possible 
    • this means it should be easy to extend functionality. 
    • eg: add a specific settings behaviour when it is not included already.
  • each option should represent a path in the settings file
  • it should be possible to have groups of settings
  • it should still using the editors own settings.json

This is what i have so far:

First some sample code i use in my polyhaven extension:

--Setups the settingsdialog or returns the already created one
--the setting is more or less a simple singleton shared via the global table
local assetsettings = require("assetsettings") 

--Now we define the settings layout and register settings
--the option groups are created by the path and the order they are added
--you can have multiple sub nodes 
local hdrnode = assetsettings.registerOptionGroup("Polyhaven/Hdri")
assetsettings.addSettingFolder(hdrnode,"Storage-Path", "Materials/Environment/Polyhaven", "extensions.polyhaven.hdri.folder")
assetsettings.addSettingCombobox(hdrnode,"Download-Size", "2k","1k;2k;4k;8k", "extensions.polyhaven.hdri.downloadSize")

local material_node = assetsettings.registerOptionGroup("Polyhaven/Material")
assetsettings.addSettingFolder(material_node,"Storage-Path", "Materials/Polyhaven", "extensions.polyhaven.material.folder")
assetsettings.addSettingCombobox(material_node,"Download-Size", "2k","1k;2k;4k;8k", "extensions.polyhaven.material.downloadSize")
assetsettings.addSettingCheckbox(material_node,"Displacement", true, "extensions.polyhaven.material.displacement")
 
local model_node = assetsettings.registerOptionGroup("Polyhaven/Model")
assetsettings.addSettingFolder(model_node,"Storage-Path", "Models/Polyhaven", "extensions.polyhaven.model.folder")
assetsettings.addSettingCombobox(model_node,"Download-Size", "2k","1k;2k;4k;8k", "extensions.polyhaven.model.downloadSize")

and this is how it looks like:

image.thumb.png.106ee1e721cb6ce6984b05fe6b499ae6.png

you can even select toplevel nodes and then you get this:

image.thumb.png.af38b69713e24113d090e59cf59675be.png

So if you want, you can get all settings in one place, or get a cleaner one by selecting the subgroup directly.

Each addSettings...() method is responsable for its own to create the required widgets and to update the values which should be saved.

sample implementation of the combox setting:

function assetsettings.addSettingCombobox(node, description, defaultvalue, possibleValues, settingspath)
    assetsettings.addSetting(node, description, defaultvalue, settingspath, 
    function(x,y, labelwidth, item, parent) 
   
        local width = parent:ClientSize().x - 10
        CreateLabel(item.description..":", x ,y + 5,labelwidth,25, parent)
        local combobox = CreateComboBox(x + labelwidth,y, width -labelwidth-5, 25, parent)

        local n = possibleValues:split(";")
        for i = 1, #n do
            combobox:AddItem(n[i], n[i] == item.valuetosave)
        end
       
        ListenEvent(EVENT_WIDGETSELECT, combobox, function() 
                local w_item = combobox.items[combobox:GetSelectedItem()]
                item.valuetosave = w_item.text
        end, assetsettings)

        return combobox
    end
    )
end

the underlying addsettings function already sets up all required properties to handle the updating and saving behaviour.

If you close and save the dialog, the item.valuetosave is the applied to the correct parogram.settings path and stored as soon as the engine saves the settings.json.

 

  • Like 2
  • Intel® Core™ i7-8550U @ 1.80 Ghz 
  • 16GB RAM 
  • INTEL UHD Graphics 620
  • Windows 10 Pro 64-Bit-Version
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...