diff Modules/BuffFrame.lua @ 61:3f083d389c18

- don't send updates for BuffAnchors hook
author Nenue
date Mon, 15 Aug 2016 09:35:46 -0400
parents 2a636b00c31e
children ef4116179e2f
line wrap: on
line diff
--- a/Modules/BuffFrame.lua	Mon Aug 15 07:23:56 2016 -0400
+++ b/Modules/BuffFrame.lua	Mon Aug 15 09:35:46 2016 -0400
@@ -2,7 +2,7 @@
 -- BuffFrame.lua
 -- Created: 7/27/2016 8:08 PM
 -- %file-revision%
---
+-- Adds progress bars and cooldown swirls to buffbutton frames
 
 local PLUGIN_NAME = 'BuffFrame'
 local plugin = {}
@@ -66,8 +66,7 @@
     veneer:SetAllPoints(frame)
     veneer:SetParent(frame)
     veneer.bg = veneer:CreateTexture()
-    veneer.bg:SetColorTexture((id / 16),0,1-(id/16),0.5)
-    print(id, id/16)
+    veneer.bg:SetColorTexture(1,1,1,0)
     veneer.bg:SetAllPoints(veneer)
     veneer.bg:Show()
     veneer:Hide()
@@ -87,7 +86,7 @@
     veneer.progress:SetPoint('TOPRIGHT', veneer, 'BOTTOMRIGHT', -3, -1)
 
     veneer.progress.bg = veneer.progress:CreateTexture(nil, 'BACKGROUND')
-    veneer.progress.bg:SetColorTexture(0,0,0,0.5)
+    veneer.progress.bg:SetColorTexture(0,0,0,1)
     veneer.progress.bg:SetAllPoints(veneer.progress)
 
     veneer.progress.fg = veneer.progress:CreateTexture(nil, 'ARTWORK')
@@ -99,40 +98,65 @@
     veneer.progress.status:SetFontObject(VeneerNumberFont)
     veneer.progress.status:SetPoint('TOP')
 
+
+    veneer.cooldown = CreateFrame('Cooldown', name ..'VeneerCooldown', veneer, 'CooldownFrameTemplate')
+    veneer.cooldown:SetAllPoints(frame)
+    veneer.cooldown:SetReverse(true)
+
   end
 
 
   return _G[name..'Veneer']
 end
 
+--- Set widgets to reflect the passed parameters
 local UpdateVeneer = function (frame, duration, expires)
   local veneer = GetVeneer(frame)
 
-  if expires and (duration ~= 0) then
-    veneer.progress:Show()
+  if expires and duration then
 
-    local startTime = (expires - duration)
-    local endTime = expires or 0
-    print('|cFF0088FF'..frame:GetName()..'|r', 'has expiration', startTime, 'to', endTime, 'over', duration, 'frame', veneer.progress:GetWidth())
-    veneer.progress:SetScript('OnUpdate', function(self)
-      local w = floor(veneer.progress:GetWidth()+.5)
-      local t = GetTime()
-      local progress = (t - startTime) / duration
+    if duration ~= 0 then
+      local startTime = (expires - duration)
+      local endTime = expires or 0
+      print('|cFF0088FF'..frame:GetName()..'|r', duration, expires)
+      veneer.progress:Show()
+      veneer.elapsed = 0
+      veneer.progress:SetScript('OnUpdate', function(self, elapsed)
+        veneer.elapsed = veneer.elapsed + elapsed
 
-      local nw = w - ceil(w * progress)
-      print(progress, nw, w)
-      if (progress >= 1) or not frame:IsVisible() then
-        veneer.startTime = nil
-        self:Hide()
-        self:SetScript('OnUpdate', nil)
-      else
-        self.fg:SetWidth(nw)
-      end
-    end)
+        local w = floor(veneer.progress:GetWidth()+.5)
+        local t = GetTime()
+        local progress = (t - startTime) / duration
+
+        local nw = (w-2) - ceil(w * progress)
+        if veneer.elapsed >= 0.25 then
+
+          print(progress, nw, w)
+          veneer.elapsed = 0.25 - veneer.elapsed
+        end
+        if (progress >= 1) or not frame:IsVisible() then
+          veneer.startTime = nil
+          self:Hide()
+          self:SetScript('OnUpdate', nil)
+        else
+          self.fg:SetWidth(nw)
+        end
+      end)
+
+      veneer.cooldown:Show()
+      veneer.cooldown:SetCooldown(startTime, duration)
+    else
+      print('|cFF00FF88'..frame:GetName()..'|r', 'duration zero')
+      veneer.progress:SetScript('OnUpdate', nil)
+      veneer.progress:Hide()
+      veneer.cooldown:Hide()
+    end
+  else
+    veneer.progress:Hide()
+    veneer.cooldown:SetCooldown(0,0)
+    veneer.cooldown:Hide()
+    print('|cFF88FF00'..frame:GetName()..'|r', 'nil duration')
   end
-
-
-
   veneer:Show()
 end
 
@@ -162,7 +186,7 @@
   end
   if duration then
     duration:ClearAllPoints()
-    duration:SetPoint('BOTTOM')
+    duration:SetPoint('TOP', frame, 'BOTTOM', 0, -8)
     duration:SetFontObject(VeneerNumberFont)
     duration:SetDrawLayer('OVERLAY')
 
@@ -196,15 +220,12 @@
   if frame and frame:IsVisible() then
     tickCounter[frame] = (tickCounter[frame] or 0) + 1
     local cacheDiff = CacheCheck(frame, UnitAura(frame.unit, frame:GetID(), frame.filter))
-    -- did something change?
-    if (cacheDiff >= 1) or not skinnedFrames[frame] then
+    -- if the name or expirationTime changed
+    if (cacheDiff >= 1) then
       print(frame:GetName(), 'diff:', cacheDiff)
-      tinsert(pendingFrames, frame)
-    end
-
-
-    if frame.expirationTime ~= expirationCache[name] then
-      print('|cFFBBFF00expirationTime|r', name, frame.expirationTime)
+      if not skinnedFrames[frame] then
+        tinsert(pendingFrames, frame)
+      end
       expirationCache[name] = frame.expirationTime
       print(unpack(aurasCache[frame]))
       UpdateVeneer(frame, aurasCache[frame][6], aurasCache[frame][7])
@@ -226,16 +247,15 @@
       local frame = tremove(pendingFrames)
       tinsert(todo, frame:GetName())
 
-      UpdateVeneer(frame)
-
-
+      -- re-apply custom anchors
     end
     print(table.concat(todo, ', '))
   end
   --BuffButton1
   --DebuffButton1
+  --todo: separate frame groups and iterate over them at appropriate times
   if BuffButton1 then
-    TempEnchant1:SetPoint('TOPRIGHT', BuffButton1, 'TOPRIGHT', BuffButton1:GetWidth()+4, 0)
+    --TempEnchant1:SetPoint('TOPRIGHT', BuffButton1, 'TOPRIGHT', BuffButton1:GetWidth()+4, 0)
   end
 
 end
@@ -249,16 +269,13 @@
     timeString = format('%d:%02d', hours, minutes)
   elseif timeLeft > 60 then
     timeString = format('%d:%02d', minutes, seconds)
-  elseif timeLeft > 10 then
+  else
     timeString = format('%d', seconds)
-  else
-    timeString = format('%0.1f', mod(timeLeft, 60))
   end
 
 
   frame.duration:SetText(timeString)
   frame.duration:SetVertexColor(1,1,1)
-
 end
 
 local visibility = {}
@@ -305,7 +322,7 @@
 end
 
 local BuffFrame_Update = function(...)
-  --print('Time for udpate!', ...)
+
 end
 
 
@@ -325,5 +342,8 @@
 end
 
 plugin.init = function ()
+
+
+
   plugin.db = vn.db[PLUGIN_NAME]
 end
\ No newline at end of file