Advertisement
Harven

lam2has.lua

Jun 16th, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.27 KB | None | 0 0
  1. --lam2has = LibAddonMenu to Harvne's Addon Settings Adapter
  2.  
  3. local LibHarvensAddonSettings = LibStub("LibHarvensAddonSettings-1.0")
  4.  
  5. --[[
  6.  
  7. LAM 2.0
  8.  
  9. --]]
  10.  
  11. local lam2has, oldminor = LibStub:NewLibrary("LibAddonMenu-2.0", 8)
  12. if lam2has then
  13.  
  14. local lam2hasControlTypes = {
  15.     ["button"] = LibHarvensAddonSettings.ST_BUTTON,
  16.     ["checkbox"] = LibHarvensAddonSettings.ST_CHECKBOX,
  17.     ["colorpicker"] = LibHarvensAddonSettings.ST_COLOR,
  18.     ["description"] = LibHarvensAddonSettings.ST_LABEL,
  19.     ["dropdown"] = LibHarvensAddonSettings.ST_DROPDOWN,
  20.     ["editbox"] = LibHarvensAddonSettings.ST_EDIT,
  21.     ["header"] = LibHarvensAddonSettings.ST_SECTION,
  22.     ["slider"] = LibHarvensAddonSettings.ST_SLIDER
  23. }
  24.  
  25. function lam2has:RegisterAddonPanel(addonKey, panelData)
  26.     if panelData.type ~= "panel" then
  27.         return
  28.     end
  29.    
  30.     if not self.addonSettings then
  31.         self.addonSettings = {}
  32.     end
  33.     self.addonSettings[addonKey] = LibHarvensAddonSettings:AddAddon(panelData.name)
  34. end
  35.  
  36. local function RegisterControl(addonKey, control)
  37.     if control.type == "submenu" then
  38.         lam2has.addonSettings[addonKey]:AddSetting({type = LibHarvensAddonSettings.ST_SECTION, label = control.name })
  39.         for i=1,#control.controls do
  40.             RegisterControl(addonKey, control.controls[i])
  41.         end
  42.         return
  43.     end
  44.     if control.type == "custom" or control.type == "texture" then --not supported yet
  45.         return
  46.     end
  47.    
  48.     control.type = lam2hasControlTypes[control.type]
  49.     control.label = control.name
  50.     if control.text then
  51.         control.label = control.text
  52.     end
  53.     if control.choices then
  54.         control.items = {}
  55.         for i=1,#control.choices do
  56.             control.items[i] = { name = control.choices[i] }
  57.         end
  58.     end
  59.     if control.type == LibHarvensAddonSettings.CT_DROPDOWN then
  60.         control.setFunction = function(combobox, name, ...)
  61.             control.setFunc(name)
  62.         end
  63.     else
  64.         control.setFunction = control.setFunc
  65.     end
  66.     control.getFunction = control.getFunc
  67.     control.clickHandler = control.func
  68.     control.format = "%f"
  69.    
  70.     lam2has.addonSettings[addonKey]:AddSetting(control)
  71. end
  72.  
  73. function lam2has:RegisterOptionControls(addonKey, optionsTable)
  74.     for i=1,#optionsTable do
  75.         RegisterControl(addonKey, optionsTable[i])
  76.     end
  77. end
  78.  
  79. end
  80.  
  81. --[[
  82.  
  83. LAM 1.0
  84.  
  85. --]]
  86.  
  87. local lam1has, oldminor = LibStub:NewLibrary("LibAddonMenu-1.0", 9)
  88. if not lam1has then return end
  89.  
  90.  
  91. lam1has.addonSettings = {}
  92.  
  93. --[[
  94.     some addons use controls returned by lam1has:Add*,
  95.     pawksickles for example. This dirty trick prevents
  96.     nil exceptions
  97. --]]
  98. dirtytrick = {
  99.     __index = function(...)
  100.         return function(...) return lam1has end
  101.     end
  102. }
  103.  
  104. setmetatable(lam1has, dirtytrick)
  105.  
  106. function lam1has:CreateControlPanel(id, name)
  107.     if not self.addonSettings then
  108.         self.addonSettings = {}
  109.     end
  110.     self.addonSettings[id] = LibHarvensAddonSettings:AddAddon(name)
  111.     return id
  112. end
  113.  
  114. function lam1has:AddHeader(id, unused, text)
  115.     if type(id) == "userdata" then --no submenus
  116.         return
  117.     end
  118.    
  119.     self.addonSettings[id]:AddSetting({type = LibHarvensAddonSettings.ST_SECTION, label = text})
  120.     return self
  121. end
  122.  
  123. function lam1has:AddSlider(id, unused, text, tooltip, minValue, maxValue, step, getFunc, setFunc, warning, warningText)
  124.     self.addonSettings[id]:AddSetting({
  125.         type = LibHarvensAddonSettings.ST_SLIDER,
  126.         label = text,
  127.         tooltip = tooltip,
  128.         min = minValue,
  129.         max = maxValue,
  130.         step = step,
  131.         getFunction = getFunc,
  132.         setFunction = setFunc,
  133.         format = "%f"
  134.     })
  135.     return self
  136. end
  137.  
  138. function lam1has:AddDropdown(id, unused, text, tooltip, validChoices, getFunc, setFunc, warning, warningText)
  139.     local dropdown = {
  140.         type = LibHarvensAddonSettings.ST_DROPDOWN,
  141.         label = text,
  142.         tooltip = tooltip,
  143.         getFunction = getFunc,
  144.         items = {},
  145.     }
  146.    
  147.     dropdown.setFunction = function(combobox, name, ...)
  148.         setFunc(name, ...)
  149.     end
  150.    
  151.     for i=1,#validChoices do
  152.         dropdown.items[i] = {name = validChoices[i]}
  153.     end
  154.    
  155.     self.addonSettings[id]:AddSetting(dropdown)
  156.     return self
  157. end
  158.  
  159. function lam1has:AddCheckbox(id, unused, text, tooltip, getFunc, setFunc, warning, warningText)
  160.     self.addonSettings[id]:AddSetting({
  161.         type = LibHarvensAddonSettings.ST_CHECKBOX,
  162.         tooltip = tooltip,
  163.         label = text,
  164.         getFunction = getFunc,
  165.         setFunction = setFunc
  166.     })
  167.     return self
  168. end
  169.  
  170. function lam1has:AddColorPicker(id, unused, text, tooltip, getFunc, setFunc, warning, warningText)
  171.     self.addonSettings[id]:AddSetting({
  172.         type = LibHarvensAddonSettings.ST_COLOR,
  173.         tooltip = tooltip,
  174.         label = text,
  175.         getFunction = getFunc,
  176.         setFunction = setFunc
  177.     })
  178.     return self
  179. end
  180.  
  181. function lam1has:AddEditBox(id, unused, text, tooltip, isMultiLine, getFunc, setFunc, warning, warningText)
  182.     self.addonSettings[id]:AddSetting({
  183.         type = LibHarvensAddonSettings.ST_EDIT,
  184.         tooltip = tooltip,
  185.         label = text,
  186.         getFunction = getFunc,
  187.         setFunction = setFunc
  188.     })
  189.     return self
  190. end
  191.  
  192. function lam1has:AddButton(id, unused, text, tooltip, onClick, warning, warningText)
  193.     self.addonSettings[id]:AddSetting({
  194.         type = LibHarvensAddonSettings.ST_BUTTON,
  195.         tooltip = tooltip,
  196.         label = text,
  197.         clickHandler = onClick,
  198.     })
  199.     return self
  200. end
  201.  
  202. function lam1has:AddDescription(id, unused, text, titleText)
  203.     self.addonSettings[id]:AddSetting({
  204.         type = LibHarvensAddonSettings.ST_LABEL,
  205.         label = text
  206.     })
  207.     return self
  208. end
  209.  
  210. function lam1has:AddSubMenu(panelID, controlName, text, tooltip) --not supported yet
  211.     return self
  212. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement