Mercurial > wow > turok
comparison Turok/Modules/Timer/Editor.lua @ 6:a9b8b0866ece
clear out log jam
author | Nenue |
---|---|
date | Sun, 21 Feb 2016 08:32:53 -0500 |
parents | |
children | 9400a0ff8540 |
comparison
equal
deleted
inserted
replaced
5:8a9a6637f082 | 6:a9b8b0866ece |
---|---|
1 --- Modules | |
2 -- @file-author@ | |
3 -- @project-revision@ @project-hash@ | |
4 -- @file-revision@ @file-hash@ | |
5 -- Created: 1/18/2016 3:33 PM | |
6 local _G = _G | |
7 local T, type, pairs = _G.Turok, type, pairs | |
8 local mod = T.modules.TimerControl | |
9 local cType, cText, cNum, cWord, cKey, cPink, cBool = cType, cText, cNum, cWord, cKey, cPink, cBool | |
10 local print = function(...) | |
11 if Devian and DevianDB.workspace ~= 1 then | |
12 print('Dialog', ...) | |
13 end | |
14 end | |
15 print('Peep!', ...) | |
16 | |
17 | |
18 local TimerConfig = { | |
19 conf = { | |
20 padding = 4, | |
21 spacing = 1, | |
22 width = 450, | |
23 }, | |
24 info = { | |
25 { key = 'timerName', | |
26 desc = 'Unique Name:', | |
27 type='EditBox', name = 'timerName', fill=true, | |
28 line = true, | |
29 }, | |
30 { key = 'spellEnable', | |
31 inherits = 'TurokCheckButtonOverlay', | |
32 type='CheckButton', name = 'spellEnable', fixed=25, point='LEFT', | |
33 get = Dialog_Boolean, getarg = 'spellID', | |
34 collapse = true, | |
35 desc = 'Spell Name', | |
36 }, | |
37 { key = 'spellID', | |
38 type='EditBox', name = 'spellName', | |
39 line = true, float = true | |
40 }, | |
41 { key = 'fill_inverse', | |
42 desc = 'Reverse Fill', | |
43 type='CheckButton', name='fillInverse', fixed=25, point='LEFT', | |
44 get = Dialog_Boolean, getarg = 'fill_inverse', text='Inverted Fill', | |
45 line = true, | |
46 }, | |
47 { key = 'display', | |
48 desc = 'Display Type', | |
49 type='EditBox', name='displayType', | |
50 line = true, | |
51 }, | |
52 }, | |
53 } | |
54 | |
55 local Dialog_SetField = {} | |
56 local dget = function(name, key) | |
57 if mod.db.timers[name] then | |
58 return mod.db.timers[name][key] | |
59 end | |
60 return nil | |
61 end | |
62 local inherits = { | |
63 EditBox = 'TkEditBox', | |
64 CheckButton = 'TurokCheckButtonInline', | |
65 Slider = 'TkSlider', | |
66 } | |
67 | |
68 Dialog_SetField['CheckButton'] = function(self, checked) self:SetChecked(checked) end | |
69 Dialog_SetField['EditBox'] = function(self, text) | |
70 print(' ', cKey(self:GetName()), text) | |
71 self:SetText(text or '') end | |
72 Dialog_SetField['Button'] = function(self, text) self:SetText(text) end | |
73 | |
74 | |
75 local function Dialog_Boolean(name, key) | |
76 print(' Dialog_Boolean', name, key) | |
77 return (mod.db.timers[name][key] and true or false) | |
78 end | |
79 | |
80 function mod.Dialog_Select(self, key) | |
81 local timer | |
82 if self.parent_values[key] then | |
83 print('matched timer name', key) | |
84 timer = self.parent_values[key] | |
85 elseif rawget(mod.frames.spellID, key) then | |
86 print('matched spellID', key) | |
87 timer = mod.frames.spellID[key][1] | |
88 for k,v in pairs(timer) do | |
89 print(' -', k, '=', v) | |
90 end | |
91 end | |
92 | |
93 if timer then | |
94 self.values = timer | |
95 self.timerName = timer.timerName | |
96 else | |
97 self.values = { | |
98 timerName = 'New Timer' | |
99 } | |
100 self.timerName = 'New Timer' | |
101 end | |
102 mod.Dialog_Init(self, TimerConfig.conf, TimerConfig.info) | |
103 end | |
104 | |
105 function mod.Dialog_Init(self, dconf, dinfo) | |
106 print('init,', self.values.timerName) | |
107 | |
108 if not self.fields then | |
109 self.fields = {} | |
110 self.rows = {} | |
111 self.Click = mod.Dialog_Click | |
112 self.Check = mod.Dialog_Check | |
113 self.EditBox = mod.Dialog_EditBox | |
114 end | |
115 print(self.name, self.timerName) | |
116 self.name:SetText(self.timerName) | |
117 | |
118 local inset = dconf.padding + dconf.spacing | |
119 -- frame X max | |
120 local fX = 0 | |
121 -- row number, row Y offset | |
122 local rn, ry = 1, -34 | |
123 -- row x offset left-align, row x offset right-aligned, largest collapsed element | |
124 local rxL, rxR, rC, rh = dconf.spacing, dconf.spacing, 0, 0 | |
125 for i, opt in ipairs(dinfo) do | |
126 if not self.rows[rn] then | |
127 self.rows[rn] = CreateFrame('Frame', self:GetName()..'Row'..rn, self, 'TurokDialogRow') | |
128 end | |
129 | |
130 local k = opt.key | |
131 if self.fields[i] == nil then | |
132 self.fields[i] = CreateFrame(opt.type, self:GetName()..opt.name, self.rows[rn], opt.inherits or inherits[opt.type]) | |
133 self.fields[i].index = i | |
134 self.fields[i].key = k | |
135 -- row point (from), row point (to), row x offset | |
136 local rp, rpt, rx | |
137 -- row delta | |
138 local rd | |
139 if opt.fill then | |
140 rpt = opt.float and 'BOTTOMLEFT' or 'BOTTOMRIGHT' | |
141 -- row point X offset | |
142 local rpx = opt.float and dconf.spacing or -dconf.spacing | |
143 self.fields[i]:SetPoint(rpt, self.rows[rn], rpt, rpx, 0) | |
144 print(' fill:', rpt, '-', rpt,' :: ', rpx, 0) | |
145 rd = 0 | |
146 else | |
147 rd = self.fields[i]:GetWidth() + dconf.spacing | |
148 end | |
149 if opt.float then | |
150 rp = 'BOTTOMRIGHT' | |
151 rx = -rxR | |
152 rxR = rxR + rd | |
153 elseif opt.collapse then | |
154 rp = 'BOTTOMLEFT' | |
155 rx = dconf.spacing | |
156 rC = math.max(rC, rd + dconf.spacing) -- spacing L + rd{width + spacing R} | |
157 else | |
158 rp = 'BOTTOMLEFT' | |
159 rx = rxL | |
160 rxL = rxL + rd | |
161 end | |
162 | |
163 rh = math.max(rh, self.fields[i]:GetHeight()) | |
164 self.fields[i]:SetPoint(rp, self.rows[rn], rp, rx, dconf.spacing) | |
165 print(' align:', rp, '-', rp, ' :: ', rx, 0) | |
166 print(' dR:', cNum(rd), 'nR:',cWord(rn), 'rX:', cNum(rx), 'i:', cText(i)) | |
167 | |
168 if opt.line or (not dinfo[i+1]) then | |
169 print(cText'nR:', cNum(rn), 'rY:', cNum(ry)) | |
170 self.rows[rn]:ClearAllPoints() | |
171 self.rows[rn]:SetPoint('TOPLEFT', self, 'TOPLEFT', dconf.padding, ry) | |
172 self.rows[rn]:SetPoint('TOPRIGHT', self, 'TOPRIGHT', -dconf.padding, ry) | |
173 self.rows[rn]:SetHeight(rh + dconf.spacing*2) | |
174 self.rows[rn]:Show() | |
175 rn = rn + 1 | |
176 ry = ry - (rh + dconf.spacing*3) -->| {spacing T + rh + spacing B} + spacing dR |<-- | |
177 | |
178 print('fX:',cNum(fX), 'rX:', cNum(rxL+rxR+dconf.spacing), 'rC:', cNum(rC)) | |
179 fX = math.max(fX, rxL+rxR+dconf.spacing) | |
180 fX = math.max(fX, rC) | |
181 rxL, rxR = dconf.spacing, dconf.spacing | |
182 rh = 0 | |
183 end | |
184 end | |
185 | |
186 self.fields[i]:Show() | |
187 if opt.desc and self.fields[i].description then | |
188 self.fields[i].description:SetText(opt.desc) | |
189 end | |
190 Dialog_SetField[opt.type](self.fields[i], opt.get and opt.get(self.values.timerName, opt.getarg) or self.values[k]) | |
191 | |
192 end | |
193 if not self.initialized then | |
194 self.initialized = true | |
195 self:SetSize(fX + dconf.padding + dconf.spacing*2, dconf.padding + math.abs(ry)) | |
196 end | |
197 end | |
198 | |
199 function mod.Dialog_Click(self,...) | |
200 local command = self:GetName():match("_(a%+)$") | |
201 | |
202 print(command) | |
203 end | |
204 | |
205 function mod.Dialog_Check(self, ...) | |
206 print('field #', self.index, self.key, 'checked') | |
207 --self:SetChecked(self:GetChecked() and false or true) | |
208 end | |
209 | |
210 function mod.Dialog_EditBox(self, ...) | |
211 print('field #', self.index, self.key, 'changed', self:GetText()) | |
212 | |
213 if self.key == 'timerName' then | |
214 self.values.timerName = self:GetText() | |
215 self.name:SetText(self.values.timerName) | |
216 self.timerName = self.values.timerName | |
217 elseif self.key == 'spellID' then | |
218 print('handling spellID') | |
219 end | |
220 | |
221 end | |
222 | |
223 function mod.Dialog_Command(str, editbox) | |
224 --local spellID = T:GetArgs(str, 1,0) | |
225 local f = mod.EditDialog | |
226 f.values = {} | |
227 local db = mod.db | |
228 | |
229 | |
230 local func, t, z = pairs(db.timers) -- iterator, table | |
231 local name, values, y = func(t) -- index, values | |
232 f.parent_values = {[name] = values} | |
233 f.timerName = name | |
234 f.values = values | |
235 f.values.timerName = name | |
236 for k,v in pairs(f.values) do | |
237 print(cText(k), cType(v)) | |
238 end | |
239 print('pairs1', func, t) | |
240 print('pairs2', z, y) | |
241 name, values = func(t, name) | |
242 while name do | |
243 print(' entry:', name, values) | |
244 f.parent_values[name] = values | |
245 name, values = func(t, name) | |
246 end | |
247 | |
248 | |
249 | |
250 if f:IsVisible() then | |
251 f:Hide() | |
252 else | |
253 mod.Dialog_Init(f, TimerConfig.conf, TimerConfig.info) | |
254 | |
255 f:Show() | |
256 end | |
257 end |