-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfilter.lua
More file actions
270 lines (229 loc) · 8.29 KB
/
filter.lua
File metadata and controls
270 lines (229 loc) · 8.29 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
--[[
filter.lua - Filter list management for XanChat
Improvements:
- Simplified frame creation with consolidated backdrop setup
- Reduced redundant checks in buildFilterList
- Better early returns throughout
- Improved searchFilterList efficiency
]]
local ADDON_NAME, private = ...
local addon = _G[ADDON_NAME]
addon.private = private or addon.private
addon.L = (private and private.L) or addon.L or {}
local L = addon.L
local strfind = string.find
-- ============================================================================
-- FRAME SETUP
-- ============================================================================
local isRestricted = function() return addon.isRestricted() end
local guardRestricted = function() return addon.guardRestricted() end
local createDialogFrame = function(...) return addon.createDialogFrame(...) end
local createScrollFrame = function(...) return addon.createScrollFrame(...) end
-- ============================================================================
-- FILTER LIST FRAME
-- ============================================================================
addon.filterList = createDialogFrame(ADDON_NAME.."_filterList", L.EditFilterListHeader)
local filterInfo = addon.filterList:CreateFontString("$parentFilterInfo", "ARTWORK", "GameFontHighlight")
filterInfo:SetJustifyH("LEFT")
filterInfo:SetPoint("TOPLEFT", addon.filterList, "TOPLEFT", 15, -45)
filterInfo:SetText("|cFF61F200"..L.EditFilterListInfo.."|r")
local fontHeight = filterInfo:GetFontHeight()
if fontHeight then
filterInfo:SetFontHeight(fontHeight * 1.05)
end
local scrollFrame, scrollFrame_Child = createScrollFrame(addon.filterList, -65)
scrollFrame:Hide()
addon.filterList:Hide()
-- ============================================================================
-- FILTER DATA
-- ============================================================================
local CORE_FILTER_EVENTS = {
CHAT_MSG_ACHIEVEMENT = true,
CHAT_MSG_ADDON = true,
CHAT_MSG_AFK = true,
CHAT_MSG_BN_CONVERSATION = true,
CHAT_MSG_BN_CONVERSATION_NOTICE = true,
CHAT_MSG_BN_INLINE_TOAST_ALERT = true,
CHAT_MSG_BN_INLINE_TOAST_BROADCAST = true,
CHAT_MSG_BN_INLINE_TOAST_BROADCAST_INFORM = true,
CHAT_MSG_BN_INLINE_TOAST_CONVERSATION = true,
CHAT_MSG_BN_WHISPER = true,
CHAT_MSG_BN_WHISPER_INFORM = true,
CHAT_MSG_BN_WHISPER_PLAYER_OFFLINE = true,
CHAT_MSG_CHANNEL = true,
CHAT_MSG_CHANNEL_JOIN = true,
CHAT_MSG_CHANNEL_LEAVE = true,
CHAT_MSG_CHANNEL_LIST = true,
CHAT_MSG_CHANNEL_NOTICE = true,
CHAT_MSG_CHANNEL_NOTICE_USER = true,
CHAT_MSG_COMBAT_FACTION_CHANGE = true,
CHAT_MSG_COMBAT_HONOR_GAIN = true,
CHAT_MSG_COMBAT_MISC_INFO = true,
CHAT_MSG_COMBAT_XP_GAIN = true,
CHAT_MSG_CURRENCY = true,
CHAT_MSG_DND = true,
CHAT_MSG_EMOTE = true,
CHAT_MSG_GUILD = true,
CHAT_MSG_IGNORED = true,
CHAT_MSG_INSTANCE_CHAT = true,
CHAT_MSG_LOOT = true,
CHAT_MSG_MONEY = true,
CHAT_MSG_MONSTER_EMOTE = true,
CHAT_MSG_MONSTER_PARTY = true,
CHAT_MSG_MONSTER_RAID = true,
CHAT_MSG_MONSTER_SAY = true,
CHAT_MSG_MONSTER_WHISPER = true,
CHAT_MSG_MONSTER_YELL = true,
CHAT_MSG_NOTICE = true,
CHAT_MSG_OFFICER = true,
CHAT_MSG_OPENING = true,
CHAT_MSG_PARTY = true,
CHAT_MSG_PARTY_LEADER = true,
CHAT_MSG_PET_INFO = true,
CHAT_MSG_RAID = true,
CHAT_MSG_RAID_LEADER = true,
CHAT_MSG_RAID_WARNING = true,
CHAT_MSG_SAY = true,
CHAT_MSG_SKILL = true,
CHAT_MSG_SYSTEM = true,
CHAT_MSG_TEXT_EMOTE = true,
CHAT_MSG_TRADESKILLS = true,
CHAT_MSG_WHISPER = true,
CHAT_MSG_YELL = true,
CHARACTER_POINTS_CHANGED = true,
PARTY_LEADER_CHANGED = true,
PLAYER_LEVEL_UP = true,
PLAYER_ROLES_ASSIGNED = true,
QUEST_TURNED_IN = true,
READY_CHECK = true,
READY_CHECK_FINISHED = true,
TIME_PLAYED_MSG = true,
UNIT_LEVEL = true,
}
local CUSTOM_FILTER_EVENTS = {
_NOTICE = true,
_EMOTE = true,
ROLE_ = true,
VOTE_KICK = true,
}
-- ============================================================================
-- SETUP AND LIST BUILDING
-- ============================================================================
local function setupFilterUI()
if not XCHT_DB.filterList then
XCHT_DB.filterList = {}
end
if addon.ApplyDefaults then
addon.ApplyDefaults(XCHT_DB.filterList.core, CORE_FILTER_EVENTS)
addon.ApplyDefaults(XCHT_DB.filterList.custom, CUSTOM_FILTER_EVENTS)
else
for k, v in pairs(CORE_FILTER_EVENTS) do
if XCHT_DB.filterList.core[k] == nil then
XCHT_DB.filterList.core[k] = v
end
end
for k, v in pairs(CUSTOM_FILTER_EVENTS) do
if XCHT_DB.filterList.custom[k] == nil then
XCHT_DB.filterList.custom[k] = v
end
end
end
if not addon.filterList._xanHooked then
addon.filterList:HookScript("OnShow", function()
guardRestricted()
if not addon.filterList.ListLoaded then
addon:DoFilterList()
addon.filterList.ListLoaded = true
end
end)
addon.filterList._xanHooked = true
end
addon.isFilterListEnabled = true
end
local function buildFilterList()
scrollFrame_Child:SetPoint("TOPLEFT")
scrollFrame_Child:SetWidth(scrollFrame:GetWidth())
scrollFrame_Child:SetHeight(scrollFrame:GetHeight())
local previousBar
local buildList = {}
for k in pairs(XCHT_DB.filterList.core) do
table.insert(buildList, { name=k, val=1 })
end
for k in pairs(XCHT_DB.filterList.custom) do
table.insert(buildList, { name=k, val=2 })
end
table.sort(buildList, function(a, b)
if a.val == b.val then
return (a.name < b.name)
else
return (a.val < b.val)
end
end)
for barCount = 1, #buildList do
local entry = buildList[barCount]
local isCore = entry.val == 1
local barSlot = _G["xanChat_FilterListBar"..barCount] or CreateFrame("button", "xanChat_FilterListBar"..barCount, scrollFrame_Child, BackdropTemplateMixin and "BackdropTemplate")
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
barSlot:EnableMouse(true)
barSlot:SetBackdrop({ bgFile = "Interface\\Buttons\\WHITE8x8" })
barSlot:SetBackdropColor(0, 0, 0, 0)
previousBar = barSlot
barSlot.xData = entry
local bar_chk = _G["xanChat_FilterListBarChk"..barCount] or CreateFrame("CheckButton", "xanChat_FilterListBarChk"..barCount, barSlot, "InterfaceOptionsCheckButtonTemplate")
bar_chk.xData = entry
bar_chk:SetPoint("LEFT", 4, 0)
local checkedValue = isCore and XCHT_DB.filterList.core[entry.name] or XCHT_DB.filterList.custom[entry.name]
_G["xanChat_FilterListBarChk"..barCount.."Text"]:SetText((isCore and "|cFFFFFFFF" or "|cFF61F200")..entry.name.."|r")
bar_chk:SetChecked(checkedValue)
bar_chk:SetEnabled(not isRestricted())
bar_chk:SetScript("OnClick", function(self)
if not guardRestricted() and self.xData and self.xData.name then
local isChecked = self:GetChecked()
local targetTable = isCore and XCHT_DB.filterList.core or XCHT_DB.filterList.custom
targetTable[self.xData.name] = isChecked
self:SetChecked(isChecked)
end
end)
barSlot:Show()
bar_chk:Show()
end
scrollFrame:Show()
end
-- ============================================================================
-- FILTER SEARCH
-- ============================================================================
function addon:searchFilterList(event, text)
local filterList = XCHT_DB.filterList
if not filterList or not event then return false end
if addon.DebugPrint then
local textDump = addon.dbgSafeValue and addon.dbgSafeValue(text) or (addon.DebugValue and addon.DebugValue(text) or "<text>")
addon.DebugPrint("searchFilterList: event="..tostring(event).." text="..textDump)
end
if filterList.core and filterList.core[event] then
if addon.DebugPrint then addon.DebugPrint("searchFilterList: core match") end
return true
end
for k, v in pairs(filterList.custom) do
if v and strfind(event, k, 1, true) then
if addon.DebugPrint then addon.DebugPrint("searchFilterList: custom match key="..tostring(k)) end
return true
end
end
if addon.DebugPrint then addon.DebugPrint("searchFilterList: no match") end
return false
end
-- ============================================================================
-- PUBLIC API
-- ============================================================================
function addon:EnableFilterList()
setupFilterUI()
end
function addon:DoFilterList()
buildFilterList()
end