Objectives can now mark the objectives they're use by when watched.
[QuestHelper.git] / objtips.lua
blobcfc88f93d3d2452debcce116d4e04d0fb752e6a0
1 local real_GameTooltipOnShow = GameTooltip:GetScript("OnShow") or QuestHelper.nop
3 local function addObjectiveObjTip(objective, gap)
4 if objective.watched or objective.progress then
5 if gap then
6 GameTooltip:AddLine(" ") -- Add a gap between what we're adding and what's already there.
7 end
9 if objective.quest then
10 GameTooltip:AddLine(QHFormat("TOOLTIP_QUEST", string.match(objective.quest.obj or "", "^%d*/%d*/(.*)$") or "???"), 1, 1, 1)
11 end
13 if objective.progress then
14 QuestHelper:AppendObjectiveProgressToTooltip(objective, GameTooltip)
15 else
16 GameTooltip:AddLine(QHText("TOOLTIP_WATCHED"), unpack(QuestHelper:GetColourTheme().tooltip))
17 end
19 -- Calling Show again to cause the tooltip's dimensions to be recalculated.
20 -- Since the frame should already be shown, the OnShow event shouldn't be called again.
21 GameTooltip:Show()
22 end
24 if objective.used then
25 for obj, text in pairs(objective.used) do
26 GameTooltip:AddLine(" ")
27 GameTooltip:AddLine(QHFormat(text, obj.obj), 1, 1, 1)
28 addObjectiveObjTip(obj, false)
29 end
30 end
31 end
33 local function addObjectiveTip(cat, obj)
34 local list = QuestHelper.objective_objects[cat]
35 if list then
36 local objective = list[obj]
37 if objective then
38 addObjectiveObjTip(objective, true)
39 end
40 end
41 end
43 GameTooltip:SetScript("OnShow", function(self, ...)
44 if not self then
45 -- Some other AddOns hook this function, but don't bother to pass the values they were called with.
46 self = GameTooltip
47 end
49 if QuestHelper_Pref.tooltip then
50 local monster, item = self:GetUnit(), self:GetItem()
52 if monster then
53 addObjectiveTip("monster", monster)
54 end
56 if item then
57 addObjectiveTip("item", item)
58 end
59 end
61 return real_GameTooltipOnShow(self, ...)
62 end)