Mercurial > wow > turok
comparison Turok/Turok_Config.lua @ 6:a9b8b0866ece
clear out log jam
author | Nenue |
---|---|
date | Sun, 21 Feb 2016 08:32:53 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
5:8a9a6637f082 | 6:a9b8b0866ece |
---|---|
1 -- User: Krakyn | |
2 -- Created: 12/19/2015 12:18 AM | |
3 | |
4 local _G = _G | |
5 local T = LibStub("AceAddon-3.0"):GetAddon("Turok") | |
6 local TL = 'Options' | |
7 local mod = T:NewModule(TL) | |
8 local LSM = LibStub("LibSharedMedia-3.0") | |
9 local ConfigDialog = LibStub("AceConfigDialog-3.0") | |
10 --@debug | |
11 local print = function(...) _G.print(TL, ...) end | |
12 local db | |
13 | |
14 local TITLE_FONT_COLOR = '|cFF88FF44' | |
15 local INPUT_FONT_COLOR = '|cFFFFFF00' | |
16 local STACK_COLOR1 = '|cFFFF8800' | |
17 local STACK_COLOR2 = '|cFFFFFF00' | |
18 local FONTVAR_COLOR = '|cFFFFAA44' | |
19 local FRAMEVAR_COLOR = '|cFFFFFF44' | |
20 local PARAMETER_COLOR = '|cFF9999FF' | |
21 local STATE_COLOR = '|cFFFF99FF' | |
22 | |
23 function mod:OnInitialize() | |
24 T:Print("config mod init") | |
25 end | |
26 | |
27 function mod:OnEnable() | |
28 T:Print("config mod enable") | |
29 db = T.db | |
30 LibStub("AceConfig-3.0"):RegisterOptionsTable('Turok', T.MakeOptions(), {"turok"}) | |
31 T.configDialog = ConfigDialog:AddToBlizOptions("Turok") | |
32 end | |
33 | |
34 local optL = { | |
35 background_color = 'Background color', | |
36 foreground_color = 'Foreground color', | |
37 width = FRAMEVAR_COLOR..'Width', | |
38 height = FRAMEVAR_COLOR..'Height', | |
39 alpha = FRAMEVAR_COLOR..'Alpha', | |
40 alpha_ooc = STATE_COLOR..'Alpha (OOC)', | |
41 label_strata = FONTVAR_COLOR..'Text Strata', | |
42 label_font = FONTVAR_COLOR..'Font', | |
43 label_size = FONTVAR_COLOR..'Font Size', | |
44 label_inset = FONTVAR_COLOR..'Text Insets', | |
45 foreground_blend = 'Foreground Blend Mode', | |
46 background_blend = 'Background Blend Mode', | |
47 isStatic = PARAMETER_COLOR..'Static Bar', | |
48 duration = PARAMETER_COLOR..'Duration', | |
49 isIcon = PARAMETER_COLOR..'Icon Only', | |
50 } | |
51 | |
52 local anchors = { | |
53 ['CENTER'] = 'Center', | |
54 ['TOPLEFT'] = 'Top Left', | |
55 ['TOP'] = 'Top', | |
56 ['TOPRIGHT'] = 'Top Right', | |
57 ['RIGHT'] = 'Right', | |
58 ['BOTTOMRIGHT'] = 'Bottom Right', | |
59 ['BOTTOM'] = 'Bottom', | |
60 ['BOTTOMLEFT'] = 'Bottom Left', | |
61 ['LEFT'] = 'Left' | |
62 } | |
63 | |
64 local frames = { | |
65 ['UIParent'] = 'UIParent', | |
66 ['TkPowerBar'] = 'Power Bar', | |
67 ['TekplayerCastBar'] = 'Player Castbar', | |
68 ['TektargetCastBar'] = 'Target Castbar', | |
69 ['TekfocusCastBar'] = 'Focus Castbar', | |
70 ['TekpetCastBar'] = 'Pet Castbar' | |
71 } | |
72 | |
73 local range = { | |
74 ['alpha'] = {0, 1, .01}, | |
75 ['alpha_ooc'] = {0, 1, .01}, | |
76 ['label_size'] = {1, 72, 1}, | |
77 ['label_inset'] = {-30, 30, 1}, | |
78 ['width'] = {0, 1200, 1}, | |
79 ['height'] = {0, 1200, 1}, | |
80 ['raidbuff_width'] = {0, 1200, 1}, | |
81 ['raidbuff_height'] = {0, 1200, 1}, | |
82 ['duration'] = {0, 6000, 0.1 }, | |
83 ['glow_size'] = {0, 30, 1}, | |
84 ['spark_size'] = {0, 30, 1}, | |
85 } | |
86 | |
87 local opt_order = { | |
88 ['width'] = 10, | |
89 ['height'] = 15, | |
90 ['anchor'] = 20, | |
91 ['anchorTo'] = 25, | |
92 ['parent'] = 30, | |
93 | |
94 ['alpha'] = 110, | |
95 ['alpha_ooc'] = 115, | |
96 ['label_size'] = 200, | |
97 ['label_inset'] = 210, | |
98 ['label_font'] = 220, | |
99 | |
100 ['background_texture'] = 300, | |
101 ['background_color'] = 320, | |
102 ['foreground_texture'] = 350, | |
103 ['foreground_color'] = 370, | |
104 } | |
105 local opt_width = { | |
106 | |
107 } | |
108 | |
109 -- options dialog root | |
110 T.myopts = { | |
111 type = 'group', | |
112 name = TITLE_FONT_COLOR..'Turok|r', | |
113 desc = 'Dinosaur HUD', | |
114 handler = T, | |
115 set = function(info,value, ...) | |
116 local db = T.db | |
117 local index = db | |
118 local traversal = 'db' | |
119 for i = 1, #info-1 do | |
120 if type(index[info[i]]) == 'table' then | |
121 --print('|cFFFF0000SET|r:', i, info[i]) | |
122 traversal = traversal .. '.' .. info[i] | |
123 index = index[info[i]] | |
124 end | |
125 | |
126 end | |
127 --print('|cFFFF0000SET|r: hops=',#info,'index=', traversal, ' key=', info[#info]) | |
128 | |
129 if type(value) ~= 'boolean' and select('#',...) == 3 then | |
130 --print('|cFFFF0000SET|r', 'multi-args', select('#',...)) | |
131 value = {value, ... } | |
132 else | |
133 --print('|cFFFF0000SET|r', 'single-arg', value) | |
134 end | |
135 | |
136 index[info[#info]] = value | |
137 end, | |
138 get = function(info) | |
139 local db = T.db | |
140 local value = db[info[1]] | |
141 local traversal = info[1] | |
142 if #info > 1 then | |
143 for i=2, #info do | |
144 traversal = traversal .. '.' .. info[i] | |
145 if value[info[i]] ~= nil then | |
146 value = value[info[i]] | |
147 end | |
148 end | |
149 end | |
150 --print('|cFFFF00FFGET|r: hops=', #info, 'index=', traversal, 'value=', value) | |
151 | |
152 if type(value) == 'table' then | |
153 return unpack(value) | |
154 end | |
155 return value | |
156 end, | |
157 } | |
158 | |
159 function T:MakeOptions(dbtable, index, name, prefix) | |
160 -- index = option insertion destination | |
161 -- parent = nesting point | |
162 local parent | |
163 if not (index and dbtable) then | |
164 dbtable = db | |
165 name = 'root' | |
166 prefix = '' | |
167 parent = T.myopts | |
168 parent.args = { | |
169 main = { | |
170 order = 1, | |
171 type = 'group', | |
172 name = 'Global', | |
173 get = function(info) print('db.'..info[#info]..' get') | |
174 if type(db[info[#info]]) == 'table' then | |
175 print('getting color data', unpack(db[info[#info]])) | |
176 return unpack(db[info[#info]]) | |
177 end | |
178 return db[info[#info]] | |
179 end, | |
180 set = function(info, value, ...) print('db.'..info[#info]..' SET') | |
181 if select('#',...) == 3 then | |
182 print('receiving color data', value, ...) | |
183 value = {value, ...} | |
184 end | |
185 db[info[#info]] = value | |
186 end, | |
187 args = {}, | |
188 }} | |
189 index = parent.args.main | |
190 print(STACK_COLOR1..'using TurokData as index') | |
191 else | |
192 index.type = 'group' | |
193 index.name = name | |
194 index.args = {} | |
195 parent = index | |
196 end | |
197 | |
198 local order = 2 | |
199 for k, v in pairs(dbtable) do | |
200 k = tostring(k) | |
201 local kt = INPUT_FONT_COLOR .. (optL[k] or k) | |
202 local nested = false | |
203 --@debug@ | |
204 print(STACK_COLOR2..prefix..'.'..STACK_COLOR1..k..'|r =',v)--@debug@ | |
205 if type(v) == 'table' then | |
206 if table.getn(v) == 4 then | |
207 index.args[k] = { | |
208 name = kt, | |
209 type = 'color', | |
210 hasAlpha = true, | |
211 --@debug@ | |
212 print('color_pack=',unpack(v))--@debug@ | |
213 } | |
214 else | |
215 parent.args[k] = {} | |
216 nested = true | |
217 T:MakeOptions(v, parent.args[k], k, prefix .. '.' .. name) | |
218 end | |
219 elseif type(v) == 'string' then | |
220 if string.match(k, "_font") then | |
221 local font_list = {} | |
222 for k, v in pairs(LSM:HashTable('font')) do | |
223 font_list[v] = k | |
224 end | |
225 index.args[k] = { | |
226 name = kt, | |
227 type = 'select', | |
228 values = font_list | |
229 } | |
230 elseif k:match('anchor$') or k:match('_point$') or k:match('anchorTo') then | |
231 | |
232 index.args[k] = { | |
233 name = kt, | |
234 type = 'select', | |
235 values = anchors | |
236 } | |
237 | |
238 elseif k:match('justifyH$') then | |
239 index.args[k] = { | |
240 name = kt, | |
241 type = 'select', | |
242 values = { | |
243 ['LEFT'] = 'Left', | |
244 ['CENTER'] = 'Center', | |
245 ['RIGHT'] = 'Right' | |
246 } | |
247 } | |
248 | |
249 elseif k:match('strata$') then | |
250 index.args[k] = { | |
251 name = kt, | |
252 type = 'select', | |
253 values = { | |
254 BACKGROUND = 'BACKGROUND (clickthrough)', | |
255 LOW = 'LOW', | |
256 MEDIUM = 'MEDIUM', | |
257 HIGH = 'HIGH', | |
258 DIALOG = 'DIALOG', | |
259 FULLSCREEN = 'FULLSCREEN', | |
260 FULLSCREEN_DIALOG = 'FULLSCREEN_DIALOG', | |
261 TOOLTIP = 'TOOLTIP (clickthrough)', | |
262 } | |
263 } | |
264 | |
265 elseif k:match('outline$') then | |
266 index.args[k] = { | |
267 name = kt, | |
268 type = 'select', | |
269 values = { | |
270 ['NONE'] = 'NONE', | |
271 ['OUTLINE'] = 'OUTLINE', | |
272 ['THICKOUTLINE'] = 'THICKOUTLINE' | |
273 } | |
274 } | |
275 elseif k:match('parent') then | |
276 index.args[k] = { | |
277 name = kt, | |
278 type = 'select', | |
279 values = frames | |
280 } | |
281 else | |
282 | |
283 index.args[k] = { | |
284 name = kt, | |
285 type = 'input', | |
286 width = 'full', | |
287 } | |
288 end | |
289 elseif type(v) == 'number' then | |
290 | |
291 if not range[k] then | |
292 range[k] = {0,150,1 } | |
293 print('missing range values for', k) | |
294 end | |
295 | |
296 index.args[k] ={ | |
297 name = kt, | |
298 type = 'range', | |
299 min = range[k][1], | |
300 max = range[k][2], | |
301 softMax = range[k][2], | |
302 step = range[k][3], | |
303 bigStep = range[k][3], | |
304 } | |
305 elseif type(v) == 'boolean' then | |
306 | |
307 index.args[k] = { | |
308 name = kt, | |
309 type = 'toggle', | |
310 } | |
311 end | |
312 if nested then | |
313 parent.args[k].order = order + (opt_order[k] and opt_order[k] or 0) | |
314 elseif index.args[k] then | |
315 index.args[k].order = order + (opt_order[k] and opt_order[k] or 0) | |
316 print(' '..kt..' order = '..index.args[k].order) | |
317 else | |
318 print('|cFF99FFFFSkipped|r', kt) | |
319 end | |
320 end | |
321 | |
322 return parent | |
323 end |