Nenue@75: Nenue@75: local plugin = CreateFrame('Frame', 'VeneerOptions', UIParent, 'TooltipBorderedFrameTemplate') Nenue@76: local vn, print = LibStub("LibKraken").register(Veneer, plugin) Nenue@75: Nenue@75: local fields = {} Nenue@75: local templateTypes = { Nenue@75: slider = 'Slider', Nenue@75: radio = 'Frame', Nenue@75: number = 'EditBox', Nenue@75: check = 'CheckButton' Nenue@75: } Nenue@75: local templateNames = { Nenue@75: slider = 'OptionsSliderTemplate', Nenue@75: radio = '', Nenue@75: number = 'NumericInputSpinnerTemplate', Nenue@75: check = 'UICheckButtonTemplate' Nenue@75: } Nenue@75: local OnLoad, OnUpdate, OnValueChanged = {}, {}, {} Nenue@75: local frameHeadings = {} Nenue@75: Nenue@75: local framePadding = 14 Nenue@75: local frameMaxWidth = 400 Nenue@75: Nenue@75: Nenue@75: local ToggleVeneerOptions = function() Nenue@75: Nenue@75: plugin:Show() Nenue@75: if plugin.initialized then Nenue@75: return Nenue@75: end Nenue@75: Nenue@75: local sizeChanged = false Nenue@75: local frameDepth = framePadding Nenue@75: local frameWidth = framePadding Nenue@75: local lineWidth = framePadding Nenue@75: local lineNum = 1 Nenue@75: local lineColumn = 1 Nenue@75: Nenue@75: for i, module in ipairs(vn.modules) do Nenue@75: if module.options then Nenue@75: if not frameHeadings[module] then Nenue@75: frameHeadings[module] = plugin:CreateFontString(nil, 'OVERLAY', 'VeneerNumberFontLarge') Nenue@75: frameHeadings[module]:SetText(module.options.nameString or module:GetName()) Nenue@75: frameHeadings[module].height = frameHeadings[module]:GetHeight() Nenue@75: Nenue@75: frameHeadings[module]:SetPoint('TOPLEFT', plugin, 'TOPLEFT', lineColumn, -frameDepth) Nenue@75: frameDepth = frameDepth + frameHeadings[module].height Nenue@75: end Nenue@75: Nenue@75: for index, args in ipairs(module.options) do Nenue@75: local fullIndex = (i*1000)+index Nenue@75: print('config field', fullIndex) Nenue@75: if not fields[fullIndex] then Nenue@75: fields[fullIndex] = {} Nenue@75: end Nenue@75: local opt = fields[fullIndex] Nenue@75: Nenue@75: if not opt.frame then Nenue@75: sizeChanged = true Nenue@75: Nenue@75: local configType = args.type Nenue@75: print('Creating', templateTypes[configType] or 'Frame', 'from', templateNames[configType]) Nenue@75: opt.frame = CreateFrame(templateTypes[configType] or 'Frame', 'VeneerOptions' .. args.name, plugin, templateNames[configType]) Nenue@75: Nenue@75: if OnLoad[configType] then Nenue@75: OnLoad[configType](opt.frame, args) Nenue@75: end Nenue@75: if opt.OnLoad then Nenue@75: opt.OnLoad(opt.frame) Nenue@75: end Nenue@75: Nenue@75: if args.OnUpdate then Nenue@75: opt.frame.Update = function(self) Nenue@75: OnUpdate[configType](self, args) Nenue@75: args.OnUpdate(self, args) Nenue@75: end Nenue@75: else Nenue@75: opt.frame.Update = function(self) Nenue@75: OnUpdate[configType](self, args) Nenue@75: end Nenue@75: end Nenue@75: Nenue@75: opt.frame:Update() Nenue@75: Nenue@75: opt.frame:SetPoint('TOPLEFT', plugin, 'TOPLEFT', lineColumn, -frameDepth) Nenue@75: Nenue@75: Nenue@75: opt.name = args.name Nenue@75: opt.line = lineNum Nenue@75: opt.column = lineColumn Nenue@75: Nenue@75: -- measure after initializer Nenue@75: frameDepth = frameDepth + opt.frame:GetHeight() Nenue@75: lineWidth = lineWidth + opt.frame:GetWidth() Nenue@75: opt.depth = frameDepth Nenue@75: opt.width = lineWidth Nenue@75: local isOverlapped = (lineWidth > frameMaxWidth) Nenue@75: if args.fullwidth or isOverlapped then Nenue@75: lineNum = lineNum + 1 Nenue@75: if isOverlapped then Nenue@75: lineWidth = framePadding + opt.frame:GetWidth() Nenue@75: lineColumn = 1 Nenue@75: else Nenue@75: lineWidth = framePadding Nenue@75: lineColumn = lineColumn + 1 Nenue@75: end Nenue@75: end Nenue@75: Nenue@75: if lineWidth > frameWidth then Nenue@75: sizeChanged = true Nenue@75: frameWidth = lineWidth Nenue@75: end Nenue@75: Nenue@75: Nenue@75: end Nenue@75: Nenue@75: Nenue@75: Nenue@75: Nenue@75: Nenue@75: Nenue@75: end Nenue@75: end Nenue@75: end Nenue@75: Nenue@75: if sizeChanged then Nenue@75: plugin:SetSize(frameWidth + framePadding, frameDepth + framePadding) Nenue@75: Nenue@75: plugin:SetPoint('CENTER') Nenue@75: end Nenue@75: Nenue@75: end Nenue@75: Nenue@75: OnLoad.slider = function(self, args) Nenue@75: print('min:', args.min, 'max:', args.max, 'steps:', args.step) Nenue@75: self:SetMinMaxValues(args.min or 0, args.max or 420) Nenue@75: self:SetValueStep(1) Nenue@75: self:SetStepsPerPage(5) Nenue@75: self:SetObeyStepOnDrag(true) Nenue@75: end Nenue@75: Nenue@75: OnUpdate.slider = function(self, args) Nenue@75: local base = args.handler or vn.db Nenue@75: self:SetValue(vn.db[self.name] or 1) Nenue@75: end Nenue@75: Nenue@75: OnValueChanged.slider = function() Nenue@75: end Nenue@75: Nenue@75: plugin.cmd = function(cmd) Nenue@75: cmd = string.lower(cmd) Nenue@75: if cmd:match('config') then Nenue@75: ToggleVeneerOptions() Nenue@75: return true Nenue@75: end Nenue@75: end Nenue@75: Nenue@75: plugin.init = function() Nenue@75: --ToggleVeneerOptions() Nenue@75: end