· 6 years ago · Sep 03, 2019, 05:16 AM
1local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
2local TT = E:GetModule('Tooltip')
3local Skins = E:GetModule('Skins')
4
5--Lua functions
6local _G = _G
7local unpack, select, ipairs = unpack, select, ipairs
8local wipe, tinsert, tconcat = wipe, tinsert, table.concat
9local floor, tonumber = floor, tonumber
10local strfind, format, strsub = strfind, format, strsub
11local strmatch, gmatch = strmatch, gmatch
12--WoW API / Variables
13local CanInspect = CanInspect
14local CreateFrame = CreateFrame
15local GameTooltip_ClearMoney = GameTooltip_ClearMoney
16local GetCreatureDifficultyColor = GetCreatureDifficultyColor
17local GetGuildInfo = GetGuildInfo
18local GetInspectSpecialization = GetInspectSpecialization
19local GetItemCount = GetItemCount
20local GetMouseFocus = GetMouseFocus
21local GetNumGroupMembers = GetNumGroupMembers
22local GetTime = GetTime
23local InCombatLockdown = InCombatLockdown
24local IsAltKeyDown = IsAltKeyDown
25local IsControlKeyDown = IsControlKeyDown
26local IsInGroup = IsInGroup
27local IsInRaid = IsInRaid
28local IsShiftKeyDown = IsShiftKeyDown
29local NotifyInspect = NotifyInspect
30local SetTooltipMoney = SetTooltipMoney
31local UnitAura = UnitAura
32local UnitBuff = UnitBuff
33local UnitClass = UnitClass
34local UnitClassification = UnitClassification
35local UnitCreatureType = UnitCreatureType
36local UnitExists = UnitExists
37local UnitGUID = UnitGUID
38local UnitInParty = UnitInParty
39local UnitInRaid = UnitInRaid
40local UnitIsAFK = UnitIsAFK
41local UnitIsDeadOrGhost = UnitIsDeadOrGhost
42local UnitIsDND = UnitIsDND
43local UnitIsPlayer = UnitIsPlayer
44local UnitIsPVP = UnitIsPVP
45local UnitIsTapDenied = UnitIsTapDenied
46local UnitIsUnit = UnitIsUnit
47local UnitLevel = UnitLevel
48local UnitName = UnitName
49local UnitPVPName = UnitPVPName
50local UnitRace = UnitRace
51local UnitReaction = UnitReaction
52local UnitRealmRelationship = UnitRealmRelationship
53
54-- GLOBALS: ElvUI_KeyBinder, ElvUI_ContainerFrame
55
56-- Custom to find LEVEL string on tooltip
57local LEVEL1 = _G.TOOLTIP_UNIT_LEVEL:gsub('%s?%%s%s?%-?','')
58local LEVEL2 = _G.TOOLTIP_UNIT_LEVEL_CLASS:gsub('^%%2$s%s?(.-)%s?%%1$s','%1'):gsub('^%-?г?о?%s?',''):gsub('%s?%%s%s?%-?','')
59
60local GameTooltip, GameTooltipStatusBar = _G.GameTooltip, _G.GameTooltipStatusBar
61local targetList = {}
62local TAPPED_COLOR = { r=.6, g=.6, b=.6 }
63local AFK_LABEL = " |cffFFFFFF[|r|cffFF0000"..L["AFK"].."|r|cffFFFFFF]|r"
64local DND_LABEL = " |cffFFFFFF[|r|cffFFFF00"..L["DND"].."|r|cffFFFFFF]|r"
65local keybindFrame
66
67local classification = {
68 worldboss = format("|cffAF5050 %s|r", _G.BOSS),
69 rareelite = format("|cffAF5050+ %s|r", _G.ITEM_QUALITY3_DESC),
70 elite = "|cffAF5050+|r",
71 rare = format("|cffAF5050 %s|r", _G.ITEM_QUALITY3_DESC)
72}
73
74function TT:GameTooltip_SetDefaultAnchor(tt, parent)
75 if tt:IsForbidden() then return end
76 if E.private.tooltip.enable ~= true then return end
77 if not self.db.visibility then return end
78 if tt:GetAnchorType() ~= "ANCHOR_NONE" then return end
79
80 if InCombatLockdown() and self.db.visibility.combat then
81 local modifier = self.db.visibility.combatOverride
82 if not ((modifier == 'SHIFT' and IsShiftKeyDown()) or (modifier == 'CTRL' and IsControlKeyDown()) or (modifier == 'ALT' and IsAltKeyDown())) then
83 tt:Hide()
84 return
85 end
86 end
87
88 local ownerName = tt:GetOwner() and tt:GetOwner().GetName and tt:GetOwner():GetName()
89 if (self.db.visibility.actionbars ~= 'NONE' and ownerName and (strfind(ownerName, "ElvUI_Bar") or strfind(ownerName, "ElvUI_StanceBar") or strfind(ownerName, "PetAction")) and not keybindFrame.active) then
90 local modifier = self.db.visibility.actionbars
91
92 if(modifier == 'ALL' or not ((modifier == 'SHIFT' and IsShiftKeyDown()) or (modifier == 'CTRL' and IsControlKeyDown()) or (modifier == 'ALT' and IsAltKeyDown()))) then
93 tt:Hide()
94 return
95 end
96 end
97
98 if tt.StatusBar then
99 if self.db.healthBar.statusPosition == "BOTTOM" then
100 if tt.StatusBar.anchoredToTop then
101 tt.StatusBar:ClearAllPoints()
102 tt.StatusBar:Point("TOPLEFT", tt, "BOTTOMLEFT", E.Border, -(E.Spacing * 3))
103 tt.StatusBar:Point("TOPRIGHT", tt, "BOTTOMRIGHT", -E.Border, -(E.Spacing * 3))
104 tt.StatusBar.text:Point("CENTER", tt.StatusBar, 0, 0)
105 tt.StatusBar.anchoredToTop = nil
106 end
107 else
108 if not tt.StatusBar.anchoredToTop then
109 tt.StatusBar:ClearAllPoints()
110 tt.StatusBar:Point("BOTTOMLEFT", tt, "TOPLEFT", E.Border, (E.Spacing * 3))
111 tt.StatusBar:Point("BOTTOMRIGHT", tt, "TOPRIGHT", -E.Border, (E.Spacing * 3))
112 tt.StatusBar.text:Point("CENTER", tt.StatusBar, 0, 0)
113 tt.StatusBar.anchoredToTop = true
114 end
115 end
116 end
117
118 if parent then
119 if self.db.cursorAnchor then
120 tt:SetOwner(parent, self.db.cursorAnchorType, self.db.cursorAnchorX, self.db.cursorAnchorY)
121 return
122 else
123 tt:SetOwner(parent, "ANCHOR_NONE")
124 end
125 end
126
127 local ElvUI_ContainerFrame = ElvUI_ContainerFrame
128 local RightChatPanel = _G.RightChatPanel
129 local TooltipMover = _G.TooltipMover
130 local _, anchor = tt:GetPoint()
131
132 if (anchor == nil or (ElvUI_ContainerFrame and anchor == ElvUI_ContainerFrame) or anchor == RightChatPanel or anchor == TooltipMover or anchor == _G.UIParent or anchor == E.UIParent) then
133 tt:ClearAllPoints()
134 if(not E:HasMoverBeenMoved('TooltipMover')) then
135 if ElvUI_ContainerFrame and ElvUI_ContainerFrame:IsShown() then
136 tt:Point('BOTTOMRIGHT', ElvUI_ContainerFrame, 'TOPRIGHT', 0, 18)
137 elseif RightChatPanel:GetAlpha() == 1 and RightChatPanel:IsShown() then
138 tt:Point('BOTTOMRIGHT', RightChatPanel, 'TOPRIGHT', 0, 18)
139 else
140 tt:Point('BOTTOMRIGHT', RightChatPanel, 'BOTTOMRIGHT', 0, 18)
141 end
142 else
143 local point = E:GetScreenQuadrant(TooltipMover)
144 if point == "TOPLEFT" then
145 tt:Point("TOPLEFT", TooltipMover, "BOTTOMLEFT", 1, -4)
146 elseif point == "TOPRIGHT" then
147 tt:Point("TOPRIGHT", TooltipMover, "BOTTOMRIGHT", -1, -4)
148 elseif point == "BOTTOMLEFT" or point == "LEFT" then
149 tt:Point("BOTTOMLEFT", TooltipMover, "TOPLEFT", 1, 18)
150 else
151 tt:Point("BOTTOMRIGHT", TooltipMover, "TOPRIGHT", -1, 18)
152 end
153 end
154 end
155end
156
157function TT:RemoveTrashLines(tt)
158 if tt:IsForbidden() then return end
159 for i=3, tt:NumLines() do
160 local tiptext = _G["GameTooltipTextLeft"..i]
161 local linetext = tiptext:GetText()
162
163 if(linetext == _G.PVP or linetext == _G.FACTION_ALLIANCE or linetext == _G.FACTION_HORDE) then
164 tiptext:SetText('')
165 tiptext:Hide()
166 end
167 end
168end
169
170function TT:GetLevelLine(tt, offset)
171 if tt:IsForbidden() then return end
172 for i=offset, tt:NumLines() do
173 local tipLine = _G["GameTooltipTextLeft"..i]
174 local tipText = tipLine and tipLine.GetText and tipLine:GetText()
175 if tipText and (tipText:find(LEVEL1) or tipText:find(LEVEL2)) then
176 return tipLine
177 end
178 end
179end
180
181function TT:SetUnitText(tt, unit, level, isShiftKeyDown)
182 local color
183 if UnitIsPlayer(unit) then
184 local localeClass, class = UnitClass(unit)
185 if not localeClass or not class then return end
186
187 local name = UnitName(unit)
188 local guildName, guildRankName, _, guildRealm = GetGuildInfo(unit)
189 local pvpName = UnitPVPName(unit)
190
191 color = _G.CUSTOM_CLASS_COLORS and _G.CUSTOM_CLASS_COLORS[class] or _G.RAID_CLASS_COLORS[class]
192
193 if not color then
194 color = _G.RAID_CLASS_COLORS.PRIEST
195 end
196
197 if self.db.playerTitles and pvpName then
198 name = pvpName
199 end
200
201 if UnitIsAFK(unit) then
202 name = name..AFK_LABEL
203 elseif UnitIsDND(unit) then
204 name = name..DND_LABEL
205 end
206
207 _G.GameTooltipTextLeft1:SetFormattedText("|c%s%s|r", color.colorStr, name)
208
209 local lineOffset = 2
210 if guildName then
211 if guildRealm and isShiftKeyDown then
212 guildName = guildName.."-"..guildRealm
213 end
214
215 if self.db.guildRanks then
216 _G.GameTooltipTextLeft2:SetFormattedText("<|cff00ff10%s|r> [|cff00ff10%s|r]", guildName, guildRankName)
217 else
218 _G.GameTooltipTextLeft2:SetFormattedText("<|cff00ff10%s|r>", guildName)
219 end
220
221 lineOffset = 3
222 end
223
224 local levelLine = self:GetLevelLine(tt, lineOffset)
225
226 local diffColor = GetCreatureDifficultyColor(level)
227 local race = UnitRace(unit)
228 local levelString = format("|cff%02x%02x%02x%s|r %s |c%s%s|r", diffColor.r * 255, diffColor.g * 255, diffColor.b * 255, level > 0 and level or "??", race or '', color.colorStr, localeClass)
229
230 if levelLine then
231 levelLine:SetText(levelString)
232 else
233 GameTooltip:AddLine(levelString)
234 end
235 else
236 if UnitIsTapDenied(unit) then
237 color = TAPPED_COLOR
238 else
239 local unitReaction = UnitReaction(unit, "player")
240 if E.db.tooltip.useCustomFactionColors then
241 if unitReaction then
242 color = E.db.tooltip.factionColors[unitReaction]
243 end
244 else
245 color = _G.FACTION_BAR_COLORS[unitReaction]
246 end
247 end
248
249 if not color then
250 color = _G.RAID_CLASS_COLORS.PRIEST
251 end
252 end
253
254 return color
255end
256
257local inspectGUIDCache = {}
258local inspectColorFallback = {1,1,1}
259function TT:PopulateInspectGUIDCache(unitGUID, itemLevel)
260 local specName = self:GetSpecializationInfo('mouseover')
261 if specName and itemLevel then
262 local inspectCache = inspectGUIDCache[unitGUID]
263 if inspectCache then
264 inspectCache.time = GetTime()
265 inspectCache.itemLevel = itemLevel
266 inspectCache.specName = specName
267 end
268
269 GameTooltip:AddDoubleLine(_G.SPECIALIZATION..":", specName, nil, nil, nil, unpack((inspectCache and inspectCache.unitColor) or inspectColorFallback))
270 GameTooltip:AddDoubleLine(L["Item Level:"], itemLevel, nil, nil, nil, 1, 1, 1)
271 GameTooltip:Show()
272 end
273end
274
275function TT:INSPECT_READY(event, unitGUID)
276 if UnitExists("mouseover") and UnitGUID("mouseover") == unitGUID then
277 local itemLevel, retryUnit, retryTable, iLevelDB = E:GetUnitItemLevel("mouseover")
278 if itemLevel == 'tooSoon' then
279 E:Delay(0.05, function()
280 local canUpdate = true
281 for _, x in ipairs(retryTable) do
282 local iLvl = E:GetGearSlotInfo(retryUnit, x)
283 if iLvl == 'tooSoon' then
284 canUpdate = false
285 else
286 iLevelDB[x] = iLvl
287 end
288 end
289
290 if canUpdate then
291 local calculateItemLevel = E:CalculateAverageItemLevel(iLevelDB, retryUnit)
292 TT:PopulateInspectGUIDCache(unitGUID, calculateItemLevel)
293 end
294 end)
295 else
296 TT:PopulateInspectGUIDCache(unitGUID, itemLevel)
297 end
298 end
299
300 if event then
301 self:UnregisterEvent(event)
302 end
303end
304
305function TT:GetSpecializationInfo(unit, isPlayer)
306 local spec = (isPlayer and GetSpecialization()) or (unit and GetInspectSpecialization(unit))
307 if spec and spec > 0 then
308 if isPlayer then
309 return select(2, GetSpecializationInfo(spec))
310 else
311 return select(2, GetSpecializationInfoByID(spec))
312 end
313 end
314end
315
316local lastGUID
317function TT:AddInspectInfo(tooltip, unit, numTries, r, g, b)
318 if (not unit) or (numTries > 3) or not CanInspect(unit) then return end
319
320 local unitGUID = UnitGUID(unit)
321 if not unitGUID then return end
322
323 if unitGUID == E.myguid then
324 tooltip:AddDoubleLine(_G.SPECIALIZATION..":", self:GetSpecializationInfo(unit, true), nil, nil, nil, r, g, b)
325 tooltip:AddDoubleLine(L["Item Level:"], E:GetUnitItemLevel(unit), nil, nil, nil, 1, 1, 1)
326 elseif inspectGUIDCache[unitGUID] and inspectGUIDCache[unitGUID].time then
327 local specName = inspectGUIDCache[unitGUID].specName
328 local itemLevel = inspectGUIDCache[unitGUID].itemLevel
329 if not (specName and itemLevel) or (GetTime() - inspectGUIDCache[unitGUID].time > 120) then
330 inspectGUIDCache[unitGUID].time = nil
331 inspectGUIDCache[unitGUID].specName = nil
332 inspectGUIDCache[unitGUID].itemLevel = nil
333 return E:Delay(0.33, TT.AddInspectInfo, TT, tooltip, unit, numTries + 1, r, g, b)
334 end
335
336 tooltip:AddDoubleLine(_G.SPECIALIZATION..":", specName, nil, nil, nil, r, g, b)
337 tooltip:AddDoubleLine(L["Item Level:"], itemLevel, nil, nil, nil, 1, 1, 1)
338 elseif unitGUID then
339 if not inspectGUIDCache[unitGUID] then
340 inspectGUIDCache[unitGUID] = {unitColor = {r, g, b}}
341 end
342
343 if lastGUID ~= unitGUID then
344 lastGUID = unitGUID
345 NotifyInspect(unit)
346 self:RegisterEvent("INSPECT_READY")
347 else
348 self:INSPECT_READY(nil, unitGUID)
349 end
350 end
351end
352
353function TT:GameTooltip_OnTooltipSetUnit(tt)
354 if tt:IsForbidden() then return end
355
356 local unit = select(2, tt:GetUnit())
357 local isShiftKeyDown = IsShiftKeyDown()
358 local isControlKeyDown = IsControlKeyDown()
359 local isPlayerUnit = UnitIsPlayer(unit)
360 if((tt:GetOwner() ~= _G.UIParent) and (self.db.visibility and self.db.visibility.unitFrames ~= 'NONE')) then
361 local modifier = self.db.visibility.unitFrames
362
363 if(modifier == 'ALL' or not ((modifier == 'SHIFT' and isShiftKeyDown) or (modifier == 'CTRL' and isControlKeyDown) or (modifier == 'ALT' and IsAltKeyDown()))) then
364 tt:Hide()
365 return
366 end
367 end
368
369 if not unit then
370 local GMF = GetMouseFocus()
371 if GMF and GMF.GetAttribute and GMF:GetAttribute("unit") then
372 unit = GMF:GetAttribute("unit")
373 end
374 if not unit or not UnitExists(unit) then
375 return
376 end
377 end
378
379 self:RemoveTrashLines(tt) --keep an eye on this may be buggy
380
381 local color = self:SetUnitText(tt, unit, UnitLevel(unit), isShiftKeyDown)
382
383 if not isShiftKeyDown and not isControlKeyDown then
384 local unitTarget = unit.."target"
385 if self.db.targetInfo and unit ~= "player" and UnitExists(unitTarget) then
386 local targetColor
387 if(UnitIsPlayer(unitTarget)) then
388 local _, class = UnitClass(unitTarget)
389 targetColor = _G.CUSTOM_CLASS_COLORS and _G.CUSTOM_CLASS_COLORS[class] or _G.RAID_CLASS_COLORS[class]
390 else
391 targetColor = E.db.tooltip.useCustomFactionColors and E.db.tooltip.factionColors[UnitReaction(unitTarget, "player")] or _G.FACTION_BAR_COLORS[UnitReaction(unitTarget, "player")]
392 end
393
394 tt:AddDoubleLine(format("%s:", _G.TARGET), format("|cff%02x%02x%02x%s|r", targetColor.r * 255, targetColor.g * 255, targetColor.b * 255, UnitName(unitTarget)))
395 end
396
397 if self.db.targetInfo and IsInGroup() then
398 for i = 1, GetNumGroupMembers() do
399 local groupUnit = (IsInRaid() and "raid"..i or "party"..i);
400 if (UnitIsUnit(groupUnit.."target", unit)) and (not UnitIsUnit(groupUnit,"player")) then
401 local _, class = UnitClass(groupUnit);
402 local classColor = _G.CUSTOM_CLASS_COLORS and _G.CUSTOM_CLASS_COLORS[class] or _G.RAID_CLASS_COLORS[class]
403 if not classColor then classColor = _G.RAID_CLASS_COLORS.PRIEST end
404 tinsert(targetList, format("|c%s%s|r", classColor.colorStr, UnitName(groupUnit)))
405 end
406 end
407 local numList = #targetList
408 if (numList > 0) then
409 tt:AddLine(format("%s (|cffffffff%d|r): %s", L["Targeted By:"], numList, tconcat(targetList, ", ")), nil, nil, nil, true);
410 wipe(targetList);
411 end
412 end
413 end
414
415--[[
416 if isShiftKeyDown and isPlayerUnit then
417 self:AddInspectInfo(tt, unit, 0, color.r, color.g, color.b)
418 end
419]]
420
421 -- NPC ID's
422 if unit and self.db.npcID and not isPlayerUnit then
423 local guid = UnitGUID(unit) or ""
424 local id = tonumber(guid:match("%-(%d-)%-%x-$"), 10)
425 if id then
426 tt:AddLine(("|cFFCA3C3C%s|r %d"):format(_G.ID, id))
427 end
428 end
429
430 if color then
431 tt.StatusBar:SetStatusBarColor(color.r, color.g, color.b)
432 else
433 tt.StatusBar:SetStatusBarColor(0.6, 0.6, 0.6)
434 end
435
436 local textWidth = tt.StatusBar.text:GetStringWidth()
437 if textWidth then
438 tt:SetMinimumWidth(textWidth)
439 end
440end
441
442function TT:GameTooltipStatusBar_OnValueChanged(tt, value)
443 if tt:IsForbidden() then return end
444 if not value or not self.db.healthBar.text or not tt.text then return end
445 local unit = select(2, tt:GetParent():GetUnit())
446 if(not unit) then
447 local GMF = GetMouseFocus()
448 if(GMF and GMF.GetAttribute and GMF:GetAttribute("unit")) then
449 unit = GMF:GetAttribute("unit")
450 end
451 end
452
453 local _, max = tt:GetMinMaxValues()
454 if(value > 0 and max == 1) then
455 tt.text:SetFormattedText("%d%%", floor(value * 100))
456 tt:SetStatusBarColor(TAPPED_COLOR.r, TAPPED_COLOR.g, TAPPED_COLOR.b) --most effeciant?
457 elseif(value == 0 or (unit and UnitIsDeadOrGhost(unit))) then
458 tt.text:SetText(_G.DEAD)
459 else
460 tt.text:SetText(E:ShortValue(value).." / "..E:ShortValue(max))
461 end
462end
463
464function TT:GameTooltip_OnTooltipCleared(tt)
465 if tt:IsForbidden() then return end
466 tt.itemCleared = nil
467end
468
469function TT:GameTooltip_OnTooltipSetItem(tt)
470 if tt:IsForbidden() then return end
471 local ownerName = tt:GetOwner() and tt:GetOwner().GetName and tt:GetOwner():GetName()
472 if (self.db.visibility and self.db.visibility.bags ~= 'NONE' and ownerName and (strfind(ownerName, "ElvUI_Container") or strfind(ownerName, "ElvUI_BankContainer"))) then
473 local modifier = self.db.visibility.bags
474
475 if(modifier == 'ALL' or not ((modifier == 'SHIFT' and IsShiftKeyDown()) or (modifier == 'CTRL' and IsControlKeyDown()) or (modifier == 'ALT' and IsAltKeyDown()))) then
476 tt.itemCleared = true
477 tt:Hide()
478 return
479 end
480 end
481
482 if not tt.itemCleared then
483 local _, link = tt:GetItem()
484 local num = GetItemCount(link)
485 local numall = GetItemCount(link,true)
486 local left = " "
487 local right = " "
488 local bankCount = " "
489
490 if link ~= nil and self.db.spellID then
491 left = (("|cFFCA3C3C%s|r %s"):format(_G.ID, link)):match(":(%w+)")
492 end
493
494 if self.db.itemCount == "BAGS_ONLY" then
495 right = ("|cFFCA3C3C%s|r %d"):format(L["Count"], num)
496 elseif self.db.itemCount == "BANK_ONLY" then
497 bankCount = ("|cFFCA3C3C%s|r %d"):format(L["Bank"],(numall - num))
498 elseif self.db.itemCount == "BOTH" then
499 right = ("|cFFCA3C3C%s|r %d"):format(L["Count"], num)
500 bankCount = ("|cFFCA3C3C%s|r %d"):format(L["Bank"],(numall - num))
501 end
502
503 if left ~= " " or right ~= " " then
504 tt:AddLine(" ")
505 tt:AddDoubleLine(left, right)
506 end
507 if bankCount ~= " " then
508 tt:AddDoubleLine(" ", bankCount)
509 end
510
511 tt.itemCleared = true
512 end
513end
514
515function TT:GameTooltip_AddQuestRewardsToTooltip(tt, questID)
516 if not (tt and questID and tt.pbBar and tt.pbBar.GetValue) or tt:IsForbidden() then return end
517 local cur = tt.pbBar:GetValue()
518 if cur then
519 local max, _
520 if tt.pbBar.GetMinMaxValues then
521 _, max = tt.pbBar:GetMinMaxValues()
522 end
523
524 Skins:StatusBarColorGradient(tt.pbBar, cur, max)
525 end
526end
527
528function TT:GameTooltip_ShowProgressBar(tt)
529 if not tt or tt:IsForbidden() or not tt.progressBarPool then return end
530
531 local sb = tt.progressBarPool:GetNextActive()
532 if (not sb or not sb.Bar) or sb.Bar.backdrop then return end
533
534 sb.Bar:StripTextures()
535 sb.Bar:CreateBackdrop('Transparent', nil, true)
536 sb.Bar:SetStatusBarTexture(E.media.normTex)
537
538 tt.pbBar = sb.Bar
539end
540
541function TT:GameTooltip_ShowStatusBar(tt)
542 if not tt or tt:IsForbidden() or not tt.statusBarPool then return end
543
544 local sb = tt.statusBarPool:GetNextActive()
545 if (not sb or not sb.Text) or sb.backdrop then return end
546
547 sb:StripTextures()
548 sb:CreateBackdrop(nil, nil, true)
549 sb:SetStatusBarTexture(E.media.normTex)
550end
551
552function TT:CheckBackdropColor(tt)
553 if (not tt) or tt:IsForbidden() then return end
554
555 local r, g, b = E:GetBackdropColor(tt)
556 if r and g and b then
557 r, g, b = E:Round(r, 1), E:Round(g, 1), E:Round(b, 1)
558
559 local red, green, blue = unpack(E.media.backdropfadecolor)
560 if r ~= red or g ~= green or b ~= blue then
561 tt:SetBackdropColor(red, green, blue, self.db.colorAlpha)
562 end
563 end
564end
565
566function TT:SetStyle(tt)
567 if not tt or tt:IsForbidden() then return end
568 tt:SetTemplate("Transparent", nil, true) --ignore updates
569
570 local r, g, b = E:GetBackdropColor(tt)
571 tt:SetBackdropColor(r, g, b, self.db.colorAlpha)
572end
573
574function TT:MODIFIER_STATE_CHANGED(_, key)
575 if key == "LSHIFT" or key == "RSHIFT" or key == "LCTRL" or key == "RCTRL" or key == "LALT" or key == "RALT" then
576 local owner = GameTooltip:GetOwner()
577 local notOnAuras = not (owner and owner.UpdateTooltip)
578 if notOnAuras and UnitExists("mouseover") then
579 GameTooltip:SetUnit('mouseover')
580 end
581 end
582end
583
584function TT:SetUnitAura(tt, unit, index, filter)
585 if tt:IsForbidden() then return end
586 local _, _, _, _, _, _, caster, _, _, id = UnitAura(unit, index, filter)
587
588 if id then
589 if self.db.spellID then
590 if caster then
591 local name = UnitName(caster)
592 local _, class = UnitClass(caster)
593 local color = _G.CUSTOM_CLASS_COLORS and _G.CUSTOM_CLASS_COLORS[class] or _G.RAID_CLASS_COLORS[class]
594 if not color then color = _G.RAID_CLASS_COLORS.PRIEST end
595 tt:AddDoubleLine(("|cFFCA3C3C%s|r %d"):format(_G.ID, id), format("|c%s%s|r", color.colorStr, name))
596 else
597 tt:AddLine(("|cFFCA3C3C%s|r %d"):format(_G.ID, id))
598 end
599 end
600
601 tt:Show()
602 end
603end
604
605function TT:GameTooltip_OnTooltipSetSpell(tt)
606 if tt:IsForbidden() then return end
607 local id = select(2, tt:GetSpell())
608 if not id or not self.db.spellID then return end
609
610 local displayString = ("|cFFCA3C3C%s|r %d"):format(_G.ID, id)
611 local lines = tt:NumLines()
612 local isFound
613 for i= 1, lines do
614 local line = _G[("GameTooltipTextLeft%d"):format(i)]
615 if line and line:GetText() and line:GetText():find(displayString) then
616 isFound = true;
617 break
618 end
619 end
620
621 if not isFound then
622 tt:AddLine(displayString)
623 tt:Show()
624 end
625end
626
627function TT:SetItemRef(link)
628 if strfind(link,"^spell:") and self.db.spellID then
629 local id = strsub(link,7)
630 _G.ItemRefTooltip:AddLine(("|cFFCA3C3C%s|r %d"):format(_G.ID, id))
631 _G.ItemRefTooltip:Show()
632 end
633end
634
635function TT:RepositionBNET(frame, _, anchor)
636 if anchor ~= _G.BNETMover then
637 frame:ClearAllPoints()
638 frame:Point(_G.BNETMover.anchorPoint or 'TOPLEFT', _G.BNETMover, _G.BNETMover.anchorPoint or 'TOPLEFT');
639 end
640end
641
642function TT:SetTooltipFonts()
643 local font = E.Libs.LSM:Fetch("font", E.db.tooltip.font)
644 local fontOutline = E.db.tooltip.fontOutline
645 local headerSize = E.db.tooltip.headerFontSize
646 local textSize = E.db.tooltip.textFontSize
647 local smallTextSize = E.db.tooltip.smallTextFontSize
648
649 _G.GameTooltipHeaderText:FontTemplate(font, headerSize, fontOutline)
650 _G.GameTooltipText:FontTemplate(font, textSize, fontOutline)
651 _G.GameTooltipTextSmall:FontTemplate(font, smallTextSize, fontOutline)
652 if GameTooltip.hasMoney then
653 for i = 1, GameTooltip.numMoneyFrames do
654 _G["GameTooltipMoneyFrame"..i.."PrefixText"]:FontTemplate(font, textSize, fontOutline)
655 _G["GameTooltipMoneyFrame"..i.."SuffixText"]:FontTemplate(font, textSize, fontOutline)
656 _G["GameTooltipMoneyFrame"..i.."GoldButtonText"]:FontTemplate(font, textSize, fontOutline)
657 _G["GameTooltipMoneyFrame"..i.."SilverButtonText"]:FontTemplate(font, textSize, fontOutline)
658 _G["GameTooltipMoneyFrame"..i.."CopperButtonText"]:FontTemplate(font, textSize, fontOutline)
659 end
660 end
661
662 -- Ignore header font size on DatatextTooltip
663 if _G.DatatextTooltip then
664 _G.DatatextTooltipTextLeft1:FontTemplate(font, textSize, fontOutline)
665 _G.DatatextTooltipTextRight1:FontTemplate(font, textSize, fontOutline)
666 end
667
668 --These show when you compare items ("Currently Equipped", name of item, item level)
669 --Since they appear at the top of the tooltip, we set it to use the header font size.
670 _G.ShoppingTooltip1TextLeft1:FontTemplate(font, headerSize, fontOutline)
671 _G.ShoppingTooltip1TextLeft2:FontTemplate(font, headerSize, fontOutline)
672 _G.ShoppingTooltip1TextLeft3:FontTemplate(font, headerSize, fontOutline)
673 _G.ShoppingTooltip1TextLeft4:FontTemplate(font, headerSize, fontOutline)
674 _G.ShoppingTooltip1TextRight1:FontTemplate(font, headerSize, fontOutline)
675 _G.ShoppingTooltip1TextRight2:FontTemplate(font, headerSize, fontOutline)
676 _G.ShoppingTooltip1TextRight3:FontTemplate(font, headerSize, fontOutline)
677 _G.ShoppingTooltip1TextRight4:FontTemplate(font, headerSize, fontOutline)
678 _G.ShoppingTooltip2TextLeft1:FontTemplate(font, headerSize, fontOutline)
679 _G.ShoppingTooltip2TextLeft2:FontTemplate(font, headerSize, fontOutline)
680 _G.ShoppingTooltip2TextLeft3:FontTemplate(font, headerSize, fontOutline)
681 _G.ShoppingTooltip2TextLeft4:FontTemplate(font, headerSize, fontOutline)
682 _G.ShoppingTooltip2TextRight1:FontTemplate(font, headerSize, fontOutline)
683 _G.ShoppingTooltip2TextRight2:FontTemplate(font, headerSize, fontOutline)
684 _G.ShoppingTooltip2TextRight3:FontTemplate(font, headerSize, fontOutline)
685 _G.ShoppingTooltip2TextRight4:FontTemplate(font, headerSize, fontOutline)
686end
687
688--This changes the growth direction of the toast frame depending on position of the mover
689local function PostBNToastMove(mover)
690 local x, y = mover:GetCenter();
691 local screenHeight = E.UIParent:GetTop();
692 local screenWidth = E.UIParent:GetRight()
693
694 local anchorPoint
695 if (y > (screenHeight / 2)) then
696 anchorPoint = (x > (screenWidth/2)) and "TOPRIGHT" or "TOPLEFT"
697 else
698 anchorPoint = (x > (screenWidth/2)) and "BOTTOMRIGHT" or "BOTTOMLEFT"
699 end
700 mover.anchorPoint = anchorPoint
701
702 _G.BNToastFrame:ClearAllPoints()
703 _G.BNToastFrame:Point(anchorPoint, mover)
704end
705
706function TT:Initialize()
707 self.db = E.db.tooltip
708
709 _G.BNToastFrame:Point('TOPRIGHT', _G.MMHolder, 'BOTTOMRIGHT', 0, -10);
710 E:CreateMover(_G.BNToastFrame, 'BNETMover', L["BNet Frame"], nil, nil, PostBNToastMove)
711 self:SecureHook(_G.BNToastFrame, "SetPoint", "RepositionBNET")
712
713 if E.private.tooltip.enable ~= true then return end
714 self.Initialized = true
715
716 GameTooltip.StatusBar = GameTooltipStatusBar
717 GameTooltip.StatusBar:Height(self.db.healthBar.height)
718 GameTooltip.StatusBar:SetScript("OnValueChanged", nil) -- Do we need to unset this?
719 GameTooltip.StatusBar.text = GameTooltip.StatusBar:CreateFontString(nil, "OVERLAY")
720 GameTooltip.StatusBar.text:Point("CENTER", GameTooltip.StatusBar, 0, 0)
721 GameTooltip.StatusBar.text:FontTemplate(E.Libs.LSM:Fetch("font", self.db.healthBar.font), self.db.healthBar.fontSize, self.db.healthBar.fontOutline)
722
723 --Tooltip Fonts
724 if not GameTooltip.hasMoney then
725 --Force creation of the money lines, so we can set font for it
726 SetTooltipMoney(GameTooltip, 1, nil, "", "")
727 SetTooltipMoney(GameTooltip, 1, nil, "", "")
728 GameTooltip_ClearMoney(GameTooltip)
729 end
730 self:SetTooltipFonts()
731
732 local GameTooltipAnchor = CreateFrame('Frame', 'GameTooltipAnchor', E.UIParent)
733 GameTooltipAnchor:Point('BOTTOMRIGHT', _G.RightChatToggleButton, 'BOTTOMRIGHT')
734 GameTooltipAnchor:Size(130, 20)
735 GameTooltipAnchor:SetFrameLevel(GameTooltipAnchor:GetFrameLevel() + 400)
736 E:CreateMover(GameTooltipAnchor, 'TooltipMover', L["Tooltip"], nil, nil, nil, nil, nil, 'tooltip,general')
737
738 self:SecureHook('SetItemRef')
739 self:SecureHook('GameTooltip_SetDefaultAnchor')
740 self:SecureHook(GameTooltip, 'SetUnitAura')
741 self:SecureHook(GameTooltip, 'SetUnitBuff', 'SetUnitAura')
742 self:SecureHook(GameTooltip, 'SetUnitDebuff', 'SetUnitAura')
743 self:SecureHookScript(GameTooltip, 'OnTooltipSetSpell', 'GameTooltip_OnTooltipSetSpell')
744 self:SecureHookScript(GameTooltip, 'OnTooltipCleared', 'GameTooltip_OnTooltipCleared')
745 self:SecureHookScript(GameTooltip, 'OnTooltipSetItem', 'GameTooltip_OnTooltipSetItem')
746 self:SecureHookScript(GameTooltip, 'OnTooltipSetUnit', 'GameTooltip_OnTooltipSetUnit')
747 self:SecureHookScript(GameTooltip.StatusBar, 'OnValueChanged', 'GameTooltipStatusBar_OnValueChanged')
748 self:RegisterEvent("MODIFIER_STATE_CHANGED")
749
750 --Variable is localized at top of file, then set here when we're sure the frame has been created
751 --Used to check if keybinding is active, if so then don't hide tooltips on actionbars
752 keybindFrame = ElvUI_KeyBinder
753end
754
755E:RegisterModule(TT:GetName())