(On Hold) Rework Properties UI Editor #159

Open
Demeter Dzadik wants to merge 10 commits from new-props-ux into master

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
2 changed files with 78 additions and 51 deletions
Showing only changes of commit 2cc2c3c54c - Show all commits

View File

@ -1518,17 +1518,26 @@ class CloudRig_UIElement(PropertyGroup):
description="Operator Keyword Arguments, as a json dict", description="Operator Keyword Arguments, as a json dict",
default="{}", default="{}",
) )
def update_icons(self, context):
# Prevent illegal icon values when users clicks X button.
if self.icon == '':
self.icon = 'BLANK1'
if self.icon_false == '':
self.icon_false = 'BLANK1'
icon: StringProperty( icon: StringProperty(
# Supported Types: Label, Row, Property(bool), Operator # Supported Types: Label, Row, Property(bool), Operator
name="Icon", name="Icon",
description="Icon", description="Icon",
default='CHECKBOX_HLT', default='CHECKBOX_HLT',
update=update_icons,
) )
icon_false: StringProperty( icon_false: StringProperty(
# Supported Types: Property(bool) # Supported Types: Property(bool)
name="Icon False", name="Icon False",
description="Icon to display when this boolean property is False", description="Icon to display when this boolean property is False",
default='CHECKBOX_DEHLT', default='CHECKBOX_DEHLT',
update=update_icons,
) )
prop_owner_path: StringProperty( prop_owner_path: StringProperty(
@ -1601,49 +1610,65 @@ class CloudRig_UIElement(PropertyGroup):
return True return True
if self.parent.element_type != 'PROPERTY': if self.parent.element_type != 'PROPERTY':
return True return True
if not self.parent_values:
return True
parent_value_str = str(self.parent.prop_value) parent_value_str = str(self.parent.prop_value)
if parent_value_str in [v.strip() for v in self.parent_values.split(",")]: if parent_value_str in [v.strip() for v in self.parent_values.split(",")]:
return True return True
return False return False
def draw_ui_element(self, context, layout): def draw_ui_recursive(self, context, layouts):
if not self.should_draw or not layout: if not self.should_draw or not layouts:
return return
parent_layout = remove_op_ui = layout layout = layouts[-1]
if self.parent and self.parent.element_type == 'PROPERTY':
layouts.pop()
layout = layouts[-1]
remove_op_ui = layout
if self.element_type == 'PANEL': if self.element_type == 'PANEL':
# TODO: Figure out how to allow elements to be drawn in the header. # TODO: Figure out how to allow elements to be drawn in the header.
header, layout = layout.panel(idname=str(self.index) + self.display_name) header, layout = layout.panel(idname=str(self.index) + self.display_name)
header.label(text=self.display_name) header.label(text=self.display_name)
remove_op_ui = header remove_op_ui = header
if self.element_type == 'LABEL': layouts.append(layout)
elif self.element_type == 'LABEL':
layout = remove_op_ui = layout.row() layout = remove_op_ui = layout.row()
if self.display_name: if self.display_name:
layout.label(text=self.display_name) layout.label(text=self.display_name)
if self.element_type == 'ROW': elif self.element_type == 'ROW':
layout = remove_op_ui = parent_layout = layout.row() layout = remove_op_ui = layout.row()
# if self.display_name: layouts.append(layout)
# layout.label(text=self.display_name) elif self.element_type == 'PROPERTY':
if self.element_type == 'PROPERTY': layout = remove_op_ui = layout.row(align=True)
if not self.parent or self.parent.element_type != 'ROW': layouts.append(layout)
layout = remove_op_ui = layout.row()
self.draw_property(context, layout) self.draw_property(context, layout)
if any([child.should_draw for child in self.children]): if any([child.should_draw and child.element_type!='OPERATOR' for child in self.children]):
layout = layout.box() layout = layout.box()
if self.element_type == 'OPERATOR': layouts.append(layout)
elif self.element_type == 'OPERATOR':
if not self.parent or self.parent.element_type != 'ROW':
layout = remove_op_ui = layout.row(align=True)
layouts.append(layout)
self.draw_operator(context, layout) self.draw_operator(context, layout)
if not layout: if layout:
return for child in self.children:
for child in self.children: child.draw_ui_recursive(context, layouts)
child.draw_ui_element(context, parent_layout) if self.element_type == 'ROW' and child != self.children[-1]:
layouts[-1].separator()
if self.rig.cloudrig.ui_edit_mode: if self.rig.cloudrig.ui_edit_mode:
remove_op_ui.operator( remove_op_ui.operator(
'object.cloudrig_ui_element_remove', text="", icon='X' 'object.cloudrig_ui_element_remove', text="", icon='X'
).element_index = self.index ).element_index = self.index
def draw_property(self, context, layout): def draw_property(self, context, layout):
prop_owner, prop_value = self.prop_owner, self.prop_value prop_owner, prop_value = self.prop_owner, self.prop_value
if not prop_owner: if not prop_owner:
@ -1725,7 +1750,10 @@ class CloudRig_UIElement(PropertyGroup):
op_icon = self.icon op_icon = self.icon
if not self.icon or self.icon == 'NONE': if not self.icon or self.icon == 'NONE':
op_icon = 'BLANK1' op_icon = 'BLANK1'
op_props = layout.operator(self.bl_idname, text=self.display_name, icon=op_icon) display_name = self.display_name
if self.parent and self.parent.element_type == 'PROPERTY':
display_name = ""
op_props = layout.operator(self.bl_idname, text=display_name, icon=op_icon)
feed_op_props(op_props, self.op_kwargs) feed_op_props(op_props, self.op_kwargs)
return op_props return op_props
@ -1748,13 +1776,13 @@ class CLOUDRIG_PT_custom_ui(CLOUDRIG_PT_base):
layout = self.layout layout = self.layout
layout.use_property_split = False layout.use_property_split = False
layout.use_property_decorate = False layout.use_property_decorate = False
layout = layout.column(align=True) col = layout.column(align=True)
rig = context.active_object # TODO rig = context.active_object # TODO
for elem in rig.cloudrig_ui: for elem in rig.cloudrig_ui:
if not elem.parent: if not elem.parent:
elem.draw_ui_element(context, layout) elem.draw_ui_recursive(context, [layout, col])
####################################### #######################################

View File

@ -28,6 +28,7 @@ def draw_ui_editing(context, layout, ui_element, operator):
# layout.prop(ui_element, 'prop_owner_path') # layout.prop(ui_element, 'prop_owner_path')
# layout.prop(ui_element, 'is_custom_prop') # layout.prop(ui_element, 'is_custom_prop')
def draw_parent_picking(context, layout, ui_element, operator): def draw_parent_picking(context, layout, ui_element, operator):
parent_row = layout.row() parent_row = layout.row()
if operator.create_new_ui: if operator.create_new_ui:
@ -41,6 +42,7 @@ def draw_parent_picking(context, layout, ui_element, operator):
if context.scene.cloudrig_ui_parent_selector: if context.scene.cloudrig_ui_parent_selector:
parent_row.prop(operator, 'create_new_ui', text="", icon='ADD') parent_row.prop(operator, 'create_new_ui', text="", icon='ADD')
def draw_prop_editing(context, layout, ui_element, operator): def draw_prop_editing(context, layout, ui_element, operator):
rig = find_cloudrig(context) rig = find_cloudrig(context)
@ -99,25 +101,26 @@ def draw_prop_editing(context, layout, ui_element, operator):
def draw_op_editing(context, layout, ui_element, operator): def draw_op_editing(context, layout, ui_element, operator):
if operator.use_batch_add: if operator.use_batch_add:
return return
op_box = layout.box().column() layout.prop(operator.temp_kmi, 'idname', text="Operator")
op_box.prop(operator.temp_kmi, 'idname', text="Operator")
operator.op_kwargs_dict = {} operator.op_kwargs_dict = {}
if operator.temp_kmi.idname: if not operator.temp_kmi.idname:
box = None return
op_rna = eval("bpy.ops." + operator.temp_kmi.idname).get_rna_type()
for key, value in op_rna.properties.items(): box = None
if key == 'rna_type': op_rna = eval("bpy.ops." + operator.temp_kmi.idname).get_rna_type()
continue for key, value in op_rna.properties.items():
if not box: if key == 'rna_type':
box = op_box.box().column(align=True) continue
box.prop(operator.temp_kmi.properties, key) if not box:
operator.op_kwargs_dict[key] = str( box = layout.box().column(align=True)
getattr(operator.temp_kmi.properties, key) box.prop(operator.temp_kmi.properties, key)
) operator.op_kwargs_dict[key] = str(
icons = UILayout.bl_rna.functions["prop"].parameters["icon"] getattr(operator.temp_kmi.properties, key)
op_box.prop_search(
ui_element, 'icon', icons, 'enum_items', icon=ui_element.icon
) )
icons = UILayout.bl_rna.functions["prop"].parameters["icon"]
layout.prop_search(
ui_element, 'icon', icons, 'enum_items', icon=ui_element.icon
)
layout.prop(ui_element, 'display_name') layout.prop(ui_element, 'display_name')
@ -291,8 +294,8 @@ class UIElementAddMixin:
self.temp_kmi = context.window_manager.keyconfigs.default.keymaps[ self.temp_kmi = context.window_manager.keyconfigs.default.keymaps[
'Info' 'Info'
].keymap_items.new('', 'NUMPAD_5', 'PRESS') ].keymap_items.new('', 'NUMPAD_5', 'PRESS')
if self.bl_idname: if self.ui_element.bl_idname:
self.temp_kmi.idname = self.bl_idname self.temp_kmi.idname = self.ui_element.bl_idname
if self.ui_element.op_kwargs: if self.ui_element.op_kwargs:
op_props = self.temp_kmi.properties op_props = self.temp_kmi.properties
feed_op_props(op_props, self.ui_element.op_kwargs) feed_op_props(op_props, self.ui_element.op_kwargs)
@ -330,19 +333,12 @@ class CLOUDRIG_OT_ui_element_add(UIElementAddMixin, Operator):
label.element_type = 'LABEL' label.element_type = 'LABEL'
label.display_name = self.new_label_name label.display_name = self.new_label_name
parent = label parent = label
if self.new_row_name:
row = rig.cloudrig_ui.add()
row.parent = parent
row.element_type = 'ROW'
row.display_name = self.new_row_name
parent = row
if ( row = rig.cloudrig_ui.add()
temp_ui_element.element_type in {'PANEL', 'LABEL', 'ROW'} row.parent = parent
and temp_ui_element.display_name.strip() == "" row.element_type = 'ROW'
): row.display_name = self.new_row_name or temp_ui_element.prop_name
self.report({'ERROR'}, "This UI element must have a display name!") parent = row
return {'CANCELLED'}
new_ui_element = rig.cloudrig_ui.add() new_ui_element = rig.cloudrig_ui.add()
@ -355,6 +351,9 @@ class CLOUDRIG_OT_ui_element_add(UIElementAddMixin, Operator):
new_ui_element.parent = parent new_ui_element.parent = parent
new_ui_element.element_type = self.element_type new_ui_element.element_type = self.element_type
if self.element_type == 'OPERATOR':
new_ui_element.bl_idname = self.temp_kmi.idname
wipe_parent_selector(context) wipe_parent_selector(context)
del rig['cloudrig_ui_new_element'] del rig['cloudrig_ui_new_element']