Initial commit
[ElvUI_GearScore.git] / ElvUI_GearScore.lua
blob7f2e13923fb2064e9e5f5866101b732cdede4e03
1 local E, L = unpack(ElvUI)
2 local GS = E:NewModule("ElvUI_GearScore", "AceHook-3.0")
3 local TT = E:GetModule("Tooltip")
5 local inspectCache = {}
6 local lastGUID = nil
8 function GS:ShowInspectInfo(self, tt, unit, r, g, b)
9 local canInspect = CanInspect(unit)
10 if not canInspect then return end
12 local GUID = UnitGUID(unit)
13 if GUID == E.myguid then
14 local _, specName = E:GetTalentSpecInfo()
15 local gearScore = GS:GetGearScore("player")
16 local gsR, gsG, gsB = GearScore_GetQuality(gearScore)
18 tt:AddDoubleLine(L["Talent Specialization:"], specName, nil, nil, nil, r, g, b)
19 tt:AddDoubleLine(L["Gear Score:"], gearScore, nil, nil, nil, gsR, gsG, gsB);
20 return
21 elseif inspectCache[GUID] then
22 local specName = inspectCache[GUID].specName
23 local gearScore = inspectCache[GUID].gearScore
24 local gsR, gsG, gsB = GearScore_GetQuality(gearScore)
26 if (GetTime() - inspectCache[GUID].time) < 900 and specName and gearScore then
27 tt:AddDoubleLine(L["Talent Specialization:"], specName, nil, nil, nil, r, g, b)
28 tt:AddDoubleLine(L["Gear Score:"], gearScore, nil, nil, nil, gsR, gsG, gsB);
29 return
30 else
31 inspectCache[GUID] = nil
32 end
33 end
35 if InspectFrame and InspectFrame.unit then
36 if UnitIsUnit(InspectFrame.unit, unit) then
37 lastGUID = GUID
38 GS:INSPECT_TALENT_READY(nil, unit)
39 end
40 else
41 lastGUID = GUID
42 NotifyInspect(unit)
43 TT:RegisterEvent("INSPECT_TALENT_READY")
44 end
45 end
47 function GS:INSPECT_TALENT_READY(self, event, unit)
48 if not unit then
49 if lastGUID ~= UnitGUID("mouseover") then return end
51 TT:UnregisterEvent(event)
53 unit = "mouseover"
54 if not UnitExists(unit) then return end
55 end
57 local gearScore = GS:GetGearScore(unit)
58 local _, specName = E:GetTalentSpecInfo(true)
59 inspectCache[lastGUID] = {time = GetTime()}
61 if specName then
62 inspectCache[lastGUID].specName = specName
63 end
65 if gearScore then
66 inspectCache[lastGUID].gearScore = gearScore
67 end
69 GameTooltip:SetUnit(unit)
70 end
72 function GS:GetGearScore(unit)
73 return GearScore_GetScore(UnitName(unit), unit)
74 end
76 function GS:Initialize()
77 GS:RawHook(TT, "ShowInspectInfo")
78 GS:RawHook(TT, "INSPECT_TALENT_READY")
79 end
81 E:RegisterModule(GS:GetName())