-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeQuiet.lua
More file actions
252 lines (218 loc) · 6.01 KB
/
Copy pathBeQuiet.lua
File metadata and controls
252 lines (218 loc) · 6.01 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
version = "v10.1.0.1"
WL_DEFAULT = {
"Temple of Fal'adora",
"Falanaar Tunnels",
"Shattered Locus",
"Crestfall",
"Snowblossom Village",
"Havenswood",
"Jorundall",
"Molten Cay",
"Un'gol Ruins",
"The Rotting Mire",
"Whispering Reef",
"Verdant Wilds",
"The Dread Chain",
"Skittering Hollow",
"Torghast, Tower of the Damned"
}
BL_DEFAULT = {}
--Initialize config variables if they are not saved
if ENABLED == nil then
ENABLED = 1
end
if VO_ENABLED == nil then
VO_ENABLED = 0
end
if VERBOSE == nil then
VERBOSE = 1
end
--Default whitelist includes the withered army training zones from legion and island expeditions from BFA
if WHITELIST == nil then
WHITELIST = WL_DEFAULT
end
-- BLACKLIST defaults to empty. This preserves off behavior from before.
if BLACKLIST == nil then
BLACKLIST = BL_DEFAULT
end
--Create the frame
local f = CreateFrame("Frame")
function close_head()
--Query current zone and subzone when talking head is triggered
subZoneName = GetSubZoneText();
zoneName = GetZoneText();
--Only run this logic if the functionality is turned on
if ENABLED == 1 then
--Block the talking head unless its in the whitelist
if (has_value(WHITELIST, subZoneName) ~= true and has_value(WHITELIST, zoneName) ~= true) then
block_head();
end
--If disabled, check blacklist
elseif (has_value(BLACKLIST, subZoneName) or has_value(BLACKLIST, zoneName)) then
block_head();
end
end
function block_head()
--Close the talking head
--TalkingHeadFrame:CloseImmediately(); pre 10.0.7
TalkingHeadFrame:Hide()
if TalkingHeadFrame.voHandle ~= nil and VO_ENABLED == 0 then
C_Timer.After(0.025, function() StopSound(TalkingHeadFrame.voHandle) end);
end
if VERBOSE == 1 then
print("BeQuiet blocked a talking head! /bq verbose to turn this alert off.")
end
end
--Main function
function f:OnEvent(event, ...)
if event == "PLAYER_LOGIN" then
hooksecurefunc(TalkingHeadFrame, "PlayCurrent", close_head);
end
end
function removeFirst(tbl, val)
for i, v in ipairs(tbl) do
if v == val then
return table.remove(tbl, i)
end
end
end
--Function to check if value in array
function has_value (tab, val)
for _, value in ipairs(tab) do
if value == val then
return true
end
end
return false
end
--Slash command function
function MyAddonCommands(args)
allow_msg = 'BeQuiet disabled - now allowing talking heads except for blacklisted zones.'
block_msg = 'BeQuiet enabled - now blocking talking heads except for whitelisted zones.'
if args == 'off' then
ENABLED = 0
print(allow_msg)
end
if args == 'on' then
ENABLED = 1
print(block_msg)
end
if args == 'toggle' then
if ENABLED == 0 then
ENABLED = 1
print(block_msg)
elseif ENABLED == 1 then
ENABLED = 0
print(allow_msg)
end
end
if args == 'whitelist currentzone' then
zone = GetZoneText()
if has_value(WHITELIST, zone) then
removeFirst(WHITELIST, zone)
print(zone .. ' removed from the whitelist.')
else
table.insert(WHITELIST, zone)
print(zone .. ' added to the whitelist.')
end
end
if args == 'whitelist currentsubzone' then
zone = GetSubZoneText()
if has_value(WHITELIST, zone) then
removeFirst(WHITELIST, zone)
print(zone .. ' removed from the whitelist.')
else
table.insert(WHITELIST, zone)
print(zone .. ' added to the whitelist.')
end
end
if args == 'blacklist currentzone' then
zone = GetZoneText()
if has_value(BLACKLIST, zone) then
removeFirst(BLACKLIST, zone)
print(zone .. ' removed from the blacklist.')
else
table.insert(BLACKLIST, zone)
print(zone .. ' added to the blacklist.')
end
end
if args == 'blacklist currentsubzone' then
zone = GetSubZoneText()
if has_value(BLACKLIST, zone) then
removeFirst(BLACKLIST, zone)
print(zone .. ' removed from the blacklist.')
else
table.insert(BLACKLIST, zone)
print(zone .. ' added to the blacklist.')
end
end
if args == 'delete' then
WHITELIST = {}
BLACKLIST = {}
print('Whitelist and blacklist have been deleted.')
end
if args == 'reset' then
WHITELIST = WL_DEFAULT
BLACKLIST = BL_DEFAULT
print('Whitelist and blacklist have been reset to default.')
end
if args == 'show' then
print('whitelist: ' .. table.concat(WHITELIST, ', '))
print('blacklist: ' .. table.concat(BLACKLIST, ', '))
end
if args == 'verbose' then
if VERBOSE == 0 then
VERBOSE = 1
print('Verbose mode enabled. A chat message will print when a talking head is blocked.')
elseif VERBOSE == 1 then
VERBOSE = 0
print('Verbose mode disabled.')
end
end
if args == 'vo on' then
VO_ENABLED = 1
print('VoiceOver enabled when talking head frame hidden')
end
if args == 'vo off' then
VO_ENABLED = 0
print('VoiceOver disabled when talking head frame hidden')
end
if args == 'vo toggle' then
if VO_ENABLED == 1 then
VO_ENABLED = 0
print('VoiceOver disabled when talking head frame hidden')
else
VO_ENABLED = 1
print('VoiceOver enabled when talking head frame hidden')
end
end
if args == 'whitelist' then
print('whitelist (currentzone | currentsubzone) - toggle whitelisting for the current major zone (Orgrimmar) or sub-zone (Valley of Strength).')
end
if args == 'blacklist' then
print('blacklist (currentzone | currentsubzone) - toggle blacklisting for the current major zone (Orgrimmar) or sub-zone (Valley of Strength).')
end
if args == 'vo' then
print ('vo (on | off | toggle) - enable or disable removal of vo seperate from hiding talking head ui')
end
if args == '' then
print('BeQuiet version ' .. version)
print('Options: on | off | toggle | verbose | whitelist | blacklist | reset | delete | show | vo')
print('-----')
if ENABLED == 1 then
print('BeQuiet is currently enabled.')
elseif ENABLED == 0 then
print('BeQuiet is currently disabled.')
end
if VERBOSE == 1 then
print('Verbose mode is currently enabled.')
elseif VERBOSE == 0 then
print('Verbose mode is currently disabled.')
end
end
end
--Add /bq to slash command list and register its function
SLASH_BQ1 = '/bq'
SlashCmdList["BQ"] = MyAddonCommands
f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", f.OnEvent)