Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function AddonLoaded(eventType, addonName)
- if addonName ~= "HarvensAddonSettingsExample" then
- return
- end
- local LibHarvensAddonSettings = LibHarvensAddonSettings
- local options = {
- allowDefaults = true, --will allow users to reset the settings to default values
- allowRefresh = true, --if this is true, when one of settings is changed, all other settings will be checked for state change (disable/enable)
- defaultsFunction = function() --this function is called when allowDefaults is true and user hit the reset button
- d("Reset")
- end,
- }
- --Create settings "container" for your addon
- --First parameter is the name that will be displayed in the options,
- --Second parameter is the options table (it is optional)
- local settings = LibHarvensAddonSettings:AddAddon("Settings Examples", options)
- if not settings then
- return
- end
- local areSettingsDisabled = false
- --[[
- CHECKBOX
- --]]
- local checked = false
- --Define checkbox table
- local checkbox = {
- type = LibHarvensAddonSettings.ST_CHECKBOX, --setting type
- label = "Example Checkbox", --label text
- tooltip = "This is an example checkbox", --tooltip text (optional)
- default = false, --default value, only used when options.allowDefaults == true (optional)
- setFunction = function(state) --this function is called when the setting is changed
- checked = state
- end,
- getFunction = function() --this function is called to set initial state of the checkbox
- return checked
- end,
- disable = function() return areSettingsDisabled end, --when options.allowRefresh == true, this function will be called when any other setting is changed (optional)
- }
- --Add the checkbox to your "container"
- settings:AddSetting(checkbox)
- --And that's is everything, below are other controls examples
- --[[
- SLIDER
- --]]
- local sliderVal = 5
- local slider = {
- type = LibHarvensAddonSettings.ST_SLIDER,
- label = "Example Slider",
- tooltip = "This is an example slider",
- setFunction = function(value)
- sliderVal = value
- end,
- getFunction = function()
- return sliderVal
- end,
- default = 5,
- min = 1,
- max = 10,
- step = 1,
- unit = "s", --optional unit
- format = "%d", --value format
- disable = function() return areSettingsDisabled end,
- }
- settings:AddSetting(slider)
- --[[
- BUTTON
- --]]
- local button = {
- type = LibHarvensAddonSettings.ST_BUTTON,
- label = "Example Button",
- tooltip = "This is an example button",
- buttonText = "Click me!",
- clickHandler = function(control, button)
- d("Click")
- end,
- disable = function() return areSettingsDisabled end,
- }
- settings:AddSetting(button)
- --[[
- EDIT
- --]]
- local editValue = "Hello"
- local edit = {
- type = LibHarvensAddonSettings.ST_EDIT,
- label = "Example Edit",
- tooltip = "This is an example edit",
- default = "Hello",
- setFunction = function(value)
- editValue = value
- end,
- getFunction = function()
- return editValue
- end,
- disable = function() return areSettingsDisabled end,
- }
- settings:AddSetting(edit)
- --[[
- DROPDOWN (COMBOBOX)
- --]]
- local selectedText = "Item 4"
- local dropdown = {
- type = LibHarvensAddonSettings.ST_DROPDOWN,
- label = "Example Dropdown",
- tooltip = "This is an example dropdown",
- setFunction = function(combobox, name, item)
- d("Selected item: "..name..", data: "..tostring(item.data))
- end,
- getFunction = function()
- return selectedText
- end,
- default = "Item 4",
- items = {
- {
- name = "Item 1",
- data = 1
- },
- {
- name = "Item 2",
- data = "Some string"
- },
- {
- name = "Item 3",
- data = true
- },
- {
- name = "Item 4",
- data = {
- value = 10
- }
- },
- },
- disable = function() return areSettingsDisabled end,
- }
- settings:AddSetting(dropdown)
- --[[
- LABEL
- --]]
- local label = {
- type = LibHarvensAddonSettings.ST_LABEL,
- label = "Example Label\nMultiline! |cff0000and colors|r",
- }
- settings:AddSetting(label)
- --[[
- SECTION TITLE
- --]]
- local section = {
- type = LibHarvensAddonSettings.ST_SECTION,
- label = "Example Section",
- }
- settings:AddSetting(section)
- --[[
- COLOR PICKER
- --]]
- local colorR = 0.3
- local colorG = 0.6
- local colorB = 0.2
- local colorA = 1.0
- local color = {
- type = LibHarvensAddonSettings.ST_COLOR,
- label = "Example Color",
- tooltip = "This is an example color",
- setFunction = function(...) --newR, newG, newB, newA
- colorR, colorG, colorB, colorA = ...
- end,
- default = {0.3, 0.6, 0.2, 1.0},
- getFunction = function()
- return colorR, colorG, colorB, colorA
- end,
- disable = function() return areSettingsDisabled end,
- }
- settings:AddSetting(color)
- local disableAll = {
- type = LibHarvensAddonSettings.ST_CHECKBOX,
- label = "Disable All",
- tooltip = "This will disable all other settings",
- default = false,
- setFunction = function(state)
- areSettingsDisabled = state
- end,
- getFunction = function()
- return areSettingsDisabled
- end,
- }
- settings:AddSetting(disableAll)
- --you can add all settings with one function call like this:
- --settings:AddSettings({checkbox, slider, button, edit, dropdown, label, section, color})
- end
- EVENT_MANAGER:RegisterForEvent("HarvensAddonSettignsExample", EVENT_ADD_ON_LOADED, AddonLoaded)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement