Skip to content

Commit

Permalink
Options: Fix loaded/unloaded buttons state + behaviour
Browse files Browse the repository at this point in the history
Instead of wrongly looking at Private.loaded to decide whether a display
button is a child, keep track of the children via an explicit table.

This fixed both the state display, and the behaviour on clicking on the
button.
  • Loading branch information
InfusOnWoW committed Jan 7, 2024
1 parent 549c6e8 commit 52dd5ad
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 36 deletions.
54 changes: 22 additions & 32 deletions WeakAurasOptions/OptionsFrames/OptionsFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -748,32 +748,26 @@ function OptionsPrivate.CreateFrame()
loadedButton:SetViewClick(function()
local suspended = OptionsPrivate.Private.PauseAllDynamicGroups()
if loadedButton.view.visibility == 2 then
for id, child in pairs(displayButtons) do
if OptionsPrivate.Private.loaded[id] ~= nil then
child:PriorityHide(2)
end
for _, child in pairs(loadedButton.childButtons) do
child:PriorityHide(2)
end
loadedButton:PriorityHide(2)
else
for id, child in pairs(displayButtons) do
if OptionsPrivate.Private.loaded[id] ~= nil then
child:PriorityShow(2)
end
for _, child in pairs(loadedButton.childButtons) do
child:PriorityShow(2)
end
loadedButton:PriorityShow(2)
end
OptionsPrivate.Private.ResumeAllDynamicGroups(suspended)
end)
loadedButton.RecheckVisibility = function(self)
local none, all = true, true
for id, child in pairs(displayButtons) do
if OptionsPrivate.Private.loaded[id] ~= nil then
if child:GetVisibility() ~= 2 then
all = false
end
if child:GetVisibility() ~= 0 then
none = false
end
for _, child in pairs(loadedButton.childButtons) do
if child:GetVisibility() ~= 2 then
all = false
end
if child:GetVisibility() ~= 0 then
none = false
end
end
local newVisibility
Expand All @@ -790,6 +784,7 @@ function OptionsPrivate.CreateFrame()
end
end
loadedButton:SetViewDescription(L["Toggle the visibility of all loaded displays"])
loadedButton.childButtons = {}
frame.loadedButton = loadedButton

-- Not Loaded section
Expand All @@ -815,32 +810,26 @@ function OptionsPrivate.CreateFrame()
unloadedButton:SetViewClick(function()
local suspended = OptionsPrivate.Private.PauseAllDynamicGroups()
if unloadedButton.view.visibility == 2 then
for id, child in pairs(displayButtons) do
if OptionsPrivate.Private.loaded[id] == nil then
child:PriorityHide(2)
end
for _, child in pairs(unloadedButton.childButtons) do
child:PriorityHide(2)
end
unloadedButton:PriorityHide(2)
else
for id, child in pairs(displayButtons) do
if OptionsPrivate.Private.loaded[id] == nil then
child:PriorityShow(2)
end
for _, child in pairs(unloadedButton.childButtons) do
child:PriorityShow(2)
end
unloadedButton:PriorityShow(2)
end
OptionsPrivate.Private.ResumeAllDynamicGroups(suspended)
end)
unloadedButton.RecheckVisibility = function(self)
local none, all = true, true
for id, child in pairs(displayButtons) do
if OptionsPrivate.Private.loaded[id] == nil then
if child:GetVisibility() ~= 2 then
all = false
end
if child:GetVisibility() ~= 0 then
none = false
end
for _, child in pairs(unloadedButton.childButtons) do
if child:GetVisibility() ~= 2 then
all = false
end
if child:GetVisibility() ~= 0 then
none = false
end
end
local newVisibility
Expand All @@ -857,6 +846,7 @@ function OptionsPrivate.CreateFrame()
end
end
unloadedButton:SetViewDescription(L["Toggle the visibility of all non-loaded displays"])
unloadedButton.childButtons = {}
frame.unloadedButton = unloadedButton


Expand Down
11 changes: 7 additions & 4 deletions WeakAurasOptions/WeakAurasOptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -971,18 +971,19 @@ function OptionsPrivate.UpdateButtonsScroll()
frame.buttonsScroll:DoLayout()
end

local function addButton(button, aurasMatchingFilter, visible)
local function addButton(button, aurasMatchingFilter, visible, list)
button.frame:Show();
if button.AcquireThumbnail then
button:AcquireThumbnail()
end
tinsert(frame.buttonsScroll.children, button);
tinsert(list, button)
visible[button] = true

if button.data.controlledChildren and button:GetExpanded() then
for _, childId in ipairs(button.data.controlledChildren) do
if aurasMatchingFilter[childId] then
addButton(displayButtons[childId], aurasMatchingFilter, visible)
addButton(displayButtons[childId], aurasMatchingFilter, visible, list)
end
end
end
Expand Down Expand Up @@ -1161,22 +1162,24 @@ function OptionsPrivate.SortDisplayButtons(filter, overrideReset, id)
end
end

wipe(frame.loadedButton.childButtons)
if frame.loadedButton:GetExpanded() then
table.sort(topLevelLoadedAuras, function(a, b) return a:lower() < b:lower() end)
for _, id in ipairs(topLevelLoadedAuras) do
if aurasMatchingFilter[id] then
addButton(displayButtons[id], aurasMatchingFilter, visible)
addButton(displayButtons[id], aurasMatchingFilter, visible, frame.loadedButton.childButtons)
end
end
end

tinsert(frame.buttonsScroll.children, frame.unloadedButton);

wipe(frame.unloadedButton.childButtons)
if frame.unloadedButton:GetExpanded() then
table.sort(topLevelUnloadedAuras, function(a, b) return a:lower() < b:lower() end)
for _, id in ipairs(topLevelUnloadedAuras) do
if aurasMatchingFilter[id] then
addButton(displayButtons[id], aurasMatchingFilter, visible)
addButton(displayButtons[id], aurasMatchingFilter, visible, frame.unloadedButton.childButtons)
end
end
end
Expand Down

0 comments on commit 52dd5ad

Please sign in to comment.