Skip to content

Commit

Permalink
[Feature] Priority sorting for Auras when using whitelist (#96)
Browse files Browse the repository at this point in the history
* enable up/down for Aura filter lists

* add annotation/defaults/const

* add toggle for priority sorting

* set whiteListPriority var on icons

* implement priority sorting

* locales
  • Loading branch information
Krealle authored Sep 30, 2024
1 parent fdaffde commit bac5e0b
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions Data/Constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ const.AURA_OPTION_KIND = {
CAST_BY_PLAYERS = "castByPlayers",
CAST_BY_NPC = "castByNPC",
HIDE_IN_COMBAT = "hideInCombat",
WHITE_LIST_PRIORITY = "whiteListPriority",
}

---@enum AuraOrientation
Expand Down
2 changes: 2 additions & 0 deletions Data/Defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ Defaults.Widgets = {
blacklist = Defaults.Filters.buffs.blacklist,
useWhitelist = false,
whitelist = Defaults.Filters.buffs.whitelist,
whiteListPriority = false,
minDuration = 0,
maxDuration = 0,
hideNoDuration = false,
Expand Down Expand Up @@ -420,6 +421,7 @@ Defaults.Widgets = {
blacklist = Defaults.Filters.debuffs.blacklist,
useWhitelist = false,
whitelist = Defaults.Filters.debuffs.whitelist,
whiteListPriority = false,
minDuration = 0,
maxDuration = 0,
hideNoDuration = false,
Expand Down
4 changes: 4 additions & 0 deletions Locales/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ L.CastByPlayers = "Cast By Players"
L.CastByNPC = "Cast By NPC"
L.blacklist = "Blacklist"
L.whitelist = "Whitelist"
L.WhiteListPriority = "Sort by Priority"

L.PersonalTooltip = "Show auras cast by you"
L.NonPersonalTooltip = "Show auras not cast by you"
Expand All @@ -75,6 +76,9 @@ L.CastByPlayersTooltip = "Show auras cast by players"
L.CastByNPCTooltip = "Show auras cast by NPCs"
L.HideNoDurationTooltip = "Hide auras with no duration"
L.HideInCombatTooltip = "Hide tooltips in combat"
L.WhiteListPriorityTooltip = [[Use priority sorting for Whitelist
The priority goes from top of the list to the bottom]]

-- Cast Bar
L.Reverse = "Reverse"
Expand Down
2 changes: 1 addition & 1 deletion Menu/AuraFilterList.lua
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ function Builder.CreateSetting_Auras(parent, which, kind)
---@param t table auraTable
function widget:SetDBValue(t)
widget.t = t
CreateAuraButtons(widget.frame, auraButtons, t, true, UpdateHeight)
CreateAuraButtons(widget.frame, auraButtons, t, false, UpdateHeight)
UpdateHeight()
end

Expand Down
7 changes: 6 additions & 1 deletion Menu/Builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ function Builder:CreateAuraFilterOptions(parent, widgetName)
---@class AuraFilterOptions: OptionsFrame
local f = CUF:CreateFrame(nil, parent, 1, 1, true, true)
f.id = "AuraFilterOptions"
f.optionHeight = 165
f.optionHeight = 195

-- Title
f.title = self:CreateOptionTitle(f, "Filter")
Expand Down Expand Up @@ -1322,6 +1322,11 @@ function Builder:CreateAuraFilterOptions(parent, widgetName)
const.AURA_OPTION_KIND.FILTER .. "." .. const.AURA_OPTION_KIND.USE_WHITELIST)
self:AnchorRightOfCB(f.useWhitelistCB, f.useBlacklistCB)

f.whiteListPriority = self:CreateCheckBox(f, widgetName, L.WhiteListPriority,
const.AURA_OPTION_KIND.FILTER .. "." .. const.AURA_OPTION_KIND.WHITE_LIST_PRIORITY,
L.WhiteListPriorityTooltip)
self:AnchorBelowCB(f.whiteListPriority, f.useBlacklistCB)

return f
end

Expand Down
1 change: 1 addition & 0 deletions WidgetAnnotations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
---@field hideInCombat boolean

---@class FilterOpt
---@field whiteListPriority boolean
---@field blacklist table<number>
---@field whitelist table<number>
---@field hideNoDuration boolean
Expand Down
8 changes: 8 additions & 0 deletions Widgets/Auras/Auras.lua
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ local function Icons_SetPersonal(icons, personal)
icons.personal = personal
end

---@param icons CellAuraIcons
---@param priority boolean
local function Icons_SetWhiteListPriority(icons, priority)
icons.whiteListPriority = priority
end

---@param icons CellAuraIcons
---@param show boolean
local function Icons_ShowDuration(icons, show)
Expand Down Expand Up @@ -380,6 +386,7 @@ function W:CreateAuraIcons(button, type)
auraIcons.SetWhitelist = Icons_SetWhitelist
auraIcons.SetUseBlacklist = Icons_SetUseBlacklist
auraIcons.SetUseWhitelist = Icons_SetUseWhitelist
auraIcons.SetWhiteListPriority = Icons_SetWhiteListPriority

auraIcons.SetBoss = Icons_SetBoss
auraIcons.SetCastByPlayers = Icons_SetCastByPlayers
Expand Down Expand Up @@ -480,6 +487,7 @@ W:RegisterCreateWidgetFunc(const.WIDGET_KIND.DEBUFFS, W.CreateDebuffs)
---@field minDuration number|boolean
---@field blacklist table<number, boolean>
---@field whitelist table<number, boolean>
---@field whiteListPriority boolean
---@field useBlacklist boolean
---@field useWhitelist boolean
---@field boss boolean
Expand Down
12 changes: 12 additions & 0 deletions Widgets/Auras/Handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ local function UpdateAuraIcons(icons)
local aData = icons._auraCache[a]
local bData = icons._auraCache[b]
if not aData or not bData then return false end

if icons.useWhitelist and icons.whiteListPriority then
local aIdx = icons.whitelist[aData.spellId]
local bIdx = icons.whitelist[bData.spellId]

if aIdx or bIdx then
if not aIdx and bIdx then return false end
if not bIdx then return true end
return aIdx < bIdx
end
end

return aData.expirationTime > bData.expirationTime
end)

Expand Down
3 changes: 3 additions & 0 deletions Widgets/Auras/Updater.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ function W.UpdateAuraWidget(button, unit, which, setting, subSetting, ...)
if not subSetting or subSetting == "personal" then
auras:SetPersonal(styleTable.filter.personal)
end
if not subSetting or subSetting == const.AURA_OPTION_KIND.WHITE_LIST_PRIORITY then
auras:SetWhiteListPriority(styleTable.filter.whiteListPriority)
end
end

auras.Update(button)
Expand Down

0 comments on commit bac5e0b

Please sign in to comment.