annotate BuffFrame/BuffButton.lua @ 59:07ef62fe201f

Re-write of BuffFrame module: - uses secure hooks on blizzard BuffFrame.lua functions to determine needed action - make use of built-in table behavior to reduce unnecessary frame updates
author Nenue
date Thu, 28 Jul 2016 18:27:56 -0400
parents d7655c4e6e06
children
rev   line source
Nenue@0 1 --- Actual BlizzUI modifications are applied here
Nenue@0 2 -- @file-author@
Nenue@0 3 -- @project-revision@ @project-hash@
Nenue@0 4 -- @file-revision@ @file-hash@
Nenue@0 5 -- Created: 3/12/2016 12:47 AM
Nenue@0 6 local MODULE = 'BuffFrame'
Nenue@48 7
Nenue@48 8 local _
Nenue@48 9 local B, _G = select(2,...).frame, _G
Nenue@0 10 local type, unpack, select, pairs, ipairs = _G.type, _G.unpack, _G.select, _G.pairs, _G.ipairs
Nenue@0 11 local min, ceil, mod, tonumber, tostring = _G.min, _G.ceil, _G.mod, _G.tonumber, _G.tostring
Nenue@0 12 local floor, wipe, max = _G.math.floor, _G.table.wipe, _G.math.max
Nenue@0 13 local CreateFrame, IsInGroup, GetCVarBool = _G.CreateFrame, _G.IsInGroup, _G.GetCVarBool
Nenue@0 14 local BuffFrame, ConsolidatedBuffs = _G.BuffFrame, _G.ConsolidatedBuffs
Nenue@0 15 local UnitAura, UnitName, RegisterStateDriver = _G.UnitAura, _G.UnitName, _G.RegisterStateDriver
Nenue@0 16
Nenue@50 17 local Aura = B:RegisterModule(MODULE)
Nenue@50 18 local displays = Aura.displays
Nenue@48 19 local print, gprint, aprint, fprint = B.print('Buff'), B.print('SetGuides'), B.print('SetAnchors'), B.fprint
Nenue@0 20
Nenue@50 21 Aura.GetBuffZoom = function(buffName)
Nenue@50 22 local zoom = tonumber(Aura.displays[buffName].conf['Zoom']) / 100 / 2
Nenue@0 23 local zoomL, zoomU, zoomR, zoomD = zoom, zoom, 1-zoom, 1-zoom
Nenue@0 24 print(buffName, zoom)
Nenue@0 25 return function(self, ...)
Nenue@0 26 if select('#',...) == 4 then
Nenue@0 27 zoomL, zoomR, zoomU, zoomD = ...
Nenue@0 28 end
Nenue@0 29 self:SetTexCoord(zoomL, zoomR, zoomU, zoomD)
Nenue@0 30 return zoomL, zoomR, zoomU, zoomD
Nenue@0 31 end
Nenue@0 32 end
Nenue@0 33
Nenue@0 34
Nenue@0 35
Nenue@50 36 Aura.UpdateButtonAlpha = function(self)
Nenue@0 37 if not self.parent.timeLeft or not self:IsVisible() then
Nenue@0 38 self:SetScript('OnUpdate', nil)
Nenue@0 39 return
Nenue@0 40 end
Nenue@0 41
Nenue@0 42 if self.parent.timeLeft < _G.BUFF_WARNING_TIME then
Nenue@0 43 self:SetAlpha(BuffFrame.BuffAlphaValue)
Nenue@0 44 else
Nenue@0 45 self:SetAlpha(1)
Nenue@0 46 end
Nenue@0 47 end
Nenue@0 48
Nenue@0 49 --- Called infrequently to align stencil frames
Nenue@0 50 local refreshCount = 0
Nenue@50 51 Aura.UpdateGuideFrames = function(buffName)
Nenue@0 52 refreshCount = refreshCount + 1
Nenue@0 53 local print = fprint()
Nenue@48 54 print(buffName)
Nenue@50 55 local displays, anchors = Aura.displays, Aura.anchors
Nenue@50 56 local guides, decors = Aura.guides, Aura.decors
Nenue@0 57
Nenue@0 58 local anchor = anchors[buffName]
Nenue@0 59 local c, g, d = displays[buffName].conf, guides[buffName], decors[buffName]
Nenue@0 60 local perRow = c['PerRow']
Nenue@0 61 local buffSpacing, buffSize, buffBorder, buffDurationSize, buffCountSize, relativeX, relativeY = c['Spacing'], c['Size'], c['Border'], c['DurationSize'], c['CountSize'], c['RelativeX'], c['RelativeY']
Nenue@0 62 local consolidated = (anchors[buffName].contains and IsInGroup())
Nenue@0 63 local consolidatedPosition = (consolidated and anchors[buffName].containPosition or 0)
Nenue@0 64
Nenue@0 65
Nenue@0 66 print('|cFF00FF00Setting Guides ('..refreshCount..'):|r', buffName, 'user max:',c['Max'], 'hard max:', displays[buffName].maxIcons)
Nenue@0 67
Nenue@0 68 local buffMax = min(c['Max'], displays[buffName].maxIcons)
Nenue@0 69 local anchorFrom, anchorTo = c.Point[1], c.Point[2]
Nenue@50 70 anchor.Zoom = Aura.GetBuffZoom(buffName)
Nenue@0 71
Nenue@0 72
Nenue@0 73
Nenue@0 74 if consolidated then
Nenue@0 75 buffMax = buffMax + 1
Nenue@0 76 end
Nenue@0 77
Nenue@0 78 local legend = {}
Nenue@0 79 legend.r, legend.g, legend.b, legend.a = unpack(displays[buffName].legendColor)
Nenue@0 80 local horizFrom = (relativeX < 0) and 'RIGHT' or 'LEFT'
Nenue@0 81 local horizTo = (relativeX < 0) and 'LEFT' or 'RIGHT'
Nenue@0 82 local vertFrom = (relativeY < 0) and 'TOP' or 'BOTTOM'
Nenue@0 83 local vertTo = (relativeY < 0) and 'BOTTOM' or 'TOP'
Nenue@0 84 local previous, up
Nenue@0 85 local bottom_extent = 0
Nenue@0 86 for i = 1, buffMax do
Nenue@0 87 print('update idx', i)
Nenue@0 88 if not g[i] then
Nenue@0 89 g[i] = CreateFrame('Frame', buffName..'Guide'..i, anchor, displays[buffName].template or 'VeneerGuideTemplate')
Nenue@0 90 RegisterStateDriver(g[i], "visibility", "[petbattle] [vehicleui] hide; show")
Nenue@0 91 end
Nenue@0 92
Nenue@0 93 local guide = g[i]
Nenue@0 94
Nenue@0 95 local row = ceil(i / perRow)
Nenue@0 96 local col = mod(i, perRow)
Nenue@0 97 if col == 0 then
Nenue@0 98 col = perRow
Nenue@0 99 end
Nenue@0 100
Nenue@0 101 guide.previous = previous
Nenue@0 102 guide.up = up
Nenue@0 103 local x, y, parent = 0, 0, anchor
Nenue@0 104 if i == 1 then
Nenue@0 105 parent = anchor
Nenue@0 106 up = guide
Nenue@0 107 elseif col == 1 then
Nenue@0 108 parent = g[i-perRow]
Nenue@0 109 y = (buffSpacing + bottom_extent) * relativeY
Nenue@0 110 up = guide
Nenue@0 111 anchorFrom = vertFrom .. horizFrom
Nenue@0 112 anchorTo = vertFrom .. horizFrom
Nenue@0 113 bottom_extent = 0
Nenue@0 114 else
Nenue@0 115 parent = g[i-1]
Nenue@0 116 x = buffSpacing * relativeX
Nenue@0 117 anchorFrom = vertFrom .. horizFrom
Nenue@0 118 anchorTo = vertFrom .. horizTo
Nenue@0 119 end
Nenue@0 120 previous = guide
Nenue@0 121 guide.parent = parent
Nenue@0 122
Nenue@0 123 ---------------------------------
Nenue@0 124 -- Positioning layer
Nenue@0 125 if i ~= consolidatedPosition or not consolidated then
Nenue@0 126 guide:SetSize(buffSize, buffSize + buffDurationSize)
Nenue@0 127 -- RaidBuffTray will fix the sizing
Nenue@0 128 end
Nenue@0 129 bottom_extent = max(bottom_extent, guide:GetHeight())
Nenue@0 130
Nenue@0 131 guide.info = {} -- UnitAura cache
Nenue@0 132
Nenue@0 133 if i == consolidatedPosition then
Nenue@59 134 guide.legend:SetColorTexture(1,1,0,0.5)
Nenue@0 135 else
Nenue@59 136 guide.legend:SetColorTexture(legend.r, legend.g, legend.b, legend.a)
Nenue@0 137 end
Nenue@0 138
Nenue@0 139 guide.idText:SetText(i) -- needs to reflect the current position
Nenue@0 140
Nenue@0 141 guide:ClearAllPoints()
Nenue@0 142 guide:SetPoint(anchorFrom, parent, anchorTo, x, y)
Nenue@0 143 print(anchorFrom, parent, anchorTo, x, y)
Nenue@0 144
Nenue@0 145 guide.icon:SetSize(buffSize - buffBorder * 2, buffSize - buffBorder * 2)
Nenue@0 146 guide.icon:ClearAllPoints()
Nenue@0 147 guide.icon:SetPoint('TOPLEFT', guide, 'TOPLEFT', buffBorder, -buffBorder )
Nenue@0 148
Nenue@0 149 local anchorTo, anchorFrom, x, y = unpack(c.DurationPoint)
Nenue@0 150 guide.duration:ClearAllPoints()
Nenue@0 151 guide.duration:SetPoint(anchorTo, guide, anchorFrom, x, y)
Nenue@0 152 --guide.duration:SetSize(buffSize, buffDurationSize)
Nenue@0 153 print(' duration ->', anchorFrom, anchorTo, x, y)
Nenue@0 154
Nenue@0 155 local anchorTo, anchorFrom, x, y = unpack(c.CountPoint)
Nenue@0 156 guide.count:ClearAllPoints()
Nenue@0 157 guide.count:SetPoint(anchorTo, guide.icon, anchorFrom, x, y)
Nenue@0 158 --guide.count:SetSize(buffSize, c.CountSize)
Nenue@0 159 print(' count ->', anchorFrom, anchorTo, x, y)
Nenue@0 160
Nenue@0 161 -----------------------------------
Nenue@0 162 -- Background decorations layer
Nenue@0 163 if not d[i] then
Nenue@0 164 d[i] = CreateFrame('Frame', buffName..i..'Decor', _G.UIParent, 'VeneerDecorTemplate')
Nenue@7 165 -- todo: sort out a way to fix this without creating taint issues
Nenue@7 166 RegisterStateDriver(d[i], "visibility", "[petbattle] [vehicleui] hide")
Nenue@0 167 end
Nenue@0 168
Nenue@0 169 d[i]:SetPoint('BOTTOMLEFT', guide.icon, 'BOTTOMLEFT', -buffBorder, -buffBorder)
Nenue@0 170 d[i]:SetPoint('TOPRIGHT', guide.icon, 'TOPRIGHT', buffBorder, buffBorder)
Nenue@0 171
Nenue@0 172
Nenue@0 173 guide:Show()
Nenue@0 174 B.SetConfigLayers(guide)
Nenue@0 175 end
Nenue@0 176
Nenue@0 177
Nenue@0 178 if #guides[buffName] > buffMax then
Nenue@0 179 local lim = #guides[buffName]
Nenue@0 180 for i = buffMax+1, lim do
Nenue@0 181
Nenue@0 182 local g = guides[buffName][i]
Nenue@0 183 if g:IsVisible() then
Nenue@0 184 print('cleaning up #', i, buffName)
Nenue@0 185 g:Hide()
Nenue@0 186 B.RemoveConfigLayers(g)
Nenue@0 187 end
Nenue@0 188
Nenue@0 189 end
Nenue@0 190 end
Nenue@0 191
Nenue@0 192 anchor.last = previous
Nenue@0 193 anchor.up = up
Nenue@0 194
Nenue@0 195 print(anchor:GetName(), anchor:GetSize())
Nenue@0 196 end
Nenue@0 197
Nenue@50 198 Aura.UpdateButtonPositions = function(buffName, auraType)
Nenue@0 199 local print = fprint()
Nenue@0 200 local c = auraType.conf
Nenue@0 201 local numBuffs = 0
Nenue@0 202 local actualIcons = auraType.actualIcons()
Nenue@0 203 local maxIcons = auraType.maxIcons
Nenue@50 204 local guides, decors, anchors, drawn = Aura.guides, Aura.decors, Aura.anchors, Aura.drawn
Nenue@48 205
Nenue@0 206 local anchor = anchors[buffName]
Nenue@0 207 local buffMax = c['Max']
Nenue@0 208 local consolidated = (anchor.contains and IsInGroup())
Nenue@0 209 local consolidatedPosition = (consolidated and anchor.containPosition or 0)
Nenue@0 210
Nenue@0 211 for k,v in pairs(decors[buffName]) do
Nenue@0 212 print(v)
Nenue@0 213 end
Nenue@0 214
Nenue@0 215 if consolidated then
Nenue@0 216 decors[buffName][1]:Hide()
Nenue@0 217 numBuffs = numBuffs + 1
Nenue@0 218 buffMax = buffMax + 1
Nenue@0 219 end
Nenue@0 220
Nenue@0 221 print(' ', 'frame count:', auraType.actualIcons(), 'hardmax:', maxIcons)
Nenue@0 222 if auraType.actualIcons() > 0 then
Nenue@0 223 for i = 1, actualIcons do
Nenue@0 224
Nenue@0 225
Nenue@0 226 local buff = _G[buffName .. i]
Nenue@0 227 local buffIcon = _G[buffName .. i .. 'Icon']
Nenue@0 228 local buffBorder = c['Border']
Nenue@0 229 local buffDuration = _G[buffName .. i .. 'Duration']
Nenue@0 230 local buffCount = _G[buffName .. i .. 'Count']
Nenue@0 231 local buffDurationSize = c['DurationSize']
Nenue@0 232 local debuffBorder = _G[buffName .. i .. 'Border']
Nenue@0 233
Nenue@0 234
Nenue@0 235 if buff and not buff.consolidated then
Nenue@0 236 numBuffs = numBuffs + 1
Nenue@0 237 local guide = guides[buffName][numBuffs]
Nenue@0 238 local deco = decors[buffName][numBuffs]
Nenue@0 239 if numBuffs > buffMax then
Nenue@0 240 -- if a limit is reached, start hiding
Nenue@0 241 if guide then
Nenue@0 242 guide.info = nil
Nenue@0 243 end
Nenue@0 244 if deco then
Nenue@0 245 deco:Hide()
Nenue@0 246 end
Nenue@0 247 buff:Hide()
Nenue@0 248 else
Nenue@0 249 local buffData = guide.info
Nenue@0 250 buffData.name, buffData.rank, buffData.icon, buffData.count, buffData.dispelType, buffData.duration, buffData.expires, buffData.caster, buffData.isStealable, buffData.shouldConsolidate, buffData.spellID, buffData.canApplyAura, buffData.isBossDebuff, buffData.value1, buffData.value2, buffData.value3
Nenue@0 251 = UnitAura(buff.unit, buff:GetID(), nil, buff.filters)
Nenue@0 252
Nenue@0 253 if guide.caster and buffData.caster then
Nenue@0 254 if (buffData.caster ~= 'player' or c.ShowSelfCast) then
Nenue@0 255 guide.caster:SetText(UnitName(buffData.caster))
Nenue@0 256 else
Nenue@0 257 guide.caster:SetText(nil)
Nenue@0 258 end
Nenue@0 259 end
Nenue@0 260
Nenue@0 261
Nenue@0 262 print(numBuffs, i, buff:GetName(), buff:GetID(), decors[buffName][numBuffs]:GetName())
Nenue@0 263
Nenue@0 264 buff:SetAllPoints(guide)
Nenue@0 265 buffIcon:ClearAllPoints()
Nenue@0 266 buffIcon:SetPoint('TOPLEFT', guide.icon, 'TOPLEFT', 0, 0)
Nenue@0 267 buffIcon:SetPoint('BOTTOMRIGHT', guide.icon, 'BOTTOMRIGHT', 0, 0)
Nenue@0 268
Nenue@0 269 deco.parent = buff
Nenue@0 270 -- make sure so they aren't re-shown in pet battle
Nenue@0 271 if not C_PetBattles.IsInBattle() then
Nenue@0 272 deco:Show()
Nenue@0 273 deco:SetAlpha(1)
Nenue@0 274 end
Nenue@0 275
Nenue@0 276 if debuffBorder then
Nenue@59 277 deco.background:SetColorTexture(debuffBorder:GetVertexColor())
Nenue@0 278 debuffBorder:Hide()
Nenue@0 279 else
Nenue@0 280 if guide.info.caster == 'player' then
Nenue@0 281 print(guide.info.caster)
Nenue@59 282 deco.background:SetColorTexture(unpack(c.PlayerColor))
Nenue@0 283 elseif buffData.isBossDebuff then
Nenue@0 284 print(guide.info.isBossDebuff)
Nenue@59 285 deco.background:SetColorTexture(unpack(c.BossColor))
Nenue@0 286 else
Nenue@0 287 print(guide.info.caster)
Nenue@59 288 deco.background:SetColorTexture(unpack(c.Color))
Nenue@0 289 end
Nenue@0 290 end
Nenue@0 291
Nenue@0 292
Nenue@0 293 buffDuration:ClearAllPoints()
Nenue@0 294 local from, to = unpack(c.DurationPoint)
Nenue@0 295 buffDuration:SetPoint(from, guide.duration, to)
Nenue@0 296 buffDuration:SetText('WHAT')
Nenue@0 297
Nenue@0 298 if buff.timeLeft and c.WarningFade then
Nenue@50 299 deco:SetScript('OnUpdate', Aura.UpdateButtonAlpha)
Nenue@0 300 else
Nenue@0 301 deco:SetScript('OnUpdate', nil)
Nenue@0 302 deco:SetAlpha(1.0)
Nenue@0 303 end
Nenue@0 304
Nenue@0 305 buffCount:ClearAllPoints()
Nenue@0 306 local from, to = unpack(c.CountPoint)
Nenue@0 307 buffCount:SetPoint(from, guide.count, to)
Nenue@0 308
Nenue@0 309 if not drawn[buffName][numBuffs] then
Nenue@0 310 anchors[buffName].Zoom(buffIcon)
Nenue@0 311
Nenue@0 312 if buffDuration then
Nenue@0 313 local font = buffDuration:GetFont()
Nenue@0 314 buffDuration:SetFont(font, c.DurationSize, 'OUTLINE')
Nenue@0 315
Nenue@0 316 end
Nenue@0 317
Nenue@0 318 if buffCount then
Nenue@0 319 local font = buffCount:GetFont()
Nenue@0 320 buffCount:SetFont(font, c.CountSize, 'OUTLINE')
Nenue@0 321 end
Nenue@0 322 drawn[buffName][numBuffs] = true
Nenue@0 323 end
Nenue@0 324 end
Nenue@0 325 end
Nenue@0 326
Nenue@0 327 end
Nenue@0 328 end
Nenue@0 329 -- clear any outliers
Nenue@0 330 for i = numBuffs+1, buffMax do
Nenue@0 331 if guides[buffName][i].caster then
Nenue@0 332 guides[buffName][i].caster:SetText(nil)
Nenue@0 333 end
Nenue@0 334 --if not decors[buffName][i].parent or
Nenue@0 335
Nenue@0 336 decors[buffName][i].parent = nil
Nenue@0 337 decors[buffName][i]:SetAlpha(1.0)
Nenue@0 338 decors[buffName][i]:SetScript('OnUpdate', nil)
Nenue@0 339 decors[buffName][i]:Hide()
Nenue@0 340 end
Nenue@0 341
Nenue@0 342 -- parametric occlusion data for compacted anchor points
Nenue@0 343 if numBuffs == 0 then
Nenue@0 344 anchor.cutout_X = 0
Nenue@0 345 anchor.cutout_Y = 0
Nenue@0 346 anchor.outer_X = 0
Nenue@0 347 anchor.outer_Y = 0
Nenue@0 348 elseif numBuffs <= buffMax then
Nenue@0 349 local sX, sY = guides[buffName][numBuffs]:GetWidth(), guides[buffName][numBuffs]:GetHeight()
Nenue@0 350 local p = c.PerRow
Nenue@0 351 local lX = mod(numBuffs, p)
Nenue@0 352 local lY = floor(numBuffs / p)
Nenue@0 353 local oX = min(numBuffs, c.PerRow)
Nenue@0 354 local oY = ceil(numBuffs / p)
Nenue@0 355 anchor.cutout_X = lX * sX + lX * c.Spacing -- max clearance to fit alongside the row
Nenue@0 356 anchor.cutout_Y = lY * sY + lY * c.Spacing
Nenue@0 357 anchor.outer_Y = oY * sY + oY * c.Spacing -- distance of farthest row
Nenue@0 358 anchor.outer_X = oX * sX + oX * c.Spacing
Nenue@0 359
Nenue@0 360
Nenue@0 361 print('|cFF0088FF', 'inner corner', lX, lY, 'outer corners', oX, oY)
Nenue@0 362 print('cutout delta =', anchor.cutout_X, anchor.cutout_Y, 'out of', floor(anchor:GetWidth()), floor(anchor:GetHeight()))
Nenue@0 363 print('extent delta =', anchor.outer_X, anchor.outer_Y)
Nenue@0 364 else
Nenue@0 365 anchor.cutout_X = 0
Nenue@0 366 anchor.cutout_Y = 0
Nenue@0 367 anchor.outer_X = 0
Nenue@0 368 anchor.outer_Y = 0
Nenue@0 369 end
Nenue@0 370
Nenue@0 371 if anchor.attached then
Nenue@50 372 Aura.UpdateAnchorChild(anchor, anchor.attached, anchor.attachmentConf)
Nenue@0 373 end
Nenue@0 374
Nenue@0 375 end
Nenue@0 376
Nenue@50 377 Aura.PostBuffAnchors = function()
Nenue@0 378 local print = fprint()
Nenue@50 379 local anchors = Aura.anchors
Nenue@50 380 if Aura.ShowConsolidatedBuffs then
Nenue@50 381 Aura.UpdateRaidBuffs()
Nenue@0 382 end
Nenue@0 383 for buttonName, auraType in pairs(displays) do
Nenue@0 384 print('sending', buttonName, auraType)
Nenue@0 385 -- if waiting for anchors
Nenue@0 386 if not anchors[buttonName] then
Nenue@0 387 return
Nenue@0 388 end
Nenue@0 389
Nenue@0 390 --if positioned[buttonName] == 0 then
Nenue@0 391 print('possibly reloaded UI, check positions')
Nenue@50 392 Aura.UpdateGuideFrames(buttonName)
Nenue@0 393 --end
Nenue@0 394
Nenue@50 395 Aura.UpdateButtonPositions(buttonName, auraType)
Nenue@0 396 end
Nenue@0 397 end
Nenue@0 398
Nenue@50 399 Aura.UpdateBuffs = function(buttonName, forced)
Nenue@50 400 local displays, drawn = Aura.displays, Aura.drawn
Nenue@0 401 local print = B.fprint(buttonName)
Nenue@0 402 local c = displays[buttonName].conf
Nenue@0 403 if drawn[buttonName] then
Nenue@0 404 wipe(drawn[buttonName])
Nenue@0 405 else
Nenue@0 406 drawn[buttonName] = {}
Nenue@0 407 end
Nenue@0 408
Nenue@50 409 Aura.UpdateAnchorFrames(buttonName)
Nenue@50 410 Aura.UpdateGuideFrames(buttonName)
Nenue@50 411 Aura.UpdateButtonPositions(buttonName, displays[buttonName])
Nenue@0 412 end
Nenue@0 413
Nenue@0 414 --- should only be called from user input
Nenue@48 415 print('init def')