Advertisement
Guest User

Untitled

a guest
Feb 6th, 2015
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 98.84 KB | None | 0 0
  1. --
  2. -- AutoBarButton
  3. -- Copyright 2007+ Toadkiller of Proudmoore.
  4. --
  5. -- Buttons for AutoBar
  6. -- http://muffinmangames.com
  7. --
  8.  
  9. local AutoBar = AutoBar
  10. local spellNameList = AutoBar.spellNameList
  11. local spellIconList = AutoBar.spellIconList
  12.  
  13. local AceOO = AceLibrary("AceOO-2.0")
  14. local LibKeyBound = LibStub("LibKeyBound-1.0")
  15. local L = AutoBar.locale
  16. local _G = getfenv(0)
  17. local _
  18.  
  19.  
  20. AutoBarButton = AceOO.Class(AutoBar.Class.Button)
  21. AutoBarButton.dirtyButton = {}
  22.  
  23.  
  24. spellNameList["Lay on Hands"], _, spellIconList["Lay on Hands"] = AutoBar:LoggedGetSpellInfo(633)
  25. spellNameList["Feign Death"], _, spellIconList["Feign Death"] = AutoBar:LoggedGetSpellInfo(5384)
  26. spellNameList["Disengage"], _, spellIconList["Disengage"] = AutoBar:LoggedGetSpellInfo(781)
  27. spellNameList["Ice Block"], _, spellIconList["Ice Block"] = AutoBar:LoggedGetSpellInfo(27619)
  28. spellNameList["Last Stand"], _, spellIconList["Last Stand"] = AutoBar:LoggedGetSpellInfo(12975)
  29. spellNameList["Desperate Prayer"], _, spellIconList["Desperate Prayer"] = AutoBar:LoggedGetSpellInfo(19236)
  30.  
  31. spellNameList["Vanish"], _, spellIconList["Vanish"] = AutoBar:LoggedGetSpellInfo(1856)
  32. spellNameList["Nature's Swiftness"], _, spellIconList["Nature's Swiftness"] = AutoBar:LoggedGetSpellInfo(132158)
  33. spellNameList["Frenzied Regeneration"], _, spellIconList["Frenzied Regeneration"] = AutoBar:LoggedGetSpellInfo(22842)
  34. spellNameList["Shadowform"], _, spellIconList["Shadowform"] = AutoBar:LoggedGetSpellInfo(15473)
  35. spellNameList["Wild Charge"], _, spellIconList["Wild Charge"] = AutoBar:LoggedGetSpellInfo(102401)
  36. spellNameList["Rune Tap"], _, spellIconList["Rune Tap"] = AutoBar:LoggedGetSpellInfo(48982)
  37. spellNameList["Bear Form"], _, spellIconList["Bear Form"] = AutoBar:LoggedGetSpellInfo(5487)
  38. spellNameList["Mangle"], _, spellIconList["Mangle"] = AutoBar:LoggedGetSpellInfo(33917)
  39. spellNameList["Cat Form"], _, spellIconList["Cat Form"] = AutoBar:LoggedGetSpellInfo(768)
  40. spellNameList["Ghost Wolf"], _, spellIconList["Ghost Wolf"] = AutoBar:LoggedGetSpellInfo(2645)
  41. spellNameList["Shadowstep"], _, spellIconList["Shadowstep"] = AutoBar:LoggedGetSpellInfo(36554)
  42. spellNameList["Charge"], _, spellIconList["Charge"] = AutoBar:LoggedGetSpellInfo(100)
  43. spellNameList["Heroic Leap"], _, spellIconList["Heroic Leap"]  = AutoBar:LoggedGetSpellInfo(6544)
  44. spellNameList["Intervene"], _, spellIconList["Intervene"]  = AutoBar:LoggedGetSpellInfo(3411)
  45. spellNameList["Enraged Regeneration"] = AutoBar:LoggedGetSpellInfo(55694)
  46.  
  47.  
  48.  
  49.  
  50. function AutoBarButton.prototype:init(parentBar, buttonDB)
  51.     AutoBarButton.super.prototype.init(self, parentBar, buttonDB)
  52. end
  53.  
  54.  
  55. -- Return the interface display name
  56. function AutoBarButton:GetDisplayName(buttonDB)
  57.     local name
  58.     if (buttonDB.name) then
  59.         name = tostring(buttonDB.name)
  60.     else
  61.         name = L[buttonDB.buttonKey] or L["Custom"]
  62.     end
  63.     return name
  64. end
  65.  
  66.  
  67. -- Handle dragging of items, macros, spells to the button
  68. -- Handle rearranging of buttons when buttonLock is off
  69. function AutoBarButton:AddCategoryItem(category, itemType, itemId, itemInfo)
  70.     local categoryInfo = AutoBarCategoryList[category]
  71.     local itemsListDB = categoryInfo.customCategoriesDB.items
  72.     local itemIndex = # itemsListDB + 1
  73. --AutoBar:Print("AutoBarButton.prototype:DropLink " .. tostring(categoryInfo.description) .. "itemType " .. tostring(itemType) .. " itemId " .. tostring(itemId) .. " itemInfo " .. tostring(itemInfo))
  74.     local itemDB = {
  75.         itemType = itemType,
  76.         itemId = itemId,
  77.         itemInfo = itemInfo
  78.     }
  79.     itemsListDB[itemIndex] = itemDB
  80.     if (itemType == "spell") then
  81.         local spellName, spellRank = GetSpellBookItemName(itemId, itemInfo)
  82.         itemDB.spellName = spellName
  83.         itemDB.spellRank = spellRank
  84.         itemDB.spellClass = AutoBar.CLASS
  85.     else
  86.         itemDB.spellName = nil
  87.         itemDB.spellRank = nil
  88.         itemDB.spellClass = nil
  89.     end
  90. end
  91.  
  92.  
  93. -- Handle dragging of items, macros, spells to the button
  94. -- Handle rearranging of buttons when buttonLock is off
  95. function AutoBarButton.prototype:DropLink(itemType, itemId, itemInfo)
  96.     if (itemType == "item" or itemType == "spell" or itemType == "macro") then
  97.         -- Select a Custom Category to use
  98.         local categoryInfo, categoryKey, dropped
  99.         for index = # self, 1, -1 do
  100.             categoryKey = self[index]
  101.             categoryInfo = AutoBarCategoryList[categoryKey]
  102.  
  103.             if (categoryInfo and categoryInfo.customKey) then
  104.                 AutoBarButton:AddCategoryItem(categoryKey, itemType, itemId, itemInfo)
  105.                 AutoBar:BarButtonChanged()
  106.                 dropped = true
  107.                 break
  108.             end
  109.         end
  110.  
  111.         -- Create a Custom Category to use
  112.         local buttonDB = self.buttonDB
  113.         if (not dropped and buttonDB.drop) then
  114.             local buttonCategoryIndex = # buttonDB + 1
  115.             local categoryKey = AutoBar:CategoryNew()
  116.             buttonDB[buttonCategoryIndex] = categoryKey
  117.             AutoBarButton:AddCategoryItem(categoryKey, itemType, itemId, itemInfo)
  118.             AutoBar:BarButtonChanged()
  119.         end
  120.     end
  121. end
  122.  
  123.  
  124. -- Handle dragging of items, macros, spells to the button
  125. -- Handle rearranging of buttons when buttonLock is off
  126. function AutoBarButton.prototype:DropObject()
  127.     local toObject = self
  128.     local fromObject = AutoBar:GetDraggingObject()
  129.     local refreshNeeded
  130. --AutoBar:Print("AutoBarButton.prototype:DropObject " .. tostring(fromObject and fromObject.buttonDB.buttonKey or "none") .. " --> " .. tostring(toObject.buttonDB.buttonKey))
  131.     if (fromObject and fromObject ~= toObject and AutoBar.moveButtonsMode) then
  132.         AutoBar:ButtonMove(fromObject.parentBar.barKey, fromObject.order, toObject.parentBar.barKey, toObject.order)
  133.         AutoBar:BarButtonChanged()
  134.         ClearCursor()
  135.     else
  136.         local buttonDB = toObject.buttonDB
  137.         if (buttonDB.hasCustomCategories and AutoBar.moveButtonsMode or buttonDB.drop) then
  138.             local itemType, itemId, itemInfo = GetCursorInfo()
  139.             if (itemType == "item" or itemType == "spell" or itemType == "macro") then
  140. --AutoBar:Print("AutoBarButton.prototype:DropObject itemType " .. tostring(itemType) .. " itemId " .. tostring(itemId) .. " itemInfo " .. tostring(itemInfo))
  141.                 toObject:DropLink(itemType, itemId, itemInfo)
  142.                 refreshNeeded = true
  143.                 ClearCursor()
  144.                 AutoBar:CategoriesChanged()
  145.             end
  146.         end
  147.     end
  148.  
  149.     if (refreshNeeded) then
  150.         if (fromObject) then
  151.             fromObject:UpdateButton()
  152.         end
  153.     end
  154.     AutoBar:SetDraggingObject(nil)
  155. end
  156.  
  157.  
  158.  
  159. -- popupNazi makes sure we dont have multiple popups open.  Google "Soup Nazi" for how this is done
  160. -- There are two cases:
  161.  
  162. --  1) Rapid movement or movement off the window breaks the Blizzard code.  We use a sensible timer to fix this - popupNaziSnippet
  163. local popupNaziSnippet = [[
  164.     local flag = self:IsUnderMouse(true)
  165.     if (flag) then
  166.         local queued = control:SetTimer(1, "hoverCheck")
  167.         print("We're under the mouse");
  168.     else
  169.         print("Not under the mouse");
  170.         local anchorButton = self:GetFrameRef("anchorButton")
  171.         x, y = anchorButton:GetMousePosition()
  172.         if (x and y) then
  173.             local queued = control:SetTimer(1, "hoverCheck")
  174.         else
  175.             self:Hide()
  176.         end
  177.     end
  178. ]]
  179.  
  180. --  2) Track the popped open menu.  If we open a new one we sensibly close the old one - popupNaziHandler
  181. local popupNaziHandler = CreateFrame("Frame", "AutoBarPopupNaziHandler", nil, "SecureHandlerAttributeTemplate")
  182. popupNaziHandler:SetAttribute("_onattributechanged", [[
  183.     local openHandler = self:GetAttribute("openhandler")
  184.     if (name == "openhandler") then
  185.         local openHandler = self:GetAttribute("openhandler")
  186.         local oldOpenHandler = self:GetAttribute("oldopenhandler")
  187.         if (oldOpenHandler and oldOpenHandler ~= openHandler) then
  188. --          print("hiding old one", oldOpenHandler, openHandler)
  189.             oldOpenHandler:Hide()
  190.         end
  191.         self:SetAttribute("oldopenhandler", openHandler)
  192.     end
  193. ]])
  194.  
  195.  
  196. -- The basic idea is to have an intervening handler frame that is Shown / Hidden if popupOnModifier is true / nil
  197. local snippetPopupKey = [[
  198.     if (newstate == "1") then
  199.         self:Show()
  200.     else
  201.         self:Hide()
  202.     end
  203. ]]
  204. local popupKeyStates = "[modifier:shift] 1; 0"
  205.  
  206. -- Clone the popup into the anchorButton
  207. local snippetOnClick = [[
  208.     local popupHeader = self:GetFrameRef("popupHeader")
  209.     local anchorButton = popupHeader:GetFrameRef("anchorButton")
  210.  
  211.     -- Move the attributes that make the button work
  212.     local itemType = self:GetAttribute("type")
  213.     local itemType1 = self:GetAttribute("type1")
  214.     if(itemType1) then
  215.         anchorButton:SetAttribute("type1", self:GetAttribute("type1"))
  216.         anchorButton:SetAttribute("target-slot1", self:GetAttribute("target-slot1"))
  217.         anchorButton:SetAttribute("target-bag1", self:GetAttribute("target-bag1")) 
  218.         anchorButton:SetAttribute("item1", self:GetAttribute("item1"))
  219.         anchorButton:SetAttribute("spell1", self:GetAttribute("spell1"))
  220.     end
  221.     anchorButton:SetAttribute("type", self:GetAttribute("type"))
  222.     anchorButton:SetAttribute("unit", self:GetAttribute("unit"))
  223.     anchorButton:SetAttribute("target-slot", self:GetAttribute("target-slot"))
  224.     anchorButton:SetAttribute("target-bag", self:GetAttribute("target-bag"))   
  225.  
  226.     if (itemType == "item") then
  227.         anchorButton:SetAttribute("item", self:GetAttribute("item"))
  228.     elseif (itemType == "spell") then
  229.         anchorButton:SetAttribute("spell", self:GetAttribute("spell"))
  230.     elseif (itemType == "macro") then
  231.         anchorButton:SetAttribute("macro", self:GetAttribute("macro"))
  232.         anchorButton:SetAttribute("macrotext", self:GetAttribute("macrotext"))
  233.         anchorButton:SetAttribute("macroName", self:GetAttribute("macroName"))
  234.         anchorButton:SetAttribute("macroBody", self:GetAttribute("macroBody"))
  235.     end
  236.  
  237.     -- Move the right click attributes
  238.     itemType = self:GetAttribute("type2")
  239.     anchorButton:SetAttribute("type2", self:GetAttribute("type2"))
  240.     anchorButton:SetAttribute("target-slot2", self:GetAttribute("target-slot2"))
  241.     anchorButton:SetAttribute("target-bag2", self:GetAttribute("target-bag2"))
  242.     anchorButton:SetAttribute("unit2", self:GetAttribute("unit2"))
  243.     if (itemType == "item") then
  244.         anchorButton:SetAttribute("item2", self:GetAttribute("item2"))
  245.     elseif (itemType == "spell") then
  246.         anchorButton:SetAttribute("spell2", self:GetAttribute("spell2"))
  247.     elseif (itemType == "macro") then
  248.         anchorButton:SetAttribute("macro2", self:GetAttribute("macro2"))
  249.         anchorButton:SetAttribute("macrotext2", self:GetAttribute("macrotext2"))
  250.     end
  251.  
  252.     -- Tooltip and Icon support
  253.     anchorButton:SetAttribute("category", self:GetAttribute("category"))
  254.     anchorButton:SetAttribute("itemId", self:GetAttribute("itemId"))
  255.     anchorButton:SetAttribute("icon", self:GetAttribute("icon"))
  256.     anchorButton:SetAttribute("itemLink", self:GetAttribute("itemLink"))
  257.  
  258.     -- Arrange on Use source popup button
  259.     anchorButton:SetAttribute("sourceButton", self)
  260. ]]
  261.  
  262. -- Clicking on a popup changes the anchor button spell.  This updates the icon texture to match
  263. local function UpdateIcon(button, texture)
  264.     button.icon:SetTexture(texture)
  265. end
  266.  
  267. -- Clicking on a popup changes the anchor button spell.  This updates the icon texture to match
  268. local function UpdateHandlers(frame, sourceButton)
  269.     sourceButton = frame:GetAttribute("sourceButton")
  270.     local TooltipSet = frame:GetAttribute("TooltipSet")
  271. ---print("UpdateHandlers", sourceButton, TooltipSet, frame.TooltipSet)
  272.     frame.TooltipSet = TooltipSet
  273.  
  274.     local itemId
  275.     local buttonKey = frame.class.buttonName
  276.     local itemType = frame:GetAttribute("type")
  277.     if (itemType) then
  278.         if (itemType == "item") then
  279.             itemId = frame:GetAttribute("itemId")
  280.         elseif (itemType == "spell") then
  281.             itemId = frame:GetAttribute("spell")
  282.         elseif (itemType == "macro") then
  283.             itemId = frame:GetAttribute("macroId")
  284.         end
  285.     end
  286.  
  287.     local buttonData = AutoBar.db.char.buttonDataList[buttonKey]
  288.     if (not buttonData) then
  289.         buttonData = {}
  290.         AutoBar.db.char.buttonDataList[buttonKey] = buttonData
  291.     end
  292.  
  293.     buttonData.arrangeOnUse = itemId
  294. end
  295.  
  296.  
  297.  
  298. local MAX_POPUP_HEIGHT = 8
  299.  
  300. -- Lay out the popups
  301. function AutoBarButton.prototype:SetupPopups(nItems)
  302.     local buttonKey = self.buttonDB.buttonKey
  303.     local frame = self.frame
  304.     local popupHeader = frame.popupHeader
  305.     local popupKeyHandler = frame.popupKeyHandler
  306.     local barKey = self.parentBar.barKey
  307.     local layoutDB = AutoBar.barLayoutDBList[barKey]
  308.  
  309.     local padding = layoutDB.padding
  310.     local hitRectPadding = -math.max(4, padding)
  311.     local popupDirection = layoutDB.popupDirection
  312.     local relativeSide, side, splitRelativeSide, splitSide
  313.     local paddingX, paddingY, splitPaddingX, splitPaddingY = 0, 0, 0, 0
  314.     if (popupDirection == "1") then -- Top
  315.         side = "BOTTOM"
  316.         relativeSide = "TOP"
  317.         paddingY = padding
  318.         splitSide = "LEFT"
  319.         splitRelativeSide = "RIGHT"
  320.         splitPaddingX = padding
  321.     elseif (popupDirection == "2") then -- Left
  322.         side = "RIGHT"
  323.         relativeSide = "LEFT"
  324.         paddingX = -padding
  325.         splitSide = "BOTTOM"
  326.         splitRelativeSide = "TOP"
  327.         splitPaddingY = padding
  328.     elseif (popupDirection == "3") then -- Bottom
  329.         side = "TOP"
  330.         relativeSide = "BOTTOM"
  331.         paddingY = -padding
  332.         splitSide = "RIGHT"
  333.         splitRelativeSide = "LEFT"
  334.         splitPaddingX = -padding
  335.     elseif (popupDirection == "4") then -- Right
  336.         side = "LEFT"
  337.         relativeSide = "RIGHT"
  338.         paddingX = padding
  339.         splitSide = "TOP"
  340.         splitRelativeSide = "BOTTOM"
  341.         splitPaddingY = -padding
  342.     end
  343.  
  344.     -- For gigantic popups, split it up into a block
  345.     local nSplits = math.ceil(nItems / MAX_POPUP_HEIGHT)
  346.     local splitLength, splitRelativePoint
  347.     if (nSplits > 1) then
  348.         splitLength = math.ceil(nItems / nSplits)
  349.     else
  350.         splitLength = nItems + 10
  351.     end
  352.  
  353.     -- Arrange on Use Buttons show the first Button because it needs to remain there for changes during combat.
  354.     local arrangeOnUse = self.buttonDB.arrangeOnUse
  355.     local popupIndexStart = 2
  356.     if (arrangeOnUse) then
  357.         popupIndexStart = 1
  358.     end
  359.  
  360.     local buttonItems = AutoBarSearch.items:GetList(buttonKey)
  361.     local buttonWidth = layoutDB.buttonWidth
  362.     local buttonHeight = layoutDB.buttonHeight
  363.     local relativePoint = popupHeader
  364.     for popupButtonIndex = popupIndexStart, nItems, 1 do
  365.         local popupButton = AutoBar.Class.PopupButton:GetPopupButton(self, popupButtonIndex, popupHeader, popupKeyHandler)
  366.         local popupButtonFrame = popupButton.frame
  367.  
  368.         -- Wrap OnClick with the Arrange on use code
  369.         local wrapped = popupButtonFrame.snippetOnClick
  370.         if (wrapped and (not arrangeOnUse)) then
  371.             local header, preBody, postBody = popupHeader:UnwrapScript(popupButtonFrame, "OnClick")
  372.             assert(wrapped == preBody, "wrapped ~= preBody in UnwrapScript")
  373.             -- ToDo: Are we the only wrapping people?  Maybe add some recursive unwrapping of our exact script.
  374.         elseif ((not wrapped) and arrangeOnUse) then
  375.             SecureHandlerWrapScript(popupButtonFrame, "OnClick", popupHeader, snippetOnClick)
  376.             popupButtonFrame.snippetOnClick = snippetOnClick
  377.         end
  378.  
  379.         -- Attach to edge of previous popupButtonFrame or the popupHeader
  380.         popupButtonFrame:ClearAllPoints()
  381.         popupButtonFrame:SetHeight(buttonHeight)
  382.         popupButtonFrame:SetWidth(buttonWidth)
  383.         popupButtonFrame:Raise()
  384.         popupButtonFrame:SetScale(1)
  385.         if (relativePoint == popupHeader) then
  386.             popupButtonFrame:SetPoint(side, relativePoint, side, paddingX, paddingY)
  387.             splitRelativePoint = popupButtonFrame
  388.         else
  389.             if (math.fmod(popupButtonIndex - popupIndexStart, splitLength) == 0) then
  390. --print(frame:GetName(), popupButtonIndex, "/", nItems, splitLength, nSplits)
  391.                 popupButtonFrame:SetPoint(splitSide, splitRelativePoint, splitRelativeSide, splitPaddingX, splitPaddingY)
  392.                 splitRelativePoint = popupButtonFrame
  393.             else
  394.                 popupButtonFrame:SetPoint(side, relativePoint, relativeSide, paddingX, paddingY)
  395.             end
  396.         end
  397.         if (popupButtonIndex == 2) then
  398.             if (popupDirection == "1") then
  399.                 popupButtonFrame:SetHitRectInsets(hitRectPadding, hitRectPadding, hitRectPadding, -padding)
  400.             elseif (popupDirection == "2") then
  401.                 popupButtonFrame:SetHitRectInsets(hitRectPadding, -padding, hitRectPadding, hitRectPadding)
  402.             elseif (popupDirection == "3") then
  403.                 popupButtonFrame:SetHitRectInsets(hitRectPadding, hitRectPadding, -padding, hitRectPadding)
  404.             elseif (popupDirection == "4") then
  405.                 popupButtonFrame:SetHitRectInsets(-padding, hitRectPadding, hitRectPadding, hitRectPadding)
  406.             end
  407.         else
  408.             popupButtonFrame:SetHitRectInsets(hitRectPadding, hitRectPadding, hitRectPadding, hitRectPadding)
  409.         end
  410.         relativePoint = popupButtonFrame
  411.  
  412.         -- Support selfcast
  413.         popupButtonFrame:SetAttribute("checkselfcast", true)
  414.         popupButtonFrame:SetAttribute("checkfocuscast", true)
  415.  
  416.         local bag, slot, spell, itemId, macroId = AutoBarSearch.sorted:GetInfo(buttonKey, popupButtonIndex)
  417.         self:SetupAttributes(popupButton, bag, slot, spell, macroId, itemId, buttonItems[itemId])
  418.         popupButton:UpdateIcon()
  419.     end
  420.  
  421.     popupHeader:ClearAllPoints()
  422. --- ToDo: fix for orientation
  423. --          popupHeader:SetWidth(buttonWidth + paddingX * 2)
  424. --          popupHeader:SetHeight((buttonHeight + paddingY) * (nItems - 1) + paddingY)
  425.     popupHeader:SetWidth(2)
  426.     popupHeader:SetHeight(2)
  427.     popupHeader:SetScale(1)
  428.     popupHeader:SetPoint(side, frame, relativeSide)
  429.     RegisterAutoHide(popupHeader, 1)
  430.  
  431.  
  432.     -- Hide unwanted buttons
  433.     for popupButtonIndex, popupButton in pairs(popupHeader.popupButtonList) do
  434.         if (popupButtonIndex > nItems) then
  435.             popupButton.frame:Hide()    -- Items have shrunk below instantiated list.  Hide the excess.
  436.         elseif (popupButtonIndex < popupIndexStart) then
  437. --print("hiding popupButtonIndex, popupIndexStart, nItems, arrangeOnUse", popupButton:getName(), popupButtonIndex, popupIndexStart, nItems, arrangeOnUse)
  438.             popupButton.frame:Hide()    -- Hide 1st popup if it is not arrange on use as it is identical to the anchorButton
  439.         elseif (self.buttonDB.alwaysPopup) then
  440.             popupButton.frame:Show()
  441.             popupHeader:Show()
  442.         else
  443.             popupButton.frame:Show()
  444.         end
  445.     end
  446. end
  447.  
  448.  
  449.  
  450. -- Set the state attributes of the button
  451. function AutoBarButton.prototype:GetHierarchicalSetting(setting)
  452.     local db = self.buttonDB
  453.     if (db[setting] ~= nil) then
  454.         return db[setting]
  455.     end
  456.     db = self.parentBar.sharedLayoutDB
  457.     if (db[setting] ~= nil) then
  458.         return db[setting]
  459.     end
  460.     db = AutoBar.db.account
  461.     if (db[setting] ~= nil) then
  462.         return db[setting]
  463.     end
  464. end
  465.  
  466.  
  467. -- Update the anchorButton after a click on a popup
  468. local snippetOnAttributeChanged = [[
  469.     if (name == "icon") then
  470.         control:CallMethod("UpdateIcon", value)
  471.     elseif (name == "sourcebutton") then -- or name == "sourceButton" Some retard code is lowercasing this.  How silly.
  472.         control:CallMethod("UpdateHandlers", self:GetAttribute("sourceButton"))
  473.     end
  474. ]]
  475.  
  476. -- Used to pop up the buttons based on popupHeader FrameRef on the button
  477. local popupHandler = CreateFrame("Frame", "AutoBarPopupHandler", nil, "SecureHandlerEnterLeaveTemplate")
  478.  
  479. -- Set the state attributes of the button
  480. function AutoBarButton.prototype:SetupButton()
  481.     local buttonKey = self.buttonDB.buttonKey
  482.     local frame = self.frame
  483.  
  484.     local bag, slot, spell, itemId, macroId = AutoBarSearch.sorted:GetInfo(buttonKey, 1)
  485.     local popupHeader = frame.popupHeader
  486.     local popupKeyHandler = frame.popupKeyHandler
  487.  
  488. --AutoBar:Print("AutoBarButton.prototype:SetupButton buttonKey " .. tostring(buttonKey) .. " bag " .. tostring(bag) .. " slot " .. tostring(slot) .. " spell " .. tostring(spell) .. " macroId " .. tostring(macroId))
  489.     if ((bag or slot or spell or macroId) and self.buttonDB.enabled) then
  490.         frame:Show()
  491.         local sortedItems = AutoBarSearch.sorted:GetList(buttonKey)
  492.         local noPopup = self.buttonDB.noPopup
  493.         local nItems = # sortedItems
  494.         if (nItems < 2) then
  495.             noPopup = true
  496.         end
  497.  
  498.         local buttonItems = AutoBarSearch.items:GetList(buttonKey)
  499.         local itemData = buttonItems[itemId]
  500.  
  501.         self:SetupAttributes(self, bag, slot, spell, macroId, itemId, itemData)
  502.         if (noPopup) then
  503.             if (popupHeader) then
  504.                 for _, popupButton in pairs(popupHeader.popupButtonList) do
  505.                     popupButton.frame:Hide()
  506.                 end
  507.             end
  508.         else
  509.             local popupOnModifier = self:GetHierarchicalSetting("popupOnShift")
  510.  
  511.             -- Create the Button's Popup Header
  512.             if (not popupHeader) then
  513.                 local name = buttonKey .. "PopupHeader"
  514.                 popupHeader = CreateFrame("Frame", name, frame, "SecureHandlerEnterLeaveTemplate")
  515.                 popupHeader:SetAttribute("_onenter", [[self:Show()]])
  516.                 popupHeader:SetAttribute("_onleave", [[self:Hide()]])
  517.                 popupHeader:SetFrameStrata("DIALOG")
  518.  
  519.                 -- Create the popupKeyHandler if required
  520.                 if (popupOnModifier) then
  521.                     -- Note that it is made a child of popupHeader, and later becomes parent to the popup buttons
  522.                     -- Hiding it will thus hide the popup buttons as well, even if popupHeader is shown
  523.                     popupKeyHandler = CreateFrame("Frame", buttonKey .. "HandlerPopupKey", popupHeader, "SecureHandlerStateTemplate")
  524.                     popupKeyHandler:SetAttribute("_onstate-modifier", snippetPopupKey)
  525.                     popupKeyHandler:SetAllPoints(popupHeader)
  526.                     RegisterStateDriver(popupKeyHandler, "modifier", popupKeyStates)
  527.                     popupKeyHandler:SetAttribute("_onenter", [[ self:GetParent():Show() ]])
  528.                     popupKeyHandler:SetAttribute("_onleave", [[ self:GetParent():Hide() ]])
  529.                     frame.popupKeyHandler = popupKeyHandler
  530.                 end
  531.  
  532.                 frame.popupHeader = popupHeader
  533.                 popupHeader.popupButtonList = {}
  534.                 RegisterAutoHide(popupHeader, 0.5)
  535.             end
  536.  
  537.             -- Add needed snippets (only execute once)
  538.             if (not frame.popupHandler) then
  539.                 frame.popupHandler = popupHandler
  540.  
  541.                 frame:SetFrameRef("popupHeader", popupHeader)
  542.                 frame:Execute([[
  543.                     popupHeader = self:GetFrameRef("popupHeader")
  544.                     popupHeader:ClearAllPoints()
  545.                     popupHeader:SetPoint("BOTTOM", self, "TOP")
  546.                     popupHeader:Raise()
  547.                     popupHeader:Hide()
  548.                 ]])
  549.  
  550.                 SecureHandlerWrapScript(frame, "OnEnter", popupHandler, [[
  551.                     popupHeader = self:GetFrameRef("popupHeader")
  552.                     popupHeader:Show()
  553.                     print("OnEnter")
  554.                 ]])
  555.                 popupHandler.TooltipHide = AutoBar.Class.BasicButton.TooltipHide
  556.                 SecureHandlerWrapScript(frame, "OnLeave", popupHandler, [[
  557.                     popupHeader = self:GetFrameRef("popupHeader")
  558.                     popupHeader:Hide()
  559.                     print("OnLeave")
  560.                 ]])
  561.                 popupHandler:SetAttribute("_adopt", frame)
  562.  
  563.                 -- Deal with rare irritating cases where Popups remain open incorrectly
  564.                 popupHeader:SetFrameRef("popupNaziHandler", popupNaziHandler)
  565.                 popupHeader:SetFrameRef("popupHeader", popupHeader)
  566.                 popupHeader:SetFrameRef("anchorButton", frame)
  567.                 popupHeader:SetAttribute("_ontimer", popupNaziSnippet)
  568.             end
  569.  
  570.             local arrangeOnUse = self.buttonDB.arrangeOnUse
  571.             local wrapped = frame.UpdateIcon
  572.             -- Trigger Updating on the Anchor Button
  573.             if (wrapped and (not arrangeOnUse)) then
  574.                 local header, preBody, postBody = popupHeader:UnwrapScript(frame, "OnAttributeChanged")
  575.             elseif ((not wrapped) and arrangeOnUse) then
  576.                 frame.UpdateIcon = UpdateIcon   -- Update Icon
  577.                 frame.UpdateHandlers = UpdateHandlers   -- Update Handlers: Tooltip
  578.                 SecureHandlerWrapScript(frame, "OnAttributeChanged", frame, snippetOnAttributeChanged)
  579.             end
  580.  
  581.             self:SetupPopups(nItems)
  582.         end
  583.  
  584.     else
  585.         frame:SetAttribute("itemId", nil)
  586.         frame:Hide()
  587.         if (popupHeader) then
  588.             popupHeader:Hide()
  589.         end
  590.  
  591.         if ((AutoBar.moveButtonsMode or AutoBar.db.account.showEmptyButtons or self.buttonDB.alwaysShow) and self.buttonDB.enabled) then
  592.             frame:Show()
  593.             if (self[1]) then
  594.                 frame:SetAttribute("category", self[# self])
  595.             else
  596.                 frame:SetAttribute("category", nil)
  597.             end
  598.         else
  599.             frame:SetAttribute("category", nil)
  600.         end
  601.     end
  602. end
  603. --[[
  604. /dump (# AutoBarSearch.sorted:GetList("AutoBarButtonRecovery"))
  605. /dump (AutoBar.buttonList["AutoBarButtonHearth"].frame.popupHeader.popupButtonList[2].frame:IsVisible())
  606. /dump (AutoBar.buttonList["AutoBarButtonHearth"].frame.popupHeader.popupButtonList[2].frame:IsShown())
  607. /script AutoBar.buttonList["AutoBarButtonHearth"].frame.popupHeader.popupButtonList[2].frame:SetPoint("RIGHT", -260,-80)
  608. --]]
  609.  
  610. -- Clear the state attributes of the button
  611. function AutoBarButton:SetupAttributesClear(frame)
  612.     frame:SetAttribute("target-slot1", nil)
  613.     frame:SetAttribute("target-slot2", nil)
  614.     frame:SetAttribute("target-bag1", nil)
  615.     frame:SetAttribute("target-bag2", nil)
  616.     frame:SetAttribute("unit2", nil)
  617.     frame:SetAttribute("type", nil)
  618.     frame:SetAttribute("type2", nil)
  619.     frame:SetAttribute("item", nil)
  620.     frame:SetAttribute("item2", nil)
  621.     frame:SetAttribute("spell", nil)
  622.     frame:SetAttribute("spell2", nil)
  623.     frame:SetAttribute("macroId", nil)
  624.     frame:SetAttribute("macro", nil)
  625.     frame:SetAttribute("macrotext", nil)
  626.     frame:SetAttribute("macroName", nil)
  627.     frame:SetAttribute("macroBody", nil)
  628.     frame:SetAttribute("macro2", nil)
  629.     frame:SetAttribute("macrotext2", nil)
  630. end
  631.  
  632. local spellHealingTouch, spellHealingTouchIcon
  633. spellHealingTouch, _, spellHealingTouchIcon = AutoBar:LoggedGetSpellInfo(5185)
  634.  
  635. local SPELL_FEED_PET = AutoBar:LoggedGetSpellInfo(6991) -- Feed Pet
  636. local SPELL_PICK_LOCK = AutoBar:LoggedGetSpellInfo(1804) -- Pick Lock
  637. local SPELL_MILL_HERB = AutoBar:LoggedGetSpellInfo(51005)
  638.  
  639. local TRINKET1_SLOT = 13
  640. local TRINKET2_SLOT = 14
  641.  
  642. -- Set the state attributes of the button
  643. function AutoBarButton.prototype:SetupAttributes(button, bag, slot, spell, macroId, itemId, itemData)
  644.     local frame = button.frame
  645.     AutoBarButton:SetupAttributesClear(frame)
  646.  
  647.     local enabled = true
  648.     frame.needsTooltip = true
  649.     local category = itemData and itemData.category
  650.  
  651.     frame:SetAttribute("category", category)
  652.     frame:SetAttribute("itemId", itemId)
  653.  
  654.     local targeted, castSpell, itemsRightClick
  655.     local buttonDB = self.buttonDB  -- Use base button info for popups as well
  656.     local selfCastRightClick = AutoBar.db.account.selfCastRightClick
  657.  
  658.     -- Set up special conditions from Category attributes
  659.     local categoryInfo = AutoBarCategoryList[category]
  660.     if (categoryInfo) then
  661.         targeted = categoryInfo.targeted
  662.  
  663.         -- Disable battleground only items outside BG
  664.         if (categoryInfo.battleground and not AutoBar.inBG) then
  665.             enabled = false
  666.         end
  667.  
  668.         castSpell = categoryInfo.castSpell
  669.         itemsRightClick = categoryInfo.itemsRightClick
  670.     end
  671.  
  672.     if (not targeted and buttonDB.targeted) then
  673.         targeted = buttonDB.targeted
  674.     end
  675.  
  676.     if (targeted) then
  677.         if (targeted == "CHEST") then
  678.             frame:SetAttribute("target-slot1", 5)
  679.             frame:SetAttribute("target-slot2", 5)
  680.         elseif (targeted == "SHIELD") then
  681.             frame:SetAttribute("target-slot1", 17)
  682.             frame:SetAttribute("target-slot2", 17)
  683.         elseif (targeted == "WEAPON") then
  684.             frame:SetAttribute("target-slot1", 16)
  685.             frame:SetAttribute("target-slot2", 17)
  686.         elseif (targeted == TRINKET1_SLOT) then
  687.             frame:SetAttribute("target-slot1", TRINKET1_SLOT)
  688.             frame:SetAttribute("target-slot2", TRINKET2_SLOT)
  689.         elseif (targeted == TRINKET2_SLOT) then
  690.             frame:SetAttribute("target-slot1", TRINKET2_SLOT)
  691.             frame:SetAttribute("target-slot2", TRINKET1_SLOT)
  692.         elseif (AutoBar.CLASS == "ROGUE" and targeted == "Lockpicking") then
  693.                 frame:SetAttribute("type2", "spell")
  694.                 frame:SetAttribute("spell2", SPELL_PICK_LOCK)
  695.                 frame:SetAttribute("target-bag2", bag)
  696.                 frame:SetAttribute("target-slot2", slot)
  697.         elseif (targeted == "Milling") then
  698.                 frame:SetAttribute("type1", "spell")
  699.                 frame:SetAttribute("spell1", SPELL_MILL_HERB)
  700.                 frame:SetAttribute("target-bag1", bag)
  701.                 frame:SetAttribute("target-slot1", slot)
  702.                 frame:SetAttribute("type2", "item")
  703.                 frame:SetAttribute("item2", "Draenic Mortar")
  704.                 frame:SetAttribute("target-bag2", bag)
  705.                 frame:SetAttribute("target-slot2", slot)
  706.         elseif (AutoBar.CLASS == "HUNTER" and targeted == "PET") then
  707.             -- Right Click targets pet
  708.             if (category and strfind(category, "Consumable.Food")) then
  709.                 frame:SetAttribute("type2", "spell")
  710.                 frame:SetAttribute("spell2", SPELL_FEED_PET)
  711.                 frame:SetAttribute("target-bag2", bag)
  712.                 frame:SetAttribute("target-slot2", slot)
  713.             else
  714.                 frame:SetAttribute("unit2", "pet")
  715.             end
  716.         elseif (targeted) then
  717.             -- Support selfcast-RightMouse
  718.             if (selfCastRightClick) then
  719.                 frame:SetAttribute("unit2", "player")
  720.             else
  721.                 frame:SetAttribute("unit2", nil)
  722.             end
  723.         end
  724.     end
  725.  
  726.     if (enabled) then
  727.         if (buttonDB) then
  728.             -- Handle right click pet targeting for a slot
  729.             if (buttonDB.rightClickTargetsPet) then
  730.                 if (category and strfind(category, "Consumable.Food")) then
  731.                     frame:SetAttribute("type2", "spell")
  732.                     frame:SetAttribute("spell2", SPELL_FEED_PET)
  733.                     frame:SetAttribute("target-bag2", bag)
  734.                     frame:SetAttribute("target-slot2", slot)
  735. --AutoBar:Print("AutoBarButton.prototype:SetupAttributes buttonKey " .. tostring(buttonKey) .. " bag ".. tostring(bag).. " slot " .. tostring(slot))
  736.                 else
  737.                     frame:SetAttribute("unit2", "pet")
  738.                 end
  739.             elseif (selfCastRightClick) then
  740.                 frame:SetAttribute("unit2", "player")
  741.             end
  742.  
  743.             if (not castSpell) then
  744.                 castSpell = buttonDB.castSpell
  745.             end
  746.         end
  747.  
  748.         -- The matched spell to cast on RightClick
  749.         if (itemsRightClick and itemsRightClick[itemId]) then
  750.             castSpell = itemsRightClick[itemId]
  751.             selfCastRightClick = nil
  752. --AutoBar:Print("AutoBarButton.prototype:SetupAttributes buttonKey " .. buttonKey .. " castSpell " .. tostring(castSpell))
  753.         end
  754.         -- Special spell to cast on RightClick
  755.         if (castSpell) then
  756.             frame:SetAttribute("type2", "spell")
  757.             frame:SetAttribute("spell2", castSpell)
  758.         end
  759.  
  760.         -- selfCastRightClick targeting
  761.         local unit2 = frame:GetAttribute("unit2")
  762.         if (selfCastRightClick and not unit2) then
  763.             frame:SetAttribute("unit2", "player")
  764.         end
  765.  
  766.         local type2 = frame:GetAttribute("type2")
  767.         if (not bag and slot) then
  768.             local itemLink = GetInventoryItemLink("player", slot)
  769.             frame:SetAttribute("type", "item")
  770.             frame:SetAttribute("item", itemLink)
  771.  
  772.             -- Tooltip
  773.             frame:SetAttribute("itemLink", itemLink)
  774.         elseif (bag and slot) then
  775.             local itemLink = GetContainerItemLink(bag, slot)
  776.             frame:SetAttribute("itemLink", itemLink)
  777. ---         if (buttonDB.shuffle) then
  778. ---             itemLink = bag .. " " .. slot
  779. ---         end
  780.             frame:SetAttribute("type", "item")
  781.             frame:SetAttribute("item", itemLink)
  782.             if (not type2) then
  783.                 frame:SetAttribute("type2", "item")
  784.                 frame:SetAttribute("item2", itemLink)
  785.             end
  786.         elseif (macroId) then
  787.             local macroInfo = AutoBarSearch.macros[macroId]
  788.             frame:SetAttribute("type", "macro")
  789.             frame:SetAttribute("macroId", macroId)
  790.             if (macroInfo.macroIndex) then
  791.                 frame:SetAttribute("macro", macroInfo.macroIndex)
  792.                 button.macroActive = true
  793.             else
  794.                 frame:SetAttribute("macrotext", macroInfo.macroText)
  795.                 button.macroActive = true
  796.                 frame:SetAttribute("macroName", macroInfo.macroName)
  797.                 frame:SetAttribute("macroBody", macroInfo.macroText)
  798.             end
  799.         elseif (spell) then
  800.             -- Default spell to cast
  801.             frame:SetAttribute("type", "spell")
  802.             frame:SetAttribute("spell", spell)
  803.  
  804.             -- Tooltip
  805.             local spellInfo = AutoBarSearch.spells[spell]
  806.             if (spellInfo.spellLink) then
  807.                 frame:SetAttribute("itemLink", spellInfo.spellLink)
  808.             end
  809.         elseif (castSpell) then
  810.             -- Set castSpell as default if nothing else is available
  811.             frame:SetAttribute("type", "spell")
  812.             frame:SetAttribute("spell", castSpell)
  813.  
  814.             -- Tooltip
  815.             local spellInfo = AutoBarSearch.spells[castSpell].spellLink
  816.             if (spellInfo.spellLink) then
  817.                 frame:SetAttribute("itemLink", spellInfo.spellLink)
  818.             end
  819.         else
  820.             frame:SetAttribute("type", nil)
  821.             frame:SetAttribute("type2", nil)
  822.         end
  823.     end
  824.     if (self.buttonDB.invertButtons) then
  825.         -- Only supports items for now (off hand buffing)
  826.         local temp
  827.         temp = frame:GetAttribute("target-slot1")
  828.         frame:SetAttribute("target-slot1", frame:GetAttribute("target-slot2"))
  829.         frame:SetAttribute("target-slot2", temp)
  830.  
  831.     end
  832.     if (frame.menu) then
  833.         frame:SetAttribute("type2", "menu")
  834.     end
  835. end
  836. --[[
  837. /dump AutoBar.buttonList["AutoBarButtonFoodPet"][1]
  838. /dump AutoBar.buttonList["AutoBarButtonFoodPet"].frame.popupHeader.popupButtonList[2].frame:GetAttribute("type2")
  839. /dump AutoBar.buttonList["AutoBarButtonFoodPet"].frame.popupHeader.popupButtonList[2].frame:GetAttribute("spell2")
  840. /dump AutoBar.buttonList["AutoBarButtonFoodPet"].frame.popupHeader.popupButtonList[2].frame:GetAttribute("target-bag2")
  841. /dump AutoBar.buttonList["AutoBarButtonFoodPet"].frame.popupHeader.popupButtonList[2].frame:GetAttribute("target-slot2")
  842. /dump AutoBar.buttonList["AutoBarButtonBuff"].frame.popupHeader.popupButtonList[2].frame:GetAttribute("target-slot1")
  843. /dump AutoBar.buttonList["AutoBarButtonClassBuff"].frame:GetAttribute("spell")
  844. /dump AutoBar.buttonList["AutoBarButtonBuff"].frame:GetAttribute("target-slot2")
  845. /dump AutoBar.buttonList["AutoBarButtonCooldownStoneMana"].frame:GetAttribute("itemId")
  846. /dump AutoBar.buttonList["AutoBarButtonCooldownStoneHealth"].frame:GetAttribute("itemId")
  847. /dump AutoBar.buttonList["AutoBarButtonMillHerbs"].frame.popupHeader.popupButtonList[10].frame:GetAttribute("type")
  848. --]]
  849.  
  850.  
  851. --
  852. -- Button Update callback functions
  853. --
  854.  
  855. function AutoBarButton:SetTooltip(button)
  856. --AutoBar:Print("SetTooltip " .. tostring(self.needsTooltip) .. " button " .. tostring(button) .. " button " .. tostring(button) .. " showTooltip " .. tostring(AutoBar.db.account.showTooltip) .. " self.needsTooltip " .. tostring(self.needsTooltip))
  857.     local isAutoBarButton = self.class and self.class.buttonDB
  858.  
  859.     if (isAutoBarButton and self.GetHotkey) then
  860.         LibKeyBound:Set(self)
  861.     end
  862.     local noTooltip = not (AutoBar.db.account.showTooltip and self.needsTooltip or AutoBar.moveButtonsMode)
  863.     noTooltip = noTooltip or (InCombatLockdown() and not AutoBar.db.account.showTooltipCombat) or (button == "OnLeave")
  864.     if (noTooltip) then
  865.         self.updateTooltip = nil
  866.         GameTooltip:Hide()
  867.         return
  868.     end
  869.  
  870.     if (GetCVar("UberTooltips") == "1") then
  871.         GameTooltip_SetDefaultAnchor(GameTooltip, self)
  872.     else
  873.         local x = self:GetRight();
  874.         if ( x >= ( GetScreenWidth() / 2 ) ) then
  875.             GameTooltip:SetOwner(self, "ANCHOR_LEFT");
  876.         else
  877.             GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  878.         end
  879.     end
  880.  
  881.     -- Add Button or Bar name
  882.     if (AutoBar.moveButtonsMode) then
  883.         if (self.class and self.class.sharedLayoutDB) then
  884.             GameTooltip:AddLine(self.class.barName)
  885.         elseif(isAutoBarButton) then
  886.             GameTooltip:AddLine(AutoBarButton:GetDisplayName(self.class.buttonDB))
  887.         end
  888.     else
  889.         local buttonType = self:GetAttribute("type")
  890.  
  891.         if (not buttonType) then
  892.             if (isAutoBarButton) then
  893.                 GameTooltip:AddLine(AutoBarButton:GetDisplayName(self.class.buttonDB))
  894.             else
  895.                 self.updateTooltip = nil
  896.             end
  897.         elseif (buttonType == "item") then
  898.             local itemLink = self:GetAttribute("item")
  899.             if (itemLink) then
  900.                 local itemId = self:GetAttribute("itemId")
  901.                 local bag, slot = AutoBarSearch.found:GetItemData(itemId)
  902.                 if (bag and slot) then
  903.                     GameTooltip:SetBagItem(bag, slot)
  904.                 elseif (slot) then
  905.                     GameTooltip:SetInventoryItem("player", slot)
  906.                 else
  907.                     GameTooltip:SetHyperlink(itemLink)
  908.                 end
  909.             end
  910.             self.updateTooltip = TOOLTIP_UPDATE_TIME
  911.             if (AutoBar.db.account.showTooltipExtended) then
  912.                 GameTooltip_ShowCompareItem()
  913.             end
  914. -- /script local bag, slot = strmatch("3,4", "^(%d+)%s+(%d+)$"); AutoBar:Print("bag " .. tostring(bag).." slot " .. tostring(slot))
  915.         elseif (buttonType == "spell") then
  916.             local spellName = self:GetAttribute("spell")
  917.  
  918.             if (spellName) then
  919.                 local spellInfo = AutoBarSearch.spells[spellName]
  920.                 GameTooltip:SetSpellBookItem(spellInfo.spellId, spellInfo.spellTab)
  921.             end
  922.             self.updateTooltip = TOOLTIP_UPDATE_TIME
  923.         end
  924.  
  925.         local rightClickType = self:GetAttribute("type2")
  926.         if (rightClickType == "spell") then
  927.             local spellName = self:GetAttribute("spell2")
  928.             if (spellName) then
  929.                 GameTooltip:AddLine(L["Right Click casts "] .. spellName, 1, 0.2, 1, 1)
  930.             end
  931.         end
  932.     end
  933.  
  934.     GameTooltip:Show()
  935. end
  936.  
  937.  
  938. -- Add your Button custom options to the optionlist
  939. -- optionList[myCustomOptionKey]
  940. -- Call specific SetOption<Type> methods to do the actual setting
  941. function AutoBarButton.prototype:AddOptions(optionList, passValue)
  942. end
  943.  
  944.  
  945. -- Call specific option type methods to do the actual setting
  946. function AutoBarButton.prototype:SetOptionBoolean(optionList, passValue, valueName, name, desc)
  947.     if (not optionList.headerCustomOptions) then
  948.         optionList.headerCustomOptions = {
  949.             type = "header",
  950.             order = 100,
  951.             name = "",
  952.         }
  953.     end
  954.     if (not optionList[valueName]) then
  955.         optionList[valueName] = {
  956.             type = "toggle",
  957.             order = 110,
  958.             name = name,
  959.             desc = desc,
  960.             arg = passValue,
  961.             disabled = InCombatLockdown,
  962.         }
  963.     else
  964.         optionList[valueName].arg = passValue
  965.     end
  966. end
  967.  
  968.  
  969. -- Add category to the end of the buttons list
  970. function AutoBarButton.prototype:AddCategory(categoryName)
  971.     for _, category in ipairs(self) do
  972.         if (category == categoryName) then
  973.             -- Ignore.  ToDo shuffle to end.
  974.             return
  975.         end
  976.     end
  977.     -- Add to end
  978.     self[# self + 1] = categoryName
  979. end
  980.  
  981. -- Delete category from the buttons list
  982. function AutoBarButton.prototype:DeleteCategory(categoryName)
  983.     for i, category in ipairs(self) do
  984.         if (category == categoryName) then
  985.             for j = i, # self do
  986.                 self[j] = self[j + 1]
  987.                 self[j + 1] = nil
  988.             end
  989.             return
  990.         end
  991.     end
  992. end
  993.  
  994. -- Register the Macro
  995. function AutoBarButton.prototype:AddMacro(macroText, macroTexture)
  996.     self.macroText = macroText
  997.     self.macroTexture = macroTexture
  998.     local buttonKey = self.buttonDB.buttonKey
  999. --AutoBar:Print("AutoBarButtonMacro.prototype:AddMacro RegisterMacro " .. tostring(buttonKey))
  1000.     AutoBarSearch:RegisterMacro(buttonKey, nil, L[buttonKey], macroText)
  1001. end
  1002.  
  1003.  
  1004. AutoBarButtonMacro = AceOO.Class(AutoBarButton)
  1005.  
  1006. function AutoBarButtonMacro.prototype:init(parentBar, buttonDB)
  1007.     AutoBarButtonMacro.super.prototype.init(self, parentBar, buttonDB)
  1008. end
  1009.  
  1010. -- Set the state attributes of the button
  1011. function AutoBarButtonMacro.prototype:SetupButton()
  1012.     local frame = self.frame
  1013.  
  1014.     if (self.macroText and self.buttonDB.enabled) then
  1015. --AutoBar:Print("AutoBarButtonMacro.prototype:SetupButton buttonKey " .. tostring(self.buttonDB.buttonKey) .. " frame " .. tostring(frame))
  1016.         frame:Show()
  1017. --- ToDo, disable popup
  1018.         self:SetupAttributes(self, nil, nil, nil, self.buttonDB.buttonKey)
  1019.     else
  1020.         frame:Hide()
  1021.     end
  1022. end
  1023.  
  1024.  
  1025. local AutoBarButtonAspect = AceOO.Class(AutoBarButton)
  1026. AutoBar.Class["AutoBarButtonAspect"] = AutoBarButtonAspect
  1027.  
  1028. function AutoBarButtonAspect.prototype:init(parentBar, buttonDB)
  1029.     AutoBarButtonAspect.super.prototype.init(self, parentBar, buttonDB)
  1030.  
  1031.     self:AddCategory("Spell.Aspect")
  1032. end
  1033.  
  1034. local AutoBarButtonPoisonLethal = AceOO.Class(AutoBarButton)
  1035. AutoBar.Class["AutoBarButtonPoisonLethal"] = AutoBarButtonPoisonLethal
  1036.  
  1037. function AutoBarButtonPoisonLethal.prototype:init(parentBar, buttonDB)
  1038.     AutoBarButtonPoisonLethal.super.prototype.init(self, parentBar, buttonDB)
  1039.  
  1040.     self:AddCategory("Spell.Poison.Lethal")
  1041. end
  1042.  
  1043. local AutoBarButtonPoisonNonlethal = AceOO.Class(AutoBarButton)
  1044. AutoBar.Class["AutoBarButtonPoisonNonlethal"] = AutoBarButtonPoisonNonlethal
  1045.  
  1046. function AutoBarButtonPoisonNonlethal.prototype:init(parentBar, buttonDB)
  1047.     AutoBarButtonPoisonNonlethal.super.prototype.init(self, parentBar, buttonDB)
  1048.  
  1049.     self:AddCategory("Spell.Poison.Nonlethal")
  1050. end
  1051.  
  1052. local AutoBarButtonBandages = AceOO.Class(AutoBarButton)
  1053. AutoBar.Class["AutoBarButtonBandages"] = AutoBarButtonBandages
  1054.  
  1055. function AutoBarButtonBandages.prototype:init(parentBar, buttonDB)
  1056.     AutoBarButtonBandages.super.prototype.init(self, parentBar, buttonDB)
  1057.  
  1058.     self:AddCategory("Consumable.Bandage.Basic")
  1059.     self:AddCategory("Consumable.Bandage.Battleground.Alterac Valley")
  1060.     self:AddCategory("Consumable.Bandage.Battleground.Arathi Basin")
  1061.     self:AddCategory("Consumable.Bandage.Battleground.Warsong Gulch")
  1062. end
  1063.  
  1064.  
  1065. local AutoBarButtonBattleStandards = AceOO.Class(AutoBarButton)
  1066. AutoBar.Class["AutoBarButtonBattleStandards"] = AutoBarButtonBattleStandards
  1067.  
  1068. function AutoBarButtonBattleStandards.prototype:init(parentBar, buttonDB)
  1069.     AutoBarButtonBattleStandards.super.prototype.init(self, parentBar, buttonDB)
  1070.  
  1071.     self:AddCategory("Misc.Battle Standard.Battleground")
  1072.     self:AddCategory("Misc.Battle Standard.Alterac Valley")
  1073.     self:AddCategory("Misc.Battle Standard.Guild")
  1074. end
  1075.  
  1076.  
  1077. local AutoBarButtonBuff = AceOO.Class(AutoBarButton)
  1078. AutoBar.Class["AutoBarButtonBuff"] = AutoBarButtonBuff
  1079.  
  1080. function AutoBarButtonBuff.prototype:init(parentBar, buttonDB)
  1081.     AutoBarButtonBuff.super.prototype.init(self, parentBar, buttonDB)
  1082.  
  1083.     self:AddCategory("Consumable.Buff.Chest")
  1084.     self:AddCategory("Consumable.Buff.Shield")
  1085.     self:AddCategory("Consumable.Buff.Other.Target")
  1086.     self:AddCategory("Consumable.Buff.Other.Self")
  1087.     self:AddCategory("Consumable.Buff Group.General.Target")
  1088.     self:AddCategory("Consumable.Buff Group.General.Self")
  1089.  
  1090.     -- Melee
  1091.     if (AutoBar.CLASS ~= "MAGE" and AutoBar.CLASS ~= "WARLOCK" and AutoBar.CLASS ~= "PRIEST") then
  1092.         self:AddCategory("Consumable.Buff Group.Melee.Target")
  1093.         self:AddCategory("Consumable.Buff Group.Melee.Self")
  1094.     end
  1095.  
  1096.     -- Mana & Spell
  1097.     if (AutoBar.CLASS ~= "ROGUE" and AutoBar.CLASS ~= "WARRIOR") then
  1098.         self:AddCategory("Consumable.Buff Group.Caster.Target")
  1099.         self:AddCategory("Consumable.Buff Group.Caster.Self")
  1100.     end
  1101.    
  1102.         self:AddCategory("Muffin.Potion.Buff")
  1103.  
  1104. end
  1105.  
  1106.  
  1107. local AutoBarButtonBuffWeapon = AceOO.Class(AutoBarButton)
  1108. AutoBar.Class["AutoBarButtonBuffWeapon"] = AutoBarButtonBuffWeapon
  1109.  
  1110. function AutoBarButtonBuffWeapon.prototype:init(parentBar, buttonDB)
  1111.     AutoBarButtonBuffWeapon.super.prototype.init(self, parentBar, buttonDB)
  1112.  
  1113.     self:AddCategory("Consumable.Weapon Buff")
  1114.     self:AddCategory("Spell.Buff.Weapon")
  1115. end
  1116.  
  1117.  
  1118. local AutoBarButtonClassBuff = AceOO.Class(AutoBarButton)
  1119. AutoBar.Class["AutoBarButtonClassBuff"] = AutoBarButtonClassBuff
  1120.  
  1121. function AutoBarButtonClassBuff.prototype:init(parentBar, buttonDB)
  1122.     AutoBarButtonClassBuff.super.prototype.init(self, parentBar, buttonDB)
  1123.  
  1124.     self:AddCategory("Spell.Class.Buff")
  1125. end
  1126.  
  1127. function AutoBarButtonClassBuff.prototype:SetupAttributes(button, bag, slot, spell, macroId, itemId, itemData)
  1128.     local selfCastRightClick = AutoBar.db.account.selfCastRightClick
  1129.     AutoBar.db.account.selfCastRightClick = nil
  1130.     AutoBarButtonClassBuff.super.prototype.SetupAttributes(self, button, bag, slot, spell, macroId, itemId, itemData)
  1131.     AutoBar.db.account.selfCastRightClick = selfCastRightClick
  1132. end
  1133.  
  1134. local AutoBarButtonClassPets2 = AceOO.Class(AutoBarButton)
  1135. AutoBar.Class["AutoBarButtonClassPets2"] = AutoBarButtonClassPets2
  1136.  
  1137. function AutoBarButtonClassPets2.prototype:init(parentBar, buttonDB)
  1138.     AutoBarButtonClassPets2.super.prototype.init(self, parentBar, buttonDB)
  1139.  
  1140.     self:AddCategory("Spell.Class.Pets2")
  1141. end
  1142.  
  1143. local AutoBarButtonClassPet = AceOO.Class(AutoBarButton)
  1144. AutoBar.Class["AutoBarButtonClassPet"] = AutoBarButtonClassPet
  1145.  
  1146. function AutoBarButtonClassPet.prototype:init(parentBar, buttonDB)
  1147.     AutoBarButtonClassPet.super.prototype.init(self, parentBar, buttonDB)
  1148.  
  1149.     self:AddCategory("Spell.Class.Pet")
  1150. end
  1151.  
  1152. local AutoBarButtonClassPets3 = AceOO.Class(AutoBarButton)
  1153. AutoBar.Class["AutoBarButtonClassPets3"] = AutoBarButtonClassPets3
  1154.  
  1155. function AutoBarButtonClassPets3.prototype:init(parentBar, buttonDB)
  1156.     AutoBarButtonClassPets3.super.prototype.init(self, parentBar, buttonDB)
  1157.  
  1158.     self:AddCategory("Spell.Class.Pets3")
  1159. end
  1160.  
  1161. local AutoBarButtonConjure = AceOO.Class(AutoBarButton)
  1162. AutoBar.Class["AutoBarButtonConjure"] = AutoBarButtonConjure
  1163.  
  1164. function AutoBarButtonConjure.prototype:init(parentBar, buttonDB)
  1165.     AutoBarButtonConjure.super.prototype.init(self, parentBar, buttonDB)
  1166.  
  1167.     if (AutoBar.CLASS == "MAGE") then
  1168.         self:AddCategory("Spell.Mage.Conjure Food")
  1169.     elseif (AutoBar.CLASS == "WARLOCK") then
  1170.         self:AddCategory("Spell.Warlock.Create Healthstone")
  1171.     end
  1172. end
  1173.  
  1174.  
  1175. local AutoBarButtonOpenable = AceOO.Class(AutoBarButton)
  1176. AutoBar.Class["AutoBarButtonOpenable"] = AutoBarButtonOpenable
  1177.  
  1178. function AutoBarButtonOpenable.prototype:init(parentBar, buttonDB)
  1179.     AutoBarButtonOpenable.super.prototype.init(self, parentBar, buttonDB)
  1180.  
  1181.     self:AddCategory("Muffin.Misc.Openable")
  1182. end
  1183.  
  1184.  
  1185. local AutoBarButtonCrafting = AceOO.Class(AutoBarButton)
  1186. AutoBar.Class["AutoBarButtonCrafting"] = AutoBarButtonCrafting
  1187.  
  1188. function AutoBarButtonCrafting.prototype:init(parentBar, buttonDB)
  1189.     AutoBarButtonCrafting.super.prototype.init(self, parentBar, buttonDB)
  1190.  
  1191.     self:AddCategory("Spell.Crafting")
  1192. end
  1193.  
  1194.  
  1195. AutoBarButtonCustom = AceOO.Class(AutoBarButton)
  1196. AutoBar.Class["AutoBarButtonCustom"] = AutoBarButtonCustom
  1197.  
  1198. function AutoBarButtonCustom.prototype:init(parentBar, buttonDB)
  1199.     AutoBarButtonCustom.super.prototype.init(self, parentBar, buttonDB)
  1200.     self.frame.SetKey = nil
  1201. end
  1202.  
  1203. function AutoBarButtonCustom.prototype:GetButtonBinding()
  1204.     return nil
  1205. end
  1206.  
  1207. function AutoBarButtonCustom.prototype:CreateButtonFrame()
  1208.     AutoBarButtonCustom.super.prototype.CreateButtonFrame(self)
  1209.     self.frame.GetActionName = nil
  1210.     self.frame.SetKey = nil
  1211.     self.frame.ClearBindings = nil
  1212.     self.frame.GetBindings = nil
  1213. end
  1214.  
  1215.  
  1216. local spellAquaticForm, spellAquaticFormIcon
  1217. local spellTreeOfLifeForm, spellTreeOfLifeFormIcon
  1218. local spellMoonkinForm, spellMoonkinFormIcon
  1219.  
  1220. spellMoonkinForm, _, spellMoonkinFormIcon = AutoBar:LoggedGetSpellInfo(24858)
  1221. spellAquaticForm, _, spellAquaticFormIcon = AutoBar:LoggedGetSpellInfo(1066)
  1222. spellTreeOfLifeForm, _, spellTreeOfLifeFormIcon = AutoBar:LoggedGetSpellInfo(114282)
  1223.  
  1224.  
  1225. local shapeshift = {
  1226. }
  1227. local shapeshiftIn = {}
  1228. local shapeshiftSet = {}
  1229. local formIndexList = {}
  1230. local concatList = {}
  1231. local excludeList = {}
  1232.  
  1233. local function ShapeshiftRefresh()
  1234.     wipe(shapeshift)
  1235.     wipe(shapeshiftIn)
  1236.     wipe(shapeshiftSet)
  1237.     wipe(formIndexList)
  1238.  
  1239.     local numShapeshiftForms = GetNumShapeshiftForms()
  1240.     for index = 1, numShapeshiftForms, 1 do
  1241.         local _, name, _, _ = GetShapeshiftFormInfo(index)
  1242.         shapeshift[name] = " [stance:" .. index .. "] " .. name .. ";"
  1243.         shapeshiftIn[name] = " [stance:" .. index .. "]"
  1244.         shapeshiftSet[name] = " [nostance:" .. index .. "] " .. name .. ";"
  1245.         formIndexList[name] = index
  1246.     end
  1247. end
  1248.  
  1249. local function GetCancelList(excludeList)
  1250.     ShapeshiftRefresh()
  1251.     wipe(concatList)
  1252.  
  1253.     local index = 1
  1254.     concatList[index] = "/cancelform [stance:"
  1255.     index = index + 1
  1256.  
  1257.     for excludeForm in pairs(excludeList) do
  1258.         formIndexList[excludeForm] = nil
  1259.     end
  1260.  
  1261.     local needsSlash = false
  1262.  
  1263.     for formName, formIndex in pairs(formIndexList) do
  1264.         if (formName and formIndex) then
  1265.             if (needsSlash) then
  1266.                 concatList[index] = "/"
  1267.                 index = index + 1
  1268.                 concatList[index] = tostring(formIndex)
  1269.             else
  1270.                 concatList[index] = tostring(formIndex)
  1271.                 needsSlash = true
  1272.             end
  1273.             index = index + 1
  1274.         end
  1275.     end
  1276.     concatList[index] = "]\n/dismount [mounted]\n/cast "
  1277.     index = index + 1
  1278.    
  1279.     return concatList
  1280. end
  1281.  
  1282. local AutoBarButtonBear = AceOO.Class(AutoBarButtonMacro)
  1283. AutoBar.Class["AutoBarButtonBear"] = AutoBarButtonBear
  1284.  
  1285. function AutoBarButtonBear.prototype:init(parentBar, buttonDB)
  1286.     AutoBarButtonBear.super.prototype.init(self, parentBar, buttonDB)
  1287.     self:Refresh(parentBar, buttonDB)
  1288. end
  1289.  
  1290. function AutoBarButtonBear.prototype:Refresh(parentBar, buttonDB)
  1291.     AutoBarButtonBear.super.prototype.Refresh(self, parentBar, buttonDB)
  1292.     self.macroActive = nil
  1293.     if (AutoBar.CLASS == "DRUID") then
  1294.         wipe(excludeList)
  1295.         excludeList[spellNameList["Bear Form"]] = true
  1296.         local concatList = GetCancelList(excludeList)
  1297.         local macroTexture
  1298.  
  1299.         if (shapeshiftSet[spellNameList["Bear Form"]]) then
  1300.             concatList[# concatList + 1] = shapeshiftSet[spellNameList["Bear Form"]]
  1301.             macroTexture = spellIconList["Bear Form"]
  1302.             self.macroActive = true
  1303.         end
  1304.  
  1305.         if (self.macroActive) then
  1306.             local macroText = table.concat(concatList)
  1307.             self:AddMacro(macroText, macroTexture)
  1308.         end
  1309.     end
  1310. end
  1311.  
  1312. local AutoBarButtonBoomkinTree = AceOO.Class(AutoBarButtonMacro)
  1313. AutoBar.Class["AutoBarButtonBoomkinTree"] = AutoBarButtonBoomkinTree
  1314.  
  1315. function AutoBarButtonBoomkinTree.prototype:init(parentBar, buttonDB)
  1316.     AutoBarButtonBoomkinTree.super.prototype.init(self, parentBar, buttonDB)
  1317.     self:Refresh(parentBar, buttonDB)
  1318. end
  1319.  
  1320. function AutoBarButtonBoomkinTree.prototype:Refresh(parentBar, buttonDB)
  1321.     AutoBarButtonBoomkinTree.super.prototype.Refresh(self, parentBar, buttonDB)
  1322.     self.macroActive = nil
  1323.     if (AutoBar.CLASS == "DRUID") then
  1324.         wipe(excludeList)
  1325.         excludeList[spellMoonkinForm] = true
  1326.         excludeList[spellTreeOfLifeForm] = true
  1327.         local concatList = GetCancelList(excludeList)
  1328.         local macroTexture
  1329.  
  1330.         if (shapeshiftSet[spellMoonkinForm]) then
  1331.             concatList[# concatList + 1] = shapeshiftSet[spellMoonkinForm]
  1332.             macroTexture = spellMoonkinFormIcon
  1333.             self.macroActive = true
  1334.         elseif (shapeshiftSet[spellTreeOfLifeForm]) then
  1335.             concatList[# concatList + 1] = shapeshiftSet[spellTreeOfLifeForm]
  1336.             macroTexture = spellTreeOfLifeFormIcon
  1337.             self.macroActive = true
  1338.         end
  1339.  
  1340.         if (self.macroActive) then
  1341.             local macroText = table.concat(concatList)
  1342.             self:AddMacro(macroText, macroTexture)
  1343.         end
  1344.     end
  1345. end
  1346.  
  1347.  
  1348. local AutoBarButtonCat = AceOO.Class(AutoBarButtonMacro)
  1349. AutoBar.Class["AutoBarButtonCat"] = AutoBarButtonCat
  1350.  
  1351. function AutoBarButtonCat.prototype:init(parentBar, buttonDB)
  1352.     AutoBarButtonCat.super.prototype.init(self, parentBar, buttonDB)
  1353.     self:Refresh(parentBar, buttonDB)
  1354. end
  1355.  
  1356. function AutoBarButtonCat.prototype:Refresh(parentBar, buttonDB)
  1357.     AutoBarButtonCat.super.prototype.Refresh(self, parentBar, buttonDB)
  1358.     self.macroActive = nil
  1359.     if (AutoBar.CLASS == "DRUID") then
  1360.         wipe(excludeList)
  1361.         excludeList[spellNameList["Cat Form"]] = true
  1362.         local concatList = GetCancelList(excludeList)
  1363.         local macroTexture
  1364.  
  1365.         if (shapeshiftSet[spellNameList["Cat Form"]]) then
  1366.             concatList[# concatList + 1] = shapeshiftSet[spellNameList["Cat Form"]]
  1367.             macroTexture = spellIconList["Cat Form"]
  1368.             self.macroActive = true
  1369.  
  1370.             local macroText = table.concat(concatList)
  1371.             self:AddMacro(macroText, macroTexture)
  1372.         end
  1373.     end
  1374. end
  1375.  
  1376.  
  1377.  
  1378. local AutoBarButtonPowerShift = AceOO.Class(AutoBarButtonMacro)
  1379. AutoBar.Class["AutoBarButtonPowerShift"] = AutoBarButtonPowerShift
  1380.  
  1381. function AutoBarButtonPowerShift.prototype:init(parentBar, buttonDB)
  1382.     AutoBarButtonPowerShift.super.prototype.init(self, parentBar, buttonDB)
  1383.     self:Refresh(parentBar, buttonDB)
  1384. end
  1385.  
  1386. function AutoBarButtonPowerShift.prototype:Refresh(parentBar, buttonDB)
  1387.     AutoBarButtonPowerShift.super.prototype.Refresh(self, parentBar, buttonDB)
  1388.     self.macroActive = nil
  1389.     if (AutoBar.CLASS == "DRUID") then
  1390. --[[
  1391. /run local f="Cat Form";f=GetSpellCooldown(f)>0 or UnitMana('player')>15 or not IsUsableSpell(f) or CancelPlayerBuff(f)
  1392. /cast [form] Mangle
  1393. /stopmacro [form]
  1394. /cast !Cat Form
  1395. --]]
  1396.         ShapeshiftRefresh()
  1397.         local macroTexture
  1398.  
  1399.         if (GetSpellInfo(spellNameList["Cat Form"]) and GetSpellInfo(spellNameList["Mangle"])) then
  1400.             concatList[1] = "/run local f=\""
  1401.             concatList[2] = spellNameList["Cat Form"]
  1402.             concatList[3] = "\";f=GetSpellCooldown(f)>0 or UnitMana('player')>15 or not IsUsableSpell(f) or CancelPlayerBuff(f)\n/cast [form] "
  1403.             concatList[4] = spellNameList["Mangle"]
  1404.             concatList[5] = "\n/stopmacro [form]\n"
  1405.             concatList[6] = "/cast !"
  1406.             concatList[7] = spellNameList["Cat Form"]
  1407.             concatList[8] = "\n"
  1408.             macroTexture = spellIconList["Mangle"]
  1409.             self.macroActive = true
  1410.  
  1411.             local macroText = table.concat(concatList)
  1412. --AutoBar:Print("AutoBarButtonPowerShift:Refresh " .. tostring(macroText) .. " macroTexture " .. tostring(macroTexture))
  1413.             self:AddMacro(macroText, macroTexture)
  1414.         end
  1415.     end
  1416. end
  1417.  
  1418.  
  1419.  
  1420.  
  1421. local AutoBarButtonCharge = AceOO.Class(AutoBarButtonMacro)
  1422. AutoBar.Class["AutoBarButtonCharge"] = AutoBarButtonCharge
  1423.  
  1424. function AutoBarButtonCharge.prototype:init(parentBar, buttonDB)
  1425.     AutoBarButtonCharge.super.prototype.init(self, parentBar, buttonDB)
  1426.     self:Refresh(parentBar, buttonDB)
  1427. end
  1428.  
  1429. function AutoBarButtonCharge.prototype:Refresh(parentBar, buttonDB)
  1430.     AutoBarButtonCharge.super.prototype.Refresh(self, parentBar, buttonDB)
  1431.     self.macroActive = nil
  1432.     wipe(concatList)
  1433.  
  1434.     concatList[1] = "/cast "
  1435.     local index = 2
  1436.     local macroTexture
  1437.     if (AutoBar.CLASS == "DRUID") then
  1438.         if (GetSpellInfo(spellNameList["Wild Charge"])) then
  1439.             concatList[index] = spellNameList["Wild Charge"]
  1440.  
  1441.             macroTexture = spellIconList["Wild Charge"]
  1442.             self.macroActive = true
  1443.         end
  1444.     elseif (AutoBar.CLASS == "ROGUE") then
  1445.         if (GetSpellInfo(spellNameList["Shadowstep"])) then
  1446.             concatList[index] = spellNameList["Shadowstep"]
  1447.  
  1448.             macroTexture = spellIconList["Shadowstep"]
  1449.             self.macroActive = true
  1450.         end
  1451.     elseif (AutoBar.CLASS == "WARRIOR") then
  1452.         if (GetSpellInfo(spellNameList["Charge"])) then
  1453.             concatList[index] = "[nocombat,harm,nostance:1]"
  1454.             concatList[index + 1] = spellNameList["Battle Stance"]
  1455.             concatList[index + 2] = ";"
  1456.             concatList[index + 3] = "[nocombat,harm,stance:1]"
  1457.             concatList[index + 4] = spellNameList["Charge"]
  1458.             concatList[index + 5] = ";"
  1459.             self.macroActive = true
  1460.             index = index + 6
  1461.         end
  1462.         if (GetSpellInfo(spellNameList["Intervene"])) then
  1463.             concatList[index] = "[nostance:2,help]"
  1464.             concatList[index + 1] = spellNameList["Defensive Stance"]
  1465.             concatList[index + 2] = ";"
  1466.             concatList[index + 3] = "[stance:2,help]"
  1467.             concatList[index + 4] = spellNameList["Intervene"]
  1468.             concatList[index + 5] = ";"
  1469.             self.macroActive = true
  1470.             index = index + 6
  1471.         end
  1472.  
  1473.         macroTexture = spellIconList["Charge"]
  1474.     end
  1475.     if (self.macroActive) then
  1476.         local macroText = table.concat(concatList)
  1477.         self:AddMacro(macroText, macroTexture)
  1478.     end
  1479. end
  1480.  
  1481.  
  1482. local AutoBarButtonTravel = AceOO.Class(AutoBarButtonMacro)
  1483. AutoBar.Class["AutoBarButtonTravel"] = AutoBarButtonTravel
  1484.  
  1485. function AutoBarButtonTravel.prototype:init(parentBar, buttonDB)
  1486.     AutoBarButtonTravel.super.prototype.init(self, parentBar, buttonDB)
  1487.  
  1488.     self:Refresh(parentBar, buttonDB)
  1489. end
  1490.  
  1491. function AutoBarButtonTravel.prototype:Refresh(parentBar, buttonDB)
  1492.     AutoBarButtonTravel.super.prototype.Refresh(self, parentBar, buttonDB)
  1493.     self.macroActive = nil
  1494.     wipe(concatList)
  1495.  
  1496.     local macroTexture
  1497.     if (AutoBar.CLASS == "DRUID") then
  1498.         wipe(excludeList)
  1499.         excludeList[spellAquaticForm] = true
  1500.         excludeList[spellNameList["Cat Form"]] = true
  1501.         excludeList[spellNameList["Travel Form"]] = true
  1502.         excludeList[spellNameList["Swift Flight Form"]] = true
  1503.         excludeList[spellNameList["Flight Form"]] = true
  1504.         local concatList = GetCancelList(excludeList)
  1505.  
  1506.         local index = # concatList + 1
  1507.         if (shapeshift[spellAquaticForm]) then
  1508.             concatList[index] = " [swimming] "
  1509.             concatList[index+1] = spellAquaticForm
  1510.             concatList[index+2] = ";"
  1511.             index = index + 3
  1512.             self.macroActive = true
  1513.         end
  1514.  
  1515.         if (shapeshift[spellNameList["Cat Form"]]) then
  1516.             concatList[index] = " [indoors] "
  1517.             concatList[index+1] = spellNameList["Cat Form"]
  1518.             concatList[index+2] = ";"
  1519.             index = index + 3
  1520.             self.macroActive = true
  1521.         end
  1522.  
  1523.         if (shapeshift[spellNameList["Swift Flight Form"]]) then
  1524.             concatList[index] = " [flyable,nocombat] "
  1525.             concatList[index+1] = spellNameList["Swift Flight Form"]
  1526.             concatList[index+2] = ";"
  1527.             index = index + 3
  1528.             self.macroActive = true
  1529.         elseif (shapeshift[spellNameList["Flight Form"]]) then
  1530.             concatList[index] = " [flyable,nocombat] "
  1531.             concatList[index+1] = spellNameList["Flight Form"]
  1532.             concatList[index+2] = ";"
  1533.             index = index + 3
  1534.             self.macroActive = true
  1535.         end
  1536.  
  1537.         if (shapeshiftSet[spellNameList["Travel Form"]]) then
  1538.             concatList[index] = " [outdoors] "
  1539.             concatList[index+1] = spellNameList["Travel Form"]
  1540.             index = index + 2
  1541.             self.macroActive = true
  1542.         end
  1543.  
  1544.         macroTexture = spellIconList["Travel Form"]
  1545.     elseif (AutoBar.CLASS == "SHAMAN") then
  1546.         if (GetSpellInfo(spellNameList["Ghost Wolf"])) then
  1547.             local index = 1
  1548.             concatList[index] = "/dismount [mounted]\n"
  1549.             concatList[index + 1] = "/cast "
  1550.             concatList[index + 2] = spellNameList["Ghost Wolf"]
  1551.             index = index + 3
  1552.  
  1553.             macroTexture = spellIconList["Ghost Wolf"]
  1554.             self.macroActive = true
  1555.         end
  1556.     end
  1557.     if (self.macroActive) then
  1558.         local macroText = table.concat(concatList)
  1559.         self:AddMacro(macroText, macroTexture)
  1560.     end
  1561. end
  1562.  
  1563.  
  1564. local AutoBarButtonDebuff = AceOO.Class(AutoBarButton)
  1565. AutoBar.Class["AutoBarButtonDebuff"] = AutoBarButtonDebuff
  1566.  
  1567. function AutoBarButtonDebuff.prototype:init(parentBar, buttonDB)
  1568.     AutoBarButtonDebuff.super.prototype.init(self, parentBar, buttonDB)
  1569.  
  1570.     self:AddCategory("Spell.Debuff.Single")
  1571.     self:AddCategory("Spell.Debuff.Multiple")
  1572. end
  1573.  
  1574.  
  1575. local AutoBarButtonElixirBattle = AceOO.Class(AutoBarButton)
  1576. AutoBar.Class["AutoBarButtonElixirBattle"] = AutoBarButtonElixirBattle
  1577.  
  1578. function AutoBarButtonElixirBattle.prototype:init(parentBar, buttonDB)
  1579.     AutoBarButtonElixirBattle.super.prototype.init(self, parentBar, buttonDB)
  1580.  
  1581.     self:AddCategory("Consumable.Buff Type.Battle")
  1582. end
  1583.  
  1584.  
  1585. local AutoBarButtonElixirGuardian = AceOO.Class(AutoBarButton)
  1586. AutoBar.Class["AutoBarButtonElixirGuardian"] = AutoBarButtonElixirGuardian
  1587.  
  1588. function AutoBarButtonElixirGuardian.prototype:init(parentBar, buttonDB)
  1589.     AutoBarButtonElixirGuardian.super.prototype.init(self, parentBar, buttonDB)
  1590.  
  1591.     self:AddCategory("Consumable.Buff Type.Guardian")
  1592. end
  1593.  
  1594.  
  1595. local AutoBarButtonElixirBoth = AceOO.Class(AutoBarButton)
  1596. AutoBar.Class["AutoBarButtonElixirBoth"] = AutoBarButtonElixirBoth
  1597.  
  1598. function AutoBarButtonElixirBoth.prototype:init(parentBar, buttonDB)
  1599.     AutoBarButtonElixirBoth.super.prototype.init(self, parentBar, buttonDB)
  1600.  
  1601.     self:AddCategory("Muffin.Flasks")
  1602. end
  1603.  
  1604.  
  1605. local AutoBarButtonER = AceOO.Class(AutoBarButtonMacro)
  1606. AutoBar.Class["AutoBarButtonER"] = AutoBarButtonER
  1607.  
  1608. function AutoBarButtonER.prototype:init(parentBar, buttonDB)
  1609.     AutoBarButtonER.super.prototype.init(self, parentBar, buttonDB)
  1610.     self:Refresh(parentBar, buttonDB)
  1611. end
  1612.  
  1613.  
  1614. function AutoBarButtonER.prototype:Refresh(parentBar, buttonDB)
  1615.     AutoBarButtonER.super.prototype.Refresh(self, parentBar, buttonDB)
  1616.     self.macroActive = nil
  1617.     wipe(concatList)
  1618.     local index = 1
  1619.  
  1620.     local macroTexture
  1621.     if (AutoBar.CLASS == "DRUID") then
  1622.         if (GetSpellInfo(spellNameList["Nature's Swiftness"])) then
  1623.             concatList[index] = "/cast "
  1624.             concatList[index + 1] = spellNameList["Nature's Swiftness"]
  1625.             concatList[index + 2] = "\n/cast "
  1626.             concatList[index + 3] = spellHealingTouch
  1627.  
  1628.             macroTexture = spellHealingTouchIcon
  1629.             self.macroActive = true
  1630.  
  1631.         elseif (GetSpellInfo(spellNameList["Frenzied Regeneration"])) then
  1632.             concatList[index] = "/cast "
  1633.             concatList[index + 1] = spellNameList["Frenzied Regeneration"]
  1634.             concatList[index + 2] = "\n"
  1635.  
  1636.             macroTexture = spellIconList["Frenzied Regeneration"]
  1637.             self.macroActive = true
  1638.  
  1639.         end
  1640.     elseif (AutoBar.CLASS == "DEATHKNIGHT") then
  1641.         if (GetSpellInfo(spellNameList["Rune Tap"])) then
  1642.             concatList[index] = "/cast "
  1643.             concatList[index + 1] = spellNameList["Rune Tap"]
  1644.  
  1645.             macroTexture = spellIconList["Rune Tap"]
  1646.             self.macroActive = true
  1647.         end
  1648.     elseif (AutoBar.CLASS == "HUNTER") then
  1649.         if (GetSpellInfo(spellNameList["Feign Death"])) then
  1650.             concatList[index] = "/cast "
  1651.             concatList[index + 1] = spellNameList["Feign Death"]
  1652.  
  1653.             macroTexture = spellIconList["Feign Death"]
  1654.             self.macroActive = true
  1655.         elseif (GetSpellInfo(spellNameList["Disengage"])) then
  1656.             concatList[index] = "/cast "
  1657.             concatList[index + 1] = spellNameList["Disengage"]
  1658.  
  1659.             macroTexture = spellIconList["Disengage"]
  1660.             self.macroActive = true
  1661.         end
  1662.     elseif (AutoBar.CLASS == "MAGE") then
  1663.         if (GetSpellInfo(spellNameList["Ice Block"])) then
  1664.             concatList[index] = "/cast "
  1665.             concatList[index + 1] = spellNameList["Ice Block"]
  1666.  
  1667.             macroTexture = spellIconList["Ice Block"]
  1668.             self.macroActive = true
  1669.         end
  1670.     elseif (AutoBar.CLASS == "PALADIN") then
  1671.         if (GetSpellInfo(spellNameList["Lay on Hands"])) then
  1672.             concatList[index] = "/cast "
  1673.             concatList[index + 1] = spellNameList["Lay on Hands"]
  1674.  
  1675.             macroTexture = spellIconList["Lay on Hands"]
  1676.             self.macroActive = true
  1677.         end
  1678.     elseif (AutoBar.CLASS == "PRIEST") then
  1679.         if (GetSpellInfo(spellNameList["Desperate Prayer"])) then
  1680.             concatList[index] = "/cast "
  1681.             concatList[index + 1] = spellNameList["Desperate Prayer"]
  1682.  
  1683.             macroTexture = spellIconList["Desperate Prayer"]
  1684.             self.macroActive = true
  1685.         end
  1686.     elseif (AutoBar.CLASS == "ROGUE") then
  1687.         if (GetSpellInfo(spellNameList["Vanish"])) then
  1688.             concatList[index] = "/cast "
  1689.             concatList[index + 1] = spellNameList["Vanish"]
  1690.  
  1691.             macroTexture = spellIconList["Vanish"]
  1692.             self.macroActive = true
  1693.         end
  1694.     elseif (AutoBar.CLASS == "WARRIOR") then
  1695.         if (GetSpellInfo(spellNameList["Last Stand"])) then
  1696.             concatList[index] = "/cast "
  1697.             concatList[index + 1] = spellNameList["Last Stand"]
  1698.  
  1699.             macroTexture = spellIconList["Last Stand"]
  1700.             self.macroActive = true
  1701.         elseif (GetSpellInfo(spellNameList["Enraged Regeneration"])) then
  1702.             concatList[index] = "/cast "
  1703.             concatList[index + 1] = spellNameList["Enraged Regeneration"]
  1704.  
  1705.             macroTexture = spellIconList["Enraged Regeneration"]
  1706.             self.macroActive = true
  1707.         end
  1708.  
  1709.     end
  1710.     if (self.macroActive) then
  1711.         local macroText = table.concat(concatList)
  1712.         self:AddMacro(macroText, macroTexture)
  1713.     end
  1714. end
  1715.  
  1716.  
  1717.  
  1718. local AutoBarButtonExplosive = AceOO.Class(AutoBarButton)
  1719. AutoBar.Class["AutoBarButtonExplosive"] = AutoBarButtonExplosive
  1720.  
  1721. function AutoBarButtonExplosive.prototype:init(parentBar, buttonDB)
  1722.     AutoBarButtonExplosive.super.prototype.init(self, parentBar, buttonDB)
  1723.  
  1724.     self:AddCategory("Misc.Explosives")
  1725. end
  1726.  
  1727.  
  1728. local AutoBarButtonFishing = AceOO.Class(AutoBarButton)
  1729. AutoBar.Class["AutoBarButtonFishing"] = AutoBarButtonFishing
  1730.  
  1731. function AutoBarButtonFishing.prototype:init(parentBar, buttonDB)
  1732.     AutoBarButtonFishing.super.prototype.init(self, parentBar, buttonDB)
  1733.  
  1734.     self:AddCategory("Tradeskill.Tool.Fishing.Lure")
  1735.     self:AddCategory("Tradeskill.Tool.Fishing.Gear")
  1736.     self:AddCategory("Tradeskill.Tool.Fishing.Other")
  1737.     self:AddCategory("Tradeskill.Tool.Fishing.Tool")
  1738.     self:AddCategory("Tradeskill.Tool.Fishing.Bait")
  1739.     self:AddCategory("Spell.Fishing")
  1740. end
  1741.  
  1742. local AutoBarButtonFood = AceOO.Class(AutoBarButton)
  1743. AutoBar.Class["AutoBarButtonFood"] = AutoBarButtonFood
  1744.  
  1745. function AutoBarButtonFood.prototype:init(parentBar, buttonDB)
  1746.     AutoBarButtonFood.super.prototype.init(self, parentBar, buttonDB)
  1747.  
  1748.     if (AutoBar.CLASS == "MAGE" and not buttonDB.disableConjure) then
  1749.         self:AddCategory("Consumable.Food.Conjure")
  1750.     end
  1751.     self:AddCategory("Muffin.Food.Health.Basic")
  1752.    
  1753.     if (buttonDB.include_combo_basic) then 
  1754.         self:AddCategory("Muffin.Food.Combo.Basic")
  1755.     end
  1756.    
  1757.     self:AddCategory("Consumable.Food.Percent.Basic")
  1758. end
  1759.  
  1760. --local function SetDisableConjure(info, value)
  1761. --  local buttonDB = AutoBar:GetButtonDB(info.arg.buttonKey)
  1762. --  buttonDB.disableConjure = value
  1763. --  AutoBar:BarButtonChanged()
  1764. --  AutoBar:CategoriesChanged()
  1765. --end
  1766.  
  1767. --function AutoBarButtonFood.prototype:Refresh(parentBar, buttonDB)
  1768. --  AutoBarButtonFood.super.prototype.Refresh(self, parentBar, buttonDB)
  1769. --  if (AutoBar.CLASS == "MAGE") then
  1770. --      if (buttonDB.disableConjure) then
  1771. --          self:DeleteCategory("Consumable.Food.Conjure")
  1772. --          buttonDB.castSpell = nil
  1773. --          AutoBarCategoryList["Consumable.Food.Edible.Combo.Conjured"]:SetCastList(nil)
  1774. --      else
  1775. --          self:AddCategory("Consumable.Food.Conjure")
  1776. --      end
  1777. --  end
  1778. --end
  1779.  
  1780. function AutoBarButtonFood.prototype:AddOptions(optionList, passValue)
  1781.     if (AutoBar.CLASS == "MAGE") then
  1782.         self:SetOptionBoolean(optionList, passValue, "disableConjure", L["Disable Conjure Button"])
  1783.     end
  1784.  
  1785.     self:SetOptionBoolean(optionList, passValue, "include_combo_basic", L["Include Basic Combo Food"])
  1786.  
  1787. end
  1788.  
  1789.  
  1790. local AutoBarButtonFoodBuff = AceOO.Class(AutoBarButton)
  1791. AutoBar.Class["AutoBarButtonFoodBuff"] = AutoBarButtonFoodBuff
  1792.  
  1793. function AutoBarButtonFoodBuff.prototype:init(parentBar, buttonDB)
  1794.     AutoBarButtonFoodBuff.super.prototype.init(self, parentBar, buttonDB)
  1795.  
  1796. --  self:AddCategory("Consumable.Food.Buff.Stamina")
  1797. --  self:AddCategory("Consumable.Food.Buff.HP Regen")
  1798. --  self:AddCategory("Consumable.Food.Percent.Bonus")
  1799.  
  1800.     self:AddCategory("Muffin.Food.Health.Buff")
  1801.  
  1802. --  if (AutoBar.CLASS == "DEATHKNIGHT" or AutoBar.CLASS == "WARRIOR") then
  1803. --      self:AddCategory("Consumable.Food.Buff.Strength")
  1804. --      self:AddCategory("Consumable.Food.Buff.Attack Power")
  1805. --      self:AddCategory("Consumable.Food.Buff.Dodge")
  1806. --  elseif (AutoBar.CLASS == "DRUID") then
  1807. --      self:AddCategory("Consumable.Food.Buff.Agility")
  1808. --      self:AddCategory("Consumable.Food.Buff.Attack Power")
  1809. --      self:AddCategory("Consumable.Food.Buff.Dodge")
  1810. --      self:AddCategory("Consumable.Food.Buff.Healing")
  1811. --      self:AddCategory("Consumable.Food.Buff.Intellect")
  1812. --      self:AddCategory("Consumable.Food.Buff.Mana Regen")
  1813. --      self:AddCategory("Consumable.Food.Buff.Spell Damage")
  1814. --      self:AddCategory("Consumable.Food.Buff.Spirit")
  1815. --  elseif (AutoBar.CLASS == "HUNTER" or AutoBar.CLASS == "ROGUE") then
  1816. --      self:AddCategory("Consumable.Food.Buff.Agility")
  1817. --      self:AddCategory("Consumable.Food.Buff.Attack Power")
  1818. --  elseif (AutoBar.CLASS == "MAGE"or AutoBar.CLASS == "WARLOCK") then
  1819. --      self:AddCategory("Consumable.Food.Buff.Intellect")
  1820. --      self:AddCategory("Consumable.Food.Buff.Mana Regen")
  1821. --      self:AddCategory("Consumable.Food.Buff.Spell Damage")
  1822. --      self:AddCategory("Consumable.Food.Buff.Spirit")
  1823. --  elseif (AutoBar.CLASS == "PALADIN") then
  1824. --      self:AddCategory("Consumable.Food.Buff.Strength")
  1825. --      self:AddCategory("Consumable.Food.Buff.Attack Power")
  1826. --      self:AddCategory("Consumable.Food.Buff.Dodge")
  1827. --      self:AddCategory("Consumable.Food.Buff.Healing")
  1828. --      self:AddCategory("Consumable.Food.Buff.Intellect")
  1829. --      self:AddCategory("Consumable.Food.Buff.Mana Regen")
  1830. --      self:AddCategory("Consumable.Food.Buff.Spell Damage")
  1831. --      self:AddCategory("Consumable.Food.Buff.Spirit")
  1832. --  elseif (AutoBar.CLASS == "PRIEST") then
  1833. --      self:AddCategory("Consumable.Food.Buff.Intellect")
  1834. --      self:AddCategory("Consumable.Food.Buff.Mana Regen")
  1835. --      self:AddCategory("Consumable.Food.Buff.Spell Damage")
  1836. --      self:AddCategory("Consumable.Food.Buff.Spirit")
  1837. --      self:AddCategory("Consumable.Food.Buff.Healing")
  1838. --  elseif (AutoBar.CLASS == "ROGUE") then
  1839. --      self:AddCategory("Consumable.Food.Buff.Agility")
  1840. --      self:AddCategory("Consumable.Food.Buff.Attack Power")
  1841. --  elseif (AutoBar.CLASS == "SHAMAN") then
  1842. --      self:AddCategory("Consumable.Food.Buff.Agility")
  1843. --      self:AddCategory("Consumable.Food.Buff.Attack Power")
  1844. --      self:AddCategory("Consumable.Food.Buff.Healing")
  1845. --      self:AddCategory("Consumable.Food.Buff.Intellect")
  1846. --      self:AddCategory("Consumable.Food.Buff.Mana Regen")
  1847. --      self:AddCategory("Consumable.Food.Buff.Spell Damage")
  1848. --      self:AddCategory("Consumable.Food.Buff.Spirit")
  1849. --  end
  1850. --
  1851. --  self:AddCategory("Consumable.Food.Buff.Other")
  1852. end
  1853.  
  1854.  
  1855. local AutoBarButtonFoodCombo = AceOO.Class(AutoBarButton)
  1856. AutoBar.Class["AutoBarButtonFoodCombo"] = AutoBarButtonFoodCombo
  1857.  
  1858. function AutoBarButtonFoodCombo.prototype:init(parentBar, buttonDB)
  1859.     AutoBarButtonFoodCombo.super.prototype.init(self, parentBar, buttonDB)
  1860.  
  1861.     self:AddCategory("Muffin.Food.Combo.Basic")
  1862.     self:AddCategory("Muffin.Food.Combo.Buff")
  1863.  
  1864. end
  1865.  
  1866.  
  1867. local AutoBarButtonFoodPet = AceOO.Class(AutoBarButton)
  1868. AutoBar.Class["AutoBarButtonFoodPet"] = AutoBarButtonFoodPet
  1869.  
  1870. function AutoBarButtonFoodPet.prototype:init(parentBar, buttonDB)
  1871.     AutoBarButtonFoodPet.super.prototype.init(self, parentBar, buttonDB)
  1872.  
  1873.     if (AutoBar.CLASS == "HUNTER") then
  1874.         self:AddCategory("Consumable.Food.Pet.Bread")
  1875.         self:AddCategory("Consumable.Food.Pet.Cheese")
  1876.         self:AddCategory("Consumable.Food.Pet.Fish")
  1877.         self:AddCategory("Consumable.Food.Pet.Fruit")
  1878.         self:AddCategory("Consumable.Food.Pet.Fungus")
  1879.         self:AddCategory("Consumable.Food.Pet.Meat")
  1880.         self:AddCategory("Consumable.Buff Pet")
  1881.     end
  1882.  
  1883.     self.rightClickTargetsPet = true
  1884. end
  1885.  
  1886.  
  1887. local AutoBarButtonFreeAction = AceOO.Class(AutoBarButton)
  1888. AutoBar.Class["AutoBarButtonFreeAction"] = AutoBarButtonFreeAction
  1889.  
  1890. function AutoBarButtonFreeAction.prototype:init(parentBar, buttonDB)
  1891.     AutoBarButtonFreeAction.super.prototype.init(self, parentBar, buttonDB)
  1892.  
  1893.     self:AddCategory("Consumable.Buff.Free Action")
  1894. end
  1895.  
  1896.  
  1897. local AutoBarButtonHeal = AceOO.Class(AutoBarButton)
  1898. AutoBar.Class["AutoBarButtonHeal"] = AutoBarButtonHeal
  1899.  
  1900. function AutoBarButtonHeal.prototype:init(parentBar, buttonDB)
  1901.     AutoBarButtonHeal.super.prototype.init(self, parentBar, buttonDB)
  1902.  
  1903.     --self:AddCategory("Consumable.Potion.Recovery.Healing.Endless")
  1904.     --self:AddCategory("Consumable.Potion.Recovery.Healing.Basic")
  1905.    
  1906.     --self:AddCategory("Consumable.Potion.Recovery.Rejuvenation.Basic")
  1907.    
  1908.     self:AddCategory("Muffin.Potion.Health")
  1909.     self:AddCategory("Muffin.Potion.Combo")
  1910.    
  1911.     self:AddCategory("Consumable.Cooldown.Stone.Health.Other")
  1912.     self:AddCategory("Consumable.Cooldown.Stone.Health.Statue")
  1913.     self:AddCategory("Consumable.Cooldown.Stone.Health.Warlock")
  1914.  
  1915.     --self:AddCategory("Consumable.Cooldown.Potion.Rejuvenation")
  1916.     --self:AddCategory("Consumable.Cooldown.Potion.Health.Coilfang")
  1917.     --self:AddCategory("Consumable.Cooldown.Potion.Health.Tempest Keep")
  1918.     --self:AddCategory("Consumable.Cooldown.Potion.Health.Blades Edge")
  1919.     --self:AddCategory("Consumable.Cooldown.Potion.Health.Anywhere")
  1920.     --self:AddCategory("Consumable.Cooldown.Potion.Health.PvP")
  1921.     --self:AddCategory("Consumable.Cooldown.Potion.Health.Basic")
  1922. end
  1923.  
  1924.  
  1925. local AutoBarButtonHearth = AceOO.Class(AutoBarButton)
  1926. AutoBar.Class["AutoBarButtonHearth"] = AutoBarButtonHearth
  1927.  
  1928. function AutoBarButtonHearth.prototype:init(parentBar, buttonDB)
  1929.     AutoBarButtonHearth.super.prototype.init(self, parentBar, buttonDB)
  1930.    
  1931.     local class = AutoBar.CLASS
  1932.  
  1933.     if (class == "DEATHKNIGHT" or class == "DRUID" or class == "MAGE" or class == "SHAMAN" or class == "WARLOCK" or class ==  "MONK") then
  1934.         self:AddCategory("Spell.Portals")
  1935.     end
  1936.  
  1937.     if(buttonDB.hearth_include_ancient_dalaran and class == "MAGE") then
  1938.         self:AddCategory("Spell.AncientDalaranPortals")
  1939.     end
  1940.    
  1941.     self:AddCategory("Misc.Hearth")
  1942. end
  1943.  
  1944. function AutoBarButtonHearth.prototype:AddOptions(optionList, passValue)
  1945.     self:SetOptionBoolean(optionList, passValue, "hearth_include_ancient_dalaran", L["HearthIncludeAncientDalaran"])
  1946. end
  1947.  
  1948. local AutoBarButtonEquipmentManager = AceOO.Class(AutoBarButtonMacro)
  1949. AutoBar.Class["AutoBarButtonEquipmentManager"] = AutoBarButtonEquipmentManager
  1950.  
  1951. function AutoBarButtonEquipmentManager.prototype:init(parentBar, buttonDB)
  1952.     AutoBarButtonEquipmentManager.super.prototype.init(self, parentBar, buttonDB)
  1953.     --self:Refresh(parentBar, buttonDB)
  1954.    
  1955.     local num_equip_sets = GetNumEquipmentSets()
  1956.     local set_name, icon, macro_text
  1957.    
  1958.     for index = 1, num_equip_sets, 1 do
  1959.         set_name, icon = GetEquipmentSetInfo(index)
  1960.         macro_text = "/equipset " .. set_name
  1961.         self:AddMacro(macro_text, icon)
  1962.         self.macroActive = true
  1963.     end
  1964.  
  1965. end
  1966.  
  1967.  
  1968. local AutoBarButtonMount = AceOO.Class(AutoBarButton)
  1969. AutoBar.Class["AutoBarButtonMount"] = AutoBarButtonMount
  1970.  
  1971. _, _, spellIconList["Amani War Bear"] = AutoBar:LoggedGetSpellInfo(43688)
  1972.  
  1973. function AutoBarButtonMount.prototype:init(parentBar, buttonDB)
  1974.     AutoBarButtonMount.super.prototype.init(self, parentBar, buttonDB)
  1975.  
  1976.     if (not AutoBarCategoryList["Spell.Mount"]) then
  1977.         AutoBarCategoryList["Spell.Mount"] = AutoBarSpells:new( "Spell.Mount", spellIconList["Amani War Bear"], {} )
  1978.         AutoBarCategoryList["Spell.Mount"]:SetNoSpellCheck(true)
  1979.     end
  1980.     self:AddCategory("Spell.Mount")
  1981.  
  1982.     local buttonData = AutoBar.db.char.buttonDataList[buttonDB.buttonKey]
  1983.     if (not buttonData) then
  1984.         buttonData = {}
  1985.         AutoBar.db.char.buttonDataList[buttonDB.buttonKey] = buttonData
  1986.     end
  1987.    
  1988.     if(buttonDB.mount_show_favourites == nil) then buttonDB.mount_show_favourites = true end
  1989.     if(buttonDB.mount_show_nonfavourites == nil) then buttonDB.mount_show_nonfavourites = false end
  1990.  
  1991.     buttonData.SetBest = self.SetBest
  1992.     self.flyable = -1
  1993.     self:Refresh(parentBar, buttonDB)
  1994. end
  1995.  
  1996. function AutoBarButtonMount.prototype:Refresh(parentBar, buttonDB, updateMount)
  1997.     AutoBarButtonMount.super.prototype.Refresh(self, parentBar, buttonDB)
  1998.  
  1999.     local category = AutoBarCategoryList["Spell.Mount"]
  2000.     if (not category) then
  2001.         AutoBarCategoryList["Spell.Mount"] = AutoBarSpells:new(
  2002.             "Spell.Mount", spellIconList["Amani War Bear"], {})
  2003.         category = AutoBarCategoryList["Spell.Mount"]
  2004.         category:SetNoSpellCheck(true)
  2005.         category.unInitialized = true
  2006.     end
  2007.    
  2008.     local companionType = "MOUNT"
  2009.     local count = GetNumCompanions(companionType)
  2010.     local total_mounts = C_MountJournal.GetNumMounts()
  2011.     local thisIsSpam = true
  2012.  
  2013. --print("NumCompanions:" .. count .. " UpdateMount:" .. tostring(updateMount))
  2014.  
  2015.     if (count > 0) then
  2016.         if (not category.castList) then
  2017.             category.castList = {}
  2018.         end
  2019.  
  2020.         local unInitialized = category.unInitialized --or (# category.castList ~= count)
  2021.         local spellName
  2022.         thisIsSpam = not unInitialized
  2023. --print("AutoBarButtonMount.prototype:Refresh unInitialized", unInitialized, "thisIsSpam", thisIsSpam, category.unInitialized, # category.castList, count)
  2024.         for index = 1, total_mounts, 1 do
  2025.             local creatureName, spellID, icon, active, isUsable, _, isFavorite, _, _, hideOnChar, isCollected = C_MountJournal.GetMountInfo(index)
  2026. --          print("  MountName:" .. creatureName .. " active:" .. tostring(active) .. " hideOnChar:" .. tostring(hideOnChar) .. " collected:" .. tostring(isCollected))
  2027.             --creatureID, creatureName, spellID, icon, active = GetCompanionInfo(companionType, index)
  2028.             spellName = GetSpellInfo(spellID)
  2029.             local user_selected = (isFavorite and buttonDB.mount_show_favourites) or (not isFavorite and buttonDB.mount_show_nonfavourites)
  2030.             if (unInitialized and isCollected and not hideOnChar and isUsable and user_selected) then
  2031.                 spellIconList[spellName] = icon
  2032.                 AutoBarSearch:RegisterSpell(spellName, true)
  2033.                 local spellInfo = AutoBarSearch.spells[spellName]
  2034.                 spellInfo.spellLink = "spell:" .. spellID
  2035.                 category.castList[# category.castList + 1] = spellName
  2036.             end
  2037.             if (active and updateMount) then
  2038.                 local buttonData = AutoBar.db.char.buttonDataList[self.buttonName]
  2039.                 if (AutoBar.flyable) then
  2040. --print("AutoBarButtonMount.prototype:Refresh flyingMount", buttonData.flyingMount, "-->", spellName)
  2041.                     if (buttonData.flyingMount ~= spellName) then
  2042.                         thisIsSpam = false
  2043. --print("AutoBarButtonMount.prototype:Refresh thisIsSpam", thisIsSpam, buttonData.flyingMount, spellName)
  2044.                     end
  2045.                     buttonData.flyingMount = spellName
  2046.                 else
  2047. --print("AutoBarButtonMount.prototype:Refresh groundMount", buttonData.groundMount, "-->", spellName)
  2048.                     if (buttonData.groundMount ~= spellName) then
  2049.                         thisIsSpam = false
  2050. --print("AutoBarButtonMount.prototype:Refresh thisIsSpam", thisIsSpam, buttonData.groundMount, spellName)
  2051.                     end
  2052.                     buttonData.groundMount = spellName
  2053.                 end
  2054.             end
  2055.         end
  2056.         category.unInitialized = nil
  2057.     end
  2058.     return thisIsSpam
  2059. end
  2060.  
  2061. function AutoBarButtonMount.prototype:AddOptions(optionList, passValue)
  2062.     self:SetOptionBoolean(optionList, passValue, "mount_show_favourites", L["MountShowFavourites"])
  2063.     self:SetOptionBoolean(optionList, passValue, "mount_show_nonfavourites", L["MountShowNonFavourites"])
  2064. end
  2065.  
  2066. function AutoBarButtonMount.prototype:Learned(parentBar, buttonDB, updateMount)
  2067. --  AutoBarButtonMount.super.prototype.Learned(self, parentBar, buttonDB)
  2068.  
  2069.  
  2070. end
  2071. --[[
  2072. /dump GetSpellInfo(43688)
  2073. /dump GetSpellInfo("Amani War Bear")
  2074. /dump AutoBarCategoryList["Spell.Mount"]
  2075. /script AutoBarSearch.sorted:Update("AutoBarButtonMount")
  2076. /dump AutoBarSearch.sorted:GetList("AutoBarButtonMount")
  2077. --]]
  2078.  
  2079. function AutoBarButtonMount.prototype.SetBest(sorted, buttonDB, buttonData, sortedItems, searchItems)
  2080.     local stopProcessing
  2081.     local flyable = AutoBar.flyable
  2082.     local self = AutoBar.buttonList[buttonDB.buttonKey]
  2083.     if (self.flyable ~= flyable) then
  2084.         self.flyable = flyable
  2085.         local mountId = nil
  2086.         if (flyable) then
  2087.             mountId = buttonData.flyingMount
  2088.         else
  2089.             mountId = buttonData.groundMount
  2090.         end
  2091.  
  2092.         if (mountId) then
  2093.             buttonData.arrangeOnUse = mountId
  2094.         end
  2095.     end
  2096.     return stopProcessing
  2097. end
  2098.  
  2099. --- Temporary until Blizzard makes their code work for mounts & critters
  2100. function AutoBarButtonMount.prototype:UpdateUsable()
  2101.     local frame = self.frame
  2102.     local itemType = frame:GetAttribute("type")
  2103.     if (itemType) then
  2104.         if (AutoBar.inCombat) then
  2105.             frame.icon:SetVertexColor(0.4, 0.4, 0.4)
  2106.         else
  2107.             frame.icon:SetVertexColor(1.0, 1.0, 1.0)
  2108.             frame.hotKey:SetVertexColor(1.0, 1.0, 1.0)
  2109.         end
  2110.  
  2111.         local popupHeader = self.frame.popupHeader
  2112.         if (popupHeader) then
  2113.             for _, popupButton in pairs(popupHeader.popupButtonList) do
  2114.                 frame = popupButton.frame
  2115.                 if (AutoBar.inCombat) then
  2116.                     frame.icon:SetVertexColor(0.4, 0.4, 0.4)
  2117.                 else
  2118.                     frame.icon:SetVertexColor(1.0, 1.0, 1.0)
  2119.                     frame.hotKey:SetVertexColor(1.0, 1.0, 1.0)
  2120.                 end
  2121.             end
  2122.         end
  2123.     end
  2124. end
  2125.  
  2126.  
  2127.  
  2128. local AutoBarButtonPets = AceOO.Class(AutoBarButton)
  2129. AutoBar.Class["AutoBarButtonPets"] = AutoBarButtonPets
  2130.  
  2131. _, _, spellIconList["Phoenix Hatchling"] = AutoBar:LoggedGetSpellInfo(46599)
  2132.  
  2133. function AutoBarButtonPets.prototype:init(parentBar, buttonDB)
  2134.     AutoBarButtonPets.super.prototype.init(self, parentBar, buttonDB)
  2135.  
  2136. --if (not AutoBarCategoryList["Spell.Critter"]) then
  2137. --  AutoBarCategoryList["Spell.Critter"] = AutoBarSpells:new(
  2138. --      "Spell.Critter", spellIconList["Phoenix Hatchling"], {})
  2139. --  AutoBarCategoryList["Spell.Critter"]:SetNoSpellCheck(true)
  2140. --end
  2141. --self:AddCategory("Spell.Critter")
  2142.  
  2143.     self:Refresh(parentBar, buttonDB)
  2144. end
  2145.  
  2146. function AutoBarButtonPets.prototype:Refresh(parentBar, buttonDB)
  2147.     AutoBarButtonPets.super.prototype.Refresh(self, parentBar, buttonDB)
  2148.  
  2149. --  if (not AutoBarCategoryList["Spell.Critter"]) then
  2150. --      AutoBarCategoryList["Spell.Critter"] = AutoBarSpells:new(
  2151. --          "Spell.Critter", spellIconList["Phoenix Hatchling"], {})
  2152. --      AutoBarCategoryList["Spell.Critter"]:SetNoSpellCheck(true)
  2153. --  end
  2154. --  local category = AutoBarCategoryList["Spell.Critter"]
  2155.  
  2156. --  local companionType = "CRITTER"
  2157. --  local count = GetNumCompanions(companionType)
  2158. --
  2159. --  if (count > 0) then
  2160. --      if (not category.castList) then
  2161. --          category.castList = {}
  2162. --      end
  2163. --      local castList = category.castList
  2164. --
  2165. --      local spellName, icon
  2166. --      local creatureID, creatureName, spellID, active
  2167. --      for index = 1, count, 1 do
  2168. --          creatureID, creatureName, spellID, icon, active = GetCompanionInfo(companionType, index)
  2169. --          spellName = GetSpellInfo(spellID)
  2170. --          spellIconList[spellName] = icon
  2171. --          AutoBarSearch:RegisterSpell(spellName, true)
  2172. --          local spellInfo = AutoBarSearch.spells[spellName]
  2173. --          spellInfo.spellLink = "spell:" .. spellID
  2174. --          category.castList[index] = spellName
  2175. --      end
  2176. --  end                            
  2177.  
  2178. --  local _, pet_count = C_PetJournal.GetNumPets()
  2179. --  local index, pet_id, owned, favorite, description, icon
  2180. --  for index = 1, pet_count, 1 do
  2181. --      local pet_data = {C_PetJournal.GetPetInfoByIndex(index)}
  2182. --      pet_id = pet_data[1]
  2183. --      owned = pet_data[3]
  2184. --      favorite = pet_data[6]
  2185. --      icon = pet_data[9]
  2186. --      description = pet_data[13]
  2187. --  end
  2188.    
  2189. end
  2190.  
  2191.  
  2192. --- Temporary until Blizzard makes their code work for mounts & critters
  2193. function AutoBarButtonPets.prototype:UpdateUsable()
  2194.     local frame = self.frame
  2195.     local itemType = frame:GetAttribute("type")
  2196.     if (itemType) then
  2197.         frame.icon:SetVertexColor(1.0, 1.0, 1.0)
  2198.         frame.hotKey:SetVertexColor(1.0, 1.0, 1.0)
  2199.  
  2200.         local popupHeader = self.frame.popupHeader
  2201.         if (popupHeader) then
  2202.             for _, popupButton in pairs(popupHeader.popupButtonList) do
  2203.                 frame = popupButton.frame
  2204.                 frame.icon:SetVertexColor(1.0, 1.0, 1.0)
  2205.                 frame.hotKey:SetVertexColor(1.0, 1.0, 1.0)
  2206.             end
  2207.         end
  2208.     end
  2209. end
  2210.  
  2211.  
  2212. local AutoBarButtonPickLock = AceOO.Class(AutoBarButton)
  2213. AutoBar.Class["AutoBarButtonPickLock"] = AutoBarButtonPickLock
  2214.  
  2215. function AutoBarButtonPickLock.prototype:init(parentBar, buttonDB)
  2216.     AutoBarButtonPickLock.super.prototype.init(self, parentBar, buttonDB)
  2217.  
  2218.     self:AddCategory("Misc.Unlock")
  2219.     self:AddCategory("Misc.Lockboxes")
  2220. end
  2221.  
  2222. local AutoBarButtonMillHerbs = AceOO.Class(AutoBarButton)
  2223. AutoBar.Class["AutoBarButtonMillHerbs"] = AutoBarButtonMillHerbs
  2224.  
  2225. function AutoBarButtonMillHerbs.prototype:init(parentBar, buttonDB)
  2226.     AutoBarButtonMillHerbs.super.prototype.init(self, parentBar, buttonDB)
  2227.  
  2228.     self:AddCategory("Tradeskill.Gather.Herbalism")
  2229. end
  2230.  
  2231.  
  2232. local AutoBarButtonMiscFun = AceOO.Class(AutoBarButton)
  2233. AutoBar.Class["AutoBarButtonMiscFun"] = AutoBarButtonMiscFun
  2234.  
  2235. function AutoBarButtonMiscFun.prototype:init(parentBar, buttonDB)
  2236.     AutoBarButtonMiscFun.super.prototype.init(self, parentBar, buttonDB)
  2237.  
  2238.     self:AddCategory("Consumable.Food.Feast")
  2239.     self:AddCategory("Misc.Usable.Permanent")
  2240.     self:AddCategory("Misc.Usable.Fun")
  2241.     self:AddCategory("Misc.Usable.Replenished")
  2242. end
  2243.  
  2244. local AutoBarButtonSunsongRanch = AceOO.Class(AutoBarButton)
  2245. AutoBar.Class["AutoBarButtonSunsongRanch"] = AutoBarButtonSunsongRanch
  2246.  
  2247. function AutoBarButtonSunsongRanch.prototype:init(parentBar, buttonDB)
  2248.     AutoBarButtonSunsongRanch.super.prototype.init(self, parentBar, buttonDB)
  2249.  
  2250.     self:AddCategory("Muffin.SunSongRanch")
  2251. end
  2252.  
  2253. local AutoBarButtonGarrison = AceOO.Class(AutoBarButton)
  2254. AutoBar.Class["AutoBarButtonGarrison"] = AutoBarButtonGarrison
  2255.  
  2256. function AutoBarButtonGarrison.prototype:init(parentBar, buttonDB)
  2257.     AutoBarButtonGarrison.super.prototype.init(self, parentBar, buttonDB)
  2258.  
  2259.     self:AddCategory("Muffin.Garrison")
  2260. end
  2261.  
  2262. local AutoBarButtonQuest = AceOO.Class(AutoBarButton)
  2263. AutoBar.Class["AutoBarButtonQuest"] = AutoBarButtonQuest
  2264.  
  2265. function AutoBarButtonQuest.prototype:init(parentBar, buttonDB)
  2266.     AutoBarButtonQuest.super.prototype.init(self, parentBar, buttonDB)
  2267.  
  2268.     self:AddCategory("Misc.Usable.StartsQuest")
  2269.     self:AddCategory("Muffin.Misc.Quest")
  2270.     self:AddCategory("Misc.Usable.BossItem")
  2271. end
  2272.  
  2273.  
  2274. local AutoBarButtonRecovery = AceOO.Class(AutoBarButton)
  2275. AutoBar.Class["AutoBarButtonRecovery"] = AutoBarButtonRecovery
  2276.  
  2277. function AutoBarButtonRecovery.prototype:init(parentBar, buttonDB)
  2278.     AutoBarButtonRecovery.super.prototype.init(self, parentBar, buttonDB)
  2279.  
  2280.     if (AutoBar.CLASS == "ROGUE") then
  2281.         self:AddCategory("Consumable.Buff.Energy")
  2282.     elseif (AutoBar.CLASS == "WARRIOR") then
  2283.         self:AddCategory("Consumable.Buff.Rage")
  2284.     elseif  (AutoBar:ClassUsesMana(AutoBar.CLASS)) then
  2285.         --self:AddCategory("Consumable.Potion.Recovery.Mana.Endless")
  2286.         --self:AddCategory("Consumable.Potion.Recovery.Mana.Basic")
  2287.    
  2288.         --self:AddCategory("Consumable.Potion.Recovery.Rejuvenation.Basic")
  2289.        
  2290.         self:AddCategory("Muffin.Potion.Mana")
  2291.         self:AddCategory("Muffin.Potion.Combo")
  2292.  
  2293.  
  2294.         self:AddCategory("Consumable.Cooldown.Stone.Mana.Other")
  2295.         --self:AddCategory("Consumable.Cooldown.Potion.Rejuvenation")
  2296.         --self:AddCategory("Consumable.Cooldown.Potion.Mana.Basic")
  2297.         --self:AddCategory("Consumable.Cooldown.Potion.Mana.Pvp")
  2298.         --self:AddCategory("Consumable.Cooldown.Potion.Mana.Coilfang")
  2299.         --self:AddCategory("Consumable.Cooldown.Potion.Mana.Tempest Keep")
  2300.         --self:AddCategory("Consumable.Cooldown.Potion.Mana.Blades Edge")
  2301.         --self:AddCategory("Consumable.Cooldown.Potion.Mana.Anywhere")
  2302.     end
  2303. end
  2304.  
  2305.  
  2306.  
  2307.  
  2308. local AutoBarButtonCooldownDrums = AceOO.Class(AutoBarButton)
  2309. AutoBar.Class["AutoBarButtonCooldownDrums"] = AutoBarButtonCooldownDrums
  2310.  
  2311. function AutoBarButtonCooldownDrums.prototype:init(parentBar, buttonDB)
  2312.     AutoBarButtonCooldownDrums.super.prototype.init(self, parentBar, buttonDB)
  2313.  
  2314.     self:AddCategory("Consumable.Cooldown.Drums")
  2315. end
  2316.  
  2317.  
  2318. local AutoBarButtonCooldownPotionCombat = AceOO.Class(AutoBarButton)
  2319. AutoBar.Class["AutoBarButtonCooldownPotionCombat"] = AutoBarButtonCooldownPotionCombat
  2320.  
  2321. function AutoBarButtonCooldownPotionCombat.prototype:init(parentBar, buttonDB)
  2322.     AutoBarButtonCooldownPotionCombat.super.prototype.init(self, parentBar, buttonDB)
  2323.  
  2324.     self:AddCategory("Consumable.Cooldown.Potion.Combat")
  2325. end
  2326.  
  2327.  
  2328. local AutoBarButtonCooldownStoneCombat = AceOO.Class(AutoBarButton)
  2329. AutoBar.Class["AutoBarButtonCooldownStoneCombat"] = AutoBarButtonCooldownStoneCombat
  2330.  
  2331. function AutoBarButtonCooldownStoneCombat.prototype:init(parentBar, buttonDB)
  2332.     AutoBarButtonCooldownStoneCombat.super.prototype.init(self, parentBar, buttonDB)
  2333.  
  2334.     self:AddCategory("Consumable.Cooldown.Stone.Combat")
  2335. end
  2336.  
  2337.  
  2338. local AutoBarButtonCooldownPotionHealth = AceOO.Class(AutoBarButton)
  2339. AutoBar.Class["AutoBarButtonCooldownPotionHealth"] = AutoBarButtonCooldownPotionHealth
  2340.  
  2341. function AutoBarButtonCooldownPotionHealth.prototype:init(parentBar, buttonDB)
  2342.     AutoBarButtonCooldownPotionHealth.super.prototype.init(self, parentBar, buttonDB)
  2343.  
  2344.     self:AddCategory("Consumable.Cooldown.Potion.Health.Basic")
  2345.     self:AddCategory("Consumable.Cooldown.Potion.Health.PvP")
  2346.     self:AddCategory("Consumable.Cooldown.Potion.Health.Coilfang")
  2347.     self:AddCategory("Consumable.Cooldown.Potion.Health.Tempest Keep")
  2348.     self:AddCategory("Consumable.Cooldown.Potion.Health.Blades Edge")
  2349.     self:AddCategory("Consumable.Cooldown.Potion.Health.Anywhere")
  2350. end
  2351.  
  2352.  
  2353. local AutoBarButtonCooldownStoneHealth = AceOO.Class(AutoBarButton)
  2354. AutoBar.Class["AutoBarButtonCooldownStoneHealth"] = AutoBarButtonCooldownStoneHealth
  2355.  
  2356. function AutoBarButtonCooldownStoneHealth.prototype:init(parentBar, buttonDB)
  2357.     AutoBarButtonCooldownStoneHealth.super.prototype.init(self, parentBar, buttonDB)
  2358.  
  2359.     self:AddCategory("Consumable.Cooldown.Stone.Health.Other")
  2360.     self:AddCategory("Consumable.Cooldown.Stone.Health.Statue")
  2361.     self:AddCategory("Consumable.Cooldown.Stone.Health.Warlock")
  2362. end
  2363.  
  2364.  
  2365. local AutoBarButtonCooldownPotionMana = AceOO.Class(AutoBarButton)
  2366. AutoBar.Class["AutoBarButtonCooldownPotionMana"] = AutoBarButtonCooldownPotionMana
  2367.  
  2368. function AutoBarButtonCooldownPotionMana.prototype:init(parentBar, buttonDB)
  2369.     AutoBarButtonCooldownPotionMana.super.prototype.init(self, parentBar, buttonDB)
  2370.  
  2371.     if (AutoBar.CLASS == "ROGUE") then
  2372.         self:AddCategory("Consumable.Buff.Energy")
  2373.     elseif (AutoBar.CLASS == "WARRIOR") then
  2374.         self:AddCategory("Consumable.Buff.Rage")
  2375.     else
  2376.         self:AddCategory("Muffin.Potion.Mana")
  2377.  
  2378.         --self:AddCategory("Consumable.Cooldown.Potion.Mana.Basic")
  2379.         --self:AddCategory("Consumable.Cooldown.Potion.Mana.Pvp")
  2380.         --self:AddCategory("Consumable.Cooldown.Potion.Mana.Coilfang")
  2381.         --self:AddCategory("Consumable.Cooldown.Potion.Mana.Tempest Keep")
  2382.         --self:AddCategory("Consumable.Cooldown.Potion.Mana.Blades Edge")
  2383.         --self:AddCategory("Consumable.Cooldown.Potion.Mana.Anywhere")
  2384.     end
  2385. end
  2386.  
  2387.  
  2388. local AutoBarButtonCooldownStoneMana = AceOO.Class(AutoBarButton)
  2389. AutoBar.Class["AutoBarButtonCooldownStoneMana"] = AutoBarButtonCooldownStoneMana
  2390.  
  2391. function AutoBarButtonCooldownStoneMana.prototype:init(parentBar, buttonDB)
  2392.     AutoBarButtonCooldownStoneMana.super.prototype.init(self, parentBar, buttonDB)
  2393.  
  2394.     if (AutoBar.CLASS ~= "ROGUE" and AutoBar.CLASS ~= "WARRIOR") then
  2395.         self:AddCategory("Consumable.Cooldown.Stone.Mana.Other")
  2396.     end
  2397. end
  2398.  
  2399.  
  2400. local AutoBarButtonCooldownPotionRejuvenation = AceOO.Class(AutoBarButton)
  2401. AutoBar.Class["AutoBarButtonCooldownPotionRejuvenation"] = AutoBarButtonCooldownPotionRejuvenation
  2402.  
  2403. function AutoBarButtonCooldownPotionRejuvenation.prototype:init(parentBar, buttonDB)
  2404.     AutoBarButtonCooldownPotionRejuvenation.super.prototype.init(self, parentBar, buttonDB)
  2405.  
  2406.     self:AddCategory("Consumable.Cooldown.Potion.Rejuvenation")
  2407. end
  2408.  
  2409.  
  2410.  
  2411. local AutoBarButtonCooldownStoneRejuvenation = AceOO.Class(AutoBarButton)
  2412. AutoBar.Class["AutoBarButtonCooldownStoneRejuvenation"] = AutoBarButtonCooldownStoneRejuvenation
  2413.  
  2414. function AutoBarButtonCooldownStoneRejuvenation.prototype:init(parentBar, buttonDB)
  2415.     AutoBarButtonCooldownStoneRejuvenation.super.prototype.init(self, parentBar, buttonDB)
  2416.  
  2417.     if (AutoBar.CLASS ~= "ROGUE" and AutoBar.CLASS ~= "WARRIOR") then
  2418. --      self:AddCategory("Consumable.Cooldown.Potion.Rejuvenation")
  2419.     end
  2420. end
  2421.  
  2422.  
  2423. local AutoBarButtonShields = AceOO.Class(AutoBarButton)
  2424. AutoBar.Class["AutoBarButtonShields"] = AutoBarButtonShields
  2425.  
  2426. function AutoBarButtonShields.prototype:init(parentBar, buttonDB)
  2427.     AutoBarButtonShields.super.prototype.init(self, parentBar, buttonDB)
  2428.  
  2429.     self:AddCategory("Spell.Shields")
  2430. end
  2431.  
  2432.  
  2433. local AutoBarButtonSpeed = AceOO.Class(AutoBarButton)
  2434. AutoBar.Class["AutoBarButtonSpeed"] = AutoBarButtonSpeed
  2435.  
  2436. function AutoBarButtonSpeed.prototype:init(parentBar, buttonDB)
  2437.     AutoBarButtonSpeed.super.prototype.init(self, parentBar, buttonDB)
  2438.  
  2439.     self:AddCategory("Consumable.Buff.Speed")
  2440. end
  2441.  
  2442.  
  2443. local AutoBarButtonStance = AceOO.Class(AutoBarButton)
  2444. AutoBar.Class["AutoBarButtonStance"] = AutoBarButtonStance
  2445.  
  2446. function AutoBarButtonStance.prototype:init(parentBar, buttonDB)
  2447.     AutoBarButtonStance.super.prototype.init(self, parentBar, buttonDB)
  2448.  
  2449.     if (AutoBar.CLASS == "WARRIOR") then
  2450.         self:AddCategory("Spell.Stance")
  2451.     end
  2452. end
  2453.  
  2454. function AutoBarButtonStance.prototype:GetLastUsed()
  2455.     local nStance = GetShapeshiftForm(true)
  2456.     local _, name = GetShapeshiftFormInfo(nStance)
  2457.     return name
  2458. end
  2459.  
  2460.  
  2461. local AutoBarButtonStealth = AceOO.Class(AutoBarButton)
  2462. AutoBar.Class["AutoBarButtonStealth"] = AutoBarButtonStealth
  2463.  
  2464. function AutoBarButtonStealth.prototype:init(parentBar, buttonDB)
  2465.     AutoBarButtonStealth.super.prototype.init(self, parentBar, buttonDB)
  2466.    
  2467.     self:AddCategory("Spell.Stealth")
  2468. end
  2469.  
  2470.  
  2471.  
  2472.  
  2473. local AutoBarButtonSeal = AceOO.Class(AutoBarButton)
  2474. AutoBar.Class["AutoBarButtonSeal"] = AutoBarButtonSeal
  2475.  
  2476. function AutoBarButtonSeal.prototype:init(parentBar, buttonDB)
  2477.     AutoBarButtonSeal.super.prototype.init(self, parentBar, buttonDB)
  2478.  
  2479.     self:AddCategory("Spell.Seal")
  2480. end
  2481.  
  2482.  
  2483. local AutoBarButtonGuildSpell = AceOO.Class(AutoBarButton)
  2484. AutoBar.Class["AutoBarButtonGuildSpell"] = AutoBarButtonGuildSpell
  2485.  
  2486. function AutoBarButtonGuildSpell.prototype:init(parentBar, buttonDB)
  2487.     AutoBarButtonGuildSpell.super.prototype.init(self, parentBar, buttonDB)
  2488.  
  2489.     self:AddCategory("Spell.Guild")
  2490. end
  2491.  
  2492.  
  2493. --------------------------------------------------ADDING NEW FUNCTIONALITY HERE
  2494.  
  2495. local totemAir = 4
  2496. local totemEarth = 2
  2497. local totemFire = 1
  2498. local totemWater = 3
  2499.  
  2500. local destroyMacro = {
  2501.     [totemFire] = "/run DestroyTotem(1)",
  2502.     [totemEarth] = "/run DestroyTotem(2)",
  2503.     [totemWater] = "/run DestroyTotem(3)",
  2504.     [totemAir] = "/run DestroyTotem(4)",
  2505. }
  2506. local function DestroyTotem(frame, totemType)
  2507.     frame:SetAttribute("type2", "macro")
  2508.     frame:SetAttribute("macrotext2", destroyMacro[totemType])
  2509. end
  2510.  
  2511. local AutoBarButtonTotemAir = AceOO.Class(AutoBarButton)
  2512. AutoBar.Class["AutoBarButtonTotemAir"] = AutoBarButtonTotemAir
  2513.  
  2514. function AutoBarButtonTotemAir.prototype:init(parentBar, buttonDB)
  2515.     AutoBarButtonTotemAir.super.prototype.init(self, parentBar, buttonDB)
  2516.  
  2517.     self:AddCategory("Spell.Totem.Air")
  2518. end
  2519.  
  2520. function AutoBarButtonTotemAir.prototype:SetupAttributes(button, bag, slot, spell, macroId, itemId, itemData)
  2521.     AutoBarButtonTotemAir.super.prototype.SetupAttributes(self, button, bag, slot, spell, macroId, itemId, itemData)
  2522.  
  2523.     DestroyTotem(self.frame, totemAir)
  2524. end
  2525.  
  2526. -- Set cooldown based on the deployed totem
  2527. function AutoBarButtonTotemAir.prototype:UpdateCooldown()
  2528.     local itemType = self.frame:GetAttribute("type")
  2529.     if (itemType and not self.parentBar.faded) then
  2530.         local start, duration, enabled = 0, 0, 1
  2531.         local totemName
  2532.         _, totemName, start, duration = GetTotemInfo(totemAir)
  2533.  
  2534.         if (start and duration and enabled and start > 0 and duration > 0) then
  2535.             self.frame.cooldown:Show() -- ToDo: necessary?
  2536.             CooldownFrame_SetTimer(self.frame.cooldown, start, duration, enabled)
  2537.         else
  2538.             CooldownFrame_SetTimer(self.frame.cooldown, 0, 0, 0)
  2539.         end
  2540.  
  2541.         local popupHeader = self.frame.popupHeader
  2542.         if (popupHeader) then
  2543.             for _, popupButton in pairs(popupHeader.popupButtonList) do
  2544.                 popupButton:UpdateCooldown()
  2545.             end
  2546.         end
  2547.     end
  2548. end
  2549. -- /script CooldownFrame_SetTimer(AutoBarButtonTotemAirFrame.cooldown, 0, 0, 0)
  2550.  
  2551. local AutoBarButtonTotemEarth = AceOO.Class(AutoBarButton)
  2552. AutoBar.Class["AutoBarButtonTotemEarth"] = AutoBarButtonTotemEarth
  2553.  
  2554. function AutoBarButtonTotemEarth.prototype:init(parentBar, buttonDB)
  2555.     AutoBarButtonTotemEarth.super.prototype.init(self, parentBar, buttonDB)
  2556.  
  2557.     self:AddCategory("Spell.Totem.Earth")
  2558. end
  2559.  
  2560. function AutoBarButtonTotemEarth.prototype:SetupAttributes(button, bag, slot, spell, macroId, itemId, itemData)
  2561.     AutoBarButtonTotemEarth.super.prototype.SetupAttributes(self, button, bag, slot, spell, macroId, itemId, itemData)
  2562.  
  2563.     DestroyTotem(self.frame, totemEarth)
  2564. end
  2565.  
  2566. -- Set cooldown based on the deployed totem
  2567. function AutoBarButtonTotemEarth.prototype:UpdateCooldown()
  2568.     local itemType = self.frame:GetAttribute("type")
  2569.     if (itemType and not self.parentBar.faded) then
  2570.         local start, duration, enabled = 0, 0, 1
  2571.         local totemName
  2572.         _, totemName, start, duration = GetTotemInfo(totemEarth)
  2573.  
  2574.         if (start and duration and enabled and start > 0 and duration > 0) then
  2575.             self.frame.cooldown:Show() -- ToDo: necessary?
  2576.             CooldownFrame_SetTimer(self.frame.cooldown, start, duration, enabled)
  2577.         else
  2578.             CooldownFrame_SetTimer(self.frame.cooldown, 0, 0, 0)
  2579.         end
  2580.  
  2581.         local popupHeader = self.frame.popupHeader
  2582.         if (popupHeader) then
  2583.             for _, popupButton in pairs(popupHeader.popupButtonList) do
  2584.                 popupButton:UpdateCooldown()
  2585.             end
  2586.         end
  2587.     end
  2588. end
  2589.  
  2590.  
  2591. local AutoBarButtonTotemFire = AceOO.Class(AutoBarButton)
  2592. AutoBar.Class["AutoBarButtonTotemFire"] = AutoBarButtonTotemFire
  2593.  
  2594. function AutoBarButtonTotemFire.prototype:init(parentBar, buttonDB)
  2595.     AutoBarButtonTotemFire.super.prototype.init(self, parentBar, buttonDB)
  2596.  
  2597.     self:AddCategory("Spell.Totem.Fire")
  2598. end
  2599.  
  2600. function AutoBarButtonTotemFire.prototype:SetupAttributes(button, bag, slot, spell, macroId, itemId, itemData)
  2601.     AutoBarButtonTotemFire.super.prototype.SetupAttributes(self, button, bag, slot, spell, macroId, itemId, itemData)
  2602.  
  2603.     DestroyTotem(self.frame, totemFire)
  2604. end
  2605.  
  2606. -- Set cooldown based on the deployed totem
  2607. function AutoBarButtonTotemFire.prototype:UpdateCooldown()
  2608.     local itemType = self.frame:GetAttribute("type")
  2609.     if (itemType and not self.parentBar.faded) then
  2610.         local start, duration, enabled = 0, 0, 1
  2611.         local totemName
  2612.         _, totemName, start, duration = GetTotemInfo(totemFire)
  2613.  
  2614.         if (start and duration and enabled and start > 0 and duration > 0) then
  2615.             self.frame.cooldown:Show() -- ToDo: necessary?
  2616.             CooldownFrame_SetTimer(self.frame.cooldown, start, duration, enabled)
  2617.         else
  2618.             CooldownFrame_SetTimer(self.frame.cooldown, 0, 0, 0)
  2619.         end
  2620.  
  2621.         local popupHeader = self.frame.popupHeader
  2622.         if (popupHeader) then
  2623.             for _, popupButton in pairs(popupHeader.popupButtonList) do
  2624.                 popupButton:UpdateCooldown()
  2625.             end
  2626.         end
  2627.     end
  2628. end
  2629.  
  2630.  
  2631. local AutoBarButtonTotemWater = AceOO.Class(AutoBarButton)
  2632. AutoBar.Class["AutoBarButtonTotemWater"] = AutoBarButtonTotemWater
  2633.  
  2634. function AutoBarButtonTotemWater.prototype:init(parentBar, buttonDB)
  2635.     AutoBarButtonTotemWater.super.prototype.init(self, parentBar, buttonDB)
  2636.  
  2637.     self:AddCategory("Spell.Totem.Water")
  2638. end
  2639.  
  2640. function AutoBarButtonTotemWater.prototype:SetupAttributes(button, bag, slot, spell, macroId, itemId, itemData)
  2641.     AutoBarButtonTotemWater.super.prototype.SetupAttributes(self, button, bag, slot, spell, macroId, itemId, itemData)
  2642.  
  2643.     DestroyTotem(self.frame, totemWater)
  2644. end
  2645.  
  2646. -- Set cooldown based on the deployed totem
  2647. function AutoBarButtonTotemWater.prototype:UpdateCooldown()
  2648.     local itemType = self.frame:GetAttribute("type")
  2649.     if (itemType and not self.parentBar.faded) then
  2650.         local start, duration, enabled = 0, 0, 1
  2651.         local totemName
  2652.         _, totemName, start, duration = GetTotemInfo(totemWater)
  2653.  
  2654.         if (start and duration and enabled and start > 0 and duration > 0) then
  2655.             self.frame.cooldown:Show() -- ToDo: necessary?
  2656.             CooldownFrame_SetTimer(self.frame.cooldown, start, duration, enabled)
  2657.         else
  2658.             CooldownFrame_SetTimer(self.frame.cooldown, 0, 0, 0)
  2659.         end
  2660.  
  2661.         local popupHeader = self.frame.popupHeader
  2662.         if (popupHeader) then
  2663.             for _, popupButton in pairs(popupHeader.popupButtonList) do
  2664.                 popupButton:UpdateCooldown()
  2665.             end
  2666.         end
  2667.     end
  2668. end
  2669.  
  2670.  
  2671. local AutoBarButtonTrap = AceOO.Class(AutoBarButton)
  2672. AutoBar.Class["AutoBarButtonTrap"] = AutoBarButtonTrap
  2673.  
  2674. function AutoBarButtonTrap.prototype:init(parentBar, buttonDB)
  2675.     AutoBarButtonTrap.super.prototype.init(self, parentBar, buttonDB)
  2676.  
  2677.     self:AddCategory("Spell.Trap")
  2678. end
  2679.  
  2680.  
  2681. local AutoBarButtonTrinket1 = AceOO.Class(AutoBarButton)
  2682. AutoBar.Class["AutoBarButtonTrinket1"] = AutoBarButtonTrinket1
  2683.  
  2684. function AutoBarButtonTrinket1.prototype:init(parentBar, buttonDB)
  2685.     AutoBarButtonTrinket1.super.prototype.init(self, parentBar, buttonDB)
  2686.  
  2687.     self:AddCategory("Muffin.Gear.Trinket")
  2688.     buttonDB.targeted = TRINKET1_SLOT
  2689.     buttonDB.equipped = TRINKET1_SLOT
  2690. end
  2691.  
  2692. function AutoBarButtonTrinket1.prototype:GetLastUsed()
  2693.     local _, itemId = AutoBar.LinkDecode(GetInventoryItemLink("player", TRINKET1_SLOT))
  2694.     return itemId
  2695. end
  2696.  
  2697. function AutoBarButtonTrinket1.prototype:SetDragCursor()
  2698.     local itemType = self.frame:GetAttribute("type")
  2699.     if (itemType) then
  2700.         if (itemType == "item") then
  2701.             PickupInventoryItem(TRINKET1_SLOT)
  2702.         end
  2703.     end
  2704. end
  2705.  
  2706. local AutoBarButtonTrinket2 = AceOO.Class(AutoBarButton)
  2707. AutoBar.Class["AutoBarButtonTrinket2"] = AutoBarButtonTrinket2
  2708.  
  2709. function AutoBarButtonTrinket2.prototype:init(parentBar, buttonDB)
  2710.     AutoBarButtonTrinket2.super.prototype.init(self, parentBar, buttonDB)
  2711.  
  2712.     self:AddCategory("Muffin.Gear.Trinket")
  2713.     buttonDB.targeted = TRINKET2_SLOT
  2714.     buttonDB.equipped = TRINKET2_SLOT
  2715. end
  2716.  
  2717. function AutoBarButtonTrinket2.prototype:GetLastUsed()
  2718.     local _, itemId = AutoBar.LinkDecode(GetInventoryItemLink("player", TRINKET2_SLOT))
  2719.     return itemId
  2720. end
  2721.  
  2722. function AutoBarButtonTrinket2.prototype:SetDragCursor()
  2723.     local itemType = self.frame:GetAttribute("type")
  2724.     if (itemType) then
  2725.         if (itemType == "item") then
  2726.       PickupInventoryItem(TRINKET2_SLOT)
  2727.         end
  2728.     end
  2729. end
  2730.  
  2731.  
  2732. local equipTrinket2String = "/equipslot " .. TRINKET2_SLOT .. " "
  2733. function AutoBarButtonTrinket2.prototype:SetupAttributes(button, bag, slot, spell, macroId, itemId, itemData)
  2734. --AutoBar:Print("AutoBarButtonTrinket2.prototype:SetupAttributes " .. tostring(bag) .. "|" .. tostring(slot) .. "|" .. tostring(itemId))
  2735.  
  2736.     local _, equippedItemId = AutoBar.LinkDecode(GetInventoryItemLink("player", TRINKET2_SLOT))
  2737.  
  2738.     if (equippedItemId == itemId) then
  2739.         AutoBarButtonTrinket2.super.prototype.SetupAttributes(self, button, bag, slot, spell, macroId, itemId, itemData)
  2740.     elseif (not bag) then
  2741.         AutoBarButtonTrinket2.super.prototype.SetupAttributes(self, button, bag, slot, spell, macroId, itemId, itemData)
  2742.     else
  2743.         local _,_,_,_,_,_,_,_,_,macroTexture = GetItemInfo(tonumber(itemId))
  2744.         local macroText = equipTrinket2String .. bag .." " .. slot -- "/equipslot [button:2] Z X Y" to do right click filtering
  2745.  
  2746.         button.macroText = macroText
  2747.         button.macroTexture = macroTexture
  2748.         local macroId = macroText
  2749.         AutoBarSearch:RegisterMacro(macroId, nil, L["AutoBarButtonTrinket2"], macroText)
  2750. --AutoBar:Print("AutoBarButtonTrinket2.prototype:SetupAttributes macroId " .. tostring(macroId))
  2751.         AutoBarButtonTrinket2.super.prototype.SetupAttributes(self, button, nil, nil, nil, macroId)
  2752.     end
  2753. end
  2754.  
  2755.  
  2756. local AutoBarButtonWater = AceOO.Class(AutoBarButton)
  2757. AutoBar.Class["AutoBarButtonWater"] = AutoBarButtonWater
  2758.  
  2759. function AutoBarButtonWater.prototype:init(parentBar, buttonDB)
  2760.     AutoBarButtonWater.super.prototype.init(self, parentBar, buttonDB)
  2761.  
  2762.     if (AutoBar.CLASS == "MAGE" and not buttonDB.disableConjure) then
  2763.         self:AddCategory("Consumable.Water.Conjure")
  2764.     end
  2765.     if (AutoBar:ClassUsesMana(AutoBar.CLASS)) then
  2766.         self:AddCategory("Consumable.Water.Percentage")
  2767.         self:AddCategory("Consumable.Water.Basic")
  2768.  
  2769.         self:AddCategory("Muffin.Food.Mana.Basic")
  2770.     end
  2771. end
  2772.  
  2773. --function AutoBarButtonWater.prototype:Refresh(parentBar, buttonDB)
  2774. --  AutoBarButtonWater.super.prototype.Refresh(self, parentBar, buttonDB)
  2775. --  if (AutoBar.CLASS == "MAGE") then
  2776. --      if (buttonDB.disableConjure) then
  2777. --          self:DeleteCategory("Consumable.Water.Conjure")
  2778. --          buttonDB.castSpell = nil
  2779. --          AutoBarCategoryList["Consumable.Water.Basic"]:SetCastList(nil)
  2780. --      else
  2781. --          self:AddCategory("Consumable.Water.Conjure")
  2782. --      end
  2783. --  end
  2784. --end
  2785.  
  2786. function AutoBarButtonWater.prototype:AddOptions(optionList, passValue)
  2787.     if (AutoBar.CLASS == "MAGE") then
  2788.         self:SetOptionBoolean(optionList, passValue, "disableConjure", L["Disable Conjure Button"])
  2789.     end
  2790. end
  2791.  
  2792.  
  2793. local AutoBarButtonWaterBuff = AceOO.Class(AutoBarButton)
  2794. AutoBar.Class["AutoBarButtonWaterBuff"] = AutoBarButtonWaterBuff
  2795.  
  2796. function AutoBarButtonWaterBuff.prototype:init(parentBar, buttonDB)
  2797.     AutoBarButtonWaterBuff.super.prototype.init(self, parentBar, buttonDB)
  2798.  
  2799.     self:AddCategory("Muffin.Food.Mana.Buff")
  2800.  
  2801. end
  2802.  
  2803.  
  2804.  
  2805. --[[
  2806. /script print(AutoBarProfile.basic[2].castSpell)
  2807. /script print(AutoBar.buttons[2].castSpell)
  2808. /script AutoBarSAB1Border:Hide()
  2809. /dump AutoBar.buttonList["AutoBarButtonMount"].frame:GetScript("OnEvent")
  2810. /dump AutoBarCategoryList["Spell.Portals"]
  2811. /dump AutoBarSearch.sorted:GetList("AutoBarButtonMount")
  2812. --]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement