comparison Options.lua @ 75:d9d16e67725c

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