Merge branch 'master' of git://cams.pavlovian.net/questhelper
[QuestHelper.git] / objtips.lua
blob18281207ddbfab2d39690a5a992028748ea00a5e
1 QuestHelper_File["objtips.lua"] = "Development Version"
2 QuestHelper_Loadtime["objtips.lua"] = GetTime()
4 --[[
5 local real_GameTooltipOnShow = GameTooltip:GetScript("OnShow") or QuestHelper.nop
7 local function addObjectiveObjTip(tooltip, objective, depth, already_touched)
8 if depth > 10 then return end -- fuck that, man. Just fuck that.
9 already_touched[objective] = true -- YOU CANNOT EAT A PURSE
11 if objective.watched or objective.progress then
12 local depth2 = depth
14 if objective.quest then
15 tooltip:AddLine((" "):rep(depth2)..QHFormat("TOOLTIP_QUEST", string.match(objective.quest.obj or "", "^%d*/%d*/(.*)$") or "???"), 1, 1, 1)
17 depth2 = depth2 + 1
18 end
20 if objective.progress then
21 QuestHelper:AppendObjectiveProgressToTooltip(objective, tooltip, nil, depth2)
22 else
23 tooltip:AddLine((" "):rep(depth2)..QHText("TOOLTIP_WATCHED"), unpack(QuestHelper:GetColourTheme().tooltip))
24 end
26 -- Calling Show again to cause the tooltip's dimensions to be recalculated.
27 -- Since the frame should already be shown, the OnShow event shouldn't be called again.
28 tooltip:Show()
29 end
31 if objective.used then
32 for obj, text in pairs(objective.used) do
33 if not already_touched[obj] then -- no infinite loops please
34 tooltip:AddLine((" "):rep(depth)..QHFormat(text, obj.obj), 1, 1, 1)
35 addObjectiveObjTip(tooltip, obj, depth+1, already_touched)
36 end
37 end
38 end
40 already_touched[objective] = nil -- oh why not. just so I can get a screenshot of some poor sap getting a 2^n case
41 end
43 local function addObjectiveTip(tooltip, cat, obj)
44 local list = QuestHelper.objective_objects[cat]
45 if list then
46 local objective = list[obj]
47 if objective then
48 addObjectiveObjTip(tooltip, objective, 0, {})
49 end
50 end
51 end
53 local function CopyOver(to, from)
54 to:SetFont(from:GetFont())
55 to:SetFontObject(from:GetFontObject())
56 to:SetText(from:GetText())
57 to:SetTextColor(from:GetTextColor())
58 to:SetSpacing(from:GetSpacing())
59 to:SetShadowOffset(from:GetShadowOffset())
60 to:SetShadowColor(from:GetShadowColor())
61 to:Show()
62 end
64 local function StripBlizzQHTooltipClone(ttp)
65 if not UnitExists("mouseover") then return end
67 local line = 2
68 local wpos = line
70 local changed = false
72 while _G["GameTooltipTextLeft" .. line] and _G["GameTooltipTextLeft" .. line]:IsShown() do
73 local r, g, b, a = _G["GameTooltipTextLeft" .. line]:GetTextColor()
74 r, g, b, a = math.floor(r * 255 + 0.5), math.floor(g * 255 + 0.5), math.floor(b * 255 + 0.5), math.floor(a * 255 + 0.5)
76 if r == 255 and g == 210 and b == 0 and a == 255 then
77 --_G["GameTooltipTextLeft" .. line]:SetText("hellos")
78 changed = true
79 else
80 if line ~= wpos then
81 CopyOver(_G["GameTooltipTextLeft" .. wpos], _G["GameTooltipTextLeft" .. line])
82 CopyOver(_G["GameTooltipTextRight" .. wpos], _G["GameTooltipTextRight" .. line])
84 changed = true
85 end
87 wpos = wpos + 1
88 end
90 line = line + 1
91 end
93 if line ~= wpos then for ts = wpos, line - 1 do
94 QuestHelper: Assert(ts > 1)
96 local tt = _G["GameTooltipTextLeft" .. ts]
97 local ttr = _G["GameTooltipTextRight" .. ts]
98 local ptt = _G["GameTooltipTextLeft" .. (ts - 1)]
100 -- this . . . this is awful!
101 tt:SetText(nil)
102 ttr:SetText(nil)
103 tt:ClearAllPoints()
104 tt:SetPoint("TOPLEFT", ptt, "BOTTOMLEFT", 0, 0)
106 changed = true
107 end end
109 if changed then
110 ttp:Show()
114 QH_Hook(GameTooltip, "OnShow", function(self, ...)
115 if not self then
116 -- Some other AddOns hook this function, but don't bother to pass the values they were called with.
117 self = GameTooltip
120 if QH_filter_hints then
121 StripBlizzQHTooltipClone(self)
124 if QuestHelper and QuestHelper_Pref.tooltip then
125 -- Apparantly, sometimes InventoryOnPar invokes our tooltip function with something that doesn't have GetItem method.
126 local monster, item = self.GetUnit and self:GetUnit(), self.GetItem and self:GetItem()
128 if monster then
129 addObjectiveTip(self, "monster", monster)
132 if item then
133 addObjectiveTip(self, "item", item)
137 return real_GameTooltipOnShow(self, ...)
138 end)