vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | DynamicData |
||
3 | |||
4 | By sarf |
||
5 | |||
6 | This AddOn allows you to access dynamic data in WoW without being forced to rely on strange Blizzard functions |
||
7 | |||
8 | Thanks goes to the Sea people, the UltimateUI team and finally the nice (but strange) people at |
||
9 | #ultimateuitesters and Blizzard. |
||
10 | |||
11 | UltimateUIUI URL: |
||
12 | http://www.ultimateuiui.org/forums/viewtopic.php?t=NOT_YET_ANNOUNCED |
||
13 | |||
14 | ]] |
||
15 | |||
16 | |||
17 | -- Utility functions |
||
18 | DynamicData.util = { |
||
19 | |||
20 | -- public functions |
||
21 | |||
22 | -- |
||
23 | -- addOnWhateverHandler (func) |
||
24 | -- |
||
25 | -- Adds a function name that will be called on whatever. |
||
26 | -- |
||
27 | addOnWhateverHandler = function (list, func) |
||
28 | for k, v in list do |
||
29 | if ( v == func ) then |
||
30 | return false; |
||
31 | end |
||
32 | end |
||
33 | table.insert(list, func); |
||
34 | return true; |
||
35 | end; |
||
36 | |||
37 | -- |
||
38 | -- removeOnWhateverHandler (list, func) |
||
39 | -- |
||
40 | -- Removes the specified function, so that it will not be called on whatever. |
||
41 | -- |
||
42 | removeOnWhateverHandler = function (list, func) |
||
43 | local index = nil; |
||
44 | for k, v in list do |
||
45 | if ( v == func ) then |
||
46 | index = k; |
||
47 | break; |
||
48 | end |
||
49 | end |
||
50 | if ( index ) then |
||
51 | table.remove(list, index); |
||
52 | return true; |
||
53 | else |
||
54 | return false; |
||
55 | end |
||
56 | end; |
||
57 | |||
58 | -- |
||
59 | -- notifyWhateverHandlers (list, ...) |
||
60 | -- |
||
61 | -- Args: |
||
62 | -- list - the list of handlers |
||
63 | -- |
||
64 | -- Notifies all handlers that an Whatever has occurred. |
||
65 | -- |
||
66 | notifyWhateverHandlers = function (list, ...) |
||
67 | local func = nil; |
||
68 | for k, v in list do |
||
69 | func = v; |
||
70 | if ( arg ) then |
||
71 | func(unpack(arg)); |
||
72 | else |
||
73 | func(); |
||
74 | end |
||
75 | end |
||
76 | end; |
||
77 | |||
78 | -- |
||
79 | -- removeEntryFromList (value, list, limit) |
||
80 | -- |
||
81 | -- Removes value from the list, up to limit times. |
||
82 | -- If limit is not specified, it will be removed once. If limit is 0 or lower, all values will be removed. |
||
83 | -- |
||
84 | removeEntryFromList = function (value, list, limit) |
||
85 | if ( not limit ) then limit = 1; end |
||
86 | if ( limit <= 0 ) then limit = -1; end |
||
87 | local hasRemoved = false; |
||
88 | local found = true; |
||
89 | local index = 1; |
||
90 | while ( found ) do |
||
91 | found = false; |
||
92 | index = DynamicData.util.getIndexInList(value, list); |
||
93 | if ( index ) then |
||
94 | found = true; |
||
95 | table.remove(list, index); |
||
96 | hasRemoved = true; |
||
97 | if ( limit > 0 ) then |
||
98 | limit = limit - 1; |
||
99 | end |
||
100 | if ( limit == 0 ) then |
||
101 | break; |
||
102 | end |
||
103 | end |
||
104 | end |
||
105 | return hasRemoved; |
||
106 | end; |
||
107 | |||
108 | -- |
||
109 | -- isThingyEqual(value, valueCheck) |
||
110 | -- |
||
111 | -- compares two things and sees if they are equal to each other |
||
112 | -- |
||
113 | isThingyEqual = function(value, valueCheck) |
||
114 | if ( value == valueCheck ) then |
||
115 | return true; |
||
116 | else |
||
117 | if ( type(valueCheck) == "table" ) then |
||
118 | return DynamicData.util.isStringInList(value, valueCheck); |
||
119 | end |
||
120 | return false; |
||
121 | end |
||
122 | end; |
||
123 | |||
124 | -- |
||
125 | -- getIndexInList (value, list, start) |
||
126 | -- |
||
127 | -- Retrieves the index of value in list, starting at start. |
||
128 | -- Start is 1 if unspecified. |
||
129 | -- |
||
130 | getIndexInList = function (value, list, start) |
||
131 | if ( not value ) then |
||
132 | return nil; |
||
133 | end |
||
134 | if ( not list ) then |
||
135 | return nil; |
||
136 | end |
||
137 | if ( type(list) ~= "table" ) and ( type(value) == "table" ) then |
||
138 | local tmp = list; |
||
139 | list = value; |
||
140 | value = tmp; |
||
141 | end |
||
142 | local found = true; |
||
143 | local index = nil; |
||
144 | local listSize = table.getn(list); |
||
145 | local oldStart = start; |
||
146 | if ( listSize > 0 ) then |
||
147 | if ( not start ) then start = 1; end |
||
148 | for i = start, listSize do |
||
149 | if ( DynamicData.util.isThingyEqual(list[i], value ) ) then |
||
150 | index = i; |
||
151 | break; |
||
152 | end |
||
153 | end |
||
154 | if ( not index ) then |
||
155 | for k, v in list do |
||
156 | if ( ( not oldStart ) or ( oldStart >= k ) ) and ( DynamicData.util.isThingyEqual(v, value ) ) then |
||
157 | index = k; |
||
158 | break; |
||
159 | end |
||
160 | end |
||
161 | end |
||
162 | else |
||
163 | for k, v in list do |
||
164 | if ( DynamicData.util.isThingyEqual(v, value ) ) then |
||
165 | index = k; |
||
166 | break; |
||
167 | end |
||
168 | end |
||
169 | end |
||
170 | return index; |
||
171 | end; |
||
172 | |||
173 | |||
174 | -- |
||
175 | -- isStringInList (str, list) |
||
176 | -- |
||
177 | -- Returns true if str is a value of list. |
||
178 | -- |
||
179 | isStringInList = function (param1, param2) |
||
180 | if ( not param1 ) or ( not param2 ) then |
||
181 | return false; |
||
182 | end |
||
183 | local str = param1; |
||
184 | local list = param2; |
||
185 | if ( type(param1) == "table" ) then |
||
186 | str = param2; |
||
187 | list = param1; |
||
188 | end |
||
189 | for k, v in list do |
||
190 | if ( v == str ) then |
||
191 | return true; |
||
192 | end |
||
193 | end |
||
194 | return false; |
||
195 | end; |
||
196 | |||
197 | -- |
||
198 | -- safeToUseTooltips () |
||
199 | -- |
||
200 | -- Checks if it is "safe" to use tooltips to dump information. |
||
201 | -- Basically, it checks if one (or more) particular frames are visible. |
||
202 | -- If they are, it is not safe to use tooltips. |
||
203 | safeToUseTooltips = function (ignoreList) |
||
204 | local frame = nil; |
||
205 | local list = {}; |
||
206 | if ( DynamicData.util.tooltipUsingFrames ) then |
||
207 | for k, v in DynamicData.util.tooltipUsingFrames do |
||
208 | list[v] = 1; |
||
209 | end |
||
210 | end |
||
211 | if ( ignoreList ) then |
||
212 | for k, v in ignoreList do |
||
213 | list[v] = nil; |
||
214 | end |
||
215 | end |
||
216 | for k, v in list do |
||
217 | frame = getglobal(k); |
||
218 | if ( ( frame ) and ( frame:IsVisible() ) ) then |
||
219 | return false; |
||
220 | end |
||
221 | end |
||
222 | return true; |
||
223 | end; |
||
224 | |||
225 | -- |
||
226 | -- clearTooltipStrings (tooltipName) |
||
227 | -- |
||
228 | -- Clears a tooltip of text. |
||
229 | -- |
||
230 | clearTooltipStrings = function (tooltipName) |
||
231 | -- local tooltip = getglobal(tooltipName); |
||
232 | if ( tooltip ) then |
||
233 | local textObj = nil; |
||
234 | for i = 1, 15 do |
||
235 | textObj = getglobal(tooltipName.."TextLeft"..i); |
||
236 | if ( textObj ) then |
||
237 | textObj:SetText(""); |
||
238 | end |
||
239 | textObj = getglobal(tooltipName.."TextRight"..i); |
||
240 | if ( textObj ) then |
||
241 | textObj:SetText(""); |
||
242 | end |
||
243 | end |
||
244 | end |
||
245 | end; |
||
246 | |||
247 | -- |
||
248 | -- getNameFromTooltip (tooltipName) |
||
249 | -- |
||
250 | -- Retrieves the name from the specified tooltip. |
||
251 | -- |
||
252 | getNameFromTooltip = function (tooltipName) |
||
253 | local strings = DynamicData.util.getTooltipStrings(tooltipName); |
||
254 | if ( strings ) and ( strings[1] ) then |
||
255 | return strings[1].left; |
||
256 | else |
||
257 | return nil; |
||
258 | end |
||
259 | end; |
||
260 | |||
261 | -- |
||
262 | -- getTooltipStrings (tooltipName) |
||
263 | -- |
||
264 | -- Retrieves strings from the specified tooltip. |
||
265 | -- It basically takes all strings in the tooltip and puts them in an array and returns the array. |
||
266 | -- All credit to Sea for this one, even though it is not copy/pasted! ;) |
||
267 | -- |
||
268 | getTooltipStrings = function (tooltipName, strings) |
||
269 | if ( not strings ) then |
||
270 | strings = {}; |
||
271 | end |
||
272 | local tooltip = getglobal(tooltipName); |
||
273 | if ( tooltip ) then |
||
274 | local textObj = nil; |
||
275 | local textLeft = nil; |
||
276 | local textRight = nil; |
||
277 | local hasElement = false; |
||
278 | for i = 1, 15 do |
||
279 | hasElement = false; |
||
280 | textObj = getglobal(tooltipName.."TextLeft"..i); |
||
281 | if ( textObj ) then |
||
282 | textLeft = textObj:GetText(); |
||
283 | if ( textLeft ) and ( strlen(textLeft) > 0 ) then |
||
284 | hasElement = true; |
||
285 | end |
||
286 | else |
||
287 | textLeft = nil; |
||
288 | end |
||
289 | textObj = getglobal(tooltipName.."TextRight"..i); |
||
290 | if ( textObj ) then |
||
291 | textRight = textObj:GetText(); |
||
292 | if ( textRight ) and ( strlen(textRight) > 0 ) then |
||
293 | hasElement = true; |
||
294 | end |
||
295 | else |
||
296 | textRight = nil; |
||
297 | end |
||
298 | if ( hasElement ) then |
||
299 | strings[i] = {}; |
||
300 | strings[i].left = textLeft; |
||
301 | strings[i].right = textRight; |
||
302 | end |
||
303 | end |
||
304 | end |
||
305 | return strings; |
||
306 | end; |
||
307 | |||
308 | -- |
||
309 | -- getItemTooltipInfo (bag, slot, tooltipName) |
||
310 | -- |
||
311 | -- Retrieves info about a particular item. |
||
312 | -- |
||
313 | getItemTooltipInfo = function (bag, slot, tooltipName, strings) |
||
314 | if ( not tooltipName ) then |
||
315 | tooltipName = "DynamicDataTooltip"; |
||
316 | end |
||
317 | local tooltip = getglobal(tooltipName); |
||
318 | DynamicData.util.clearTooltipStrings(tooltipName); |
||
319 | if ( bag > -1 ) then |
||
320 | DynamicData.util.protectTooltipMoney(); |
||
321 | tooltip:SetBagItem(bag, slot); |
||
322 | DynamicData.util.unprotectTooltipMoney(); |
||
323 | strings = DynamicData.util.getTooltipStrings(tooltipName, strings); |
||
324 | else |
||
325 | if ( slot == -1 ) then |
||
326 | return nil; |
||
327 | end |
||
328 | DynamicData.util.protectTooltipMoney(); |
||
329 | local hasItem, hasCooldown = tooltip:SetInventoryItem("player", slot); |
||
330 | DynamicData.util.unprotectTooltipMoney(); |
||
331 | strings = DynamicData.util.getTooltipStrings(tooltipName, strings); |
||
332 | if ( not hasItem) then |
||
333 | DynamicData.util.clearTooltipStrings(tooltipName); |
||
334 | if ( strings[1] ) then |
||
335 | strings[1].left = ""; |
||
336 | end |
||
337 | end |
||
338 | end |
||
339 | return strings; |
||
340 | end; |
||
341 | |||
342 | -- |
||
343 | -- getCurrentAndMaxDurability (strings) |
||
344 | -- |
||
345 | -- Extracts durability info from an array that correspond to a tooltip. |
||
346 | -- |
||
347 | getCurrentAndMaxDurability = function (strings) |
||
348 | if ( not strings ) then |
||
349 | return nil, nil; |
||
350 | end |
||
351 | local index = nil; |
||
352 | local index2 = nil; |
||
353 | local tmp = nil; |
||
354 | for k, v in strings do |
||
355 | if ( v.left ) then |
||
356 | index = strfind(v.left, DYNAMICDATA_DURABILITY); |
||
357 | if ( index ) then |
||
358 | tmp = strsub(v.left, strlen(DYNAMICDATA_DURABILITY)+1); |
||
359 | while ( strsub(tmp, 1, 1) == " " ) do |
||
360 | tmp = strsub(tmp, 2); |
||
361 | end |
||
362 | index = strfind(tmp, " "); |
||
363 | index2 = strfind(tmp, "/"); |
||
364 | if ( index2 < index ) then |
||
365 | local indexTmp = index; |
||
366 | index = index2; |
||
367 | index2 = indexTmp; |
||
368 | end |
||
369 | local currentDurability = tonumber(strsub(tmp, 1, index-1)); |
||
370 | tmp = strsub(tmp, index2+1); |
||
371 | while ( strsub(tmp, 1, 1) == " " ) do |
||
372 | tmp = strsub(tmp, 2); |
||
373 | end |
||
374 | index = strfind(tmp, " "); |
||
375 | if ( not index ) then |
||
376 | index = strlen(tmp); |
||
377 | end |
||
378 | local maxDurability = tonumber(strsub(tmp, 1, index)); |
||
379 | return currentDurability, maxDurability; |
||
380 | end |
||
381 | end |
||
382 | end |
||
383 | return nil, nil; |
||
384 | end; |
||
385 | |||
386 | -- |
||
387 | -- getDPS (strings) |
||
388 | -- |
||
389 | -- Extracts DPS info from an array that correspond to a tooltip. |
||
390 | -- |
||
391 | getDPS = function (strings) |
||
392 | if ( not strings ) then |
||
393 | return nil, nil; |
||
394 | end |
||
395 | local tmpNumber = nil; |
||
396 | local tmp = nil; |
||
397 | for k, v in strings do |
||
398 | for tmp in string.gfind(v.left, DYNAMICDATA_DPS_GSUB) do |
||
399 | tmpNumber = tonumber(tmp); |
||
400 | if ( tmpNumber ) then |
||
401 | return tmpNumber; |
||
402 | end |
||
403 | end |
||
404 | end |
||
405 | return nil; |
||
406 | end; |
||
407 | |||
408 | |||
409 | -- |
||
410 | -- getItemNameFromLink (link) |
||
411 | -- |
||
412 | -- retrieves an item name from a link or nil if it fails |
||
413 | -- Thanks to Telo for providing me with the code! |
||
414 | -- |
||
415 | getItemNameFromLink = function (link) |
||
416 | local name; |
||
417 | if( not link ) then |
||
418 | return nil; |
||
419 | end |
||
420 | for name in string.gfind(link, "|c%x+|Hitem:%d+:%d+:%d+:%d+|h%[(.-)%]|h|r") do |
||
421 | return name; |
||
422 | end |
||
423 | return nil; |
||
424 | end; |
||
425 | |||
426 | -- |
||
427 | -- isItemNotBindOnAnything (strings) |
||
428 | -- |
||
429 | -- Checks if the item represented by the parameter is not bind on anything. |
||
430 | -- |
||
431 | isItemNotBindOnAnything = function (strings) |
||
432 | if ( not strings ) then |
||
433 | return false; |
||
434 | end |
||
435 | local tmpNumber = nil; |
||
436 | local tmp = nil; |
||
437 | for k, v in strings do |
||
438 | if ( ( v.left ) and ( string.find(v.left, DYNAMICDATA_BIND_ON) ) ) then |
||
439 | return true; |
||
440 | end |
||
441 | end |
||
442 | return false; |
||
443 | end; |
||
444 | |||
445 | -- |
||
446 | -- getDamage (strings) |
||
447 | -- |
||
448 | -- Extracts damage info from an array that correspond to a tooltip. |
||
449 | -- |
||
450 | getDamage = function (strings) |
||
451 | if ( not strings ) then |
||
452 | return nil, nil; |
||
453 | end |
||
454 | local tmpNumber = nil; |
||
455 | local tmp = nil; |
||
456 | for k, v in strings do |
||
457 | if ( v.left ) then |
||
458 | local firstNumber = nil; |
||
459 | for tmp in string.gfind(v.left, "%w+") do |
||
460 | tmpNumber = tonumber(tmp); |
||
461 | if ( tmpNumber ) then |
||
462 | if ( firstNumber ) then |
||
463 | return firstNumber, tmpNumber; |
||
464 | else |
||
465 | firstNumber = tmpNumber; |
||
466 | end |
||
467 | end |
||
468 | end |
||
469 | end |
||
470 | end |
||
471 | return nil, nil; |
||
472 | end; |
||
473 | |||
474 | -- |
||
475 | -- getItemStringType (strings) |
||
476 | -- |
||
477 | -- Extracts item type information from an array that correspond to a tooltip. |
||
478 | -- |
||
479 | getItemStringType = function (strings) |
||
480 | if ( not strings ) then |
||
481 | return nil; |
||
482 | end |
||
483 | local str = nil; |
||
484 | if ( ( strings[2] ) and ( strings[2].right ) ) then |
||
485 | str = strings[2].right; |
||
486 | end |
||
487 | if ( ( not str ) or ( strlen(str) <= 0 ) ) then |
||
488 | if ( ( strings[3] ) and ( strings[3].right ) ) then |
||
489 | str = strings[3].right; |
||
490 | end |
||
491 | end |
||
492 | if ( ( not str ) or ( strlen(str) <= 0 ) ) then |
||
493 | if ( ( strings[4] ) and ( strings[4].right ) ) then |
||
494 | str = strings[4].right; |
||
495 | end |
||
496 | end |
||
497 | return str; |
||
498 | end; |
||
499 | |||
500 | -- |
||
501 | -- extractWeaponSpeed (str) |
||
502 | -- |
||
503 | -- Extracts weapon speed information from a string. |
||
504 | -- |
||
505 | extractWeaponSpeed = function (str) |
||
506 | local speed = -1; |
||
507 | local tmp = str; |
||
508 | local index = strfind(tmp, DYNAMICDATA_WEAPON_SPEED); |
||
509 | if ( index ) then |
||
510 | tmp = strsub(tmp, index+1); |
||
511 | while ( strsub(tmp, 1, 1) == " " ) do |
||
512 | tmp = strsub(tmp, 2); |
||
513 | end |
||
514 | speed = tonumber(tmp); |
||
515 | if ( not speed ) then |
||
516 | speed = -1; |
||
517 | end |
||
518 | end |
||
519 | return speed; |
||
520 | end; |
||
521 | |||
522 | -- |
||
523 | -- getWeaponSpeed (strings) |
||
524 | -- |
||
525 | -- Extracts weapon speed information from an array that correspond to a tooltip. |
||
526 | -- |
||
527 | getWeaponSpeed = function (strings) |
||
528 | if ( not strings ) then |
||
529 | return nil; |
||
530 | end |
||
531 | local str = ""; |
||
532 | if ( ( strings[2] ) and ( strings[2].right ) ) then |
||
533 | str = strings[2].right; |
||
534 | end |
||
535 | if ( strlen(str) <= 0 ) then |
||
536 | if ( ( strings[3] ) and ( strings[3].right ) ) then |
||
537 | str = strings[3].right; |
||
538 | end |
||
539 | else |
||
540 | end |
||
541 | if ( strlen(str) <= 0 ) then |
||
542 | if ( ( strings[4] ) and ( strings[4].right ) ) then |
||
543 | str = strings[4].right; |
||
544 | end |
||
545 | end |
||
546 | local speed = DynamicData.util.extractWeaponSpeed(str); |
||
547 | if ( speed <= 0 ) then |
||
548 | return nil; |
||
549 | else |
||
550 | return speed; |
||
551 | end |
||
552 | end; |
||
553 | |||
554 | -- |
||
555 | -- protectTooltipMoney () |
||
556 | -- |
||
557 | -- Thanks to Telo for providing this solution! |
||
558 | -- Prevents the clearing of money from tooltips. |
||
559 | -- USE WITH CAUTION! ALWAYS CALL unhookMoneyTooltip() AFTER SETTING THE TOOLTIP! |
||
560 | -- |
||
561 | protectTooltipMoney = function() |
||
562 | if ( not DynamicData.util.saved_GameTooltip_ClearMoney ) then |
||
563 | DynamicData.util.saved_GameTooltip_ClearMoney = GameTooltip_ClearMoney; |
||
564 | GameTooltip_ClearMoney = DynamicData.util.doNothing; |
||
565 | end |
||
566 | end; |
||
567 | |||
568 | -- |
||
569 | -- unprotectTooltipMoney () |
||
570 | -- |
||
571 | -- Thanks to Telo for providing this solution! |
||
572 | -- Allows the clearing of money from tooltips. |
||
573 | -- |
||
574 | unprotectTooltipMoney = function() |
||
575 | if ( DynamicData.util.saved_GameTooltip_ClearMoney ) then |
||
576 | GameTooltip_ClearMoney = DynamicData.util.saved_GameTooltip_ClearMoney; |
||
577 | DynamicData.util.saved_GameTooltip_ClearMoney = nil; |
||
578 | end |
||
579 | end; |
||
580 | |||
581 | -- |
||
582 | -- scheduleFunction(when, function, [arguments]) |
||
583 | -- |
||
584 | -- schedules a function to occur in WHEN seconds. |
||
585 | -- |
||
586 | scheduleFunction = function(when, func, ...) |
||
587 | if ( not when ) then |
||
588 | return; |
||
589 | end |
||
590 | if ( not func ) then |
||
591 | return; |
||
592 | end |
||
593 | local scheduledFunction = {}; |
||
594 | scheduledFunction.time = when+GetTime(); |
||
595 | scheduledFunction.func = func; |
||
596 | scheduledFunction.args = arg; |
||
597 | DynamicData.util.addScheduledFunction(scheduledFunction); |
||
598 | end; |
||
599 | |||
600 | -- |
||
601 | -- scheduleNamedFunction(name, when, function, [arguments]) |
||
602 | -- |
||
603 | -- schedules a function to occur in WHEN seconds. Only one function with the same name will be scheduled. |
||
604 | -- |
||
605 | scheduleNamedFunction = function(name, when, func, ...) |
||
606 | if ( not name ) then |
||
607 | if ( arg ) then |
||
608 | return DynamicData.util.scheduleFunction(when, func, unpack(arg)); |
||
609 | else |
||
610 | return DynamicData.util.scheduleFunction(when, func); |
||
611 | end |
||
612 | end |
||
613 | if ( not func ) then |
||
614 | return; |
||
615 | end |
||
616 | local scheduledFunction = {}; |
||
617 | scheduledFunction.name = name; |
||
618 | scheduledFunction.time = when+GetTime(); |
||
619 | scheduledFunction.func = func; |
||
620 | scheduledFunction.args = arg; |
||
621 | local i; |
||
622 | local size = table.getn(DynamicData.util.scheduledFunctions); |
||
623 | local entry = nil; |
||
624 | for i=1, size, 1 do |
||
625 | entry = DynamicData.util.scheduledFunctions[i]; |
||
626 | if ( ( entry.name ) and ( entry.name == name ) ) then |
||
627 | table.remove(DynamicData.util.scheduledFunctions, i); |
||
628 | break; |
||
629 | end |
||
630 | end |
||
631 | DynamicData.util.addScheduledFunction(scheduledFunction); |
||
632 | end; |
||
633 | |||
634 | -- |
||
635 | -- scheduleAfterInitFunction (function, [args] ) |
||
636 | -- |
||
637 | -- schedules a function to be run after the init. |
||
638 | -- |
||
639 | scheduleAfterInitFunction = function (func, ...) |
||
640 | local playerName = UnitName("player"); |
||
641 | if ( ( playerName ) and ( playerName ~= TEXT(UKNOWNBEING) ) and ( DynamicData.util.variablesHasBeenLoaded ) ) then |
||
642 | if ( arg ) then |
||
643 | func(unpack(arg)); |
||
644 | else |
||
645 | func(); |
||
646 | end |
||
647 | else |
||
648 | if ( arg ) then |
||
649 | DynamicData.util.scheduleFunction(1, DynamicData.util.scheduleAfterInitFunction, func, unpack(arg)); |
||
650 | else |
||
651 | DynamicData.util.scheduleFunction(1, DynamicData.util.scheduleAfterInitFunction, func); |
||
652 | end |
||
653 | end |
||
654 | end; |
||
655 | |||
656 | -- protected functions |
||
657 | |||
658 | -- |
||
659 | -- postpone (params) |
||
660 | -- |
||
661 | -- params.schedulingName = scheduling name |
||
662 | -- params.func = function name |
||
663 | -- params.args = function arguments |
||
664 | -- params.lastPostponedName = name of the variable with last postponed information |
||
665 | -- params.lastUpdatedName = name of the variable with last updated information |
||
666 | -- params.minimumDelay = the smallest amount of time between function calls |
||
667 | -- |
||
668 | postpone = function (params) |
||
669 | local curTime = GetTime(); |
||
670 | if ( not params.minimumDelay ) then |
||
671 | params.minimumDelay = 0.1; |
||
672 | end |
||
673 | if ( not params.lastPostponedName ) then |
||
674 | params.lastPostponedName = params.schedulingName.."_lastPostponedName"; |
||
675 | end |
||
676 | if ( not params.lastUpdatedName ) then |
||
677 | params.lastUpdatedName = params.schedulingName.."_lastUpdatedName"; |
||
678 | end |
||
679 | setglobal(params.lastPostponedName, curTime); |
||
680 | -- postpone checking until the updates have stopped |
||
681 | if ( params.schedulingName ) then |
||
682 | UltimateUI_ScheduleByName(params.schedulingName, params.minimumDelay+0.01, DynamicData.util.handlePostponement, params); |
||
683 | else |
||
684 | UltimateUI_Schedule(params.minimumDelay+0.01, DynamicData.util.handlePostponement, params); |
||
685 | end |
||
686 | end; |
||
687 | |||
688 | |||
689 | -- |
||
690 | -- handlePostponement (params) |
||
691 | -- |
||
692 | -- params.schedulingName = scheduling name |
||
693 | -- params.func = function name |
||
694 | -- params.args = function arguments |
||
695 | -- params.lastPostponedName = name of the variable with last postponed information |
||
696 | -- params.lastUpdatedName = name of the variable with last updated information |
||
697 | -- params.minimumDelay = the smallest amount of time between function calls |
||
698 | -- |
||
699 | handlePostponement = function (params) |
||
700 | local curTime = GetTime(); |
||
701 | local lastPostponed = getglobal(params.lastPostponedName); |
||
702 | local lastUpdated = getglobal(params.lastUpdatedName); |
||
703 | if ( not lastPostponed ) then |
||
704 | lastPostponed = 0; |
||
705 | end |
||
706 | if ( not lastUpdated ) then |
||
707 | lastUpdated = 0; |
||
708 | end |
||
709 | if ( ( lastPostponed == 0 ) or ( curTime-lastPostponed <= params.minimumDelay ) and ( params.allowInitialUpdate == 1 ) ) then |
||
710 | postpone(params); |
||
711 | return; |
||
712 | end |
||
713 | if ( curTime-lastUpdated <= params.minimumDelay ) then |
||
714 | postpone(params); |
||
715 | return; |
||
716 | end |
||
717 | setglobal(params.lastPostponedName, 0); |
||
718 | setglobal(params.lastUpdatedName, curTime); |
||
719 | local f = params.func; |
||
720 | if ( f ) then |
||
721 | if ( params.args ) then |
||
722 | f(unpack(params.args)); |
||
723 | else |
||
724 | f(); |
||
725 | end |
||
726 | end |
||
727 | end; |
||
728 | -- private functions |
||
729 | |||
730 | -- |
||
731 | -- addTooltipUsingFrame (frame) |
||
732 | -- |
||
733 | -- Adds a frame to the list of frames that want tooltips to be untouched. |
||
734 | -- |
||
735 | addTooltipUsingFrame = function(frame) |
||
736 | if ( not frame ) then |
||
737 | return; |
||
738 | end |
||
739 | local frameName = nil; |
||
740 | if ( type(frame) == "string" ) then |
||
741 | frameName = frame; |
||
742 | else |
||
743 | frameName = frame:GetName(); |
||
744 | end |
||
745 | if ( not frameName ) then |
||
746 | return; |
||
747 | end |
||
748 | for k, v in DynamicData.util.tooltipUsingFrames do |
||
749 | if ( v == frameName ) then |
||
750 | return; |
||
751 | end |
||
752 | end |
||
753 | table.insert(DynamicData.util.tooltipUsingFrames, frameName); |
||
754 | end; |
||
755 | |||
756 | |||
757 | -- |
||
758 | -- doNothing() |
||
759 | -- |
||
760 | -- Does nothing. |
||
761 | -- |
||
762 | doNothing = function() |
||
763 | end; |
||
764 | |||
765 | -- |
||
766 | -- handleScheduledFunctions(elapsed) |
||
767 | -- |
||
768 | -- handles scheduled functions |
||
769 | -- |
||
770 | handleScheduledFunctions = function(elapsed) |
||
771 | local curTime = GetTime(); |
||
772 | local scheduledFunction = {}; |
||
773 | while ( ( DynamicData.util.scheduledFunctions[1] ) and ( DynamicData.util.scheduledFunctions[1].time <= curTime ) ) do |
||
774 | scheduledFunction = table.remove(DynamicData.util.scheduledFunctions, 1); |
||
775 | if ( scheduledFunction.args) then |
||
776 | scheduledFunction.func(unpack(scheduledFunction.args)); |
||
777 | else |
||
778 | scheduledFunction.func(); |
||
779 | end |
||
780 | end |
||
781 | end; |
||
782 | |||
783 | -- |
||
784 | -- OnLoad() |
||
785 | -- |
||
786 | -- sets up the util library. NOTE: This inserts an emulated UltimateUI_Schedule if not present. |
||
787 | -- |
||
788 | OnLoad = function() |
||
789 | local needHandler = false; |
||
790 | if ( not UltimateUI_Schedule ) then |
||
791 | UltimateUI_Schedule = DynamicData.util.scheduleFunction; |
||
792 | needHandler = true; |
||
793 | end |
||
794 | if ( not UltimateUI_ScheduleByName ) then |
||
795 | UltimateUI_ScheduleByName = DynamicData.util.scheduleNamedFunction; |
||
796 | needHandler = true; |
||
797 | end |
||
798 | if ( not UltimateUI_AfterInit ) then |
||
799 | UltimateUI_AfterInit = DynamicData.util.scheduleAfterInitFunction; |
||
800 | needHandler = true; |
||
801 | end |
||
802 | if ( needHandler ) then |
||
803 | DynamicData.util.addOnTimeUpdateHandler(DynamicData.util.handleScheduledFunctions); |
||
804 | end |
||
805 | end; |
||
806 | |||
807 | -- |
||
808 | -- addOnTimeUpdateHandler(func) |
||
809 | -- |
||
810 | -- adds the func to the OnTime update handlers |
||
811 | -- |
||
812 | addOnTimeUpdateHandler = function (func) |
||
813 | DynamicData.util.addOnWhateverHandler(DynamicData.util.onUpdateHandlers, func); |
||
814 | end; |
||
815 | |||
816 | -- |
||
817 | -- removeOnTimeUpdateHandler(func) |
||
818 | -- |
||
819 | -- removes the func from the OnTime update handlers |
||
820 | -- |
||
821 | removeOnTimeUpdateHandler = function (func) |
||
822 | DynamicData.util.removeOnWhateverHandler(DynamicData.util.onUpdateHandlers, func); |
||
823 | end; |
||
824 | |||
825 | -- |
||
826 | -- variablesLoaded() |
||
827 | -- |
||
828 | -- run on VARIABLES_LOADED event |
||
829 | -- |
||
830 | variablesLoaded = function () |
||
831 | variablesHasBeenLoaded = true; |
||
832 | end; |
||
833 | |||
834 | -- |
||
835 | -- addScheduledFunction(scheduledFunction) |
||
836 | -- |
||
837 | -- schedules a function to occur sometime |
||
838 | -- |
||
839 | addScheduledFunction = function(scheduledFunction) |
||
840 | local i = 1; |
||
841 | while ( ( DynamicData.util.scheduledFunctions[i] ) and ( DynamicData.util.scheduledFunctions[i].time < scheduledFunction.time ) ) do |
||
842 | i = i + 1; |
||
843 | end |
||
844 | table.insert(DynamicData.util.scheduledFunctions, i, scheduledFunction); |
||
845 | end; |
||
846 | |||
847 | -- variables |
||
848 | |||
849 | variablesHasBeenLoaded = false; |
||
850 | |||
851 | scheduledFunctions = {}; |
||
852 | |||
853 | onUpdateHandlers = {}; |
||
854 | |||
855 | saved_GameTooltip_ClearMoney = nil; |
||
856 | |||
857 | -- contains default frames which should prevent tooltips from being parsed. |
||
858 | tooltipUsingFrames = { |
||
859 | "TaxiFrame", "MerchantFrame", "TradeSkillFrame", |
||
860 | "SuggestFrame", "WhoFrame", "AuctionFrame", "MailFrame" |
||
861 | }; |
||
862 | |||
863 | }; |
||
864 | |||
865 | |||
866 |