flold

Broker_ACP snippet

Dec 27th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.04 KB | None | 0 0
  1. ----- Broker ACP -----
  2. myACP_LQT = LibStub("LibQTip-1.0")
  3.  
  4.  
  5. local LDB_Name = 'ACP'
  6. local BrokerName = 'Broker_' .. LDB_Name
  7. local target_addon = 'acp'
  8. local command_line = '/acp'
  9. local icon = "Interface\\Icons\\INV_GIZMO_GOBLINGTONKCONTROLLER"
  10. local name, title, notes, enabled, loadable, reason, security = GetAddOnInfo(target_addon)
  11. if enabled then
  12.     if type(myObjACP) ~= 'table' then
  13.         myObjACP = LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject(BrokerName, {})
  14.     end
  15.     local myObj = myObjACP
  16.     myObj.type = "launcher"
  17.     myObj.label = LDB_Name
  18.     myObj.text = LDB_Name
  19.     myObj.icon = icon
  20. else
  21.     myObjACP = {}
  22. end
  23.  
  24. function myObjACP.OnEnter(self)
  25.     local ADDON_NAME = 'Broker_ACP'
  26.     if not (myACP_LQT:IsAcquired(ADDON_NAME)) then
  27.         Broker_ACP_tooltip = myACP_LQT:Acquire(ADDON_NAME, 3, "LEFT", "LEFT", "LEFT")
  28.         Broker_ACP_tooltip:SmartAnchorTo(self)
  29.         Broker_ACP_tooltip:SetAutoHideDelay(0.25, self)
  30.     end
  31.     Broker_ACP_ShowTooltip()
  32. end
  33.  
  34. function myObjACP.OnLeave(self) end
  35.  
  36. function myObjACP:OnClick(button)
  37.     ACP:ToggleUI()
  38. end
  39.  
  40. function Broker_ACP_ShowTooltip()
  41.     local line
  42.    
  43.     Broker_ACP_tooltip:Clear()
  44.    
  45.     line = Broker_ACP_tooltip:AddLine()
  46.     line = Broker_ACP_tooltip:SetCell(line, 1, 'Disable All')
  47.     Broker_ACP_tooltip:SetLineScript(line, 'OnMouseUp', Broker_ACP_OnMouseUp, 'Disable All')
  48.    
  49.     local PlayerClass = UnitClass("player")
  50.     for k, v in pairs(ACP_Data.AddonSet) do
  51.         if type(ACP_Data.AddonSet[k]["name"]) ~= 'nil' then
  52.             line = Broker_ACP_tooltip:AddLine()
  53.             line = Broker_ACP_tooltip:SetCell(line, 1, tostring(k) .. " - " .. ACP_Data.AddonSet[k]["name"])
  54.             line = Broker_ACP_tooltip:SetCell(line, 2, Broker_ACP_SetIsEnabled(k))
  55.             Broker_ACP_tooltip:SetLineScript(line, 'OnMouseUp', Broker_ACP_OnMouseUp, k)
  56.         elseif k == PlayerClass then
  57.             line = Broker_ACP_tooltip:AddLine()
  58.             line = Broker_ACP_tooltip:SetCell(line, 1, k)
  59.             line = Broker_ACP_tooltip:SetCell(line, 2, Broker_ACP_SetIsEnabled(k))
  60.             Broker_ACP_tooltip:SetLineScript(line, 'OnMouseUp', Broker_ACP_OnMouseUp, k)
  61.         end
  62.     end
  63.    
  64.     line = Broker_ACP_tooltip:AddLine()
  65.     line = Broker_ACP_tooltip:SetCell(line, 1, "|cff00ff00-------------------|r")
  66.    
  67.     line = Broker_ACP_tooltip:AddLine()
  68.     line = Broker_ACP_tooltip:SetCell(line, 1, 'Reload UI')
  69.     Broker_ACP_tooltip:SetLineScript(line, 'OnMouseUp', Broker_ACP_OnMouseUp, 'ReloadUI')
  70.    
  71.     Broker_ACP_tooltip:Show()
  72.    
  73.    
  74. end
  75.  
  76.  
  77. function Broker_ACP_OnMouseUp(frame, var, button)
  78.     if var == 'Disable All' then
  79.         ACP:DisableAllAddons()
  80.         local PlayerClass = UnitClass("player")
  81.         ACP:LoadSet(PlayerClass)
  82.     elseif var == 'Toggle ACP' then
  83.         ACP:ToggleUI()
  84.     elseif var == 'ReloadUI' then
  85.         StaticPopupDialogs["EXAMPLE_HELLOWORLD"] = {
  86.             text = "Do you want to ReloadUI?",
  87.             button1 = "Yes",
  88.             button2 = "No",
  89.             OnAccept = function()
  90.                 ReloadUI()
  91.             end,
  92.             timeout = 0,
  93.             whileDead = true,
  94.             hideOnEscape = true,
  95.             preferredIndex = 3, -- avoid some UI taint, see http://www.wowace.com/announcements/how-to-avoid-some-ui-taint/
  96.         }
  97.         StaticPopup_Show("EXAMPLE_HELLOWORLD")
  98.     else
  99.         if button == 'LeftButton' then
  100.             ACP:LoadSet(var)
  101.         else
  102.             ACP:UnloadSet(var)
  103.         end
  104.     end
  105.     Broker_ACP_ShowTooltip()
  106. end
  107.  
  108. function Broker_ACP_SetIsEnabled(k)
  109.     local AllAddonsForSetEnabled = "Enabled"
  110.     for i, v in pairs(ACP_Data.AddonSet[k]) do
  111.         if type(i) == "number" then
  112.             local name, title, notes, enabled, loadable, reason, security = GetAddOnInfo(v)
  113.             if not enabled and (reason ~= "MISSING") then
  114.                 AllAddonsForSetEnabled = " "
  115.                 break
  116.             end
  117.         end
  118.     end
  119.     return AllAddonsForSetEnabled
  120. end
  121. ------------------------------
Advertisement
Add Comment
Please, Sign In to add comment