vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | -- |
||
3 | -- Sea.wow.tooltip |
||
4 | -- |
||
5 | -- |
||
6 | -- Tooltip related functions |
||
7 | -- |
||
8 | -- $LastChangedBy: mugendai $ |
||
9 | -- $Rev: 2919 $ |
||
10 | -- $Date: 2006-01-04 15:34:41 -0600 (Wed, 04 Jan 2006) $ |
||
11 | --]] |
||
12 | |||
13 | Sea.wow.tooltip = { |
||
14 | |||
15 | -- |
||
16 | -- clear( tooltipNameBase ) |
||
17 | -- |
||
18 | -- Clears out a tooltip |
||
19 | -- |
||
20 | -- args |
||
21 | -- (String tooltipNamebase) |
||
22 | -- tooltipNameBase - the base name of the tooltip, like "GameTooltip" |
||
23 | -- |
||
24 | clear = function ( tooltipBase ) |
||
25 | for i=1, 15, 1 do |
||
26 | getglobal(tooltipBase.."TextLeft"..i):SetText(""); |
||
27 | getglobal(tooltipBase.."TextRight"..i):SetText(""); |
||
28 | end |
||
29 | end; |
||
30 | |||
31 | -- |
||
32 | -- scan (tooltipName, strings) |
||
33 | -- |
||
34 | -- Returns an associated table of the strings in a tooltip |
||
35 | -- |
||
36 | -- args |
||
37 | -- (String tooltipName) |
||
38 | -- tooltipName - the name of the tooltip frame, like "GameTooltip" |
||
39 | -- strings - the table to store the strings in, use this to avoid continuously |
||
40 | -- recreating and deleting tables |
||
41 | -- |
||
42 | -- Returns: |
||
43 | -- (table[id][.left .right .leftColor .rightColor] strings) |
||
44 | -- |
||
45 | -- strings - all of the strings and colors in the tooltip |
||
46 | -- |
||
47 | scan = function ( tooltipName, strings ) |
||
48 | if ( tooltipName == nil ) then |
||
49 | tooltipName = "GameTooltip"; |
||
50 | end |
||
51 | |||
52 | if (not strings) then |
||
53 | strings = {}; |
||
54 | end |
||
55 | local textLeft, textRight, ttextLeft, ttextRight, textLeftColorR, textLeftColorG, textLeftColorB, textLeftColorA, textRightColorR, textRightColorG, textRightColorB, textRightColorA; |
||
56 | |||
57 | for idx = 1, 10 do |
||
58 | textLeftColor = nil; |
||
59 | textRightColor = nil; |
||
60 | ttextLeft = getglobal(tooltipName.."TextLeft"..idx); |
||
61 | if(ttextLeft and ttextLeft:IsShown()) then |
||
62 | textLeft = ttextLeft:GetText(); |
||
63 | if (textLeft) then |
||
64 | textLeftColorR, textLeftColorG, textLeftColorB, textLeftColorA = ttextLeft:GetTextColor(); |
||
65 | textLeftColor = {r=r, g=g, b=b, a=a}; |
||
66 | end |
||
67 | else |
||
68 | textLeft = nil; |
||
69 | end |
||
70 | |||
71 | ttextRight = getglobal(tooltipName.."TextRight"..idx); |
||
72 | if(ttextRight and ttextRight:IsShown()) then |
||
73 | textRight = ttextRight:GetText(); |
||
74 | if (textRight) then |
||
75 | textRightColorR, textRightColorG, textRightColorB, textRightColorA = ttextRight:GetTextColor(); |
||
76 | end |
||
77 | else |
||
78 | textRight = nil; |
||
79 | end |
||
80 | |||
81 | --If there is text here, and the table doesn't exist for this row, then make it |
||
82 | if ( ( textLeft or textRight ) and ( type( strings[idx] ) ~= "table" ) ) then |
||
83 | strings[idx] = {}; |
||
84 | end |
||
85 | --If we have a row to work with, then clear it |
||
86 | if ( type( strings[idx] ) == "table" ) then |
||
87 | if ( type( strings[idx].leftColor ) ~= "table" ) then |
||
88 | strings[idx].leftColor = {}; |
||
89 | end |
||
90 | if ( type( strings[idx].rightColor ) ~= "table" ) then |
||
91 | strings[idx].rightColor = {}; |
||
92 | end |
||
93 | --Clear the data for this row |
||
94 | strings[idx].left = nil; |
||
95 | strings[idx].right = nil; |
||
96 | strings[idx].leftColor.r = nil; |
||
97 | strings[idx].leftColor.g = nil; |
||
98 | strings[idx].leftColor.b = nil; |
||
99 | strings[idx].leftColor.a = nil; |
||
100 | strings[idx].rightColor.r = nil; |
||
101 | strings[idx].rightColor.g = nil; |
||
102 | strings[idx].rightColor.b = nil; |
||
103 | strings[idx].rightColor.a = nil; |
||
104 | end |
||
105 | |||
106 | if (textLeft or textRight) then |
||
107 | strings[idx].left = textLeft; |
||
108 | strings[idx].right = textRight; |
||
109 | strings[idx].leftColor.r = textLeftColorR; |
||
110 | strings[idx].leftColor.g = textLeftColorG; |
||
111 | strings[idx].leftColor.b = textLeftColorB; |
||
112 | strings[idx].leftColor.a = textLeftColorA; |
||
113 | strings[idx].rightColor.r = textRightColorR; |
||
114 | strings[idx].rightColor.g = textRightColorG; |
||
115 | strings[idx].rightColor.b = textRightColorB; |
||
116 | strings[idx].rightColor.a = textRightColorA; |
||
117 | end |
||
118 | end |
||
119 | |||
120 | return strings; |
||
121 | end; |
||
122 | |||
123 | -- |
||
124 | -- get (tooltip, row, value) |
||
125 | -- |
||
126 | -- Returns text and/or color data from a single row in a tooltip. |
||
127 | -- Unlike scan, it gets only the data requested, not the entire tooltip. |
||
128 | -- This function will not generate any garbage collections. |
||
129 | -- |
||
130 | -- args |
||
131 | -- (String tooltip) |
||
132 | -- tooltip - the name of the tooltip frame, defaults to "GameTooltip" |
||
133 | -- (Integer row) |
||
134 | -- row - the row to retreive from the tooltip, defaults to 1 |
||
135 | -- (String value) |
||
136 | -- value - which value you want to get, can be any of "left", "right", "leftColor", or "rightColor" |
||
137 | -- |
||
138 | -- Returns: |
||
139 | -- Based on value: |
||
140 | -- nil - left, right, leftRed, leftGreen, leftBlue, leftAlpha, rightRed, rightGreen, rightBlue, rightAlpha |
||
141 | -- "left" - String - left |
||
142 | -- "right" - String - right |
||
143 | -- "leftColor" - Integers - leftRed, leftGreen, leftBlue, leftAlpha |
||
144 | -- "rightColor" - Integers - lrightRed, rightGreen, rightBlue, rightAlpha |
||
145 | -- |
||
146 | -- |
||
147 | -- strings - all of the strings and colors in the tooltip |
||
148 | -- |
||
149 | get = function ( tooltip, row, value ) |
||
150 | --Default to GameTooltip |
||
151 | if (not tooltip) then |
||
152 | tooltip = "GameTooltip"; |
||
153 | end |
||
154 | --Default to first row |
||
155 | if (not row) then |
||
156 | row = 1; |
||
157 | end |
||
158 | |||
159 | local text, left, right, leftRed, leftGreen, leftBlue, leftAlpha, rightRed, rightGreen, rightBlue, rightAlpha; |
||
160 | |||
161 | --Get the left tooltip |
||
162 | if ( ( value == nil ) or ( value == "left" ) or ( value == "leftColor" ) ) then |
||
163 | text = getglobal(tooltip.."TextLeft"..row); |
||
164 | |||
165 | --Get the left tooltip text |
||
166 | if ( ( value == nil ) or ( value == "left" ) ) then |
||
167 | if ( text and text:IsShown() ) then |
||
168 | left = text:GetText(); |
||
169 | end |
||
170 | --If this is all they want, then return it now |
||
171 | if ( value == "left" ) then |
||
172 | return left; |
||
173 | end |
||
174 | end |
||
175 | --Get the left tooltip color |
||
176 | if ( ( value == nil ) or ( value == "leftColor" ) ) then |
||
177 | if ( text and text:IsShown() ) then |
||
178 | leftRed, leftGreen, leftBlue, leftAlpha = text:GetTextColor(); |
||
179 | end |
||
180 | --If this is all they want, then return it now |
||
181 | if ( value == "leftColor" ) then |
||
182 | return leftRed, leftGreen, leftBlue, leftAlpha; |
||
183 | end |
||
184 | end |
||
185 | end |
||
186 | |||
187 | --Get the right tooltip |
||
188 | if ( ( value == nil ) or ( value == "right" ) or ( value == "rightColor" ) ) then |
||
189 | text = getglobal(tooltip.."TextRight"..row); |
||
190 | |||
191 | --Get the right tooltip text |
||
192 | if ( ( value == nil ) or ( value == "right" ) ) then |
||
193 | if ( text and text:IsShown() ) then |
||
194 | right = text:GetText(); |
||
195 | end |
||
196 | --If this is all they want, then return it now |
||
197 | if ( value == "right" ) then |
||
198 | return right; |
||
199 | end |
||
200 | end |
||
201 | --Get the right tooltip color |
||
202 | if ( ( value == nil ) or ( value == "rightColor" ) ) then |
||
203 | |||
204 | if ( text and text:IsShown() ) then |
||
205 | rightRed, rightGreen, rightBlue, rightAlpha = text:GetTextColor(); |
||
206 | end |
||
207 | --If this is all they want, then return it now |
||
208 | if ( value == "rightColor" ) then |
||
209 | return rightRed, rightGreen, rightBlue, rightAlpha; |
||
210 | end |
||
211 | end |
||
212 | end |
||
213 | |||
214 | --If no individual value was specified, return the entire row |
||
215 | return left, right, leftRed, leftGreen, leftBlue, leftAlpha, rightRed, rightGreen, rightBlue, rightAlpha; |
||
216 | end; |
||
217 | |||
218 | -- |
||
219 | -- compareTooltipScan(scanTable left, scanTable right) |
||
220 | -- |
||
221 | -- compares the results of two tooltip scans (by string only, not color) |
||
222 | -- |
||
223 | -- Args: |
||
224 | -- left - the result of a scan or string (implies tooltip base to scan) |
||
225 | -- right - the result of a scan or string (implies tooltip base to scan) |
||
226 | -- or nil (implies gametooltip) |
||
227 | -- |
||
228 | -- Returns: |
||
229 | -- (boolean, number) |
||
230 | -- true if equal |
||
231 | -- 0 if equals, -1 if left is less, 1 if right is less |
||
232 | -- |
||
233 | -- |
||
234 | compareTooltipScan = function ( leftScan, rightScan ) |
||
235 | if ( type(leftScan) == "string" ) then |
||
236 | leftScan = Sea.wow.tooltip.scan(leftScan); |
||
237 | end |
||
238 | if ( type(rightScan) == "string" ) then |
||
239 | rightScan = Sea.wow.tooltip.scan(rightScan); |
||
240 | end |
||
241 | if ( type(leftScan) == "nil" ) then |
||
242 | leftScan = Sea.wow.tooltip.scan(); |
||
243 | end |
||
244 | if ( type(rightScan) == "nil" ) then |
||
245 | rightScan = Sea.wow.tooltip.scan(); |
||
246 | end |
||
247 | |||
248 | |||
249 | local result = 0; |
||
250 | |||
251 | for i=1,10,1 do |
||
252 | if ( leftScan[i] ) then |
||
253 | if ( leftScan[i].left ~= nil ) then |
||
254 | if ( rightScan[i] and (rightScan[i].left ~= nil) ) then |
||
255 | if ( leftScan[i].left < rightScan[i].left ) then |
||
256 | result = -1; |
||
257 | break; |
||
258 | elseif ( leftScan[i].left > rightScan[i].left ) then |
||
259 | result = 1; |
||
260 | break; |
||
261 | end |
||
262 | else |
||
263 | result = 1; |
||
264 | break; |
||
265 | end |
||
266 | end |
||
267 | if ( leftScan[i].right ~= nil ) then |
||
268 | if ( rightScan[i].right and (rightScan[i].right ~= nil) ) then |
||
269 | if ( leftScan[i].right < rightScan[i].right ) then |
||
270 | result = -1; |
||
271 | break; |
||
272 | elseif ( leftScan[i].right > rightScan[i].right ) then |
||
273 | result = 1; |
||
274 | break; |
||
275 | end |
||
276 | else |
||
277 | result = 1; |
||
278 | break; |
||
279 | end |
||
280 | end |
||
281 | end |
||
282 | end |
||
283 | |||
284 | return (result==0), result; |
||
285 | end; |
||
286 | |||
287 | -- |
||
288 | -- create (tooltipTable, tooltipName) |
||
289 | -- |
||
290 | -- Returns nil if failed, true if successful. |
||
291 | -- Dont forget to set ownership of the Tooltip before creation: |
||
292 | -- Use ToolTip:SetOwner, Sea.wow.tooltip.smartSetOwner, or GameTooltip_SetDefaultAnchor |
||
293 | -- *Currently ignores line size, font* |
||
294 | -- |
||
295 | -- args |
||
296 | -- (table tooltipTable, String tooltipName) |
||
297 | -- tooltipTable - associated table of the strings for the tooltip |
||
298 | -- tooltipName (Optional) - the name of the tooltip frame, uses "GameTooltip" as default |
||
299 | -- |
||
300 | -- Returns: |
||
301 | -- true (success) or nil (failure) |
||
302 | -- |
||
303 | -- |
||
304 | create = function ( tooltipTable, tooltipName ) |
||
305 | if ( tooltipName == nil ) then |
||
306 | tooltipName = "GameTooltip"; |
||
307 | end |
||
308 | local tooltip = getglobal(tooltipName); |
||
309 | local ttext; |
||
310 | for idx, line in tooltipTable do |
||
311 | if (idx == 1) and ((line.left) or (line.right)) then |
||
312 | tooltip:SetText(line.left); |
||
313 | --SetText will clear tooltip |
||
314 | if (line.right) then |
||
315 | ttext = getglobal(tooltipName.."TextRight"..idx); |
||
316 | if (ttext) then |
||
317 | ttext:SetText(line.right); |
||
318 | if (line.rightColor) then |
||
319 | ttext:SetTextColor(line.rightColor.r, line.rightColor.g, line.rightColor.b, line.rightColor.a); |
||
320 | end |
||
321 | ttext:Show(); |
||
322 | end |
||
323 | end |
||
324 | else |
||
325 | if (line.right) then |
||
326 | tooltip:AddDoubleLine(line.left, line.right); |
||
327 | if (line.rightColor) then |
||
328 | ttext = getglobal(tooltipName.."TextRight"..idx); |
||
329 | if (ttext) and (line.rightColor) then |
||
330 | ttext:SetTextColor(line.rightColor.r, line.rightColor.g, line.rightColor.b, line.rightColor.a); |
||
331 | --Would just use AddDoubleLine to set the color but it has no way to set alpha |
||
332 | end |
||
333 | end |
||
334 | else |
||
335 | tooltip:AddLine(line.left); |
||
336 | end |
||
337 | end |
||
338 | |||
339 | if (line.leftColor) then |
||
340 | ttext = getglobal(tooltipName.."TextLeft"..idx); |
||
341 | if (ttext) and (line.leftColor)then |
||
342 | ttext:SetTextColor(line.leftColor.r, line.leftColor.g, line.leftColor.b, line.leftColor.a); |
||
343 | end |
||
344 | end |
||
345 | end |
||
346 | |||
347 | tooltip:Show() -- Dynamicly Update Size (in the OnShow) |
||
348 | return true; |
||
349 | end; |
||
350 | |||
351 | -- |
||
352 | -- smartSetOwner (owner, tooltip, x, y) |
||
353 | -- |
||
354 | -- Sets the tooltip relative to the owner in a position |
||
355 | -- appropriate for where the owner is on the screen. |
||
356 | -- owner - optional, the owner object, defaults to this |
||
357 | -- tooltip, optional, the tooltip to set, defaults to GameTooltip |
||
358 | -- setX, optional, sets the x offset(flipped based on screen corner) |
||
359 | -- setY, optional, sets the y offset(flipped based on screen corner) |
||
360 | -- |
||
361 | -- Args: |
||
362 | -- (Frame owner, Tooltip tooltip, float x, float y) |
||
363 | -- |
||
364 | -- owner - the new parent frame |
||
365 | -- tooltip - the tooltip to relocate |
||
366 | -- x - new x |
||
367 | -- y - new y |
||
368 | -- |
||
369 | smartSetOwner = function (owner, tooltip, setX, setY) |
||
370 | if (not owner) then |
||
371 | owner = this; |
||
372 | end |
||
373 | if (not tooltip) then |
||
374 | tooltip = GameTooltip; |
||
375 | end |
||
376 | if (not setX) then |
||
377 | setX = 0; |
||
378 | end |
||
379 | if (not setY) then |
||
380 | setY = 0; |
||
381 | end |
||
382 | if (owner) then |
||
383 | local x,y = owner:GetCenter(); |
||
384 | local left = owner:GetLeft(); |
||
385 | local right = owner:GetRight(); |
||
386 | local top = owner:GetTop(); |
||
387 | local bottom = owner:GetBottom(); |
||
388 | local screenWidth = UIParent:GetWidth(); |
||
389 | local screenHeight = UIParent:GetHeight(); |
||
390 | local scale = owner:GetScale(); |
||
391 | if (x~=nil and y~=nil and left~=nil and right~=nil and top~=nil and bottom~=nil and screenWidth>0 and screenHeight>0) then |
||
392 | setX = setX * scale; |
||
393 | setY = setY * scale; |
||
394 | x = x * scale; |
||
395 | y = y * scale; |
||
396 | left = left * scale; |
||
397 | right = right * scale; |
||
398 | width = right - left; |
||
399 | top = top * scale; |
||
400 | bottom = bottom * scale; |
||
401 | local anchorPoint = ""; |
||
402 | if (y <= (screenHeight * (1/2))) then |
||
403 | top = top + setY; |
||
404 | anchorPoint = "TOP"; |
||
405 | if (top < 0) then |
||
406 | setY = setY - top; |
||
407 | end |
||
408 | else |
||
409 | setY = -setY; |
||
410 | bottom = bottom + setY; |
||
411 | anchorPoint = "BOTTOM"; |
||
412 | if (bottom > screenHeight) then |
||
413 | setY = setY + (screenHeight - bottom); |
||
414 | end |
||
415 | end |
||
416 | if (x <= (screenWidth * (1/2))) then |
||
417 | left = left + setX; |
||
418 | if (anchorPoint == "BOTTOM") then |
||
419 | anchorPoint = anchorPoint.."RIGHT"; |
||
420 | setX = setX - width; |
||
421 | if (left < 0) then |
||
422 | setX = setX - left; |
||
423 | end |
||
424 | else |
||
425 | anchorPoint = anchorPoint.."LEFT"; |
||
426 | if (left < 0) then |
||
427 | setX = setX - left; |
||
428 | end |
||
429 | end |
||
430 | else |
||
431 | setX = -setX; |
||
432 | right = right + setX; |
||
433 | if (anchorPoint == "BOTTOM") then |
||
434 | anchorPoint = anchorPoint.."LEFT"; |
||
435 | setX = setX + width; |
||
436 | if (right > screenWidth) then |
||
437 | setX = setX - (right - screenWidth); |
||
438 | end |
||
439 | else |
||
440 | anchorPoint = anchorPoint.."RIGHT"; |
||
441 | if (right > screenWidth) then |
||
442 | setX = setX + (screenWidth - right); |
||
443 | end |
||
444 | end |
||
445 | end |
||
446 | |||
447 | if (anchorPoint == "") then |
||
448 | anchorPoint = "TOPLEFT"; |
||
449 | end |
||
450 | scale = tooltip:GetScale(); |
||
451 | if (scale) then |
||
452 | setX = setX / scale; |
||
453 | setY = setY / scale; |
||
454 | end |
||
455 | tooltip:SetOwner(owner, "ANCHOR_"..anchorPoint, setX, setY); |
||
456 | end |
||
457 | else |
||
458 | tooltip:SetOwner(owner, "ANCHOR_TOPLEFT"); |
||
459 | end |
||
460 | end; |
||
461 | |||
462 | |||
463 | -- |
||
464 | -- protectTooltipMoney () |
||
465 | -- |
||
466 | -- Args: |
||
467 | -- None. |
||
468 | -- |
||
469 | -- Returns: |
||
470 | -- Nothing. |
||
471 | -- |
||
472 | -- Thanks to Telo for providing this solution! |
||
473 | -- Prevents the clearing of money from tooltips. Changes GameTooltip_ClearMoney. |
||
474 | -- USE WITH CAUTION! ALWAYS CALL unprotectMoneyTooltip() AFTER SETTING THE TOOLTIP! |
||
475 | -- |
||
476 | protectTooltipMoney = function() |
||
477 | if ( not Sea.wow.tooltip.saved_GameTooltip_ClearMoney ) then |
||
478 | Sea.wow.tooltip.saved_GameTooltip_ClearMoney = GameTooltip_ClearMoney; |
||
479 | GameTooltip_ClearMoney = Sea.wow.tooltip.doNothingTooltipMoney; |
||
480 | end |
||
481 | end; |
||
482 | |||
483 | -- |
||
484 | -- unprotectTooltipMoney () |
||
485 | -- |
||
486 | -- Args: |
||
487 | -- None. |
||
488 | -- |
||
489 | -- Returns: |
||
490 | -- Nothing. |
||
491 | -- |
||
492 | -- Thanks to Telo for providing this solution! |
||
493 | -- Allows the clearing of money from tooltips. Changes GameTooltip_ClearMoney. |
||
494 | -- |
||
495 | unprotectTooltipMoney = function() |
||
496 | if ( Sea.wow.tooltip.saved_GameTooltip_ClearMoney ) then |
||
497 | GameTooltip_ClearMoney = Sea.wow.tooltip.saved_GameTooltip_ClearMoney; |
||
498 | Sea.wow.tooltip.saved_GameTooltip_ClearMoney = nil; |
||
499 | end |
||
500 | end; |
||
501 | |||
502 | -- |
||
503 | -- unprotectTooltipMoney () |
||
504 | -- |
||
505 | -- Args: |
||
506 | -- None. |
||
507 | -- |
||
508 | -- Returns: |
||
509 | -- Nothing. |
||
510 | -- |
||
511 | -- Does nothing. |
||
512 | -- |
||
513 | doNothingTooltipMoney = function() |
||
514 | end; |
||
515 | |||
516 | saved_GameTooltip_ClearMoney = nil; |
||
517 | }; |