Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: Sh1pley on Nov 7th, 2013  |  syntax: None  |  size: 9.44 KB  |  hits: 42  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2.   --get the addon namespace
  3.   local addon, ns = ...
  4.  
  5.   --get the config values
  6.   local cfg = ns.cfg
  7.  
  8.   ---------------------------------------
  9.   -- CONSTANTS
  10.   ---------------------------------------
  11.  
  12.   local _G = _G
  13.  
  14.   --disable consolidated buffs
  15.   SetCVar("consolidateBuffs", 0)
  16.  
  17.   local BuffFrame               = _G["BuffFrame"]
  18.   local TemporaryEnchantFrame   = _G["TemporaryEnchantFrame"]
  19.   local ConsolidatedBuffs       = _G["ConsolidatedBuffs"]
  20.  
  21.   --rewrite the oneletter shortcuts
  22.   HOUR_ONELETTER_ABBR = "%dh";
  23.   DAY_ONELETTER_ABBR = "%dd";
  24.   MINUTE_ONELETTER_ABBR = "%dm";
  25.   SECOND_ONELETTER_ABBR = "%ds";
  26.  
  27.   --classcolor
  28.   local classcolor = RAID_CLASS_COLORS[select(2, UnitClass("player"))]
  29.  
  30.   if cfg.color.classcolored then
  31.     cfg.color.normal = classcolor
  32.   end
  33.  
  34.   if cfg.background.classcolored then
  35.     cfg.background.shadowcolor = classcolor
  36.   end
  37.  
  38.   --backdrop
  39.   local backdrop = {
  40.     bgFile = "",
  41.     edgeFile = cfg.textures.outer_shadow,
  42.     tile = false,
  43.     tileSize = 32,
  44.     edgeSize = cfg.background.inset,
  45.     insets = {
  46.       left = cfg.background.inset,
  47.       right = cfg.background.inset,
  48.       top = cfg.background.inset,
  49.       bottom = cfg.background.inset,
  50.     },
  51.   }
  52.  
  53.   ---------------------------------------
  54.   -- FUNCTIONS
  55.   ---------------------------------------
  56.  
  57.   --allows frames to become movable but frames can be locked or set to default positions
  58.   local function applyDragFunctionality(f,userplaced,locked)
  59.     f:SetScript("OnDragStart", function(s) if IsAltKeyDown() and IsShiftKeyDown() then s:StartMoving() end end)
  60.     f:SetScript("OnDragStop", function(s) s:StopMovingOrSizing() end)
  61.  
  62.     local t = f:CreateTexture(nil,"OVERLAY",nil,6)
  63.     t:SetAllPoints(f)
  64.     t:SetTexture(0,1,0)
  65.     t:SetAlpha(0)
  66.     f.dragtexture = t
  67.     f:SetHitRectInsets(-15,-15,-15,-15)
  68.     f:SetClampedToScreen(true)
  69.  
  70.     if not userplaced then
  71.       f:SetMovable(false)
  72.     else
  73.       f:SetMovable(true)
  74.       f:SetUserPlaced(true)
  75.       if not locked then
  76.         f.dragtexture:SetAlpha(0.2)
  77.         f:EnableMouse(true)
  78.         f:RegisterForDrag("LeftButton")
  79.         f:SetScript("OnEnter", function(s)
  80.           GameTooltip:SetOwner(s, "ANCHOR_TOP")
  81.           GameTooltip:AddLine(s:GetName(), 0, 1, 0.5, 1, 1, 1)
  82.           GameTooltip:AddLine("Hold down ALT+SHIFT to drag!", 1, 1, 1, 1, 1, 1)
  83.           GameTooltip:Show()
  84.         end)
  85.         f:SetScript("OnLeave", function(s) GameTooltip:Hide() end)
  86.       else
  87.         f.dragtexture:SetAlpha(0)
  88.         f:EnableMouse(nil)
  89.         f:RegisterForDrag(nil)
  90.         f:SetScript("OnEnter", nil)
  91.         f:SetScript("OnLeave", nil)
  92.       end
  93.     end
  94.   end
  95.  
  96.   --update wpn enchant icon positions
  97.   local function updateTempEnchantAnchors()
  98.     local previousBuff
  99.     for i=1, NUM_TEMP_ENCHANT_FRAMES do
  100.       local b = _G["TempEnchant"..i]
  101.       if b then
  102.         if (i == 1) then
  103.           b:SetPoint("TOPRIGHT", TemporaryEnchantFrame, "TOPRIGHT", 0, 0)
  104.         else
  105.           b:SetPoint("RIGHT", previousBuff, "LEFT", -cfg.tempenchant.colSpacing, 0)
  106.         end
  107.         previousBuff = b
  108.       end
  109.     end
  110.   end
  111.  
  112.   --create drag frame for temp enchant icons
  113.   local function createTempEnchantHolder()
  114.     local f = CreateFrame("Frame", "rBFS_TempEnchantHolder", UIParent)
  115.     f:SetSize(50,50)
  116.     f:SetPoint(cfg.tempenchant.pos.a1,cfg.tempenchant.pos.af,cfg.tempenchant.pos.a2,cfg.tempenchant.pos.x,cfg.tempenchant.pos.y)
  117.     applyDragFunctionality(f,cfg.tempenchant.userplaced,cfg.tempenchant.locked)
  118.   end
  119.  
  120.   --create drag frame for buff icons
  121.   local function createBuffFrameHolder()
  122.     local f = CreateFrame("Frame", "rBFS_BuffFrameHolder", UIParent)
  123.     f:SetSize(50,50)
  124.     f:SetPoint(cfg.buffframe.pos.a1,cfg.buffframe.pos.af,cfg.buffframe.pos.a2,cfg.buffframe.pos.x,cfg.buffframe.pos.y)
  125.     applyDragFunctionality(f,cfg.buffframe.userplaced,cfg.buffframe.locked)
  126.   end
  127.  
  128.   --move tempenchant frame
  129.   local function moveTempEnchantFrame()
  130.     local f = _G["rBFS_TempEnchantHolder"]
  131.     TemporaryEnchantFrame:SetParent(f)
  132.     TemporaryEnchantFrame:ClearAllPoints()
  133.     TemporaryEnchantFrame:SetPoint("TOPRIGHT",0,0)
  134.   end
  135.  
  136.   --move buff frame
  137.   local function moveBuffFrame()
  138.     local f = _G["rBFS_BuffFrameHolder"]
  139.     BuffFrame:SetParent(f)
  140.     BuffFrame:ClearAllPoints()
  141.     BuffFrame:SetPoint("TOPRIGHT",0,0)
  142.   end
  143.  
  144.   --apply aura frame texture func
  145.   local function applySkin(b,type)
  146.     if not b or (b and b.styled) then return end
  147.  
  148.     local name = b:GetName()
  149.     --print("applying skin for "..name)
  150.     local border = _G[name.."Border"]
  151.     local icon = _G[name.."Icon"]
  152.  
  153.     if border then
  154.       border:SetTexture(cfg.textures.normal)
  155.       border:SetTexCoord(0,1,0,1)
  156.       border:SetDrawLayer("BACKGROUND",-7)
  157.       if type == "wpn" then
  158.         border:SetVertexColor(0.7,0,1)
  159.       end
  160.       border:ClearAllPoints()
  161.       border:SetAllPoints(b)
  162.       b.Border = border
  163.     else
  164.       --create border (for buff icons)
  165.       local new = b:CreateTexture(nil,"BACKGROUND",nil,-7)
  166.       new:SetAllPoints(b)
  167.       new:SetTexture(cfg.textures.normal)
  168.       new:SetVertexColor(cfg.color.normal.r,cfg.color.normal.g,cfg.color.normal.b)
  169.       b.Border = border
  170.     end
  171.  
  172.     --icon
  173.     icon:SetTexCoord(0.1,0.9,0.1,0.9)
  174.     icon:SetPoint("TOPLEFT", b, "TOPLEFT", 2, -2)
  175.     icon:SetPoint("BOTTOMRIGHT", b, "BOTTOMRIGHT", -2, 2)
  176.     icon:SetDrawLayer("BACKGROUND",-8)
  177.  
  178.     --duration
  179.     b.duration:SetFont(cfg.font, cfg.duration.fontsize, "THINOUTLINE")
  180.     b.duration:ClearAllPoints()
  181.     b.duration:SetPoint(cfg.duration.pos.a1,cfg.duration.pos.x,cfg.duration.pos.y)
  182.  
  183.     --count
  184.     b.count:SetFont(cfg.font, cfg.count.fontsize, "THINOUTLINE")
  185.     b.count:ClearAllPoints()
  186.     b.count:SetPoint(cfg.count.pos.a1,cfg.count.pos.x,cfg.count.pos.y)
  187.  
  188.     --shadow
  189.     if cfg.background.showshadow then
  190.       local back = CreateFrame("Frame", nil, b)
  191.       back:SetPoint("TOPLEFT", b, "TOPLEFT", -4, 4)
  192.       back:SetPoint("BOTTOMRIGHT", b, "BOTTOMRIGHT", 4, -4)
  193.       back:SetFrameLevel(b:GetFrameLevel()-1)
  194.       back:SetBackdrop(backdrop)
  195.       back:SetBackdropBorderColor(cfg.background.shadowcolor.r,cfg.background.shadowcolor.g,cfg.background.shadowcolor.b,cfg.background.shadowcolor.a)
  196.     end
  197.  
  198.     --set button styled variable
  199.     b.styled = true
  200.   end
  201.  
  202.   --update buff anchors
  203.   local function updateBuffAnchors()
  204.     --print(BUFF_ACTUAL_DISPLAY)
  205.     local numBuffs = 0
  206.     local buff, previousBuff, aboveBuff
  207.     for i = 1, BUFF_ACTUAL_DISPLAY do
  208.       buff = _G["BuffButton"..i]
  209.       if not buff.styled then applySkin(buff,"buff") end
  210.       buff:SetParent(BuffFrame)
  211.       buff.consolidated = nil
  212.       buff.parent = BuffFrame
  213.       buff:ClearAllPoints()
  214.       numBuffs = numBuffs + 1
  215.       index = numBuffs
  216.       if ((index > 1) and (mod(index, cfg.buffframe.buffsPerRow) == 1)) then
  217.         buff:SetPoint("TOP", aboveBuff, "BOTTOM", 0, -cfg.buffframe.rowSpacing)
  218.         aboveBuff = buff
  219.       elseif (index == 1) then
  220.         buff:SetPoint("TOPRIGHT", BuffFrame, "TOPRIGHT", 0, 0)
  221.         aboveBuff = buff
  222.       else
  223.         buff:SetPoint("RIGHT", previousBuff, "LEFT", -cfg.buffframe.colSpacing, 0)
  224.       end
  225.       previousBuff = buff
  226.     end
  227.   end
  228.  
  229.   --update debuff anchors
  230.   local function updateDebuffAnchors(buttonName,index)
  231.     local numBuffs = BUFF_ACTUAL_DISPLAY
  232.     local rows = ceil(numBuffs/cfg.buffframe.buffsPerRow)
  233.     local gap = cfg.buffframe.gap
  234.     if rows == 0 then gap = 0 end
  235.     local buff = _G[buttonName..index]
  236.     if not buff.styled then applySkin(buff,"debuff") end
  237.     -- Position debuffs
  238.     if ((index > 1) and (mod(index, cfg.buffframe.buffsPerRow) == 1)) then
  239.       buff:SetPoint("TOP", _G[buttonName..(index-cfg.buffframe.buffsPerRow)], "BOTTOM", 0, -cfg.buffframe.rowSpacing)
  240.     elseif (index == 1) then
  241.       buff:SetPoint("TOPRIGHT", BuffFrame, "TOPRIGHT", 0, -(rows*(cfg.buffframe.rowSpacing+buff:GetHeight())+gap))
  242.     else
  243.       buff:SetPoint("RIGHT", _G[buttonName..(index-1)], "LEFT", -cfg.buffframe.colSpacing, 0)
  244.     end
  245.   end
  246.  
  247.   --create drag frames
  248.   createTempEnchantHolder()
  249.   createBuffFrameHolder()
  250.  
  251.   --init func
  252.   local function init()
  253.     --BuffFrame scale
  254.     BuffFrame:SetScale(cfg.buffframe.scale)
  255.     --temp enchantframe scale
  256.     TemporaryEnchantFrame:SetScale(cfg.tempenchant.scale)
  257.     --position buff frame
  258.     moveBuffFrame()
  259.     --position temp enchant icons
  260.     moveTempEnchantFrame()
  261.     --skin temp enchant
  262.     for i=1, NUM_TEMP_ENCHANT_FRAMES do
  263.       local b = _G["TempEnchant"..i]
  264.       if b and not b.styled then
  265.         applySkin(b, "wpn")
  266.       end
  267.     end
  268.     --move temp enchant icons in position
  269.     updateTempEnchantAnchors()
  270.     --hook the consolidatedbuffs
  271.     if ConsolidatedBuffs then
  272.       ConsolidatedBuffs:UnregisterAllEvents()
  273.       ConsolidatedBuffs:HookScript("OnShow", function(s)
  274.         s:Hide()
  275.         moveTempEnchantFrame()
  276.       end)
  277.       ConsolidatedBuffs:HookScript("OnHide", function(s)
  278.         moveTempEnchantFrame()
  279.       end)
  280.       ConsolidatedBuffs:Hide()
  281.     end
  282.   end
  283.  
  284.   ---------------------------------------
  285.   -- CALLS // HOOKS
  286.   ---------------------------------------
  287.  
  288.   --hook Blizzard functions to move the buffframe
  289.   hooksecurefunc("BuffFrame_UpdateAllBuffAnchors",    updateBuffAnchors)
  290.   hooksecurefunc("DebuffButton_UpdateAnchors",        updateDebuffAnchors)
  291.  
  292.   local a = CreateFrame("Frame")
  293.   a:RegisterEvent("PLAYER_LOGIN")
  294.   a:SetScript("OnEvent", init)