-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathxanErrorDevourer.lua
More file actions
410 lines (354 loc) · 11.1 KB
/
xanErrorDevourer.lua
File metadata and controls
410 lines (354 loc) · 11.1 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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
--[[
xanErrorDevourer
Created by Xruptor
This addon will eat up those pesky errors that appear on your screen.
You can add custom errors in the options menu.
--]]
local ADDON_NAME, private = ...
if type(private) ~= "table" then
private = {}
end
local _G = _G
local string = string
local table = table
local pairs = pairs
local type = type
local lower = string.lower
local find = string.find
local tinsert = table.insert
local tsort = table.sort
local addon = _G[ADDON_NAME]
if not addon then
addon = CreateFrame("Frame", ADDON_NAME, UIParent, BackdropTemplateMixin and "BackdropTemplate")
_G[ADDON_NAME] = addon
end
local L = private.L or {}
local storedBarCount = 0
local prevClickedBar
local errorList = ""
local errorListEmpty = true
local function OnEvent(self, event, ...)
if event == "ADDON_LOADED" then
local name = ...
if name ~= ADDON_NAME then return end
self:UnregisterEvent("ADDON_LOADED")
if IsLoggedIn() then
self:EnableAddon()
else
self:RegisterEvent("PLAYER_LOGIN")
end
return
end
if event == "PLAYER_LOGIN" then
self:UnregisterEvent("PLAYER_LOGIN")
self:EnableAddon()
return
end
local handler = self[event]
if handler then
return handler(self, event, ...)
end
end
addon:RegisterEvent("ADDON_LOADED")
addon:SetScript("OnEvent", OnEvent)
local function updateErrorList()
if not xErrD_DB then
errorList = ""
errorListEmpty = true
return
end
local parts = {}
for k, v in pairs(xErrD_DB) do
if v and type(k) == "string" then
parts[#parts + 1] = lower(k)
end
end
if #parts == 0 then
errorList = ""
errorListEmpty = true
else
errorList = "|" .. table.concat(parts, "|")
errorListEmpty = false
end
end
--[[------------------------
ENABLE
--------------------------]]
function addon:EnableAddon()
--Initialize custom DB
xErrD_CDB = xErrD_CDB or {}
xErrD_LOC = xErrD_LOC or {}
--first time DB check
if xErrD_DB == nil then
--do a one complete setup
xErrD_DB = {}
--standard error list (only do the ones that are on by default)
for k, v in pairs(xErrD) do
if k and v then
xErrD_DB[string.lower(k)] = true
end
end
--localized error list
for k, v in pairs(xErrD_LOC) do
if k and v then
xErrD_DB[string.lower(k)] = true
end
end
local getMeta = (C_AddOns and C_AddOns.GetAddOnMetadata) or GetAddOnMetadata
local ver = (type(getMeta) == "function" and getMeta(ADDON_NAME, "Version")) or "1.0"
xErrD_DB.dbver = ver
end
--update error list
updateErrorList()
--populate scroll
addon:DoErrorList()
SLASH_XANERRORDEVOURER1 = "/xed";
SlashCmdList["XANERRORDEVOURER"] = function()
addon:DoErrorList()
addon:Show()
end
local getMeta = (C_AddOns and C_AddOns.GetAddOnMetadata) or GetAddOnMetadata
local ver = (type(getMeta) == "function" and getMeta(ADDON_NAME, "Version")) or "1.0"
DEFAULT_CHAT_FRAME:AddMessage(string.format("|cFF99CC33%s|r [v|cFF20ff20%s|r] loaded: /xed", ADDON_NAME, ver))
end
--Nom-Nom-Nom Errors!
local originalOnEvent = UIErrorsFrame:GetScript("OnEvent")
UIErrorsFrame:SetScript("OnEvent", function(self, event, num, msg, r, g, b, ...)
if not msg then
if originalOnEvent then
return originalOnEvent(self, event, num, msg, r, g, b, ...)
end
return
end
if not xErrD_DB then
if originalOnEvent then
return originalOnEvent(self, event, num, msg, r, g, b, ...)
end
return
end
local msgLower = lower(msg)
if xErrD_DB[msgLower] then
return
end
if not errorListEmpty and find(errorList, msgLower, 1, true) then
return
end
if originalOnEvent then
return originalOnEvent(self, event, num, msg, r, g, b, ...)
end
end)
--[[------------------------
OPTIONS
--------------------------]]
addon:SetFrameStrata("HIGH")
addon:SetToplevel(true)
addon:EnableMouse(true)
addon:SetMovable(true)
addon:SetClampedToScreen(true)
addon:SetWidth(380)
addon:SetHeight(570)
addon:SetBackdrop({
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = true,
tileSize = 16,
edgeSize = 32,
insets = { left = 5, right = 5, top = 5, bottom = 5 }
})
addon:SetBackdropColor(0,0,0,1)
addon:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
local closeButton = CreateFrame("Button", nil, addon, "UIPanelCloseButton");
closeButton:SetPoint("TOPRIGHT", addon, -15, -8);
local header = addon:CreateFontString("$parentHeaderText", "ARTWORK", "GameFontNormalSmall")
header:SetJustifyH("LEFT")
header:SetFontObject("GameFontNormal")
header:SetPoint("CENTER", addon, "TOP", 0, -20)
header:SetText(ADDON_NAME)
local nomnom = addon:CreateFontString("$parentNomText", "ARTWORK", "GameFontNormalSmall")
nomnom:SetJustifyH("LEFT")
nomnom:SetFontObject("GameFontNormal")
nomnom:SetPoint("CENTER", addon, "TOP", 0, -35)
nomnom:SetText(L.NomNomNom)
local scrollFrame = CreateFrame("ScrollFrame", ADDON_NAME.."_Scroll", addon, "UIPanelScrollFrameTemplate")
local scrollFrame_Child = CreateFrame("frame", ADDON_NAME.."_ScrollChild", scrollFrame, BackdropTemplateMixin and "BackdropTemplate")
scrollFrame:SetPoint("TOPLEFT", 10, -50)
--scrollbar on the right (x shifts the slider left or right)
scrollFrame:SetPoint("BOTTOMRIGHT", -40, 70)
scrollFrame:SetScrollChild(scrollFrame_Child)
--hide both frames
scrollFrame:Hide()
addon:Hide()
--Add Error
local addErrorBTN = CreateFrame("Button", ADDON_NAME.."_AddError", addon, "UIPanelButtonTemplate")
addErrorBTN:SetSize(120, 25)
addErrorBTN:SetPoint("BOTTOMLEFT", addon, "BOTTOMLEFT", 20, 15)
addErrorBTN:SetText(L.AddError)
addErrorBTN:SetScript("OnClick", function() StaticPopup_Show("XANERRD_ADDERROR") end)
--Remove Error
local RemErrorBTN = CreateFrame("Button", ADDON_NAME.."_RemoveError", addon, "UIPanelButtonTemplate")
RemErrorBTN:SetSize(120, 25)
RemErrorBTN:SetPoint("BOTTOMRIGHT", addon, "BOTTOMRIGHT", -20, 15)
RemErrorBTN:SetText(L.RemoveError)
RemErrorBTN:SetScript("OnClick", function()
if prevClickedBar and prevClickedBar.xData and prevClickedBar.xData.val and prevClickedBar.xData.val == 3 then
--delete the custom entry
if xErrD_CDB[prevClickedBar.xData.name] then
xErrD_CDB[prevClickedBar.xData.name] = nil --remove from custom DB
end
if xErrD_DB[prevClickedBar.xData.name] then
xErrD_DB[prevClickedBar.xData.name] = nil --remove from currently active
end
--update error list
updateErrorList()
--refresh the scroll
addon:DoErrorList()
end
end)
RemErrorBTN:Disable()
--add error popup box
StaticPopupDialogs["XANERRD_ADDERROR"] = {
text = L.InfoCustomAdd,
button1 = L.Yes,
button2 = L.No,
hasEditBox = true,
hasWideEditBox = true,
timeout = 0,
exclusive = 1,
hideOnEscape = 1,
EditBoxOnEscapePressed = function(self) self:GetParent():Hide() end,
OnAccept = function (self, data, data2)
--for backwards compatibility for older clients
local eb = self.editBox or self.EditBox or self:GetEditBox()
local text = eb:GetText()
addon:processAdd(text)
end,
whileDead = 1,
maxLetters = 255,
}
function addon:DoErrorList()
scrollFrame_Child:SetPoint("TOPLEFT")
scrollFrame_Child:SetSize(scrollFrame:GetWidth(), scrollFrame:GetHeight())
local previousBar
local buildList = {}
--first lets collect all the known items
--standard error list
for k in pairs(xErrD) do
tinsert(buildList, { name=lower(k), val=1 } )
end
--localized error list
for k in pairs(xErrD_LOC) do
tinsert(buildList, { name=lower(k), val=2 } )
end
--custom db
for k in pairs(xErrD_CDB) do
tinsert(buildList, { name=lower(k), val=3 } )
end
--sort it based on where the list is coming from
tsort(buildList, function(a,b) return (a.val < b.val) end)
local total = #buildList
for barCount=1, total do
--store the bar counts for future use
if barCount > storedBarCount then storedBarCount = barCount end
local barSlot = _G["xED_Bar"..barCount]
if not barSlot then
barSlot = CreateFrame("button", "xED_Bar"..barCount, scrollFrame_Child, BackdropTemplateMixin and "BackdropTemplate")
barSlot:EnableMouse(true)
barSlot:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8x8",
})
barSlot:SetBackdropColor(0,0,0,0)
barSlot:SetScript("OnClick", function(self)
if prevClickedBar then
prevClickedBar:SetBackdropColor(0,0,0,0)
end
prevClickedBar = self
self:SetBackdropColor(0,1,0,0.25)
if self.xData and self.xData.val and self.xData.val == 3 then
RemErrorBTN:Enable()
else
RemErrorBTN:Disable()
end
end)
end
if barCount==1 then
barSlot:SetPoint("TOPLEFT",scrollFrame_Child, "TOPLEFT", 10, -10)
barSlot:SetPoint("BOTTOMRIGHT",scrollFrame_Child, "TOPRIGHT", -10, -30)
else
barSlot:SetPoint("TOPLEFT", previousBar, "BOTTOMLEFT", 0, 0)
barSlot:SetPoint("BOTTOMRIGHT", previousBar, "BOTTOMRIGHT", 0, -20)
end
--store previous bar to position correctly for next one ;)
previousBar = barSlot
--store the data
barSlot.xData = buildList[barCount]
--check button stuff
local bar_chk = _G["xED_BarChk"..barCount]
if not bar_chk then
bar_chk = CreateFrame("CheckButton", "xED_BarChk"..barCount, barSlot, "InterfaceOptionsCheckButtonTemplate")
bar_chk:SetPoint("LEFT", 4, 0)
bar_chk:SetScript("OnClick", function(self)
local checked = self:GetChecked()
if self.xData and self.xData.name and xErrD_DB then
if checked then
xErrD_DB[self.xData.name] = true
else
if xErrD_DB[self.xData.name] then xErrD_DB[self.xData.name] = nil end
end
updateErrorList()
end
self:GetParent():Click()
end)
end
--change text color depending on where the entry came from
local barText = bar_chk.Text or _G[bar_chk:GetName().."Text"]
if buildList[barCount].val == 1 then
--standard list
barText:SetText("|cFFFFFFFF"..buildList[barCount].name.."|r")
elseif buildList[barCount].val == 2 then
--localizard list
barText:SetText("|cFF61F200"..buildList[barCount].name.."|r")
else
--custom list
barText:SetText("|cFFFF9933"..buildList[barCount].name.."|r")
end
barText:SetFontObject("GameFontNormal")
--store the data
bar_chk.xData = buildList[barCount]
--set if checked or not
if xErrD_DB and xErrD_DB[buildList[barCount].name] then
bar_chk:SetChecked(true)
else
bar_chk:SetChecked(false)
end
--show them if hidden
barSlot:Show()
bar_chk:Show()
end
--hide the unused bars (if some custom ones were removed)
if total < storedBarCount then
for q=total+1, storedBarCount do
if _G["xED_Bar"..q] then _G["xED_Bar"..q]:Hide() end
if _G["xED_BarChk"..q] then _G["xED_BarChk"..q]:Hide() end
end
end
--show the scroll frame
scrollFrame:Show()
end
--[[------------------------
ADD/REMOVE CUSTOM ERROR
--------------------------]]
function addon:processAdd(err)
if not err then return end
if not xErrD_CDB then return end
local trim = strtrim or function(s) return (s:gsub("^%s+", ""):gsub("%s+$", "")) end
err = trim(err)
if err == "" then return end
err = lower(err) --force to lowercase
if xErrD_CDB[err] then return end --don't add the same darn error twice
xErrD_CDB[err] = true --lets add it to the custom DB
xErrD_DB[err] = true --lets automatically enable it
--update error list
updateErrorList()
--refresh the scroll
addon:DoErrorList()
end