Mercurial > wow > buffalo2
comparison ObjectiveStyle.lua @ 10:f03c75f63566
ObjectiveStyle & ObjectiveFrame
- abstract aesthetic details away from ObjectiveFrame
- revise SetBlockStyle into a more general algorithm for every frame
- implement caching of resolved attribute combinations
- use loadstring functions to store resolved attributes and call upon those when, for example, a MouseUp leads a tracker block to restore its original style
| author | Nenue |
|---|---|
| date | Sat, 02 Apr 2016 03:19:25 -0400 |
| parents | |
| children | fb80e365bab3 |
comparison
equal
deleted
inserted
replaced
| 9:2698173edd40 | 10:f03c75f63566 |
|---|---|
| 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 itemButtonSize, itemButtonSpacing = 36, 1 | |
| 9 local wrapperPosition = {'RIGHT', UIParent, 'RIGHT', -84, 0} | |
| 10 local titleFont, textFont = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Regular.ttf]] | |
| 11 local titleSize, textSize = 15, 15 | |
| 12 local titleOutline, textOutline = "OUTLINE", "OUTLINE" | |
| 13 local titleSpacing, textSpacing = 4, 3 | |
| 14 local textIndent = 5 | |
| 15 local wrapperMaxWidth, wrapperMaxHeight = 280, 490 -- these are the hard bounds, actual *Height variables are changed | |
| 16 local wrapperHeadFont, wrapperHeadSize, wrapperHeadOutline = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], 16, 'NONE' | |
| 17 local headerFont, headerSize, headerHeight = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], 18, 24 | |
| 18 local headerOutline, headerColor, headerSpacing = 'OUTLINE', {1,1,1,1}, 2 | |
| 19 | |
| 20 mod.defaults.ObjectiveWrapper = { | |
| 21 ObjectiveTrackerFloat = {'BOTTOM', 'RIGHT'}, | |
| 22 ObjectiveTrackerParent = 'DebuffButton', | |
| 23 ObjectiveTrackerSize = {250, 600}, | |
| 24 ObjectiveWrapperParent = '', | |
| 25 } | |
| 26 mod.defaults.Style = { | |
| 27 FontBank = { | |
| 28 ['Normal'] = _G.VeneerCriteriaFontNormal, | |
| 29 ['Progress'] = _G.VeneerCriteriaFontProgress, | |
| 30 ['Complete'] = _G.VeneerCriteriaFontComplete, | |
| 31 ['Failed'] = _G.VeneerCriteriaFontFailed, | |
| 32 }, | |
| 33 Normal = { | |
| 34 title = { | |
| 35 TextColor = {1, 1, 1, 1}, | |
| 36 Width = 270, | |
| 37 }, | |
| 38 titlebg = { | |
| 39 Background = {0, 0, 0, 1}, | |
| 40 Width = 270, | |
| 41 }, | |
| 42 status = { | |
| 43 Width = 270, | |
| 44 }, | |
| 45 statusbg = { | |
| 46 Width = 270, | |
| 47 }, | |
| 48 Frame = { | |
| 49 Width = 270, | |
| 50 } | |
| 51 }, | |
| 52 Wrapper = { | |
| 53 Frame = { | |
| 54 Point = {wrapperPosition}, | |
| 55 MaxSize = {wrapperMaxWidth, wrapperMaxHeight}, | |
| 56 BackgroundComplex = {Left = {'', 0, 0.4, 0,1, 100}, Right={'', 0.6,1,0,1}, Tile = {'', 0.4,.6,0,1, 100}}, }, | |
| 57 title = { | |
| 58 Font = {wrapperHeadFont, wrapperHeadSize, wrapperHeadOutline}, | |
| 59 Spacing = 4,} | |
| 60 }, | |
| 61 Tracker = { | |
| 62 Normal = { | |
| 63 title = { | |
| 64 Font = {headerFont, headerSize, headerOutline}, Spacing = headerSpacing, | |
| 65 }, | |
| 66 titlebg = { | |
| 67 Gradient = {MinColor = {0,0,0,0.7}, MaxColor = {0,0,0,.35}}, | |
| 68 } | |
| 69 } | |
| 70 }, | |
| 71 TrackerBlock = { | |
| 72 Normal = { | |
| 73 titlebg = { | |
| 74 Gradient = { MinColor = {0.2, .4, 1, 0.45}, MaxColor = {.7, 0, 0.9, .19}}, | |
| 75 }, | |
| 76 title = { | |
| 77 Font = {titleFont, titleSize, titleOutline}, | |
| 78 Spacing = titleSpacing, | |
| 79 }, | |
| 80 status = { | |
| 81 Font = {textFont, textSize, textOutline}, Spacing = textSpacing, | |
| 82 }, | |
| 83 statusbg = { | |
| 84 Gradient = { MinColor = {0.2, .4, 1, 0.25}, MaxColor = {.7, 0, 0.9, .12}}, | |
| 85 } | |
| 86 }, | |
| 87 Super = { | |
| 88 title = { | |
| 89 Font = {titleFont, titleSize, titleOutline}, | |
| 90 Spacing = titleSpacing, BackgroundFullWidth = true | |
| 91 }, | |
| 92 titlebg = { | |
| 93 Gradient = { MinColor = {0, .7, .6, .8}, MaxColor = {0, .7, .6, 0.2}}, | |
| 94 }, | |
| 95 status = { | |
| 96 Font = {textFont, textSize, textOutline}, Spacing = textSpacing, | |
| 97 }, | |
| 98 statusbg = { | |
| 99 Gradient = { MinColor = {0, .7, .6, 0.5}, MaxColor = {0, .7, .6, 0.1} }, | |
| 100 }, | |
| 101 }, | |
| 102 MouseDown = { | |
| 103 title = { | |
| 104 Font = {titleFont, titleSize, titleOutline}, | |
| 105 Spacing = titleSpacing, | |
| 106 }, | |
| 107 titlebg = { | |
| 108 Gradient = { MinColor = {0.2, .4, 1, 1}, MaxColor = {0.2, .4, 1, .4}, }, | |
| 109 BackgroundFullWidth = true, | |
| 110 }, | |
| 111 status = { | |
| 112 Font = {textFont, textSize, textOutline}, | |
| 113 Spacing = textSpacing, | |
| 114 }, | |
| 115 statusbg = { | |
| 116 BackgroundFullWidth = true, | |
| 117 Gradient = { MinColor = {0.2, .4, 1, 1}, MaxColor = {0.2, .4, 1, .2}, }, | |
| 118 } | |
| 119 }, | |
| 120 Complete = { | |
| 121 title = { | |
| 122 Font = {titleFont, titleSize, titleOutline}, Spacing = titleSpacing, | |
| 123 }, | |
| 124 titlebg = { | |
| 125 Gradient = { MinColor = {0, 1, 0, 0.34}, MaxColor = {0, 1, 0, .17}, }, | |
| 126 BackgroundFullWidth = true | |
| 127 }, | |
| 128 status = { | |
| 129 Font = {textFont, textSize, textOutline}, Spacing = textSpacing, | |
| 130 }, | |
| 131 statusbg = { | |
| 132 Gradient = { MinColor = {0, 1, 0, .25}, MaxColor = {0, 1, 0, 0.12}, }, | |
| 133 BackgroundFullWidth = true | |
| 134 } | |
| 135 }, | |
| 136 Cheev = { | |
| 137 Normal = { | |
| 138 | |
| 139 title = { | |
| 140 Font = {titleFont, titleSize, titleOutline}, | |
| 141 Spacing = titleSpacing, | |
| 142 }, | |
| 143 titlebg = { | |
| 144 Gradient = { MinColor = {0.2, .4, 1, 0.45}, MaxColor = {.7, 0, 0.9, .19}}, | |
| 145 | |
| 146 }, | |
| 147 status = { | |
| 148 Font = {textFont, textSize, textOutline}, | |
| 149 Spacing = textSpacing, | |
| 150 }, | |
| 151 statusbg = { | |
| 152 Gradient = { MinColor = {0.2, .4, 1, 0.25}, MaxColor = {.7, 0, 0.9, .12}}, | |
| 153 }, | |
| 154 }, | |
| 155 Complete = { | |
| 156 title = { | |
| 157 Font = {titleFont, titleSize, titleOutline}, | |
| 158 Spacing = titleSpacing, | |
| 159 }, | |
| 160 titlebg = { | |
| 161 Gradient = { MinColor = {0.2, .4, 1, 0.45}, MaxColor = {.7, 0, 0.9, .19}}, | |
| 162 }, | |
| 163 status = { | |
| 164 Font = {textFont, textSize, textOutline}, | |
| 165 Spacing = textSpacing, | |
| 166 }, | |
| 167 statusbg = { | |
| 168 Gradient = { MinColor = {0.2, .4, 1, 0.25}, MaxColor = {.7, 0, 0.9, .12}}, | |
| 169 }, | |
| 170 }, | |
| 171 } | |
| 172 } | |
| 173 } | |
| 174 | |
| 175 local style_cache_func = {} | |
| 176 local block_vars = { | |
| 177 ['titleSize'] = {'titleWidth', 'titleHeight'}, | |
| 178 ['FrameSize'] = {'width', 'height'} | |
| 179 } | |
| 180 local attrib_vars = { | |
| 181 ['Font'] = {'height'}, | |
| 182 } | |
| 183 | |
| 184 mod.BlockStyleCache = {} | |
| 185 local style_cache = mod.BlockStyleCache | |
| 186 mod.regions = {} | |
| 187 mod.regionStyles = {} | |
| 188 mod.SetBlockStyle = function(frame, frameType, ...) | |
| 189 -- var names intended to reflect argument order | |
| 190 --@debug@ | |
| 191 local c = mod.defaults.Normal | |
| 192 local style_list = {... } | |
| 193 local styleName = frameType .. '-' .. table.concat(style_list,'') | |
| 194 | |
| 195 if not style_cache[styleName] then | |
| 196 local style = {} | |
| 197 | |
| 198 if mod.defaults.Style[frameType] then | |
| 199 print(' setting style class |cFF00FFFF'..frameType) | |
| 200 else | |
| 201 print(' resorting to class Normal (missing |cFFFF8800'.. frameType..'|r)') | |
| 202 end | |
| 203 local normal = mod.defaults.Style.Normal | |
| 204 local root = mod.defaults.Style[frameType] or normal | |
| 205 for i, className in ipairs(style_list) do | |
| 206 local class = root[className] or normal[className] or root | |
| 207 if root[className] then | |
| 208 | |
| 209 print(' SubClass |cFF0088FF'.. className .. '|r') | |
| 210 elseif normal[className] then | |
| 211 print(' SubClass Normal.|cFFFF0088'..className..'|r') | |
| 212 else | |
| 213 print(' SubClass Normal') | |
| 214 end | |
| 215 for elementName, element in pairs(class) do | |
| 216 if not elementName:match('^%u') then | |
| 217 print(' scanning Element |cFF8800FF'.. elementName ..'|r') | |
| 218 if not style[elementName] then | |
| 219 style[elementName] = {} | |
| 220 end | |
| 221 for key, value in pairs(element) do | |
| 222 if mod.SetBlockAttribute[key] then | |
| 223 print(' |cFF00FF00'..elementName..'|r.|cFF00FFFF'..key..' =', (type(value) == 'table' and ('{'..table.concat(value,', ')..'}') or tostring(value))) | |
| 224 style[elementName][key] = value | |
| 225 end | |
| 226 | |
| 227 end | |
| 228 end | |
| 229 | |
| 230 end | |
| 231 | |
| 232 end | |
| 233 | |
| 234 for k, elements in pairs(mod.defaults.Style.Normal) do | |
| 235 if not style[k] and type(elements) ~= 'table' then | |
| 236 style[k] = elements | |
| 237 end | |
| 238 end | |
| 239 | |
| 240 | |
| 241 print('result for: ', frame:GetName()) | |
| 242 for k,v in pairs(style) do | |
| 243 if type(v) == 'table' and not k:match('^%u') then | |
| 244 for kk, vv in pairs(v) do | |
| 245 print(' |cFFFFFF00'..k..'|r.|cFF00FF00'..kk..'|r =', tostring(vv)) | |
| 246 end | |
| 247 else | |
| 248 print(' |cFFFFFFFF' .. k ..'|r =', tostring(v)) | |
| 249 end | |
| 250 end | |
| 251 style_cache[styleName] = style | |
| 252 else | |
| 253 print('Cache hit: ', styleName) | |
| 254 end | |
| 255 | |
| 256 local style = style_cache[styleName] | |
| 257 | |
| 258 if not style_cache_func[styleName] then | |
| 259 local code = | |
| 260 "return function (frame)\n".. | |
| 261 " local func = Veneer.ObjectiveTracker.SetBlockAttribute\n".. | |
| 262 " local cache = Veneer.ObjectiveTracker.BlockStyleCache" .. | |
| 263 " print('CacheFunc', '|cFFFFFF00SET|r "..styleName.." |cFFFFFF00ON|r', frame:GetName()) " | |
| 264 | |
| 265 for elementName, styleset in pairs(style) do | |
| 266 code = code .. | |
| 267 "\n if frame['"..elementName.."'] then" | |
| 268 | |
| 269 for attributeName, value in pairs(styleset) do | |
| 270 if mod.SetBlockAttribute[attributeName] then | |
| 271 print(' '..elementName..':'.. attributeName ..'(', value, ')') | |
| 272 | |
| 273 | |
| 274 --mod.SetBlockAttribute[attributeName](region, value) | |
| 275 code = code .. "\n print('CacheFunc', ' applying', '|cFF00FFFF" .. attributeName .. "|r to', '|cFF0088FF"..elementName.."|r', cache['"..styleName.."']['"..elementName.."']['".. attributeName .."'])" .. | |
| 276 "\n\n func['" .. attributeName .. "'](frame['"..elementName.."'],".. | |
| 277 " cache['"..styleName.."']['"..elementName.."']['".. attributeName .."'])" | |
| 278 | |
| 279 --- Set any frame.blah variables used in Updates | |
| 280 if block_vars[elementName .. attributeName] then | |
| 281 print('|cFF008800BVar|r', elementName..attributeName) | |
| 282 for i, blockKey in ipairs(block_vars[elementName .. attributeName]) do | |
| 283 print(' assigning |cFF008800'..blockKey..'|r') | |
| 284 frame[blockKey] = (type(value) == 'table') and value[i] or value | |
| 285 end | |
| 286 end | |
| 287 | |
| 288 end | |
| 289 end | |
| 290 code = code .. | |
| 291 "\n else".. | |
| 292 "\n print('CacheFunc', ' |cFFFF4400missing', frame:GetName()..'."..elementName.."')".. | |
| 293 "\n end" | |
| 294 end | |
| 295 code = code .. "\nend" | |
| 296 local result = assert(loadstring(code)) | |
| 297 print('storing style func', styleName, result()) | |
| 298 style_cache_func[styleName] = result() | |
| 299 | |
| 300 else | |
| 301 print('Cache function hit:', styleName) | |
| 302 end | |
| 303 style_cache_func[styleName](frame) | |
| 304 | |
| 305 | |
| 306 --print("Generated func = function()\n",code, "\nend") | |
| 307 --local cache_func[styleName] = loadstring(code) | |
| 308 | |
| 309 -- todo: remove hardcode and rely on attribute handler | |
| 310 if frame.status then | |
| 311 frame.status:SetWidth(270) | |
| 312 end | |
| 313 if frame.title then | |
| 314 frame.title:SetWidth(270) | |
| 315 end | |
| 316 | |
| 317 | |
| 318 frame.titleHeight = frame.title and (frame.title:GetStringHeight() + frame.title.spacing*2) or 0 | |
| 319 frame.statusHeight = frame.status and (frame.status:GetStringHeight() + frame.status.spacing*2 + frame.attachmentHeight) or 0 | |
| 320 frame.height = frame.titleHeight + frame.statusHeight | |
| 321 frame.width = 270 | |
| 322 | |
| 323 | |
| 324 if frame.status then | |
| 325 print('status ', frame.statusHeight) | |
| 326 frame.status:SetHeight(frame.statusHeight) | |
| 327 if frame.statusbg then | |
| 328 | |
| 329 print('statusbg', frame.statusHeight) | |
| 330 frame.statusbg:SetHeight(frame.statusHeight) | |
| 331 frame.statusbg:SetWidth(frame.width) | |
| 332 end | |
| 333 end | |
| 334 if frame.title then | |
| 335 print('title ',frame.titleHeight) | |
| 336 frame.title:SetHeight(frame.titleHeight) | |
| 337 if frame.titlebg then | |
| 338 print('titlebg',frame.titleHeight) | |
| 339 frame.titlebg:SetHeight(frame.titleHeight) | |
| 340 frame.titlebg:SetWidth(frame.width) | |
| 341 end | |
| 342 end | |
| 343 print('sizing frame', frame.width, frame.height) | |
| 344 frame:SetSize(frame.width, frame.height) | |
| 345 print(frame:GetSize()) | |
| 346 --[[ | |
| 347 local titleSpacing, titleSpacing2 = c.Title.Spacing, (c.Title.Spacing * 2) | |
| 348 local textSpacing, textSpacing2 = c.Text.Spacing, (c.Text.Spacing * 2) | |
| 349 | |
| 350 block.title:SetSpacing(titleSpacing) | |
| 351 block.objectives:SetSpacing(textSpacing) | |
| 352 block.objectives:SetWordWrap(true) | |
| 353 | |
| 354 local titleHeight, textHeight = block.title:GetStringHeight(), block.objectives:GetStringHeight() + block.attachmentHeight | |
| 355 local blockHeight = titleHeight + titleSpacing2 + textHeight + textSpacing2 | |
| 356 local blockWidth = wrapperMaxWidth | |
| 357 | |
| 358 block.titlebg:SetSize(min(w1, w2), titleHeight + titleSpacing2) | |
| 359 block.bg:SetSize(w1, textHeight + textSpacing2) | |
| 360 block:SetSize(blockWidth, blockHeight) | |
| 361 | |
| 362 block.title:SetPoint('TOPLEFT', block.titlebg, 'TOPLEFT', 0, -titleSpacing) | |
| 363 block.objectives:SetPoint('TOPLEFT', block.titlebg, 'BOTTOMLEFT', textIndent, -textSpacing) | |
| 364 | |
| 365 -- store | |
| 366 block.titleHeight = titleHeight | |
| 367 block.textHeight = textHeight | |
| 368 block.width = blockWidth | |
| 369 block.height = blockHeight | |
| 370 --]] | |
| 371 --print(' |cFF00FFFF'..block:GetName()..'|r:|cFF0088FFSetStyle|r(', blockWidth, 'x', blockHeight, '(textH', textHeight,', titleH', titleHeight, ')') | |
| 372 end | |
| 373 | |
| 374 --- Argument containers | |
| 375 local o = "" -- text flag | |
| 376 local a1, a2, a3, a4, b1, b2, b3, b4 = 0,0,0,1, 0,0,0,1 -- color1, color2 | |
| 377 local f1, f2, f3 = "", 0, "" -- font | |
| 378 local w1, w2 = 0, 0 -- size | |
| 379 local p1, p2, p3, x, y = "", "", "", 0, 0 -- path/point args | |
| 380 mod.SetBlockAttribute = {} | |
| 381 local sb = mod.SetBlockAttribute | |
| 382 local print = B.print('Attribute') | |
| 383 sb.Gradient = function(region, value) | |
| 384 print('|cFF8844FFGradient|r', region:GetName(), unpack(value)) | |
| 385 o = 'HORIZONTAL' | |
| 386 a1, a2, a3, a4 = unpack(value.MinColor) | |
| 387 b1, b2, b3, b4 = unpack(value.MaxColor) | |
| 388 region:SetVertexColor(1,1,1) | |
| 389 region:SetTexture(1,1,1,1) | |
| 390 region:SetGradientAlpha(o, a1, a2, a3, a4, b1, b2, b3, b4) | |
| 391 end | |
| 392 | |
| 393 sb.Background = function(region, value) | |
| 394 print('|cFF0088FFBackground|r', unpack(value)) | |
| 395 region:SetVertexColor(1,1,1) -- reset | |
| 396 region:SetTexture(unpack(value)) | |
| 397 end | |
| 398 sb.BackgroundComplex = function (region, value) | |
| 399 local left, tile, right = value.Left, value.Tile, value.Right | |
| 400 | |
| 401 end | |
| 402 sb.Font = function(region, value) | |
| 403 f1, f2, f3 = unpack(value) | |
| 404 print('|cFFFFFF00Font|r', f1, f2, f3) | |
| 405 region:SetFont(f1, f2, f3) | |
| 406 end | |
| 407 | |
| 408 sb.Spacing = function(region, value) | |
| 409 print('FontSpacing', value) | |
| 410 region:SetSpacing(value) | |
| 411 region.spacing = value | |
| 412 end | |
| 413 | |
| 414 sb.TextColor = function(region, value) | |
| 415 a1, a2, a3, a4 = unpack(value) | |
| 416 print('TextColor', a1, a2, a3, a4) | |
| 417 region:SetTextColor(a1, a2, a3, a4) | |
| 418 end | |
| 419 sb.Texture = function(region, value) | |
| 420 | |
| 421 p1, a1, a2, a3, a4 = unpack(value) | |
| 422 print('Texture', p1, a1, a2, a3, a4) | |
| 423 region:SetTexture(p1) | |
| 424 if a1 then | |
| 425 region:SetTexCoord(a1, a2, a3, a4) | |
| 426 end | |
| 427 end | |
| 428 sb.Width = function(region, value) | |
| 429 w1 = value | |
| 430 region:SetWidth(w1) | |
| 431 end | |
| 432 | |
| 433 sb.Height = function(region, value) | |
| 434 w2 = value | |
| 435 region:SetHeight(w2) | |
| 436 end | |
| 437 sb.Size = function(region, value) | |
| 438 w1, w2 = unpack(value) | |
| 439 region:SetSize(w1, w2) | |
| 440 end |
