Skip to content

Commit

Permalink
Fix Constant nodes should not be treated as actual inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Zylann committed Jun 1, 2023
1 parent 8be549a commit 4784ac6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
20 changes: 18 additions & 2 deletions editor/graph/voxel_graph_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ VoxelGraphEditor::VoxelGraphEditor() {
_context_menu->add_item("Relay", VoxelGraphFunction::NODE_RELAY);
continue;
}
if (i == CATEGORY_CONSTANT) {
continue;
}
String name = get_category_name(Category(i));
PopupMenu *menu = memnew(PopupMenu);
menu->set_name(name);
Expand All @@ -203,15 +206,28 @@ VoxelGraphEditor::VoxelGraphEditor() {
if (i == VoxelGraphFunction::NODE_RELAY) {
continue;
}

const NodeType &node_type = NodeTypeDB::get_singleton().get_type(i);
PopupMenu *menu = category_menus[node_type.category];
ZN_ASSERT(menu != nullptr);

if (i == VoxelGraphFunction::NODE_FUNCTION) {
PopupMenu *menu = category_menus[node_type.category];
ZN_ASSERT(menu != nullptr);
menu->add_item(ZN_TTR("Browse..."), CONTEXT_MENU_FUNCTION_BROWSE);
#ifdef ZN_GODOT
menu->add_item(TTR("Quick Open..."), CONTEXT_MENU_FUNCTION_QUICK_OPEN);
#endif
} else if (i == VoxelGraphFunction::NODE_CONSTANT) {
// Exceptionally keep the constant node into the input category in the editor. Internally, "Input" means the
// node is an entry point of the graph, like a function parameter. Constants are not considered as such, and
// won't work as inputs in graph functions. They have their own category internally, but it still makes
// sense to have them in the "input" sub-menu in the editor.
PopupMenu *menu = category_menus[CATEGORY_INPUT];
ZN_ASSERT(menu != nullptr);
menu->add_item(node_type.name, i);

} else {
PopupMenu *menu = category_menus[node_type.category];
ZN_ASSERT(menu != nullptr);
menu->add_item(node_type.name, i);
}
}
Expand Down
6 changes: 5 additions & 1 deletion generators/graph/node_type_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ const char *get_category_name(Category category) {
return "Debug";
case CATEGORY_FUNCTIONS:
return "Functions";
case CATEGORY_RELAY:
return "Relay";
case CATEGORY_CONSTANT:
return "Constant";
default:
CRASH_NOW_MSG("Unhandled category");
}
Expand Down Expand Up @@ -318,7 +322,7 @@ NodeTypeDB::NodeTypeDB() {
{
NodeType &t = types[VoxelGraphFunction::NODE_CONSTANT];
t.name = "Constant";
t.category = CATEGORY_INPUT;
t.category = CATEGORY_CONSTANT;
t.outputs.push_back(NodeType::Port("value"));
t.params.push_back(NodeType::Param("value", Variant::FLOAT));
}
Expand Down
1 change: 1 addition & 0 deletions generators/graph/node_type_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum Category {
CATEGORY_DEBUG,
CATEGORY_FUNCTIONS,
CATEGORY_RELAY,
CATEGORY_CONSTANT,
CATEGORY_COUNT
};

Expand Down

0 comments on commit 4784ac6

Please sign in to comment.