Skip to content

Commit

Permalink
move the sort function up
Browse files Browse the repository at this point in the history
  • Loading branch information
kodewdle committed Dec 6, 2024
1 parent 0be8d74 commit 1cb0fe6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ElvUI_Options/Core/StyleFilters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1cb0fe6

Please sign in to comment.