AllTheIDs.lua 1.75 KB
Newer Older
1
2
3
4
5
6
7
8

local addon_name, addon = ...

function addon:AddIDLine(tip, ...)  -- idname, id
    if tip._alltheid then
        return
    end

9
10
11
12
13
14
15
16
17
18
19
    local line = self:IDLine(...)
    if line then
        tip:AddLine(line)
        if tip:IsShown() then
            -- force redraw
            tip:Show()
        end
        tip._alltheid = true
    end
end

20
21
22
23
24
25
26
27
28
29
30
31
32
33
do
    local tmp = {}
    function addon:IDLine(...)
        wipe(tmp)

        for i = 1,select("#", ...),2 do
            local name, id = select(i, ...)
            if id then
                tinsert(tmp, format("|cff33cc44%s ID:|r %s", name, id))
            end
        end

        if #tmp > 0 then
            return table.concat(tmp, " / ")
34
35
        end
    end
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
end

do
    local tmp = {}
    function addon:TextAppendID(fs, ...)
        local line = self:IDLine(...)
        local orig = fs:GetText()
        if line == fs._alltheid and strfind(orig, line) then
            return
        end

        wipe(tmp)
        tinsert(tmp, orig)
        tinsert(tmp, "\n")
        tinsert(tmp, line)
        fs:SetText(table.concat(tmp, ""))
52

53
        fs._alltheid = line
54
55
56
    end
end

57
58
59
60
61
62
63
64
function addon:HookTipScript(handler, func)
    if GameTooltip:HasScript(handler) then
        GameTooltip:HookScript(handler, func)
    end

    if ItemRefTooltip:HasScript(handler) then
        ItemRefTooltip:HookScript(handler, func)
    end
65
66
67
end

function addon:HookTip(method, hookfunc)
68
69
70
71
72
73
74
    if GameTooltip[method] then
        hooksecurefunc(GameTooltip, method, function(self, ...) hookfunc(GameTooltip, ...) end)
    end

    if ItemRefTooltip[method] then
        hooksecurefunc(ItemRefTooltip, method, function(self, ...) hookfunc(ItemRefTooltip, ...) end)
    end
75
76
77
78
79
80
end

addon:HookTipScript("OnTooltipCleared", function(self)
    self._alltheid = nil
end)