arrrgh
[QuestHelper.git] / objtips.lua
blob712c2fd560a083be05cb8d31ce6df9c3d27be051
1 QuestHelper_File["objtips.lua"] = "Development Version"
3 local real_GameTooltipOnShow = GameTooltip:GetScript("OnShow") or QuestHelper.nop
5 local function addObjectiveObjTip(tooltip, objective, depth, already_touched)
6 if depth > 10 then return end -- fuck that, man. Just fuck that.
7 already_touched[objective] = true -- YOU CANNOT EAT A PURSE
9 if objective.watched or objective.progress then
10 local depth2 = depth
12 if objective.quest then
13 tooltip:AddLine((" "):rep(depth2)..QHFormat("TOOLTIP_QUEST", string.match(objective.quest.obj or "", "^%d*/%d*/(.*)$") or "???"), 1, 1, 1)
15 depth2 = depth2 + 1
16 end
18 if objective.progress then
19 QuestHelper:AppendObjectiveProgressToTooltip(objective, tooltip, nil, depth2)
20 else
21 tooltip:AddLine((" "):rep(depth2)..QHText("TOOLTIP_WATCHED"), unpack(QuestHelper:GetColourTheme().tooltip))
22 end
24 -- Calling Show again to cause the tooltip's dimensions to be recalculated.
25 -- Since the frame should already be shown, the OnShow event shouldn't be called again.
26 tooltip:Show()
27 end
29 if objective.used then
30 for obj, text in pairs(objective.used) do
31 if not already_touched[obj] then -- no infinite loops please
32 tooltip:AddLine((" "):rep(depth)..QHFormat(text, obj.obj), 1, 1, 1)
33 addObjectiveObjTip(tooltip, obj, depth+1, already_touched)
34 end
35 end
36 end
38 already_touched[objective] = nil -- oh why not. just so I can get a screenshot of some poor sap getting a 2^n case
39 end
41 local function addObjectiveTip(tooltip, cat, obj)
42 local list = QuestHelper.objective_objects[cat]
43 if list then
44 local objective = list[obj]
45 if objective then
46 addObjectiveObjTip(tooltip, objective, 0, {})
47 end
48 end
49 end
51 GameTooltip:SetScript("OnShow", function(self, ...)
52 if not self then
53 -- Some other AddOns hook this function, but don't bother to pass the values they were called with.
54 self = GameTooltip
55 end
57 if QuestHelper_Pref.tooltip then
58 -- Apparantly, sometimes InventoryOnPar invokes our tooltip function with something that doesn't have GetItem method.
59 local monster, item = self.GetUnit and self:GetUnit(), self.GetItem and self:GetItem()
61 if monster then
62 addObjectiveTip(self, "monster", monster)
63 end
65 if item then
66 addObjectiveTip(self, "item", item)
67 end
68 end
70 return real_GameTooltipOnShow(self, ...)
71 end)