Files
DamnSimplePoseLibrary/gui.py

191 lines
8.4 KiB
Python

import bpy
from .common import *
class DATA_PT_YaplPanel(bpy.types.Panel):
bl_label = "Yet Another Pose Library"
bl_id = "DATA_PT_YaplPanel"
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):
yapl_panel_layout = self.layout
yaplsettings = bpy.context.scene.yaplSettings
# Detect Armature object and parent
armature_layout = yapl_panel_layout.column(align=True)
active_obj = context.active_object
arm_object, pose_library = get_armature_data(context)
pose_library_action = get_armature_action(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="yapl.create_pose_library", unlink="yapl.unlink_pose_library")
elif pose_library_action and not pose_library:
armature_layout.template_ID(
arm_object.animation_data, "action", new="yapl.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(
"yapl.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="yapl.create_pose_library")
armature_layout.label(text="Pose Library is opened as Action")
armature_layout.label(text="Keyframes will affect pose")
armature_layout.operator(
"yapl.convert_pose_library", icon='PLUGIN', text="Unlink from Action")
# List poses in pose library
if pose_library:
pose_box_layout = yapl_panel_layout.column()
# Menu switcher
pose_box_menu_switcher_layout = pose_box_layout.row()
pose_box_menu_switcher_layout.prop(
yaplsettings, "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(
"yapl.browse_poses", icon='CON_ARMATURE', text="Browse")
if yaplsettings.new_menu == False:
quick_apply_layout.operator(
"yapl.apply_pose", icon='ARMATURE_DATA', text="Apply Pose").posename = pose_library.pose_markers.active.name
else:
quick_apply_layout.prop(yaplsettings,
"edit_mode", icon='GREASEPENCIL', text="Edit", toggle=True)
# New menu
if yaplsettings.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 yaplsettings.edit_mode == False:
row.label(text="", icon='PMARKER_ACT' if selected else 'PMARKER_SEL')
# Pose operator buttons
if yaplsettings.edit_mode == True:
row.operator('yapl.rename_pose', text=pm.name).posename = pm.name
else:
row.operator('yapl.apply_pose', text=pm.name).posename = pm.name
if yaplsettings.edit_mode == True:
movebuttondown = row.operator("yapl.move_pose", icon='TRIA_DOWN', text="")
movebuttondown.direction = "DOWN"
movebuttondown.posename = pm.name
movebuttonup = row.operator("yapl.move_pose", icon='TRIA_UP', text="")
movebuttonup.direction = "UP"
movebuttonup.posename = pm.name
row.operator("yapl.remove_pose", icon='REMOVE', text="").posename = pm.name
# Old menu
elif yaplsettings.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(
"yapl.remove_pose", icon='REMOVE', text="")
pose_ops_layout.operator(
"yapl.apply_pose", icon='ARMATURE_DATA', text=""
).posename = pose_library.pose_markers.active.name
pose_ops_layout.operator(
"yapl.move_pose", icon='TRIA_UP', text="").direction = "UP"
pose_ops_layout.operator(
"yapl.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="yapl.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 = get_armature_data(context)
yapl_add_menu_layout = self.layout
yapl_add_menu_layout.operator(
"yapl.add_pose", icon='ADD', text="Add New Pose")
if len(pose_library.pose_markers):
yapl_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 = get_armature_data(context)
yapl_replace_menu_layout = self.layout
for pm in pose_library.pose_markers:
op = yapl_replace_menu_layout.operator("yapl.add_pose", text=pm.name, icon="PMARKER")
op.replace = True
op.posename = pm.name
classes = (
DATA_PT_YaplPanel,
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)