Browse Source

UI: Mantis in Add Armature and Import Menu

Joseph Brandenburg 2 months ago
parent
commit
5d6bfb30b3
3 changed files with 39 additions and 10 deletions
  1. 4 1
      __init__.py
  2. 29 6
      menu_classes.py
  3. 6 3
      preferences.py

+ 4 - 1
__init__.py

@@ -342,7 +342,8 @@ def on_undo_post_handler(scene): # the undo will trigger a depsgraph update
             # set the tree to invalid to trigger a tree update
             # since the context data is wiped by an undo.
 
-from .menu_classes import node_context_menu_draw, node_add_menu_draw
+from .menu_classes import (node_context_menu_draw, node_add_menu_draw,
+                           armature_add_menu_draw, import_menu_draw)
 
 def register():
     from bpy.utils import register_class
@@ -357,6 +358,8 @@ def register():
     nodeitems_utils.register_node_categories('SchemaNodeCategories', schema_categories)
     bpy.types.NODE_MT_context_menu.append(node_context_menu_draw)
     bpy.types.NODE_MT_add.append(node_add_menu_draw)
+    bpy.types.VIEW3D_MT_armature_add.append(armature_add_menu_draw)
+    bpy.types.TOPBAR_MT_file_import.append(import_menu_draw)
 
 
 

+ 29 - 6
menu_classes.py

@@ -4,9 +4,9 @@ def TellClasses():
     return [
         MantisActiveTreePanel,
         MantisNodeGroupsMenu,
+        MantisAddArmature,
     ]
 
-
 # Function to append submenu to context menu
 def node_context_menu_draw(self, context):
     layout = self.layout
@@ -18,15 +18,21 @@ def node_context_menu_draw(self, context):
     layout.operator("mantis.import_from_component_library")
     # layout.menu('NODE_MT_context_menu_mantis')
 
-
 # Function to append submenu to node add menu
 def node_add_menu_draw(self, context):
-    # NODE_MT_add
     layout = self.layout
     layout.separator()  # Optional: Adds a separator before your submenu
     layout.menu("NODE_MT_add_mantis_groups")
 
-    # layout.menu('NODE_MT_context_menu_mantis')
+# Function to append Mantis Component Packs to armature add menu
+def armature_add_menu_draw(self, context):
+    layout = self.layout
+    layout.separator()
+    layout.menu("VIEW3D_MT_armature_add_mantis_packs")
+
+# Function to append Mantis to Import Menu
+def import_menu_draw(self, context):
+    self.layout.operator("mantis.import_tree")
 
 class MantisNodeGroupsMenu(Menu):
     """Menu to show available node groups"""
@@ -60,8 +66,25 @@ class MantisNodeGroupsMenu(Menu):
                 operator_settings.node_group_tree_name=ng.name
                 operator_settings.tree_invoked = node_tree.name
 
-
-
+class MantisAddArmature(Menu):
+    """Menu to show the user's component pack library in the Add Armature menu"""
+    bl_idname= "VIEW3D_MT_armature_add_mantis_packs"
+    bl_label = "Mantis Rigs"
+    def draw(self, context):
+        # start showing the mantis packs
+        from .preferences import get_bl_addon_object
+        bl_mantis_addon = get_bl_addon_object()
+        if bl_mantis_addon:
+            components_path = bl_mantis_addon.preferences.ComponentsLibraryFolder
+            # now we're clear to do the menu function
+            layout = self.layout
+            from .utilities import get_component_library_items
+            component_items = get_component_library_items()
+            for component_item in component_items:
+                # how to "EXEC_DEFAULT" here?
+                operator_settings = layout.operator( operator="mantis.import_tree_no_menu", text=component_item[1])
+                from os import path as os_path
+                operator_settings.filepath = os_path.join(components_path, component_item[0])
 
 class MantisActiveTreePanel(Panel):
     """N-Panel menu for Mantis"""

+ 6 - 3
preferences.py

@@ -81,7 +81,11 @@ class MantisPreferences(bpy.types.AddonPreferences):
         description = "Location of .rig files to place in the Add Armature menu.",
         subtype = 'FILE_PATH',
         default = os.path.join(dir_path, 'widgets'),)
-    ImportComponents:bpy.props.BoolProperty(default=False)
+    ComponentsAutoLoadFolder:bpy.props.StringProperty(
+        name = "Component Autoload Folder",
+        description = "Location of .rig files to load automatically.",
+        subtype = 'FILE_PATH',
+        default = os.path.join(dir_path, 'widgets'),)
     
     def draw(self, context):
         layout = self.layout
@@ -90,5 +94,4 @@ class MantisPreferences(bpy.types.AddonPreferences):
         layout.prop(self, "WidgetDefaultCollection")
         layout.prop(self, "ComponentsLibraryFolder", icon='FILE_FOLDER')
         layout.prop(self, "CurveDefaultCollection")
-        layout.prop(self, "MetaArmatureDefaultCollection")
-        layout.prop(self, "ImportComponents")
+        layout.prop(self, "MetaArmatureDefaultCollection")