Mercurial > wow > buffalo2
view ObjectiveStyle.lua @ 15:f660f1c1e0aa
Objective Widgets
- determine completion by fractional value
author | Nenue |
---|---|
date | Mon, 04 Apr 2016 03:41:28 -0400 |
parents | ed642234f017 |
children | 880828018bf4 |
line wrap: on
line source
local B = select(2,...).frame local mod = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') local print = B.print('SetStyle') ------------------------------------------------------------- --- Deals with swapping between different color palettes --- local titleFont, textFont = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Regular.ttf]] local titleSize, textSize = 16, 15 local titleOutline, textOutline = "OUTLINE", "OUTLINE" local titleSpacing, textSpacing = 3, 1 local unpack, type, pairs, tconcat = unpack, type, pairs, table.concat local wrapperHeadFont, wrapperHeadSize, wrapperHeadOutline = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], 16, 'NONE' local headerFont, headerSize = [[Interface\Addons\SharedMedia_MyMedia\font\ArchivoNarrow-Bold.ttf]], 24 local headerOutline, headerSpacing = 'OUTLINE', 2 mod.defaults.Wrapper = { WrapperPoint = 'TOPRIGHT', WrapperFloatX = -25, WrapperFloatV = 'TOP', WrapperFloatY = -200, WrapperWidth = 270, WrapperHeight = 600, } mod.defaults.Tracker = { HeaderHeight = 24, } mod.defaults.Style = { Format = { Frame = { Width = 270, }, title = { Indent = 0, Spacing = 0, }, status = { Indent = 5, Spacing = 0, } }, FontBank = { ['Normal'] = _G.VeneerCriteriaFontNormal, ['Progress'] = _G.VeneerCriteriaFontProgress, ['Complete'] = _G.VeneerCriteriaFontComplete, ['Failed'] = _G.VeneerCriteriaFontFailed, }, Normal = { title = { TextColor = {1, 1, 1, 1}, Width = 270, Spacing = 0, Indent = 2, }, titlebg = { Background = {0, 0, 0, 1}, Width = 270, }, status = { Width = 270, Spacing = 0, }, statusbg = { Width = 270, }, Frame = { Width = 270, } }, Wrapper = { Frame = { BackgroundComplex = {Left = {'', 0, 0.4, 0,1, 100}, Right={'', 0.6,1,0,1}, Tile = {'', 0.4,.6,0,1, 100}}, }, title = { Font = {wrapperHeadFont, wrapperHeadSize, wrapperHeadOutline}, Spacing = 4,} }, Tracker = { Normal = { title = { Font = {headerFont, headerSize, headerOutline}, Spacing = headerSpacing, Indent = 2, TextColor = {1, .9, .2, 1}, }, titlebg = { Gradient = {MinColor = {0,0,0,0.25}, MaxColor = {0,0,0,.15}}, } } }, TrackerBlock = { Normal = { titlebg = { Indent = 2, Gradient = { MinColor = {0.2, .4, 1, 0}, MaxColor = {.7, 0, 0.9, .14}}, }, title = { TextColor = {1,1,1,0.5}, Font = {titleFont, titleSize, titleOutline}, Spacing = titleSpacing, }, status = { TextColor = {1,1,1,0.5}, Font = {textFont, textSize, textOutline}, Spacing = textSpacing, }, statusbg = { Gradient = { MinColor = {0.2, .4, 1, 0}, MaxColor = {.7, 0, 0.9, .11}}, } }, Super = { title = { TextColor = {1,1,1,1}, Font = {titleFont, titleSize, titleOutline}, Spacing = titleSpacing, BackgroundFullWidth = true }, titlebg = { Gradient = { MinColor = {0, .7, .6, .45}, MaxColor = {0, .7, .6, 0.23}}, }, status = { TextColor = {1,1,1,1}, Font = {textFont, textSize, textOutline}, Spacing = textSpacing, }, statusbg = { Gradient = { MinColor = {0, .7, .6, 0.40}, MaxColor = {0, .7, .6, 0.23} }, }, }, MouseDown = { title = { Font = {titleFont, titleSize, titleOutline}, Spacing = titleSpacing, }, titlebg = { Gradient = { MinColor = {0.2, .4, 1, 1}, MaxColor = {0.2, .4, 1, .4}, }, }, status = { Font = {textFont, textSize, textOutline}, Spacing = textSpacing, }, statusbg = { Gradient = { MinColor = {0.2, .4, 1, 1}, MaxColor = {0.2, .4, 1, .2}, }, } }, Complete = { title = { TextColor = {1,1,1,0.5}, Font = {titleFont, titleSize, titleOutline}, Spacing = titleSpacing, }, titlebg = { Gradient = { MinColor = {0, 1, 0, 0.34}, MaxColor = {0, 1, 0, .17}, }, }, status = { TextColor = {1,1,1,0.5}, Font = {textFont, textSize, textOutline}, Spacing = textSpacing, }, statusbg = { Gradient = { MinColor = {0, 1, 0, .25}, MaxColor = {0, 1, 0, 0.12}, }, } }, Daily = { titlebg = { Gradient = { MinColor = {0, .4, 1, 0.34}, MaxColor = {0, 0.4, 1, .17}, }, }, statusbg = { Gradient = { MinColor = {0, .4, 1, 0.25}, MaxColor = {0, 0.4, 1, .12}, }, }, }, Cheev = { Normal = { title = { Font = {titleFont, titleSize, titleOutline}, Spacing = titleSpacing, }, titlebg = { Gradient = { MinColor = {0.2, .4, 1, 0.45}, MaxColor = {.7, 0, 0.9, .19}}, }, status = { Font = {textFont, textSize, textOutline}, Spacing = textSpacing, }, statusbg = { Gradient = { MinColor = {0.2, .4, 1, 0.25}, MaxColor = {.7, 0, 0.9, .12}}, }, }, Complete = { title = { Font = {titleFont, titleSize, titleOutline}, Spacing = titleSpacing, }, titlebg = { Gradient = { MinColor = {0.2, .4, 1, 0.45}, MaxColor = {.7, 0, 0.9, .19}}, }, status = { Font = {textFont, textSize, textOutline}, Spacing = textSpacing, }, statusbg = { Gradient = { MinColor = {0.2, .4, 1, 0.25}, MaxColor = {.7, 0, 0.9, .12}}, }, }, } } } local style_cache_func = {} local block_vars = { ['titleSize'] = {'titleWidth', 'titleHeight'}, ['FrameSize'] = {'width', 'height'} } local attrib_vars = { ['Font'] = {'height'}, } mod.BlockStyleCache = {} local style_cache = mod.BlockStyleCache mod.regions = {} mod.regionStyles = {} mod.SetBlockStyle = function(frame, frameType, ...) -- var names intended to reflect argument order print('|cFFFFFF00'..frame:GetName()..'|r') --@debug@ local c = mod.defaults.Normal local style_list = {... } local styleName = frameType .. '-' .. table.concat(style_list,'') if not style_cache[styleName] then local style = {} if mod.defaults.Style[frameType] then print(' setting style class |cFF00FFFF'..frameType) else print(' resorting to class Normal (missing |cFFFF8800'.. frameType..'|r)') end local normal = mod.defaults.Style.Normal local root = mod.defaults.Style[frameType] or normal for i, className in ipairs(style_list) do local class = root[className] or normal[className] or root if root[className] then print(' SubClass |cFF0088FF'.. className .. '|r') elseif normal[className] then print(' SubClass Normal.|cFFFF0088'..className..'|r') else print(' SubClass Normal') end for elementName, element in pairs(class) do if not elementName:match('^%u') then print(' scanning Element |cFF8800FF'.. elementName ..'|r') if not style[elementName] then style[elementName] = {} end for key, value in pairs(element) do if mod.SetBlockAttribute[key] then print(' |cFF00FF00'..elementName..'|r.|cFF00FFFF'..key..' =', (type(value) == 'table' and ('{'..table.concat(value,', ')..'}') or tostring(value))) style[elementName][key] = value end end end end end for k, elements in pairs(mod.defaults.Style.Normal) do if not style[k] and type(elements) ~= 'table' then style[k] = elements end end print('result for: ', frame:GetName()) for k,v in pairs(style) do if type(v) == 'table' and not k:match('^%u') then for kk, vv in pairs(v) do print(' |cFFFFFF00'..k..'|r.|cFF00FF00'..kk..'|r =', tostring(vv)) end else print(' |cFFFFFFFF' .. k ..'|r =', tostring(v)) end end style_cache[styleName] = style end local style = style_cache[styleName] if not style_cache_func[styleName] then local code = "return function (frame)\n".. " local func = Veneer.ObjectiveTracker.SetBlockAttribute\n".. " local cache = Veneer.ObjectiveTracker.BlockStyleCache" --.. " print('CacheFunc', '|cFFFFFF00SET|r "..styleName.." |cFFFFFF00ON|r', frame:GetName()) " for elementName, styleset in pairs(style) do code = code .. "\n if frame['"..elementName.."'] then" for attributeName, value in pairs(styleset) do if mod.SetBlockAttribute[attributeName] then print(' '..elementName..':'.. attributeName ..'(', value, ')') --mod.SetBlockAttribute[attributeName](region, value) code = code --.. "\n print('CacheFunc', ' applying', '|cFF00FFFF" .. attributeName .. "|r to', '|cFF0088FF"..elementName.."|r', cache['"..styleName.."']['"..elementName.."']['".. attributeName .."'])" .. "\n\n func['" .. attributeName .. "'](frame['"..elementName.."'],".. " cache['"..styleName.."']['"..elementName.."']['".. attributeName .."'])" --- Set any frame.blah variables used in Updates if block_vars[elementName .. attributeName] then print('|cFF008800BVar|r', elementName..attributeName) for i, blockKey in ipairs(block_vars[elementName .. attributeName]) do print(' assigning |cFF008800'..blockKey..'|r') frame[blockKey] = (type(value) == 'table') and value[i] or value end end end end code = code .. "\n else".. --"\n print('CacheFunc', ' |cFFFF4400missing', frame:GetName()..'."..elementName.."')".. "\n end" end code = code .. "\nend" local result = assert(loadstring(code)) print('storing style func', styleName, result()) style_cache_func[styleName] = result() end style_cache_func[styleName](frame) --- Hardcoding the sizing vars for sanity local normalSettings = mod.defaults.Style.Format frame.titleHeight = frame.title and (frame.title:GetStringHeight() + (frame.title.spacing or 0)*2) or 0 frame.statusHeight = frame.status and (frame.status:GetStringHeight() + (frame.status.spacing or 0)*2) or 0 frame.height = frame.titleHeight + frame.statusHeight + (frame.attachmentHeight or 0) frame.width = normalSettings.Frame.Width frame.statusWidth = frame.width - normalSettings.status.Indent frame.titleWidth = frame.width - normalSettings.title.Indent if frame.status then print('status ', frame.statusHeight, normalSettings.status.Indent, 0, 'statusbg', frame.statusHeight) frame.status:SetPoint('LEFT', frame, 'LEFT', normalSettings.status.Indent, 0) frame.status:SetHeight(frame.statusHeight) if frame.statusbg then frame.statusbg:SetHeight(frame.statusHeight + (frame.attachmentHeight or 0)) frame.statusbg:SetWidth(frame.width) end end if frame.title then print('title ',frame.titleHeight, normalSettings.title.Indent, 'titlebg',frame.titleHeight) frame.title:SetPoint('LEFT', frame, 'LEFT', normalSettings.title.Indent) frame.title:SetHeight(frame.titleHeight) if frame.titlebg then frame.titlebg:SetHeight(frame.titleHeight) frame.titlebg:SetWidth(frame.width) end end frame:SetSize(frame.width, frame.height) print('sizing frame', frame.width, frame.height) --[[ local titleSpacing, titleSpacing2 = c.Title.Spacing, (c.Title.Spacing * 2) local textSpacing, textSpacing2 = c.Text.Spacing, (c.Text.Spacing * 2) block.title:SetSpacing(titleSpacing) block.objectives:SetSpacing(textSpacing) block.objectives:SetWordWrap(true) local titleHeight, textHeight = block.title:GetStringHeight(), block.objectives:GetStringHeight() + block.attachmentHeight local blockHeight = titleHeight + titleSpacing2 + textHeight + textSpacing2 local blockWidth = wrapperMaxWidth block.titlebg:SetSize(min(w1, w2), titleHeight + titleSpacing2) block.bg:SetSize(w1, textHeight + textSpacing2) block:SetSize(blockWidth, blockHeight) block.title:SetPoint('TOPLEFT', block.titlebg, 'TOPLEFT', 0, -titleSpacing) block.objectives:SetPoint('TOPLEFT', block.titlebg, 'BOTTOMLEFT', textIndent, -textSpacing) -- store block.titleHeight = titleHeight block.textHeight = textHeight block.width = blockWidth block.height = blockHeight --]] --print(' |cFF00FFFF'..block:GetName()..'|r:|cFF0088FFSetStyle|r(', blockWidth, 'x', blockHeight, '(textH', textHeight,', titleH', titleHeight, ')') end local segments = {'Left', 'Right', 'Tile' } local Wrapper = _G.VeneerObjectiveWrapper mod.UpdateWrapperStyle = function() local c = mod.Conf.Wrapper --Wrapper:ClearAllPoints() --Wrapper:SetPoint(c.WrapperPoint, UIParent, c.WrapperPoint, c.WrapperFloatX, c.WrapperFloatY) end mod.Tracker.SetBlockTags = function(block, info) if info.isComplete then block.mainStyle = 'Complete' end if info.superTracked then block.subStyle = 'Super' elseif info.isDaily then block.subStyle = 'Daily' end end local unitLevel = UnitLevel('player') mod.Quest.SetBlockTags = function(block, info) mod.Tracker.SetBlockTags(block, info) if info.level then local levelDiff = unitLevel - info.level if levelDiff > 9 then block.title:SetTextColor(0.7, 0.7, 0.7, 1) elseif levelDiff > 1 then block.title:SetTextColor(0.5, 1, 0.5, 1) elseif levelDiff < -1 then block.title:SetTextColor(1, 0.4, 0.25, 1) elseif levelDiff < -4 then block.title:SetTextColor(1, 0, 0, 1) else block.title:SetTextColor(1,1,1,1) end end end mod.Cheevs.SetBlockTags = function(block, info) mod.Tracker.SetBlockTags(block, info) end --- Argument containers local o -- text flag local a1, a2, a3, a4, b1, b2, b3, b4 -- color1, color2 local f1, f2, f3 -- font local w1, w2 -- size local p1, p2, p3, x, y -- path/point args mod.SetBlockAttribute = {} local sb = mod.SetBlockAttribute local print = B.print('Attribute') sb.Gradient = function(region, value) print('|cFF8844FFGradient|r', region:GetName(), unpack(value)) o = 'HORIZONTAL' a1, a2, a3, a4 = unpack(value.MinColor) b1, b2, b3, b4 = unpack(value.MaxColor) region:SetVertexColor(1,1,1) region:SetTexture(1,1,1,1) region:SetGradientAlpha(o, a1, a2, a3, a4, b1, b2, b3, b4) end sb.Background = function(region, value) print('|cFF0088FFBackground|r', unpack(value)) region:SetVertexColor(1,1,1) -- reset region:SetTexture(unpack(value)) end sb.BackgroundComplex = function (region, value) local left, tile, right = value.Left, value.Tile, value.Right end sb.Font = function(region, value) f1, f2, f3 = unpack(value) print('|cFFFFFF00Font|r', f1, f2, f3) region:SetFont(f1, f2, f3) end sb.Spacing = function(region, value) print('FontSpacing', region:GetName(), value) region:SetSpacing(value) region.spacing = value end sb.TextColor = function(region, value) a1, a2, a3, a4 = unpack(value) print('TextColor', a1, a2, a3, a4) region:SetTextColor(a1, a2, a3, a4) end sb.Texture = function(region, value) p1, a1, a2, a3, a4 = unpack(value) print('Texture', p1, a1, a2, a3, a4) region:SetTexture(p1) if a1 then region:SetTexCoord(a1, a2, a3, a4) end end sb.Width = function(region, value) w1 = value region:SetWidth(w1) end sb.Height = function(region, value) w2 = value region:SetHeight(w2) end sb.Size = function(region, value) w1, w2 = unpack(value) region:SetSize(w1, w2) end