Automated update from: http://smariot.no-ip.org/translate
[QuestHelper.git] / tooltip.lua
blobe5de1a7013d74b9b8bae746908530ccbf0bb1f45
1 QuestHelper_File["tooltip.lua"] = "Development Version"
2 QuestHelper_Loadtime["tooltip.lua"] = GetTime()
4 if QuestHelper_File["tooltip.lua"] == "Development Version" then
5 qh_hackery_nosuppress = true
6 end
10 local function DoTooltip(self, data, lines, prefix)
11 local indent = 1
13 if prefix then
14 self:AddLine((" "):rep(indent) .. prefix, 1, 1, 1)
15 indent = indent + 1
16 end
18 --QuestHelper:TextOut(QuestHelper:StringizeTable(data))
19 --QuestHelper:TextOut(QuestHelper:StringizeTable(lines))
20 for _, v in ipairs(lines) do
21 self:AddLine((" "):rep(indent) .. v, 1, 1, 1)
22 indent = indent + 1
23 end
24 self:AddLine((" "):rep(indent) .. data.desc, 1, 1, 1)
25 QuestHelper:AppendObjectiveProgressToTooltip(data, self, nil, indent + 1)
26 end
28 local function DoTooltipDefault(self, qname, text)
29 self:AddLine(" " .. QHFormat("TOOLTIP_SLAY", text), 1, 1, 1)
30 self:AddLine(" " .. QHFormat("TOOLTIP_QUEST", qname), 1, 1, 1)
31 end
33 local ctts = {}
35 -- Format:
36 -- { ["monster@@1234"] = {{"Slay for blah blah blah"}, (Objective)} }
37 -- ("Slay for" is frequently an empty table)
38 function QH_Tooltip_Canned_Add(tooltips)
39 for k, v in pairs(tooltips) do
40 local typ, id = k:match("([^@]+)@@([^@]+)")
41 --[[print(k)
42 for tk, tv in pairs(v[1]) do
43 print(" ", 1, tk, tv)
44 end
45 for tk, tv in pairs(v[2]) do
46 print(" ", 2, tk, tv)
47 end]]
48 QuestHelper: Assert(typ and id, k)
49 if not ctts[typ] then ctts[typ] = {} end
50 if not ctts[typ][id] then ctts[typ][id] = {} end
51 QuestHelper: Assert(not ctts[typ][id][v[2]])
52 ctts[typ][id][v[2]] = v[1]
53 end
54 end
55 function QH_Tooltip_Canned_Remove(tooltips)
56 for k, v in pairs(tooltips) do
57 local typ, id = k:match("([^@]+)@@([^@]+)")
58 QuestHelper: Assert(typ and id, k)
59 QuestHelper: Assert(ctts[typ][id][v[2]])
60 ctts[typ][id][v[2]] = nil
62 local cleanup = true
63 for _, _ in pairs(ctts[typ][id]) do
64 cleanup = false
65 end
67 if cleanup then
68 ctts[typ][id] = nil
69 end
70 end
71 end
73 local deferences = {}
74 local deference_default = {} -- this is just a unique value that we can use to lookup
76 -- think about what we want out of this
77 -- If it matches quest/objective, we suppress it and show our canned text
78 -- If it matches quest, but has unknown objectives, we suppress it and show some synthesized "Canned thing, for Quest Blahblahblah"
80 -- tooltips is the same slay/objective pair in the above thing
81 function QH_Tooltip_Defer_Add(questname, objective, tooltips)
82 --print("defer add", questname, objective)
83 local objo = objective
84 if not objective then objective = deference_default end
86 if not deferences[questname] then deferences[questname] = {} end
87 if not deferences[questname][objective] then deferences[questname][objective] = {} end
89 for k, v in pairs(deferences[questname][objective]) do
90 QuestHelper: Assert(v ~= tooltips)
91 end
92 table.insert(deferences[questname][objective], tooltips)
94 --print("adding", questname, objective)
95 end
96 function QH_Tooltip_Defer_Remove(questname, objective, tooltips)
97 local objo = objective
98 if not objective then objective = deference_default end
100 --print("remove", questname, objective)
101 --print("removing", questname, objective, deferences[questname][objective])
102 QuestHelper: Assert(deferences[questname][objective], string.format("%s %s %s", tostring(questname), tostring(objective), tostring(objo)))
104 local remmed = false
105 for k, v in pairs(deferences[questname][objective]) do
106 if v == tooltips then
107 table.remove(deferences[questname][objective], k)
108 remmed = true
109 break
112 QuestHelper: Assert(remmed)
114 if #deferences[questname][objective] == 0 then
115 deferences[questname][objective] = nil
118 local cleanup = true
119 for _ in pairs(deferences[questname]) do
120 cleanup = false
123 if cleanup then
124 deferences[questname] = nil
127 function QH_Tooltip_Defer_Dump()
128 for k, v in pairs(deferences) do
129 print(k)
130 for t, m in pairs(v) do
131 print(" ", t, #m)
136 -- TODO: move this into some common file, I hate that I'm duplicating them but I just want this to work. entire codebase will need a going-over soon
137 local function IsMonsterGUID(guid)
138 QuestHelper: Assert(#guid == 18, "guid len " .. guid) -- 64 bits, plus the 0x prefix
139 QuestHelper: Assert(guid:sub(1, 2) == "0x", "guid 0x-prefix " .. guid)
140 return guid:sub(5, 5) == "3" or guid:sub(5, 5) == "5"
143 local function GetMonsterType(guid)
144 QuestHelper: Assert(#guid == 18, "guid len " .. guid) -- 64 bits, plus the 0x prefix
145 QuestHelper: Assert(guid:sub(1, 2) == "0x", "guid 0x-prefix " .. guid)
146 QuestHelper: Assert(guid:sub(5, 5) == "3" or guid:sub(5, 5) == "5", "guid 3-prefix " .. guid) -- It *shouldn't* be a player or a pet by the time we've gotten here. If so, something's gone wrong.
147 if GetBuildInfo():sub(1, 3) == "3.2" then
148 return tonumber(guid:sub(9, 12), 16) -- here's our actual identifier
149 else
150 return tonumber(guid:sub(7, 10), 16) -- 3.3 and in the future, including 0.3.0
154 local function GetItemType(link, vague)
155 return tonumber(string.match(link,
156 (vague and "" or "^") .. "|cff%x%x%x%x%x%x|Hitem:(%d+):[%d:-]+|h%[[^%]]*%]|h|r".. (vague and "" or "$")
160 local function CopyOver(to, from)
161 to:SetFont(from:GetFont())
162 to:SetFontObject(from:GetFontObject())
163 to:SetText(from:GetText())
164 to:SetTextColor(from:GetTextColor())
165 to:SetSpacing(from:GetSpacing())
166 to:SetShadowOffset(from:GetShadowOffset())
167 to:SetShadowColor(from:GetShadowColor())
168 to:Show()
171 local sigil_bar = CreateFrame("Frame", GameTooltip)
172 sigil_bar:SetFrameStrata("TOOLTIP")
173 sigil_bar:SetPoint("LEFT", GameTooltip, "LEFT", 10, 0)
174 sigil_bar:SetPoint("RIGHT", GameTooltip, "RIGHT", -10, 0)
175 sigil_bar:SetHeight(0.5)
176 sigil_bar:SetFrameLevel(10)
177 sigil_bar:Hide()
179 local sigil_bar_filler = sigil_bar:CreateTexture()
180 sigil_bar_filler:SetTexture(1, 1, 1)
181 sigil_bar_filler:SetAllPoints()
183 local sigil = GameTooltip:CreateTexture()
184 sigil:SetParent(sigil_bar)
185 sigil:SetHeight(16)
186 sigil:SetWidth(16)
187 --sigil:SetPoint("CENTER", 0, 0)
188 sigil:SetTexture("Interface\\AddOns\\QuestHelper\\sigil")
189 sigil:SetPoint("TOPRIGHT", sigil_bar, "BOTTOMRIGHT", 2, -2)
190 local sigil_text
191 local sigil_item
193 local bar_split = 10
194 local bar_boost
196 local tooltip_tweaked = false
198 local function FixBlizzTooltip()
199 if not tooltip_tweaked then return end
201 assert(sigil_item)
202 for i = 1, sigil_item:GetNumPoints() do
203 local point, relative, rlpoint, x, y = sigil_item:GetPoint(i)
204 if point == "TOPLEFT" and y < -bar_split then
205 y = y + bar_split
206 sigil_item:SetPoint(point, relative, rlpoint, x, y)
210 tooltip_tweaked = false
213 local function StripBlizzQHTooltipClone(ttp)
214 --do return end
215 if not UnitExists("mouseover") then return end
218 local changed = false
219 local removed = 0
221 local qobj = nil
222 local qobj_name = nil
224 local done = QuestHelper:CreateTable("tooltip")
226 local linemax
228 local line = 2
229 while _G["GameTooltipTextLeft" .. line] and _G["GameTooltipTextLeft" .. line]:IsShown() do
230 linemax = line
231 line = line + 1
235 for line = 2, linemax do
236 local r, g, b, a = _G["GameTooltipTextLeft" .. line]:GetTextColor()
237 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)
239 if qh_tooltip_print_a_lot then print(thistext, r, g, b, a, qobj) end
241 local thistext = _G["GameTooltipTextLeft" .. line]:GetText()
242 local hideme
243 local thistextm = thistext:match(" %- (.*)")
245 --print(thistext, thistextm)
247 if r == 255 and g == 210 and b == 0 and a == 255 and deferences[thistext] then
248 qobj = deferences[thistext]
249 qobj_name = thistext
250 hideme = true
251 elseif r == 255 and g == 255 and b == 255 and a == 255 and qobj and thistextm and qobj[thistextm] then
252 if not done[qobj[thistextm]] then
253 done[qobj[thistextm]] = true -- Blizzard, why do you show duplicates of your *own quest objectives*?
254 local ite = qobj[thistextm][1]
255 QuestHelper: Assert(ite)
257 local ttsplat = thistextm:match("(.*): ([0-9]+)/([0-9]+)")
258 if ttsplat == ttp:GetUnit() then
259 ttsplat = nil
261 DoTooltip(ttp, ite[2], ite[1], ttsplat and QHFormat("TOOLTIP_SLAY", ttsplat))
262 hideme = true
264 elseif r == 255 and g == 255 and b == 255 and a == 255 and qobj and thistextm and not qobj[thistextm] and thistextm:find(":") then
265 hideme = true -- it parses as an objective, but we don't know about it, so it's probably a completed objective. todo: actually store completed objectives.
266 elseif r == 255 and g == 255 and b == 255 and a == 255 and qobj and thistextm and not thistextm:find(":") then -- Blizzard cleverly does not suppress tooltips when the user has finished getting certain items, so we do instead
267 DoTooltipDefault(ttp, qobj_name, thistextm)
268 hideme = true
271 if hideme and not qh_hackery_nosuppress then
272 _G["GameTooltipTextLeft" .. line]:SetText(nil)
273 _G["GameTooltipTextLeft" .. line]:SetHeight(0)
274 _G["GameTooltipTextLeft" .. line]:ClearAllPoints()
275 _G["GameTooltipTextLeft" .. line]:SetPoint("TOPLEFT", _G["GameTooltipTextLeft" .. (line - 1)], "BOTTOMLEFT", 0, 1)
276 changed = true
277 removed = removed + 1
281 if changed then
282 ttp:Show()
285 local qhstart = linemax + 1
286 if _G["GameTooltipTextLeft" .. qhstart] and _G["GameTooltipTextLeft" .. qhstart]:IsShown() then
287 sigil_item = _G["GameTooltipTextLeft" .. qhstart]
288 sigil_text = sigil_item:GetText()
289 local cbar = _G["GameTooltipTextLeft" .. qhstart]
290 for i = 1, cbar:GetNumPoints() do
291 local point, relative, rlpoint, x, y = cbar:GetPoint(i)
292 if point == "TOPLEFT" and y > -bar_split then
293 y = y - bar_split
294 cbar:SetPoint(point, relative, rlpoint, x, y)
295 tooltip_tweaked = true
298 sigil_bar:SetPoint("TOP", sigil_item, "TOP", 0, bar_split / 2)
299 --sigil_bar:SetParent(sigil_item)
300 --sigil:SetPoint("TOP", sigil_item, "TOP", 0, 3)
301 --sigil:SetPoint("LEFT", GameTooltip, "LEFT")
302 sigil_bar:Show()
303 bar_boost = true
307 QuestHelper:ReleaseTable(done)
309 return removed
312 local glob_strip = 0
313 function CreateTooltip(self)
314 FixBlizzTooltip()
316 glob_strip = 0
317 bar_boost = nil
319 if QuestHelper_Pref.tooltip then
320 local inu, ilink = self:GetItem()
321 local un, ulink = self:GetUnit()
322 if ulink then ulink = UnitGUID(ulink) end
324 --[[
325 if ilink then
326 local ite = tostring(GetItemType(ilink))
328 if ctts["item"] and ctts["item"][ite] then
329 DoTooltip(self, ctts["item"][ite])
332 self:Show()
333 end]]
335 if qh_tooltip_print_a_lot then print("wut", ulink, IsMonsterGUID(ulink)) print(ulink) print(IsMonsterGUID(ulink)) end
336 if ulink and IsMonsterGUID(ulink) then
337 if qh_tooltip_print_a_lot then print("huhwuzat") print(QH_filter_hints) end
339 glob_strip = StripBlizzQHTooltipClone(self) or 0
341 local ite = tostring(GetMonsterType(ulink))
343 if ctts["monster"] and ctts["monster"][ite] then
344 for data, lines in pairs(ctts["monster"][ite]) do
345 DoTooltip(self, data, lines)
349 self:Show()
354 local unit_to_adjust = nil
356 -- SmoothQuest and possibly others
357 QH_AddNotifier(GetTime() + 5, function ()
358 local ottsu = GameTooltip:GetScript("OnTooltipSetUnit")
359 QH_Hook(GameTooltip, "OnTooltipSetUnit", function (self, ...)
360 if qh_tooltip_print_a_lot then print("lol") end
361 CreateTooltip(self)
362 if ottsu then QH_Hook_NotMyFault(ottsu, self, ...) end
363 unit_to_adjust = self:GetUnit()
364 end, "tooltip OnTooltipSetUnit")
366 local ottsi = GameTooltip:GetScript("OnTooltipSetItem")
367 QH_Hook(GameTooltip, "OnTooltipSetItem", function (self, ...)
368 QH_Hook_NotMyFault(CreateTooltip, self)
369 if ottsi then return QH_Hook_NotMyFault(ottsi, self, ...) end
370 end, "tooltip OnTooltipSetItem")
372 local ttsx = GameTooltip:GetScript("OnUpdate")
373 QH_Hook(GameTooltip, "OnUpdate", function (self, ...)
374 if sigil_bar:IsShown() then
375 sigil_bar:SetAlpha(GameTooltip:GetAlpha())
376 if not (sigil_bar:IsShown() and sigil_item and sigil_item:GetText() == sigil_text) then
377 sigil_bar:Hide()
378 FixBlizzTooltip()
381 if ttsx then QH_Hook_NotMyFault(ttsx, self, ...) end
382 if (glob_strip > 0 or bar_boost) and unit_to_adjust and unit_to_adjust == self:GetUnit() then
383 self:SetHeight(self:GetHeight() - glob_strip * 3 + (bar_boost and bar_split or 0)) -- maaaaaagic
384 unit_to_adjust = nil
386 end, "tooltip OnUpdate")
387 end)