Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/Classes/ConfigTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ function ConfigTabClass:ConfigTab(build)
self.toggleConfigs = not self.toggleConfigs
end)

local function isCollapsed(section)
return self:IsSectionCollapsed(section)
end

local function searchMatch(varData)
local searchStr = self.controls.search.buf:lower():gsub("[%-%.%+%[%]%$%^%%%?%*]", "%%%0")
if searchStr and searchStr:match("%S") then
Expand Down Expand Up @@ -253,7 +257,11 @@ function ConfigTabClass:ConfigTab(build)
lastSection = new("SectionControl"):SectionControl({"TOPLEFT",self.controls.search,"BOTTOMLEFT"}, {0, 0, 360, 0}, varData.section)
lastSection.varControlList = { }
lastSection.col = varData.col
lastSection.collapsed = false
lastSection.height = function(self)
if self.collapsed then
return 16
end
local height = 20
for _, varControl in pairs(self.varControlList) do
if varControl:IsShown() then
Expand All @@ -263,8 +271,18 @@ function ConfigTabClass:ConfigTab(build)
end
return m_max(height, 32)
end
-- Collapse toggle, matching the Calcs tab: right aligned, '-' when expanded, '+' when collapsed.
-- Sits on the section's top border, as the header label does, to clear the option controls below.
local section = lastSection
local toggle = new("ButtonControl"):ButtonControl({"TOPRIGHT",lastSection,"TOPRIGHT"}, {-6, -7, 16, 16}, function()
return section.collapsed and "+" or "-"
end, function()
section.collapsed = not section.collapsed
end)
-- Deliberately not in varControlList: it must not count towards the section's height or visibility
t_insert(self.sectionList, lastSection)
t_insert(self.controls, lastSection)
t_insert(self.controls, toggle)
if varData.section == "Custom Modifiers" then
self.customSection = lastSection
end
Expand Down Expand Up @@ -774,6 +792,15 @@ function ConfigTabClass:ConfigTab(build)
end
end

local ownSection = lastSection
local eligibleShown = control.shown
control.shown = function()
if isCollapsed(ownSection) then
return false
end
return type(eligibleShown) == "boolean" and eligibleShown or eligibleShown()
end

t_insert(self.controls, control)
t_insert(lastSection.varControlList, control)
end
Expand All @@ -788,13 +815,21 @@ function ConfigTabClass:ConfigTab(build)
self:BuildModList()
self.build.buildFlag = true
end)
self.controls.customModsAddBlock.shown = function()
return not isCollapsed(self.customSection)
end
self.customModsBlockControls = { }
self:UpdateCustomModsControls()
end

return self
end

-- A collapsed section hides its contents, unless a search is active
function ConfigTabClass:IsSectionCollapsed(section)
return section.collapsed and not self.controls.search.buf:match("%S")
end

function ConfigTabClass:Load(xml, fileName)
self.activeConfigSetId = 1
self.configSets = { }
Expand Down Expand Up @@ -1017,6 +1052,10 @@ function ConfigTabClass:Draw(viewPort, inputEvents)
for _, section in ipairs(self.sectionList) do
local y = 14
section.shown = true
-- Probe with the section expanded, so a collapsed section that still has
-- eligible options keeps its (clickable) header on screen
local collapsed = section.collapsed
section.collapsed = false
local doShow = false
for _, varControl in pairs(section.varControlList) do
if varControl:IsShown() then
Expand All @@ -1027,6 +1066,7 @@ function ConfigTabClass:Draw(viewPort, inputEvents)
y = y + height + 4
end
end
section.collapsed = collapsed
section.shown = doShow
if doShow then
local width, height = section:GetSize()
Expand Down Expand Up @@ -1278,6 +1318,9 @@ function ConfigTabClass:UpdateCustomModsControls()

for index, block in ipairs(configSet.customModsList) do
local blockControl = new("CustomModBlockControl"):CustomModBlockControl({"TOPLEFT", self.customSection, "TOPLEFT"}, {8, 0, 344, 120}, self, index, block)
blockControl.shown = function()
return not self:IsSectionCollapsed(self.customSection)
end
t_insert(self.customModsBlockControls, blockControl)
t_insert(self.controls, blockControl)
t_insert(self.customSection.varControlList, blockControl)
Expand Down
Loading