All pastes #85200 Raw Edit

IDCard

public lua v1 · immutable
·published 2006-07-11 19:17 UTC
rendered paste body
IDCard = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0","AceHook-2.0","AceDB-2.0","AceConsole-2.0","AceDebug-2.0")IDCard:RegisterDB("IDCardDB")IDCard:RegisterChatCommand({"/idcard"})IDCard.version = "0.$Rev: 4302 $"IDCard.date = "$Date: 2006-07-08 14:49:21 -0500 (Sat, 08 Jul 2006) $"IDCard.ItemColors = {[0] = "ff9d9d9d","ffffffff","ff1eff00","ff0070dd","ffa335ee","ffff8000","ffe6cc80"}function IDCard:OnInitialize()    local f = CreateFrame("Button",nil,ItemRefTooltip)    f:SetWidth(37)    f:SetHeight(37)    f:SetPoint("TOPRIGHT",ItemRefTooltip,"TOPLEFT",0,-3)        f:RegisterForDrag("LeftButton")    f:RegisterForClicks("LeftButtonUp")        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 = fendfunction IDCard:OnEnable()    self:Hook(ItemRefTooltip,"SetHyperlink")endfunction IDCard:OnDisable()    self.button:Hide()endfunction IDCard:SetHyperlink(frame,itemID)    if(not itemID) then return end    self:Debug(itemID)    local _,_,_,_,_,_,_,_,texture = GetItemInfo(itemID)    self.id = itemID    if(not texture and not self:IsHooked(frame,"OnSizeChanged")) then        if(self:IsDebugging()) then debugprofilestart() end        self:HookScript(frame,"OnSizeChanged","TooltipUpdate")    end    self.button:SetNormalTexture(texture)    self.hooks[frame].SetHyperlink.orig(frame,itemID)endfunction 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")endfunction 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    self.hooks[this].OnSizeChanged.orig()end