whups
[QuestHelper.git] / tooltip.lua
blobfb41691d629ab4f14ef232ebcfa6d91477fcfd55
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
8 local function DoTooltip(self, data, lines)
9 local indent = 1
10 --QuestHelper:TextOut(QuestHelper:StringizeTable(data))
11 --QuestHelper:TextOut(QuestHelper:StringizeTable(lines))
12 for _, v in ipairs(lines) do
13 self:AddLine((" "):rep(indent) .. v, 1, 1, 1)
14 indent = indent + 1
15 end
16 self:AddLine((" "):rep(indent) .. data.desc, 1, 1, 1)
17 QuestHelper:AppendObjectiveProgressToTooltip(data, self, nil, indent + 1)
18 end
20 local ctts = {}
22 -- Format:
23 -- { ["monster@@1234"] = {{"Slay for blah blah blah"}, (Objective)} }
24 -- ("Slay for" is frequently an empty table)
25 function QH_Tooltip_Canned_Add(tooltips)
26 for k, v in pairs(tooltips) do
27 local typ, id = k:match("([^@]+)@@([^@]+)")
28 --[[print(k)
29 for tk, tv in pairs(v[1]) do
30 print(" ", 1, tk, tv)
31 end
32 for tk, tv in pairs(v[2]) do
33 print(" ", 2, tk, tv)
34 end]]
35 QuestHelper: Assert(typ and id, k)
36 if not ctts[typ] then ctts[typ] = {} end
37 if not ctts[typ][id] then ctts[typ][id] = {} end
38 QuestHelper: Assert(not ctts[typ][id][v[2]])
39 ctts[typ][id][v[2]] = v[1]
40 end
41 end
42 function QH_Tooltip_Canned_Remove(tooltips)
43 for k, v in pairs(tooltips) do
44 local typ, id = k:match("([^@]+)@@([^@]+)")
45 QuestHelper: Assert(typ and id, k)
46 QuestHelper: Assert(ctts[typ][id][v[2]])
47 ctts[typ][id][v[2]] = nil
49 local cleanup = true
50 for _, _ in pairs(ctts[typ][id]) do
51 cleanup = false
52 end
54 if cleanup then
55 ctts[typ][id] = nil
56 end
57 end
58 end
60 local deferences = {}
61 local deference_default = {} -- this is just a unique value that we can use to lookup
63 -- think about what we want out of this
64 -- If it matches quest/objective, we suppress it and show our canned text
65 -- If it matches quest, but has unknown objectives, we suppress it and show some synthesized "Canned thing, for Quest Blahblahblah"
67 -- tooltips is the same slay/objective pair in the above thing
68 function QH_Tooltip_Defer_Add(questname, objective, tooltips)
69 --print("defer add", questname, objective)
70 if not objective then objective = deference_default end
72 if not deferences[questname] then deferences[questname] = {} end
73 QuestHelper: Assert(not deferences[questname][objective])
74 deferences[questname][objective] = tooltips
75 if not deferences[questname][objective] then deferences[questname] = true end
76 end
77 function QH_Tooltip_Defer_Remove(questname, objective)
78 if not objective then objective = deference_default end
80 QuestHelper: Assert(deferences[questname][objective])
81 deferences[questname][objective] = nil
83 local cleanup = true
84 for _ in pairs(deferences[questname]) do
85 cleanup = false
86 end
88 if cleanup then
89 deferences[questname] = nil
90 end
91 end
93 -- 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
94 local function IsMonsterGUID(guid)
95 QuestHelper: Assert(#guid == 18, "guid len " .. guid) -- 64 bits, plus the 0x prefix
96 QuestHelper: Assert(guid:sub(1, 2) == "0x", "guid 0x-prefix " .. guid)
97 return guid:sub(5, 5) == "3" or guid:sub(5, 5) == "5"
98 end
100 local function GetMonsterType(guid)
101 QuestHelper: Assert(#guid == 18, "guid len " .. guid) -- 64 bits, plus the 0x prefix
102 QuestHelper: Assert(guid:sub(1, 2) == "0x", "guid 0x-prefix " .. guid)
103 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.
104 return tonumber(guid:sub(9, 12), 16) -- here's our actual identifier
107 local function GetItemType(link, vague)
108 return tonumber(string.match(link,
109 (vague and "" or "^") .. "|cff%x%x%x%x%x%x|Hitem:(%d+):[%d:-]+|h%[[^%]]*%]|h|r".. (vague and "" or "$")
113 local function CopyOver(to, from)
114 to:SetFont(from:GetFont())
115 to:SetFontObject(from:GetFontObject())
116 to:SetText(from:GetText())
117 to:SetTextColor(from:GetTextColor())
118 to:SetSpacing(from:GetSpacing())
119 to:SetShadowOffset(from:GetShadowOffset())
120 to:SetShadowColor(from:GetShadowColor())
121 to:Show()
124 local function StripBlizzQHTooltipClone(ttp)
125 --do return end
126 if not UnitExists("mouseover") then return end
128 local line = 2
129 local wpos = line
131 local changed = false
132 local removed = 0
134 if qh_tooltip_print_a_lot then print(line, _G["GameTooltipTextLeft" .. line], _G["GameTooltipTextLeft" .. line]:IsShown()) end
136 local qobj = nil
138 while _G["GameTooltipTextLeft" .. line] and _G["GameTooltipTextLeft" .. line]:IsShown() do
139 local r, g, b, a = _G["GameTooltipTextLeft" .. line]:GetTextColor()
140 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)
142 if qh_tooltip_print_a_lot then print(r, g, b, a) end
144 if r == 255 and g == 210 and b == 0 and a == 255 and not qh_tooltip_do_not_hide_things then
145 if qh_tooltip_print_a_lot then print("hiding") end
147 local thistext = _G["GameTooltipTextLeft" .. line]:GetText()
149 if deferences[thistext] then
150 qobj = deferences[thistext]
151 elseif qobj and qobj[thistext] then
152 DoTooltip(ttp, qobj[thistext][2], qobj[thistext][1])
155 if not qh_hackery_nosuppress then
156 _G["GameTooltipTextLeft" .. line]:SetText(nil)
157 _G["GameTooltipTextLeft" .. line]:SetHeight(0)
158 _G["GameTooltipTextLeft" .. line]:ClearAllPoints()
159 _G["GameTooltipTextLeft" .. line]:SetPoint("TOPLEFT", _G["GameTooltipTextLeft" .. (line - 1)], "BOTTOMLEFT", 0, 1)
160 changed = true
161 removed = removed + 1
165 line = line + 1
168 if changed then
169 ttp:Show()
172 return removed
175 local glob_strip = 0
176 function CreateTooltip(self)
177 glob_strip = 0
179 if QuestHelper_Pref.tooltip then
180 local inu, ilink = self:GetItem()
181 local un, ulink = self:GetUnit()
182 if ulink then ulink = UnitGUID(ulink) end
184 if ilink then
185 local ite = tostring(GetItemType(ilink))
187 if ctts["item"] and ctts["item"][ite] then
188 DoTooltip(self, ctts["item"][ite])
191 self:Show()
194 if qh_tooltip_print_a_lot then print("wut", ulink, IsMonsterGUID(ulink)) print(ulink) print(IsMonsterGUID(ulink)) end
195 if ulink and IsMonsterGUID(ulink) then
196 if qh_tooltip_print_a_lot then print("huhwuzat") print(QH_filter_hints) end
198 glob_strip = StripBlizzQHTooltipClone(self)
200 local ite = tostring(GetMonsterType(ulink))
202 if ctts["monster"] and ctts["monster"][ite] then
203 for data, lines in pairs(ctts["monster"][ite]) do
204 DoTooltip(self, data, lines)
208 self:Show()
213 local unit_to_adjust = nil
215 local ottsu = GameTooltip:GetScript("OnTooltipSetUnit")
216 QH_Hook(GameTooltip, "OnTooltipSetUnit", function (self, ...)
217 if qh_tooltip_print_a_lot then print("lol") end
218 CreateTooltip(self)
219 if ottsu then ottsu(self, ...) end
220 unit_to_adjust = self:GetUnit()
221 end, "tooltip OnTooltipSetUnit")
223 local ottsi = GameTooltip:GetScript("OnTooltipSetItem")
224 QH_Hook(GameTooltip, "OnTooltipSetItem", function (self, ...)
225 QH_Hook_NotMyFault(CreateTooltip, self)
226 if ottsi then return QH_Hook_NotMyFault(ottsi, self, ...) end
227 end, "tooltip OnTooltipSetItem")
229 local ttsx = GameTooltip:GetScript("OnUpdate")
230 QH_Hook(GameTooltip, "OnUpdate", function (self, ...)
231 if ttsx then QH_Hook_NotMyFault(ttsx, self, ...) end
232 if glob_strip and unit_to_adjust and unit_to_adjust == self:GetUnit() then
233 self:SetHeight(self:GetHeight() - glob_strip * 3) -- maaaaaagic
234 unit_to_adjust = nil
236 end, "tooltip OnUpdate")