diff --git a/ballance_blender_plugin/BMFILE_export.py b/ballance_blender_plugin/BMFILE_export.py index f83c638..1fdb6e3 100644 --- a/ballance_blender_plugin/BMFILE_export.py +++ b/ballance_blender_plugin/BMFILE_export.py @@ -44,7 +44,7 @@ class BALLANCE_OT_export_bm(bpy.types.Operator, bpy_extras.io_utils.ExportHelper def draw(self, context): layout = self.layout - layout.prop(self, "export_mode") + layout.prop(self, "export_mode", expand=True) if self.export_mode == 'COLLECTION': layout.prop(context.scene.BallanceBlenderPluginProperty, "collection_picker") elif self.export_mode == 'OBJECT': diff --git a/ballance_blender_plugin/OBJS_group_opers.py b/ballance_blender_plugin/OBJS_group_opers.py index dfd7967..1491945 100644 --- a/ballance_blender_plugin/OBJS_group_opers.py +++ b/ballance_blender_plugin/OBJS_group_opers.py @@ -1,33 +1,7 @@ import bpy from . import UTILS_constants, UTILS_functions, UTILS_virtools_prop -class common_group_name_props(bpy.types.Operator): - use_custom_name: bpy.props.BoolProperty( - name="Use Custom Name", - description="Whether use user defined group name.", - default=False, - ) - - group_name: bpy.props.EnumProperty( - name="Group Name", - description="Pick vanilla Ballance group name.", - items=tuple((x, x, "") for x in UTILS_constants.propsVtGroups_availableGroups), - ) - - custom_group_name: bpy.props.StringProperty( - name="Custom Group Name", - description="Input your custom group name.", - default="", - ) - - def get_group_name_string(self): - return str(self.custom_group_name if self.use_custom_name else self.group_name) - - def invoke(self, context, event): - wm = context.window_manager - return wm.invoke_props_dialog(self) - -class BALLANCE_OT_select_virtools_group(common_group_name_props): +class BALLANCE_OT_select_virtools_group(UTILS_virtools_prop.common_group_name_props): """Select objects by Virtools Group.""" bl_idname = "ballance.select_virtools_group" bl_label = "Select by Virtools Group" @@ -71,13 +45,9 @@ class BALLANCE_OT_select_virtools_group(common_group_name_props): row.prop(self, 'merge_selection') layout.separator() - layout.prop(self, 'use_custom_name') - if (self.use_custom_name): - layout.prop(self, 'custom_group_name') - else: - layout.prop(self, 'group_name') + self.parent_draw(layout) -class BALLANCE_OT_filter_virtools_group(common_group_name_props): +class BALLANCE_OT_filter_virtools_group(UTILS_virtools_prop.common_group_name_props): """Filter objects by Virtools Group.""" bl_idname = "ballance.filter_virtools_group" bl_label = "Filter by Virtools Group" @@ -123,15 +93,11 @@ class BALLANCE_OT_filter_virtools_group(common_group_name_props): row.prop(self, 'reverse_selection') layout.separator() - layout.prop(self, 'use_custom_name') - if (self.use_custom_name): - layout.prop(self, 'custom_group_name') - else: - layout.prop(self, 'group_name') + self.parent_draw(layout) -class BALLANCE_OT_ctx_set_group(common_group_name_props): +class BALLANCE_OT_ctx_set_group(UTILS_virtools_prop.common_group_name_props): """Grouping selected objects""" bl_idname = "ballance.ctx_set_group" bl_label = "Grouping Objects" @@ -162,13 +128,9 @@ class BALLANCE_OT_ctx_set_group(common_group_name_props): def draw(self, context): layout = self.layout - layout.prop(self, 'use_custom_name') - if (self.use_custom_name): - layout.prop(self, 'custom_group_name') - else: - layout.prop(self, 'group_name') + self.parent_draw(layout) -class BALLANCE_OT_ctx_unset_group(common_group_name_props): +class BALLANCE_OT_ctx_unset_group(UTILS_virtools_prop.common_group_name_props): """Ungrouping selected objects""" bl_idname = "ballance.ctx_unset_group" bl_label = "Ungrouping Objects" @@ -195,11 +157,7 @@ class BALLANCE_OT_ctx_unset_group(common_group_name_props): def draw(self, context): layout = self.layout - layout.prop(self, 'use_custom_name') - if (self.use_custom_name): - layout.prop(self, 'custom_group_name') - else: - layout.prop(self, 'group_name') + self.parent_draw(layout) class BALLANCE_OT_ctx_clear_group(bpy.types.Operator): """Clear Virtools Groups for selected objects""" diff --git a/ballance_blender_plugin/PROPS_virtools_group.py b/ballance_blender_plugin/PROPS_virtools_group.py index b22fc59..35bd9eb 100644 --- a/ballance_blender_plugin/PROPS_virtools_group.py +++ b/ballance_blender_plugin/PROPS_virtools_group.py @@ -1,55 +1,26 @@ import bpy from . import UTILS_constants, UTILS_functions, UTILS_virtools_prop -class BALLANCE_OT_add_virtools_group(bpy.types.Operator): +class BALLANCE_OT_add_virtools_group(UTILS_virtools_prop.common_group_name_props): """Add a Virtools Group for Active Object.""" bl_idname = "ballance.add_virtools_group" bl_label = "Add Virtools Group" bl_options = {'UNDO'} - use_custom_name: bpy.props.BoolProperty( - name="Use Custom Name", - description="Whether use user defined group name.", - default=False, - ) - - group_name: bpy.props.EnumProperty( - name="Group Name", - description="Pick vanilla Ballance group name.", - items=tuple((x, x, "") for x in UTILS_constants.propsVtGroups_availableGroups), - ) - - custom_group_name: bpy.props.StringProperty( - name="Custom Group Name", - description="Input your custom group name.", - default="", - ) - @classmethod def poll(self, context): return context.object is not None def execute(self, context): - # get name first - gotten_group_name = str(self.custom_group_name if self.use_custom_name else self.group_name) - # try adding obj = context.object - if not UTILS_virtools_prop.add_virtools_group_data(obj, gotten_group_name): + if not UTILS_virtools_prop.add_virtools_group_data(obj, self.get_group_name_string()): UTILS_functions.show_message_box(("Group name is duplicated!", ), "Duplicated Name", 'ERROR') return {'FINISHED'} - - def invoke(self, context, event): - wm = context.window_manager - return wm.invoke_props_dialog(self) - + def draw(self, context): - self.layout.prop(self, 'use_custom_name') - if (self.use_custom_name): - self.layout.prop(self, 'custom_group_name') - else: - self.layout.prop(self, 'group_name') + self.parent_draw(self.layout) class BALLANCE_OT_rm_virtools_group(bpy.types.Operator): diff --git a/ballance_blender_plugin/UTILS_virtools_prop.py b/ballance_blender_plugin/UTILS_virtools_prop.py index 02a062d..7027dd0 100644 --- a/ballance_blender_plugin/UTILS_virtools_prop.py +++ b/ballance_blender_plugin/UTILS_virtools_prop.py @@ -73,6 +73,40 @@ class BALLANCE_PG_virtools_group(bpy.types.PropertyGroup): default="" ) +class common_group_name_props(bpy.types.Operator): + group_name_source: bpy.props.EnumProperty( + name="Group Name Source", + items=(('DEFINED', "Predefined", "Pre-defined group name."), + ('CUSTOM', "Custom", "User specified group name."), + ), + ) + + group_name: bpy.props.EnumProperty( + name="Group Name", + description="Pick vanilla Ballance group name.", + items=tuple((x, x, "") for x in UTILS_constants.propsVtGroups_availableGroups), + ) + + custom_group_name: bpy.props.StringProperty( + name="Custom Group Name", + description="Input your custom group name.", + default="", + ) + + def parent_draw(self, parent_layout): + parent_layout.prop(self, 'group_name_source', expand=True) + if (self.group_name_source == 'CUSTOM'): + parent_layout.prop(self, 'custom_group_name') + else: + parent_layout.prop(self, 'group_name') + + def get_group_name_string(self): + return str(self.custom_group_name if self.group_name_source == 'CUSTOM' else self.group_name) + + def invoke(self, context, event): + wm = context.window_manager + return wm.invoke_props_dialog(self) + def get_virtools_material(mtl): return mtl.virtools_material diff --git a/ballance_blender_plugin/__init__.py b/ballance_blender_plugin/__init__.py index e29738a..b3891f6 100644 --- a/ballance_blender_plugin/__init__.py +++ b/ballance_blender_plugin/__init__.py @@ -85,18 +85,6 @@ class BALLANCE_MT_ThreeDViewerMenu(bpy.types.Menu): layout.operator(MODS_rail_uv.BALLANCE_OT_rail_uv.bl_idname) layout.operator(MODS_flatten_uv.BALLANCE_OT_flatten_uv.bl_idname) -class BALLANCE_MT_OutlinerMenu(bpy.types.Menu): - """Ballance rename operators""" - bl_idname = "BALLANCE_MT_OutlinerMenu" - bl_label = "Ballance" - - def draw(self, context): - layout = self.layout - - oprt = layout.operator(NAMES_rename_system.BALLANCE_OT_rename_by_group.bl_idname) - oprt = layout.operator(NAMES_rename_system.BALLANCE_OT_convert_name.bl_idname) - oprt = layout.operator(NAMES_rename_system.BALLANCE_OT_auto_grouping.bl_idname) - class BALLANCE_MT_AddFloorMenu(bpy.types.Menu): """Add Ballance floor""" bl_idname = "BALLANCE_MT_AddFloorMenu" @@ -144,7 +132,6 @@ classes = ( NAMES_rename_system.BALLANCE_OT_rename_by_group, NAMES_rename_system.BALLANCE_OT_convert_name, NAMES_rename_system.BALLANCE_OT_auto_grouping, - BALLANCE_MT_OutlinerMenu, UTILS_virtools_prop.BALLANCE_PG_virtools_material, UTILS_virtools_prop.BALLANCE_PG_virtools_group, @@ -182,7 +169,13 @@ def menu_func_ballance_add(self, context): layout.menu(BALLANCE_MT_AddFloorMenu.bl_idname, icon='MESH_CUBE') def menu_func_ballance_rename(self, context): layout = self.layout - layout.menu(BALLANCE_MT_OutlinerMenu.bl_idname) + layout.separator() + col = layout.column() + col.operator_context = 'INVOKE_DEFAULT' + col.label(text="Ballance") + col.operator(NAMES_rename_system.BALLANCE_OT_rename_by_group.bl_idname, icon='GREASEPENCIL') + col.operator(NAMES_rename_system.BALLANCE_OT_convert_name.bl_idname, icon='ARROW_LEFTRIGHT') + col.operator(NAMES_rename_system.BALLANCE_OT_auto_grouping.bl_idname, icon='GROUP') def menu_func_ballance_select(self, context): layout = self.layout layout.separator() @@ -220,10 +213,13 @@ def register(): bpy.types.VIEW3D_MT_editor_menus.prepend(menu_func_ballance_3d) bpy.types.VIEW3D_MT_add.append(menu_func_ballance_add) - bpy.types.OUTLINER_HT_header.append(menu_func_ballance_rename) + bpy.types.OUTLINER_MT_collection.append(menu_func_ballance_rename) bpy.types.VIEW3D_MT_select_object.append(menu_func_ballance_select) + bpy.types.VIEW3D_MT_object_context_menu.append(menu_func_ballance_grouping) + bpy.types.OUTLINER_MT_object.append(menu_func_ballance_grouping) # share the same menu + def unregister(): bpy.types.TOPBAR_MT_file_import.remove(menu_func_bm_import) @@ -231,10 +227,12 @@ def unregister(): bpy.types.VIEW3D_MT_editor_menus.remove(menu_func_ballance_3d) bpy.types.VIEW3D_MT_add.remove(menu_func_ballance_add) - bpy.types.OUTLINER_HT_header.remove(menu_func_ballance_rename) + bpy.types.OUTLINER_MT_collection.remove(menu_func_ballance_rename) bpy.types.VIEW3D_MT_select_object.remove(menu_func_ballance_select) + bpy.types.VIEW3D_MT_object_context_menu.remove(menu_func_ballance_grouping) + bpy.types.OUTLINER_MT_object.append(menu_func_ballance_grouping) UTILS_virtools_prop.unregister_props() del bpy.types.Scene.BallanceBlenderPluginProperty