import bpy from .common import * class DATA_PT_DSPLPanel(bpy.types.Panel): bl_label = "Damn Simple Pose Library" bl_id = "DATA_PT_DSPLPanel" bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = 'Pose' @classmethod def poll(cls, context): return len(bpy.context.selected_objects) def draw(self, context): dspl_panel_layout = self.layout dsplsettings = bpy.context.scene.dsplSettings # Detect Armature object and parent armature_layout = dspl_panel_layout.column(align=True) active_obj = context.active_object arm_object, pose_library = getArmatureData(context) pose_library_action = getArmatureAction(context) if arm_object: if arm_object == active_obj: armature_layout.label(text=arm_object.name + " (Active)") elif arm_object == active_obj.parent: armature_layout.label(text=arm_object.name + " (Parent)") # Attach or create pose library if pose_library or pose_library_action: if pose_library and not pose_library_action: armature_layout.template_ID( arm_object, "pose_library", new="dspl.create_pose_library", unlink="dspl.unlink_pose_library") elif pose_library_action and not pose_library: armature_layout.template_ID( arm_object.animation_data, "action", new="dspl.create_pose_library") armature_layout.label( text="Pose Library detected as Action") armature_layout.label( text="You should convert to avoid problems") armature_layout.operator( "dspl.convert_pose_library", icon='PLUGIN', text="Convert to Pose Library") elif pose_library and pose_library_action: armature_layout.template_ID( arm_object, "pose_library", new="dspl.create_pose_library") armature_layout.label(text="Pose Library is opened as Action") armature_layout.label(text="Keyframes will affect pose") armature_layout.operator( "dspl.convert_pose_library", icon='PLUGIN', text="Unlink from Action") # List poses in pose library if pose_library: pose_box_layout = dspl_panel_layout.column() # Menu switcher pose_box_menu_switcher_layout = pose_box_layout.row() pose_box_menu_switcher_layout.prop( dsplsettings, "new_menu", icon='PMARKER_ACT', text="New Menu", toggle=True) # Quick controls quick_pose_controls_layout = pose_box_layout.column() quick_pose_controls_layout.menu( OBJECT_MT_AddPoseMenu.bl_idname, icon='ADD', text="New Pose") if pose_library.pose_markers.active: quick_apply_layout = quick_pose_controls_layout.split( align=True) quick_apply_layout.operator( "dspl.browse_poses", icon='CON_ARMATURE', text="Browse") if dsplsettings.new_menu == False: quick_apply_layout.operator( "dspl.apply_pose", icon='ARMATURE_DATA', text="Apply Pose").posename = pose_library.pose_markers.active.name else: quick_apply_layout.prop(dsplsettings, "edit_mode", icon='GREASEPENCIL', text="Edit", toggle=True) # New menu if dsplsettings.new_menu == True: pose_button_layout = pose_box_layout.row() pose_button_entries_layout = pose_button_layout.column(align=True) for pm in pose_library.pose_markers: row = pose_button_entries_layout.row(align=True) # Selected indicator selected = pm.frame == pose_library.pose_markers.active.frame if dsplsettings.edit_mode == False: row.label(text="", icon='PMARKER_ACT' if selected else 'PMARKER_SEL') # Pose operator buttons if dsplsettings.edit_mode == True: row.operator('dspl.rename_pose', text=pm.name).posename = pm.name else: row.operator('dspl.apply_pose', text=pm.name).posename = pm.name if dsplsettings.edit_mode == True: movebuttondown = row.operator("dspl.move_pose", icon='TRIA_DOWN', text="") movebuttondown.direction = "DOWN" movebuttondown.posename = pm.name movebuttonup = row.operator("dspl.move_pose", icon='TRIA_UP', text="") movebuttonup.direction = "UP" movebuttonup.posename = pm.name row.operator("dspl.remove_pose", icon='REMOVE', text="").posename = pm.name # Old menu elif dsplsettings.new_menu == False: pose_list_layout = pose_box_layout.column() # Pose list pose_list_entries_layout = pose_list_layout.row() pose_list_entries_layout.template_list("UI_UL_list","pose_markers", pose_library, "pose_markers", pose_library.pose_markers, "active_index", rows=4) # Pose operators pose_ops_layout = pose_list_entries_layout.column(align=True) pose_ops_layout.operator( "wm.call_menu", icon='ADD', text="").name = "OBJECT_MT_AddPoseMenu" if pose_library.pose_markers.active: pose_ops_layout.operator( "dspl.remove_pose", icon='REMOVE', text="") pose_ops_layout.operator( "dspl.apply_pose", icon='ARMATURE_DATA', text="" ).posename = pose_library.pose_markers.active.name pose_ops_layout.operator( "dspl.move_pose", icon='TRIA_UP', text="").direction = "UP" pose_ops_layout.operator( "dspl.move_pose", icon='TRIA_DOWN', text="").direction = "DOWN" else: armature_layout.label( text="No Action or Pose Library detected") armature_layout.template_ID( arm_object, "pose_library", new="dspl.create_pose_library") else: armature_layout.label(text="No armature or parent selected") class OBJECT_MT_AddPoseMenu(bpy.types.Menu): bl_idname = "OBJECT_MT_AddPoseMenu" bl_label = "Add Pose" def draw(self, context): arm_object, pose_library = getArmatureData(context) dspl_add_menu_layout = self.layout dspl_add_menu_layout.operator( "dspl.add_pose", icon='ADD', text="Add New Pose") if len(pose_library.pose_markers): dspl_add_menu_layout.menu( "OBJECT_MT_ReplacePoseMenu", text="Replace Existing Pose", icon="DECORATE_OVERRIDE") class OBJECT_MT_ReplacePoseMenu(bpy.types.Menu): bl_idname = "OBJECT_MT_ReplacePoseMenu" bl_label = "Add Pose" def draw(self, context): arm_object, pose_library = getArmatureData(context) dspl_replace_menu_layout = self.layout for pm in pose_library.pose_markers: op = dspl_replace_menu_layout.operator("dspl.add_pose", text=pm.name, icon="PMARKER") op.replace = True op.posename = pm.name classes = ( DATA_PT_DSPLPanel, OBJECT_MT_AddPoseMenu, OBJECT_MT_ReplacePoseMenu, ) def register(): from bpy.utils import register_class for cls in classes: register_class(cls) def unregister(): from bpy.utils import unregister_class for cls in classes: unregister_class(cls)