Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --lam2has = LibAddonMenu to Harvne's Addon Settings Adapter
- local LibHarvensAddonSettings = LibStub("LibHarvensAddonSettings-1.0")
- --[[
- LAM 2.0
- --]]
- local lam2has, oldminor = LibStub:NewLibrary("LibAddonMenu-2.0", 8)
- if lam2has then
- local lam2hasControlTypes = {
- ["button"] = LibHarvensAddonSettings.ST_BUTTON,
- ["checkbox"] = LibHarvensAddonSettings.ST_CHECKBOX,
- ["colorpicker"] = LibHarvensAddonSettings.ST_COLOR,
- ["description"] = LibHarvensAddonSettings.ST_LABEL,
- ["dropdown"] = LibHarvensAddonSettings.ST_DROPDOWN,
- ["editbox"] = LibHarvensAddonSettings.ST_EDIT,
- ["header"] = LibHarvensAddonSettings.ST_SECTION,
- ["slider"] = LibHarvensAddonSettings.ST_SLIDER
- }
- function lam2has:RegisterAddonPanel(addonKey, panelData)
- if panelData.type ~= "panel" then
- return
- end
- if not self.addonSettings then
- self.addonSettings = {}
- end
- self.addonSettings[addonKey] = LibHarvensAddonSettings:AddAddon(panelData.name)
- end
- local function RegisterControl(addonKey, control)
- if control.type == "submenu" then
- lam2has.addonSettings[addonKey]:AddSetting({type = LibHarvensAddonSettings.ST_SECTION, label = control.name })
- for i=1,#control.controls do
- RegisterControl(addonKey, control.controls[i])
- end
- return
- end
- if control.type == "custom" or control.type == "texture" then --not supported yet
- return
- end
- control.type = lam2hasControlTypes[control.type]
- control.label = control.name
- if control.text then
- control.label = control.text
- end
- if control.choices then
- control.items = {}
- for i=1,#control.choices do
- control.items[i] = { name = control.choices[i] }
- end
- end
- if control.type == LibHarvensAddonSettings.CT_DROPDOWN then
- control.setFunction = function(combobox, name, ...)
- control.setFunc(name)
- end
- else
- control.setFunction = control.setFunc
- end
- control.getFunction = control.getFunc
- control.clickHandler = control.func
- control.format = "%f"
- lam2has.addonSettings[addonKey]:AddSetting(control)
- end
- function lam2has:RegisterOptionControls(addonKey, optionsTable)
- for i=1,#optionsTable do
- RegisterControl(addonKey, optionsTable[i])
- end
- end
- end
- --[[
- LAM 1.0
- --]]
- local lam1has, oldminor = LibStub:NewLibrary("LibAddonMenu-1.0", 9)
- if not lam1has then return end
- lam1has.addonSettings = {}
- --[[
- some addons use controls returned by lam1has:Add*,
- pawksickles for example. This dirty trick prevents
- nil exceptions
- --]]
- dirtytrick = {
- __index = function(...)
- return function(...) return lam1has end
- end
- }
- setmetatable(lam1has, dirtytrick)
- function lam1has:CreateControlPanel(id, name)
- if not self.addonSettings then
- self.addonSettings = {}
- end
- self.addonSettings[id] = LibHarvensAddonSettings:AddAddon(name)
- return id
- end
- function lam1has:AddHeader(id, unused, text)
- if type(id) == "userdata" then --no submenus
- return
- end
- self.addonSettings[id]:AddSetting({type = LibHarvensAddonSettings.ST_SECTION, label = text})
- return self
- end
- function lam1has:AddSlider(id, unused, text, tooltip, minValue, maxValue, step, getFunc, setFunc, warning, warningText)
- self.addonSettings[id]:AddSetting({
- type = LibHarvensAddonSettings.ST_SLIDER,
- label = text,
- tooltip = tooltip,
- min = minValue,
- max = maxValue,
- step = step,
- getFunction = getFunc,
- setFunction = setFunc,
- format = "%f"
- })
- return self
- end
- function lam1has:AddDropdown(id, unused, text, tooltip, validChoices, getFunc, setFunc, warning, warningText)
- local dropdown = {
- type = LibHarvensAddonSettings.ST_DROPDOWN,
- label = text,
- tooltip = tooltip,
- getFunction = getFunc,
- items = {},
- }
- dropdown.setFunction = function(combobox, name, ...)
- setFunc(name, ...)
- end
- for i=1,#validChoices do
- dropdown.items[i] = {name = validChoices[i]}
- end
- self.addonSettings[id]:AddSetting(dropdown)
- return self
- end
- function lam1has:AddCheckbox(id, unused, text, tooltip, getFunc, setFunc, warning, warningText)
- self.addonSettings[id]:AddSetting({
- type = LibHarvensAddonSettings.ST_CHECKBOX,
- tooltip = tooltip,
- label = text,
- getFunction = getFunc,
- setFunction = setFunc
- })
- return self
- end
- function lam1has:AddColorPicker(id, unused, text, tooltip, getFunc, setFunc, warning, warningText)
- self.addonSettings[id]:AddSetting({
- type = LibHarvensAddonSettings.ST_COLOR,
- tooltip = tooltip,
- label = text,
- getFunction = getFunc,
- setFunction = setFunc
- })
- return self
- end
- function lam1has:AddEditBox(id, unused, text, tooltip, isMultiLine, getFunc, setFunc, warning, warningText)
- self.addonSettings[id]:AddSetting({
- type = LibHarvensAddonSettings.ST_EDIT,
- tooltip = tooltip,
- label = text,
- getFunction = getFunc,
- setFunction = setFunc
- })
- return self
- end
- function lam1has:AddButton(id, unused, text, tooltip, onClick, warning, warningText)
- self.addonSettings[id]:AddSetting({
- type = LibHarvensAddonSettings.ST_BUTTON,
- tooltip = tooltip,
- label = text,
- clickHandler = onClick,
- })
- return self
- end
- function lam1has:AddDescription(id, unused, text, titleText)
- self.addonSettings[id]:AddSetting({
- type = LibHarvensAddonSettings.ST_LABEL,
- label = text
- })
- return self
- end
- function lam1has:AddSubMenu(panelID, controlName, text, tooltip) --not supported yet
- return self
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement