comparison Modules/BuffFrame.lua @ 75:d9d16e67725c

- refactor objectives plugin
author Nenue
date Sat, 27 Aug 2016 07:09:54 -0400
parents cd6e78091b04
children 08951972041a
comparison
equal deleted inserted replaced
74:cd6e78091b04 75:d9d16e67725c
9 - Individual BuffButton frames are created upon use, making it difficult to do any sort of securestate priming 9 - Individual BuffButton frames are created upon use, making it difficult to do any sort of securestate priming
10 - TempEnchant info returns relative values only, and they don't synchronize with aura events 10 - TempEnchant info returns relative values only, and they don't synchronize with aura events
11 - BuffButtons can only be hidden/shown by blizzcode, so functions doing that have to be accounted for 11 - BuffButtons can only be hidden/shown by blizzcode, so functions doing that have to be accounted for
12 --]] 12 --]]
13 13
14 local BUFFS_PER_ROW = 12
14 local BUFF_BUTTON_SIZE = 48 15 local BUFF_BUTTON_SIZE = 48
15 local BUFF_BUTTON_SPACING_H = 4 16 local BUFF_BUTTON_SPACING_H = 4
16 local BUFF_BUTTON_SPACING_V = 14 17 local BUFF_BUTTON_SPACING_V = 14
17 local BUFF_PROGRESS_SIZE = 4 18 local BUFF_PROGRESS_SIZE = 4
18 local BUFF_PROGRESS_INSET = 1 19 local BUFF_PROGRESS_INSET = 1
19 local BUFF_BUTTON_ZOOM = .15 20 local BUFF_BUTTON_ZOOM = .15
20 local BORDER_SIZE_L = 0 21 local BORDER_SIZE_L = 0
21 local BORDER_SIZE_R = 0 22 local BORDER_SIZE_R = 0
22 local BORDER_SIZE_U = 4 23 local BORDER_SIZE_U = 4
23 local BORDER_SIZE_D = 0 24 local BORDER_SIZE_D = 0
25 local BUFF_FRAMES_X = -230
26 local BUFF_FRAMES_Y = -4
24 27
25 28
26 local plugin = CreateFrame('Frame', 'VeneerBuffFrame', UIParent) 29 local plugin = CreateFrame('Frame', 'VeneerBuffFrame', UIParent)
27 local vn, print = LibStub("LibKraken").register(VeneerController, plugin) 30 local vn, print = LibStub("LibKraken").register(Veneer, plugin)
28 local tprint = DEVIAN_WORKSPACE and function(...) _G.print('Timer', ...) end or function() end 31 local tprint = DEVIAN_WORKSPACE and function(...) _G.print('Timer', ...) end or function() end
29 32
30 local _G, UIParent = _G, UIParent 33 local _G, UIParent = _G, UIParent
31 local tinsert, tremove, unpack, select, tconcat = table.insert, table.remove, unpack, select, table.concat 34 local tinsert, tremove, unpack, select, tconcat = table.insert, table.remove, unpack, select, table.concat
32 local floor, tonumber, format = math.floor, tonumber, string.format 35 local floor, tonumber, format = math.floor, tonumber, string.format
33 local UnitAura, GetTime, CreateFrame = UnitAura, GetTime, CreateFrame 36 local UnitAura, GetTime, CreateFrame = UnitAura, GetTime, CreateFrame
34 local hooksecurefunc = hooksecurefunc 37 local hooksecurefunc = hooksecurefunc
35 38
36 local buttons = {}
37 local buffTypes = {
38 {
39 name = 'buff',
40 pattern = 'BuffButton(%d)',
41 filters = 'HELPFUL',
42 },
43 {
44 name = 'debuff',
45 pattern = 'DebuffButton(%d)',
46 filters = 'HARMFUL',
47 },
48 {
49 name = 'tempenchant',
50 pattern = 'TempEnchant(%d)',
51 filters = 'TEMPENCHANT'
52 }
53 }
54
55 local textureMapping = {
56 [1] = 16, --Main hand
57 [2] = 17, --Off-hand
58 [3] = 18, --Ranged
59 }
60
61 local tickCounter = {}
62 local aurasCache = {} 39 local aurasCache = {}
63 local skinnedFrames = {} 40 local skinnedFrames = {}
64 local pendingFrames = {} 41 local pendingFrames = {}
65 local anchors = {} 42 local veneers = {}
66 local expirationCache = {} 43 local expirationCache = {}
67 local visibility = {} 44 local visibility = {}
68 45 local isHooked = {}
46
47 plugin.options = {
48 nameString = 'Buff Frames',
49 {
50 name = 'BuffButtonZoom',
51 type = 'slider',
52 min = 0,
53 max = 100,
54 fullwidth = true,
55 },
56 {
57 name = 'BuffBorderLeft',
58 type = 'slider',
59 min = 0,
60 max = 16,
61 },
62 {
63 name = 'BuffBorderLeft',
64 type = 'slider',
65 min = 0,
66 max = 16,
67 }
68 }
69 69
70 70
71 local GetVeneer = function(frame) 71 local GetVeneer = function(frame)
72 local name = frame:GetName() 72
73 if not (_G[name..'Veneer']) then 73 if not (veneers[frame]) then
74 local name = frame:GetName()
74 print('|cFF88FF00Creating', name,'Veneer') 75 print('|cFF88FF00Creating', name,'Veneer')
75 local veneer = vn.GetVeneer(frame, 'VeneerBuffTemplate') 76 local veneer = vn.GetVeneer(frame, 'VeneerBuffTemplate')
76 local id = frame:GetID() 77 local id = frame:GetID()
77 78
78 79
79 veneer.progress:SetPoint('BOTTOMLEFT', veneer, 'BOTTOMLEFT', 0, -6) 80 veneer.progress:SetPoint('BOTTOMLEFT', veneer, 'BOTTOMLEFT', 0, -6)
80 veneer.progress:SetPoint('TOPRIGHT', veneer, 'BOTTOMRIGHT', 0, -1) 81 veneer.progress:SetPoint('TOPRIGHT', veneer, 'BOTTOMRIGHT', 0, -1)
81 veneer.progress:SetHeight(BUFF_PROGRESS_SIZE + (BUFF_PROGRESS_INSET * 2)) 82 veneer.progress:SetHeight(BUFF_PROGRESS_SIZE + (BUFF_PROGRESS_INSET * 2))
82 83
83 veneer.progress.fg:SetColorTexture(0,1,0,1) 84 veneer.progress.bg:SetColorTexture(0,0,0,1)
85
86 veneer.progress.fg:SetColorTexture(1,1,1,1)
87 veneer.progress.fg:ClearAllPoints()
84 veneer.progress.fg:SetPoint('BOTTOMLEFT', BUFF_PROGRESS_INSET,BUFF_PROGRESS_INSET) 88 veneer.progress.fg:SetPoint('BOTTOMLEFT', BUFF_PROGRESS_INSET,BUFF_PROGRESS_INSET)
85 veneer.progress.fg:SetPoint('TOP', 0, -BUFF_PROGRESS_INSET) 89 veneer.progress.fg:SetPoint('TOP', 0, -BUFF_PROGRESS_INSET)
86 90
87 veneer.duration:SetFontObject(VeneerNumberFont) 91 veneer.duration:SetFontObject(VeneerNumberFont)
88 veneer.duration:ClearAllPoints() 92 veneer.duration:ClearAllPoints()
98 veneer.border:SetPoint('TOPLEFT', veneer, 'TOPLEFT', -BORDER_SIZE_L, BORDER_SIZE_U) 102 veneer.border:SetPoint('TOPLEFT', veneer, 'TOPLEFT', -BORDER_SIZE_L, BORDER_SIZE_U)
99 veneer.border:SetPoint('BOTTOMRIGHT', veneer, 'BOTTOMRIGHT', BORDER_SIZE_R, -BORDER_SIZE_D) 103 veneer.border:SetPoint('BOTTOMRIGHT', veneer, 'BOTTOMRIGHT', BORDER_SIZE_R, -BORDER_SIZE_D)
100 veneer.border:Show() 104 veneer.border:Show()
101 105
102 106
103 end 107 veneers[frame] = veneer
104 108 end
105 109
106 return _G[name..'Veneer'] 110
111 return veneers[frame]
107 end 112 end
108 113
109 114
110 -- Associates skinning elements with said button 115 -- Associates skinning elements with said button
111 local SkinFrame = function(name) 116 local SkinFrame = function(name)
139 if aurasCache[frame] and aurasCache[frame][5] then 144 if aurasCache[frame] and aurasCache[frame][5] then
140 color = DebuffTypeColor[aurasCache[frame][5]] 145 color = DebuffTypeColor[aurasCache[frame][5]]
141 end 146 end
142 147
143 veneer.progress.fg:SetColorTexture(color.r,color.g,color.b) 148 veneer.progress.fg:SetColorTexture(color.r,color.g,color.b)
144 veneer.border:SetColorTexture(color.r,color.g,color.b) 149 veneer.border:SetColorTexture(0,0,0,1)
145 end 150 end
146 if duration then 151 if duration then
147 duration:ClearAllPoints() 152 duration:ClearAllPoints()
148 --duration:SetPoint('TOP', frame, 'BOTTOM', 0, -8) 153 --duration:SetPoint('TOP', frame, 'BOTTOM', 0, -8)
149 --duration:SetFontObject(VeneerNumberFont) 154 --duration:SetFontObject(VeneerNumberFont)
203 visibility[self] = isVisible 208 visibility[self] = isVisible
204 end 209 end
205 veneer.underlay:Show() 210 veneer.underlay:Show()
206 end) 211 end)
207 212
208 anchors[frame] = veneer 213 end
209 end 214
210
211 local Aura_SetBorderColor = function(self, r,g,b,a) end
212 local Aura_OnShow = function(self) end
213 local Aura_OnHide = function(self) end
214 215
215 --- Set widgets to reflect the passed parameters 216 --- Set widgets to reflect the passed parameters
216 local UpdateVeneer = function (frame, duration, expires) 217 local UpdateVeneer = function (frame, duration, expires)
217 local veneer = GetVeneer(frame) 218 local veneer = GetVeneer(frame)
218 -- is it a new button? 219 -- is it a new button?
292 293
293 local AuraButton_Update = function(name, index, filter) 294 local AuraButton_Update = function(name, index, filter)
294 local bName = name..index 295 local bName = name..index
295 local frame = _G[bName] 296 local frame = _G[bName]
296 if frame and frame:IsVisible() then 297 if frame and frame:IsVisible() then
297 tickCounter[frame] = (tickCounter[frame] or 0) + 1
298 local cacheDiff = CacheCheck(frame, UnitAura(frame.unit, frame:GetID(), frame.filter)) 298 local cacheDiff = CacheCheck(frame, UnitAura(frame.unit, frame:GetID(), frame.filter))
299 -- if the name or expirationTime changed 299 -- if the name or expirationTime changed
300 if (cacheDiff >= 1) then 300 if (cacheDiff >= 1) then
301 print('|cFFFF4400', frame:GetName(), 'diff:', cacheDiff) 301 print('|cFFFF4400', frame:GetName(), 'diff:', cacheDiff)
302 if not skinnedFrames[frame] then 302 if not skinnedFrames[frame] then
336 for i = 1, BUFF_ACTUAL_DISPLAY do 336 for i = 1, BUFF_ACTUAL_DISPLAY do
337 local buff = _G['BuffButton'..i] 337 local buff = _G['BuffButton'..i]
338 if buff then 338 if buff then
339 numBuffs = numBuffs + 1 339 numBuffs = numBuffs + 1
340 buff:ClearAllPoints() 340 buff:ClearAllPoints()
341 if mod(numBuffs,12) == 1 then 341 if mod(numBuffs,BUFFS_PER_ROW) == 1 then
342 if numBuffs == 1 then 342 if numBuffs == 1 then
343 buff:SetPoint('TOPRIGHT', UIParent, 'TOPRIGHT', -120, -6) 343 buff:SetPoint('TOPRIGHT', UIParent, 'TOPRIGHT', BUFF_FRAMES_X, BUFF_FRAMES_Y)
344 plugin.currentTop = buff:GetTop() 344 plugin.currentTop = buff:GetTop()
345 else 345 else
346 buff:SetPoint('TOPRIGHT', topBuff, 'BOTTOMRIGHT', 0, -BUFF_BUTTON_SPACING_V) 346 buff:SetPoint('TOPRIGHT', topBuff, 'BOTTOMRIGHT', 0, -BUFF_BUTTON_SPACING_V)
347 end 347 end
348 topBuff = buff 348 topBuff = buff
363 debuff:SetPoint('TOPRIGHT', topBuff, 'BOTTOMRIGHT', 0, -BUFF_BUTTON_SPACING_V) 363 debuff:SetPoint('TOPRIGHT', topBuff, 'BOTTOMRIGHT', 0, -BUFF_BUTTON_SPACING_V)
364 else 364 else
365 debuff:SetPoint('TOPRIGHT', UIParent, 'TOPRIGHT', -120, -6) 365 debuff:SetPoint('TOPRIGHT', UIParent, 'TOPRIGHT', -120, -6)
366 end 366 end
367 topBuff = debuff 367 topBuff = debuff
368 elseif mod(numBuffs, 12) == 1 then 368 elseif mod(numBuffs, BUFFS_PER_ROW) == 1 then
369 debuff:SetPoint('TOPRIGHT', topBuff, 'BOTTOMRIGHT', 0, -BUFF_BUTTON_SPACING_V) 369 debuff:SetPoint('TOPRIGHT', topBuff, 'BOTTOMRIGHT', 0, -BUFF_BUTTON_SPACING_V)
370 topBuff = debuff 370 topBuff = debuff
371 else 371 else
372 debuff:SetPoint('TOPRIGHT', lastBuff, 'TOPLEFT', -BUFF_BUTTON_SPACING_H, 0) 372 debuff:SetPoint('TOPRIGHT', lastBuff, 'TOPLEFT', -BUFF_BUTTON_SPACING_H, 0)
373 end 373 end
396 396
397 if timeLeft < 10 then 397 if timeLeft < 10 then
398 if not veneer.duration.getHuge then 398 if not veneer.duration.getHuge then
399 veneer.duration.getHuge = true 399 veneer.duration.getHuge = true
400 veneer.duration:SetFontObject(VeneerNumberFontLarge) 400 veneer.duration:SetFontObject(VeneerNumberFontLarge)
401 veneer.duration:SetTextColor(1,0,0,1) 401 veneer.duration:SetTextColor(1,1,0,1)
402 end 402 end
403 else 403 else
404 if veneer.duration.getHuge then 404 if veneer.duration.getHuge then
405 veneer.duration.getHuge = nil 405 veneer.duration.getHuge = nil
406 veneer.duration:SetFontObject(VeneerNumberFont) 406 veneer.duration:SetFontObject(VeneerNumberFont)