-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hooks.lua
103 lines (93 loc) · 3.12 KB
/
Hooks.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
setfenv(1, ScoreKeeper)
LoadAddOn('Blizzard_InspectUI')
GameTooltip:HookScript('OnTooltipSetUnit', function(self)
local name, unitId = self:GetUnit()
local character, name, realm = Database:addCharacterFromUnitId(unitId)
if character then
self:AddLine(character:getScoreText())
self:Show()
end
end)
GameTooltip:HookScript("OnTooltipSetItem", function(self)
local name, link = self:GetItem()
local item = ItemObject:loadFromLink(link)
local equipLoc = ItemObject.getEquipLoc(item)
if item and equipLoc and equipLoc ~= '' then
self:AddLine(ItemObject.getScoreText(item))
self:Show()
end
end)
CharacterFrame:HookScript('OnShow', function(self)
local character = Database:addCharacterFromUnitId('player')
ScoreKeeper_CharacterScoreFrame_Text:SetText(character:getScoreText())
end)
local inspectUnitName, inspectUnitRealm
InspectFrame:HookScript('OnShow', function(self)
if InspectFrame.unit then
inspectUnitName, inspectUnitRealm = UnitName(InspectFrame.unit)
inspectUnitRealm = inspectUnitRealm or GetRealmName()
end
HideUIPanel(ScoreKeeper_InspectFrame)
local character = Database:getCharacterFromUnitId(self.unit)
ScoreKeeper_InspectCharacterScoreFrame_Text:SetText(character:getScoreText())
end)
hooksecurefunc('InspectPaperDollFrame_SetLevel', function(unit)
local unit = InspectFrame.unit
local guild = GetGuildInfo(unit)
if guild then
local PLAYER_GUILD = '<%s>'
InspectGuildText:SetFormattedText(PLAYER_GUILD, guild)
InspectGuildText:Show()
else
InspectGuildText:Hide()
end
end)
local oldInspectFrameOnUpdate = InspectFrame:GetScript('OnUpdate')
InspectFrame:SetScript('OnUpdate', function(self, ...)
local wasVisible = UnitIsVisible(self.unit)
local oldName, oldRealm = inspectUnitName, inspectUnitRealm
local res = {oldInspectFrameOnUpdate(self, ...)}
if not wasVisible
and oldName
and inspectUnitRealm
and not InspectFrame:IsShown()
then
local character = Database:getCharacter(oldName, oldRealm)
if character then
Ui:inspectCharacter(character, oldName, oldRealm)
end
end
return unpack(res)
end)
local oldInspectFrameOnEvent = InspectFrame:GetScript('OnEvent')
InspectFrame:SetScript('OnEvent', function(self, event, ...)
local wasShown = self:IsShown()
local couldInspect = false
local oldUnit = self.unit
local oldName, oldRealm = inspectUnitName, inspectUnitRealm
if self.unit then
couldInspect = CanInspect(self.unit)
end
local res = {oldInspectFrameOnEvent(self, event, ...)}
if wasShown
and (
(event == "PLAYER_TARGET_CHANGED" and oldUnit == "target")
or (event == "PARTY_MEMBERS_CHANGED" and oldUnit ~= "target")
)
and oldName
and oldRealm
then
if couldInspect then
inspectUnitName, inspectUnitRealm = UnitName(self.unit)
inspectUnitRealm = inspectUnitRealm or GetRealmName()
local character = Database:getCharacterFromUnitId(self.unit)
ScoreKeeper_InspectCharacterScoreFrame_Text:SetText(character:getScoreText())
elseif not InspectFrame:IsShown() then
local character, name, realm = Database:getCharacter(oldName, oldRealm)
if character then
Ui:inspectCharacter(character, name, realm)
end
end
end
return unpack(res)
end)