IDCard = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0","AceHook-2.0","AceDB-2.0","AceConsole-2.0","AceLocale-2.0","AceDebug-2.0")
IDCard:RegisterDB("IDCardDB")
IDCard:RegisterChatCommand({"/idcard"})
IDCard.version = "0.$Rev$"
IDCard.date = "$Date$"
IDCard.ItemColors = {[0] = "ff9d9d9d","ffffffff","ff1eff00","ff0070dd","ffa335ee","ffff8000","ffe6cc80"}
function IDCard:OnInitialize()
self.super.OnInitialize(self)
local f = CreateFrame("Button",nil,ItemRefTooltip)
f:SetWidth(37)
f:SetHeight(37)
f:SetPoint("TOPRIGHT",ItemRefTooltip,"TOPLEFT",-3,0)
f:SetScript("OnDragStart",function() this:GetParent():StartMoving() end)
f:SetScript("OnDragStop",function() this:GetParent():StopMovingOrSizing() end)
f:SetScript("OnClick",function()
if(IsShiftKeyDown() and ChatFrameEditBox:IsVisible()) then
self:InsertLink()
elseif(IsControlKeyDown()) then
DressUpItemLink(self.id)
end
end)
self.button = f
end
function IDCard:OnEnable()
self:Hook(ItemRefTooltip,"SetHyperlink")
end
function IDCard:OnDisable()
self.frame:Hide()
end
function IDCard:SetHyperlink(itemID)
if(not itemID) then return end
local _,_,_,_,_,_,_,_,texture = GetItemInfo(itemID)
self.id = itemID
if(not texture and not self:IsHooked(ItemRefTooltip,"OnSizeChanged")) then
if(self:IsDebugging()) then debugprofilestart() end
self:HookScript(ItemRefTooltip,"OnSizeChanged","TooltipUpdate")
end
self.button:SetNormalTexture(texture)
self.Hooks[ItemRefTooltip].SetHyperlink.orig(ItemRefTooltip,itemID)
end
function IDCard:InsertLink()
local name,item,quality = GetItemInfo(self.id)
if not name then return end
ChatFrameEditBox:Insert("|c"..self.ItemColors[quality].."|H"..item.."|h["..name.."]|h|r")
end
function IDCard:TooltipUpdate()
local _,_,_,_,_,_,_,_,texture = GetItemInfo(self.id)
if(texture) then
self:UnhookScript(this,"OnSizeChanged")
self:Debug("Time to fetch item info from server: %s",debugprofilestop())
self.button:SetNormalTexture(texture)
end
end