Advertisement
Guest User

Untitled

a guest
Apr 26th, 2014
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.74 KB | None | 0 0
  1. function Module:SetupHooks()
  2.     local function AddRegionKeys(self)
  3.         local name = self:GetName()
  4.         self.__name = _G[name.."Name"]
  5.         self.__count = _G[name.."Count"]
  6.         self.__hotkey = _G[name.."HotKey"]
  7.         self.__border = _G[name.."Border"]
  8.         self.__flash = _G[name.."Flash"]
  9.         self.__normalTexture = _G[name.."NormalTexture"]
  10.         self.__normalTexture2 = _G[name.."NormalTexture2"]
  11.         self.__pushedTexture = self:GetPushedTexture()
  12.         self.__highlightTexture = self:GetHighlightTexture()
  13.         self.__checkedTexture = self:GetCheckedTexture()
  14.         return name
  15.     end
  16.  
  17.     local function ColorButton(texture)
  18.         if db.misc.classcolor then
  19.             texture:SetVertexColor(classColor.r * 1.2, classColor.g * 1.2, classColor.b * 1.2)
  20.         else
  21.             local color = db.actionbars.color
  22.             texture:SetVertexColor(color.r, color.g, color.b)
  23.         end
  24.     end
  25.  
  26.     local function UpdateButton(button, iconOffset, borderOffset)
  27.         if not button then return end
  28.         iconOffset = iconOffset or 1
  29.         borderOffset = borderOffset or 15
  30.  
  31.         button:SetNormalTexture("Interface\\BUTTONS\\UI-Quickslot2")
  32.  
  33.         local icon = button.icon
  34.         icon:ClearAllPoints()
  35.         icon:SetPoint("TOPLEFT", -iconOffset, iconOffset)
  36.         icon:SetPoint("BOTTOMRIGHT", iconOffset, -iconOffset)
  37.         icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
  38.  
  39.         local normalTexture = button.__normalTexture2 or button.__normalTexture
  40.         if not normalTexture then
  41.             AddRegionKeys(button)
  42.             normalTexture = button.__normalTexture2 or button.__normalTexture
  43.         end
  44.         normalTexture:ClearAllPoints()
  45.         normalTexture:SetPoint("TOPLEFT", -borderOffset, borderOffset)
  46.         normalTexture:SetPoint("BOTTOMRIGHT", borderOffset, -borderOffset)
  47.  
  48.         ColorButton(normalTexture)
  49.     end
  50.  
  51.     local extraActionButtons = setmetatable({}, { __index = function(t, self)
  52.         local name = AddRegionKeys(self)
  53.         local v = not not strmatch(name, "ExtraActionButton")
  54.         t[f] = v
  55.         return v
  56.     end })
  57.  
  58.     hooksecurefunc("ActionButton_Update", function(self)
  59.         if not extraActionButtons[self] then
  60.             UpdateButton(self, 0, 14)
  61.         end
  62.     end)
  63.  
  64.     hooksecurefunc("ActionButton_UpdateUsable", function(self)
  65.         if not extraActionButtons[self] then
  66.             ColorButton(self.__normalTexture)
  67.         end
  68.     end)
  69.  
  70.     hooksecurefunc("ActionButton_ShowGrid", function(self)
  71.         if not extraActionButtons[self] then
  72.             ColorButton(self.__normalTexture)
  73.         end
  74.     end)
  75.  
  76.     hooksecurefunc("PetActionBar_Update", function()
  77.         for i = 1, NUM_PET_ACTION_SLOTS do
  78.             UpdateButton(_G["PetActionButton"..i])
  79.         end
  80.     end)
  81.  
  82.     hooksecurefunc("PossessBar_UpdateState", function()
  83.         for i = 1, NUM_POSSESS_SLOTS do
  84.             UpdateButton(_G["PossessButton"..i])
  85.         end
  86.     end)
  87.  
  88.     hooksecurefunc("StanceBar_UpdateState", function()
  89.         for i = 1, NUM_STANCE_SLOTS do
  90.             UpdateButton(_G["StanceButton"..i])
  91.         end
  92.     end)
  93.  
  94.     ---------------------------------------------------------------------
  95.  
  96.     hooksecurefunc("AuraButton_Update", function(buttonName, index, filter)
  97.         if not db.actionbars.auraborder then return end
  98.  
  99.         local buffName = buttonName..index
  100.         local self = _G[buffName]
  101.         if not self.__border then AddRegionKeys(self) end
  102.  
  103.         local icon = self.icon
  104.         if icon then
  105.             icon:SetTexCoord(.07, .93, .07, .93)
  106.         end
  107.  
  108.         local border = self.__border
  109.         if not border then
  110.             border = self:CreateTexture("$parentOverlay", "ARTWORK")
  111.             self.__border = border
  112.         end
  113.         border:SetTexture("Interface\\BUTTONS\\UI-Quickslot2")
  114.         border:ClearAllPoints()
  115.         border:SetPoint("TOPLEFT", bu, -12, 12)
  116.         border:SetPoint("BOTTOMRIGHT", bu, 12, -12)
  117.         border:SetTexCoord(0, 1, 0, 1)
  118.         ColorButton(border)
  119.     end)
  120.  
  121.     ---------------------------------------------------------------------
  122.  
  123.     local rangeAddons = {
  124.         "GreenRange",
  125.         "RangeColors",
  126.         "RedRange",
  127.         "tullaRange",
  128.     }
  129.     for i = 1, #rangeAddons do
  130.         local _, _, _, enabled = GetAddOnInfo(rangeAddons[i])
  131.         if enabled then
  132.             rangeAddons = nil
  133.             break
  134.         end
  135.     end
  136.  
  137.     if rangeAddons then
  138.         hooksecurefunc("ActionButton_UpdateUsable", function(self)
  139.             local isUsable, notEnoughMana = IsUsableAction(self.action)
  140.             if isUsable then
  141.                 self.icon:SetVertexColor(1, 1, 1)
  142.             elseif notEnoughMana then
  143.                 local color = db.actionbars.color.OutOfMana
  144.                 self.icon:SetVertexColor(color.r, color.g, color.b)
  145.             else
  146.                 local color = db.actionbars.color.NotUsable
  147.                 self.icon:SetVertexColor(color.r, color.g, color.b)
  148.             end
  149.         end)
  150.  
  151.         hooksecurefunc("ActionButton_OnUpdate", function(self, elapsed)
  152.             local rangeTimer = self.rangeTimer2 or 0
  153.             rangeTimer = rangeTimer - elapsed
  154.             if rangeTimer <= 0 then
  155.                 if IsActionInRange(self.action) == 0 then
  156.                     local color = db.actionbars.color.OutOfRange
  157.                     self.icon:SetVertexColor(color.r, color.g, color.b)
  158.                 end
  159.                 rangeTimer = TOOLTIP_UPDATE_TIME
  160.             end
  161.             self.rangeTimer2 = rangeTimer
  162.         end)
  163.     end
  164.  
  165.     self.SetupHooks = nil
  166. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement