public
Description: WoW Addon - Prospecting and Disenchanting Aide
Homepage: http://www.tekkub.net
Clone URL: git://github.com/tekkub/panda.git
Click here to lend your support to: panda and make a donation at www.pledgie.com !
tekkub (author)
Tue Apr 15 14:24:48 -0700 2008
commit  1a3fe6d70cca41071cb9a06a2f6886fb2d06ef06
tree    a0e63973cd848921e7e25c84cd443b33dbb78c31
parent  88825f764210a8cedf108e33d68b0edf66755560
panda / GemTooltip.lua
100644 37 lines (28 sloc) 1.104 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

local Panda = Panda
local GS = Panda.GS
local BC_GREEN_GEMS, BC_BLUE_GEMS, CUTS = Panda.BC_GREEN_GEMS, Panda.BC_BLUE_GEMS, Panda.CUTS
 
 
local values = setmetatable({}, {
  __index = function(t, link)
    if not link then return end
    local id = tonumber((link:match("item:(%d+):")))
    if not id or not CUTS[id] or not Panda:GetAHBuyout(id) then return end
 
    local val = 0
    for _,cutid in pairs(CUTS[id]) do val = val + (Panda:GetAHBuyout(cutid) or 0) end
    val = string.format("%s (%.2f%% profit)", GS(val/#CUTS[id]), ((val/#CUTS[id])/Panda:GetAHBuyout(id) - 1) * 100)
    t[link] = val
    return val
  end,
})
 
 
local origs = {}
local OnTooltipSetItem = function(frame, ...)
  assert(frame, "arg 1 is nil, someone isn't hooking correctly")
 
  local _, link = frame:GetItem()
  local val = values[link]
  if val and val ~= 0 then frame:AddDoubleLine("Average cut value:", val) end
  if origs[frame] then return origs[frame](frame, ...) end
end
 
for i,frame in pairs{GameTooltip, ItemRefTooltip} do
  origs[frame] = frame:GetScript("OnTooltipSetItem")
  frame:SetScript("OnTooltipSetItem", OnTooltipSetItem)
end