perf scale 2, tuning
[QuestHelper.git] / tooltip.lua
blob87c9758d90a8d8a8885e46c71b3c88ae22ddc0f7
1 QuestHelper_File["tooltip.lua"] = "Development Version"
2 QuestHelper_Loadtime["tooltip.lua"] = GetTime()
4 local function DoTooltip(self, tooltipi)
5 local ct = 0
6 for data, lines in pairs(tooltipi) do
7 ct = ct + 1
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
19 --QuestHelper:TextOut(string.format("Got %d items", ct))
20 end
22 local ctts = {}
24 function QH_Tooltip_Add(tooltips)
25 for k, v in pairs(tooltips) do
26 local typ, id = k:match("([^@]+)@@([^@]+)")
27 QuestHelper: Assert(typ and id, k)
28 if not ctts[typ] then ctts[typ] = {} end
29 if not ctts[typ][id] then ctts[typ][id] = {} end
30 QuestHelper: Assert(not ctts[typ][id][v[2]])
31 ctts[typ][id][v[2]] = v[1]
32 end
33 end
34 function QH_Tooltip_Remove(tooltips)
35 for k, v in pairs(tooltips) do
36 local typ, id = k:match("([^@]+)@@([^@]+)")
37 QuestHelper: Assert(typ and id, k)
38 QuestHelper: Assert(ctts[typ][id][v[2]])
39 ctts[typ][id][v[2]] = nil
41 local cleanup = true
42 for _, _ in pairs(ctts[typ][id]) do
43 cleanup = false
44 end
46 if cleanup then
47 ctts[typ][id] = nil
48 end
49 end
50 end
52 -- 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
53 local function IsMonsterGUID(guid)
54 QuestHelper: Assert(#guid == 18, "guid len " .. guid) -- 64 bits, plus the 0x prefix
55 QuestHelper: Assert(guid:sub(1, 2) == "0x", "guid 0x-prefix " .. guid)
56 return guid:sub(5, 5) == "3" or guid:sub(5, 5) == "5"
57 end
59 local function GetMonsterType(guid)
60 QuestHelper: Assert(#guid == 18, "guid len " .. guid) -- 64 bits, plus the 0x prefix
61 QuestHelper: Assert(guid:sub(1, 2) == "0x", "guid 0x-prefix " .. guid)
62 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.
63 return tonumber(guid:sub(9, 12), 16) -- here's our actual identifier
64 end
66 local function GetItemType(link, vague)
67 return tonumber(string.match(link,
68 (vague and "" or "^") .. "|cff%x%x%x%x%x%x|Hitem:(%d+):[%d:-]+|h%[[^%]]*%]|h|r".. (vague and "" or "$")
70 end
72 local function CopyOver(to, from)
73 to:SetFont(from:GetFont())
74 to:SetFontObject(from:GetFontObject())
75 to:SetText(from:GetText())
76 to:SetTextColor(from:GetTextColor())
77 to:SetSpacing(from:GetSpacing())
78 to:SetShadowOffset(from:GetShadowOffset())
79 to:SetShadowColor(from:GetShadowColor())
80 to:Show()
81 end
83 local function StripBlizzQHTooltipClone(ttp)
84 if not UnitExists("mouseover") then return end
86 local line = 2
87 local wpos = line
89 local changed = false
90 local removed = 0
92 if qh_tooltip_print_a_lot then print(line, _G["GameTooltipTextLeft" .. line], _G["GameTooltipTextLeft" .. line]:IsShown()) end
94 while _G["GameTooltipTextLeft" .. line] and _G["GameTooltipTextLeft" .. line]:IsShown() do
95 local r, g, b, a = _G["GameTooltipTextLeft" .. line]:GetTextColor()
96 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)
98 if qh_tooltip_print_a_lot then print(r, g, b, a) end
100 if r == 255 and g == 210 and b == 0 and a == 255 and not qh_tooltip_do_not_hide_things then
101 if qh_tooltip_print_a_lot then print("hiding") end
102 --_G["GameTooltipTextLeft" .. line]:SetText("hellos")
103 _G["GameTooltipTextLeft" .. line]:SetText(nil)
104 _G["GameTooltipTextLeft" .. line]:SetHeight(0)
105 _G["GameTooltipTextLeft" .. line]:ClearAllPoints()
106 _G["GameTooltipTextLeft" .. line]:SetPoint("TOPLEFT", _G["GameTooltipTextLeft" .. (line - 1)], "BOTTOMLEFT", 0, 1)
107 changed = true
108 removed = removed + 1
111 line = line + 1
114 if changed then
115 ttp:Show()
118 return removed
121 local glob_strip = 0
122 function CreateTooltip(self)
123 glob_strip = 0
125 if QuestHelper_Pref.tooltip then
126 local inu, ilink = self:GetItem()
127 local un, ulink = self:GetUnit()
128 if ulink then ulink = UnitGUID(ulink) end
130 if ilink then
131 local ite = tostring(GetItemType(ilink))
133 if ctts["item"] and ctts["item"][ite] then
134 DoTooltip(self, ctts["item"][ite])
137 self:Show()
140 if qh_tooltip_print_a_lot then print("wut", ulink, IsMonsterGUID(ulink)) print(ulink) print(IsMonsterGUID(ulink)) end
141 if ulink and IsMonsterGUID(ulink) then
142 if qh_tooltip_print_a_lot then print("huhwuzat") print(QH_filter_hints) end
144 glob_strip = StripBlizzQHTooltipClone(self)
146 local ite = tostring(GetMonsterType(ulink))
148 if ctts["monster"] and ctts["monster"][ite] then
149 DoTooltip(self, ctts["monster"][ite])
152 self:Show()
157 local unit_to_adjust = nil
159 local ottsu = GameTooltip:GetScript("OnTooltipSetUnit")
160 QH_Hook(GameTooltip, "OnTooltipSetUnit", function (self, ...)
161 if qh_tooltip_print_a_lot then print("lol") end
162 CreateTooltip(self)
163 if ottsu then ottsu(self, ...) end
164 unit_to_adjust = self:GetUnit()
165 end, "tooltip OnTooltipSetUnit")
167 local ottsi = GameTooltip:GetScript("OnTooltipSetItem")
168 QH_Hook(GameTooltip, "OnTooltipSetItem", function (self, ...)
169 QH_Hook_NotMyFault(CreateTooltip, self)
170 if ottsi then return QH_Hook_NotMyFault(ottsi, self, ...) end
171 end, "tooltip OnTooltipSetItem")
173 local ttsx = GameTooltip:GetScript("OnUpdate")
174 QH_Hook(GameTooltip, "OnUpdate", function (self, ...)
175 if ttsx then QH_Hook_NotMyFault(ttsx, self, ...) end
176 if glob_strip and unit_to_adjust and unit_to_adjust == self:GetUnit() then
177 self:SetHeight(self:GetHeight() - glob_strip * 3) -- maaaaaagic
178 unit_to_adjust = nil
180 end, "tooltip OnUpdate")