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)
Fri Jun 27 20:44:44 -0700 2008
commit  0549be7ae2f3eb24cbe1079fdd19372e4586c7df
tree    4e2431039d3768d1744f442524013ae08fa1a1b2
parent  21e00a5520c69bc10efc9f3f93e7802b4b6043a5
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