annotate Modules/BuffFrame.lua @ 128:799ec6dce9c3

- use BagBrother for inventory items, fixes bank stuff not being counted
author Nenue
date Thu, 19 Oct 2017 10:39:04 -0400
parents ea2c616a3b4f
children 414e37af1b1b
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@75 14 local BUFFS_PER_ROW = 12
Nenue@64 15 local BUFF_BUTTON_SIZE = 48
Nenue@86 16 local BUFF_BUTTON_SPACING_H = 5
Nenue@71 17 local BUFF_BUTTON_SPACING_V = 14
Nenue@64 18 local BUFF_PROGRESS_SIZE = 4
Nenue@86 19 local BUFF_PROGRESS_INSET = 2
Nenue@86 20 local PROGRESS_ANCHOR = 'BOTTOM'
Nenue@86 21 local PROGRESS_PARENT
Nenue@86 22 local PROGRESS_OFFSET = 1
Nenue@106 23 local BUFF_MAX_DISPLAY = 24
Nenue@106 24 local DEBUFF_MAX_DISPLAY = 12
Nenue@86 25
Nenue@68 26 local BUFF_BUTTON_ZOOM = .15
Nenue@86 27 local BORDER_SIZE_L = 2
Nenue@86 28 local BORDER_SIZE_R = 2
Nenue@86 29 local BORDER_SIZE_U = 2
Nenue@86 30 local BORDER_SIZE_D = 2
Nenue@75 31 local BUFF_FRAMES_X = -230
Nenue@75 32 local BUFF_FRAMES_Y = -4
Nenue@64 33
Nenue@86 34 local COUNT_ANCHOR = 'TOPRIGHT'
Nenue@86 35 local COUNT_INSET = 4
Nenue@86 36 local COUNT_PARENT
Nenue@86 37
Nenue@86 38 local DURATION_ANCHOR = 'BOTTOMLEFT'
Nenue@97 39 local DURATION_INSET = 1
Nenue@86 40 local DURATION_PARENT
Nenue@86 41
Nenue@84 42 VeneerBuffFrameMixin = {
Nenue@84 43 moduleName = 'Buff Frames',
Nenue@115 44 anchorPoint = 'TOPRIGHT',
Nenue@90 45 anchorX = BUFF_FRAMES_X,
Nenue@90 46 anchorY = BUFF_FRAMES_Y,
Nenue@115 47
Nenue@84 48 Buttons = {},
Nenue@84 49 DetectedFrames = {},
Nenue@121 50 AuraCache = {},
Nenue@121 51 ValueMasks = {}
Nenue@84 52 }
Nenue@94 53 VeneerBuffFrameButtonMixin = {}
Nenue@94 54 local Facade = VeneerBuffFrameButtonMixin
Nenue@84 55 local plugin = VeneerBuffFrameMixin
Nenue@62 56
Nenue@84 57 local vn = Veneer
Nenue@84 58 local print = DEVIAN_WORKSPACE and function(...) _G.print('BuffFrame', ...) end or function() end
Nenue@68 59 local tprint = DEVIAN_WORKSPACE and function(...) _G.print('Timer', ...) end or function() end
Nenue@59 60
Nenue@68 61 local _G, UIParent = _G, UIParent
Nenue@68 62 local tinsert, tremove, unpack, select, tconcat = table.insert, table.remove, unpack, select, table.concat
Nenue@68 63 local floor, tonumber, format = math.floor, tonumber, string.format
Nenue@68 64 local UnitAura, GetTime, CreateFrame = UnitAura, GetTime, CreateFrame
Nenue@68 65 local hooksecurefunc = hooksecurefunc
Nenue@59 66
Nenue@75 67 local aurasCache = {}
Nenue@75 68 local skinnedFrames = {}
Nenue@75 69 local pendingFrames = {}
Nenue@75 70 local veneers = {}
Nenue@75 71 local expirationCache = {}
Nenue@75 72 local visibility = {}
Nenue@75 73 local isHooked = {}
Nenue@121 74 local valueMasks
Nenue@75 75
Nenue@75 76 plugin.options = {
Nenue@75 77 nameString = 'Buff Frames',
Nenue@59 78 {
Nenue@75 79 name = 'BuffButtonZoom',
Nenue@75 80 type = 'slider',
Nenue@75 81 min = 0,
Nenue@75 82 max = 100,
Nenue@75 83 fullwidth = true,
Nenue@59 84 },
Nenue@59 85 {
Nenue@75 86 name = 'BuffBorderLeft',
Nenue@75 87 type = 'slider',
Nenue@75 88 min = 0,
Nenue@75 89 max = 16,
Nenue@59 90 },
Nenue@59 91 {
Nenue@75 92 name = 'BuffBorderLeft',
Nenue@75 93 type = 'slider',
Nenue@75 94 min = 0,
Nenue@75 95 max = 16,
Nenue@59 96 }
Nenue@59 97 }
Nenue@59 98
Nenue@86 99 local OFFSET_PARALLELS = {
Nenue@86 100 TOP = {'LEFT', 'RIGHT', 'SetHeight'},
Nenue@86 101 BOTTOM = {'LEFT', 'RIGHT', 'SetHeight'},
Nenue@86 102 LEFT = {'TOP', 'BOTTOM', 'SetWidth'},
Nenue@86 103 RIGHT = {'TOP', 'BOTTOM', 'SetWidth'},
Nenue@86 104 }
Nenue@86 105 local ANCHOR_OFFSET_POINT = {
Nenue@86 106 TOP = 'BOTTOM',
Nenue@86 107 TOPLEFT = 'BOTTOMRIGHT',
Nenue@86 108 TOPRIGHT = 'BOTTOMLEFT',
Nenue@86 109 LEFT = 'RIGHT',
Nenue@86 110 RIGHT = 'LEFT',
Nenue@86 111 CENTER = 'CENTER',
Nenue@86 112 BOTTOM = 'TOP',
Nenue@86 113 BOTTOMRIGHT = 'TOPLEFT',
Nenue@86 114 BOTTOMLEFT = 'TOPRIGHT',
Nenue@86 115 }
Nenue@86 116 local ANCHOR_INSET_DELTA = {
Nenue@86 117 TOP = {0, -1},
Nenue@86 118 TOPLEFT = {1, -1},
Nenue@86 119 TOPRIGHT = {-1,-1},
Nenue@86 120 LEFT = {1, 0},
Nenue@86 121 BOTTOMLEFT = {1, 1},
Nenue@86 122 BOTTOM = {0, 1},
Nenue@86 123 BOTTOMRIGHT = {-1, 1},
Nenue@86 124 RIGHT = {-1, 0},
Nenue@86 125 CENTER = {0, 0},
Nenue@86 126 }
Nenue@59 127
Nenue@90 128 -- Associates skinning elements with said button
Nenue@90 129 local surrogates = {
Nenue@90 130 ['Show'] = false,
Nenue@90 131 ['Hide'] = false,
Nenue@90 132 ['SetText'] = false,
Nenue@90 133 ['SetVertexColor'] = function(self, region, r, g, b, a)
Nenue@90 134 if not self.progress then
Nenue@90 135 return
Nenue@90 136 end
Nenue@90 137
Nenue@90 138 region:Hide()
Nenue@93 139 --tprint('|cFF0088FFborder:SetVertexColor|r', r,g,b,a)
Nenue@90 140 self.progress.fg:SetColorTexture(r,g,b,a)
Nenue@90 141 self.border:SetColorTexture(r,g,b,a)
Nenue@90 142 self.border:Show()
Nenue@90 143 end,
Nenue@90 144 }
Nenue@90 145 local DoRegionHooks = function (veneer, region)
Nenue@90 146
Nenue@90 147 if region then
Nenue@90 148 --print('hooking', region:GetName())
Nenue@90 149 region:ClearAllPoints()
Nenue@90 150 for method, callback in pairs(surrogates) do
Nenue@90 151 if type(region[method]) == 'function' then
Nenue@90 152
Nenue@90 153 --print(method, type(callback))
Nenue@90 154 local func
Nenue@90 155 if callback then
Nenue@90 156 hooksecurefunc(region, method, function(self, ...)
Nenue@90 157 --tprint('|cFF00FFFF'.. region:GetName().. ':', method)
Nenue@90 158 region:ClearAllPoints()
Nenue@90 159 callback(veneer, region, ...)
Nenue@90 160 end)
Nenue@90 161 else
Nenue@90 162 hooksecurefunc(region, method, function(self,...)
Nenue@93 163 --tprint('|cFF0088FF'.. self:GetName().. ':', method)
Nenue@90 164 self:ClearAllPoints()
Nenue@90 165 veneer:Show()
Nenue@90 166 veneer[method](veneer, ...)
Nenue@90 167
Nenue@90 168 if self:GetName():match('Debuff.+Count') then
Nenue@90 169
Nenue@93 170 --print('|cFF00FFFF'.. self:GetName().. ':'.. method, '->', veneer:GetName()..':'..method..'(', ...,')')
Nenue@93 171 --print(veneer:IsVisible(),veneer:GetStringWidth(),veneer:GetText())
Nenue@93 172 --print(veneer:GetTop(), veneer:GetLeft())
Nenue@93 173 --print(veneer:GetPoint(1))
Nenue@90 174 end
Nenue@90 175
Nenue@90 176 end)
Nenue@90 177 end
Nenue@90 178 end
Nenue@90 179 end
Nenue@90 180 end
Nenue@90 181 end
Nenue@75 182
Nenue@93 183
Nenue@94 184
Nenue@94 185 function Facade:OnShow()
Nenue@95 186 print(self:GetName(), 'OnShow')
Nenue@94 187 self.underlay:Show()
Nenue@94 188 end
Nenue@94 189 function Facade:OnHide()
Nenue@95 190
Nenue@95 191 print(self:GetName(), 'OnHide')
Nenue@94 192 self.underlay:Hide()
Nenue@95 193
Nenue@94 194 end
Nenue@94 195
Nenue@94 196 function Facade:OnLoad()
Nenue@94 197
Nenue@94 198 self.duration = self.progress.duration
Nenue@94 199 self.count = self.overlay.count
Nenue@94 200 self.border = self.underlay.bg
Nenue@94 201
Nenue@94 202 VeneerBuffFrame.ConfigLayers = VeneerBuffFrame.ConfigLayers or {}
Nenue@94 203 self.configIndex = #VeneerBuffFrame.ConfigLayers
Nenue@94 204 for i, region in ipairs(self.ConfigLayers) do
Nenue@94 205 tinsert(VeneerBuffFrame.ConfigLayers, region)
Nenue@94 206 end
Nenue@94 207
Nenue@94 208 self.configIndexEnd = #VeneerBuffFrame.ConfigLayers
Nenue@94 209 end
Nenue@94 210
Nenue@94 211 function Facade:Setup()
Nenue@94 212 self:SetSize(BUFF_BUTTON_SIZE,BUFF_BUTTON_SIZE)
Nenue@94 213
Nenue@94 214 self.progress[OFFSET_PARALLELS[PROGRESS_ANCHOR][3]](self.progress, BUFF_PROGRESS_SIZE + (BUFF_PROGRESS_INSET * 2))
Nenue@94 215 --print(BUFF_PROGRESS_SIZE + (BUFF_PROGRESS_INSET * 2))
Nenue@94 216
Nenue@94 217 self.progress:ClearAllPoints()
Nenue@94 218 self.progress:SetPoint(ANCHOR_OFFSET_POINT[PROGRESS_ANCHOR], PROGRESS_PARENT or self.border, PROGRESS_ANCHOR,
Nenue@94 219 (ANCHOR_INSET_DELTA[PROGRESS_ANCHOR][1] * PROGRESS_OFFSET * -1),
Nenue@94 220 (ANCHOR_INSET_DELTA[PROGRESS_ANCHOR][2] * PROGRESS_OFFSET * -1))
Nenue@94 221 self.progress:SetPoint(OFFSET_PARALLELS[PROGRESS_ANCHOR][1], self.border, OFFSET_PARALLELS[PROGRESS_ANCHOR][1], 0, 0)
Nenue@94 222 self.progress:SetPoint(OFFSET_PARALLELS[PROGRESS_ANCHOR][2], self.border, OFFSET_PARALLELS[PROGRESS_ANCHOR][2], 0, 0)
Nenue@94 223
Nenue@94 224 --print(self.progress:GetPoint(1))
Nenue@94 225 --print(self.progress:GetPoint(2))
Nenue@94 226 --print(self.progress:GetPoint(3))
Nenue@94 227 self.progress:Show()
Nenue@94 228
Nenue@94 229 self.progress.bg:ClearAllPoints()
Nenue@94 230 self.progress.bg:SetAllPoints(self.progress)
Nenue@94 231
Nenue@94 232 self.progress.fg:ClearAllPoints()
Nenue@94 233 self.progress.fg:SetPoint('BOTTOMLEFT', BUFF_PROGRESS_INSET,BUFF_PROGRESS_INSET)
Nenue@94 234 self.progress.fg:SetPoint('TOP', 0, -BUFF_PROGRESS_INSET)
Nenue@94 235 --self.count:ClearAllPoints()
Nenue@94 236 --self.count:SetPoint('TOPRIGHT', self,'TOPRIGHT', -3, -3)
Nenue@94 237
Nenue@94 238
Nenue@94 239 self.duration:ClearAllPoints()
Nenue@94 240 self.duration:SetPoint(DURATION_ANCHOR, DURATION_PARENT or self, DURATION_ANCHOR,
Nenue@94 241 (ANCHOR_INSET_DELTA[DURATION_ANCHOR][1] * DURATION_INSET),
Nenue@94 242 (ANCHOR_INSET_DELTA[DURATION_ANCHOR][2] * DURATION_INSET))
Nenue@94 243
Nenue@94 244 self.count:ClearAllPoints()
Nenue@94 245 self.count:SetPoint(COUNT_ANCHOR, COUNT_PARENT or self, COUNT_ANCHOR,
Nenue@94 246 (ANCHOR_INSET_DELTA[COUNT_ANCHOR][1] * COUNT_INSET),
Nenue@94 247 (ANCHOR_INSET_DELTA[COUNT_ANCHOR][2] * COUNT_INSET))
Nenue@94 248
Nenue@95 249 self.underlay:SetParent(UIParent)
Nenue@95 250
Nenue@94 251 self.underlay:SetFrameStrata('BACKGROUND')
Nenue@94 252 self.border:SetColorTexture(0,0,0,1)
Nenue@94 253 self.border:SetPoint('TOPLEFT', self, 'TOPLEFT', -BORDER_SIZE_L, BORDER_SIZE_U)
Nenue@94 254 self.border:SetPoint('BOTTOMRIGHT', self, 'BOTTOMRIGHT', BORDER_SIZE_R, -BORDER_SIZE_D)
Nenue@94 255 self.border:Show()
Nenue@95 256
Nenue@96 257 -- play nice with Blizzard's frame locking structure
Nenue@96 258 FRAMELOCK_STATES.PETBATTLES[self:GetName()] = "hidden"
Nenue@95 259 FRAMELOCK_STATES.PETBATTLES[self.underlay:GetName()] = "hidden"
Nenue@94 260 end
Nenue@94 261
Nenue@106 262 plugin.defaultSettings = {
Nenue@106 263 width = 48,
Nenue@106 264 height = 48,
Nenue@106 265 }
Nenue@106 266
Nenue@94 267 function plugin:AcquireConfigButton(name)
Nenue@94 268 print('|cFF88FF00Creating config dummy', name,'Veneer')
Nenue@94 269 local button = self.Buttons[name]
Nenue@94 270 if not button then
Nenue@94 271 button = CreateFrame('Frame', name .. 'Veneer', self, 'VeneerBuffTemplate')
Nenue@94 272 button:Setup()
Nenue@94 273 button:SetShown(true)
Nenue@94 274 self.Buttons[name] = button
Nenue@94 275 end
Nenue@94 276 return button
Nenue@94 277 end
Nenue@94 278
Nenue@94 279 function plugin:Acquire(name)
Nenue@94 280 local frame = self.Buttons[name]
Nenue@94 281 if not frame then
Nenue@94 282 local target = _G[name]
Nenue@84 283 local id = target:GetID()
Nenue@94 284 print('|cFF88FF00Creating', name .. 'Veneer')
Nenue@93 285 frame = vn:Acquire(target, 'VeneerBuffTemplate')
Nenue@94 286 frame:Setup()
Nenue@94 287 self.Buttons[name] = frame
Nenue@59 288 end
Nenue@84 289 return frame
Nenue@59 290 end
Nenue@59 291
Nenue@94 292 function plugin:OnLoad()
Nenue@115 293 print(self:GetName(), 'OnLoad()')
Nenue@115 294 Veneer:AddHandler(self)
Nenue@84 295 end
Nenue@68 296
Nenue@94 297 function plugin:Setup()
Nenue@115 298 print(self:GetName(), 'Setup()')
Nenue@84 299 hooksecurefunc("BuffFrame_Update", function(...) self:OnBuffFrameUpdate(...) end)
Nenue@97 300 hooksecurefunc("AuraButton_UpdateDuration", function(...) self:OnUpdateDuration(...) end)
Nenue@84 301 hooksecurefunc("AuraButton_Update", function(...) self:OnAuraButton_Update(...) end)
Nenue@84 302 hooksecurefunc("BuffFrame_UpdateAllBuffAnchors", function(...) self:OnUpdateAllBuffAnchors(...) end)
Nenue@84 303 hooksecurefunc("TemporaryEnchantFrame_Update", function(...) self:OnTemporaryEnchantFrameUpdate(...) end)
Nenue@84 304 for i = 1, 3 do
Nenue@84 305 self:SetupButton('TempEnchant'..i)
Nenue@84 306 _G['TempEnchant'..i..'Border']:SetVertexColor(0.5,0,1,1)
Nenue@84 307 end
Nenue@121 308
Nenue@121 309 VeneerData.BuffFrame = VeneerData.BuffFrame or {}
Nenue@121 310 VeneerData.BuffFrame.ValueMasks = VeneerData.BuffFrame.ValueMasks or {}
Nenue@121 311 valueMasks = VeneerData.BuffFrame.ValueMasks
Nenue@84 312 end
Nenue@86 313
Nenue@94 314 function plugin:SetHidden(region)
Nenue@93 315 if not self.hiddenRegions[region] then
Nenue@93 316 self.hiddenRegions[region] = true
Nenue@93 317 region:SetShown(false)
Nenue@121 318
Nenue@121 319 end
Nenue@121 320 end
Nenue@121 321
Nenue@121 322 local lastAuditName = ''
Nenue@121 323 local lastAuditIndex = ''
Nenue@121 324 local Audit_OnClick = function(self)
Nenue@121 325
Nenue@121 326 local facade = self:GetParent()
Nenue@121 327 local index = self.index
Nenue@121 328 local name = facade.buffName
Nenue@121 329 if name then
Nenue@121 330 DEFAULT_CHAT_FRAME:AddMessage('|cFF00FFFFVeneer|r: Hiding |cFF00FF88'..name..' value'..index..'|r, type /vn buffs reset to undo.')
Nenue@121 331 valueMasks[name] = valueMasks[name] or {}
Nenue@121 332 valueMasks[name][index] = false
Nenue@121 333 print('AuditClick', name, index, false)
Nenue@93 334 end
Nenue@93 335 end
Nenue@84 336
Nenue@94 337 function plugin:SetupButton (name)
Nenue@94 338 local frame = _G[name]
Nenue@95 339 print('|cFFFFFF00Adopting', name)
Nenue@68 340
Nenue@68 341 local icon = _G[name .. 'Icon']
Nenue@68 342 local border = _G[name .. 'Border']
Nenue@68 343 local count = _G[name .. 'Count']
Nenue@68 344 local duration = _G[name .. 'Duration']
Nenue@106 345 local facade = self:Acquire(name)
Nenue@84 346 local offset = BUFF_BUTTON_ZOOM/2
Nenue@68 347
Nenue@84 348 self.DetectedFrames[frame] = frame
Nenue@68 349 frame:SetSize(BUFF_BUTTON_SIZE,BUFF_BUTTON_SIZE)
Nenue@84 350 icon:SetTexCoord(offset, 1 - offset, offset, 1 - offset)
Nenue@68 351
Nenue@78 352
Nenue@106 353 DoRegionHooks(facade, border)
Nenue@68 354 if border then
Nenue@68 355 local color = DebuffTypeColor["none"]
Nenue@68 356 if aurasCache[frame] and aurasCache[frame][5] then
Nenue@68 357 color = DebuffTypeColor[aurasCache[frame][5]]
Nenue@68 358 end
Nenue@106 359 facade.progress.fg:SetColorTexture(color.r,color.g,color.b)
Nenue@106 360 facade.border:SetColorTexture(0,0,0,1)
Nenue@106 361 facade.border:Show()
Nenue@79 362 else
Nenue@106 363 facade.border:SetColorTexture(0,0,0,1)
Nenue@106 364 facade.border:Show()
Nenue@68 365 end
Nenue@68 366
Nenue@93 367 if count then
Nenue@86 368 count:ClearAllPoints()
Nenue@93 369 hooksecurefunc(count, 'Show', function(self) self:Hide() end)
Nenue@93 370 if count:GetText() then
Nenue@106 371 facade.count:SetText(count:GetText())
Nenue@93 372 end
Nenue@86 373 end
Nenue@86 374 if duration then
Nenue@86 375 duration:ClearAllPoints()
Nenue@86 376 end
Nenue@86 377
Nenue@95 378 hooksecurefunc(frame, "Hide", function(frame)
Nenue@106 379 facade:Hide()
Nenue@68 380 end)
Nenue@68 381
Nenue@95 382 hooksecurefunc(frame, 'Show', function(frame)
Nenue@106 383 facade:Show()
Nenue@68 384 end)
Nenue@68 385
Nenue@95 386 hooksecurefunc(frame, 'SetShown', function(frame, isShown)
Nenue@106 387 facade:SetShown(isShown)
Nenue@95 388 end)
Nenue@95 389
Nenue@121 390 facade.Audit = facade.Audit or {}
Nenue@121 391 for i = 1, 3 do
Nenue@121 392 local button = CreateFrame('Button', nil, facade, 'VeneerBuffAuditTemplate')
Nenue@121 393 button.index = i
Nenue@121 394 button:RegisterForClicks('AnyUp')
Nenue@121 395 button:SetScript('OnClick', Audit_OnClick)
Nenue@122 396 button:SetScript('OnEvent', Audit_OnEvent)
Nenue@122 397 button:RegisterEvent('POWER_REGEN_ENABLED')
Nenue@121 398 button:SetPoint('TOPLEFT', 0, (i-1) * 16 * -1)
Nenue@121 399 facade.Audit[i] = button
Nenue@121 400 end
Nenue@121 401
Nenue@106 402 facade.IsAcquired = true
Nenue@106 403 facade:SetParent(UIParent)
Nenue@106 404 facade:SetAllPoints(frame)
Nenue@106 405 facade:SetFrameStrata('MEDIUM')
Nenue@68 406 end
Nenue@68 407
Nenue@68 408
Nenue@61 409 --- Set widgets to reflect the passed parameters
Nenue@121 410 local values = {}
Nenue@94 411 function plugin:UpdateButton (name, duration, expires)
Nenue@94 412 local frame = _G[name]
Nenue@106 413 local facade = self:Acquire(name)
Nenue@68 414 -- is it a new button?
Nenue@84 415 if not self.DetectedFrames[frame] then
Nenue@94 416 print('|cFFFF4400detected', name)
Nenue@94 417 self:SetupButton(name)
Nenue@68 418 end
Nenue@86 419 --[[
Nenue@86 420 if frame.count then
Nenue@86 421 frame.count:SetText('test')
Nenue@86 422 frame.count:Show()
Nenue@86 423 end
Nick@108 424 --]]
Nick@108 425
Nick@108 426 local name, rank, icon, count, dispelType, duration, expires, caster, isStealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, _, nameplateShowAll, timeMod, value1, value2, value3 = UnitAura(frame.unit, frame:GetID(), frame.filter)
Nenue@121 427 values[1] = value1
Nenue@121 428 values[2] = value2
Nenue@121 429 values[3] = value3
Nick@108 430
Nenue@121 431 facade.buffName = name
Nenue@59 432
Nenue@61 433 if expires and duration then
Nenue@61 434 if duration ~= 0 then
Nenue@61 435 local startTime = (expires - duration)
Nenue@61 436 local endTime = expires or 0
Nenue@61 437 print('|cFF0088FF'..frame:GetName()..'|r', duration, expires)
Nenue@106 438 facade.progress:Show()
Nenue@106 439 facade.elapsed = 0
Nenue@106 440 facade.progress:SetScript('OnUpdate', function(self, elapsed)
Nenue@106 441 facade.elapsed = facade.elapsed + elapsed
Nenue@60 442
Nenue@106 443 local w = floor(facade.progress:GetWidth()+.5) - (BUFF_PROGRESS_INSET*2)
Nenue@61 444 local t = GetTime()
Nenue@61 445 local progress = (t - startTime) / duration
Nenue@61 446
Nenue@67 447 local nw = (w - (w * progress))
Nenue@106 448 if facade.elapsed >= 0.25 then
Nenue@61 449
Nenue@93 450 --tprint(t, startTime, floor(progress*100), w * progress, nw, w)
Nenue@106 451 facade.elapsed = 0.25 - facade.elapsed
Nenue@61 452 end
Nenue@61 453 if (progress >= 1) or not frame:IsVisible() then
Nenue@106 454 facade.startTime = nil
Nenue@61 455 self:Hide()
Nenue@61 456 self:SetScript('OnUpdate', nil)
Nenue@61 457 else
Nenue@61 458 self.fg:SetWidth(nw)
Nenue@61 459 end
Nick@108 460
Nick@108 461
Nenue@61 462 end)
Nenue@61 463
Nenue@121 464 --facade.cooldown:Show()
Nenue@121 465 --facade.cooldown:SetCooldown(startTime, duration)
Nenue@61 466 else
Nenue@61 467 print('|cFF00FF88'..frame:GetName()..'|r', 'duration zero')
Nenue@106 468 facade.progress:SetScript('OnUpdate', nil)
Nenue@106 469 facade.progress:Hide()
Nenue@121 470 --facade.cooldown:Hide()
Nenue@61 471 end
Nenue@86 472
Nenue@90 473 if count and count > 1 then
Nenue@106 474 facade.count:SetText(count)
Nenue@106 475 facade.count:Show()
Nenue@90 476 frame.count:ClearAllPoints()
Nenue@86 477 else
Nenue@106 478 facade.count:Hide()
Nenue@86 479 end
Nenue@86 480
Nenue@121 481 for i, button in ipairs(facade.Audit) do
Nenue@121 482 local isShown = (values[i] and true)
Nenue@121 483 if valueMasks[name] and valueMasks[name][i] ~= nil then
Nenue@121 484 print(':: use value mask', name, i)
Nenue@121 485 isShown = (values[i] == 1) and true or false
Nenue@121 486 end
Nenue@86 487
Nenue@121 488 facade.Audit[i]:SetShown(isShown)
Nenue@121 489 facade.Audit[i].Value:SetText(values[i])
Nenue@121 490 end
Nenue@121 491
Nick@110 492
Nenue@61 493 else
Nenue@106 494 facade.progress:Hide()
Nenue@121 495 --facade.cooldown:SetCooldown(0,0)
Nenue@121 496 --facade.cooldown:Hide()
Nenue@61 497 print('|cFF88FF00'..frame:GetName()..'|r', 'nil duration')
Nenue@59 498 end
Nenue@106 499 facade:Show()
Nenue@59 500 end
Nenue@59 501
Nenue@59 502
Nenue@59 503 --- Provides the number of changed indices for use in deciding between partial and full veneer updates
Nenue@94 504 function plugin:ButtonHasChanged (frame, ...)
Nenue@59 505 aurasCache[frame] = aurasCache[frame] or {}
Nenue@59 506 local hasChange = 0
Nenue@59 507 local numVals = select('#',...)
Nenue@59 508 for i = 1, numVals do
Nenue@59 509 local arg = select(i, ...)
Nenue@59 510 if aurasCache[frame][i] ~= arg then
Nenue@59 511 hasChange = hasChange + 1
Nenue@59 512 end
Nenue@59 513 aurasCache[frame][i] = arg
Nenue@59 514 end
Nenue@59 515 return hasChange
Nenue@59 516 end
Nenue@59 517
Nenue@94 518 function plugin:OnAuraButton_Update (name, index, filter)
Nenue@59 519 local bName = name..index
Nenue@59 520 local frame = _G[bName]
Nick@110 521 if frame and frame:IsShown() then
Nenue@61 522 -- if the name or expirationTime changed
Nenue@86 523
Nenue@94 524 if not skinnedFrames[bName] then
Nenue@94 525 tinsert(pendingFrames, bName)
Nenue@61 526 end
Nenue@59 527 expirationCache[name] = frame.expirationTime
Nenue@94 528 self:UpdateButton(bName)
Nenue@68 529
Nenue@59 530
Nenue@59 531 end
Nenue@59 532 end
Nenue@59 533
Nenue@94 534 function plugin:OnUpdateAllBuffAnchors ()
Nenue@59 535
Nenue@59 536 --BuffButton1
Nenue@59 537 --DebuffButton1
Nenue@61 538 --todo: separate frame groups and iterate over them at appropriate times
Nenue@60 539 if BuffButton1 then
Nenue@78 540
Nenue@68 541 TempEnchant1:SetPoint('TOPRIGHT', BuffButton1, 'TOPRIGHT', BuffButton1:GetWidth()+4, 0)
Nenue@60 542 end
Nenue@60 543
Nenue@70 544 local lastBuff, topBuff
Nenue@74 545 local numBuffs = 0
Nenue@90 546 local numColumns = 1
Nenue@90 547 local maxColumn = 1
Nenue@94 548 local limit = self.configMode and BUFF_MAX_DISPLAY or BUFF_ACTUAL_DISPLAY
Nenue@94 549 for i = 1, limit do
Nenue@94 550 local name = 'BuffButton'..i
Nenue@94 551 local buff = _G[name] or self.Buttons[name]
Nenue@106 552 print(i, name, buff)
Nenue@70 553 if buff then
Nenue@74 554 numBuffs = numBuffs + 1
Nenue@74 555 buff:ClearAllPoints()
Nenue@75 556 if mod(numBuffs,BUFFS_PER_ROW) == 1 then
Nenue@74 557 if numBuffs == 1 then
Nenue@80 558 buff:SetPoint('TOPRIGHT', UIParent, 'TOPRIGHT', BUFF_FRAMES_X, BUFF_FRAMES_Y)
Nenue@90 559 plugin.currentTop = buff
Nenue@71 560 else
Nenue@71 561 buff:SetPoint('TOPRIGHT', topBuff, 'BOTTOMRIGHT', 0, -BUFF_BUTTON_SPACING_V)
Nenue@71 562 end
Nenue@90 563 numColumns = 1
Nenue@70 564 topBuff = buff
Nenue@70 565 else
Nenue@71 566 buff:SetPoint('TOPRIGHT', lastBuff, 'TOPLEFT', -BUFF_BUTTON_SPACING_H, 0)
Nenue@90 567 numColumns = numColumns + 1
Nenue@90 568 end
Nenue@90 569 if numColumns > maxColumn then
Nenue@90 570 maxColumn = numColumns
Nenue@90 571 plugin.currentLeft = buff
Nenue@70 572 end
Nenue@70 573 lastBuff = buff
Nenue@70 574 end
Nenue@70 575 end
Nenue@70 576
Nenue@74 577 numBuffs = 0
Nenue@94 578 limit = self.configMode and DEBUFF_MAX_DISPLAY or DEBUFF_ACTUAL_DISPLAY
Nenue@106 579 local lastDebuff
Nenue@106 580 local topDebuff = topBuff
Nenue@106 581 for i = 1, limit do
Nenue@94 582 local name = 'DebuffButton'..i
Nenue@94 583 local debuff = _G[name] or self.Buttons[name]
Nenue@106 584 print(i, name, debuff)
Nenue@70 585 if debuff then
Nenue@74 586 numBuffs = numBuffs + 1
Nenue@93 587 if mod(numBuffs, BUFFS_PER_ROW) == 1 then
Nenue@93 588
Nenue@106 589 if topDebuff then
Nenue@106 590 debuff:SetPoint('TOPRIGHT', topDebuff, 'BOTTOMRIGHT', 0, -BUFF_BUTTON_SPACING_V)
Nenue@93 591 else
Nenue@93 592 debuff:SetPoint('TOPRIGHT', UIParent, 'TOPRIGHT', BUFF_FRAMES_X, BUFF_FRAMES_Y)
Nenue@93 593 end
Nenue@106 594 topDebuff = debuff
Nenue@93 595
Nenue@70 596 else
Nenue@106 597 debuff:SetPoint('TOPRIGHT', lastDebuff, 'TOPLEFT', -BUFF_BUTTON_SPACING_H, 0)
Nenue@70 598 end
Nenue@106 599 lastDebuff = debuff
Nenue@94 600
Nenue@70 601 end
Nenue@70 602 end
Nenue@70 603
Nenue@74 604 if lastBuff then
Nenue@90 605 plugin.currentBottom = lastBuff
Nenue@74 606 end
Nenue@90 607
Nenue@90 608 self.Background:ClearAllPoints()
Nenue@90 609 self.Background:SetPoint('TOPRIGHT', plugin.currentTop, 'TOPRIGHT', 4, 4)
Nenue@90 610 self.Background:SetPoint('BOTTOM', plugin.currentBottom, 'BOTTOM', 0, -4)
Nenue@90 611 self.Background:SetPoint('LEFT', plugin.currentLeft, 'LEFT', -4, 0)
Nenue@59 612 end
Nenue@94 613 function plugin:UpdateConfigLayers (configMode)
Nenue@90 614 self:SetShown(configMode)
Nenue@94 615 self.configMode = configMode
Nenue@94 616 for i = 1, BUFF_MAX_DISPLAY do
Nenue@94 617 local name = 'BuffButton' .. i
Nenue@94 618 local button = self:AcquireConfigButton(name)
Nenue@106 619 if not button.IsAcquired then
Nenue@106 620 button.underlay.bg:SetColorTexture(0,1,0,0.5)
Nenue@106 621 end
Nenue@94 622 end
Nenue@94 623 for i = 1, DEBUFF_MAX_DISPLAY do
Nenue@94 624 local name = 'DebuffButton' .. i
Nenue@94 625 local button = self:AcquireConfigButton(name)
Nenue@106 626 if not button.IsAcquired then
Nenue@106 627 button.underlay.bg:SetColorTexture(1,0,0,0.5)
Nenue@106 628 end
Nenue@93 629 end
Nenue@106 630 self:OnUpdateAllBuffAnchors()
Nenue@90 631 end
Nenue@94 632 function plugin:OnUpdateDuration (frame, timeLeft)
Nenue@97 633 local veneer = self:Acquire(frame:GetName())
Nenue@60 634 local hours = floor(timeLeft/3600)
Nenue@60 635 local minutes = floor(mod(timeLeft, 3600)/60)
Nenue@60 636 local seconds = floor(mod(timeLeft, 60))
Nenue@60 637 local timeString = '%ds'
Nenue@59 638 if timeLeft > 3600 then
Nenue@60 639 timeString = format('%d:%02d', hours, minutes)
Nenue@60 640 elseif timeLeft > 60 then
Nenue@60 641 timeString = format('%d:%02d', minutes, seconds)
Nenue@61 642 else
Nenue@60 643 timeString = format('%d', seconds)
Nenue@59 644 end
Nenue@59 645
Nenue@74 646 if timeLeft < 10 then
Nenue@74 647 if not veneer.duration.getHuge then
Nenue@74 648 veneer.duration.getHuge = true
Nenue@97 649 veneer.duration:SetTextColor(1,.5,0,1)
Nenue@74 650 end
Nenue@74 651 else
Nenue@74 652 if veneer.duration.getHuge then
Nenue@74 653 veneer.duration.getHuge = nil
Nenue@74 654 veneer.duration:SetTextColor(1,1,1,1)
Nenue@74 655 end
Nenue@74 656 end
Nenue@74 657
Nenue@69 658 veneer.duration:SetText(timeString)
Nenue@59 659 end
Nenue@59 660
Nenue@59 661
Nenue@59 662 -- Obtains the first instance of Tenchant use
Nenue@59 663
Nenue@94 664 function plugin:OnTemporaryEnchantFrameUpdate (...)
Nenue@59 665 local numVals = select('#', ...)
Nenue@59 666 local numItems = numVals / 4
Nenue@59 667 if numItems >= 1 then
Nenue@59 668 for itemIndex = numItems, 1, -1 do
Nenue@94 669 local name = 'TempEnchant'..itemIndex
Nenue@94 670 local frame = _G[name]
Nenue@59 671 local hasEnchant, timeRemaining, enchantCharges = select((4 * (itemIndex -1)) + 1, ...)
Nenue@59 672
Nenue@59 673
Nenue@59 674 if hasEnchant then
Nenue@59 675 local endTime = floor(GetTime()*1000) + timeRemaining
Nenue@59 676
Nenue@59 677
Nenue@59 678 --print(endTime)
Nenue@59 679 if endTime ~= expirationCache[frame] then
Nenue@59 680 if expirationCache[frame] then
Nenue@59 681 print(endTime, expirationCache[frame], endTime - expirationCache[frame])
Nenue@59 682 end
Nenue@59 683 expirationCache[frame] = endTime
Nenue@59 684 print('push tempenchant timer update', timeRemaining / 1000, GetTime()+(timeRemaining/1000))
Nenue@94 685 self:UpdateButton(frame, timeRemaining/1000, GetTime()+(timeRemaining/1000))
Nenue@59 686 end
Nenue@59 687 else
Nenue@94 688 self:Acquire(name):Hide()
Nenue@59 689 end
Nenue@59 690 end
Nenue@59 691 end
Nenue@59 692 end
Nenue@59 693
Nenue@94 694 function plugin:OnBuffFrameUpdate () end
Nenue@59 695
Nenue@90 696
Nenue@84 697 -- The TempEnchant frames are hardcoded in the base FrameXML, so get them now
Nenue@59 698