annotate Options.lua @ 110:73316951ce73

- Fix extra value text updates
author Nick@Zahhak
date Mon, 06 Mar 2017 02:31:15 -0500
parents 26938ae258b7
children
rev   line source
Nenue@75 1
Nenue@75 2 local plugin = CreateFrame('Frame', 'VeneerOptions', UIParent, 'TooltipBorderedFrameTemplate')
Nenue@76 3 local vn, print = LibStub("LibKraken").register(Veneer, plugin)
Nenue@75 4
Nenue@75 5 local fields = {}
Nenue@75 6 local templateTypes = {
Nenue@75 7 slider = 'Slider',
Nenue@75 8 radio = 'Frame',
Nenue@75 9 number = 'EditBox',
Nenue@75 10 check = 'CheckButton'
Nenue@75 11 }
Nenue@75 12 local templateNames = {
Nenue@75 13 slider = 'OptionsSliderTemplate',
Nenue@75 14 radio = '',
Nenue@75 15 number = 'NumericInputSpinnerTemplate',
Nenue@75 16 check = 'UICheckButtonTemplate'
Nenue@75 17 }
Nenue@75 18 local OnLoad, OnUpdate, OnValueChanged = {}, {}, {}
Nenue@75 19 local frameHeadings = {}
Nenue@75 20
Nenue@75 21 local framePadding = 14
Nenue@75 22 local frameMaxWidth = 400
Nenue@75 23
Nenue@75 24
Nenue@75 25 local ToggleVeneerOptions = function()
Nenue@75 26
Nenue@75 27 plugin:Show()
Nenue@75 28 if plugin.initialized then
Nenue@75 29 return
Nenue@75 30 end
Nenue@75 31
Nenue@75 32 local sizeChanged = false
Nenue@75 33 local frameDepth = framePadding
Nenue@75 34 local frameWidth = framePadding
Nenue@75 35 local lineWidth = framePadding
Nenue@75 36 local lineNum = 1
Nenue@75 37 local lineColumn = 1
Nenue@75 38
Nenue@75 39 for i, module in ipairs(vn.modules) do
Nenue@75 40 if module.options then
Nenue@75 41 if not frameHeadings[module] then
Nenue@75 42 frameHeadings[module] = plugin:CreateFontString(nil, 'OVERLAY', 'VeneerNumberFontLarge')
Nenue@75 43 frameHeadings[module]:SetText(module.options.nameString or module:GetName())
Nenue@75 44 frameHeadings[module].height = frameHeadings[module]:GetHeight()
Nenue@75 45
Nenue@75 46 frameHeadings[module]:SetPoint('TOPLEFT', plugin, 'TOPLEFT', lineColumn, -frameDepth)
Nenue@75 47 frameDepth = frameDepth + frameHeadings[module].height
Nenue@75 48 end
Nenue@75 49
Nenue@75 50 for index, args in ipairs(module.options) do
Nenue@75 51 local fullIndex = (i*1000)+index
Nenue@75 52 print('config field', fullIndex)
Nenue@75 53 if not fields[fullIndex] then
Nenue@75 54 fields[fullIndex] = {}
Nenue@75 55 end
Nenue@75 56 local opt = fields[fullIndex]
Nenue@75 57
Nenue@75 58 if not opt.frame then
Nenue@75 59 sizeChanged = true
Nenue@75 60
Nenue@75 61 local configType = args.type
Nenue@75 62 print('Creating', templateTypes[configType] or 'Frame', 'from', templateNames[configType])
Nenue@75 63 opt.frame = CreateFrame(templateTypes[configType] or 'Frame', 'VeneerOptions' .. args.name, plugin, templateNames[configType])
Nenue@75 64
Nenue@75 65 if OnLoad[configType] then
Nenue@75 66 OnLoad[configType](opt.frame, args)
Nenue@75 67 end
Nenue@75 68 if opt.OnLoad then
Nenue@75 69 opt.OnLoad(opt.frame)
Nenue@75 70 end
Nenue@75 71
Nenue@75 72 if args.OnUpdate then
Nenue@75 73 opt.frame.Update = function(self)
Nenue@75 74 OnUpdate[configType](self, args)
Nenue@75 75 args.OnUpdate(self, args)
Nenue@75 76 end
Nenue@75 77 else
Nenue@75 78 opt.frame.Update = function(self)
Nenue@75 79 OnUpdate[configType](self, args)
Nenue@75 80 end
Nenue@75 81 end
Nenue@75 82
Nenue@75 83 opt.frame:Update()
Nenue@75 84
Nenue@75 85 opt.frame:SetPoint('TOPLEFT', plugin, 'TOPLEFT', lineColumn, -frameDepth)
Nenue@75 86
Nenue@75 87
Nenue@75 88 opt.name = args.name
Nenue@75 89 opt.line = lineNum
Nenue@75 90 opt.column = lineColumn
Nenue@75 91
Nenue@75 92 -- measure after initializer
Nenue@75 93 frameDepth = frameDepth + opt.frame:GetHeight()
Nenue@75 94 lineWidth = lineWidth + opt.frame:GetWidth()
Nenue@75 95 opt.depth = frameDepth
Nenue@75 96 opt.width = lineWidth
Nenue@75 97 local isOverlapped = (lineWidth > frameMaxWidth)
Nenue@75 98 if args.fullwidth or isOverlapped then
Nenue@75 99 lineNum = lineNum + 1
Nenue@75 100 if isOverlapped then
Nenue@75 101 lineWidth = framePadding + opt.frame:GetWidth()
Nenue@75 102 lineColumn = 1
Nenue@75 103 else
Nenue@75 104 lineWidth = framePadding
Nenue@75 105 lineColumn = lineColumn + 1
Nenue@75 106 end
Nenue@75 107 end
Nenue@75 108
Nenue@75 109 if lineWidth > frameWidth then
Nenue@75 110 sizeChanged = true
Nenue@75 111 frameWidth = lineWidth
Nenue@75 112 end
Nenue@75 113
Nenue@75 114
Nenue@75 115 end
Nenue@75 116
Nenue@75 117
Nenue@75 118
Nenue@75 119
Nenue@75 120
Nenue@75 121
Nenue@75 122 end
Nenue@75 123 end
Nenue@75 124 end
Nenue@75 125
Nenue@75 126 if sizeChanged then
Nenue@75 127 plugin:SetSize(frameWidth + framePadding, frameDepth + framePadding)
Nenue@75 128
Nenue@75 129 plugin:SetPoint('CENTER')
Nenue@75 130 end
Nenue@75 131
Nenue@75 132 end
Nenue@75 133
Nenue@75 134 OnLoad.slider = function(self, args)
Nenue@75 135 print('min:', args.min, 'max:', args.max, 'steps:', args.step)
Nenue@75 136 self:SetMinMaxValues(args.min or 0, args.max or 420)
Nenue@75 137 self:SetValueStep(1)
Nenue@75 138 self:SetStepsPerPage(5)
Nenue@75 139 self:SetObeyStepOnDrag(true)
Nenue@75 140 end
Nenue@75 141
Nenue@75 142 OnUpdate.slider = function(self, args)
Nenue@75 143 local base = args.handler or vn.db
Nenue@75 144 self:SetValue(vn.db[self.name] or 1)
Nenue@75 145 end
Nenue@75 146
Nenue@75 147 OnValueChanged.slider = function()
Nenue@75 148 end
Nenue@75 149
Nenue@75 150 plugin.cmd = function(cmd)
Nenue@75 151 cmd = string.lower(cmd)
Nenue@75 152 if cmd:match('config') then
Nenue@75 153 ToggleVeneerOptions()
Nenue@75 154 return true
Nenue@75 155 end
Nenue@75 156 end
Nenue@75 157
Nenue@75 158 plugin.init = function()
Nenue@75 159 --ToggleVeneerOptions()
Nenue@75 160 end