-
Notifications
You must be signed in to change notification settings - Fork 1
/
Addon.lua
210 lines (181 loc) · 6.25 KB
/
Addon.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
-- Addon.lua
-- @Author : Dencer ([email protected])
-- @Link : https://dengsir.github.io
-- @Date : 5/18/2020, 11:25:23 AM
--
---@class ns
---@field Inspect Inspect
---@field Talent Talent
---@field Glyph Glyph
---@field ItemLevelCalculator ItemLevelCalculator
local ns = select(2, ...)
local ShowUIPanel = LibStub('LibShowUIPanel-1.0').ShowUIPanel
---@class UI
---@field BaseItem UI.BaseItem
---@field GearItem UI.GearItem
---@field GearFrame UI.GearFrame
---@field GemItem UI.GemItem
---@field EnchantItem UI.EnchantItem
---@field InspectFrame UI.InspectFrame
---@field InspectGearFrame UI.InspectGearFrame
---@field GlyphItem UI.GlyphItem
---@field TalentFrame UI.TalentFrame
---@field CharacterGearFrame UI.CharacterGearFrame
---@field GlyphFrame UI.GlyphFrame
---@field PaperDoll UI.PaperDoll
---@field InspectTalent UI.InspectTalent
---@field ModelFrame UI.ModelFrame
---@field SlotItem UI.SlotItem
ns.UI = {}
ns.L = LibStub('AceLocale-3.0'):GetLocale('tdInspect')
ns.VERSION = tonumber((GetAddOnMetadata('tdInspect', 'Version'):gsub('(%d+)%.?', function(x)
return format('%02d', tonumber(x))
end))) or 0
_G.BINDING_HEADER_TDINSPECT = 'tdInspect'
_G.BINDING_NAME_TDINSPECT_VIEW_TARGET = ns.L['Inspect target']
_G.BINDING_NAME_TDINSPECT_VIEW_MOUSEOVER = ns.L['Inspect mouseover']
---@class Addon: AceAddon, LibClass-2.0, AceEvent-3.0
local Addon = LibStub('AceAddon-3.0'):NewAddon('tdInspect', 'LibClass-2.0', 'AceEvent-3.0')
ns.Addon = Addon
function Addon:OnInitialize()
---@class tdInspectProfile: table
local profile = { --
global = { --
userCache = {},
},
profile = { --
characterGear = true,
inspectGear = true,
inspectCompare = true,
showTalentBackground = true,
showOptionButtonInCharacter = true,
showOptionButtonInInspect = true,
showGem = true,
showEnchant = true,
showLost = true,
},
}
---@type tdInspectProfile | AceDB.Schema
self.db = LibStub('AceDB-3.0'):New('TDDB_INSPECT2', profile, true)
if not self.db.global.version or self.db.global.version < 20000 then
wipe(self.db.global.userCache)
end
for k, v in pairs(self.db.global.userCache) do
if not v.class then
self.db.global.userCache[k] = nil
end
end
self.db.global.version = ns.VERSION
self.CharacterGearParent = CreateFrame('Frame', nil, PaperDollFrame)
self.CharacterGearParent:SetPoint('TOPLEFT', CharacterFrame, 'TOPRIGHT', -33, -12)
self.CharacterGearParent:SetSize(1, 1)
self.CharacterGearParent:SetScript('OnShow', function()
self:OpenCharacterGearFrame()
end)
self:SetupOptionFrame()
end
function Addon:OnEnable()
self:RegisterEvent('ADDON_LOADED')
self:RegisterMessage('INSPECT_READY')
self:RegisterMessage('INSPECT_TALENT_READY', 'INSPECT_READY')
self:RegisterMessage('TDINSPECT_OPTION_CHANGED')
end
function Addon:OnModuleCreated(module)
ns[module:GetName()] = module
end
function Addon:OnClassCreated(class, name)
local uiName = name:match('^UI%.(.+)$')
if uiName then
ns.UI[uiName] = class
LibStub('AceEvent-3.0'):Embed(class)
else
ns[name] = class
end
end
function Addon:SetupUI()
self.InspectFrame = ns.UI.InspectFrame:Bind(InspectFrame)
end
function Addon:ADDON_LOADED(_, addon)
if addon ~= 'Blizzard_InspectUI' then
return
end
self:SetupUI()
self:UnregisterEvent('ADDON_LOADED')
end
function Addon:INSPECT_READY(_, unit, name)
if not InspectFrame then
return
end
if unit == ns.Inspect.unit or name == ns.Inspect.unitName then
ShowUIPanel(self.InspectFrame)
end
end
function Addon:TDINSPECT_OPTION_CHANGED(_, key, value)
if key == 'characterGear' then
if value then
if self.CharacterGearParent:IsShown() then
self:OpenCharacterGearFrame()
end
elseif self.CharacterGearFrame then
if not self.db.profile.inspectCompare or not self.InspectGearFrame or not self.InspectGearFrame:IsShown() then
self.CharacterGearFrame:Hide()
end
end
elseif key == 'inspectGear' and InspectPaperDollFrame then
if value then
if InspectPaperDollFrame:IsShown() then
self:OpenInspectGearFrame()
elseif self.InspectGearFrame then
self.InspectGearFrame:Hide()
end
elseif self.InspectGearFrame then
self.InspectGearFrame:Hide()
end
elseif key == 'inspectCompare' and InspectPaperDollFrame then
if value then
if InspectPaperDollFrame:IsShown() then
self:OpenInspectGearFrame()
end
elseif self.CharacterGearFrame then
self.CharacterGearFrame:Hide()
if self.CharacterGearParent:IsShown() then
self:OpenCharacterGearFrame()
end
end
end
end
---@return UI.CharacterGearFrame
function Addon:GetCharacterGearFrame()
if not self.CharacterGearFrame then
self.CharacterGearFrame = ns.UI.CharacterGearFrame:Create(self.CharacterGearParent)
end
return self.CharacterGearFrame
end
function Addon:GetInspectGearFrame()
if not self.InspectGearFrame then
self.InspectGearFrame = ns.UI.InspectGearFrame:Create(InspectPaperDollFrame, true)
self.InspectGearFrame:SetPoint('TOPLEFT', InspectPaperDollFrame, 'TOPRIGHT', -33, -12)
end
return self.InspectGearFrame
end
function Addon:OpenCharacterGearFrame()
if self.db.profile.characterGear then
local characterGearFrame = self:GetCharacterGearFrame()
if characterGearFrame:IsShown() then
return
end
characterGearFrame:TapTo(self.CharacterGearParent, 'TOPLEFT')
characterGearFrame:Show()
end
end
function Addon:OpenInspectGearFrame()
if self.db.profile.inspectGear then
local inspectGearFrame = self:GetInspectGearFrame()
inspectGearFrame:Show()
if self.db.profile.inspectCompare then
local characterGearFrame = self:GetCharacterGearFrame()
characterGearFrame:TapTo(inspectGearFrame, 'TOPLEFT', inspectGearFrame, 'TOPRIGHT', 0, 0)
characterGearFrame:Show()
end
end
end