Mercurial > wow > buffalo2
comparison ObjectiveStyle.lua @ 19:605e8f0e46db
ObjectiveCore / Style / Events / Frame
- polishing the execution path for better performance
- make use of the Blizzard_ObjectiveTracker bitfield values to ensure compatibility in possible secure hooks
- avoid full updates when possible (using said bitfield values to indicate targeted sections)
- extreme streamlining of event handling layout: specific reason updates are invoked from API hooks; broader updates are invoked by when the event listener catches something vague like 'QUEST_LOG_UPDATE'
author | Nenue |
---|---|
date | Wed, 06 Apr 2016 07:38:35 -0400 |
parents | d1812fb10ae6 |
children | d5ee940de273 |
comparison
equal
deleted
inserted
replaced
18:d1812fb10ae6 | 19:605e8f0e46db |
---|---|
12 local unpack, type, pairs, tconcat = unpack, type, pairs, table.concat | 12 local unpack, type, pairs, tconcat = unpack, type, pairs, table.concat |
13 local wrapperHeadFont, wrapperHeadSize, wrapperHeadOutline = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], 16, 'NONE' | 13 local wrapperHeadFont, wrapperHeadSize, wrapperHeadOutline = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], 16, 'NONE' |
14 local headerFont, headerSize = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], 24 | 14 local headerFont, headerSize = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], 24 |
15 local headerOutline, headerSpacing = 'OUTLINE', 2 | 15 local headerOutline, headerSpacing = 'OUTLINE', 2 |
16 | 16 |
17 | |
18 mod.defaults.Wrapper = { | |
19 WrapperPoint = 'TOPRIGHT', | |
20 WrapperFloatX = -25, | |
21 WrapperFloatV = 'TOP', | |
22 WrapperFloatY = -200, | |
23 | |
24 WrapperWidth = 270, | |
25 WrapperHeight = 600, | |
26 } | |
27 mod.defaults.Tracker = { | |
28 HeaderHeight = 24, | |
29 } | |
30 | 17 |
31 mod.defaults.Style = { | 18 mod.defaults.Style = { |
32 Format = { | 19 Format = { |
33 Frame = { | 20 Frame = { |
34 Width = 270, | 21 Width = 270, |
54 Width = 270, | 41 Width = 270, |
55 Spacing = 0, | 42 Spacing = 0, |
56 Indent = 2, | 43 Indent = 2, |
57 }, | 44 }, |
58 titlebg = { | 45 titlebg = { |
59 Background = {0, 0, 0, 1}, | |
60 Width = 270, | |
61 }, | 46 }, |
62 status = { | 47 status = { |
63 Width = 270, | 48 Width = 270, |
64 Spacing = 0, | 49 Spacing = 0, |
65 }, | 50 }, |
66 statusbg = { | 51 statusbg = { |
67 Width = 270, | |
68 }, | 52 }, |
69 Frame = { | 53 Frame = { |
70 Width = 270, | |
71 } | 54 } |
72 }, | 55 }, |
73 Wrapper = { | 56 Wrapper = { |
74 Frame = { | |
75 BackgroundComplex = {Left = {'', 0, 0.4, 0,1, 100}, Right={'', 0.6,1,0,1}, Tile = {'', 0.4,.6,0,1, 100}}, }, | |
76 title = { | 57 title = { |
77 Font = {wrapperHeadFont, wrapperHeadSize, wrapperHeadOutline}, | 58 Font = {wrapperHeadFont, wrapperHeadSize, wrapperHeadOutline}, |
78 Spacing = 4,} | 59 Spacing = 4,} |
79 }, | 60 }, |
80 Tracker = { | 61 Tracker = { |
94 titlebg = { | 75 titlebg = { |
95 Indent = 2, | 76 Indent = 2, |
96 Gradient = { 'HORIZONTAL', MinColor = {0.7, 0, 0.9, 0}, MaxColor = {.7, 0, 0.9, .25}}, | 77 Gradient = { 'HORIZONTAL', MinColor = {0.7, 0, 0.9, 0}, MaxColor = {.7, 0, 0.9, .25}}, |
97 }, | 78 }, |
98 title = { | 79 title = { |
99 TextColor = {1,1,1,0.8}, | 80 TextColor = {1,1,1,1}, |
100 Font = {titleFont, titleSize, titleOutline}, | 81 Font = {titleFont, titleSize, titleOutline}, |
101 Spacing = titleSpacing, | 82 Spacing = titleSpacing, |
102 }, | 83 }, |
103 status = { | 84 status = { |
104 TextColor = {1,1,1,0.8}, | 85 TextColor = {1,1,1,1}, |
105 Font = {textFont, textSize, textOutline}, | 86 Font = {textFont, textSize, textOutline}, |
106 Spacing = textSpacing, | 87 Spacing = textSpacing, |
107 }, | 88 }, |
108 statusbg = { | 89 statusbg = { |
109 Gradient = { 'HORIZONTAL', MinColor = {0.2, .4, 1, 0}, MaxColor = {.7, 0, 0.9, .11}}, | 90 Gradient = { 'HORIZONTAL', MinColor = {0.2, .4, 1, 0}, MaxColor = {.7, 0, 0.9, .11}}, |
120 TextColor = {0.7,1,1,1}, | 101 TextColor = {0.7,1,1,1}, |
121 Font = {titleFont, titleSize, titleOutline}, | 102 Font = {titleFont, titleSize, titleOutline}, |
122 Spacing = titleSpacing, | 103 Spacing = titleSpacing, |
123 }, | 104 }, |
124 status = { | 105 status = { |
125 TextColor = {1,1,1,0.5}, | 106 TextColor = {1,1,1,1}, |
126 Font = {textFont, textSize, textOutline}, | 107 Font = {textFont, textSize, textOutline}, |
127 Spacing = textSpacing, | 108 Spacing = textSpacing, |
128 }, | 109 }, |
129 }, | 110 }, |
130 Super = { | 111 Super = { |
161 Gradient = {'HORIZONTAL', MinColor = {0.2, .4, 1, 1}, MaxColor = {0.2, .4, 1, .2}, }, | 142 Gradient = {'HORIZONTAL', MinColor = {0.2, .4, 1, 1}, MaxColor = {0.2, .4, 1, .2}, }, |
162 } | 143 } |
163 }, | 144 }, |
164 Complete = { | 145 Complete = { |
165 title = { | 146 title = { |
166 TextColor = {1,1,1,0.5}, | 147 TextColor = {1,1,1,1}, |
167 Font = {titleFont, titleSize, titleOutline}, Spacing = titleSpacing, | 148 Font = {titleFont, titleSize, titleOutline}, Spacing = titleSpacing, |
168 }, | 149 }, |
169 titlebg = { | 150 titlebg = { |
170 Gradient = {'HORIZONTAL', MinColor = {0, 1, 0, 0}, MaxColor = {0, 1, 0, 0.34}, }, | 151 Gradient = {'HORIZONTAL', MinColor = {0, 1, 0, 0}, MaxColor = {0, 1, 0, 0.34}, }, |
171 }, | 152 }, |
172 status = { | 153 status = { |
173 TextColor = {1,1,1,0.5}, | 154 TextColor = {1,1,1,1}, |
174 Font = {textFont, textSize, textOutline}, Spacing = textSpacing, | 155 Font = {textFont, textSize, textOutline}, Spacing = textSpacing, |
175 }, | 156 }, |
176 statusbg = { | 157 statusbg = { |
177 Gradient = {'HORIZONTAL', MinColor = {0, 1, 0, 0}, MaxColor = {0, 1, 0, .25}, }, | 158 Gradient = {'HORIZONTAL', MinColor = {0, 1, 0, 0}, MaxColor = {0, 1, 0, .25}, }, |
178 } | 159 } |
255 print('|cFFFFFF00'..frame:GetName()..'|r', frameType, ...) | 236 print('|cFFFFFF00'..frame:GetName()..'|r', frameType, ...) |
256 --@debug@ | 237 --@debug@ |
257 local c = mod.defaults.Normal | 238 local c = mod.defaults.Normal |
258 local style_list = {... } | 239 local style_list = {... } |
259 local styleName = frameType .. '-' .. table.concat(style_list,'') | 240 local styleName = frameType .. '-' .. table.concat(style_list,'') |
260 local previousClass = mod.Conf.Style[frameType] | 241 local previousClass = {mod.Conf.Style[frameType] } |
242 local previousClassString = {'frame' } | |
243 local parentName | |
261 | 244 |
262 if not style_cache[styleName] then | 245 if not style_cache[styleName] then |
263 local style = {} | 246 local style = {} |
264 | 247 |
248 --[[ | |
265 if mod.defaults.Style[frameType] then | 249 if mod.defaults.Style[frameType] then |
266 print(' setting style class |cFF00FFFF'..frameType) | 250 print(' setting style class |cFF00FFFF'..frameType) |
267 else | 251 else |
268 print(' resorting to class Normal (missing |cFFFF8800'.. frameType..'|r)') | 252 print(' resorting to class Normal (missing |cFFFF8800'.. frameType..'|r)') |
269 end | 253 end |
254 --]] | |
270 local normal = mod.defaults.Style.Normal | 255 local normal = mod.defaults.Style.Normal |
271 local root = mod.defaults.Style[frameType] or normal | 256 local root = mod.defaults.Style[frameType] or normal |
272 for i, className in ipairs(style_list) do | 257 for i, className in ipairs(style_list) do |
258 print('|cFF00FF00'..i..'|r', className) | |
273 local class = normal | 259 local class = normal |
274 if previousClass and previousClass[className] then | 260 local childClass |
275 class = previousClass[className] | 261 if previousClass then |
276 print(' ChildClass |cFFFF0088'.. className .. '|r') | 262 for i = #previousClass, 1, -1 do |
263 print('checking if '..className..' child of '.. previousClassString[i]) | |
264 if previousClass[i][className] then | |
265 print(' it is!') | |
266 childClass = previousClass[i][className] | |
267 parentName = previousClassString[i] | |
268 break | |
269 end | |
270 end | |
271 end | |
272 if childClass then | |
273 class = childClass | |
274 print(' ChildClass '..parentName..'.|cFFFF0088'.. className .. '|r') | |
277 elseif root[className] then | 275 elseif root[className] then |
278 class = root[className] | 276 class = root[className] |
279 print(' SubClass |cFF0088FF'.. className .. '|r') | 277 print(' SubClass |cFF0088FF'.. className .. '|r') |
280 elseif normal[className] then | 278 elseif normal[className] then |
281 class = normal[className] | 279 class = normal[className] |
282 print(' SubClass Normal.|cFFFF0088'..className..'|r') | 280 print(' SubClass Normal.|cFFFF0088'..className..'|r') |
283 else | 281 else |
284 print(' SubClass not found '..className..'') | 282 --print(' SubClass not found '..className..'') |
285 end | 283 end |
286 previousClass = class | 284 tinsert(previousClass, class) |
285 tinsert(previousClassString, className) | |
287 | 286 |
288 for elementName, element in pairs(class) do | 287 for elementName, element in pairs(class) do |
289 if not elementName:match('^%u') then | 288 if not elementName:match('^%u') then |
290 print(' scanning Element |cFF8800FF'.. elementName ..'|r') | 289 --print(' scanning Element |cFF8800FF'.. elementName ..'|r') |
291 if not style[elementName] then | 290 if not style[elementName] then |
292 style[elementName] = {} | 291 style[elementName] = {} |
293 end | 292 end |
294 for key, value in pairs(element) do | 293 for key, value in pairs(element) do |
295 if mod.SetBlockAttribute[key] then | 294 if mod.SetBlockAttribute[key] then |
296 print(' |cFF00FF00'..elementName..'|r.|cFF00FFFF'..key..' =', (type(value) == 'table' and ('{'..table.concat(value,', ')..'}') or tostring(value))) | 295 --print(' |cFF00FF00'..elementName..'|r.|cFF00FFFF'..key..' =', (type(value) == 'table' and ('{'..table.concat(value,', ')..'}') or tostring(value))) |
297 style[elementName][key] = value | 296 style[elementName][key] = value |
298 end | 297 end |
299 | 298 |
300 end | 299 end |
301 end | 300 end |
308 style[k] = elements | 307 style[k] = elements |
309 end | 308 end |
310 end | 309 end |
311 | 310 |
312 | 311 |
313 print('result for: ', frame:GetName()) | 312 --[[print('result for: ', frame:GetName()) |
314 for k,v in pairs(style) do | 313 for k,v in pairs(style) do |
315 if type(v) == 'table' and not k:match('^%u') then | 314 if type(v) == 'table' and not k:match('^%u') then |
316 for kk, vv in pairs(v) do | 315 for kk, vv in pairs(v) do |
317 print(' |cFFFFFF00'..k..'|r.|cFF00FF00'..kk..'|r =', (type(vv) == 'table' and ('{'..table.concat(vv,', ')..'}') or tostring(vv))) | 316 --print(' |cFFFFFF00'..k..'|r.|cFF00FF00'..kk..'|r =', (type(vv) == 'table' and ('{'..table.concat(vv,', ')..'}') or tostring(vv))) |
318 end | 317 end |
319 else | 318 else |
320 print(' |cFFFFFFFF' .. k ..'|r =', tostring(v)) | 319 --print(' |cFFFFFFFF' .. k ..'|r =', tostring(v)) |
321 end | 320 end |
322 end | 321 end |
322 --]] | |
323 print('saving |cFFFFFF00'..styleName) | |
323 style_cache[styleName] = style | 324 style_cache[styleName] = style |
325 else | |
326 | |
327 print('using |cFFFF00FF'..styleName) | |
324 end | 328 end |
325 | 329 |
326 local style = style_cache[styleName] | 330 local style = style_cache[styleName] |
327 | 331 |
328 if not style_cache_func[styleName] then | 332 if not style_cache_func[styleName] then |
336 code = code .. | 340 code = code .. |
337 "\n if frame['"..elementName.."'] then" | 341 "\n if frame['"..elementName.."'] then" |
338 | 342 |
339 for attributeName, value in pairs(styleset) do | 343 for attributeName, value in pairs(styleset) do |
340 if mod.SetBlockAttribute[attributeName] then | 344 if mod.SetBlockAttribute[attributeName] then |
341 print(' add function '..elementName..':'.. attributeName ..'(', (type(value) == 'table' and ('{'..table.concat(value,', ')..'}') or tostring(value)), ')') | 345 --print(' add function '..elementName..':'.. attributeName ..'(', (type(value) == 'table' and ('{'..table.concat(value,', ')..'}') or tostring(value)), ')') |
342 | 346 |
343 | 347 |
344 --mod.SetBlockAttribute[attributeName](region, value) | 348 --mod.SetBlockAttribute[attributeName](region, value) |
345 code = code | 349 code = code |
346 --.. "\n print('CacheFunc', ' applying', '|cFF00FFFF" .. attributeName .. "|r to', '|cFF0088FF"..elementName.."|r', cache['"..styleName.."']['"..elementName.."']['".. attributeName .."'])" | 350 --.. "\n print('CacheFunc', ' applying', '|cFF00FFFF" .. attributeName .. "|r to', '|cFF0088FF"..elementName.."|r', cache['"..styleName.."']['"..elementName.."']['".. attributeName .."'])" |
347 .. "\n\n func['" .. attributeName .. "'](frame['"..elementName.."'],".. | 351 .. "\n\n func['" .. attributeName .. "'](frame['"..elementName.."'],".. |
348 " cache['"..styleName.."']['"..elementName.."']['".. attributeName .."'])" | 352 " cache['"..styleName.."']['"..elementName.."']['".. attributeName .."'])" |
349 | 353 |
350 --- Set any frame.blah variables used in Updates | 354 --- Set any frame.blah variables used in Updates |
351 if block_vars[elementName .. attributeName] then | 355 if block_vars[elementName .. attributeName] then |
352 print('|cFF008800BVar|r', elementName..attributeName) | 356 --print('|cFF008800BVar|r', elementName..attributeName) |
353 for i, blockKey in ipairs(block_vars[elementName .. attributeName]) do | 357 for i, blockKey in ipairs(block_vars[elementName .. attributeName]) do |
354 print(' assigning |cFF008800'..blockKey..'|r') | 358 --print(' assigning |cFF008800'..blockKey..'|r') |
355 frame[blockKey] = (type(value) == 'table') and value[i] or value | 359 frame[blockKey] = (type(value) == 'table') and value[i] or value |
356 end | 360 end |
357 end | 361 end |
358 | 362 |
359 end | 363 end |
363 --"\n print('CacheFunc', ' |cFFFF4400missing', frame:GetName()..'."..elementName.."')".. | 367 --"\n print('CacheFunc', ' |cFFFF4400missing', frame:GetName()..'."..elementName.."')".. |
364 "\n end" | 368 "\n end" |
365 end | 369 end |
366 code = code .. "\nend" | 370 code = code .. "\nend" |
367 local result = assert(loadstring(code)) | 371 local result = assert(loadstring(code)) |
368 print('storing style func', styleName, result()) | 372 --print('storing style func', styleName, result()) |
369 style_cache_func[styleName] = result() | 373 style_cache_func[styleName] = result() |
370 | 374 |
371 end | 375 end |
372 style_cache_func[styleName](frame) | 376 style_cache_func[styleName](frame) |
373 | 377 |
374 --- Hardcoding the sizing vars for sanity | 378 --- Hardcoding the sizing vars for sanity |
379 local defaultWidth = mod.Conf.Wrapper.Width | |
375 local normalSettings = mod.defaults.Style.Format | 380 local normalSettings = mod.defaults.Style.Format |
376 frame.width = normalSettings.Frame.Width | 381 frame.width = defaultWidth |
377 frame.statusWidth = frame.width - normalSettings.status.Indent | 382 frame.statusWidth = defaultWidth - normalSettings.status.Indent |
378 frame.titleWidth = frame.width - normalSettings.title.Indent | 383 frame.titleWidth = defaultWidth - normalSettings.title.Indent |
379 | 384 |
380 if frame.title then | 385 if frame.title then |
381 frame.titleHeight = frame.title and (frame.title:GetStringHeight() + (frame.title.spacing or 0)*2) or 0 | 386 frame.titleHeight = frame.title and frame.title:GetStringHeight() or 0 |
387 if frame.titleHeight > 0 then | |
388 frame.titleHeight = frame.titleHeight + (frame.title.spacing or 0)*2 | |
389 end | |
390 | |
382 frame.title.spacing = frame.title.spacing or frame.title:GetSpacing() | 391 frame.title.spacing = frame.title.spacing or frame.title:GetSpacing() |
383 frame.title:SetPoint('LEFT', frame, 'LEFT', normalSettings.title.Indent) | 392 frame.title:SetPoint('LEFT', frame, 'LEFT', normalSettings.title.Indent) |
384 frame.title:SetPoint('TOP', frame, 'TOP', 0, -frame.title.spacing) | 393 frame.title:SetPoint('TOP', frame, 'TOP', 0, -frame.title.spacing) |
385 frame.title:SetWidth(frame.width) | 394 frame.title:SetWidth(frame.width) |
386 if frame.titlebg then | 395 if frame.titlebg then |
387 frame.titlebg:SetHeight(frame.titleHeight) | 396 frame.titlebg:SetHeight(frame.titleHeight) |
388 frame.titlebg:SetWidth(frame.width) | 397 frame.titlebg:SetWidth(frame.width) |
389 end | 398 end |
390 print(' title, textHeight', frame.titleHeight, 'indent', normalSettings.title.Indent, 'spacing', frame.title.spacing) | 399 print(' titleHeight', frame.titleHeight, 'indent', normalSettings.title.Indent, 'spacing', frame.title.spacing) |
391 else | 400 else |
392 frame.titleHeight = 0 | 401 frame.titleHeight = 0 |
393 end | 402 end |
394 | 403 |
395 if frame.status then | 404 if frame.status then |
396 frame.statusHeight = frame.status and (frame.status:GetStringHeight() + (frame.status.spacing or 0)*2) or 0 | 405 frame.statusHeight = frame.status and frame.status:GetStringHeight() or 0 |
406 if frame.statusHeight > 0 then | |
407 frame.statusHeight = frame.statusHeight + (frame.status.spacing or 0)*2 | |
408 end | |
409 | |
397 frame.status.spacing = frame.status.spacing or frame.status:GetSpacing() | 410 frame.status.spacing = frame.status.spacing or frame.status:GetSpacing() |
398 frame.status:SetWidth(frame.width) | 411 frame.status:SetWidth(frame.width) |
399 frame.status:SetPoint('LEFT', frame, 'LEFT', normalSettings.status.Indent, 0) | 412 frame.status:SetPoint('LEFT', frame, 'LEFT', normalSettings.status.Indent, 0) |
400 frame.status:SetPoint('TOPLEFT', frame.titlebg, 'BOTTOMLEFT', normalSettings.status.Indent, -frame.status.spacing) | 413 frame.status:SetPoint('TOP', frame.titlebg, 'BOTTOM', 0, 0) |
401 --frame.status:SetHeight(frame.statusHeight) | 414 frame.status:SetHeight(frame.statusHeight) |
402 if frame.statusbg then | 415 if frame.statusbg then |
403 | 416 |
404 frame.statusbg:SetHeight(frame.statusHeight) | 417 frame.statusbg:SetHeight(frame.statusHeight + (frame.attachmentHeight or 0)) |
405 frame.statusbg:SetWidth(frame.width) | 418 frame.statusbg:SetWidth(frame.width) |
406 end | 419 end |
407 print(' status, textHeight', frame.statusHeight, 'indent', normalSettings.status.Indent, 'spacing', frame.status.spacing) | 420 print(' status tHeight', frame.statusHeight, 'indent', normalSettings.status.Indent, 'spacing', frame.status.spacing) |
408 else | 421 else |
409 frame.statusHeight = 0 | 422 frame.statusHeight = 0 |
410 end | 423 end |
411 | 424 |
412 frame.height = frame.titleHeight + frame.statusHeight + (frame.attachmentHeight or 0) | 425 frame.height = frame.titleHeight + frame.statusHeight + (frame.attachmentHeight or 0) |
413 frame:SetSize(frame.width, frame.height) | 426 frame:SetSize(frame.width, frame.height) |
414 print(' sizing frame', frame.width, frame.height) | 427 print(' |cFF0088FFsizing frame', frame.width, frame.height) |
415 end | |
416 mod.UpdateWrapperStyle = function() | |
417 local c = mod.Conf.Wrapper | |
418 --Wrapper:ClearAllPoints() | |
419 --Wrapper:SetPoint(c.WrapperPoint, UIParent, c.WrapperPoint, c.WrapperFloatX, c.WrapperFloatY) | |
420 end | 428 end |
421 | 429 |
422 --- Argument containers | 430 --- Argument containers |
423 local o -- text flag | 431 local o -- text flag |
424 local a1, a2, a3, a4, b1, b2, b3, b4 -- color1, color2 | 432 local a1, a2, a3, a4, b1, b2, b3, b4 -- color1, color2 |