(On Hold) Rework Properties UI Editor #159
@ -1518,17 +1518,26 @@ class CloudRig_UIElement(PropertyGroup):
|
||||
description="Operator Keyword Arguments, as a json dict",
|
||||
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(
|
||||
# Supported Types: Label, Row, Property(bool), Operator
|
||||
name="Icon",
|
||||
description="Icon",
|
||||
default='CHECKBOX_HLT',
|
||||
update=update_icons,
|
||||
)
|
||||
icon_false: StringProperty(
|
||||
# Supported Types: Property(bool)
|
||||
name="Icon False",
|
||||
description="Icon to display when this boolean property is False",
|
||||
default='CHECKBOX_DEHLT',
|
||||
update=update_icons,
|
||||
)
|
||||
|
||||
prop_owner_path: StringProperty(
|
||||
@ -1601,49 +1610,65 @@ class CloudRig_UIElement(PropertyGroup):
|
||||
return True
|
||||
if self.parent.element_type != 'PROPERTY':
|
||||
return True
|
||||
if not self.parent_values:
|
||||
return True
|
||||
|
||||
parent_value_str = str(self.parent.prop_value)
|
||||
if parent_value_str in [v.strip() for v in self.parent_values.split(",")]:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def draw_ui_element(self, context, layout):
|
||||
if not self.should_draw or not layout:
|
||||
def draw_ui_recursive(self, context, layouts):
|
||||
if not self.should_draw or not layouts:
|
||||
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':
|
||||
# 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.label(text=self.display_name)
|
||||
remove_op_ui = header
|
||||
if self.element_type == 'LABEL':
|
||||
layouts.append(layout)
|
||||
elif self.element_type == 'LABEL':
|
||||
layout = remove_op_ui = layout.row()
|
||||
if self.display_name:
|
||||
layout.label(text=self.display_name)
|
||||
if self.element_type == 'ROW':
|
||||
layout = remove_op_ui = parent_layout = layout.row()
|
||||
# if self.display_name:
|
||||
# layout.label(text=self.display_name)
|
||||
if self.element_type == 'PROPERTY':
|
||||
if not self.parent or self.parent.element_type != 'ROW':
|
||||
layout = remove_op_ui = layout.row()
|
||||
elif self.element_type == 'ROW':
|
||||
layout = remove_op_ui = layout.row()
|
||||
layouts.append(layout)
|
||||
elif self.element_type == 'PROPERTY':
|
||||
layout = remove_op_ui = layout.row(align=True)
|
||||
layouts.append(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()
|
||||
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)
|
||||
|
||||
if not layout:
|
||||
return
|
||||
for child in self.children:
|
||||
child.draw_ui_element(context, parent_layout)
|
||||
if layout:
|
||||
for child in self.children:
|
||||
child.draw_ui_recursive(context, layouts)
|
||||
if self.element_type == 'ROW' and child != self.children[-1]:
|
||||
layouts[-1].separator()
|
||||
|
||||
if self.rig.cloudrig.ui_edit_mode:
|
||||
remove_op_ui.operator(
|
||||
'object.cloudrig_ui_element_remove', text="", icon='X'
|
||||
).element_index = self.index
|
||||
|
||||
|
||||
def draw_property(self, context, layout):
|
||||
prop_owner, prop_value = self.prop_owner, self.prop_value
|
||||
if not prop_owner:
|
||||
@ -1725,7 +1750,10 @@ class CloudRig_UIElement(PropertyGroup):
|
||||
op_icon = self.icon
|
||||
if not self.icon or self.icon == 'NONE':
|
||||
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)
|
||||
return op_props
|
||||
|
||||
@ -1748,13 +1776,13 @@ class CLOUDRIG_PT_custom_ui(CLOUDRIG_PT_base):
|
||||
layout = self.layout
|
||||
layout.use_property_split = False
|
||||
layout.use_property_decorate = False
|
||||
layout = layout.column(align=True)
|
||||
col = layout.column(align=True)
|
||||
|
||||
rig = context.active_object # TODO
|
||||
|
||||
for elem in rig.cloudrig_ui:
|
||||
if not elem.parent:
|
||||
elem.draw_ui_element(context, layout)
|
||||
elem.draw_ui_recursive(context, [layout, col])
|
||||
|
||||
|
||||
#######################################
|
||||
|
@ -28,6 +28,7 @@ def draw_ui_editing(context, layout, ui_element, operator):
|
||||
# layout.prop(ui_element, 'prop_owner_path')
|
||||
# layout.prop(ui_element, 'is_custom_prop')
|
||||
|
||||
|
||||
def draw_parent_picking(context, layout, ui_element, operator):
|
||||
parent_row = layout.row()
|
||||
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:
|
||||
parent_row.prop(operator, 'create_new_ui', text="", icon='ADD')
|
||||
|
||||
|
||||
def draw_prop_editing(context, layout, ui_element, operator):
|
||||
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):
|
||||
if operator.use_batch_add:
|
||||
return
|
||||
op_box = layout.box().column()
|
||||
op_box.prop(operator.temp_kmi, 'idname', text="Operator")
|
||||
layout.prop(operator.temp_kmi, 'idname', text="Operator")
|
||||
operator.op_kwargs_dict = {}
|
||||
if operator.temp_kmi.idname:
|
||||
box = None
|
||||
op_rna = eval("bpy.ops." + operator.temp_kmi.idname).get_rna_type()
|
||||
for key, value in op_rna.properties.items():
|
||||
if key == 'rna_type':
|
||||
continue
|
||||
if not box:
|
||||
box = op_box.box().column(align=True)
|
||||
box.prop(operator.temp_kmi.properties, key)
|
||||
operator.op_kwargs_dict[key] = str(
|
||||
getattr(operator.temp_kmi.properties, key)
|
||||
)
|
||||
icons = UILayout.bl_rna.functions["prop"].parameters["icon"]
|
||||
op_box.prop_search(
|
||||
ui_element, 'icon', icons, 'enum_items', icon=ui_element.icon
|
||||
if not operator.temp_kmi.idname:
|
||||
return
|
||||
|
||||
box = None
|
||||
op_rna = eval("bpy.ops." + operator.temp_kmi.idname).get_rna_type()
|
||||
for key, value in op_rna.properties.items():
|
||||
if key == 'rna_type':
|
||||
continue
|
||||
if not box:
|
||||
box = layout.box().column(align=True)
|
||||
box.prop(operator.temp_kmi.properties, key)
|
||||
operator.op_kwargs_dict[key] = str(
|
||||
getattr(operator.temp_kmi.properties, key)
|
||||
)
|
||||
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')
|
||||
|
||||
@ -291,8 +294,8 @@ class UIElementAddMixin:
|
||||
self.temp_kmi = context.window_manager.keyconfigs.default.keymaps[
|
||||
'Info'
|
||||
].keymap_items.new('', 'NUMPAD_5', 'PRESS')
|
||||
if self.bl_idname:
|
||||
self.temp_kmi.idname = self.bl_idname
|
||||
if self.ui_element.bl_idname:
|
||||
self.temp_kmi.idname = self.ui_element.bl_idname
|
||||
if self.ui_element.op_kwargs:
|
||||
op_props = self.temp_kmi.properties
|
||||
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.display_name = self.new_label_name
|
||||
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 (
|
||||
temp_ui_element.element_type in {'PANEL', 'LABEL', 'ROW'}
|
||||
and temp_ui_element.display_name.strip() == ""
|
||||
):
|
||||
self.report({'ERROR'}, "This UI element must have a display name!")
|
||||
return {'CANCELLED'}
|
||||
row = rig.cloudrig_ui.add()
|
||||
row.parent = parent
|
||||
row.element_type = 'ROW'
|
||||
row.display_name = self.new_row_name or temp_ui_element.prop_name
|
||||
parent = row
|
||||
|
||||
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.element_type = self.element_type
|
||||
|
||||
if self.element_type == 'OPERATOR':
|
||||
new_ui_element.bl_idname = self.temp_kmi.idname
|
||||
|
||||
wipe_parent_selector(context)
|
||||
del rig['cloudrig_ui_new_element']
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user