From 59dd8735bf21c160a1038d7f3efd8748939d819a Mon Sep 17 00:00:00 2001 From: furo Date: Sun, 25 Aug 2024 19:41:10 +0200 Subject: [PATCH] Add button to collapse/expand all groups in editor --- src/game/editor/editor.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 4f2591914..1829811e4 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -4297,7 +4297,7 @@ void CEditor::RenderLayers(CUIRect LayersBox) s_ScrollToSelectionNext = true; } - CUIRect AddGroupButton; + CUIRect AddGroupButton, CollapseAllButton; LayersBox.HSplitTop(RowHeight + 1.0f, &AddGroupButton, &LayersBox); if(s_ScrollRegion.AddRect(AddGroupButton)) { @@ -4311,6 +4311,35 @@ void CEditor::RenderLayers(CUIRect LayersBox) } } + LayersBox.HSplitTop(5.0f, nullptr, &LayersBox); + LayersBox.HSplitTop(RowHeight + 1.0f, &CollapseAllButton, &LayersBox); + if(s_ScrollRegion.AddRect(CollapseAllButton)) + { + unsigned long TotalCollapsed = 0; + for(const auto &pGroup : m_Map.m_vpGroups) + { + if(pGroup->m_Collapse) + { + TotalCollapsed++; + } + } + + const char *pActionText = TotalCollapsed == m_Map.m_vpGroups.size() ? "Expand all" : "Collapse all"; + + CollapseAllButton.HSplitTop(RowHeight, &CollapseAllButton, 0); + static int s_CollapseAllButton = 0; + if(DoButton_Editor(&s_CollapseAllButton, pActionText, 0, &CollapseAllButton, IGraphics::CORNER_R, "Expand or collapse all groups")) + { + for(const auto &pGroup : m_Map.m_vpGroups) + { + if(TotalCollapsed == m_Map.m_vpGroups.size()) + pGroup->m_Collapse = false; + else + pGroup->m_Collapse = true; + } + } + } + s_ScrollRegion.End(); if(s_Operation == OP_NONE)