Advertisement
Guest User

Untitled

a guest
Apr 25th, 2014
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local Core = LibStub("AceAddon-3.0"):GetAddon("BasicUI")
  2. local Module = Core:NewModule("Actionbars", "AceEvent-3.0")
  3.  
  4. local db, classColor
  5.  
  6. ----------------
  7. -- Actionbars --
  8. ----------------
  9.  
  10. function Module:OnInitialize()
  11.     db = Core.db.profile
  12.  
  13.     local _, class = UnitClass("player")
  14.     classColor = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  15. end
  16.  
  17. function Module:OnEnable()
  18.     if InCombatLockdown() then
  19.         return self:RegisterEvent("PLAYER_REGEN_ENABLED", "OnEnable")
  20.     end
  21.     self:UnregisterEvent("PLAYER_REGEN_ENABLED")
  22.  
  23.     if self.SetupHooks then
  24.         self:SetupHooks()
  25.     end
  26.  
  27.     if enabled or not db.actionbars.enable then return end
  28.     enabled = true -- since most of this stuff is non-undoable (eg. hooksecurefunc)
  29.  
  30.     local hotkeyAlpha = db.actionbars.showHotKeys and 1 or 0
  31.     for i = 1, 12 do
  32.         _G["ActionButton"..i.."HotKey"]:SetAlpha(hotkeyAlpha) -- main bar
  33.         _G["MultiBarBottomRightButton"..i.."HotKey"]:SetAlpha(hotkeyAlpha) -- bottom right bar
  34.         _G["MultiBarBottomLeftButton"..i.."HotKey"]:SetAlpha(hotkeyAlpha) -- bottom left bar
  35.         _G["MultiBarRightButton"..i.."HotKey"]:SetAlpha(hotkeyAlpha) -- right bar
  36.         _G["MultiBarLeftButton"..i.."HotKey"]:SetAlpha(hotkeyAlpha) -- left bar
  37.     end
  38.  
  39.     local macroAlpha = db.actionbars.showMacronames and 1 or 0
  40.     for i = 1, 12 do
  41.         _G["ActionButton"..i.."Name"]:SetAlpha(macroAlpha) -- main bar
  42.         _G["MultiBarBottomRightButton"..i.."Name"]:SetAlpha(macroAlpha) -- bottom right bar
  43.         _G["MultiBarBottomLeftButton"..i.."Name"]:SetAlpha(macroAlpha) -- bottom left bar
  44.         _G["MultiBarRightButton"..i.."Name"]:SetAlpha(macroAlpha) -- right bar
  45.         _G["MultiBarLeftButton"..i.."Name"]:SetAlpha(macroAlpha) -- left bar
  46.     end
  47. end
  48.  
  49. function Module:SetupHooks()
  50.     -- BetterBlizzardButtonBorder v1.1.1
  51.     -- By Aprikot - http://aprikot.wowinterface.com
  52.     -- Based upon functions within nMainbar by Neal, and thek: Buttonskin by thek
  53.  
  54.     local function AddRegionKeys(self)
  55.         local name = self:GetName()
  56.         self.__name = _G[name.."Name"]
  57.         self.__count = _G[name.."Count"]
  58.         self.__hotkey = _G[name.."HotKey"]
  59.         self.__border = _G[name.."Border"]
  60.         self.__flash = _G[name.."Flash"]
  61.         self.__normalTexture = _G[name.."NormalTexture"]
  62.         self.__normalTexture2 = _G[name.."NormalTexture2"]
  63.         self.__pushedTexture = self:GetPushedTexture()
  64.         self.__highlightTexture = self:GetHighlightTexture()
  65.         self.__checkedTexture = self:GetCheckedTexture()
  66.         return name
  67.     end
  68.  
  69.     local function ColorButton(texture)
  70.         if db.misc.classcolor then
  71.             texture:SetVertexColor(classColor.r * 1.2, classColor.g * 1.2, classColor.b * 1.2)
  72.         else
  73.             local color = db.actionbars.color
  74.             texture:SetVertexColor(color.r, color.g, color.b)
  75.         end
  76.     end
  77.  
  78.     local extraActionButtons = setmetatable({}, { __index = function(t, self)
  79.         local name = AddRegionKeys(self)
  80.         local v = not not strmatch(name, "ExtraActionButton")
  81.         t[f] = v
  82.         return v
  83.     end })
  84.  
  85.     hooksecurefunc("ActionButton_Update", function(self)
  86.         if extraActionButtons[self] then return end
  87.  
  88.         self:SetNormalTexture("Interface\\BUTTONS\\UI-Quickslot2")
  89.  
  90.         local icon = self.icon
  91.         icon:SetTexCoord(.05, .95, .05, .95)
  92.         icon:ClearAllPoints()
  93.         icon:SetPoint("TOPLEFT")
  94.         icon:SetPoint("BOTTOMRIGHT")
  95.  
  96.         local normalTexture = self.__normalTexture
  97.         normalTexture:ClearAllPoints()
  98.         normalTexture:SetPoint("TOPLEFT", -14, 14)
  99.         normalTexture:SetPoint("BOTTOMRIGHT", 14, -14)
  100.         ColorButton(normalTexture)
  101.     end)
  102.  
  103.     hooksecurefunc("ActionButton_UpdateUsable", function(self)
  104.         if extraActionButtons[self] then return end
  105.         ColorButton(self.__normalTexture)
  106.     end)
  107.  
  108.     hooksecurefunc("ActionButton_ShowGrid", function(self)
  109.         if extraActionButtons[self] then return end
  110.         ColorButton(self.__normalTexture)
  111.     end)
  112.  
  113.     local petButtons = { "PetActionButton", "PossessButton", "ShapeshiftButton" }
  114.     hooksecurefunc("PetActionBar_Update",  function()
  115.         for i = 1, #petButtons do
  116.             for j = 1, 12 do
  117.                 local button = _G[petButtons[i]..j]
  118.                 button:SetNormalTexture("Interface\\BUTTONS\\UI-Quickslot2")
  119.  
  120.                 AddRegionKeys(button)
  121.  
  122.                 local icon = button.icon
  123.                 icon:SetTexCoord(.05, .95, .05, .95)
  124.                 icon:ClearAllPoints()
  125.                 icon:SetPoint("TOPLEFT", -1, 1)
  126.                 icon:SetPoint("BOTTOMRIGHT", 1, -1)
  127.  
  128.                 local normalTexture = button.__normalTexture2 or button.__normalTexture
  129.                 normalTexture:ClearAllPoints()
  130.                 normalTexture:SetPoint("TOPLEFT", -15, 15)
  131.                 normalTexture:SetPoint("BOTTOMRIGHT",15, -15)
  132.  
  133.                 ColorButton(normalTexture)
  134.             end
  135.         end
  136.     end)
  137.  
  138.     hooksecurefunc("AuraButton_Update", function(buttonName, index, filter)
  139.         if not db.actionbars.auraborder then return end
  140.  
  141.         local buffName = buttonName..index
  142.         local self = _G[buffName]
  143.         if not self.__border then AddRegionKeys(self) end
  144.  
  145.         local icon = self.icon
  146.         if icon then
  147.             icon:SetTexCoord(.07, .93, .07, .93)
  148.         end
  149.  
  150.         local border = self.__border
  151.         if not border then
  152.             border = self:CreateTexture("$parentOverlay", "ARTWORK")
  153.             self.__border = border
  154.         end
  155.         border:SetTexture("Interface\\BUTTONS\\UI-Quickslot2")
  156.         border:ClearAllPoints()
  157.         border:SetPoint("TOPLEFT", bu, -12, 12)
  158.         border:SetPoint("BOTTOMRIGHT", bu, 12, -12)
  159.         border:SetTexCoord(0, 1, 0, 1)
  160.         ColorButton(border)
  161.     end)
  162.  
  163.     ---------------------------------------------------------------------
  164.  
  165.     local rangeAddons = {
  166.         "GreenRange",
  167.         "RangeColors",
  168.         "RedRange",
  169.         "tullaRange",
  170.     }
  171.     for i = 1, #rangeAddons do
  172.         local _, _, _, enabled = GetAddOnInfo(rangeAddons[i])
  173.         if enabled then
  174.             rangeAddons = nil
  175.             break
  176.         end
  177.     end
  178.  
  179.     if rangeAddons then
  180.         hooksecurefunc("ActionButton_UpdateUsable", function(self)
  181.             local isUsable, notEnoughMana = IsUsableAction(self.action)
  182.             if isUsable then
  183.                 self.icon:SetVertexColor(1, 1, 1)
  184.             elseif notEnoughMana then
  185.                 local color = db.actionbars.color.OutOfMana
  186.                 self.icon:SetVertexColor(color.r, color.g, color.b)
  187.             else
  188.                 local color = db.actionbars.color.NotUsable
  189.                 self.icon:SetVertexColor(color.r, color.g, color.b)
  190.             end
  191.         end)
  192.  
  193.         hooksecurefunc("ActionButton_OnUpdate", function(self, elapsed)
  194.             local rangeTimer = self.rangeTimer2 or 0
  195.             rangeTimer = rangeTimer - elapsed
  196.             if rangeTimer <= 0 then
  197.                 if IsActionInRange(self.action) == 0 then
  198.                     local color = db.actionbars.color.OutOfRange
  199.                     self.icon:SetVertexColor(color.r, color.g, color.b)
  200.                 end
  201.                 rangeTimer = TOOLTIP_UPDATE_TIME
  202.             end
  203.             self.rangeTimer2 = rangeTimer
  204.         end)
  205.     end
  206.  
  207.     self.SetupHooks = nil
  208. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement