annotate Modules/BuffFrame.lua @ 62:ef4116179e2f v7.0.3-1

- cleaned up old file structure remnants
author Nenue
date Tue, 16 Aug 2016 08:37:07 -0400
parents 3f083d389c18
children ba9c13261bb2
rev   line source
Nenue@59 1 -- Veneer
Nenue@59 2 -- BuffFrame.lua
Nenue@59 3 -- Created: 7/27/2016 8:08 PM
Nenue@59 4 -- %file-revision%
Nenue@62 5 --[[
Nenue@62 6 Adds progress bars and cooldown swirls to buffbutton frames
Nenue@60 7
Nenue@62 8 Known Limitations:
Nenue@62 9 - Individual BuffButton frames are created upon use, making it difficult to do any sort of securestate priming
Nenue@62 10 - TempEnchant info returns relative values only, and they don't synchronize with aura events
Nenue@62 11 - BuffButtons can only be hidden/shown by blizzcode, so functions doing that have to be accounted for
Nenue@62 12 --]]
Nenue@62 13
Nenue@62 14
Nenue@62 15 local plugin = CreateFrame('Frame', 'VeneerBuffFrame', UIParent)
Nenue@59 16 local vn, print = LibStub("LibKraken").register(VeneerController, plugin)
Nenue@59 17
Nenue@59 18
Nenue@59 19 local buttons = {}
Nenue@59 20 local buffTypes = {
Nenue@59 21 {
Nenue@59 22 name = 'buff',
Nenue@59 23 pattern = 'BuffButton(%d)',
Nenue@59 24 filters = 'HELPFUL',
Nenue@59 25 },
Nenue@59 26 {
Nenue@59 27 name = 'debuff',
Nenue@59 28 pattern = 'DebuffButton(%d)',
Nenue@59 29 filters = 'HARMFUL',
Nenue@59 30 },
Nenue@59 31 {
Nenue@59 32 name = 'tempenchant',
Nenue@59 33 pattern = 'TempEnchant(%d)',
Nenue@59 34 filters = 'TEMPENCHANT'
Nenue@59 35 }
Nenue@59 36 }
Nenue@59 37
Nenue@59 38 local textureMapping = {
Nenue@59 39 [1] = 16, --Main hand
Nenue@59 40 [2] = 17, --Off-hand
Nenue@59 41 [3] = 18, --Ranged
Nenue@59 42 }
Nenue@59 43
Nenue@59 44 local tickCounter = {}
Nenue@59 45 local aurasCache = {}
Nenue@59 46 local skinnedFrames = {}
Nenue@59 47 local pendingFrames = {}
Nenue@59 48 local anchors = {}
Nenue@59 49 local expirationCache = {}
Nenue@59 50
Nenue@59 51 local VeneerButton_OnHide = function(self)
Nenue@59 52 self:SetScript('OnDragStart', self.StartMoving)
Nenue@59 53 self:SetScript('OnDragStop', self.StopMovingOrSizing)
Nenue@60 54 self:SetMovable(false)
Nenue@60 55 self:EnableMouse(false)
Nenue@59 56 self:RegisterForDrag('LeftButton')
Nenue@59 57 end
Nenue@59 58 local VeneerButton_OnShow = function(self)
Nenue@59 59 self:SetScript('OnDragStart', self.StartMoving)
Nenue@59 60 self:SetScript('OnDragStop', self.StopMovingOrSizing)
Nenue@60 61 self:SetMovable(false)
Nenue@60 62 self:EnableMouse(false)
Nenue@59 63 self:RegisterForDrag('LeftButton')
Nenue@59 64 end
Nenue@59 65
Nenue@59 66
Nenue@59 67 local GetVeneer = function(frame)
Nenue@59 68 local name = frame:GetName()
Nenue@59 69 if not _G[name..'Veneer'] then
Nenue@59 70
Nenue@59 71 local veneer = CreateFrame('Frame', name..'Veneer', UIParent)
Nenue@60 72 local id = frame:GetID()
Nenue@59 73 veneer:SetAllPoints(frame)
Nenue@60 74 veneer:SetParent(frame)
Nenue@59 75 veneer.bg = veneer:CreateTexture()
Nenue@61 76 veneer.bg:SetColorTexture(1,1,1,0)
Nenue@59 77 veneer.bg:SetAllPoints(veneer)
Nenue@60 78 veneer.bg:Show()
Nenue@59 79 veneer:Hide()
Nenue@60 80 veneer:EnableMouse(false)
Nenue@59 81
Nenue@59 82 veneer:SetScript('OnShow', VeneerButton_OnShow)
Nenue@59 83 veneer:SetScript('OnHide', VeneerButton_OnHide)
Nenue@59 84
Nenue@59 85 local position = tonumber(name:match("%d"))
Nenue@59 86 if position == 1 then
Nenue@59 87 veneer:Show()
Nenue@59 88 end
Nenue@59 89
Nenue@59 90 veneer.progress = CreateFrame('Frame', name .. 'VeneerProgress', veneer)
Nenue@59 91 veneer.progress:Hide()
Nenue@59 92 veneer.progress:SetPoint('BOTTOMLEFT', veneer, 'BOTTOMLEFT', 3, -6)
Nenue@59 93 veneer.progress:SetPoint('TOPRIGHT', veneer, 'BOTTOMRIGHT', -3, -1)
Nenue@59 94
Nenue@59 95 veneer.progress.bg = veneer.progress:CreateTexture(nil, 'BACKGROUND')
Nenue@61 96 veneer.progress.bg:SetColorTexture(0,0,0,1)
Nenue@59 97 veneer.progress.bg:SetAllPoints(veneer.progress)
Nenue@59 98
Nenue@59 99 veneer.progress.fg = veneer.progress:CreateTexture(nil, 'ARTWORK')
Nenue@59 100 veneer.progress.fg:SetColorTexture(0,1,0,1)
Nenue@59 101 veneer.progress.fg:SetPoint('BOTTOMLEFT', 1,1)
Nenue@59 102 veneer.progress.fg:SetPoint('TOP', 0, -1)
Nenue@59 103
Nenue@59 104 veneer.progress.status = veneer.progress:CreateFontString()
Nenue@59 105 veneer.progress.status:SetFontObject(VeneerNumberFont)
Nenue@59 106 veneer.progress.status:SetPoint('TOP')
Nenue@59 107
Nenue@61 108
Nenue@61 109 veneer.cooldown = CreateFrame('Cooldown', name ..'VeneerCooldown', veneer, 'CooldownFrameTemplate')
Nenue@61 110 veneer.cooldown:SetAllPoints(frame)
Nenue@61 111 veneer.cooldown:SetReverse(true)
Nenue@61 112
Nenue@59 113 end
Nenue@59 114
Nenue@59 115
Nenue@59 116 return _G[name..'Veneer']
Nenue@59 117 end
Nenue@59 118
Nenue@61 119 --- Set widgets to reflect the passed parameters
Nenue@59 120 local UpdateVeneer = function (frame, duration, expires)
Nenue@59 121 local veneer = GetVeneer(frame)
Nenue@59 122
Nenue@61 123 if expires and duration then
Nenue@59 124
Nenue@61 125 if duration ~= 0 then
Nenue@61 126 local startTime = (expires - duration)
Nenue@61 127 local endTime = expires or 0
Nenue@61 128 print('|cFF0088FF'..frame:GetName()..'|r', duration, expires)
Nenue@61 129 veneer.progress:Show()
Nenue@61 130 veneer.elapsed = 0
Nenue@61 131 veneer.progress:SetScript('OnUpdate', function(self, elapsed)
Nenue@61 132 veneer.elapsed = veneer.elapsed + elapsed
Nenue@60 133
Nenue@61 134 local w = floor(veneer.progress:GetWidth()+.5)
Nenue@61 135 local t = GetTime()
Nenue@61 136 local progress = (t - startTime) / duration
Nenue@61 137
Nenue@61 138 local nw = (w-2) - ceil(w * progress)
Nenue@61 139 if veneer.elapsed >= 0.25 then
Nenue@61 140
Nenue@61 141 print(progress, nw, w)
Nenue@61 142 veneer.elapsed = 0.25 - veneer.elapsed
Nenue@61 143 end
Nenue@61 144 if (progress >= 1) or not frame:IsVisible() then
Nenue@61 145 veneer.startTime = nil
Nenue@61 146 self:Hide()
Nenue@61 147 self:SetScript('OnUpdate', nil)
Nenue@61 148 else
Nenue@61 149 self.fg:SetWidth(nw)
Nenue@61 150 end
Nenue@61 151 end)
Nenue@61 152
Nenue@61 153 veneer.cooldown:Show()
Nenue@61 154 veneer.cooldown:SetCooldown(startTime, duration)
Nenue@61 155 else
Nenue@61 156 print('|cFF00FF88'..frame:GetName()..'|r', 'duration zero')
Nenue@61 157 veneer.progress:SetScript('OnUpdate', nil)
Nenue@61 158 veneer.progress:Hide()
Nenue@61 159 veneer.cooldown:Hide()
Nenue@61 160 end
Nenue@61 161 else
Nenue@61 162 veneer.progress:Hide()
Nenue@61 163 veneer.cooldown:SetCooldown(0,0)
Nenue@61 164 veneer.cooldown:Hide()
Nenue@61 165 print('|cFF88FF00'..frame:GetName()..'|r', 'nil duration')
Nenue@59 166 end
Nenue@59 167 veneer:Show()
Nenue@59 168 end
Nenue@59 169
Nenue@59 170
Nenue@59 171 -- Associates skinning elements with said button
Nenue@59 172 local SkinFrame = function(name)
Nenue@59 173 local frame = _G[name ]
Nenue@59 174 if skinnedFrames[frame] then
Nenue@59 175 print('|cFFFF4400Attempting to skin a frame that already went through.|r')
Nenue@59 176 return
Nenue@59 177 end
Nenue@59 178
Nenue@59 179 local icon = _G[name .. 'Icon']
Nenue@59 180 local border = _G[name .. 'Border']
Nenue@59 181 local duration = _G[name .. 'Duration']
Nenue@59 182 local slot = frame:GetID() or 0
Nenue@59 183
Nenue@59 184 tickCounter[frame] = (tickCounter[frame] or 0) + 1
Nenue@59 185
Nenue@59 186
Nenue@59 187 print(tickCounter[frame], frame:GetName(), '|cFFFFFF00'..slot..'|r')
Nenue@59 188 skinnedFrames[frame] = frame
Nenue@59 189 frame:SetSize(48,48)
Nenue@59 190 icon:SetTexCoord(0,1,0,1)
Nenue@59 191 if border then
Nenue@59 192 border:SetSize(50,50)
Nenue@59 193 end
Nenue@59 194 if duration then
Nenue@59 195 duration:ClearAllPoints()
Nenue@61 196 duration:SetPoint('TOP', frame, 'BOTTOM', 0, -8)
Nenue@59 197 duration:SetFontObject(VeneerNumberFont)
Nenue@59 198 duration:SetDrawLayer('OVERLAY')
Nenue@59 199
Nenue@59 200 end
Nenue@59 201
Nenue@59 202 GetVeneer(frame)
Nenue@59 203
Nenue@59 204 anchors[frame] = veneer
Nenue@59 205 print('Initializing', name)
Nenue@59 206 end
Nenue@59 207
Nenue@59 208
Nenue@59 209 --- Provides the number of changed indices for use in deciding between partial and full veneer updates
Nenue@59 210 local CacheCheck = function(frame, ...)
Nenue@59 211 aurasCache[frame] = aurasCache[frame] or {}
Nenue@59 212 local hasChange = 0
Nenue@59 213 local numVals = select('#',...)
Nenue@59 214 for i = 1, numVals do
Nenue@59 215 local arg = select(i, ...)
Nenue@59 216 if aurasCache[frame][i] ~= arg then
Nenue@59 217 hasChange = hasChange + 1
Nenue@59 218 end
Nenue@59 219 aurasCache[frame][i] = arg
Nenue@59 220 end
Nenue@59 221 return hasChange
Nenue@59 222 end
Nenue@59 223
Nenue@59 224 local AuraButton_Update = function(name, index, filter)
Nenue@59 225 local bName = name..index
Nenue@59 226 local frame = _G[bName]
Nenue@59 227 if frame and frame:IsVisible() then
Nenue@59 228 tickCounter[frame] = (tickCounter[frame] or 0) + 1
Nenue@59 229 local cacheDiff = CacheCheck(frame, UnitAura(frame.unit, frame:GetID(), frame.filter))
Nenue@61 230 -- if the name or expirationTime changed
Nenue@61 231 if (cacheDiff >= 1) then
Nenue@59 232 print(frame:GetName(), 'diff:', cacheDiff)
Nenue@61 233 if not skinnedFrames[frame] then
Nenue@61 234 tinsert(pendingFrames, frame)
Nenue@61 235 end
Nenue@59 236 expirationCache[name] = frame.expirationTime
Nenue@59 237 print(unpack(aurasCache[frame]))
Nenue@59 238 UpdateVeneer(frame, aurasCache[frame][6], aurasCache[frame][7])
Nenue@59 239 end
Nenue@59 240
Nenue@59 241 -- is it a new button?
Nenue@59 242 if not skinnedFrames[frame] then
Nenue@59 243 SkinFrame(bName)
Nenue@59 244 end
Nenue@59 245 end
Nenue@59 246 end
Nenue@59 247
Nenue@59 248 local BuffFrame_UpdateAllBuffAnchors = function()
Nenue@59 249 local todo = {}
Nenue@59 250 if #pendingFrames >= 1 then
Nenue@59 251
Nenue@59 252 print('|cFFBBFF00AllBuffAnchors|r', #pendingFrames)
Nenue@59 253 while pendingFrames[1] do
Nenue@59 254 local frame = tremove(pendingFrames)
Nenue@59 255 tinsert(todo, frame:GetName())
Nenue@59 256
Nenue@61 257 -- re-apply custom anchors
Nenue@59 258 end
Nenue@59 259 print(table.concat(todo, ', '))
Nenue@59 260 end
Nenue@59 261 --BuffButton1
Nenue@59 262 --DebuffButton1
Nenue@61 263 --todo: separate frame groups and iterate over them at appropriate times
Nenue@60 264 if BuffButton1 then
Nenue@61 265 --TempEnchant1:SetPoint('TOPRIGHT', BuffButton1, 'TOPRIGHT', BuffButton1:GetWidth()+4, 0)
Nenue@60 266 end
Nenue@60 267
Nenue@59 268 end
Nenue@59 269
Nenue@59 270 local AuraButton_UpdateDuration = function(frame, timeLeft)
Nenue@60 271 local hours = floor(timeLeft/3600)
Nenue@60 272 local minutes = floor(mod(timeLeft, 3600)/60)
Nenue@60 273 local seconds = floor(mod(timeLeft, 60))
Nenue@60 274 local timeString = '%ds'
Nenue@59 275 if timeLeft > 3600 then
Nenue@60 276 timeString = format('%d:%02d', hours, minutes)
Nenue@60 277 elseif timeLeft > 60 then
Nenue@60 278 timeString = format('%d:%02d', minutes, seconds)
Nenue@61 279 else
Nenue@60 280 timeString = format('%d', seconds)
Nenue@59 281 end
Nenue@59 282
Nenue@60 283
Nenue@60 284 frame.duration:SetText(timeString)
Nenue@59 285 frame.duration:SetVertexColor(1,1,1)
Nenue@59 286 end
Nenue@59 287
Nenue@59 288 local visibility = {}
Nenue@59 289 local TempEnchantButton_OnHide = function(self)
Nenue@59 290 local isVisible = self:IsVisible()
Nenue@59 291 if isVisible ~= visibility[self] then
Nenue@59 292 print('|cFFFFFF00HIDE|r', self:GetName())
Nenue@59 293 visibility[self] = isVisible
Nenue@59 294 end
Nenue@59 295 end
Nenue@59 296
Nenue@59 297 -- Obtains the first instance of Tenchant use
Nenue@59 298
Nenue@59 299 local TemporaryEnchantFrame_Update = function(...)
Nenue@59 300 local numVals = select('#', ...)
Nenue@59 301 local numItems = numVals / 4
Nenue@59 302 if numItems >= 1 then
Nenue@59 303 for itemIndex = numItems, 1, -1 do
Nenue@59 304 local frame = _G['TempEnchant'..itemIndex]
Nenue@59 305 local hasEnchant, timeRemaining, enchantCharges = select((4 * (itemIndex -1)) + 1, ...)
Nenue@59 306
Nenue@59 307
Nenue@59 308 if hasEnchant then
Nenue@59 309 local endTime = floor(GetTime()*1000) + timeRemaining
Nenue@59 310
Nenue@59 311
Nenue@59 312 --print(endTime)
Nenue@59 313 if endTime ~= expirationCache[frame] then
Nenue@59 314 if expirationCache[frame] then
Nenue@59 315 print(endTime, expirationCache[frame], endTime - expirationCache[frame])
Nenue@59 316 end
Nenue@59 317 expirationCache[frame] = endTime
Nenue@59 318 print('push tempenchant timer update', timeRemaining / 1000, GetTime()+(timeRemaining/1000))
Nenue@59 319 UpdateVeneer(frame, timeRemaining/1000, GetTime()+(timeRemaining/1000))
Nenue@59 320 end
Nenue@59 321 else
Nenue@59 322 GetVeneer(frame):Hide()
Nenue@59 323 end
Nenue@59 324
Nenue@59 325 end
Nenue@59 326
Nenue@59 327 end
Nenue@59 328
Nenue@59 329 end
Nenue@59 330
Nenue@59 331 local BuffFrame_Update = function(...)
Nenue@61 332
Nenue@59 333 end
Nenue@59 334
Nenue@59 335
Nenue@59 336 hooksecurefunc("BuffFrame_Update", BuffFrame_Update)
Nenue@59 337 hooksecurefunc("AuraButton_UpdateDuration", AuraButton_UpdateDuration)
Nenue@59 338 hooksecurefunc("AuraButton_Update", AuraButton_Update)
Nenue@59 339 hooksecurefunc("BuffFrame_UpdateAllBuffAnchors", BuffFrame_UpdateAllBuffAnchors)
Nenue@59 340 hooksecurefunc("TemporaryEnchantFrame_Update", TemporaryEnchantFrame_Update)
Nenue@59 341
Nenue@59 342 -- The TempEnchant frames are hardcoded in the base FrameXML, so get them now
Nenue@59 343 for i = 1, 3 do
Nenue@59 344
Nenue@59 345 SkinFrame('TempEnchant'..i)
Nenue@59 346 hooksecurefunc(_G['TempEnchant'..i], "Hide", TempEnchantButton_OnHide)
Nenue@59 347
Nenue@59 348
Nenue@59 349 end
Nenue@59 350
Nenue@59 351 plugin.init = function ()
Nenue@61 352
Nenue@61 353
Nenue@61 354
Nenue@59 355 plugin.db = vn.db[PLUGIN_NAME]
Nenue@59 356 end