Skip to content

Commit

Permalink
Handle Collapsed State
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoRogai committed Nov 23, 2024
1 parent d52e6f1 commit 79c6677
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions RepHub.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ local RepHubFrameShown,
SORT_ASC,
SORT_DESC,
pendingUpdateFactionEvent,
updateFactionEventInterval = false, nil, nil, nil, nil, 1, 2, false, 10
updateFactionEventInterval,
reputationListCollapsedState = false, nil, nil, nil, nil, 1, 2, false, 10, nil

local reputationLabels = {
[-42000] = "Hated",
Expand Down Expand Up @@ -101,9 +102,10 @@ function RepHub:RefreshReputationGlobalDB()
table.insert(self.db.global.characterNames, characterName)
end

RepHub:HandleReputationListCollapsedState()

local currentGroup = nil

C_Reputation.ExpandAllFactionHeaders()
local numFactions = C_Reputation.GetNumFactions()
local factionIndex = 1
while (factionIndex <= numFactions) do
Expand All @@ -112,6 +114,11 @@ function RepHub:RefreshReputationGlobalDB()
if not factionData.isHeaderWithRep then
currentGroup = factionData.name
end

if factionData.isCollapsed then -- C_Reputation.ExpandAllFactionHeaders() doesn't work correctly, use this workaround instead
C_Reputation.ExpandFactionHeader(factionIndex)
numFactions = C_Reputation.GetNumFactions()
end
end

if not self.db.global.reputationList[factionData.factionID] then
Expand All @@ -129,6 +136,8 @@ function RepHub:RefreshReputationGlobalDB()

factionIndex = factionIndex + 1
end

RepHub:HandleReputationListCollapsedState(true)
end

function RepHub:ResetDB()
Expand Down Expand Up @@ -255,6 +264,27 @@ function RepHub:GetRepHubTableData()
return dataArr
end

function RepHub:HandleReputationListCollapsedState(restoreState)
if not restoreState then
reputationListCollapsedState = {}
end

local numFactions = C_Reputation.GetNumFactions()
local factionIndex = 1
while (factionIndex <= numFactions) do
local factionData = C_Reputation.GetFactionDataByIndex(factionIndex)
if factionData.isHeader then
if not restoreState and factionData.isCollapsed then
reputationListCollapsedState[factionData.factionID] = true
elseif restoreState and reputationListCollapsedState[factionData.factionID] then
C_Reputation.CollapseFactionHeader(factionIndex)
end
end

factionIndex = factionIndex + 1
end
end

-- GUI

function RepHub:CreateRepHubFrame()
Expand Down

0 comments on commit 79c6677

Please sign in to comment.