diff --git a/ElvUI_Options/Core/StyleFilters.lua b/ElvUI_Options/Core/StyleFilters.lua index 44a1e6f60e..eef8203ec1 100644 --- a/ElvUI_Options/Core/StyleFilters.lua +++ b/ElvUI_Options/Core/StyleFilters.lua @@ -8,7 +8,7 @@ local LCS = E.Libs.LCS local _G = _G local wipe, pairs, strmatch, strsplit, tostring = wipe, pairs, strmatch, strsplit, tostring -local next, sort, tonumber, format = next, sort, tonumber, format +local next, sort, tinsert, tonumber, format = next, sort, tinsert, tonumber, format local GetClassInfo = GetClassInfo local GetDifficultyInfo = GetDifficultyInfo @@ -194,12 +194,20 @@ function C:StyleFilterSetConfig(filter) E.Libs.AceConfigDialog:SelectGroup('ElvUI', 'nameplates', 'stylefilters', filter and 'triggers' or 'import') end +local function sortFilters(a, b) + local list = E.global.nameplates.filters + if not list then return end + + local A, B = list[a].triggers, list[b].triggers + if A and B then return A.priority < B.priority end +end + local function validateCreateFilter(_, value) return not (strmatch(value, '^[%s%p]-$') or E.global.nameplates.filters[value]) end local function validateString(_, value) return value and not strmatch(value, '^[%s%p]-$') end StyleFilters.addFilter = ACH:Input(L["Create Filter"], nil, 1, nil, nil, nil, function(_, value) E.global.nameplates.filters[value] = NP:StyleFilterCopyDefaults() C:StyleFilterSetConfig(value) end, nil, nil, validateCreateFilter) StyleFilters.selectFilter = ACH:Select(L["Select Filter"], nil, 2, GetFilters, nil, nil, function() return C.StyleFilterSelected end, function(_, value) C:StyleFilterSetConfig(value) end, nil, nil) -StyleFilters.selectFilter.sorting = function() wipe(sortedFilters) local list = E.global.nameplates.filters for filter in next, list do tinsert(sortedFilters, filter) end sort(sortedFilters, function(a, b) return list[a].triggers.priority < list[b].triggers.priority end) return sortedFilters end +StyleFilters.selectFilter.sorting = function() wipe(sortedFilters) for filter in next, E.global.nameplates.filters do tinsert(sortedFilters, filter) end sort(sortedFilters, sortFilters) return sortedFilters end StyleFilters.removeFilter = ACH:Select(L["Delete Filter"], L["Delete a created filter, you cannot delete pre-existing filters, only custom ones."], 3, function() wipe(filters) for filterName in next, E.global.nameplates.filters do if not G.nameplates.filters[filterName] then filters[filterName] = filterName end end return filters end, true, nil, nil, function(_, value) for profile in pairs(E.data.profiles) do if E.data.profiles[profile].nameplates and E.data.profiles[profile].nameplates.filters then E.data.profiles[profile].nameplates.filters[value] = nil end end E.global.nameplates.filters[value] = nil exportList[value] = nil NP:ConfigureAll() C:StyleFilterSetConfig() end) StyleFilters.triggers = ACH:Group(L["Triggers"], nil, 5, nil, nil, nil, function() return not C.StyleFilterSelected end)