From ebfbc7757b16e7bdfc87272e89584afb8f75a2a4 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Sat, 14 Dec 2024 11:51:19 +0100 Subject: [PATCH] Fix #128589: allow disabling node group interface UI for custom node tree types This adds a new `bl_use_group_interface` property that can be set on custom node group types. By default it is `true` to avoid this being a breaking change. If it's set to `false` some UI elements related to the built-in node group interface are hidden. Pull Request: https://projects.blender.org/blender/blender/pulls/131877 --- scripts/startup/bl_ui/space_node.py | 35 ++++++++++++------- source/blender/blenkernel/BKE_node.hh | 6 ++++ .../blender/makesrna/intern/rna_nodetree.cc | 8 +++++ 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/scripts/startup/bl_ui/space_node.py b/scripts/startup/bl_ui/space_node.py index a8f119e998e..1b3b1604508 100644 --- a/scripts/startup/bl_ui/space_node.py +++ b/scripts/startup/bl_ui/space_node.py @@ -336,6 +336,7 @@ class NODE_MT_node(Menu): def draw(self, context): layout = self.layout snode = context.space_data + group = snode.edit_tree is_compositor = snode.tree_type == 'CompositorNodeTree' layout.operator("transform.translate").view2d_edge_pan = True @@ -372,11 +373,12 @@ class NODE_MT_node(Menu): layout.operator("node.links_detach") layout.operator("node.links_mute") - layout.separator() - layout.operator("node.group_make", icon='NODETREE') - layout.operator("node.group_insert", text="Insert Into Group") - layout.operator("node.group_edit").exit = False - layout.operator("node.group_ungroup") + if not group or group.bl_use_group_interface: + layout.separator() + layout.operator("node.group_make", icon='NODETREE') + layout.operator("node.group_insert", text="Insert Into Group") + layout.operator("node.group_edit").exit = False + layout.operator("node.group_ungroup") layout.separator() layout.menu("NODE_MT_context_menu_show_hide_menu") @@ -581,6 +583,7 @@ class NODE_MT_context_menu(Menu): snode = context.space_data is_nested = (len(snode.path) > 1) is_geometrynodes = snode.tree_type == 'GeometryNodeTree' + group = snode.edit_tree selected_nodes_len = len(context.selected_nodes) active_node = context.active_node @@ -640,17 +643,18 @@ class NODE_MT_context_menu(Menu): layout.separator() - layout.operator("node.group_make", text="Make Group", icon='NODETREE') - layout.operator("node.group_insert", text="Insert Into Group") + if group and group.bl_use_group_interface: + layout.operator("node.group_make", text="Make Group", icon='NODETREE') + layout.operator("node.group_insert", text="Insert Into Group") - if active_node and active_node.type == 'GROUP': - layout.operator("node.group_edit").exit = False - layout.operator("node.group_ungroup", text="Ungroup") + if active_node and active_node.type == 'GROUP': + layout.operator("node.group_edit").exit = False + layout.operator("node.group_ungroup", text="Ungroup") - if is_nested: - layout.operator("node.tree_path_parent", text="Exit Group", icon='FILE_PARENT') + if is_nested: + layout.operator("node.tree_path_parent", text="Exit Group", icon='FILE_PARENT') - layout.separator() + layout.separator() layout.operator("node.join", text="Join in New Frame") layout.operator("node.detach", text="Remove from Frame") @@ -921,6 +925,8 @@ class NODE_PT_node_tree_interface(Panel): return False if tree.is_embedded_data: return False + if not tree.bl_use_group_interface: + return False return True def draw(self, context): @@ -1003,6 +1009,9 @@ class NODE_PT_node_tree_properties(Panel): else: layout.prop(group, "description", text="Description") + if not group.bl_use_group_interface: + return + layout.prop(group, "color_tag") row = layout.row(align=True) row.prop(group, "default_group_node_width", text="Node Width") diff --git a/source/blender/blenkernel/BKE_node.hh b/source/blender/blenkernel/BKE_node.hh index 8c7acef2f29..ba84e4f91a2 100644 --- a/source/blender/blenkernel/BKE_node.hh +++ b/source/blender/blenkernel/BKE_node.hh @@ -482,6 +482,12 @@ struct bNodeTreeType { /* Check if the socket type is valid for this tree type. */ bool (*valid_socket_type)(bNodeTreeType *ntreetype, bNodeSocketType *socket_type); + /** + * If true, then some UI elements related to building node groups will be hidden. + * This can be used by Python-defined custom node tree types. + */ + bool no_group_interface; + /* RNA integration */ ExtensionRNA rna_ext; }; diff --git a/source/blender/makesrna/intern/rna_nodetree.cc b/source/blender/makesrna/intern/rna_nodetree.cc index 384977b4377..06fa7cdc8a4 100644 --- a/source/blender/makesrna/intern/rna_nodetree.cc +++ b/source/blender/makesrna/intern/rna_nodetree.cc @@ -11463,6 +11463,14 @@ static void rna_def_nodetree(BlenderRNA *brna) RNA_def_property_flag(prop, PROP_REGISTER); RNA_def_property_ui_text(prop, "Icon", "The node tree icon"); + prop = RNA_def_property(srna, "bl_use_group_interface", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_negative_sdna(prop, nullptr, "typeinfo->no_group_interface", 1); + RNA_def_property_boolean_default(prop, true); + RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL); + RNA_def_property_ui_text(prop, + "Use Group Interface", + "Determines the visibility of some UI elements related to node groups"); + /* poll */ func = RNA_def_function(srna, "poll", nullptr); RNA_def_function_ui_description(func, "Check visibility in the editor");