浏览代码

Add Node Color Pallete

this also fixes some issues in socket drawing (socket displaying
incorrectly when plugged in, or when coming from group)
and adds a new file for the ui operators for nodes.
todo: move the ui operators from ops_nodegroup to ops_ui
Joseph Brandenburg 3 月之前
父节点
当前提交
802b1d0c97
共有 5 个文件被更改,包括 113 次插入4 次删除
  1. 3 0
      __init__.py
  2. 21 1
      misc_nodes.py
  3. 18 0
      misc_nodes_ui.py
  4. 57 0
      ops_ui.py
  5. 14 3
      socket_definitions.py

+ 3 - 0
__init__.py

@@ -1,4 +1,5 @@
 from . import ( ops_nodegroup,
+                ops_ui, 
                 base_definitions,
                 socket_definitions,
                 link_definitions,
@@ -25,6 +26,7 @@ classLists = [module.TellClasses() for module in [
  misc_nodes_ui,
  socket_definitions,
  ops_nodegroup,
+ ops_ui,
  primitives_definitions,
  deformer_definitions,
  math_definitions,
@@ -77,6 +79,7 @@ input_category=[
             NodeItem("InputExistingGeometryData"),
             NodeItem("UtilityDeclareCollections"),
             NodeItem("InputThemeBoneColorSets"),
+            NodeItem("InputColorSetPallete"),
     ]
 link_transform_category = [
         NodeItem("LinkCopyLocation"),

+ 21 - 1
misc_nodes.py

@@ -19,6 +19,7 @@ def TellClasses():
              InputExistingGeometryObject,
              InputExistingGeometryData,
              InputThemeBoneColorSets,
+             InputColorSetPallete,
              UtilityDeclareCollections,
              UtilityCollectionJoin,
              UtilityCollectionHierarchy,
@@ -315,7 +316,26 @@ class InputThemeBoneColorSets(SimpleInputNode):
         ui_node = get_node_prototype(self.ui_signature, self.base_tree)
         for i in range(20):
             self.parameters[f"Color {str(i).zfill(2)}"] = ui_node.outputs[i].default_value
-            
+
+class InputColorSetPallete(SimpleInputNode):
+    '''A node representing the theme's colors'''
+    def __init__(self, signature, base_tree):
+        super().__init__(signature, base_tree, MatrixFromCurveSockets)
+        self.init_parameters()
+        self.node_type = "UTILITY"
+        # we'll go ahead and fill them here
+        from .utilities import get_node_prototype
+        ui_node = get_node_prototype(self.ui_signature, self.base_tree)
+        from .base_definitions import MantisSocketTemplate
+        outputs = []
+        for o in ui_node.outputs:
+            outputs.append (MantisSocketTemplate( name = o.name,))
+        self.outputs.init_sockets(outputs)
+        self.init_parameters()
+        for o in ui_node.outputs:
+            self.parameters[o.name] = o.default_value
+            prRed(o.name)
+            prPurple(o.default_value)
 
 class UtilityMatrixFromCurve(MantisNode):
     '''Get a matrix from a curve'''

+ 18 - 0
misc_nodes_ui.py

@@ -22,6 +22,7 @@ def TellClasses():
              InputExistingGeometryObjectNode,
              InputExistingGeometryDataNode,
              InputThemeBoneColorSets,
+             InputColorSetPallete,
              UtilityDeclareCollections,
              UtilityCollectionJoin,
              UtilityCollectionHierarchy,
@@ -765,6 +766,23 @@ class InputThemeBoneColorSets(Node, MantisUINode):
             s.color_index=i
         self.initialized = True
 
+class InputColorSetPallete(Node, MantisUINode):
+    """Displays the theme's colors."""
+    bl_idname = "InputColorSetPallete"
+    bl_label = "Color Pallete"
+    bl_icon = "NODE"
+    bl_width_min=280
+    initialized : bpy.props.BoolProperty(default = False)
+    mantis_node_class_name=bl_idname
+    
+    def init(self, context):
+        self.initialized = True
+    
+    def draw_buttons(self, context, layout):
+        ops_props = layout.operator('mantis.color_pallete_socket_add')
+        ops_props.tree_invoked = self.id_data.name
+        ops_props.node_invoked = self.name
+
 def socket_data_from_collection_paths(root_data, root_name, path, socket_data):
     # so we need to 'push' the socket names and their paths in order
     # socket_data is a list of tuples of ( name, path, )

+ 57 - 0
ops_ui.py

@@ -0,0 +1,57 @@
+# gonna start putting the UI operators in here so
+# that the nodegroup operators file is more focused
+
+import bpy
+from bpy.types import Operator
+from .utilities import (prRed, prGreen, prPurple, prWhite,
+                              prOrange,
+                              wrapRed, wrapGreen, wrapPurple, wrapWhite,
+                              wrapOrange,)
+
+def TellClasses():
+    return [
+        ColorPalleteAddSocket,
+        ColorPalleteRemoveSocket,
+    ]
+
+class ColorPalleteAddSocket(Operator):
+    """Add a Color Set socket to the node"""
+    bl_idname = "mantis.color_pallete_socket_add"
+    bl_label = "Add Color Set"
+    bl_options = {'REGISTER', 'UNDO'}
+
+    tree_invoked : bpy.props.StringProperty(options ={'HIDDEN'})
+    node_invoked : bpy.props.StringProperty(options ={'HIDDEN'})
+
+    @classmethod
+    def poll(cls, context):
+        return True
+    
+    def execute(self, context):
+        n = bpy.data.node_groups[self.tree_invoked].nodes[self.node_invoked]
+        # the name doesn't matter, will probably be Color Set.001 or something instead
+        n.outputs.new("ColorSetSocket", "Color Set")
+        return {'FINISHED'}
+
+class ColorPalleteRemoveSocket(Operator):
+    """Remove a Color Set socket from the node"""
+    bl_idname = "mantis.color_pallete_socket_remove"
+    bl_label = "X"
+    bl_options = {'REGISTER', 'UNDO'}
+
+    tree_invoked : bpy.props.StringProperty(options   = {'HIDDEN'})
+    node_invoked : bpy.props.StringProperty(options   = {'HIDDEN'})
+    socket_invoked : bpy.props.StringProperty(options = {'HIDDEN'})
+
+    @classmethod
+    def poll(cls, context):
+        return True
+    
+    def execute(self, context):
+        n = bpy.data.node_groups[self.tree_invoked].nodes[self.node_invoked]
+        # the name doesn't matter, will probably be Color Set.001 or something instead
+        for s in n.outputs:
+            if s.identifier == self.socket_invoked:
+                break
+        n.outputs.remove(s)
+        return {'FINISHED'}

+ 14 - 3
socket_definitions.py

@@ -353,13 +353,16 @@ def update_metarig_posebone(self, context,):
 #  Sockets
 ########################################################################
 
+text_only_output_types = ["NodeGroupInput", "NodeGroupOutput", "SchemaArrayInput",
+                          "SchemaArrayInputGet", "SchemaArrayInputAll", "SchemaConstInput",
+                          "SchemaIncomingConnection"]
 
 def ChooseDraw(self, context, layout, node, text, icon = "NONE", use_enum=True, nice_bool=True, icon_only=False):
     invert_checkbox = False
     if hasattr(self, "invert") and self.invert == True:
         invert_checkbox=True
     # TEXT ONLY
-    if self.node.bl_idname in ["NodeGroupInput", "NodeGroupOutput"]:
+    if self.node.bl_idname in text_only_output_types:
         layout.label(text=text)
     elif hasattr(self, "display_text") and self.display_text and self.is_linked:
             layout.label(text=self.display_text)
@@ -986,8 +989,10 @@ class ColorSetSocket(MantisSocket):
         default=get_select_color(None),)
     is_valid_interface_type=False
     def draw(self, context, layout, node, text):
-        if self.is_linked:
-            layout.label(text='Custom Color Set')
+        if (self.is_output == False) and (self.is_linked == True):
+            layout.label(text=self.name)
+        elif self.node.bl_idname in text_only_output_types:
+            layout.label(text=self.name)
         else:
             layout.prop( text='Color Set', data=self,
                         property='active_color', )
@@ -995,6 +1000,12 @@ class ColorSetSocket(MantisSocket):
                 property='normal_color',)
             layout.prop( text='', data=self,
                         property='selected_color',)
+        if self.node.bl_idname == 'InputColorSetPallete':
+            ops_props = layout.operator('mantis.color_pallete_socket_remove')
+            ops_props.tree_invoked = self.node.id_data.name
+            ops_props.node_invoked = self.node.name
+            ops_props.socket_invoked = self.identifier
+                
     def draw_color(self, context, node):
         return self.color
     @classmethod