WoWInterface SVN QueTip

[/] [trunk/] [QueTip/] [core.lua] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 Slakah-64906
local qmobs, qitems = {} , {} -- cache the data
2 Slakah-64906
 
3 Slakah-64906
local match, format, tonumber = strmatch,  format, tonumber --apparently its good for you
4 Slakah-64906
 
5 Slakah-64906
--taken from the wonderful LibQuixote-2.0 by kemayo
6 Slakah-64906
local objects_pattern = "^"..QUEST_OBJECTS_FOUND:gsub("(%%.)", "(.+)").."$" --QUEST_OBJECTS_FOUND = "%s: %d/%d"
7 Slakah-64906
local monsters_pattern = "^"..QUEST_MONSTERS_KILLED:gsub("(%%.)", "(.+)").."$" --QUEST_MONSTERS_KILLED = "%s slain: %d/%d"
8 Slakah-64906
 
9 Slakah-64906
local function ColourGradient(perc) -- for colouring in
10 Slakah-64906
    if perc <= 0.5 then
11 Slakah-64906
        return 1, perc*2, 0
12 Slakah-64906
    else
13 Slakah-64906
        return 2 - perc*2, 1, 0
14 Slakah-64906
    end
15 Slakah-64906
end
16 Slakah-64906
local function AddQuest(table, title, name, have, need)
17 Slakah-64906
    if table[name] then -- incase theres more than one quest wanting  the same thing
18 Slakah-64906
        if type(table[name]) == "string" then
19 Slakah-64906
            table[name] = {table[name]}
20 Slakah-64906
        end
21 Slakah-64906
        local t = table[name]
22 Slakah-64906
        t[#t+1] = format("%s:%d/%d", title, tonumber(have), tonumber(need))
23 Slakah-64906
    else table[name] = format("%s:%d/%d", title, tonumber(have), tonumber(need))
24 Slakah-64906
    end
25 Slakah-64906
end
26 Slakah-64906
 
27 Slakah-64906
local qtitle, header, _, need, have, desc, qtype, mobname
28 Slakah-64906
 
29 Slakah-64906
--update qmobs/qitems when quest log updates
30 Slakah-64906
local f = CreateFrame("Frame")
31 Slakah-64906
f:RegisterEvent("QUEST_LOG_UPDATE")
32 Slakah-64906
f:SetScript("OnEvent", function()
33 Slakah-64906
    for i, v in pairs(qmobs) do qmobs[i] = nil end  --erase tables
34 Slakah-64906
    for i, v in pairs(qitems) do qitems[i] = nil end
35 Slakah-64906
 
36 Slakah-64906
 
37 Slakah-64906
    for questid = 1, GetNumQuestLogEntries() do
38 Slakah-64906
        qtitle, _, _, _, header = GetQuestLogTitle(questid)
39 Slakah-64906
        if not header and GetNumQuestLeaderBoards(questid) > 0 then
40 Slakah-64906
            for questob = 1, GetNumQuestLeaderBoards(questid) do
41 Slakah-64906
                desc, qtype = GetQuestLogLeaderBoard(questob, questid)
42 Slakah-64906
                if qtype == "monster" then
43 Slakah-64906
                    mobname, have, need = desc:match(monsters_pattern)
44 Slakah-64906
                    if mobname == nil or have == nil or need == nil then
45 Slakah-64906
                        AddQuest(qmobs,qtitle,desc:match("^%w+ (.+):(.+)/(.+)$")) -- Find Mankrik's Wife: 0/1
46 Slakah-64906
                        AddQuest(qmobs,qtitle,desc:match("^(.+) %w+:(.+)/(.+)$")) --Aether Rays Wrangled: 5/6
47 Slakah-64906
                    else AddQuest(qmobs,qtitle,mobname,have,need)
48 Slakah-64906
                    end
49 Slakah-64906
 
50 Slakah-64906
                elseif qtype == "item" or qtype == "object" then
51 Slakah-64906
                    AddQuest(qitems,qtitle,desc:match(objects_pattern))
52 Slakah-64906
                end
53 Slakah-64906
            end
54 Slakah-64906
        end
55 Slakah-64906
    end
56 Slakah-64906
end)
57 Slakah-64906
 
58 Slakah-64906
local function AddQuestTooltipLine(name, table, tooltip)
59 Slakah-64906
    local obs = table[name]
60 Slakah-64906
    if obs then
61 Slakah-64906
        if type(obs) == "table" then
62 Slakah-64906
            for i, v in ipairs(obs) do
63 Slakah-64906
                qtitle, have, need = match(v, "(.+:)(%d+)/(%d+)")
64 Slakah-64906
                tooltip:AddDoubleLine(qtitle, have.."/"..need, 1, 1, 1, ColourGradient(have/need))
65 Slakah-64906
            end
66 Slakah-64906
        else qtitle, have, need = match(obs, "(.+:)(%d+)/(%d+)")
67 Slakah-64906
            tooltip:AddDoubleLine(qtitle, have.."/"..need, 1, 1, 1, ColourGradient(have/need))
68 Slakah-64906
        end
69 Slakah-64906
    end
70 Slakah-64906
end
71 Slakah-64906
 
72 Slakah-64906
 
73 Slakah-64906
 
74 Slakah-64906
--Hooks
75 Slakah-64906
local name
76 Slakah-64906
GameTooltip:HookScript("OnTooltipSetItem", function(tooltip)
77 Slakah-64906
    name = tooltip:GetItem()
78 Slakah-64906
    if name then
79 Slakah-64906
        AddQuestTooltipLine(name, qitems, tooltip)
80 Slakah-64906
    end
81 Slakah-64906
end)
82 Slakah-64906
 
83 Slakah-64906
ItemRefTooltip:HookScript("OnTooltipSetItem", function(tooltip)
84 Slakah-64906
    name = tooltip:GetItem()
85 Slakah-64906
    if name then
86 Slakah-64906
        AddQuestTooltipLine(name, qitems, tooltip)
87 Slakah-64906
    end
88 Slakah-64906
end)
89 Slakah-64906
 
90 Slakah-64906
 
91 Slakah-64906
GameTooltip:HookScript("OnTooltipSetUnit", function(tooltip)
92 Slakah-64906
    name = tooltip:GetUnit()
93 Slakah-64906
    if not UnitIsPlayer("mouseover") and name then
94 Slakah-64906
        AddQuestTooltipLine(name, qmobs, tooltip)
95 Slakah-64906
    end
96 Slakah-64906
end)
97 Slakah-64906
 
98 Slakah-64906
 
99 Slakah-64906