Files
DamnSimplePoseLibrary/gui.py
2024-11-23 13:23:42 -06:00

184 lines
8.4 KiB
Python

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 = getArmatureObject(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
pose_library_dspl = getDsplAction(context)
pose_library_action = getArmatureAction(context)
if pose_library_dspl or pose_library_action:
if pose_library_dspl and not pose_library_action:
active_pose_library = pose_library_dspl
armature_layout.template_ID(
arm_object.dspl, "pose_library", new="dspl.create_pose_library", unlink="dspl.unlink_pose_library")
elif pose_library_action and not pose_library_dspl:
active_pose_library = pose_library_action
armature_layout.template_ID(
arm_object.animation_data, "action", new="dspl.create_pose_library")
armature_layout.label(
text="Legacy Pose Library detected.")
armature_layout.label(
text="You may convert to avoid problems")
armature_layout.operator(
"dspl.convert_pose_library", icon='PLUGIN', text="Convert to DSPL")
elif pose_library_action and pose_library_dspl:
armature_layout.template_ID(
arm_object.dspl, "pose_library", new="dspl.create_pose_library")
armature_layout.label(text="Double pose configuration!!")
armature_layout.label(text="You should not proceed")
armature_layout.operator(
"dspl.convert_pose_library", icon='PLUGIN', text="Convert to DSPL")
active_pose_library = pose_library_dspl
# List poses in pose library
if active_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 active_pose_library.pose_markers.active:
quick_apply_layout = quick_pose_controls_layout.split(
align=True)
quick_apply_layout.prop(arm_object.dsplvars,
"only_selected", icon='GROUP_BONE', text="Selected", toggle=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 = active_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 active_pose_library.pose_markers:
row = pose_button_entries_layout.row(align=True)
# Selected indicator
selected = pm.frame == active_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",
active_pose_library, "pose_markers",
active_pose_library.pose_markers, "active_index", rows=4)
# Pose operators
pose_ops_layout = pose_list_entries_layout.column(align=True)
pose_ops_layout.operator(
"dspl.draw_new_pose_menu", icon='ADD', text="")
if active_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 = active_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.dspl, "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 = getArmatureObject(context)
action_object = getPoseLib(context)
dspl_add_menu_layout = self.layout
dspl_add_menu_layout.operator(
"dspl.draw_new_pose_menu", icon='DECORATE_DRIVER', text="Add New Pose")
if action_object.pose_markers.active:
dspl_add_menu_layout.operator(
"dspl.add_pose", icon='DECORATE_OVERRIDE', text="Replace Existing Pose").replace = True
classes = (
DATA_PT_DSPLPanel,
OBJECT_MT_AddPoseMenu,
)
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)