forked from ElvUI-WotLK/ElvUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInit.lua
403 lines (338 loc) · 13.6 KB
/
Init.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
--[[
~AddOn Engine~
To load the AddOn engine add this to the top of your file:
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
]]
--Lua functions
local _G, min, pairs, strsplit, unpack, wipe, type, tcopy = _G, min, pairs, strsplit, unpack, wipe, type, table.copy
--WoW API / Variables
local hooksecurefunc = hooksecurefunc
local CreateFrame = CreateFrame
local GetAddOnInfo = GetAddOnInfo
local GetAddOnMetadata = GetAddOnMetadata
local GetTime = GetTime
local HideUIPanel = HideUIPanel
local InCombatLockdown = InCombatLockdown
local IsAddOnLoaded = IsAddOnLoaded
local LoadAddOn = LoadAddOn
local ReloadUI = ReloadUI
local ERR_NOT_IN_COMBAT = ERR_NOT_IN_COMBAT
local GameMenuButtonLogout = GameMenuButtonLogout
local GameMenuFrame = GameMenuFrame
BINDING_HEADER_ELVUI = GetAddOnMetadata(..., "Title")
local AceAddon, AceAddonMinor = LibStub("AceAddon-3.0")
local CallbackHandler = LibStub("CallbackHandler-1.0")
local AddOnName, Engine = ...
local AddOn = AceAddon:NewAddon(AddOnName, "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0", "AceHook-3.0")
AddOn.callbacks = AddOn.callbacks or CallbackHandler:New(AddOn)
AddOn.DF = {profile = {}, global = {}}; AddOn.privateVars = {profile = {}} -- Defaults
AddOn.Options = {type = "group", name = AddOnName, args = {}}
Engine[1] = AddOn
Engine[2] = {}
Engine[3] = AddOn.privateVars.profile
Engine[4] = AddOn.DF.profile
Engine[5] = AddOn.DF.global
_G[AddOnName] = Engine
do
AddOn.Libs = {}
AddOn.LibsMinor = {}
function AddOn:AddLib(name, major, minor)
if not name then return end
-- in this case: `major` is the lib table and `minor` is the minor version
if type(major) == "table" and type(minor) == "number" then
self.Libs[name], self.LibsMinor[name] = major, minor
else -- in this case: `major` is the lib name and `minor` is the silent switch
self.Libs[name], self.LibsMinor[name] = LibStub(major, minor)
end
end
AddOn:AddLib("AceAddon", AceAddon, AceAddonMinor)
AddOn:AddLib("AceDB", "AceDB-3.0")
AddOn:AddLib("EP", "LibElvUIPlugin-1.0")
AddOn:AddLib("LSM", "LibSharedMedia-3.0")
AddOn:AddLib("ACL", "AceLocale-3.0-ElvUI")
AddOn:AddLib("LAB", "LibActionButton-1.0-ElvUI")
AddOn:AddLib("LAI", "LibAuraInfo-1.0-ElvUI", true)
AddOn:AddLib("LBF", "LibButtonFacade", true)
AddOn:AddLib("LDB", "LibDataBroker-1.1")
AddOn:AddLib("DualSpec", "LibDualSpec-1.0")
AddOn:AddLib("SimpleSticky", "LibSimpleSticky-1.0")
AddOn:AddLib("SpellRange", "SpellRange-1.0")
AddOn:AddLib("ItemSearch", "LibItemSearch-1.2-ElvUI")
AddOn:AddLib("Compress", "LibCompress")
AddOn:AddLib("Base64", "LibBase64-1.0-ElvUI")
AddOn:AddLib("Translit", "LibTranslit-1.0")
-- added on ElvUI_OptionsUI load: AceGUI, AceConfig, AceConfigDialog, AceConfigRegistry, AceDBOptions
-- backwards compatible for plugins
AddOn.LSM = AddOn.Libs.LSM
AddOn.Masque = AddOn.Libs.Masque
end
AddOn.oUF = Engine.oUF
AddOn.ActionBars = AddOn:NewModule("ActionBars","AceHook-3.0","AceEvent-3.0")
AddOn.AFK = AddOn:NewModule("AFK","AceEvent-3.0","AceTimer-3.0")
AddOn.Auras = AddOn:NewModule("Auras","AceHook-3.0","AceEvent-3.0")
AddOn.Bags = AddOn:NewModule("Bags","AceHook-3.0","AceEvent-3.0","AceTimer-3.0")
AddOn.Blizzard = AddOn:NewModule("Blizzard","AceEvent-3.0","AceHook-3.0")
AddOn.Chat = AddOn:NewModule("Chat","AceTimer-3.0","AceHook-3.0","AceEvent-3.0")
AddOn.DataBars = AddOn:NewModule("DataBars","AceEvent-3.0")
AddOn.DataTexts = AddOn:NewModule("DataTexts","AceTimer-3.0","AceHook-3.0","AceEvent-3.0")
AddOn.DebugTools = AddOn:NewModule("DebugTools","AceEvent-3.0","AceHook-3.0")
AddOn.Distributor = AddOn:NewModule("Distributor","AceEvent-3.0","AceTimer-3.0","AceComm-3.0","AceSerializer-3.0")
AddOn.Layout = AddOn:NewModule("Layout","AceEvent-3.0")
AddOn.Minimap = AddOn:NewModule("Minimap","AceEvent-3.0")
AddOn.Misc = AddOn:NewModule("Misc","AceEvent-3.0","AceTimer-3.0")
AddOn.ModuleCopy = AddOn:NewModule("ModuleCopy","AceEvent-3.0","AceTimer-3.0","AceComm-3.0","AceSerializer-3.0")
AddOn.NamePlates = AddOn:NewModule("NamePlates","AceHook-3.0","AceEvent-3.0","AceTimer-3.0")
AddOn.PluginInstaller = AddOn:NewModule("PluginInstaller")
AddOn.RaidUtility = AddOn:NewModule("RaidUtility","AceEvent-3.0")
AddOn.ReminderBuffs = AddOn:NewModule("ReminderBuffs", "AceEvent-3.0")
AddOn.Skins = AddOn:NewModule("Skins","AceTimer-3.0","AceHook-3.0","AceEvent-3.0")
AddOn.Threat = AddOn:NewModule("Threat","AceEvent-3.0")
AddOn.Tooltip = AddOn:NewModule("Tooltip","AceTimer-3.0","AceHook-3.0","AceEvent-3.0")
AddOn.TotemBar = AddOn:NewModule("Totems","AceEvent-3.0")
AddOn.UnitFrames = AddOn:NewModule("UnitFrames","AceTimer-3.0","AceEvent-3.0","AceHook-3.0")
AddOn.WorldMap = AddOn:NewModule("WorldMap","AceHook-3.0","AceEvent-3.0","AceTimer-3.0")
AddOn.OptionsModule = AddOn:NewModule("Options")
do
local arg2, arg3 = "([%(%)%.%%%+%-%*%?%[%^%$])", "%%%1"
function AddOn:EscapeString(str)
return gsub(str, arg2, arg3)
end
end
do
DisableAddOn("ElvUI_EverySecondCounts")
DisableAddOn("ElvUI_FogOfWar")
DisableAddOn("ElvUI_VisualAuraTimers")
DisableAddOn("ElvUI_MinimapButtons")
DisableAddOn("ElvUI_ChannelAlerts")
end
function AddOn:OnInitialize()
if not ElvCharacterDB then
ElvCharacterDB = {}
end
self.db = tcopy(self.DF.profile, true)
self.global = tcopy(self.DF.global, true)
if ElvDB then
if ElvDB.global then
self:CopyTable(self.global, ElvDB.global)
end
local profileKey
if ElvDB.profileKeys then
profileKey = ElvDB.profileKeys[self.myname.." - "..self.myrealm]
end
if profileKey and ElvDB.profiles and ElvDB.profiles[profileKey] then
self:CopyTable(self.db, ElvDB.profiles[profileKey])
end
end
self.private = tcopy(self.privateVars.profile, true)
if ElvPrivateDB then
local profileKey
if ElvPrivateDB.profileKeys then
profileKey = ElvPrivateDB.profileKeys[self.myname.." - "..self.myrealm]
end
if profileKey and ElvPrivateDB.profiles and ElvPrivateDB.profiles[profileKey] then
self:CopyTable(self.private, ElvPrivateDB.profiles[profileKey])
end
end
self.twoPixelsPlease = false
self.ScanTooltip = CreateFrame("GameTooltip", "ElvUI_ScanTooltip", _G.UIParent, "GameTooltipTemplate")
self.PixelMode = self.twoPixelsPlease or self.private.general.pixelPerfect -- keep this over `UIScale`
self:UIScale(true)
self:UpdateMedia()
self:CheckRole()
self:RegisterEvent("UPDATE_FLOATING_CHAT_WINDOWS", "PixelScaleChanged")
self:RegisterEvent("PLAYER_REGEN_DISABLED")
self:Contruct_StaticPopups()
self:InitializeInitialModules()
if IsAddOnLoaded("Tukui") then
self:StaticPopup_Show("TUKUI_ELVUI_INCOMPATIBLE")
end
local GameMenuButton = CreateFrame("Button", "ElvUI_MenuButton", GameMenuFrame, "GameMenuButtonTemplate")
GameMenuButton:SetText(self.title)
GameMenuButton:SetScript("OnClick", function()
AddOn:ToggleOptionsUI()
HideUIPanel(GameMenuFrame)
end)
GameMenuFrame[AddOnName] = GameMenuButton
GameMenuButton:Size(GameMenuButtonLogout:GetWidth(), GameMenuButtonLogout:GetHeight())
GameMenuButtonRatings:HookScript("OnShow", function(self)
GameMenuFrame:SetHeight(GameMenuFrame:GetHeight() + self:GetHeight())
end)
GameMenuButtonRatings:HookScript("OnHide", function(self)
GameMenuFrame:SetHeight(GameMenuFrame:GetHeight() - self:GetHeight())
end)
GameMenuFrame:HookScript("OnShow", function()
if not GameMenuFrame.isElvUI then
GameMenuFrame:SetHeight(GameMenuFrame:GetHeight() + GameMenuButtonLogout:GetHeight() + 1)
GameMenuFrame.isElvUI = true
end
local _, relTo = GameMenuButtonLogout:GetPoint()
if relTo ~= GameMenuFrame[AddOnName] then
GameMenuFrame[AddOnName]:ClearAllPoints()
GameMenuFrame[AddOnName]:Point("TOPLEFT", relTo, "BOTTOMLEFT", 0, -1)
GameMenuButtonLogout:ClearAllPoints()
GameMenuButtonLogout:Point("TOPLEFT", GameMenuFrame[AddOnName], "BOTTOMLEFT", 0, -16)
end
end)
self.loadedtime = GetTime()
end
local LoadUI = CreateFrame("Frame")
LoadUI:RegisterEvent("PLAYER_LOGIN")
LoadUI:SetScript("OnEvent", function()
AddOn.Masque = AddOn.Masque or LibStub("Masque", true)
AddOn:Initialize()
end)
function AddOn:PLAYER_REGEN_ENABLED()
self:ToggleOptionsUI()
self:UnregisterEvent("PLAYER_REGEN_ENABLED")
end
function AddOn:PLAYER_REGEN_DISABLED()
local err
local ACD = self.Libs.AceConfigDialog
if ACD and ACD.OpenFrames and ACD.OpenFrames[AddOnName] then
self:RegisterEvent("PLAYER_REGEN_ENABLED")
ACD:Close(AddOnName)
err = true
end
if self.CreatedMovers then
for name in pairs(self.CreatedMovers) do
local mover = _G[name]
if mover and mover:IsShown() then
mover:Hide()
err = true
end
end
end
if err then
self:Print(ERR_NOT_IN_COMBAT)
end
end
function AddOn:ResetProfile()
local profileKey
if ElvPrivateDB.profileKeys then
profileKey = ElvPrivateDB.profileKeys[self.myname.." - "..self.myrealm]
if profileKey and ElvPrivateDB.profiles and ElvPrivateDB.profiles[profileKey] then
ElvPrivateDB.profiles[profileKey] = nil
end
end
ElvCharacterDB = nil
self.data:_ResetProfile()
ReloadUI()
end
function AddOn:OnProfileReset()
AddOn:StaticPopup_Show("RESET_PROFILE_PROMPT")
end
function AddOn:ResetConfigSettings()
AddOn.configSavedPositionTop, AddOn.configSavedPositionLeft = nil, nil
AddOn.global.general.AceGUI = AddOn:CopyTable({}, AddOn.DF.global.general.AceGUI)
end
function AddOn:GetConfigPosition()
return AddOn.configSavedPositionTop, AddOn.configSavedPositionLeft
end
function AddOn:GetConfigSize()
return AddOn.global.general.AceGUI.width, AddOn.global.general.AceGUI.height
end
function AddOn:UpdateConfigSize(reset)
local frame = self.GUIFrame
if not frame then return end
local maxWidth, maxHeight = self.UIParent:GetSize()
frame:SetMinResize(600, 500)
frame:SetMaxResize(maxWidth-50, maxHeight-50)
self.Libs.AceConfigDialog:SetDefaultSize(AddOnName, self:GetConfigDefaultSize())
local status = frame.obj and frame.obj.status
if status then
if reset then
self:ResetConfigSettings()
status.top, status.left = self:GetConfigPosition()
status.width, status.height = self:GetConfigDefaultSize()
frame.obj:ApplyStatus()
else
local top, left = self:GetConfigPosition()
if top and left then
status.top, status.left = top, left
frame.obj:ApplyStatus()
end
end
end
end
function AddOn:GetConfigDefaultSize()
local width, height = AddOn:GetConfigSize()
local maxWidth, maxHeight = AddOn.UIParent:GetSize()
width, height = min(maxWidth - 50, width), min(maxHeight - 50, height)
return width, height
end
function AddOn:ConfigStopMovingOrSizing()
if self.obj and self.obj.status then
AddOn.configSavedPositionTop, AddOn.configSavedPositionLeft = AddOn:Round(self:GetTop(), 2), AddOn:Round(self:GetLeft(), 2)
AddOn.global.general.AceGUI.width, AddOn.global.general.AceGUI.height = AddOn:Round(self:GetWidth(), 2), AddOn:Round(self:GetHeight(), 2)
end
end
local pageNodes = {}
function AddOn:ToggleOptionsUI(msg)
if InCombatLockdown() then
self:Print(ERR_NOT_IN_COMBAT)
self:RegisterEvent("PLAYER_REGEN_ENABLED")
return
end
local ACD = self.Libs.AceConfigDialog
local ConfigOpen = ACD and ACD.OpenFrames and ACD.OpenFrames[AddOnName]
local pages, msgStr
if msg and msg ~= "" then
pages = {strsplit(",", msg)}
msgStr = gsub(msg, ",","\001")
end
local mode = "Close"
if not ConfigOpen or (pages ~= nil) then
if pages ~= nil then
local pageCount, index, mainSel = #pages
if pageCount > 1 then
wipe(pageNodes)
index = 0
local main, mainNode, mainSelStr, sub, subNode, subSel
for i = 1, pageCount do
if i == 1 then
main = pages[i] and ACD and ACD.Status and ACD.Status.ElvUI
mainSel = main and main.status and main.status.groups and main.status.groups.selected
mainSelStr = mainSel and ("^"..self:EscapeString(mainSel).."\001")
mainNode = main and main.children and main.children[pages[i]]
pageNodes[index + 1], pageNodes[index + 2] = main, mainNode
else
sub = pages[i] and pageNodes[i] and ((i == pageCount and pageNodes[i]) or pageNodes[i].children[pages[i]])
subSel = sub and sub.status and sub.status.groups and sub.status.groups.selected
subNode = (mainSelStr and msgStr:match(mainSelStr..self:EscapeString(pages[i]).."$") and (subSel and subSel == pages[i])) or ((i == pageCount and not subSel) and mainSel and mainSel == msgStr)
pageNodes[index + 1], pageNodes[index + 2] = sub, subNode
end
index = index + 2
end
else
local main = pages[1] and ACD and ACD.Status and ACD.Status.ElvUI
mainSel = main and main.status and main.status.groups and main.status.groups.selected
end
if ConfigOpen and ((not index and mainSel and mainSel == msg) or (index and pageNodes and pageNodes[index])) then
mode = "Close"
else
mode = "Open"
end
else
mode = "Open"
end
end
if ACD then
ACD[mode](ACD, AddOnName)
end
if mode == "Open" then
ConfigOpen = ACD and ACD.OpenFrames and ACD.OpenFrames[AddOnName]
if ConfigOpen then
local frame = ConfigOpen.frame
if frame and not self.GUIFrame then
self.GUIFrame = frame
ElvUIGUIFrame = self.GUIFrame
self:UpdateConfigSize()
hooksecurefunc(frame, "StopMovingOrSizing", AddOn.ConfigStopMovingOrSizing)
end
end
if ACD and pages then
ACD:SelectGroup(AddOnName, unpack(pages))
end
end
GameTooltip:Hide() --Just in case you're mouseovered something and it closes.
end