update changes
[QuestHelper.git] / objtips.lua
blobf404fafd842ebfa7d8dbba60a8c2aa0f545bb65b
1 QuestHelper_File["objtips.lua"] = "Development Version"
2 QuestHelper_Loadtime["objtips.lua"] = GetTime()
4 local real_GameTooltipOnShow = GameTooltip:GetScript("OnShow") or QuestHelper.nop
6 local function addObjectiveObjTip(tooltip, objective, depth, already_touched)
7 if depth > 10 then return end -- fuck that, man. Just fuck that.
8 already_touched[objective] = true -- YOU CANNOT EAT A PURSE
10 if objective.watched or objective.progress then
11 local depth2 = depth
13 if objective.quest then
14 tooltip:AddLine((" "):rep(depth2)..QHFormat("TOOLTIP_QUEST", string.match(objective.quest.obj or "", "^%d*/%d*/(.*)$") or "???"), 1, 1, 1)
16 depth2 = depth2 + 1
17 end
19 if objective.progress then
20 QuestHelper:AppendObjectiveProgressToTooltip(objective, tooltip, nil, depth2)
21 else
22 tooltip:AddLine((" "):rep(depth2)..QHText("TOOLTIP_WATCHED"), unpack(QuestHelper:GetColourTheme().tooltip))
23 end
25 -- Calling Show again to cause the tooltip's dimensions to be recalculated.
26 -- Since the frame should already be shown, the OnShow event shouldn't be called again.
27 tooltip:Show()
28 end
30 if objective.used then
31 for obj, text in pairs(objective.used) do
32 if not already_touched[obj] then -- no infinite loops please
33 tooltip:AddLine((" "):rep(depth)..QHFormat(text, obj.obj), 1, 1, 1)
34 addObjectiveObjTip(tooltip, obj, depth+1, already_touched)
35 end
36 end
37 end
39 already_touched[objective] = nil -- oh why not. just so I can get a screenshot of some poor sap getting a 2^n case
40 end
42 local function addObjectiveTip(tooltip, cat, obj)
43 local list = QuestHelper.objective_objects[cat]
44 if list then
45 local objective = list[obj]
46 if objective then
47 addObjectiveObjTip(tooltip, objective, 0, {})
48 end
49 end
50 end
52 local function CopyOver(to, from)
53 to:SetFont(from:GetFont())
54 to:SetFontObject(from:GetFontObject())
55 to:SetText(from:GetText())
56 to:SetTextColor(from:GetTextColor())
57 to:SetSpacing(from:GetSpacing())
58 to:SetShadowOffset(from:GetShadowOffset())
59 to:SetShadowColor(from:GetShadowColor())
60 to:Show()
61 end
63 local function StripBlizzQHTooltipClone(ttp)
64 if not UnitExists("mouseover") then return end
66 local line = 2
67 local wpos = line
69 local changed = false
71 while _G["GameTooltipTextLeft" .. line] and _G["GameTooltipTextLeft" .. line]:IsShown() do
72 local r, g, b, a = _G["GameTooltipTextLeft" .. line]:GetTextColor()
73 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)
75 if r == 255 and g == 210 and b == 0 and a == 255 then
76 --_G["GameTooltipTextLeft" .. line]:SetText("hellos")
77 changed = true
78 else
79 if line ~= wpos then
80 CopyOver(_G["GameTooltipTextLeft" .. wpos], _G["GameTooltipTextLeft" .. line])
81 CopyOver(_G["GameTooltipTextRight" .. wpos], _G["GameTooltipTextRight" .. line])
83 changed = true
84 end
86 wpos = wpos + 1
87 end
89 line = line + 1
90 end
92 if line ~= wpos then for ts = wpos, line - 1 do
93 QuestHelper: Assert(ts > 1)
95 local tt = _G["GameTooltipTextLeft" .. ts]
96 local ttr = _G["GameTooltipTextRight" .. ts]
97 local ptt = _G["GameTooltipTextLeft" .. (ts - 1)]
99 -- this . . . this is awful!
100 tt:SetText(nil)
101 ttr:SetText(nil)
102 tt:ClearAllPoints()
103 tt:SetPoint("TOPLEFT", ptt, "BOTTOMLEFT", 0, 0)
105 changed = true
106 end end
108 if changed then
109 ttp:Show()
113 GameTooltip:SetScript("OnShow", function(self, ...)
114 if not self then
115 -- Some other AddOns hook this function, but don't bother to pass the values they were called with.
116 self = GameTooltip
119 if QH_filter_hints then
120 StripBlizzQHTooltipClone(self)
123 if QuestHelper and QuestHelper_Pref.tooltip then
124 -- Apparantly, sometimes InventoryOnPar invokes our tooltip function with something that doesn't have GetItem method.
125 local monster, item = self.GetUnit and self:GetUnit(), self.GetItem and self:GetItem()
127 if monster then
128 addObjectiveTip(self, "monster", monster)
131 if item then
132 addObjectiveTip(self, "item", item)
136 return real_GameTooltipOnShow(self, ...)
137 end)