sirinsidiator / ESO-LibAddonMenu

http://www.esoui.com/downloads/info7-LibAddonMenu.html
Artistic License 2.0
42 stars 20 forks source link

Add callback on reset to default #23

Closed sirinsidiator closed 8 years ago

sirinsidiator commented 9 years ago

Ayantir wrote:

little request, allow us to execute code when reverting to default.

the code will look like getFunc

default = function()
        -- do stuff
        return value
end,

Thank you.

sirinsidiator commented 9 years ago

Ayantir wrote:

For the default, I found the trick because my need was on a dropdown. If you cannot set a func in your "default" parameter, set it in your setFunc parameter.

and write something like this : In this exemple. I set a sound ID in my db and I show its localized string.

    index = index + 1
        optionsTable[index] = {
            type = "dropdown",
            name = pChat.lang.soundforincwhisps,
            tooltip = pChat.lang.soundforincwhispsTT,
            choices = {
                pChat.lang.soundforincwhispschoice[SOUNDS.NONE],
                pChat.lang.soundforincwhispschoice[SOUNDS.NEW_NOTIFICATION],
                pChat.lang.soundforincwhispschoice[SOUNDS.DEFAULT_CLICK],
                pChat.lang.soundforincwhispschoice[SOUNDS.EDIT_CLICK],
            },
            width = "full",
            default = defaults.soundforincwhisps, --> SOUNDS.NEW_NOTIFICATION
            getFunc = function() return pChat.lang.soundforincwhispschoice[pChat.opts.soundforincwhisps] end,
            setFunc = function(choice)
                if choice == pChat.lang.soundforincwhispschoice[SOUNDS.NONE] then
                    pChat.opts.soundforincwhisps = SOUNDS.NONE
                    PlaySound(SOUNDS.NONE)
                elseif choice == pChat.lang.soundforincwhispschoice[SOUNDS.NEW_NOTIFICATION] then
                    pChat.opts.soundforincwhisps = SOUNDS.NEW_NOTIFICATION
                    PlaySound(SOUNDS.NEW_NOTIFICATION)
                elseif choice == pChat.lang.soundforincwhispschoice[SOUNDS.DEFAULT_CLICK] then
                    pChat.opts.soundforincwhisps = SOUNDS.DEFAULT_CLICK
                    PlaySound(SOUNDS.DEFAULT_CLICK)
                elseif choice == pChat.lang.soundforincwhispschoice[SOUNDS.EDIT_CLICK] then
                    pChat.opts.soundforincwhisps = SOUNDS.EDIT_CLICK
                    PlaySound(SOUNDS.EDIT_CLICK)
                else
                    -- When clicking on LAM default button
                    pChat.opts.soundforincwhisps = defaults.soundforincwhisps
                end
            end,
        }

When user click on a button, a sound is played (see the setFunc). When user click on "reinit" button, "default" send value to setFunc and sound is not played. because I send the stored value, not a dropdown one.

When user don't get a saved vars, Zo_VavedVars will set the value to (here) defaults.soundforincwhisps. Then the getFunc will handle it. I was maybe tired to see it.

If you want some exemple of complex LAM build tables, I recommand you pChat and MiniMap. there is good example inside.

sirinsidiator commented 8 years ago

this is now a thing