-
Notifications
You must be signed in to change notification settings - Fork 0
/
AchievementInfoSettings.lua
229 lines (196 loc) · 7.67 KB
/
AchievementInfoSettings.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
--[[
AchievementInfo
@author Asto, @Astarax
]]
-- Function to determine if Account Wide Settings should be used
function AchievementInfo.loadUseAccountWideSettings()
return ZO_SavedVars:New("ACHIEVEMENT_INFO_DB_USE_AW", 1, nil, {
enabled = false
})
end
-- Function to set and load the Saved Variables
function AchievementInfo.loadSavedVars()
local defaults = {
genEnabled = true,
genShowEveryUpdate = true,
genShowUpdateSteps = 25,
genShowDetails = false,
genShowOpenDetailsOnly = true,
genOnePerLine = true,
cat1 = true,
cat2 = true,
cat3 = true,
cat4 = true,
cat5 = true,
cat6 = true,
cat7 = true,
cat8 = true,
cat9 = true,
cat10 = true,
cat11 = true,
cat12 = true,
cat13 = true,
cat14 = true,
cat15 = true,
cat16 = true,
cat17 = true,
cat18 = true,
cat19 = true,
cat20 = true,
cat21 = true,
cat22 = true,
-- ... new one default to true
devDebug = false
}
if AchievementInfo.useAccountWideSettings["enabled"] == true then
return ZO_SavedVars:NewAccountWide("ACHIEVEMENT_INFO_DB", 1, nil, defaults)
end
return ZO_SavedVars:New("ACHIEVEMENT_INFO_DB", 1, nil, defaults)
end
-- Function to create the settings panel
function AchievementInfo.createSettingsPanel()
local panelData = {
type = "panel",
name = AchievementInfo.name,
displayName = AchievementInfo.clrDefault .. AchievementInfo.name,
author = AchievementInfo.author,
version = string.format("%.2f", AchievementInfo.version),
slashCommand = "/achievementInfo"
}
local optionsTable = {
[1] = {
type = "header",
name = AchievementInfo.clrSettingsHeader .. LANG.SettingsHeader.General
},
[2] = {
type = "checkbox",
name = LANG.SettingsOption.AddOnEnabled,
tooltip = LANG.SettingsOption.AddOnEnabledTooltip,
getFunc = function() return AchievementInfo.settingGet("genEnabled") end,
setFunc = function() AchievementInfo.settingToogle("genEnabled") end,
warning = LANG.SettingsOption.AddOnEnabledWarning
},
[3] = {
type = "checkbox",
name = LANG.SettingsOption.AccountWideEnabled,
tooltip = LANG.SettingsOption.AccountWideEnabledTooltip,
getFunc = function() return AchievementInfo.useAccountWideSettings["enabled"] end,
setFunc = function() AchievementInfo.toggleAccountWideSettings() end,
requiresReload = true
},
[4] = {
type = "checkbox",
name = LANG.SettingsOption.ShowEveryUpdate,
tooltip = LANG.SettingsOption.ShowEveryUpdateTooltip,
getFunc = function() return AchievementInfo.settingGet("genShowEveryUpdate") end,
setFunc = function() AchievementInfo.settingToogle("genShowEveryUpdate") end
},
[5] = {
type = "slider",
name = LANG.SettingsOption.ShowUpdateSteps,
tooltip = LANG.SettingsOption.ShowUpdateStepsTooltip,
min = 1,
max = 100,
step = 1,
getFunc = function() return AchievementInfo.settingGet("genShowUpdateSteps") end,
setFunc = function(value) AchievementInfo.settingSet("genShowUpdateSteps", value) end,
default = 25
},
[6] = {
type = "checkbox",
name = LANG.SettingsOption.ShowDetails,
tooltip = LANG.SettingsOption.ShowDetailsTooltip,
getFunc = function() return AchievementInfo.settingGet("genShowDetails") end,
setFunc = function() AchievementInfo.settingToogle("genShowDetails") end
},
[7] = {
type = "checkbox",
name = LANG.SettingsOption.ShowOpenDetailsOnly,
tooltip = LANG.SettingsOption.ShowOpenDetailsOnlyTooltip,
getFunc = function() return AchievementInfo.settingGet("genShowOpenDetailsOnly") end,
setFunc = function() AchievementInfo.settingToogle("genShowOpenDetailsOnly") end
},
[8] = {
type = "checkbox",
name = LANG.SettingsOption.OneElementPerLine,
tooltip = LANG.SettingsOption.OneElementPerLineTooltip,
getFunc = function() return AchievementInfo.settingGet("genOnePerLine") end,
setFunc = function() AchievementInfo.settingToogle("genOnePerLine") end,
warning = LANG.SettingsOption.OneElementPerLineWarning
},
[9] = {
type = "header",
name = AchievementInfo.clrSettingsHeader .. LANG.SettingsHeader.Categories
},
[10] = {
type = "description",
text = LANG.SettingsHeader.CategoriesDescription .. ":"
}
}
-- Add categories dynamically
local numCats = GetNumAchievementCategories()
for i = 1, numCats, 1 do
catName = GetAchievementCategoryInfo(i)
table.insert(optionsTable, {
type = "checkbox",
name = catName,
tooltip = LANG.SettingsOption.CategoryTooltip .. " '" .. catName .. "'",
getFunc = function() return AchievementInfo.settingGetForCategory("cat" .. i) end,
setFunc = function() AchievementInfo.settingToogle("cat" .. i) end
})
end
-- Debug setting at the end
table.insert(optionsTable, {
type = "header",
name = AchievementInfo.clrSettingsHeader .. LANG.SettingsHeader.Development
})
table.insert(optionsTable, {
type = "checkbox",
name = LANG.SettingsOption.DebugMode,
tooltip = LANG.SettingsOption.DebugModeTooltip,
getFunc = function() return AchievementInfo.settingGet("devDebug") end,
setFunc = function() AchievementInfo.settingToogle("devDebug") end,
warning = LANG.SettingsOption.DebugModeWarning
})
-- Register
LibAddonMenu2:RegisterAddonPanel(AchievementInfo.name .. "SettingsPanel", panelData)
LibAddonMenu2:RegisterOptionControls(AchievementInfo.name .. "SettingsPanel", optionsTable)
end
-- Function to retrieve settings
function AchievementInfo.settingGet(id)
if AchievementInfo.savedVars[id] == nil then
AchievementInfo.savedVars[id] = false
return false
else
return AchievementInfo.savedVars[id]
end
end
-- Function to retrieve settings for categories (default true)
function AchievementInfo.settingGetForCategory(id)
if AchievementInfo.savedVars[id] == nil then
AchievementInfo.savedVars[id] = true
return true
else
return AchievementInfo.savedVars[id]
end
end
-- Function to toggle Checkbox values
function AchievementInfo.settingToogle(id)
if AchievementInfo.savedVars[id] == false then
AchievementInfo.savedVars[id] = true
else
AchievementInfo.savedVars[id] = false
end
end
-- Function to toggle Checkbox value for accountWideSettings
function AchievementInfo.toggleAccountWideSettings()
if AchievementInfo.useAccountWideSettings["enabled"] == false then
AchievementInfo.useAccountWideSettings["enabled"] = true
else
AchievementInfo.useAccountWideSettings["enabled"] = false
end
end
-- Function to set settings
function AchievementInfo.settingSet(id, value)
AchievementInfo.savedVars[id] = value
end