vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | local EMPTY_TABLE = {}; |
2 | local TIMEX_BAR = "TimexBar"; |
||
3 | local DEFAULT_SCALE = 0.8; |
||
4 | local DEFAULT_RES = 0.1; |
||
5 | |||
6 | local strformat = string.format; |
||
7 | |||
8 | local function ARG_ID(t) return t.timexBar.id; end; |
||
9 | local function ARG_ELAPSED(t) return t.timexBar.elapsed; end; |
||
10 | local function ARG_REMAINING(t) return t.timexBar.v; end; |
||
11 | |||
12 | local timexDebug = nil; |
||
13 | |||
14 | --<< ================================================= >>-- |
||
15 | -- Section I: Initialize the AddOn Object. -- |
||
16 | --<< ================================================= >>-- |
||
17 | |||
18 | TimexBar = AceModule:new({ |
||
19 | -- name = TimexLocals.TimexBar_Title, |
||
20 | -- author = "Rowne/facboy", |
||
21 | -- aceCompatible = "100", |
||
22 | |||
23 | ARG_ID = ARG_ID, |
||
24 | ARG_ELAPSED = ARG_ELAPSED, |
||
25 | ARG_REMAINING = ARG_REMAINING, |
||
26 | }) |
||
27 | |||
28 | function TimexBar:Enable() |
||
29 | self.barDB = {}; |
||
30 | self.barMap = setmetatable({}, Timex.weakV_mt); |
||
31 | table.setn(self.barDB, 20); |
||
32 | for id = 1,20,1 do getglobal(TIMEX_BAR..id):SetScale(DEFAULT_SCALE); end |
||
33 | --for id = 1,20,1 do getglobal(TIMEX_BAR..id):SetFrameStrata("TOOLTIP"); end |
||
34 | end |
||
35 | |||
36 | --<< ================================================= >>-- |
||
37 | -- Section II: Private utility functions. -- |
||
38 | --<< ================================================= >>-- |
||
39 | |||
40 | -------------------- |
||
41 | -- argument stuff |
||
42 | -------------------- |
||
43 | local args_switch = {}; |
||
44 | args_switch[ARG_ID] = ARG_ID; |
||
45 | args_switch[ARG_ELAPSED] = ARG_ELAPSED; |
||
46 | args_switch[ARG_REMAINING] = ARG_REMAINING; |
||
47 | |||
48 | local function buildArgs(args, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) |
||
49 | local sub = args.sub; |
||
50 | local f = args_switch[a20]; args[20], sub[20] = not f and a20 or nil, f; |
||
51 | f = args_switch[a19]; args[19], sub[19] = not f and a19 or nil, f; |
||
52 | f = args_switch[a18]; args[18], sub[18] = not f and a18 or nil, f; |
||
53 | f = args_switch[a17]; args[17], sub[17] = not f and a17 or nil, f; |
||
54 | f = args_switch[a16]; args[16], sub[16] = not f and a16 or nil, f; |
||
55 | f = args_switch[a15]; args[15], sub[15] = not f and a15 or nil, f; |
||
56 | f = args_switch[a14]; args[14], sub[14] = not f and a14 or nil, f; |
||
57 | f = args_switch[a13]; args[13], sub[13] = not f and a13 or nil, f; |
||
58 | f = args_switch[a12]; args[12], sub[12] = not f and a12 or nil, f; |
||
59 | f = args_switch[a11]; args[11], sub[11] = not f and a11 or nil, f; |
||
60 | f = args_switch[a10]; args[10], sub[10] = not f and a10 or nil, f; |
||
61 | f = args_switch[a9]; args[9], sub[9] = not f and a9 or nil, f; |
||
62 | f = args_switch[a8]; args[8], sub[8] = not f and a8 or nil, f; |
||
63 | f = args_switch[a7]; args[7], sub[7] = not f and a7 or nil, f; |
||
64 | f = args_switch[a6]; args[6], sub[6] = not f and a6 or nil, f; |
||
65 | f = args_switch[a5]; args[5], sub[5] = not f and a5 or nil, f; |
||
66 | f = args_switch[a4]; args[4], sub[4] = not f and a4 or nil, f; |
||
67 | f = args_switch[a3]; args[3], sub[3] = not f and a3 or nil, f; |
||
68 | f = args_switch[a2]; args[2], sub[2] = not f and a2 or nil, f; |
||
69 | f = args_switch[a1]; args[1], sub[1] = not f and a1 or nil, f; |
||
70 | end |
||
71 | |||
72 | local args_mt = { |
||
73 | __index = function(t, k) |
||
74 | local f = t.sub[k]; |
||
75 | if f then return f(t); end |
||
76 | end, |
||
77 | } |
||
78 | |||
79 | local function newArgs(timexBar) |
||
80 | local args = { timexBar = timexBar, sub = {} }; |
||
81 | setmetatable(args, args_mt); |
||
82 | return args; |
||
83 | end |
||
84 | |||
85 | --<< ================================================= >>-- |
||
86 | -- Section III: The Time-Event Handler. -- |
||
87 | --<< ================================================= >>-- |
||
88 | |||
89 | local function timexHandler(self, timexBar, elapsed) |
||
90 | --self.cmd:msg("timexHandler: timexBar.n = %s", tostring(timexBar.n)); |
||
91 | local v = timexBar.v; |
||
92 | if v then |
||
93 | v = v - elapsed; |
||
94 | if v <= 0 then |
||
95 | if timexBar.f then |
||
96 | timexBar.elapsed = elapsed; |
||
97 | local a = timexBar.a; |
||
98 | local status, err = pcall(timexBar.f, a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], a[18], a[19], a[20]); |
||
99 | if (not status) then |
||
100 | Timex.cmd:msg("TimexBar function '%s' failed with error: %s", tostring(timexBar.id), tostring(err)); |
||
101 | end |
||
102 | end |
||
103 | self:Stop(timexBar.id); |
||
104 | return; |
||
105 | elseif timexBar.uf then |
||
106 | timexBar.elapsed = elapsed; |
||
107 | local a = timexBar.ua; |
||
108 | local status, err = pcall(timexBar.uf, a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], a[18], a[19], a[20]); |
||
109 | if (not status) then |
||
110 | Timex.cmd:msg("TimexBar update function '%s' failed with error: %s", tostring(timexBar.id), tostring(err)); |
||
111 | end |
||
112 | end |
||
113 | -- Update bar |
||
114 | local settext = ceil(v); |
||
115 | settext = settext > 60 and (format("%d", settext / 60)..":"..format("%02d", mod(settext, 60))) or settext; |
||
116 | timexBar.ttxt:SetText(settext); |
||
117 | timexBar.sbar:SetValue(v); |
||
118 | timexBar.v = v; |
||
119 | end |
||
120 | end |
||
121 | |||
122 | --<< ================================================= >>-- |
||
123 | -- Section IV: The TimexBarClass 'inner' class -- |
||
124 | --<< ================================================= >>-- |
||
125 | |||
126 | -- class definition |
||
127 | local TimexBarClass = { |
||
128 | bR = 0.1, bB = 0.2, bG = 0.8, bA = 1.0, |
||
129 | tR = 1.0, tB = 1.0, tG = 1.0, tA = 1.0, |
||
130 | aP = "CENTER", aF = "UIParent", aRP = "CENTER", xO = 0, yO = 0, |
||
131 | }; |
||
132 | local TimexBarClass_mt = { __index = TimexBarClass }; |
||
133 | |||
134 | do |
||
135 | local bar = getglobal(TIMEX_BAR.."1"); |
||
136 | TimexBarClass.s, TimexBarClass.bW, TimexBarClass.bH = DEFAULT_SCALE, bar:GetWidth(), bar:GetHeight(); |
||
137 | local ttxt = getglobal(TIMEX_BAR.."1TimerText"); |
||
138 | TimexBarClass.tW = ttxt:GetWidth(); |
||
139 | end |
||
140 | |||
141 | -- private constructor |
||
142 | local function newTimexBar(timexBar, b) |
||
143 | local n = TIMEX_BAR..b; |
||
144 | local newInst = { |
||
145 | n = n, |
||
146 | bar = getglobal(n), |
||
147 | sbar = getglobal(n.."StatusBar"), |
||
148 | txt = getglobal(n.."Text"), |
||
149 | ttxt = getglobal(n.."TimerText"), |
||
150 | btn = getglobal(n.."Button"), |
||
151 | btnTex = getglobal(n.."ButtonTexture") |
||
152 | }; |
||
153 | setmetatable(newInst, TimexBarClass_mt); |
||
154 | return newInst; |
||
155 | end |
||
156 | |||
157 | -- private reset function (only resets the 'functional' attributes, not the formatting ones) |
||
158 | local function resetTimexBar(timexBar) |
||
159 | -- reset all values to nil |
||
160 | timexBar.id, timexBar.f, timexBar.uf, timexBar.elapsed, timexBar.v, timexBar.res = nil, nil, nil, nil, nil, nil; |
||
161 | -- clear arg tables |
||
162 | local args = timexBar.a; |
||
163 | if args then |
||
164 | args[1], args[2], args[3], args[4], args[5] = nil, nil, nil, nil, nil; |
||
165 | args[6], args[7], args[8], args[9], args[10] = nil, nil, nil, nil, nil; |
||
166 | args[11], args[12], args[13], args[14], args[15] = nil, nil, nil, nil, nil; |
||
167 | args[16], args[17], args[18], args[19], args[20] = nil, nil, nil, nil, nil; |
||
168 | end |
||
169 | args = timexBar.ua; |
||
170 | if args then |
||
171 | args[1], args[2], args[3], args[4], args[5] = nil, nil, nil, nil, nil; |
||
172 | args[6], args[7], args[8], args[9], args[10] = nil, nil, nil, nil, nil; |
||
173 | args[11], args[12], args[13], args[14], args[15] = nil, nil, nil, nil, nil; |
||
174 | args[16], args[17], args[18], args[19], args[20] = nil, nil, nil, nil, nil; |
||
175 | end |
||
176 | if timexBar.cf then |
||
177 | timexBar.cf = nil; |
||
178 | args = timexBar.ca; |
||
179 | if args then |
||
180 | args[1], args[2], args[3], args[4], args[5] = nil, nil, nil, nil, nil; |
||
181 | args[6], args[7], args[8], args[9], args[10] = nil, nil, nil, nil, nil; |
||
182 | args[11], args[12], args[13], args[14], args[15] = nil, nil, nil, nil, nil; |
||
183 | args[16], args[17], args[18], args[19], args[20] = nil, nil, nil, nil, nil; |
||
184 | end |
||
185 | end |
||
186 | end |
||
187 | |||
188 | -- private formatting function |
||
189 | local function resetTimexBarFormat(timexBar) |
||
190 | local bar, txt, ttxt = timexBar.bar, timexBar.txt, timexBar.ttxt; |
||
191 | |||
192 | if not timexBar.sColor and timexBar.rColor then |
||
193 | timexBar.bR, timexBar.bB, timexBar.bG, timexBar.bA = nil, nil, nil, nil; |
||
194 | timexBar.sbar:SetStatusBarColor(timexBar.bR, timexBar.bB, timexBar.bG, timexBar.bA); |
||
195 | timexBar.rColor = nil; |
||
196 | end |
||
197 | |||
198 | if not timexBar.sTextColor and timexBar.rTextColor then |
||
199 | timexBar.tR, timexBar.tB, timexBar.tG, timexBar.tA = nil, nil, nil, nil; |
||
200 | txt:SetTextColor(timexBar.tR, timexBar.tB, timexBar.tG, timexBar.tA); |
||
201 | ttxt:SetTextColor(timexBar.tR, timexBar.tB, timexBar.tG, timexBar.tA); |
||
202 | timexBar.rTextColor = nil; |
||
203 | end |
||
204 | |||
205 | if not timexBar.sPoint and timexBar.rPoint then |
||
206 | timexBar.aP, timexBar.aF, timexBar.aRP, timexBar.xO, timexBar.yO = nil, nil, nil, nil, nil; |
||
207 | bar:ClearAllPoints(); |
||
208 | bar:SetPoint(timexBar.aP, timexBar.aF, timexBar.aRP, timexBar.xO, timexBar.yO); |
||
209 | timexBar.rPoint = nil; |
||
210 | end |
||
211 | |||
212 | if not timexBar.sWidth and timexBar.rWidth then |
||
213 | timexBar.bW = nil; |
||
214 | bar:SetWidth(timexBar.bW); |
||
215 | timexBar.rWidth = nil; |
||
216 | end |
||
217 | |||
218 | if not timexBar.sHeight and timexBar.rHeight then |
||
219 | timexBar.bH = nil; |
||
220 | bar:SetHeight(timexBar.bH); |
||
221 | timexBar.rHeight = nil; |
||
222 | end |
||
223 | |||
224 | if not timexBar.sScale and timexBar.rScale then |
||
225 | timexBar.s = nil; |
||
226 | bar:SetScale(timexBar.s); |
||
227 | timexBar.rScale = nil; |
||
228 | end |
||
229 | |||
230 | if not timexBar.sTimeWidth and timexBar.rTimeWidth then |
||
231 | timexBar.tW = nil; |
||
232 | ttxt:SetWidth(timexBar.tW); |
||
233 | txt:SetPoint("TOPLEFT", bar, "LEFT", timexBar.tW, 13); |
||
234 | timexBar.rTimeWidth = nil; |
||
235 | end |
||
236 | |||
237 | if not timexBar.sText and timexBar.rText then |
||
238 | timexBar.text = nil; |
||
239 | if timexBar.text then |
||
240 | timexBar.txt:SetText("| "..timexBar.text); |
||
241 | else |
||
242 | timexBar.txt:SetText(""); |
||
243 | end |
||
244 | timexBar.rText = nil; |
||
245 | end |
||
246 | |||
247 | if not timexBar.sTexture and timexBar.rTexture then |
||
248 | timexBar.tex = nil; |
||
249 | if timexBar.tex then |
||
250 | timexBar.btnTex:SetTexture(timexBar.tex); |
||
251 | timexBar.btn:Show(); |
||
252 | else |
||
253 | timexBar.btn:Hide(); |
||
254 | end |
||
255 | timexBar.rTexture = nil; |
||
256 | end |
||
257 | end |
||
258 | |||
259 | local function clearSetFlags(timexBar) |
||
260 | timexBar.sColor, timexBar.sTextColor, timexBar.sPoint, timexBar.sWidth = nil, nil, nil, nil; |
||
261 | timexBar.sHeight, timexBar.sScale, timexBar.sTimeWidth, timexBar.sText, timexBar.sTexture = nil, nil, nil, nil, nil; |
||
262 | end |
||
263 | |||
264 | --<< ================================================= >>-- |
||
265 | -- Section V: The Start and Stop Bar Functions. -- |
||
266 | --<< ================================================= >>-- |
||
267 | |||
268 | -- Assigns a bar to id |
||
269 | function TimexBar:Get(id) |
||
270 | if id and id ~= "" then |
||
271 | local timexBar = self.barMap[id]; |
||
272 | -- if not found |
||
273 | if not timexBar then |
||
274 | -- find first available |
||
275 | local b = 1; |
||
276 | timexBar = self.barDB[b]; |
||
277 | while (timexBar) do |
||
278 | if (not timexBar.v) then |
||
279 | break; |
||
280 | end |
||
281 | b = b + 1; |
||
282 | timexBar = self.barDB[b]; |
||
283 | end |
||
284 | if timexBar then |
||
285 | clearSetFlags(timexBar); |
||
286 | elseif (b <= 20) then |
||
287 | timexBar = newTimexBar(self, b); |
||
288 | self.barDB[b] = timexBar; |
||
289 | else |
||
290 | error("No more bars available!"); |
||
291 | end |
||
292 | -- assign id |
||
293 | timexBar.id, self.barMap[id] = id, timexBar; |
||
294 | end |
||
295 | return timexBar.n; |
||
296 | end |
||
297 | end |
||
298 | |||
299 | function TimexBar:Start(id, time, res) |
||
300 | if (time) then |
||
301 | local timexBar = self.barMap[id]; |
||
302 | if timexBar then |
||
303 | res = res or DEFAULT_RES; |
||
304 | timexBar.v = time; |
||
305 | timexBar.res = res; |
||
306 | |||
307 | -- reset bar format and show |
||
308 | resetTimexBarFormat(timexBar); |
||
309 | |||
310 | local settext = ceil(timexBar.v); |
||
311 | settext = settext > 60 and format("%d:%02d", settext/60, mod(settext, 60)) or settext; |
||
312 | timexBar.ttxt:SetText(settext); |
||
313 | local sbar = timexBar.sbar; |
||
314 | sbar:SetMinMaxValues(0, time); |
||
315 | sbar:SetValue(timexBar.v); |
||
316 | |||
317 | if timexBar.cf then |
||
318 | timexBar.btn:EnableMouse(1); |
||
319 | timexBar.btn:SetScript("OnClick", timexBar.onClick); |
||
320 | end |
||
321 | timexBar.bar:Show(); |
||
322 | |||
323 | Timex:AddSchedule(timexBar, res, true, nil, timexHandler, self, timexBar, Timex.ARG_ELAPSED); |
||
324 | return timexBar.n; |
||
325 | else |
||
326 | error(strformat("TimexBar '%s' not found.", tostring(id))); |
||
327 | end |
||
328 | end |
||
329 | end |
||
330 | |||
331 | function TimexBar:Stop(id) |
||
332 | local timexBar = self.barMap[id]; |
||
333 | if timexBar then |
||
334 | Timex:DeleteSchedule(timexBar); |
||
335 | if timexBar.cf then |
||
336 | timexBar.btn:EnableMouse(0); |
||
337 | timexBar.btn:SetScript("OnClick", nil); |
||
338 | end |
||
339 | timexBar.bar:Hide(); |
||
340 | resetTimexBar(timexBar); |
||
341 | self.barMap[id] = nil; |
||
342 | end |
||
343 | end |
||
344 | |||
345 | function TimexBar:Pause(id) |
||
346 | local timexBar = self.barMap[id]; |
||
347 | if timexBar then |
||
348 | Timex:DeleteSchedule(timexBar); |
||
349 | end |
||
350 | end |
||
351 | |||
352 | function TimexBar:Resume(id) |
||
353 | local timexBar = self.barMap[id]; |
||
354 | if timexBar then |
||
355 | if timexBar.res then |
||
356 | Timex:AddSchedule(timexBar, timexBar.res, true, nil, timexHandler, self, timexBar, Timex.ARG_ELAPSED); |
||
357 | else |
||
358 | error(strformat("TimexBar '%s' has not been started yet.", tostring(id))); |
||
359 | end |
||
360 | end |
||
361 | end |
||
362 | |||
363 | function TimexBar:Check(id, r) |
||
364 | local timexBar = self.barMap[id]; |
||
365 | if timexBar then |
||
366 | return (r and timexBar.n) or TRUE; |
||
367 | end |
||
368 | end |
||
369 | |||
370 | function TimexBar:ChangeDuration(id, t) |
||
371 | local timexBar = self.barMap[id]; |
||
372 | if timexBar then |
||
373 | if timexBar.v then |
||
374 | timexBar.v = t; |
||
375 | end |
||
376 | end |
||
377 | end |
||
378 | |||
379 | function TimexBar:Debug(debug) |
||
380 | timexDebug = debug; |
||
381 | end |
||
382 | |||
383 | --<< ================================================= >>-- |
||
384 | -- Section VI: The Bar Formatting Functions -- |
||
385 | --<< ================================================= >>-- |
||
386 | |||
387 | function TimexBar:SetColor(id, red, blue, green, alpha) |
||
388 | local timexBar = self.barMap[id]; |
||
389 | if timexBar then |
||
390 | if timexBar.bR ~= red or timexBar.bB ~= blue or timexBar.bG ~= green or timexBar.bA ~= alpha then |
||
391 | timexBar.bR, timexBar.bB, timexBar.bG, timexBar.bA = red, blue, green, alpha; |
||
392 | timexBar.sbar:SetStatusBarColor(timexBar.bR, timexBar.bB, timexBar.bG, timexBar.bA); |
||
393 | timexBar.rColor = true; |
||
394 | end |
||
395 | timexBar.sColor = true; |
||
396 | else |
||
397 | error(strformat("TimexBar '%s' not found.", tostring(id))); |
||
398 | end |
||
399 | end |
||
400 | |||
401 | function TimexBar:SetTextColor(id, red, blue, green, alpha) |
||
402 | local timexBar = self.barMap[id]; |
||
403 | if timexBar then |
||
404 | if timexBar.tR ~= red or timexBar.tB ~= blue or timexBar.tG ~= green or timexBar.tA ~= alpha then |
||
405 | timexBar.tR, timexBar.tB, timexBar.tG, timexBar.tA = red, blue, green, alpha; |
||
406 | timexBar.txt:SetTextColor(timexBar.tR, timexBar.tB, timexBar.tG, timexBar.tA); |
||
407 | timexBar.ttxt:SetTextColor(timexBar.tR, timexBar.tB, timexBar.tG, timexBar.tA); |
||
408 | timexBar.rTextColor = true; |
||
409 | end |
||
410 | timexBar.sTextColor = true; |
||
411 | else |
||
412 | error(strformat("TimexBar '%s' not found.", tostring(id))); |
||
413 | end |
||
414 | end |
||
415 | |||
416 | function TimexBar:SetPoint(id, point, relativeFrame, relativePoint, xOffset, yOffset) |
||
417 | local timexBar = self.barMap[id]; |
||
418 | if timexBar then |
||
419 | if timexBar.aP ~= point or timexBar.aF ~= relativeFrame or timexBar.aRP ~= relativePoint or timexBar.xO ~= xOffset or timexBar.yO ~= yOffset then |
||
420 | timexBar.aP, timexBar.aF, timexBar.aRP, timexBar.xO, timexBar.yO = point, relativeFrame, relativePoint, xOffset, yOffset; |
||
421 | local bar = timexBar.bar; |
||
422 | bar:ClearAllPoints(); |
||
423 | bar:SetPoint(timexBar.aP, timexBar.aF, timexBar.aRP, timexBar.xO, timexBar.yO); |
||
424 | timexBar.rPoint = true; |
||
425 | end |
||
426 | timexBar.sPoint = true; |
||
427 | else |
||
428 | error(strformat("TimexBar '%s' not found.", tostring(id))); |
||
429 | end |
||
430 | end |
||
431 | |||
432 | function TimexBar:SetWidth(id, width) |
||
433 | local timexBar = self.barMap[id]; |
||
434 | if timexBar then |
||
435 | if timexBar.bW ~= width then |
||
436 | timexBar.bW = width; |
||
437 | timexBar.bar:SetWidth(timexBar.bW); |
||
438 | timexBar.rWidth = true; |
||
439 | end |
||
440 | timexBar.sWidth = true; |
||
441 | else |
||
442 | error(strformat("TimexBar '%s' not found.", tostring(id))); |
||
443 | end |
||
444 | end |
||
445 | |||
446 | function TimexBar:SetHeight(id, height) |
||
447 | local timexBar = self.barMap[id]; |
||
448 | if timexBar then |
||
449 | if timexBar.bH ~= height then |
||
450 | timexBar.bH = height; |
||
451 | timexBar.bar:SetHeight(timexBar.bH); |
||
452 | timexBar.rHeight = true; |
||
453 | end |
||
454 | timexBar.sHeight = true; |
||
455 | else |
||
456 | error(strformat("TimexBar '%s' not found.", tostring(id))); |
||
457 | end |
||
458 | end |
||
459 | |||
460 | function TimexBar:SetScale(id, scale) |
||
461 | local timexBar = self.barMap[id]; |
||
462 | if timexBar then |
||
463 | if timexBar.s ~= scale then |
||
464 | timexBar.s = scale; |
||
465 | timexBar.bar:SetScale(timexBar.s); |
||
466 | timexBar.rScale = true; |
||
467 | end |
||
468 | timexBar.sScale = true; |
||
469 | else |
||
470 | error(strformat("TimexBar '%s' not found.", tostring(id))); |
||
471 | end |
||
472 | end |
||
473 | |||
474 | function TimexBar:SetTimeWidth(id, width) |
||
475 | local timexBar = self.barMap[id]; |
||
476 | if timexBar then |
||
477 | if timexBar.tW ~= width then |
||
478 | timexBar.tW = width; |
||
479 | timexBar.ttxt:SetWidth(timexBar.tW); |
||
480 | timexBar.txt:SetPoint("TOPLEFT", timexBar.bar, "LEFT", timexBar.tW, 13); |
||
481 | timexBar.rTimeWidth = true; |
||
482 | end |
||
483 | timexBar.sTimeWidth = true; |
||
484 | else |
||
485 | error(strformat("TimexBar '%s' not found.", tostring(id))); |
||
486 | end |
||
487 | end |
||
488 | |||
489 | function TimexBar:SetText(id, text) |
||
490 | local timexBar = self.barMap[id]; |
||
491 | if timexBar then |
||
492 | if timexBar.text ~= text then |
||
493 | timexBar.text = text; |
||
494 | if timexBar.text then |
||
495 | timexBar.txt:SetText("| "..timexBar.text); |
||
496 | else |
||
497 | timexBar.txt:SetText(""); |
||
498 | end |
||
499 | timexBar.rText = true; |
||
500 | end |
||
501 | timexBar.sText = true; |
||
502 | else |
||
503 | error(strformat("TimexBar '%s' not found.", tostring(id))); |
||
504 | end |
||
505 | end |
||
506 | |||
507 | function TimexBar:SetTexture(id, texturePath) |
||
508 | local timexBar = self.barMap[id]; |
||
509 | if timexBar then |
||
510 | if timexBar.tex ~= texturePath then |
||
511 | timexBar.tex = texturePath; |
||
512 | if timexBar.tex then |
||
513 | timexBar.btnTex:SetTexture(timexBar.tex); |
||
514 | timexBar.btn:Show(); |
||
515 | else |
||
516 | timexBar.btn:Hide(); |
||
517 | end |
||
518 | timexBar.rTexture = true; |
||
519 | end |
||
520 | timexBar.sTexture = true; |
||
521 | else |
||
522 | error(strformat("TimexBar '%s' not found.", tostring(id))); |
||
523 | end |
||
524 | end |
||
525 | |||
526 | function TimexBar:SetFunction(id, f, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) |
||
527 | local timexBar = self.barMap[id]; |
||
528 | if timexBar then |
||
529 | timexBar.f = f; |
||
530 | if not timexBar.a then |
||
531 | timexBar.a = newArgs(timexBar); |
||
532 | end |
||
533 | buildArgs(timexBar.a, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); |
||
534 | else |
||
535 | error(strformat("TimexBar '%s' not found.", tostring(id))); |
||
536 | end |
||
537 | end |
||
538 | |||
539 | function TimexBar:SetUpdateFunction(id, f, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) |
||
540 | local timexBar = self.barMap[id]; |
||
541 | if timexBar then |
||
542 | timexBar.uf = f; |
||
543 | if not timexBar.ua then |
||
544 | timexBar.ua = newArgs(timexBar); |
||
545 | end |
||
546 | buildArgs(timexBar.ua, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); |
||
547 | else |
||
548 | error(strformat("TimexBar '%s' not found.", tostring(id))); |
||
549 | end |
||
550 | end |
||
551 | |||
552 | function TimexBar:SetClickFunction(id, f, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) |
||
553 | local timexBar = self.barMap[id]; |
||
554 | if timexBar then |
||
555 | -- create the onClick function for this bar. |
||
556 | if not timexBar.onClick then |
||
557 | timexBar.onClick = function() |
||
558 | local a = timexBar.ca; |
||
559 | local status, err = pcall(timexBar.cf, a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], a[18], a[19], a[20]); |
||
560 | if not status then |
||
561 | Timex.cmd:msg("TimexBar click function '%s' failed with error: %s", tostring(timexBar.id), tostring(err)); |
||
562 | end |
||
563 | end |
||
564 | end |
||
565 | |||
566 | timexBar.cf = f; |
||
567 | if not timexBar.ca then |
||
568 | timexBar.ca = newArgs(timexBar); |
||
569 | end |
||
570 | buildArgs(timexBar.ca, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); |
||
571 | else |
||
572 | error(strformat("TimexBar '%s' not found.", tostring(id))); |
||
573 | end |
||
574 | end |
||
575 | |||
576 | --<< ================================================= >>-- |
||
577 | -- Section Omega: Register the AddOn Object. -- |
||
578 | --<< ================================================= >>-- |
||
579 | |||
580 | --TimexBar:RegisterForLoad() |