-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddonSettings.lua
145 lines (129 loc) · 6.43 KB
/
AddonSettings.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
--- @class (partial) CustomAbilityIcons
local CustomAbilityIcons = CustomAbilityIcons
local LAM2 = LibAddonMenu2
--- Initializes saved variables and configures their corresponding menus, using LibAddonMenu2 (if it exists).
function CustomAbilityIcons.InitializeSettings()
CustomAbilityIcons.CONFIG = ZO_SavedVars:NewAccountWide("CustomAbilityIcons_SavedVariables", CustomAbilityIcons.SAVEDVARIABLES_VERSION, nil, CustomAbilityIcons.DEFAULT_ADDON_CONFIG)
CustomAbilityIcons.CleanupAccountWideSettings(CustomAbilityIcons_SavedVariables, CustomAbilityIcons.DEFAULT_ADDON_CONFIG, nil)
CustomAbilityIcons.GLOBALSETTINGS = ZO_SavedVars:NewAccountWide("CustomAbilityIcons_Globals", CustomAbilityIcons.SAVEDVARIABLES_VERSION, "global_settings", CustomAbilityIcons.DEFAULT_SETTINGS)
CustomAbilityIcons.CleanupAccountWideSettings(CustomAbilityIcons_Globals, CustomAbilityIcons.DEFAULT_SETTINGS, "global_settings")
CustomAbilityIcons.CHARACTERSETTINGS = ZO_SavedVars:NewCharacterIdSettings("CustomAbilityIcons_Settings", CustomAbilityIcons.SAVEDVARIABLES_VERSION, "character_settings", CustomAbilityIcons.DEFAULT_SETTINGS)
CustomAbilityIcons.CleanupCharacterIdSettings(CustomAbilityIcons_Settings, CustomAbilityIcons.DEFAULT_SETTINGS, "character_settings")
if LAM2 == nil then return end
local panelData = {
type = "panel",
name = "Custom Ability Icons",
displayName = "Custom Ability Icons",
author = "Vartalus & Iresil",
version = CustomAbilityIcons.version,
slashCommand = "/caigb", -- (optional) will register a keybind to open to this panel
registerForRefresh = true, -- boolean (optional) (will refresh all options controls when a setting is changed and when the panel is shown)
registerForDefaults = true -- boolean (optional) (will set all options controls back to default values)
}
LAM2:RegisterAddonPanel("CustomAbilityIcons_Panel", panelData)
local optionsData = {
{
type = "header",
name = "Settings",
},
{
type = "checkbox",
name = "Use the same settings for all characters",
getFunc = function()
return CustomAbilityIcons.CONFIG.saveSettingsGlobally
end,
setFunc = CustomAbilityIcons.SetOptionGlobalIcons
},
{
type = "checkbox",
name = "Use Skill Style Icons on ability bar",
getFunc = function()
return CustomAbilityIcons:GetSettings().showSkillStyleIcons
end,
setFunc = CustomAbilityIcons.SetOptionSkillStyleIcons
},
{
type = "checkbox",
name = "Use Custom Scribed Ability Icons on ability bar",
getFunc = function()
return CustomAbilityIcons:GetSettings().showCustomScribeIcons
end,
setFunc = CustomAbilityIcons.SetOptionCustomIcons
},
{
type = "checkbox",
name = "Replace mismatched Base Ability Icons",
getFunc = function()
return CustomAbilityIcons:GetSettings().replaceMismatchedBaseIcons
end,
setFunc = CustomAbilityIcons.SetOptionMismatchedIcons
}
}
LAM2:RegisterOptionControls("CustomAbilityIcons_Panel", optionsData)
end
--- Retrieves the saved settings, whether global or per character (and the default settings if nothing was previously saved).
function CustomAbilityIcons.GetSettings()
if CustomAbilityIcons.CONFIG and CustomAbilityIcons.CONFIG.saveSettingsGlobally then
return CustomAbilityIcons.GLOBALSETTINGS or CustomAbilityIcons.DEFAULT_SETTINGS
else
return CustomAbilityIcons.CHARACTERSETTINGS or CustomAbilityIcons.DEFAULT_SETTINGS
end
end
--- Cleanup account-wide settings from previous versions.
--- @param savedVars table Contains the current account-wide saved variables.
--- @param defaultConfig table Contains the default account-wide saved variables.
--- @param namespace string? The sub-table (if any) in which the saved variables are stored.
function CustomAbilityIcons.CleanupAccountWideSettings(savedVars, defaultConfig, namespace)
local currentConfig = savedVars["Default"][GetDisplayName()]["$AccountWide"]
if namespace then
currentConfig = currentConfig[namespace]
end
for key, _ in pairs(currentConfig) do
if key ~= "version" and defaultConfig[key] == nil then
currentConfig[key] = nil
end
end
end
--- Cleanup character id settings from previous versions.
--- @param savedVars table Contains the current character id saved variables.
--- @param defaultConfig table Contains the default character id saved variables.
--- @param namespace string? The sub-table (if any) in which the saved variables are stored.
function CustomAbilityIcons.CleanupCharacterIdSettings(savedVars, defaultConfig, namespace)
local characterKey = GetCurrentCharacterId()
local currentConfig = savedVars["Default"][GetDisplayName()][characterKey]
if namespace then
currentConfig = currentConfig[namespace]
end
for key, _ in pairs(currentConfig) do
if key ~= "version" and defaultConfig[key] == nil then
currentConfig[key] = nil
end
end
end
--- Set the setting for global (Account Wide) icons to on/off
--- @param value boolean
function CustomAbilityIcons.SetOptionGlobalIcons(value)
local oldSettings = CustomAbilityIcons:GetSettings()
CustomAbilityIcons.CONFIG.saveSettingsGlobally = value
CustomAbilityIcons:GetSettings().showSkillStyleIcons = oldSettings.showSkillStyleIcons
CustomAbilityIcons:GetSettings().showCustomScribeIcons = oldSettings.showCustomScribeIcons
CustomAbilityIcons:GetSettings().replaceMismatchedBaseIcons = oldSettings.replaceMismatchedBaseIcons
end
--- Set the setting for skill style icons to on/off
--- @param value boolean
function CustomAbilityIcons.SetOptionSkillStyleIcons(value)
CustomAbilityIcons:GetSettings().showSkillStyleIcons = value
CustomAbilityIcons.OnCollectibleUpdated()
end
--- Set the setting for custom scribed icons to on/off
--- @param value boolean
function CustomAbilityIcons.SetOptionCustomIcons(value)
CustomAbilityIcons:GetSettings().showCustomScribeIcons = value
CustomAbilityIcons.OnCollectibleUpdated()
end
--- Set the setting for mismatched icons to on/off
--- @param value boolean
function CustomAbilityIcons.SetOptionMismatchedIcons(value)
CustomAbilityIcons:GetSettings().replaceMismatchedBaseIcons = value
CustomAbilityIcons.ReplaceMismatchedIcons()
end