-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMuteBardsOptions.lua
More file actions
306 lines (282 loc) · 8.21 KB
/
MuteBardsOptions.lua
File metadata and controls
306 lines (282 loc) · 8.21 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
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
MBI = MBI or {};
local isInitialized = false;
local bardZoneToRemove
local musicZoneToRemove
local musicDropdownOption
local bardDropdownOption
local function copyTable(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in pairs(orig) do
copy[orig_key] = orig_value
end
else
copy = orig
end
return copy
end
local function firstNonEmptyValue(zoneOptions)
local tempTable = copyTable(zoneOptions)
local keys = {}
for k,_ in pairs(tempTable) do
table.insert(keys, k)
end
table.sort(keys)
return tempTable[keys[1]]
end
local function getCurrentActiveZoneName(savedVariables)
if (savedVariables ~= nil and savedVariables.currentActiveZone ~= nil and savedVariables.currentActiveZone ~= "") then
return savedVariables.currentActiveZone;
end
return "UNKNOWN"
end
local function getCurrentMainZoneName(savedVariables)
if (savedVariables ~= nil and savedVariables.currentMainZone ~= nil and savedVariables.currentMainZone ~= "") then
return savedVariables.currentMainZone;
end
return "UNKNOWN"
end
local function generateBardZoneDropdownOption(savedVariables)
local currentActiveZone = getCurrentActiveZoneName(savedVariables)
local result = MBI:ContainsZone(currentActiveZone, nil)
if (result ~= nil and result.bard == true) then
bardDropdownOption = currentActiveZone
else
local zoneOptions = copyTable(savedVariables.mutedBardZones)
table.sort(zoneOptions)
bardDropdownOption = firstNonEmptyValue(zoneOptions)
end
bardZoneToRemove = bardDropdownOption
return bardDropdownOption
end
local function generateMusicZoneDropdownOption(savedVariables)
local currentMainZone = getCurrentMainZoneName(savedVariables)
local result = MBI:ContainsZone(nil, currentMainZone)
if (result ~= nil and result.music == true) then
musicDropdownOption = currentMainZone
else
local zoneOptions = copyTable(savedVariables.mutedMusicZones)
table.sort(zoneOptions)
musicDropdownOption = firstNonEmptyValue(zoneOptions)
end
musicZoneToRemove = musicDropdownOption
return musicDropdownOption
end
local function changeZoneToRemove(value, type)
if (type == VOLUME_TYPES.BARD) then
bardZoneToRemove = value
else
musicZoneToRemove = value
end
end
function MBI:InitSettingsPanel(savedVariables)
local function refreshCallback()
self:Refresh();
end
local panelName = "Mute Bards Improved"
local panelData = {
type = "panel",
name = panelName,
displayName = panelName,
author = "@psi-pisi",
version = self.version,
website = "https://www.esoui.com/downloads/info4016-MuteBardsImproved.html",
feedback = "https://www.esoui.com/downloads/info4016-MuteBardsImproved.html#comments",
slashCommand = "/mbi",
registerForRefresh = true,
registerForDefaults = false
}
local optionsTable = {
{
type = "header",
name = "Bard Zone Settings",
width = "full"
},
{
type = "divider",
width = "full",
height = 10,
alpha = 0.25
},
{
type = "description",
title = "Current Zone:",
text = function() return " " .. getCurrentActiveZoneName(savedVariables) end,
width = "full"
},
{
type = "divider",
width = "full",
height = 10,
alpha = 0.25
},
{
type = "dropdown",
name = "Muted Bard Zones",
choices = savedVariables.mutedBardZones,
sort = "name-up",
getFunc = function() return generateBardZoneDropdownOption(savedVariables) end,
setFunc = function(value) changeZoneToRemove(value, VOLUME_TYPES.BARD) end,
reference = "mutedBardZonesDropdown",
},
{
type = "button",
name = "Add Zone",
disabled = function() return getCurrentActiveZoneName(savedVariables) == "UNKNOWN" end,
func = function()
if (getCurrentActiveZoneName(savedVariables) ~= "UNKNOWN") then
self:AddZone(getCurrentActiveZoneName(savedVariables), VOLUME_TYPES.BARD, refreshCallback);
mutedBardZonesDropdown:UpdateChoices(savedVariables.mutedBardZones)
ReloadUI("ingame")
end
end,
width = "half",
warning = "This will reload the UI for changes to be applied."
},
{
type = "button",
name = "Remove Zone",
func = function()
d("bardZoneToRemove: " .. bardZoneToRemove)
self:RemoveZone(bardZoneToRemove, VOLUME_TYPES.BARD, refreshCallback);
mutedBardZonesDropdown:UpdateChoices(savedVariables.mutedBardZones)
ReloadUI("ingame")
end,
width = "half",
warning = "This will reload the UI for changes to be applied."
},
{
type = "header",
name = "Music Zone Settings",
width = "full"
},
{
type = "divider",
width = "full",
height = 10,
alpha = 0.25
},
{
type = "description",
title = "Current Main Zone:",
text = function() return " " .. getCurrentMainZoneName(savedVariables) end,
width = "full"
},
{
type = "divider",
width = "full",
height = 10,
alpha = 0.25
},
{
type = "dropdown",
name = "Muted Music Zones",
choices = savedVariables.mutedMusicZones,
sort = "name-up",
getFunc = function() return generateMusicZoneDropdownOption(savedVariables) end,
setFunc = function(value) changeZoneToRemove(value, VOLUME_TYPES.MUSIC) end,
reference = "mutedMusicZonesDropdown",
},
{
type = "button",
name = "Add Zone",
disabled = function() return getCurrentMainZoneName(savedVariables) == "UNKNOWN" end,
func = function()
if (getCurrentMainZoneName(savedVariables) ~= "UNKNOWN") then
self:AddZone(getCurrentMainZoneName(savedVariables), VOLUME_TYPES.MUSIC, refreshCallback);
mutedMusicZonesDropdown:UpdateChoices(savedVariables.mutedMusicZones)
ReloadUI("ingame")
end
end,
width = "half",
warning = "This will reload the UI for changes to be applied."
},
{
type = "button",
name = "Remove Zone",
func = function()
d("musicZoneToRemove: " .. musicZoneToRemove)
self:RemoveZone(musicZoneToRemove, VOLUME_TYPES.MUSIC, refreshCallback);
mutedMusicZonesDropdown:UpdateChoices(savedVariables.mutedMusicZones)
ReloadUI("ingame")
end,
width = "half",
warning = "This will reload the UI for changes to be applied."
},
{
type = "header",
name = "Sound Settings",
width = "full"
},
{
type = "divider",
width = "full",
height = 10,
alpha = 0.25
},
{
type = "description",
text = "Default sound effects sfxVolume when you are not around Bards.",
width = "full"
},
{
type = "slider",
name = "SFX Volume",
min = 1,
max = 100,
step = 1,
getFunc = function() return savedVariables.sfxVolume end,
setFunc = function(value) MBI:ChangeVolume(value, VOLUME_TYPES.BARD) end,
},
{
type = "description",
text = "Default music volume of the game.",
width = "full"
},
{
type = "slider",
name = "Music Volume",
min = 1,
max = 100,
step = 1,
getFunc = function() return savedVariables.musicVolume end,
setFunc = function(value) MBI:ChangeVolume(value, VOLUME_TYPES.MUSIC) end,
},
{
type = "header",
name = "Log Settings",
width = "full"
},
{
type = "divider",
width = "full",
height = 10,
alpha = 0.25
},
{
type = "description",
text = "Since zones keep changing while you are moving around, it may cause too many logs getting printed in the chat.",
width = "full"
},
{
type = "description",
text = "You can disable printing logs when sound effects are muted or unmuted.",
width = "full"
},
{
type = "checkbox",
name = "Print mute/unmute logs",
getFunc = function() return savedVariables.printLogs end,
setFunc = function(value) MBI:TogglePrintLogs(value) end,
width = "full"
}
}
local LAM = LibAddonMenu2
if (not isInitialized) then
LAM:RegisterAddonPanel(panelName, panelData);
end
LAM:RegisterOptionControls(panelName, optionsTable);
isInitialized = true;
end