1313
1414using namespace geode ::prelude;
1515
16- std::string formatNodeName (CCNode* node, size_t index) {
17- std::string name = fmt::format (" [{}] {} " , index, geode::cocos::getObjectName (node));
16+ std::string formatNodeName (CCNode* node, size_t index, bool fake, bool flagHidden) {
17+ std::string prefix = " " ;
18+ if (fake) prefix += " *" ;
19+ if (flagHidden) prefix += " ..." ;
20+ std::string name = fmt::format (" [{}{}] {} " , prefix, index, geode::cocos::getObjectName (node));
1821 if (node->getTag () != -1 ) {
1922 name += fmt::format (" ({}) " , node->getTag ());
2023 }
@@ -36,12 +39,21 @@ bool isNodeParentOf(CCNode* parent, CCNode* child) {
3639 return false ;
3740}
3841
39- void DevTools::drawTreeBranch (CCNode* node, size_t index, bool drag, bool visible ) {
42+ void DevTools::drawTreeBranch (CCNode* node, size_t index, TreeBranchOptions options ) {
4043 if (!this ->searchBranch (node)) {
4144 return ;
4245 }
4346
44- visible = node->isVisible () && visible;
47+ if (node->getUserFlag (" hide" _spr) && m_settings.hideFlaggedNodes ) {
48+ this ->drawNodeChildren (node, {
49+ .drag = options.drag ,
50+ .visible = options.visible ,
51+ .flagHidden = true
52+ });
53+ return ;
54+ }
55+
56+ options.visible = node->isVisible () && options.visible ;
4557
4658 auto selected = DevTools::get ()->getSelectedNode () == node;
4759
@@ -58,7 +70,7 @@ void DevTools::drawTreeBranch(CCNode* node, size_t index, bool drag, bool visibl
5870
5971 bool drawSeparator = false ;
6072
61- if (auto dragged = this ->getDraggedNode (); dragged && dragged != node && !drag) {
73+ if (auto dragged = this ->getDraggedNode (); dragged && dragged != node && !options. drag && !options. fake ) {
6274 float mouseY = ImGui::GetMousePos ().y ;
6375 float cursorY = ImGui::GetCursorPosY () + ImGui::GetWindowPos ().y - ImGui::GetScrollY ();
6476 float height = ImGui::GetTextLineHeight ();
@@ -109,10 +121,10 @@ void DevTools::drawTreeBranch(CCNode* node, size_t index, bool drag, bool visibl
109121 auto alpha = ImGui::GetStyle ().DisabledAlpha ;
110122 ImGui::GetStyle ().DisabledAlpha = node->isVisible () ? alpha + 0 .15f : alpha;
111123
112- ImGui::BeginDisabled (!visible);
124+ ImGui::BeginDisabled (!options. visible );
113125 ImGui::PushItemFlag (ImGuiItemFlags_Disabled, false ); // Bypass iteract blocking in imgui
114126
115- const auto name = formatNodeName (node, index);
127+ const auto name = formatNodeName (node, index, options. fake , options. flagHidden );
116128 // The order here is unusual due to imgui weirdness; see the second-to-last paragraph in https://kahwei.dev/2022/06/20/imgui-tree-node/
117129 bool expanded = ImGui::TreeNodeEx (node, flags, " %s" , name.c_str ());
118130 float height = ImGui::GetItemRectSize ().y ;
@@ -164,10 +176,13 @@ void DevTools::drawTreeBranch(CCNode* node, size_t index, bool drag, bool visibl
164176 if (m_settings.attributesInTree ) {
165177 this ->drawNodeAttributes (node);
166178 }
167- size_t i = 0 ;
168- for (auto & child : CCArrayExt<CCNode*>(node->getChildren ())) {
169- this ->drawTreeBranch (child, i++, drag || isDrag, visible);
170- }
179+
180+ this ->drawNodeChildren (node, {
181+ .drag = options.drag || isDrag,
182+ .visible = options.visible ,
183+ .flagHidden = false
184+ });
185+
171186 ImGui::TreePop ();
172187 }
173188 // on leaf nodes expanded is true
@@ -176,6 +191,30 @@ void DevTools::drawTreeBranch(CCNode* node, size_t index, bool drag, bool visibl
176191 }
177192}
178193
194+ void DevTools::drawNodeChildren (CCNode* node, ParentNodeInformation info) {
195+ size_t i = 0 ;
196+ for (auto & child : CCArrayExt<CCNode*>(node->getChildren ())) {
197+ this ->drawTreeBranch (child, i++, {
198+ .drag = info.drag ,
199+ .visible = info.visible ,
200+ .fake = false ,
201+ .flagHidden = info.flagHidden
202+ });
203+ }
204+
205+ i = 0 ;
206+ if (auto fakeChildren = typeinfo_cast<CCArray*>(node->getUserObject (" extra-children" _spr))) {
207+ for (auto & child : CCArrayExt<CCNode*>(fakeChildren)) {
208+ this ->drawTreeBranch (child, i++, {
209+ .drag = info.drag ,
210+ .visible = info.visible ,
211+ .fake = true ,
212+ .flagHidden = info.flagHidden
213+ });
214+ }
215+ }
216+ }
217+
179218void DevTools::drawTree () {
180219#ifdef GEODE_IS_MOBILE
181220 ImGui::Dummy ({0 .f , 60 .f });
@@ -191,11 +230,11 @@ void DevTools::drawTree() {
191230 m_searchQuery.clear ();
192231 }
193232
194- this ->drawTreeBranch (CCDirector::get ()->getRunningScene (), 0 , false , true );
195- this ->drawTreeBranch (OverlayManager::get (), 1 , false , true );
233+ this ->drawTreeBranch (CCDirector::get ()->getRunningScene (), 0 , { . drag = false } );
234+ this ->drawTreeBranch (OverlayManager::get (), 1 , { . drag = false } );
196235
197236 if (auto * dragged = this ->getDraggedNode ()) {
198- const auto name = formatNodeName (dragged, 0 );
237+ const auto name = formatNodeName (dragged, 0 , false , false );
199238 auto bgColor = ImGui::GetColorU32 (ImGui::GetStyle ().Colors [ImGuiCol_Header]);
200239 auto textColor = ImGui::GetColorU32 (ImGui::GetStyle ().Colors [ImGuiCol_Text]);
201240
0 commit comments