vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Additional function hooks to allow hooks into more tooltips
3 3.8.0 (Kangaroo)
4 $Id: Tooltip.lua 957 2006-08-16 04:16:22Z mentalpower $
5  
6 You should hook into EnhTooltip using Stubby:
7 Stubby.RegisterFunctionHook("EnhTooltip.HOOK", 200, myHookingFunction)
8 Where myHooking function is one of your functions (see calling parameters below)
9 And HOOK is one of:
10 addTooltip
11 checkPopup
12 merchantHook
13 tradeHook
14 bankHook
15 bagHook
16 The number 200 is a number that determines calling order
17 A lower number will make your tooltip information display earlier (higher)
18 A higher number will call your tooltip later (lower)
19 Auctioneer (if installed) gets called at position 100.
20 Informant (if installed) gets called at position 300.
21 Enchantrix (if installed) gets called at position 400.
22  
23 The appropriate function calls are, respectively:
24 tooltip - A tooltip is being displayed, hookFunc will be called as:
25 addTooltipHook(frame, name, link, quality, count, price)
26 popup - A tooltip may be displayed, unless you want to popup something:
27 popped = checkPopupHook(name, link, quality, count, price, hyperlink)
28 If your function returns true, then we won't present a tooltip
29 merchant - Get called for each of a merchant's items.
30 merchantHook(frame, name, link, quality, count, price)
31 trade - Get called when a tradeskill window is displayed / item selected
32 tradeHook(type, selid)
33 valid types: 'trade', 'craft'
34 selID will be nil when the window is first displayed
35 bank - You are at the bank and are able to scan it's containers
36 bankHook()
37 bag - One or more of the items in your bags has updated.
38 bagHook()
39  
40  
41 You may use the following methods of the EnhTooltip class:
42  
43 EnhTooltip.HideTooltip()
44 Causes the enhanced tooltip to vanish.
45  
46 EnhTooltip.ClearTooltip()
47 Clears the current tooltip of contents and hides it.
48  
49 EnhTooltip.GetGSC(money)
50 Returns the given money (in copper) amount in gold, silver and copper.
51  
52 EnhTooltip.GetTextGSC(money, exact)
53 Returns the money (in copper) amount as colored text, suitable for display.
54 If exact evaluates to true, then the text will be exact, otherwise rounded.
55  
56 EnhTooltip.AddLine(lineText, moneyAmount, embed)
57 Adds the lineText to the tooltip.
58 If moneyAmount is supplied, the line has a money amount right-aligned after it.
59 It embed evaluates to true, then the line is placed at the end of the game tooltip
60 and the money amount is converted to a textual form.
61  
62 EnhTooltip.AddSeparator()
63 Adds an empty line to the tooltip.
64  
65 EnhTooltip.LineColor(r, g, b)
66 Changes the color of the most recently added line to the given R,G,B value.
67 The R,G,B values are floating point values from 0.0 (dark) to 1.0 (bright)
68  
69 EnhTooltip.LineSize_Large()
70 Changes the size of the font string to 12
71  
72 EnhTooltip.LineSize_Small()
73 Changes the size of the font string to 10
74  
75 EnhTooltip.LineQuality(quality)
76 Changes the color of the most recently added line to the quality color of the
77 item that is supplied in the quality parameter.
78  
79 EnhTooltip.SetIcon(iconPath)
80 Adds an icon to the current tooltip, where the texture path is set to that of
81 the iconPath parameter.
82  
83 EnhTooltip.NameFromLink(link)
84 Given a link, returns the embedded item name.
85  
86 EnhTooltip.HyperlinkFromLink(link)
87 Given a link, returns the blizzard hyperlink (eg: "item:12345:0:321:0")
88  
89 EnhTooltip.BaselinkFromLink(link)
90 Given a link, returns the first 3 numbers from the item link (eg: "12345:0:321")
91  
92 EnhTooltip.QualityFromLink(link)
93 Given a link, returns the numerical quality value (0=Poor/Gray ... 4=Epic/Purple)
94  
95 EnhTooltip.FakeLink(hyperlink, quality, name)
96 Given a hyperlink, a numerical quality and an item name, does it's best to fabricate
97 as authentic a link as it can. This link may not be suitable for messaging however.
98  
99 EnhTooltip.LinkType(link)
100 Given a link, returns the type of link (eg: "item", "enchant")
101  
102 EnhTooltip.AddHook(hookType, hookFunc, position)
103 Allows dependant addons to register a function for inclusion at key moments.
104 Where:
105 hookType = The type of event to be notified of. One of:
106 tooltip - A tooltip is being displayed, hookFunc will be called as:
107 addTooltipHook(frame, name, link, quality, count, price)
108 popup - A tooltip may be displayed, unless you want to popup something:
109 popped = checkPopupHook(name, link, quality, count, price, hyperlink)
110 If your function returns true, then we won't present a tooltip
111 merchant - Get called for each of a merchant's items.
112 merchantHook(frame, name, link, quality, count, price)
113 trade - Get called when a tradeskill window is displayed / item selected
114 tradeHook(type, selid)
115 valid types: 'trade', 'craft'
116 selID will be nil when the window is first displayed
117 bank - You are at the bank and are able to scan it's containers
118 bankHook()
119 bag - One or more of the items in your bags has updated.
120 bagHook()
121 hookFunction = Your function (prototyped as above) that we will call.
122 position = A number that determines calling order
123 The default position if not supplied is 100.
124 A lower number will make your tooltip information display earlier (higher)
125 A higher number will call your tooltip later (lower)
126 Auctioneer (if installed) gets called at position 50.
127 Enchantrix (if installed) gets called at position 150.
128  
129 EnhTooltip.BreakLink(link)
130 Given an item link, splits it into it's component parts as follows:
131 itemID, randomProperty, enchantment, uniqueID, itemName = EnhTooltip.BreakLink(link)
132 Note that the return order is not the same as the order of the items in the link
133 (ie: randomProp and enchant are reversed from their link order)
134  
135 EnhTooltip.FindItemInBags(findName)
136 Searches through your bags to find an item with the given name (exact match)
137 It returns the following information about the item:
138 bag, slot, itemID, randomProp, enchant, uniqID = EnhTooltip.FindItemInBags(itemName)
139  
140 EnhTooltip.SetElapsed(elapsed)
141 If a value is given, adds the elapsed interval to our own internal timer.
142 Checks to see if it is time to hide the tooltip.
143 Returns the total elapsed time that the tooltip has been displayed since startup.
144  
145 EnhTooltip.SetMoneySpacing(spacing)
146 Sets the amount of padding (if provided) that money should be given in the tooltips.
147 Returns the current spacing.
148  
149 EnhTooltip.SetPopupKey(key)
150 Sets a key (if provided), which if pressed while a tooltip is being displayed, checks
151 for hooked functions that may wish to provide popups.
152 Returns the current key.
153  
154 License:
155 This program is free software; you can redistribute it and/or
156 modify it under the terms of the GNU General Public License
157 as published by the Free Software Foundation; either version 2
158 of the License, or (at your option) any later version.
159  
160 This program is distributed in the hope that it will be useful,
161 but WITHOUT ANY WARRANTY; without even the implied warranty of
162 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
163 GNU General Public License for more details.
164  
165 You should have received a copy of the GNU General Public License
166 along with this program(see GLP.txt); if not, write to the Free Software
167 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
168  
169 ]]
170  
171 -- setting version number
172 ENHTOOLTIP_VERSION = "3.8.0"
173 if (ENHTOOLTIP_VERSION == "<".."%version%>") then
174 ENHTOOLTIP_VERSION = "3.7.DEV"
175 end
176  
177 --[[
178 ---- Initialize a storage space that all our functions can see
179 --]]
180 local self = {
181 showIgnore = false,
182 moneySpacing = 4,
183 embedLines = {},
184 eventTimer = 0,
185 hideTime = 0,
186 currentGametip = nil,
187 currentItem = nil,
188 forcePopupKey = "alt",
189 oldChatItem = nil,
190 hooks = {},
191 notify = { tooltip = {}, popup = {}, merchant = {}, bank = {}, bag = {}, trade = {} },
192 notifyFuncs = {},
193 }
194  
195 -- =============== LOCAL FUNCTIONS =============== --
196  
197 -- prototypes for all local functions
198 local addLine -- AddLine(lineText,moneyAmount,embed)
199 local addSeparator -- AddSeparator(embed)
200 local addTooltip -- AddTooltip(frame,name,link,quality,count,price)
201 local afHookOnEnter -- AfHookOnEnter(type,index)
202 local bagHook -- BagHook()
203 local bankHook -- BankHook()
204 local baselinkFromLink -- BaselinkFromLink(link)
205 local breakLink -- BreakLink(link)
206 local callBagHook -- CallBagHook(event,bagNumber)
207 local callBankHook -- CallBankHook()
208 local callCheckPopup -- CallCheckPopup(name,link,quality,count,price,hyperlink)
209 local callTradeHook -- CallTradeHook(type,event,selID)
210 local cfHookUpdate -- CfHookUpdate(frame)
211 local chatHookOnHyperlinkShow -- ChatHookOnHyperlinkShow(reference,link,button)
212 local checkHide -- CheckHide()
213 local checkPopup -- CheckPopup(name,link,quality,count,price,hyperlink)
214 local clearTooltip -- ClearTooltip()
215 local debugPrint -- DebugPrint(...)
216 local doHyperlink -- DoHyperlink(reference,link,button)
217 local embedRender -- EmbedRender()
218 local fakeLink -- FakeLink(hyperlink,quality,name)
219 local findItemInBags -- FindItemInBags(findName)
220 local getglobalIterator -- GetglobalIterator(format,first,last)
221 local getGSC -- GetGSC(money)
222 local getLootLinkLink -- GetLootLinkLink(name)
223 local getLootLinkServer -- GetLootLinkServer()
224 local getRect -- GetRect(object,curRect)
225 local getTextGSC -- GetTextGSC(money,exact)
226 local gtHookOnHide -- GtHookOnHide()
227 local gtHookSetAuctionSellItem -- GtHookSetAuctionSellItem(frame)
228 local gtHookSetBagItem -- GtHookSetBagItem(frame,frameID,buttonID,retVal)
229 local gtHookSetCraftItem -- GtHookSetCraftItem(frame,skill,slot)
230 local gtHookSetCraftSpell -- GtHookSetCraftSpell(frame,skill,slot)
231 local gtHookSetInboxItem -- GtHookSetinboxItem(frame,index)
232 local gtHookSetInventoryItem -- GtHookSetInventoryItem(frame,unit,slot,retVal)
233 local gtHookSetLootItem -- GtHookSetLootItem(frame,slot)
234 local gtHookSetMerchantItem -- GtHookSetMerchantItem(frame,slot)
235 local gtHookSetOwner -- GtHookSetOwner(frame,owner,anchor)
236 local gtHookSetQuestItem -- GtHookSetQuestItem(frame,qtype,slot)
237 local gtHookSetQuestLogItem -- GtHookSetQuestLogItem(frame,qtype,slot)
238 local gtHookSetTradeSkillItem -- GtHookSetTradeSkillItem(frame,skill,slot)
239 local gtHookSetText -- GtHookSetText(funcArgs, retval, frame, text, r, g, b, unknown1, unknown2)
240 local gtHookAppendText -- GtHookAppendText(funcArgs, retVal, frame)
241 local gtHookShow -- GtHookShow(funcArgs, retVal, frame)
242 local hideTooltip -- HideTooltip()
243 local hyperlinkFromLink -- HyperlinkFromLink(link)
244 local imHookOnEnter -- ImHookOnEnter()
245 local imiHookOnEnter -- ImiHookOnEnter()
246 local lineColor -- LineColor(r,g,b)
247 local lineQuality -- LineQuality(quality)
248 local lineSize_Large -- LineSize_Large()
249 local lineSize_Small -- LineSize_Small()
250 local linkType -- LinkType()
251 local llHookOnEnter -- LlHookOnEnter()
252 local merchantHook -- MerchantHook(merchant,slot,name,link,quality,count,price,limit)
253 local merchantScanner -- MerchantScanner()
254 local nameFromLink -- NameFromLink(link)
255 local qualityFromLink -- QualityFromLink(link)
256 local setElapsed -- SetElapsed(elapsed)
257 local setIcon -- SetIcon(iconPath)
258 local setMoneySpacing -- SetMoneySpacing(spacing)
259 local setPopupKey -- SetPopupKey(key)
260 local showTooltip -- ShowTooltip(currentTooltip,skipEmbedRender)
261 local tooltipCall -- TooltipCall(frame,name,link,quality,count,price,forcePopup,hyperlink)
262 local tradeHook -- TradeHook(type,selID)
263 local ttInitialize -- TtInitialize()
264  
265  
266 ------------------------
267 -- Hookable functions
268 ------------------------
269  
270 function addTooltip(frame, name, link, quality, count, price)
271 -- This is it.
272 -- Hook this function when you have something to put into the
273 -- tooltip and use the AddLine etc methods to do so.
274 end
275  
276 function checkPopup(name, link, quality, count, price, hyperlink)
277 -- Hook this function to stop EnhTooltip putting up a tooltip
278 -- Return true to stop EnhTooltip's tooltip.
279 end
280  
281 function merchantHook(merchant, slot, name, link, quality, count, price, limit)
282 -- Hook this function to be notified of an item at a merchant
283 end
284  
285 function bankHook()
286 -- Hook this function to be alerted to do a bank scan
287 end
288  
289 function bagHook()
290 -- Hook this function to be alerted to do a bag scan
291 end
292  
293 function tradeHook(type,selID)
294 -- Hook this function to be notified when a trade window is
295 -- displayed or an item therein is selected.
296 -- type is one of: "trade", or "craft"
297 -- selID can be nil when first opened, or the id of the selected item.
298 end
299  
300 ------------------------
301 -- Function definitions
302 ------------------------
303  
304 function hideTooltip()
305 EnhancedTooltip:Hide()
306 self.currentItem = ""
307 self.hideTime = 0
308 end
309  
310 -- Iterate over numbered global objects
311 function getglobalIterator(fmt, first, last)
312 local i = tonumber(first) or 1
313 return function()
314 if last and (i > last) then
315 return
316 end
317 local obj = getglobal(string.format(fmt, i))
318 i = i + 1
319 return obj
320 end
321 end
322  
323 function clearTooltip()
324 hideTooltip()
325 EnhancedTooltip.hasEmbed = false
326 EnhancedTooltip.curEmbed = false
327 EnhancedTooltip.hasData = false
328 EnhancedTooltip.hasIcon = false
329 EnhancedTooltipIcon:Hide()
330 EnhancedTooltipIcon:SetTexture("Interface\\Buttons\\UI-Quickslot2")
331  
332 for ttText in getglobalIterator("EnhancedTooltipText%d") do
333 ttText:Hide()
334 ttText:SetTextColor(1.0,1.0,1.0)
335 ttText:SetFont(STANDARD_TEXT_FONT, 10);
336 end
337  
338 for ttMoney in getglobalIterator("EnhancedTooltipMoney%d") do
339 ttMoney.myLine = nil
340 ttMoney:Hide()
341 end
342  
343 EnhancedTooltip.lineCount = 0
344 EnhancedTooltip.moneyCount = 0
345 EnhancedTooltip.minWidth = 0
346 for curLine in self.embedLines do
347 self.embedLines[curLine] = nil;
348 end
349 table.setn(self.embedLines, 0);
350 end
351  
352 function getRect(object, curRect)
353 local rect = curRect
354 if (not rect) then
355 rect = {}
356 end
357 rect.t = object:GetTop() or 0
358 rect.l = object:GetLeft() or 0
359 rect.b = object:GetBottom() or 0
360 rect.r = object:GetRight() or 0
361 rect.w = object:GetWidth() or 0
362 rect.h = object:GetHeight() or 0
363 rect.cx = rect.l + (rect.w / 2)
364 rect.cy = rect.t - (rect.h / 2)
365 return rect
366 end
367  
368 function showTooltip(currentTooltip, skipEmbedRender)
369 if (self.showIgnore == true) then return end
370 if (EnhancedTooltip.hasEmbed and not skipEmbedRender) then
371 embedRender()
372 self.showIgnore=true;
373 currentTooltip:Show()
374 self.showIgnore=false;
375 end
376 if (not EnhancedTooltip.hasData) then
377 return
378 end
379  
380 local width = EnhancedTooltip.minWidth
381 if (EnhancedTooltip.hasIcon) then
382 width = width + EnhancedTooltipIcon:GetWidth()
383 end
384 local lineCount = EnhancedTooltip.lineCount
385 if (lineCount == 0) then
386 if (not EnhancedTooltip.hasEmbed) then
387 hideTooltip()
388 return
389 end
390 end
391  
392 local height = 0
393 for currentLine in getglobalIterator("EnhancedTooltipText%d", 1, lineCount) do
394 height = height + currentLine:GetHeight() + 1
395 end
396 if EnhancedTooltip.hasIcon then
397 height = math.max(height, EnhancedTooltipIcon:GetHeight() - 6)
398 end
399 height = height + 20
400  
401 local sWidth = GetScreenWidth()
402 local sHeight = GetScreenHeight()
403  
404 local cWidth = currentTooltip:GetWidth()
405 if (cWidth < width) then
406 currentTooltip:SetWidth(width - 20)
407 self.showIgnore=true;
408 currentTooltip:Show()
409 self.showIgnore=false;
410 else
411 width = cWidth
412 end
413  
414 local parentObject = currentTooltip.owner
415 if (parentObject) then
416 local align = currentTooltip.anchor
417  
418 enhTooltipParentRect = getRect(currentTooltip.owner, enhTooltipParentRect)
419  
420 local xAnchor, yAnchor
421 if (enhTooltipParentRect.l - width < sWidth * 0.2) then
422 xAnchor = "RIGHT"
423 elseif (enhTooltipParentRect.r + width > sWidth * 0.8) then
424 xAnchor = "LEFT"
425 elseif (align == "ANCHOR_RIGHT") then
426 xAnchor = "RIGHT"
427 elseif (align == "ANCHOR_LEFT") then
428 xAnchor = "LEFT"
429 else
430 xAnchor = "RIGHT"
431 end
432 if (enhTooltipParentRect.cy < sHeight/2) then
433 yAnchor = "TOP"
434 else
435 yAnchor = "BOTTOM"
436 end
437  
438 -- Handle the situation where there isn't enough room on the choosen side of
439 -- the parent to display the tooltip. In that case we'll just shift tooltip
440 -- enough to the left or right so that it doesn't hang off the screen.
441 local xOffset = 0;
442 if (xAnchor == "RIGHT" and enhTooltipParentRect.r + width > sWidth - 5) then
443 xOffset = -(enhTooltipParentRect.r + width - sWidth + 5);
444 elseif (xAnchor == "LEFT" and enhTooltipParentRect.l - width < 5) then
445 xOffset = -(enhTooltipParentRect.l - width - 5);
446 end
447  
448 -- Handle the situation where there isn't enough room on the top or bottom of
449 -- the parent to display the tooltip. In that case we'll just shift tooltip
450 -- enough up or down so that it doesn't hang off the screen.
451 local yOffset = 0;
452 local totalHeight = height + currentTooltip:GetHeight();
453 if (yAnchor == "TOP" and enhTooltipParentRect.t + totalHeight > sHeight - 5) then
454 yOffset = -(enhTooltipParentRect.t + totalHeight - sHeight + 5);
455 elseif (yAnchor == "BOTTOM" and enhTooltipParentRect.b - totalHeight < 5) then
456 yOffset = -(enhTooltipParentRect.b - totalHeight - 5);
457 end
458  
459 currentTooltip:ClearAllPoints()
460 EnhancedTooltip:ClearAllPoints()
461 local anchor = yAnchor..xAnchor
462  
463 if (anchor == "TOPLEFT") then
464 EnhancedTooltip:SetPoint("BOTTOMRIGHT", parentObject, "TOPLEFT", -5 + xOffset, 5 + yOffset)
465 currentTooltip:SetPoint("BOTTOMRIGHT", EnhancedTooltip, "TOPRIGHT", 0,0)
466 elseif (anchor == "TOPRIGHT") then
467 EnhancedTooltip:SetPoint("BOTTOMLEFT", parentObject, "TOPRIGHT", 5 + xOffset, 5 + yOffset)
468 currentTooltip:SetPoint("BOTTOMLEFT", EnhancedTooltip, "TOPLEFT", 0,0)
469 elseif (anchor == "BOTTOMLEFT") then
470 currentTooltip:SetPoint("TOPRIGHT", parentObject, "BOTTOMLEFT", -5 + xOffset, -5 + yOffset)
471 EnhancedTooltip:SetPoint("TOPRIGHT", currentTooltip, "BOTTOMRIGHT", 0,0)
472 else -- BOTTOMRIGHT
473 currentTooltip:SetPoint("TOPLEFT", parentObject, "BOTTOMRIGHT", 5 + xOffset, -5 + yOffset)
474 EnhancedTooltip:SetPoint("TOPLEFT", currentTooltip, "BOTTOMLEFT", 0,0)
475 end
476  
477 else
478 -- No parent
479 -- The only option is to tack the object underneath / shuffle it up if there aint enuff room
480 self.showIgnore=true;
481 currentTooltip:Show()
482 self.showIgnore=false;
483 enhTooltipTipRect = getRect(currentTooltip, enhTooltipTipRect)
484  
485 if (enhTooltipTipRect.b - height < 60) then
486 currentTooltip:ClearAllPoints()
487 currentTooltip:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", enhTooltipTipRect.l, height+60)
488 end
489 EnhancedTooltip:ClearAllPoints()
490 if (enhTooltipTipRect.cx < 6*sWidth/10) then
491 EnhancedTooltip:SetPoint("TOPLEFT", currentTooltip, "BOTTOMLEFT", 0,0)
492 else
493 EnhancedTooltip:SetPoint("TOPRIGHT", currentTooltip, "BOTTOMRIGHT", 0,0)
494 end
495 end
496  
497 EnhancedTooltip:SetHeight(height)
498 EnhancedTooltip:SetWidth(width)
499 currentTooltip:SetWidth(width)
500 EnhancedTooltip:Show()
501  
502 for ttMoney in getglobalIterator("EnhancedTooltipMoney%d") do
503 if (ttMoney.myLine ~= nil) then
504 local myLine = getglobal(ttMoney.myLine)
505 local ttMoneyWidth = ttMoney:GetWidth()
506 local ttMoneyLineWidth = myLine:GetWidth()
507 ttMoney:ClearAllPoints()
508 if ((ttMoney.myLineNumber < 4) and (EnhancedTooltip.hasIcon)) then
509 ttMoney:SetPoint("LEFT", myLine, "RIGHT", width - ttMoneyLineWidth - ttMoneyWidth - self.moneySpacing*2 - 34, 0)
510 else
511 ttMoney:SetPoint("LEFT", myLine, "RIGHT", width - ttMoneyLineWidth - ttMoneyWidth - self.moneySpacing*2, 0)
512 end
513 end
514 end
515 end
516  
517 -- calculate the gold, silver, and copper values based the amount of copper
518 function getGSC(money)
519 if (money == nil) then money = 0 end
520 local g = math.floor(money / 10000)
521 local s = math.floor((money - (g*10000)) / 100)
522 local c = math.ceil(money - (g*10000) - (s*100))
523 return g,s,c
524 end
525  
526 -- formats money text by color for gold, silver, copper
527 function getTextGSC(money, exact, dontUseColorCodes)
528 local TEXT_NONE = "0"
529  
530 local GSC_GOLD="ffd100"
531 local GSC_SILVER="e6e6e6"
532 local GSC_COPPER="c8602c"
533 local GSC_START="|cff%s%d|r"
534 local GSC_PART=".|cff%s%02d|r"
535 local GSC_NONE="|cffa0a0a0"..TEXT_NONE.."|r"
536  
537 if (not exact) and (money >= 10000) then
538 -- Round to nearest silver
539 money = math.floor(money / 100 + 0.5) * 100
540 end
541 local g, s, c = getGSC(money)
542  
543 local gsc = ""
544 if (not dontUseColorCodes) then
545 local fmt = GSC_START
546 if (g > 0) then
547 gsc = gsc..string.format(fmt, GSC_GOLD, g)
548 fmt = GSC_PART
549 end
550 if (s > 0) or (c > 0) then
551 gsc = gsc..string.format(fmt, GSC_SILVER, s)
552 fmt = GSC_PART
553 end
554 if (c > 0) then
555 gsc = gsc..string.format(fmt, GSC_COPPER, c)
556 end
557 if (gsc == "") then
558 gsc = GSC_NONE
559 end
560 else
561 if (g > 0) then
562 gsc = gsc .. g .. "g ";
563 end;
564 if (s > 0) then
565 gsc = gsc .. s .. "s ";
566 end;
567 if (c > 0) then
568 gsc = gsc .. c .. "c ";
569 end;
570 if (gsc == "") then
571 gsc = TEXT_NONE
572 end
573 end
574 return gsc
575 end
576  
577 function embedRender()
578 for pos, lData in self.embedLines do
579 self.currentGametip:AddLine(lData.line)
580 if (lData.r) then
581 local lastLine = getglobal(self.currentGametip:GetName().."TextLeft"..self.currentGametip:NumLines())
582 lastLine:SetTextColor(lData.r,lData.g,lData.b)
583 end
584 end
585 end
586  
587 --[[
588 @param bExact (boolean) - optional parameter
589 if true, then the copper value of the given moneyAmount will always be printed out
590 if false (default), then the copper value of the given moneyAmount will not be printed out, if the moneyAmount is too high (see getTextGSC for the exact limit)
591 bExact has no meaning, if moneyAmount is nil.
592 ]]
593 function addLine(lineText, moneyAmount, embed, bExact)
594 if (embed) and (self.currentGametip) then
595 EnhancedTooltip.hasEmbed = true
596 EnhancedTooltip.curEmbed = true
597 local line = ""
598 if (moneyAmount) then
599 line = lineText .. ": " .. getTextGSC(moneyAmount, bExact)
600 else
601 line = lineText
602 end
603 table.insert(self.embedLines, {line = line})
604 return
605 end
606 EnhancedTooltip.hasData = true
607 EnhancedTooltip.curEmbed = false
608  
609 local curLine = EnhancedTooltip.lineCount + 1
610 local line = getglobal("EnhancedTooltipText"..curLine)
611 line:SetText(lineText)
612 line:SetTextColor(1.0, 1.0, 1.0)
613 line:Show()
614 local lineWidth = line:GetWidth()
615  
616 EnhancedTooltip.lineCount = curLine
617 if (moneyAmount ~= nil) and (moneyAmount > 0) then
618 local curMoney = EnhancedTooltip.moneyCount + 1
619 local money = getglobal("EnhancedTooltipMoney"..curMoney)
620 money:SetPoint("LEFT", line, "RIGHT", self.moneySpacing, 0)
621 TinyMoneyFrame_Update(money:GetName(), math.floor(moneyAmount))
622 money.myLine = line:GetName()
623 money.myLineNumber = curLine
624 money:Show()
625 local moneyWidth = money:GetWidth()
626 lineWidth = lineWidth + moneyWidth + self.moneySpacing
627 getglobal("EnhancedTooltipMoney"..curMoney.."SilverButtonText"):SetTextColor(1.0,1.0,1.0)
628 getglobal("EnhancedTooltipMoney"..curMoney.."CopperButtonText"):SetTextColor(0.86,0.42,0.19)
629 EnhancedTooltip.moneyCount = curMoney
630 end
631 lineWidth = lineWidth + 20
632 if (lineWidth > EnhancedTooltip.minWidth) then
633 EnhancedTooltip.minWidth = lineWidth
634 end
635 end
636  
637 function addSeparator(embed)
638 if (embed) and (self.currentGametip) then
639 EnhancedTooltip.hasEmbed = true
640 EnhancedTooltip.curEmbed = true
641 table.insert(self.embedLines, {line = " "})
642 return
643 end
644 EnhancedTooltip.hasData = true
645 EnhancedTooltip.curEmbed = false
646  
647 local curLine = EnhancedTooltip.lineCount +1;
648 local line = getglobal("EnhancedTooltipText"..curLine)
649 line:SetText(" ");
650 line:SetTextColor(1.0, 1.0, 1.0);
651 line:Show();
652 EnhancedTooltip.lineCount = curLine
653 end
654  
655 function lineColor(r, g, b)
656 if (EnhancedTooltip.curEmbed) and (self.currentGametip) then
657 local n = table.getn(self.embedLines)
658 self.embedLines[n].r = r
659 self.embedLines[n].g = g
660 self.embedLines[n].b = b
661 return
662 end
663 local curLine = EnhancedTooltip.lineCount
664 if (curLine == 0) then return end
665 local line = getglobal("EnhancedTooltipText"..curLine)
666 line:SetTextColor(r, g, b)
667 end
668  
669 function lineSize_Large()
670 if (EnhancedTooltip.curEmbed) and (self.currentGametip) then return end
671 local curLine = EnhancedTooltip.lineCount
672 if (curLine == 0) then return end
673 local line = getglobal("EnhancedTooltipText"..curLine)
674 line:SetFont(STANDARD_TEXT_FONT, 12)
675 end
676  
677 function lineSize_Small()
678 if (EnhancedTooltip.curEmbed) and (self.currentGametip) then return end
679 local curLine = EnhancedTooltip.lineCount
680 if (curLine == 0) then return end
681 local line = getglobal("EnhancedTooltipText"..curLine)
682 line:SetFont(STANDARD_TEXT_FONT, 10)
683 end
684  
685 function lineQuality(quality)
686 if ( quality ) then
687 local r, g, b = GetItemQualityColor(quality)
688 lineColor(r, g, b)
689 else
690 lineColor(1.0, 1.0, 1.0)
691 end
692 end
693  
694 function setIcon(iconPath)
695 EnhancedTooltipIcon:SetTexture(iconPath)
696 EnhancedTooltipIcon:Show()
697 EnhancedTooltip.hasIcon = true
698 end
699  
700 function gtHookOnHide()
701 local curName = ""
702 local hidingName = this:GetName()
703 if (self.currentGametip) then curName = self.currentGametip:GetName() end
704 if (curName == hidingName) then
705 HideObj = hidingName
706 self.hideTime = self.eventTimer + 0.1
707 end
708 end
709  
710 function doHyperlink(reference, link, button)
711 if (ItemRefTooltip:IsVisible()) then
712 local itemName = ItemRefTooltipTextLeft1:GetText()
713 if (itemName and self.currentItem ~= itemName) then
714 self.currentItem = itemName
715  
716 local testPopup = false
717 if (button == "RightButton") then
718 testPopup = true
719 end
720 local callRes = tooltipCall(ItemRefTooltip, itemName, link, -1, 1, 0, testPopup, reference)
721 if (callRes == true) then
722 self.oldChatItem = {['reference']=reference, ['link']=link, ['button']=button, ['embed']=EnhancedTooltip.hasEmbed}
723 elseif (callRes == false) then
724 return false;
725 end
726 end
727 end
728 end
729  
730 function checkHide()
731 if (self.hideTime == 0) then return end
732  
733 if (self.eventTimer >= self.hideTime) then
734 hideTooltip()
735 if (HideObj and HideObj == "ItemRefTooltip") then
736 -- closing chatreferenceTT?
737 self.oldChatItem = nil -- remove old chatlink data
738 elseif self.oldChatItem then
739 -- closing another tooltip
740 -- redisplay old chatlinkdata, if it was not embeded
741 if not self.oldChatItem.embed then
742 doHyperlink(self.oldChatItem.reference, self.oldChatItem.link, self.oldChatItem.button)
743 end
744 end
745 end
746 end
747  
748 function linkType(link)
749 if type(link) ~= "string" then
750 return
751 end
752 local _, _, linktype = string.find(link, "|H(%a+):")
753 return linktype
754 end
755  
756 function nameFromLink(link)
757 local name
758 if( not link ) then
759 return
760 end
761 _, _, name = string.find(link, "|c%x+|Hitem:%d+:%d+:%d+:%d+|h%[(.-)%]|h|r");
762 if (name) then
763 return name;
764 end
765 return
766 end
767  
768 function hyperlinkFromLink(link)
769 if( not link ) then
770 return
771 end
772 _, _, hyperlink = string.find(link, "|H([^|]+)|h");
773 if (hyperlink) then
774 return hyperlink;
775 end
776 end
777  
778 function baselinkFromLink(link)
779 if( not link ) then
780 return
781 end
782 _, _, baselink = string.find(link, "|Hitem:(%d+:%d+:%d+):%d+|h");
783 if (baselink) then
784 return baselink;
785 end
786 end
787  
788 function qualityFromLink(link)
789 if (not link) then return end
790 local _, _, color = string.find(link, "(|c%x+)|Hitem:%d+:%d+:%d+:%d+|h%[.-%]|h|r");
791 if color then
792 for i = 0, 6 do
793 local _, _, _, hex = GetItemQualityColor(i)
794 if color == hex then
795 return i
796 end
797 end
798 end
799 return -1
800 end
801  
802 function fakeLink(hyperlink, quality, name)
803 -- make this function nilSafe, as it's a global one and might be used by external addons
804 if not hyperlink then
805 return
806 end
807 local sName, sLink, iQuality = GetItemInfo(hyperlink)
808 if (quality == nil) then quality = iQuality or -1 end
809 if (name == nil) then name = sName or "unknown" end
810 local _, _, _, color = GetItemQualityColor(quality)
811 return color.. "|H"..hyperlink.."|h["..name.."]|h|r"
812 end
813  
814 function tooltipCall(frame, name, link, quality, count, price, forcePopup, hyperlink)
815 self.currentGametip = frame
816 self.hideTime = 0
817  
818 local itemSig = frame:GetName()
819 if (link) then itemSig = itemSig..link end
820 if (count) then itemSig = itemSig..count end
821 if (price) then itemSig = itemSig..price end
822  
823 if (self.currentItem and self.currentItem == itemSig) then
824 -- We are already showing this... No point doing it again.
825 showTooltip(self.currentGametip)
826 return
827 end
828  
829 self.currentItem = itemSig
830  
831 if (quality==nil or quality==-1) then
832 local linkQuality = qualityFromLink(link)
833 if (linkQuality and linkQuality > -1) then
834 quality = linkQuality
835 else
836 quality = -1
837 end
838 end
839 if (hyperlink == nil) then hyperlink = link end
840 local extract = hyperlinkFromLink(hyperlink)
841 if (extract) then hyperlink = extract end
842  
843 local showTip = true
844 local popupKeyPressed = (
845 (self.forcePopupKey == "ctrl" and IsControlKeyDown()) or
846 (self.forcePopupKey == "alt" and IsAltKeyDown()) or
847 (self.forcePopupKey == "shift" and IsShiftKeyDown())
848 )
849  
850 if ((forcePopup == true) or ((forcePopup == nil) and (popupKeyPressed))) then
851 local popupTest = checkPopup(name, link, quality, count, price, hyperlink)
852 if (popupTest) then
853 showTip = false
854 end
855 end
856  
857 if (showTip) then
858 clearTooltip()
859 self.showIgnore = true
860 EnhTooltip.AddTooltip(frame, name, link, quality, count, price)
861 self.showIgnore = false
862 showTooltip(frame)
863 self.currentItem = itemSig
864 return true
865 else
866 frame:Hide()
867 hideTooltip()
868 return false
869 end
870 end
871  
872  
873  
874 ------------------------
875 -- Hook calling functions
876 ------------------------
877  
878 function callCheckPopup(name, link, quality, count, price, hyperlink)
879 if (EnhTooltip.CheckPopup(name, link, quality, count, price, hyperlink)) then
880 return true;
881 end
882 return false
883 end
884  
885 function merchantScanner()
886 local npcName = UnitName("NPC")
887 local numMerchantItems = GetMerchantNumItems()
888 local link, quality, name, texture, price, quantity, numAvailable, isUsable
889 for i=1, numMerchantItems, 1 do
890 link = GetMerchantItemLink(i)
891 quality = qualityFromLink(link)
892 name, texture, price, quantity, numAvailable, isUsable = GetMerchantItemInfo(i)
893 EnhTooltip.MerchantHook(npcName, i, name, link, quality, quantity, price, numAvailable)
894 end
895 end
896  
897 function callBankHook()
898 if not (BankFrame and BankFrame:IsVisible()) then return end
899 EnhTooltip.BankHook(0)
900 end
901  
902 function callBagHook(funcVars, event, bagNumber)
903 if (bagNumber >= 5) and (bagNumber < 10) then
904 if not (BankFrame and BankFrame:IsVisible()) then return end
905 EnhTooltip.BankHook(bagNumber)
906 else
907 EnhTooltip.BagHook(bagNumber)
908 end
909 end
910  
911 function callTradeHook(funcVars, event, selID)
912 EnhTooltip.TradeHook(funcVars[1], selID)
913 end
914  
915  
916  
917 ------------------------
918 -- Tooltip functions that we have hooked
919 ------------------------
920  
921 function chatHookOnHyperlinkShow(funcArgs, retVal, reference, link, button)
922 if (IsAltKeyDown()) and AuctionFrame and (AuctionFrame:IsVisible()) then
923 AuctionFrameTab_OnClick(1)
924 local itemID = breakLink(link)
925 if (itemID) then
926 local itemName = GetItemInfo(tostring(itemID))
927 if (itemName) then
928 BrowseName:SetText(itemName)
929 BrowseMinLevel:SetText("")
930 BrowseMaxLevel:SetText("")
931 AuctionFrameBrowse.selectedInvtype = nil
932 AuctionFrameBrowse.selectedInvtypeIndex = nil
933 AuctionFrameBrowse.selectedClass = nil
934 AuctionFrameBrowse.selectedClassIndex = nil
935 AuctionFrameBrowse.selectedSubclass = nil
936 AuctionFrameBrowse.selectedSubclassIndex = nil
937 AuctionFrameFilters_Update()
938 IsUsableCheckButton:SetChecked(0)
939 UIDropDownMenu_SetSelectedValue(BrowseDropDown, -1)
940 AuctionFrameBrowse_Search()
941 BrowseNoResultsText:SetText(BROWSE_NO_RESULTS)
942 ItemRefTooltip:Hide()
943 end
944 end
945 return
946 end
947  
948 doHyperlink(reference, link, button)
949 end
950  
951 function afHookOnEnter(funcArgs, retVal, type, index)
952 local link = GetAuctionItemLink(type, index)
953 if (link) then
954 local name = nameFromLink(link)
955 if (name) then
956 local aiName, aiTexture, aiCount, aiQuality, aiCanUse, aiLevel, aiMinBid, aiMinIncrement, aiBuyoutPrice, aiBidAmount, aiHighBidder, aiOwner = GetAuctionItemInfo(type, index)
957 tooltipCall(GameTooltip, name, link, aiQuality, aiCount)
958 end
959 end
960 end
961  
962 function cfHookUpdate(funcArgs, retVal, frame)
963 local frameID = frame:GetID()
964 local frameName = frame:GetName()
965 local iButton
966 for iButton = 1, frame.size do
967 local button = getglobal(frameName.."Item"..iButton)
968 if (GameTooltip:IsOwned(button)) then
969 local buttonID = button:GetID()
970 local link = GetContainerItemLink(frameID, buttonID)
971 local name = nameFromLink(link)
972  
973 if (name) then
974 local texture, itemCount, locked, quality, readable = GetContainerItemInfo(frameID, buttonID)
975 if (quality == nil) then quality = qualityFromLink(link) end
976  
977 tooltipCall(GameTooltip, name, link, quality, itemCount)
978 end
979 end
980 end
981 end
982  
983 function gtHookSetLootItem(funcArgs, retVal, frame, slot)
984 local link = GetLootSlotLink(slot)
985 local name = nameFromLink(link)
986 if (name) then
987 local texture, item, quantity, quality = GetLootSlotInfo(slot)
988 if (quality == nil) then quality = qualityFromLink(link) end
989 tooltipCall(GameTooltip, name, link, quality, quantity)
990 end
991 end
992  
993 function gtHookSetQuestItem(funcArgs, retVal, frame, qtype, slot)
994 local link = GetQuestItemLink(qtype, slot)
995 if (link) then
996 local name, texture, quantity, quality, usable = GetQuestItemInfo(qtype, slot)
997 tooltipCall(GameTooltip, name, link, quality, quantity)
998 end
999 end
1000  
1001 function gtHookSetQuestLogItem(funcArgs, retVal, frame, qtype, slot)
1002 local link = GetQuestLogItemLink(qtype, slot)
1003 if (link) then
1004 local name, texture, quantity, quality, usable = GetQuestLogRewardInfo(slot)
1005 if (name == nil) then name = nameFromLink(link) end
1006 quality = qualityFromLink(link) -- I don't trust the quality returned from the above function.
1007  
1008 tooltipCall(GameTooltip, name, link, quality, quantity)
1009 end
1010 end
1011  
1012 function gtHookSetBagItem(funcArgs, retVal, frame, frameID, buttonID)
1013 local link = GetContainerItemLink(frameID, buttonID)
1014 local name = nameFromLink(link)
1015  
1016 if (name) then
1017 local texture, itemCount, locked, quality, readable = GetContainerItemInfo(frameID, buttonID)
1018 if (quality==nil or quality==-1) then quality = qualityFromLink(link) end
1019  
1020 tooltipCall(GameTooltip, name, link, quality, itemCount)
1021 end
1022 end
1023  
1024 function gtHookSetInboxItem(funcArgs, retVal, frame, index)
1025 local inboxItemName, itemTexture, inboxItemCount, inboxItemQuality = GetInboxItem(index)
1026 local itemName, hyperLink, itemQuality, itemLink
1027  
1028 for itemID = 1, 30000 do
1029 itemName, hyperLink, itemQuality = GetItemInfo(itemID)
1030 if (itemName and itemName == inboxItemName) then
1031 local _, _, _, hex = GetItemQualityColor(tonumber(itemQuality))
1032 itemLink = hex.. "|H"..hyperLink.."|h["..itemName.."]|h|r"
1033 tooltipCall(GameTooltip, inboxItemName, itemLink, inboxItemQuality, inboxItemCount)
1034 break
1035 end
1036 end
1037  
1038 end
1039  
1040 function gtHookSetInventoryItem(funcArgs, retVal, frame, unit, slot)
1041 local link = GetInventoryItemLink(unit, slot)
1042 if (link) then
1043 local name = nameFromLink(link)
1044 local quantity
1045 if (slot >= 20 and slot <= 23) then
1046 -- Workaround for bag slots. Quiver slots report the number of
1047 -- arrows in there instead of 1 for the actual bag.
1048 -- And well, bags aren't stackable anyway, so here you go:
1049 quantity = 1
1050 else
1051 -- Should be 1 for anything but quivers, because even empty slots
1052 -- return 1.. but who knows what crazy stuff Blizzard will add ;)
1053 quantity = GetInventoryItemCount(unit, slot)
1054 end
1055 local quality = GetInventoryItemQuality(unit, slot)
1056 if (quality == nil) then quality = qualityFromLink(link) end
1057  
1058 tooltipCall(GameTooltip, name, link, quality, quantity)
1059 end
1060 end
1061  
1062 function gtHookSetMerchantItem(funcArgs, retVal, frame, slot)
1063 local link = GetMerchantItemLink(slot)
1064 if (link) then
1065 local name, texture, price, quantity, numAvailable, isUsable = GetMerchantItemInfo(slot)
1066 local quality = qualityFromLink(link)
1067 tooltipCall(GameTooltip, name, link, quality, quantity, price)
1068 end
1069 end
1070  
1071 function gtHookSetCraftItem(funcArgs, retVal, frame, skill, slot)
1072 local link
1073 if (slot) then
1074 link = GetCraftReagentItemLink(skill, slot)
1075 if (link) then
1076 local name, texture, quantity, quantityHave = GetCraftReagentInfo(skill, slot)
1077 local quality = qualityFromLink(link)
1078 tooltipCall(GameTooltip, name, link, quality, quantity, 0)
1079 end
1080 else
1081 link = GetCraftItemLink(skill)
1082 if (link) then
1083 local name = nameFromLink(link)
1084 local quality = qualityFromLink(link)
1085 tooltipCall(GameTooltip, name, link, quality, 1, 0)
1086 end
1087 end
1088 end
1089  
1090 function gtHookSetCraftSpell(funcArgs, retVal, frame, slot)
1091 local name = GetCraftInfo(slot)
1092 local link = GetCraftItemLink(slot)
1093 if name and link then
1094 tooltipCall(GameTooltip, name, link)
1095 end
1096 end
1097  
1098 function gtHookSetTradeSkillItem(funcArgs, retVal, frame, skill, slot)
1099 local link
1100 if (slot) then
1101 link = GetTradeSkillReagentItemLink(skill, slot)
1102 if (link) then
1103 local name, texture, quantity, quantityHave = GetTradeSkillReagentInfo(skill, slot)
1104 local quality = qualityFromLink(link)
1105 tooltipCall(GameTooltip, name, link, quality, quantity, 0)
1106 end
1107 else
1108 link = GetTradeSkillItemLink(skill)
1109 if (link) then
1110 local name = nameFromLink(link)
1111 local quality = qualityFromLink(link)
1112 tooltipCall(GameTooltip, name, link, quality, 1, 0)
1113 end
1114 end
1115 end
1116  
1117 -- Given a Blizzard item link, breaks it into it's itemID, randomProperty, enchantProperty, uniqueness and name
1118 function breakLink(link)
1119 if (type(link) ~= 'string') then return end
1120 local i,j, itemID, enchant, randomProp, uniqID, name = string.find(link, "|Hitem:(%d+):(%d+):(%d+):(%d+)|h[[]([^]]+)[]]|h")
1121 return tonumber(itemID or 0), tonumber(randomProp or 0), tonumber(enchant or 0), tonumber(uniqID or 0), name
1122 end
1123  
1124  
1125 function findItemInBags(findName)
1126 for bag = 0, 4, 1 do
1127 size = GetContainerNumSlots(bag)
1128 if (size) then
1129 for slot = size, 1, -1 do
1130 local link = GetContainerItemLink(bag, slot)
1131 if (link) then
1132 local itemID, randomProp, enchant, uniqID, itemName = breakLink(link)
1133 if (itemName == findName) then
1134 return bag, slot, itemID, randomProp, enchant, uniqID
1135 end
1136 end
1137 end
1138 end
1139 end
1140 end
1141  
1142 function gtHookSetAuctionSellItem(funcArgs, retVal, frame)
1143 local name, texture, quantity, quality, canUse, price = GetAuctionSellItemInfo()
1144 if (name) then
1145 local bag, slot = findItemInBags(name)
1146 if (bag) then
1147 local link = GetContainerItemLink(bag, slot)
1148 if (link) then
1149 tooltipCall(GameTooltip, name, link, quality, quantity, price)
1150 end
1151 end
1152 end
1153 end
1154  
1155 function gtHookSetText(funcArgs, retval, frame, text, r, g, b, a, textWrap)
1156 -- Nothing to do for plain text
1157 if (self.currentGametip == frame) then
1158 clearTooltip()
1159 end
1160 end
1161  
1162 function gtHookAppendText(funcArgs, retVal, frame)
1163 if (self.currentGametip and self.currentItem and self.currentItem ~= "") then
1164 showTooltip(self.currentGametip, true)
1165 end
1166 end
1167  
1168 function gtHookShow(funcArgs, retVal, frame)
1169 if (self.hookRecursion) then
1170 return;
1171 end
1172 if (self.currentGametip and self.currentItem and self.currentItem ~= "") then
1173 self.hookRecursion = true;
1174 showTooltip(self.currentGametip, true)
1175 self.hookRecursion = nil;
1176 end
1177 end
1178  
1179 function imiHookOnEnter()
1180 if(not IM_InvList) then return end
1181 local id = this:GetID()
1182  
1183 if(id == 0) then
1184 id = this:GetParent():GetID()
1185 end
1186 local offset = FauxScrollFrame_GetOffset(ItemsMatrix_IC_ScrollFrame)
1187 local item = IM_InvList[id + offset]
1188  
1189 if (not item) then return end
1190 local imlink = ItemsMatrix_GetHyperlink(item.name)
1191 local link = fakeLink(imlink, item.quality, item.name)
1192 if (link) then
1193 tooltipCall(GameTooltip, item.name, link, item.quality, item.count, 0)
1194 end
1195 end
1196  
1197 function imHookOnEnter()
1198 local imlink = ItemsMatrix_GetHyperlink(this:GetText())
1199 if (imlink) then
1200 local name = this:GetText()
1201 local link = fakeLink(imlink, -1, name)
1202 tooltipCall(GameTooltip, name, link, -1, 1, 0)
1203 end
1204 end
1205  
1206 function getLootLinkServer()
1207 return LootLinkState.ServerNamesToIndices[GetCVar("realmName")]
1208 end
1209  
1210 function getLootLinkLink(name)
1211 local itemLink = ItemLinks[name]
1212 if (itemLink and itemLink.c and itemLink.i and LootLink_CheckItemServer(itemLink, getLootLinkServer())) then
1213 local item = string.gsub(itemLink.i, "(%d+):(%d+):(%d+):(%d+)", "%1:0:%3:%4")
1214 local link = "|c"..itemLink.c.."|Hitem:"..item.."|h["..name.."]|h|r"
1215 return link
1216 end
1217 return
1218 end
1219  
1220 function llHookOnEnter()
1221 local name = this:GetText()
1222 local link = getLootLinkLink(name)
1223 if (link) then
1224 local quality = qualityFromLink(link)
1225 tooltipCall(LootLinkTooltip, name, link, quality, 1, 0)
1226 end
1227 end
1228  
1229 function gtHookSetOwner(funcArgs, retVal, frame, owner, anchor)
1230 frame.owner = owner
1231 frame.anchor = anchor
1232 end
1233  
1234 ------------------------
1235 -- Operation functions
1236 ------------------------
1237  
1238 function setElapsed(elapsed)
1239 if (elapsed) then
1240 self.eventTimer = self.eventTimer + elapsed
1241 end
1242 checkHide()
1243 return self.eventTimer
1244 end
1245  
1246 function setMoneySpacing(spacing)
1247 if (spacing ~= nil) then self.moneySpacing = spacing end
1248 return self.moneySpacing
1249 end
1250  
1251 function setPopupKey(key)
1252 if (key ~= nil) then self.forcePopupKey = key end
1253 return self.forcePopupKey
1254 end
1255  
1256  
1257 ------------------------
1258 -- Debug functions
1259 ------------------------
1260  
1261 local function dump(...)
1262 local out = "";
1263 for i = 1, arg.n, 1 do
1264 local d = arg[i];
1265 local t = type(d);
1266 if (t == "table") then
1267 out = out .. "{";
1268 local first = true;
1269 if (d) then
1270 for k, v in pairs(d) do
1271 if (not first) then out = out .. ", "; end
1272 first = false;
1273 out = out .. dump(k);
1274 out = out .. " = ";
1275 out = out .. dump(v);
1276 end
1277 end
1278 out = out .. "}";
1279 elseif (t == "nil") then
1280 out = out .. "NIL";
1281 elseif (t == "number") then
1282 out = out .. d;
1283 elseif (t == "string") then
1284 out = out .. "\"" .. d .. "\"";
1285 elseif (t == "boolean") then
1286 if (d) then
1287 out = out .. "true";
1288 else
1289 out = out .. "false";
1290 end
1291 else
1292 out = out .. string.upper(t) .. "??";
1293 end
1294  
1295 if (i < arg.n) then out = out .. ", "; end
1296 end
1297 return out;
1298 end
1299  
1300 function debugPrint(...)
1301 local debugWin = 0;
1302 local name, shown;
1303 for i=1, NUM_CHAT_WINDOWS do
1304 name,_,_,_,_,_,shown = GetChatWindowInfo(i);
1305 if (string.lower(name) == "ettdebug") then debugWin = i; break; end
1306 end
1307 if (debugWin == 0) then return end
1308  
1309 local out = "";
1310 for i = 1, arg.n, 1 do
1311 if (i > 1) then out = out .. ", "; end
1312 local t = type(arg[i]);
1313 if (t == "string") then
1314 out = out .. '"'..arg[i]..'"';
1315 elseif (t == "number") then
1316 out = out .. arg[i];
1317 else
1318 out = out .. dump(arg[i]);
1319 end
1320 end
1321 getglobal("ChatFrame"..debugWin):AddMessage(out, 1.0, 1.0, 0.3);
1322 end
1323  
1324  
1325 ------------------------
1326 -- Load and initialization functions
1327 ------------------------
1328  
1329 --The new blizzard addons are called:
1330 -- Blizzard_TrainerUI, Blizzard_MacroUI, Blizzard_RaidUI, Blizzard_TradeSkillUI,
1331 -- Blizzard_InspectUI, Blizzard_BattlefieldMinimap, Blizzard_TalentUI,
1332 -- Blizzard_AuctionUI, Blizzard_BindingUI, Blizzard_CraftUI
1333  
1334  
1335 -- Hook in alternative Auctionhouse tooltip code
1336 local function hookAuctionHouse()
1337 Stubby.RegisterFunctionHook("AuctionFrameItem_OnEnter", 200, afHookOnEnter)
1338 end
1339  
1340 -- Hook the ItemsMatrix tooltip functions
1341 local function hookItemsMatrix()
1342 Stubby.RegisterFunctionHook("IMInv_ItemButton_OnEnter", 200, imiHookOnEnter)
1343 Stubby.RegisterFunctionHook("ItemsMatrixItemButton_OnEnter", 200, imHookOnEnter)
1344 end
1345  
1346 -- Hook the LootLink tooltip function
1347 local function hookLootLink()
1348 Stubby.RegisterFunctionHook("LootLinkItemButton_OnEnter", 200, llHookOnEnter)
1349 end
1350  
1351 -- Hook tradeskill functions
1352 local function hookTradeskill()
1353 Stubby.RegisterFunctionHook("TradeSkillFrame_Update", 200, callTradeHook, "trade", "")
1354 Stubby.RegisterFunctionHook("TradeSkillFrame_SetSelection", 200, callTradeHook, "trade", "")
1355 end
1356  
1357 -- Hook craft functions
1358 local function hookCraft()
1359 Stubby.RegisterFunctionHook("CraftFrame_Update", 200, callTradeHook, "craft", "");
1360 Stubby.RegisterFunctionHook("CraftFrame_SetSelection", 200, callTradeHook, "craft", "");
1361 end
1362  
1363 function ttInitialize()
1364 ---- Establish hooks to all the game tooltips.
1365  
1366 -- Hook in alternative Chat/Hyperlinking code
1367 Stubby.RegisterFunctionHook("ChatFrame_OnHyperlinkShow", 200, chatHookOnHyperlinkShow)
1368  
1369 -- Container frame linking
1370 Stubby.RegisterFunctionHook("ContainerFrame_Update", 200, cfHookUpdate)
1371  
1372 -- Game tooltips
1373 Stubby.RegisterFunctionHook("GameTooltip.SetLootItem", 200, gtHookSetLootItem);
1374 Stubby.RegisterFunctionHook("GameTooltip.SetQuestItem", 200, gtHookSetQuestItem);
1375 Stubby.RegisterFunctionHook("GameTooltip.SetQuestLogItem", 200, gtHookSetQuestLogItem);
1376 Stubby.RegisterFunctionHook("GameTooltip.SetInboxItem", 200, gtHookSetInboxItem);
1377 Stubby.RegisterFunctionHook("GameTooltip.SetInventoryItem", 200, gtHookSetInventoryItem);
1378 Stubby.RegisterFunctionHook("GameTooltip.SetBagItem", 200, gtHookSetBagItem);
1379 Stubby.RegisterFunctionHook("GameTooltip.SetMerchantItem", 200, gtHookSetMerchantItem);
1380 Stubby.RegisterFunctionHook("GameTooltip.SetCraftItem", 200, gtHookSetCraftItem);
1381 Stubby.RegisterFunctionHook("GameTooltip.SetCraftSpell", 200, gtHookSetCraftSpell);
1382 Stubby.RegisterFunctionHook("GameTooltip.SetTradeSkillItem", 200, gtHookSetTradeSkillItem);
1383 Stubby.RegisterFunctionHook("GameTooltip.SetAuctionSellItem", 200, gtHookSetAuctionSellItem);
1384 Stubby.RegisterFunctionHook("GameTooltip.SetText", 200, gtHookSetText);
1385 Stubby.RegisterFunctionHook("GameTooltip.AppendText", 200, gtHookAppendText);
1386 Stubby.RegisterFunctionHook("GameTooltip.SetOwner", 200, gtHookSetOwner);
1387 Stubby.RegisterFunctionHook("GameTooltip.Show", 200, gtHookShow);
1388 Stubby.RegisterFunctionHook("GameTooltip_OnHide", 200, gtHookOnHide);
1389  
1390 -- Establish hooks for us to use.
1391 Stubby.RegisterAddOnHook("Blizzard_AuctionUI", "EnhTooltip", hookAuctionHouse)
1392 Stubby.RegisterAddOnHook("ItemsMatrix", "EnhTooltip", hookItemsMatrix)
1393 Stubby.RegisterAddOnHook("LootLink", "EnhTooltip", hookLootLink)
1394 Stubby.RegisterAddOnHook("Blizzard_TradeSkillUI", "EnhTooltip", hookTradeskill)
1395 Stubby.RegisterAddOnHook("Blizzard_CraftUI", "EnhTooltip", hookCraft)
1396  
1397 -- Register event notification
1398 Stubby.RegisterEventHook("MERCHANT_SHOW", "EnhTooltip", merchantScanner);
1399 Stubby.RegisterEventHook("TRADE_SKILL_SHOW", "EnhTooltip", callTradeHook, 'trade');
1400 Stubby.RegisterEventHook("TRADE_SKILL_CLOSE", "EnhTooltip", callTradeHook, 'trade');
1401 Stubby.RegisterEventHook("CRAFT_SHOW", "EnhTooltip", callTradeHook, 'craft');
1402 Stubby.RegisterEventHook("CRAFT_CLOSE", "EnhTooltip", callTradeHook, 'craft');
1403 Stubby.RegisterEventHook("BANKFRAME_OPENED", "EnhTooltip", callBankHook);
1404 Stubby.RegisterEventHook("PLAYERBANKSLOTS_CHANGED", "EnhTooltip", callBankHook);
1405 Stubby.RegisterEventHook("BAG_UPDATE", "EnhTooltip", callBagHook);
1406 end
1407  
1408  
1409 -- =============== EVENT HANDLERS =============== --
1410  
1411 function TT_OnLoad()
1412 EnhancedTooltip:SetBackdropColor(0,0,0)
1413 clearTooltip()
1414 ttInitialize()
1415 end
1416  
1417 function TT_OnUpdate(elapsed)
1418 setElapsed(elapsed)
1419 end
1420  
1421 -- =============== DEFINE ACCESS OBJECT =============== --
1422  
1423 -- Global object
1424 EnhTooltip = {
1425 AddTooltip = addTooltip,
1426 CheckPopup = checkPopup,
1427 MerchantHook = merchantHook,
1428 TradeHook = tradeHook,
1429 BankHook = bankHook,
1430 BagHook = bagHook,
1431  
1432 AddLine = addLine,
1433 AddSeparator = addSeparator,
1434 LineColor = lineColor,
1435 LineQuality = lineQuality,
1436 LineSize_Large = lineSize_Large,
1437 LineSize_Small = lineSize_Small,
1438 SetIcon = setIcon,
1439  
1440 ClearTooltip = clearTooltip,
1441 HideTooltip = hideTooltip,
1442 ShowTooltip = showTooltip,
1443  
1444 GetglobalIterator = getglobalIterator,
1445 GetGSC = getGSC,
1446 GetTextGSC = getTextGSC,
1447 BaselinkFromLink = baselinkFromLink,
1448 BreakLink = breakLink,
1449 FindItemInBags = findItemInBags,
1450  
1451 FakeLink = fakeLink,
1452 HyperlinkFromLink = hyperlinkFromLink,
1453 NameFromLink = nameFromLink,
1454 QualityFromLink = qualityFromLink,
1455 LinkType = linkType,
1456  
1457 SetMoneySpacing = setMoneySpacing,
1458 SetPopupKey = setPopupKey,
1459 TooltipCall = tooltipCall,
1460  
1461 SetElapsed = setElapsed,
1462 DebugPrint = debugPrint,
1463 }