forked from Snsei987/SenseiClassResourceBar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSenseiClassResourceBar.lua
More file actions
71 lines (57 loc) · 2.3 KB
/
SenseiClassResourceBar.lua
File metadata and controls
71 lines (57 loc) · 2.3 KB
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
local addonName, addonTable = ...
------------------------------------------------------------
-- BAR FACTORY
------------------------------------------------------------
local function CreateBarInstance(config, parent, frameLevel)
-- Initialize database
if not SenseiClassResourceBarDB[config.dbName] then
SenseiClassResourceBarDB[config.dbName] = {}
end
-- Create frame
local bar = CreateFromMixins(config.mixin or addonTable.BarMixin)
bar:Init(config, parent, frameLevel)
-- Copy defaults if needed
local curLayout = addonTable.LEM.GetActiveLayoutName() or "Default"
if not SenseiClassResourceBarDB[config.dbName][curLayout] then
SenseiClassResourceBarDB[config.dbName][curLayout] = CopyTable(bar.defaults)
end
bar:OnLoad()
bar:GetFrame():SetScript("OnEvent", function(_, ...)
bar:OnEvent(...)
end)
bar:ApplyVisibilitySettings()
bar:ApplyLayout(true)
bar:UpdateDisplay(true)
return bar
end
------------------------------------------------------------
-- INITIALIZE BARS
------------------------------------------------------------
local function InitializeBar(config, frameLevel)
local bar = CreateBarInstance(config, UIParent, math.max(0, frameLevel or 0))
local defaults = CopyTable(addonTable.commonDefaults)
for k, v in pairs(config.defaultValues or {}) do
defaults[k] = v
end
local LEMSettingsLoader = CreateFromMixins(addonTable.LEMSettingsLoaderMixin)
LEMSettingsLoader:Init(bar, defaults)
LEMSettingsLoader:LoadSettings()
return bar
end
local SCRB = CreateFrame("Frame")
SCRB:RegisterEvent("ADDON_LOADED")
SCRB:SetScript("OnEvent", function(_, event, arg1)
if event == "ADDON_LOADED" and arg1 == addonName then
if not SenseiClassResourceBarDB then
SenseiClassResourceBarDB = {}
end
addonTable.barInstances = addonTable.barInstances or {}
for _, config in pairs(addonTable.RegisteredBar or {}) do
if config.loadPredicate == nil or (type(config.loadPredicate) == "function" and config.loadPredicate(config) == true) then
local frame = InitializeBar(config, config.frameLevel or 1)
addonTable.barInstances[config.frameName] = frame
end
end
addonTable.SettingsRegistrar()
end
end)