Skip to content
Open
Show file tree
Hide file tree
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
17 changes: 16 additions & 1 deletion src/DevTools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ struct Settings {
bool buttonInGame = false;
bool buttonEnabled = false;
bool treeDragReorder = false;
bool hideFlaggedNodes = false;
};

struct TreeBranchOptions {
bool drag = true;
bool visible = true;
bool fake = false;
bool flagHidden = false;
};

struct ParentNodeInformation {
bool drag = true;
bool visible = true;
bool flagHidden = false;
};

class DevTools {
Expand Down Expand Up @@ -66,7 +80,8 @@ class DevTools {
void setupPlatform();

void drawTree();
void drawTreeBranch(CCNode* node, size_t index, bool drag, bool visible);
void drawTreeBranch(CCNode* node, size_t index, TreeBranchOptions options);
void drawNodeChildren(CCNode* node, ParentNodeInformation info);
void drawSettings();
void drawAdvancedSettings();
void drawNodeAttributes(CCNode* node);
Expand Down
8 changes: 8 additions & 0 deletions src/pages/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ void DevTools::drawSettings() {
"(Experimental)\nAllows you to drag/drop nodes in the node tree, changing\ntheir parents or ordering."
);
}
ImGui::Checkbox("Hide Flagged Nodes", &m_settings.hideFlaggedNodes);
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip(
"If enabled, hides nodes in the node tree with the \"geode.devtools/hide\"\n"
"user flag set. Allows for hiding nodes irrelevant to debugging, such as containers.\n"
"This will keep the children of those nodes visible in the node tree."
);
}
ImGui::Checkbox("Advanced Settings", &m_settings.advancedSettings);
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip(
Expand Down
67 changes: 53 additions & 14 deletions src/pages/Tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@

using namespace geode::prelude;

std::string formatNodeName(CCNode* node, size_t index) {
std::string name = fmt::format("[{}] {} ", index, geode::cocos::getObjectName(node));
std::string formatNodeName(CCNode* node, size_t index, bool fake, bool flagHidden) {
std::string prefix = "";
if (fake) prefix += "*";
if (flagHidden) prefix += "...";
std::string name = fmt::format("[{}{}] {} ", prefix, index, geode::cocos::getObjectName(node));
if (node->getTag() != -1) {
name += fmt::format("({}) ", node->getTag());
}
Expand All @@ -36,12 +39,21 @@ bool isNodeParentOf(CCNode* parent, CCNode* child) {
return false;
}

void DevTools::drawTreeBranch(CCNode* node, size_t index, bool drag, bool visible) {
void DevTools::drawTreeBranch(CCNode* node, size_t index, TreeBranchOptions options) {
if (!this->searchBranch(node)) {
return;
}

visible = node->isVisible() && visible;
if (node->getUserFlag("hide"_spr) && m_settings.hideFlaggedNodes) {
this->drawNodeChildren(node, {
.drag = options.drag,
.visible = options.visible,
.flagHidden = true
});
return;
}

options.visible = node->isVisible() && options.visible;

auto selected = DevTools::get()->getSelectedNode() == node;

Expand All @@ -58,7 +70,7 @@ void DevTools::drawTreeBranch(CCNode* node, size_t index, bool drag, bool visibl

bool drawSeparator = false;

if (auto dragged = this->getDraggedNode(); dragged && dragged != node && !drag) {
if (auto dragged = this->getDraggedNode(); dragged && dragged != node && !options.drag && !options.fake) {
float mouseY = ImGui::GetMousePos().y;
float cursorY = ImGui::GetCursorPosY() + ImGui::GetWindowPos().y - ImGui::GetScrollY();
float height = ImGui::GetTextLineHeight();
Expand Down Expand Up @@ -109,10 +121,10 @@ void DevTools::drawTreeBranch(CCNode* node, size_t index, bool drag, bool visibl
auto alpha = ImGui::GetStyle().DisabledAlpha;
ImGui::GetStyle().DisabledAlpha = node->isVisible() ? alpha + 0.15f : alpha;

ImGui::BeginDisabled(!visible);
ImGui::BeginDisabled(!options.visible);
ImGui::PushItemFlag(ImGuiItemFlags_Disabled, false); // Bypass iteract blocking in imgui

const auto name = formatNodeName(node, index);
const auto name = formatNodeName(node, index, options.fake, options.flagHidden);
// 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/
bool expanded = ImGui::TreeNodeEx(node, flags, "%s", name.c_str());
float height = ImGui::GetItemRectSize().y;
Expand Down Expand Up @@ -164,10 +176,13 @@ void DevTools::drawTreeBranch(CCNode* node, size_t index, bool drag, bool visibl
if (m_settings.attributesInTree) {
this->drawNodeAttributes(node);
}
size_t i = 0;
for (auto& child : CCArrayExt<CCNode*>(node->getChildren())) {
this->drawTreeBranch(child, i++, drag || isDrag, visible);
}

this->drawNodeChildren(node, {
.drag = options.drag || isDrag,
.visible = options.visible,
.flagHidden = false
});

ImGui::TreePop();
}
// on leaf nodes expanded is true
Expand All @@ -176,6 +191,30 @@ void DevTools::drawTreeBranch(CCNode* node, size_t index, bool drag, bool visibl
}
}

void DevTools::drawNodeChildren(CCNode* node, ParentNodeInformation info) {
size_t i = 0;
for (auto& child : CCArrayExt<CCNode*>(node->getChildren())) {
this->drawTreeBranch(child, i++, {
.drag = info.drag,
.visible = info.visible,
.fake = false,
.flagHidden = info.flagHidden
});
}

i = 0;
if (auto fakeChildren = typeinfo_cast<CCArray*>(node->getUserObject("extra-children"_spr))) {
for (auto& child : CCArrayExt<CCNode*>(fakeChildren)) {
this->drawTreeBranch(child, i++, {
.drag = info.drag,
.visible = info.visible,
.fake = true,
.flagHidden = info.flagHidden
});
}
}
}

void DevTools::drawTree() {
#ifdef GEODE_IS_MOBILE
ImGui::Dummy({0.f, 60.f});
Expand All @@ -191,11 +230,11 @@ void DevTools::drawTree() {
m_searchQuery.clear();
}

this->drawTreeBranch(CCDirector::get()->getRunningScene(), 0, false, true);
this->drawTreeBranch(OverlayManager::get(), 1, false, true);
this->drawTreeBranch(CCDirector::get()->getRunningScene(), 0, { .drag = false });
this->drawTreeBranch(OverlayManager::get(), 1, { .drag = false });

if (auto* dragged = this->getDraggedNode()) {
const auto name = formatNodeName(dragged, 0);
const auto name = formatNodeName(dragged, 0, false, false);
auto bgColor = ImGui::GetColorU32(ImGui::GetStyle().Colors[ImGuiCol_Header]);
auto textColor = ImGui::GetColorU32(ImGui::GetStyle().Colors[ImGuiCol_Text]);

Expand Down
Loading