Skip to content

Commit

Permalink
feat: hide some operators in edit mode and add some notify for groupi…
Browse files Browse the repository at this point in the history
…ng oper.

- now grouping, ungrouping clear groups operators will show a report at the bottom of blender to indicate their work have done.
- disable fix material, 3ds max align, select by virtools group operators in edit mode to prevent any possible undefined behavior.
  • Loading branch information
yyc12345 committed Apr 22, 2024
1 parent c58af8c commit 84e7e83
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
5 changes: 4 additions & 1 deletion bbp_ng/OP_MTL_fix_material.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import bpy
from . import UTIL_functions
from . import PROP_virtools_material, PROP_preferences

class BBP_OT_fix_all_material(bpy.types.Operator):
Expand All @@ -9,7 +10,9 @@ class BBP_OT_fix_all_material(bpy.types.Operator):

@classmethod
def poll(cls, context):
return PROP_preferences.get_raw_preferences().has_valid_blc_tex_folder()
# only enable this when plugin have a valid ballance texture folder
# and we are in object mode
return PROP_preferences.get_raw_preferences().has_valid_blc_tex_folder() and UTIL_functions.is_in_object_mode()

def invoke(self, context, event):
wm = context.window_manager
Expand Down
23 changes: 13 additions & 10 deletions bbp_ng/OP_OBJECT_legacy_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,25 @@ class BBP_PG_legacy_align_history(bpy.types.PropertyGroup):
align_x: bpy.props.BoolProperty(
name = "X Position",
default = False,
)
) # type: ignore
align_y: bpy.props.BoolProperty(
name = "Y Position",
default = False,
)
) # type: ignore
align_z: bpy.props.BoolProperty(
name = "Z Position",
default = False,
)
) # type: ignore
current_align_mode: bpy.props.EnumProperty(
name = "Current Object (Active Object)",
items = _g_EnumHelper_AlignMode.generate_items(),
default = _g_EnumHelper_AlignMode.to_selection(AlignMode.AxisCenter),
)
) # type: ignore
target_align_mode: bpy.props.EnumProperty(
name = "Target Objects (Other Objects)",
items = _g_EnumHelper_AlignMode.generate_items(),
default = _g_EnumHelper_AlignMode.to_selection(AlignMode.AxisCenter),
)
) # type: ignore

#endregion

Expand Down Expand Up @@ -109,21 +109,21 @@ def apply_flag_updated(self, context):
options = {'HIDDEN', 'SKIP_SAVE'},
default = True, # default True value to make it as a "light" button, not a grey one.
update = apply_flag_updated,
)
) # type: ignore
recursive_hinder: bpy.props.BoolProperty(
name = "Recursive Hinder",
description = "An internal flag to prevent the loop calling to apply_flags's updator.",
options = {'HIDDEN', 'SKIP_SAVE'},
default = False,
)
) # type: ignore
align_history : bpy.props.CollectionProperty(
name = "Historys",
description = "Align history.",
type = BBP_PG_legacy_align_history,
)
) # type: ignore

@classmethod
def poll(self, context):
def poll(cls, context):
return _check_align_requirement()

def invoke(self, context, event):
Expand Down Expand Up @@ -180,10 +180,13 @@ def draw(self, context):
#region Core Functions

def _check_align_requirement() -> bool:
# if we are not in object mode, do not do legacy align
if not UTIL_functions.is_in_object_mode():
return False

# check current obj
if bpy.context.active_object is None:
return False

# check target obj with filter of current obj
length = len(bpy.context.selected_objects)
if bpy.context.active_object in bpy.context.selected_objects:
Expand Down
15 changes: 11 additions & 4 deletions bbp_ng/OP_OBJECT_virtools_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ class BBP_OT_select_object_by_virtools_group(bpy.types.Operator, PROP_virtools_g
description = "Selection mode",
items = _g_EnumHelper_SelectMode.generate_items(),
default = _g_EnumHelper_SelectMode.to_selection(SelectMode.Intersect)
)
) # type: ignore

@classmethod
def poll(cls, context):
return UTIL_functions.is_in_object_mode()

def invoke(self, context, event):
wm = context.window_manager
Expand Down Expand Up @@ -119,7 +123,7 @@ class BBP_OT_add_objects_virtools_group(bpy.types.Operator, PROP_virtools_group.
bl_options = {'UNDO'}

@classmethod
def poll(self, context):
def poll(cls, context):
return len(bpy.context.selected_objects) != 0

def invoke(self, context, event):
Expand All @@ -131,6 +135,7 @@ def execute(self, context):
for obj in bpy.context.selected_objects:
with PROP_virtools_group.VirtoolsGroupsHelper(obj) as gp:
gp.add_group(group_name)
self.report({'INFO'}, "Grouping objects successfully.")
return {'FINISHED'}

def draw(self, context):
Expand All @@ -143,7 +148,7 @@ class BBP_OT_rm_objects_virtools_group(bpy.types.Operator, PROP_virtools_group.S
bl_options = {'UNDO'}

@classmethod
def poll(self, context):
def poll(cls, context):
return len(bpy.context.selected_objects) != 0

def invoke(self, context, event):
Expand All @@ -155,6 +160,7 @@ def execute(self, context):
for obj in bpy.context.selected_objects:
with PROP_virtools_group.VirtoolsGroupsHelper(obj) as gp:
gp.remove_group(group_name)
self.report({'INFO'}, "Ungrouping objects successfully.")
return {'FINISHED'}

def draw(self, context):
Expand All @@ -167,7 +173,7 @@ class BBP_OT_clear_objects_virtools_group(bpy.types.Operator):
bl_options = {'UNDO'}

@classmethod
def poll(self, context):
def poll(cls, context):
return len(bpy.context.selected_objects) != 0

def invoke(self, context, event):
Expand All @@ -179,6 +185,7 @@ def execute(self, context):
for obj in bpy.context.selected_objects:
with PROP_virtools_group.VirtoolsGroupsHelper(obj) as gp:
gp.clear_groups()
self.report({'INFO'}, "Clear objects groups successfully.")
return {'FINISHED'}

#endregion
Expand Down
10 changes: 10 additions & 0 deletions bbp_ng/UTIL_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ def select_certain_objects(objs: tuple[bpy.types.Object, ...]) -> None:
# select first object as active object
bpy.context.view_layer.objects.active = objs[0]

def is_in_object_mode() -> bool:
# get active object from context
obj = bpy.context.active_object

# if there is no active object, we think it is in object mode
if obj is None: return True

# simply check active object mode
return obj.mode == 'OBJECT'

class EnumPropHelper():
"""
These class contain all functions related to EnumProperty, including generating `items`,
Expand Down

0 comments on commit 84e7e83

Please sign in to comment.