Mercurial > wow > buffalo2
comparison ObjectiveTracker/ObjectiveStyle.lua @ 23:e837384ac363
Separating objective tracker module
author | Nenue |
---|---|
date | Sun, 10 Apr 2016 04:35:32 -0400 |
parents | ObjectiveStyle.lua@d5ee940de273 |
children | 07ef62fe201f |
comparison
equal
deleted
inserted
replaced
22:9b3fa734abff | 23:e837384ac363 |
---|---|
1 local B = select(2,...).frame | |
2 local mod = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') | |
3 local print = B.print('SetStyle') | |
4 ------------------------------------------------------------- | |
5 --- Deals with swapping between different color palettes | |
6 --- | |
7 | |
8 local titleFont, textFont = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Regular.ttf]] | |
9 local titleSize, textSize = 16, 15 | |
10 local titleOutline, textOutline = "OUTLINE", "OUTLINE" | |
11 local titleSpacing, textSpacing = 3, 3 | |
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' | |
14 local headerFont, headerSize = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], 24 | |
15 local headerOutline, headerSpacing = 'OUTLINE', 2 | |
16 | |
17 | |
18 mod.defaults.Style = { | |
19 Format = { | |
20 Frame = { | |
21 Width = 270, | |
22 }, | |
23 title = { | |
24 Indent = 0, | |
25 Spacing = 0, | |
26 }, | |
27 status = { | |
28 Indent = 5, | |
29 Spacing = 0, | |
30 } | |
31 }, | |
32 FontBank = { | |
33 ['Normal'] = _G.VeneerCriteriaFontNormal, | |
34 ['Progress'] = _G.VeneerCriteriaFontProgress, | |
35 ['Complete'] = _G.VeneerCriteriaFontComplete, | |
36 ['Failed'] = _G.VeneerCriteriaFontFailed, | |
37 }, | |
38 Normal = { | |
39 title = { | |
40 TextColor = {1, 1, 1, 1}, | |
41 Width = 270, | |
42 Spacing = 0, | |
43 Indent = 2, | |
44 }, | |
45 titlebg = { | |
46 }, | |
47 status = { | |
48 Width = 270, | |
49 Spacing = 0, | |
50 }, | |
51 statusbg = { | |
52 }, | |
53 Frame = { | |
54 } | |
55 }, | |
56 Tracker = { | |
57 Normal = { | |
58 title = { | |
59 Font = {headerFont, headerSize, headerOutline}, Spacing = headerSpacing, | |
60 Indent = 2, | |
61 TextColor = {1, .9, .2, 1}, | |
62 }, | |
63 titlebg = { | |
64 Gradient = {'VERTICAL', MinColor = {0,0,0,0.25}, MaxColor = {0,0,0,.15}}, | |
65 } | |
66 } | |
67 }, | |
68 TrackerBlock = { | |
69 Normal = { | |
70 titlebg = { | |
71 Indent = 2, | |
72 Gradient = { 'HORIZONTAL', MinColor = {0.7, 0, 0.9, 1}, MaxColor = {.7, 0, 0.9, .1}}, | |
73 }, | |
74 title = { | |
75 TextColor = {1,1,1,1}, | |
76 Font = {titleFont, titleSize, titleOutline}, | |
77 Spacing = titleSpacing, | |
78 }, | |
79 status = { | |
80 TextColor = {1,1,1,1}, | |
81 Font = {textFont, textSize, textOutline}, | |
82 Spacing = textSpacing, | |
83 }, | |
84 statusbg = { | |
85 Gradient = { 'HORIZONTAL', MinColor = {0.2, .4, 1, 1}, MaxColor = {.7, 0, 0.9, .1}}, | |
86 } | |
87 }, | |
88 Daily = { | |
89 titlebg = { | |
90 Gradient = {'HORIZONTAL', MinColor = {0, .4, 1, 1}, MaxColor = {0, 0.4, 1, .1}, }, | |
91 }, | |
92 statusbg = { | |
93 Gradient = {'HORIZONTAL', MinColor = {0, .4, 1, 1}, MaxColor = {0, 0.35, .90, .1}, }, | |
94 }, | |
95 title = { | |
96 TextColor = {0.7,1,1,1}, | |
97 Font = {titleFont, titleSize, titleOutline}, | |
98 Spacing = titleSpacing, | |
99 }, | |
100 status = { | |
101 TextColor = {1,1,1,1}, | |
102 Font = {textFont, textSize, textOutline}, | |
103 Spacing = textSpacing, | |
104 }, | |
105 }, | |
106 Super = { | |
107 title = { | |
108 TextColor = {1,1,1,1}, | |
109 Font = {titleFont, titleSize, titleOutline}, | |
110 Spacing = titleSpacing, BackgroundFullWidth = true | |
111 }, | |
112 titlebg = { | |
113 Gradient = { 'HORIZONTAL', MinColor = {0, .7, .6, 1}, MaxColor = {0, .7, .6, 1}}, | |
114 }, | |
115 status = { | |
116 TextColor = {1,1,1,1}, | |
117 Font = {textFont, textSize, textOutline}, | |
118 Spacing = textSpacing, | |
119 }, | |
120 statusbg = { | |
121 Gradient = { 'HORIZONTAL', MinColor = {0, .7, .6, 1}, MaxColor = {0, .7, .6, 1} }, | |
122 }, | |
123 }, | |
124 MouseDown = { | |
125 title = { | |
126 Font = {titleFont, titleSize, titleOutline}, | |
127 Spacing = titleSpacing, | |
128 }, | |
129 titlebg = { | |
130 Gradient = {'HORIZONTAL', MinColor = {0.2, .4, 1, 1}, MaxColor = {0.2, .4, 1, 1}, }, | |
131 }, | |
132 status = { | |
133 Font = {textFont, textSize, textOutline}, | |
134 Spacing = textSpacing, | |
135 }, | |
136 statusbg = { | |
137 Gradient = {'HORIZONTAL', MinColor = {0.2, .4, 1, 1}, MaxColor = {0.2, .4, 1, 1}, }, | |
138 } | |
139 }, | |
140 Complete = { | |
141 title = { | |
142 TextColor = {1,1,1,1}, | |
143 Font = {titleFont, titleSize, titleOutline}, Spacing = titleSpacing, | |
144 }, | |
145 titlebg = { | |
146 Gradient = {'HORIZONTAL', MinColor = {0, 1, 0, 1}, MaxColor = {0, 1, 0, 1}, }, | |
147 }, | |
148 status = { | |
149 TextColor = {1,1,1,1}, | |
150 Font = {textFont, textSize, textOutline}, Spacing = textSpacing, | |
151 }, | |
152 statusbg = { | |
153 Gradient = {'HORIZONTAL', MinColor = {0, 1, 0, 1}, MaxColor = {0, 1, 0, 1}, }, | |
154 } | |
155 }, | |
156 AutoQuest = { | |
157 Normal = { | |
158 titlebg = { | |
159 Indent = 2, | |
160 Gradient = {'HORIZONTAL', MinColor = {0.2, .4, 1, 1}, MaxColor = {.7, 0, 0.9, 1}}, | |
161 }, | |
162 title = { | |
163 TextColor = {1,1,1,1}, | |
164 Font = {titleFont, titleSize, titleOutline}, | |
165 Spacing = titleSpacing, | |
166 }, | |
167 status = { | |
168 TextColor = {0,1,0,1}, | |
169 Font = {textFont, textSize, textOutline}, | |
170 Spacing = textSpacing, | |
171 }, | |
172 statusbg = { | |
173 Gradient = {'HORIZONTAL', MinColor = {0.2, .4, 1, 1}, MaxColor = {.7, 0, 0.9, 1}}, | |
174 } | |
175 }, | |
176 }, | |
177 Cheevs = { | |
178 Normal = { | |
179 | |
180 title = { | |
181 Font = {titleFont, titleSize, titleOutline}, | |
182 Spacing = titleSpacing, | |
183 }, | |
184 titlebg = { | |
185 Gradient = {'HORIZONTAL', MinColor = {0.2, .4, 1, 1}, MaxColor = {.7, 0, 0.9, 1}}, | |
186 | |
187 }, | |
188 status = { | |
189 Font = {textFont, textSize, textOutline}, | |
190 Spacing = textSpacing, | |
191 }, | |
192 statusbg = { | |
193 Gradient = {'HORIZONTAL', MinColor = {0.2, .4, 1, 1}, MaxColor = {.7, 0, 0.9, 1}}, | |
194 }, | |
195 }, | |
196 Complete = { | |
197 title = { | |
198 Font = {titleFont, titleSize, titleOutline}, | |
199 Spacing = titleSpacing, | |
200 }, | |
201 titlebg = { | |
202 Gradient = {'HORIZONTAL', MinColor = {0.2, .4, 1, 1}, MaxColor = {.7, 0, 0.9, 1}}, | |
203 }, | |
204 status = { | |
205 Font = {textFont, textSize, textOutline}, | |
206 Spacing = textSpacing, | |
207 }, | |
208 statusbg = { | |
209 Gradient = {'HORIZONTAL', MinColor = {0.2, .4, 1, 1}, MaxColor = {.7, 0, 0.9, 1}}, | |
210 }, | |
211 }, | |
212 } | |
213 } | |
214 } | |
215 | |
216 local style_cache_func = {} | |
217 local block_vars = { | |
218 ['titleSize'] = {'titleWidth', 'titleHeight'}, | |
219 ['FrameSize'] = {'width', 'height'} | |
220 } | |
221 local attrib_vars = { | |
222 ['Font'] = {'height'}, | |
223 } | |
224 | |
225 mod.BlockStyleCache = {} | |
226 local style_cache = mod.BlockStyleCache | |
227 mod.regions = {} | |
228 mod.regionStyles = {} | |
229 mod.SetBlockStyle = function(frame, frameType, ...) | |
230 -- var names intended to reflect argument order | |
231 print('|cFFFFFF00'..frame:GetName()..'|r', frameType, ...) | |
232 --@debug@ | |
233 local c = mod.defaults.Normal | |
234 local style_list = {... } | |
235 local styleName = frameType .. '-' .. table.concat(style_list,'') | |
236 local previousClass = {mod.Conf.Style[frameType] } | |
237 local previousClassString = {'frame' } | |
238 local parentName | |
239 | |
240 if not style_cache[styleName] then | |
241 local style = {} | |
242 | |
243 --[[ | |
244 if mod.defaults.Style[frameType] then | |
245 print(' setting style class |cFF00FFFF'..frameType) | |
246 else | |
247 print(' resorting to class Normal (missing |cFFFF8800'.. frameType..'|r)') | |
248 end | |
249 --]] | |
250 local normal = mod.defaults.Style.Normal | |
251 local root = mod.defaults.Style[frameType] or normal | |
252 for i, className in ipairs(style_list) do | |
253 print('|cFF00FF00'..i..'|r', className) | |
254 local class = normal | |
255 local childClass | |
256 if previousClass then | |
257 for i = #previousClass, 1, -1 do | |
258 print('checking if '..className..' child of '.. previousClassString[i]) | |
259 if previousClass[i][className] then | |
260 print(' it is!') | |
261 childClass = previousClass[i][className] | |
262 parentName = previousClassString[i] | |
263 break | |
264 end | |
265 end | |
266 end | |
267 if childClass then | |
268 class = childClass | |
269 print(' ChildClass '..parentName..'.|cFFFF0088'.. className .. '|r') | |
270 elseif root[className] then | |
271 class = root[className] | |
272 print(' SubClass |cFF0088FF'.. className .. '|r') | |
273 elseif normal[className] then | |
274 class = normal[className] | |
275 print(' SubClass Normal.|cFFFF0088'..className..'|r') | |
276 else | |
277 --print(' SubClass not found '..className..'') | |
278 end | |
279 tinsert(previousClass, class) | |
280 tinsert(previousClassString, className) | |
281 | |
282 for elementName, element in pairs(class) do | |
283 if not elementName:match('^%u') then | |
284 --print(' scanning Element |cFF8800FF'.. elementName ..'|r') | |
285 if not style[elementName] then | |
286 style[elementName] = {} | |
287 end | |
288 for key, value in pairs(element) do | |
289 if mod.SetBlockAttribute[key] then | |
290 --print(' |cFF00FF00'..elementName..'|r.|cFF00FFFF'..key..' =', (type(value) == 'table' and ('{'..table.concat(value,', ')..'}') or tostring(value))) | |
291 style[elementName][key] = value | |
292 end | |
293 | |
294 end | |
295 end | |
296 | |
297 end | |
298 end | |
299 | |
300 for k, elements in pairs(mod.defaults.Style.Normal) do | |
301 if not style[k] and type(elements) ~= 'table' then | |
302 style[k] = elements | |
303 end | |
304 end | |
305 | |
306 | |
307 --[[print('result for: ', frame:GetName()) | |
308 for k,v in pairs(style) do | |
309 if type(v) == 'table' and not k:match('^%u') then | |
310 for kk, vv in pairs(v) do | |
311 --print(' |cFFFFFF00'..k..'|r.|cFF00FF00'..kk..'|r =', (type(vv) == 'table' and ('{'..table.concat(vv,', ')..'}') or tostring(vv))) | |
312 end | |
313 else | |
314 --print(' |cFFFFFFFF' .. k ..'|r =', tostring(v)) | |
315 end | |
316 end | |
317 --]] | |
318 print('saving |cFFFFFF00'..styleName) | |
319 style_cache[styleName] = style | |
320 else | |
321 | |
322 print('using |cFFFF00FF'..styleName) | |
323 end | |
324 | |
325 local style = style_cache[styleName] | |
326 | |
327 if not style_cache_func[styleName] then | |
328 local code = | |
329 "return function (frame)\n".. | |
330 " local func = Veneer.ObjectiveTracker.SetBlockAttribute\n".. | |
331 " local cache = Veneer.ObjectiveTracker.BlockStyleCache" | |
332 --.. " print('CacheFunc', '|cFFFFFF00SET|r "..styleName.." |cFFFFFF00ON|r', frame:GetName()) " | |
333 | |
334 for elementName, styleset in pairs(style) do | |
335 code = code .. | |
336 "\n if frame['"..elementName.."'] then" | |
337 | |
338 for attributeName, value in pairs(styleset) do | |
339 if mod.SetBlockAttribute[attributeName] then | |
340 --print(' add function '..elementName..':'.. attributeName ..'(', (type(value) == 'table' and ('{'..table.concat(value,', ')..'}') or tostring(value)), ')') | |
341 | |
342 | |
343 --mod.SetBlockAttribute[attributeName](region, value) | |
344 code = code | |
345 --.. "\n print('CacheFunc', ' applying', '|cFF00FFFF" .. attributeName .. "|r to', '|cFF0088FF"..elementName.."|r', cache['"..styleName.."']['"..elementName.."']['".. attributeName .."'])" | |
346 .. "\n\n func['" .. attributeName .. "'](frame['"..elementName.."'],".. | |
347 " cache['"..styleName.."']['"..elementName.."']['".. attributeName .."'])" | |
348 | |
349 --- Set any frame.blah variables used in Updates | |
350 if block_vars[elementName .. attributeName] then | |
351 --print('|cFF008800BVar|r', elementName..attributeName) | |
352 for i, blockKey in ipairs(block_vars[elementName .. attributeName]) do | |
353 --print(' assigning |cFF008800'..blockKey..'|r') | |
354 frame[blockKey] = (type(value) == 'table') and value[i] or value | |
355 end | |
356 end | |
357 | |
358 end | |
359 end | |
360 code = code .. | |
361 "\n else".. | |
362 --"\n print('CacheFunc', ' |cFFFF4400missing', frame:GetName()..'."..elementName.."')".. | |
363 "\n end" | |
364 end | |
365 code = code .. "\nend" | |
366 local result = assert(loadstring(code)) | |
367 --print('storing style func', styleName, result()) | |
368 style_cache_func[styleName] = result() | |
369 | |
370 end | |
371 style_cache_func[styleName](frame) | |
372 | |
373 --- Hardcoding the sizing vars for sanity | |
374 local defaultWidth = mod.Conf.Wrapper.Width | |
375 local normalSettings = mod.defaults.Style.Format | |
376 frame.width = defaultWidth | |
377 frame.statusWidth = defaultWidth - normalSettings.status.Indent | |
378 frame.titleWidth = defaultWidth - normalSettings.title.Indent | |
379 frame.attachmentHeight = frame.attachmentHeight or 0 | |
380 | |
381 if frame.title then | |
382 frame.titleHeight = frame.title and frame.title:GetStringHeight() or 0 | |
383 if frame.titleHeight > 0 then | |
384 print('add spacing to', frame.titleHeight) | |
385 frame.titleHeight = frame.titleHeight + (frame.title.spacing or 0)*2 | |
386 end | |
387 | |
388 frame.title.spacing = frame.title.spacing or frame.title:GetSpacing() | |
389 frame.title:SetPoint('LEFT', frame, 'LEFT', normalSettings.title.Indent) | |
390 frame.title:SetPoint('TOP', frame, 'TOP', 0, -frame.title.spacing) | |
391 frame.title:SetWidth(frame.width) | |
392 if frame.titlebg then | |
393 frame.titlebg:SetHeight(frame.titleHeight) | |
394 frame.titlebg:SetWidth(frame.width) | |
395 end | |
396 print(' titleHeight', frame.titleHeight, 'indent', normalSettings.title.Indent, 'spacing', frame.title.spacing) | |
397 print(' -- text:', frame.title:GetSize()) | |
398 print(' -- bg:', frame.titlebg:GetSize()) | |
399 | |
400 else | |
401 frame.titleHeight = 0 | |
402 end | |
403 | |
404 | |
405 if frame.status and (frame.status:GetText() or frame.attachmentHeight > 0) then | |
406 frame.statusHeight = frame.status and frame.status:GetStringHeight() or 0 | |
407 if frame.statusHeight > 0 then | |
408 frame.statusHeight = frame.statusHeight + (frame.status.spacing or 0)*2 | |
409 end | |
410 | |
411 frame.status.spacing = frame.status.spacing or frame.status:GetSpacing() | |
412 | |
413 frame.status:SetWidth(frame.width) | |
414 frame.status:SetPoint('LEFT', frame, 'LEFT', normalSettings.status.Indent, 0) | |
415 frame.status:SetPoint('TOP', frame.titlebg, 'BOTTOM', 0, 0) | |
416 --frame.status:SetHeight(frame.statusHeight) | |
417 if frame.statusbg then | |
418 | |
419 --frame.statusbg:SetHeight(frame.statusHeight + (frame.attachmentHeight or 0)) | |
420 --frame.statusbg:SetPoint('BOTTOM', frame, 'BOTTOM', 0, 0) | |
421 frame.statusbg:SetWidth(frame.width) | |
422 end | |
423 print(' status tHeight', frame.statusHeight, 'indent', normalSettings.status.Indent, 'spacing', frame.status.spacing) | |
424 else | |
425 if frame.status then | |
426 frame.status:Hide() | |
427 end | |
428 if frame.statusbg then | |
429 frame.statusbg:Hide() | |
430 end | |
431 frame.statusHeight = 0 | |
432 end | |
433 | |
434 frame.height = frame.titleHeight + frame.statusHeight + (frame.attachmentHeight or 0) | |
435 frame:SetSize(frame.width, frame.height) | |
436 print(' |cFF0088FFsizing frame', frame.width, frame.height) | |
437 end | |
438 | |
439 --- Argument containers | |
440 local o -- text flag | |
441 local a1, a2, a3, a4, b1, b2, b3, b4 -- color1, color2 | |
442 local f1, f2, f3 -- font | |
443 local w1, w2 -- size | |
444 local p1, p2, p3, x, y -- path/point args | |
445 mod.SetBlockAttribute = {} | |
446 local sb = mod.SetBlockAttribute | |
447 local print = B.print('Attribute') | |
448 sb.Gradient = function(region, value) | |
449 print('|cFF8844FFGradient|r', region:GetName(), unpack(value)) | |
450 o = value[1] | |
451 a1, a2, a3, a4 = unpack(value.MinColor) | |
452 b1, b2, b3, b4 = unpack(value.MaxColor) | |
453 region:SetVertexColor(1,1,1) | |
454 region:SetTexture(1,1,1,1) | |
455 region:SetGradientAlpha(o, a1, a2, a3, a4, b1, b2, b3, b4) | |
456 end | |
457 | |
458 sb.Background = function(region, value) | |
459 print('|cFF0088FFBackground|r', unpack(value)) | |
460 region:SetVertexColor(1,1,1) -- reset | |
461 region:SetTexture(unpack(value)) | |
462 end | |
463 sb.BackgroundComplex = function (region, value) | |
464 local left, tile, right = value.Left, value.Tile, value.Right | |
465 | |
466 end | |
467 sb.Font = function(region, value) | |
468 f1, f2, f3 = unpack(value) | |
469 print('|cFFFFFF00Font|r', f1, f2, f3) | |
470 region:SetFont(f1, f2, f3) | |
471 end | |
472 | |
473 sb.Spacing = function(region, value) | |
474 print('FontSpacing', region:GetName(), value) | |
475 region:SetSpacing(value) | |
476 region.spacing = value | |
477 end | |
478 | |
479 sb.TextColor = function(region, value) | |
480 a1, a2, a3, a4 = unpack(value) | |
481 print('TextColor', a1, a2, a3, a4) | |
482 region:SetTextColor(a1, a2, a3, a4) | |
483 end | |
484 sb.Texture = function(region, value) | |
485 | |
486 p1, a1, a2, a3, a4 = unpack(value) | |
487 print('Texture', p1, a1, a2, a3, a4) | |
488 region:SetTexture(p1) | |
489 if a1 then | |
490 region:SetTexCoord(a1, a2, a3, a4) | |
491 end | |
492 end | |
493 sb.Width = function(region, value) | |
494 w1 = value | |
495 region:SetWidth(w1) | |
496 end | |
497 | |
498 sb.Height = function(region, value) | |
499 w2 = value | |
500 region:SetHeight(w2) | |
501 end | |
502 sb.Size = function(region, value) | |
503 w1, w2 = unpack(value) | |
504 region:SetSize(w1, w2) | |
505 end | |
506 |