-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfig.lua
155 lines (140 loc) · 4.7 KB
/
Config.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
---@class WBL
local _, WBL = ...
-- Localize global functions
local ipairs = ipairs
local pairs = pairs
local type = type
local rawset = rawset
local setmetatable = setmetatable
WBL.db = {}
WBL.db.defaults = {
xPos = 0,
yPos = 0,
relativePoint = "CENTER",
height = 300,
width = 500,
timeFormat = 5,
autoOpen = false,
autoClose = false,
minimap = {
enable = true,
}
}
WBL.timeFormats = {
"%H:%M", --20:16
"%I:%M %p", --08:16 AM
"%X", --20:16:41
"%I:%M:%S %p", --08:16:41 AM
"%c", --Thu Nov 28 20:16:41 2024
"%x %X", --11/28/24 20:16:41
"%m/%d/%Y %H:%M:%S", --11/28/2024 20:16:41
"%b %d %Y %X", --Nov 28 2024 20:16:41
"%d %b %Y %X", --28 Nov 2024 20:16:41
"%Y-%m-%d %H:%M:%S", --2024-11-28 20:16:41
}
local function copyTable(source)
local copy = {}
if type(source) == "table" then
for key, value in pairs(source) do
if type(value) == "table" then
value = copyTable(value)
end
copy[key] = value
end
end
return copy
end
local function setDefaults(defaults, settings)
settings = settings or {}
local mt = {}
mt.__index = {}
for key, value in pairs(defaults) do
if type(value) == "table" then
settings[key] = setDefaults(defaults[key], settings[key])
else
rawset(mt.__index, key, value)
end
end
setmetatable(settings, mt)
return settings
end
local function removeDefaults(settings, defaults)
if type(settings) == "table" then
for key, value in pairs(settings) do
if type(value) == "table" then
removeDefaults(value, defaults[key])
elseif value == defaults[key] then
settings[key] = nil
end
end
end
end
function WBL:LoadDB()
WarbandBankLogSettings = WarbandBankLogSettings or {}
WBL.db.settings = {}
if WarbandBankLogSettings.profiles then
--Move AceDB settings to new setup
WBL.db.settings = copyTable(WarbandBankLogSettings.profiles.Default)
else
WBL.db.settings = copyTable(WarbandBankLogSettings)
end
WBL.db.settings = setDefaults(WBL.db.defaults, WBL.db.settings)
end
function WBL:UnloadDB()
WarbandBankLogSettings = {}
removeDefaults(WBL.db.settings, WBL.db.defaults)
WarbandBankLogSettings = copyTable(WBL.db.settings)
end
function WBL:GenerateSettingsMenu(frame)
local function SettingsMenu(frame, rootDescription)
rootDescription:SetTag("WarbandBankLog_Settings_Menu")
frame.settings = {}
frame.settings.autoOpen = rootDescription:CreateCheckbox("Auto Open with Bank",
function() --Getter function
return WBL.db.settings.autoOpen
end,
function() --Setter function
WBL.db.settings.autoOpen = not WBL.db.settings.autoOpen
end
)
frame.settings.autoClose = rootDescription:CreateCheckbox("Auto Close with Bank",
function() --Getter function
return WBL.db.settings.autoClose
end,
function() --Setter function
WBL.db.settings.autoClose = not WBL.db.settings.autoClose
end
)
frame.settings.minimap = rootDescription:CreateCheckbox("Minimap Icon",
function() --Getter function
return WBL.db.settings.minimap.enable
end,
function() --Setter function
WBL.db.settings.minimap.enable = not WBL.db.settings.minimap.enable
WBL:MinimapHandler(WBL.db.settings.minimap.enable)
end
)
frame.settings.timeFormat = rootDescription:CreateButton("Time Format", function() end)
local function IsSelected(index)
return index == WBL.db.settings.timeFormat
end
local function SetSelected(index)
WBL.db.settings.timeFormat = index
if #WBL.Logs > 0 then
WBL.DataProvider:Flush()
WBL.DataProvider:InsertTable(WBL.Logs)
end
WBL.Display.BaseFrame.Container.ScrollBox:SetScrollPercentage(100)
end
frame.settings.timeFormat.options = {}
for index, format in ipairs(WBL.timeFormats) do
frame.settings.timeFormat.options[index] = frame.settings.timeFormat:CreateRadio(date(format, 1732849485), IsSelected, SetSelected, index)
end
end
WBL.Display.Menu = MenuUtil.CreateContextMenu(frame, SettingsMenu)
end
function WarbandBankLog_OnAddonCompartmentClick(addonName, button)
if (button == "LeftButton") then
WBL_API:Toggle()
end
end