From 1819997a673cee43bd006b98491e18467e813f75 Mon Sep 17 00:00:00 2001 From: Tristan Strathearn Date: Sat, 25 Jun 2022 15:32:53 +1000 Subject: [PATCH] fix: fix no predictions logic in the fast menu --- interface/fast_menu.py | 54 ++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/interface/fast_menu.py b/interface/fast_menu.py index 0e477aa..7b470ae 100644 --- a/interface/fast_menu.py +++ b/interface/fast_menu.py @@ -28,7 +28,8 @@ keys = [] icons = build_icon_lookup_table() - +SECTION_COUNT = 1 +NO_SECTION_COUNT = 0 class ND_MT_fast_menu(bpy.types.Menu): bl_label = "ND v%s — Fast (Predict)" % ('.'.join([str(v) for v in bl_info['version']])) @@ -38,19 +39,19 @@ class ND_MT_fast_menu(bpy.types.Menu): def draw(self, context): objs = context.selected_objects - if len(objs) == 0: - return self.draw_no_object_predictions(context) - - if len(objs) == 1: - return self.draw_single_object_predictions(context) + total_sections = 0 - if len(objs) == 2: - return self.draw_two_object_predictions(context) - - if len(objs) > 2: - return self.draw_many_object_predictions(context) - - return self.draw_no_predictions(context) + if len(objs) == 0: + total_sections += self.draw_no_object_predictions(context) + elif len(objs) == 1: + total_sections += self.draw_single_object_predictions(context) + elif len(objs) == 2: + total_sections += self.draw_two_object_predictions(context) + elif len(objs) > 2: + total_sections += self.draw_many_object_predictions(context) + + if total_sections == 0: + return self.draw_no_predictions(context) def draw_no_predictions(self, context): @@ -93,7 +94,7 @@ def draw_two_object_predictions(self, context): layout.operator("nd.hydrate", icon=icons['nd.hydrate']) layout.operator("nd.swap_solver", text="Swap Solver (Booleans)", icon=icons['nd.swap_solver']) - return + return SECTION_COUNT layout.operator("nd.bool_vanilla", text="Difference", icon=icons['nd.bool_vanilla+DIFFERENCE']).mode = 'DIFFERENCE' layout.operator("nd.bool_vanilla", text="Union", icon=icons['nd.bool_vanilla+UNION']).mode = 'UNION' @@ -105,6 +106,8 @@ def draw_two_object_predictions(self, context): layout.operator("nd.circular_array", icon=icons['nd.circular_array']) layout.operator("nd.snap_align", icon=icons['nd.snap_align']) + return SECTION_COUNT + def draw_single_object_predictions(self, context): layout = self.layout @@ -139,10 +142,10 @@ def draw_single_object_predictions(self, context): self.draw_make_edge_face_ops(context) made_prediction = True - if not made_prediction: - self.draw_no_predictions(context) - - return + if made_prediction: + return SECTION_COUNT + + return NO_SECTION_COUNT if context.mode == 'OBJECT': depsgraph = context.evaluated_depsgraph_get() @@ -211,7 +214,7 @@ def draw_single_object_predictions(self, context): layout.operator("nd.hydrate", icon=icons['nd.hydrate']) layout.operator("nd.swap_solver", text="Swap Solver (Booleans)", icon=icons['nd.swap_solver']) - return + return SECTION_COUNT if was_profile_extrude or self.sketch: layout.operator("nd.solidify", icon=icons['nd.solidify']) if not has_mod_solidify else None @@ -219,14 +222,14 @@ def draw_single_object_predictions(self, context): layout.operator("nd.mirror", icon=icons['nd.mirror']) layout.operator("nd.screw", icon=icons['nd.screw']) if not has_mod_screw else None - return + return SECTION_COUNT if self.profile: layout.operator("nd.profile_extrude", icon=icons['nd.profile_extrude']) if not has_mod_profile_extrude else None layout.operator("nd.screw", icon=icons['nd.screw']) if not has_mod_screw else None layout.operator("nd.mirror", icon=icons['nd.mirror']) - return + return SECTION_COUNT if self.has_faces: layout.separator() @@ -241,8 +244,11 @@ def draw_single_object_predictions(self, context): layout.operator("nd.geo_lift", icon=icons['nd.geo_lift']) layout.operator("nd.view_align", icon=icons['nd.view_align']) - return + return SECTION_COUNT + return NO_SECTION_COUNT + + return NO_SECTION_COUNT def draw_many_object_predictions(self, context): layout = self.layout @@ -253,7 +259,7 @@ def draw_many_object_predictions(self, context): layout.operator("nd.hydrate", icon=icons['nd.hydrate']) layout.operator("nd.swap_solver", text="Swap Solver (Booleans)", icon=icons['nd.swap_solver']) - return + return SECTION_COUNT layout.operator("nd.mirror", icon=icons['nd.mirror']) layout.operator("nd.triangulate", icon=icons['nd.triangulate']) @@ -262,6 +268,8 @@ def draw_many_object_predictions(self, context): layout.operator("nd.set_lod_suffix", text="Low LOD", icon=icons['nd.set_lod_suffix+LOW']).mode = 'LOW' layout.operator("nd.set_lod_suffix", text="High LOD", icon=icons['nd.set_lod_suffix+HIGH']).mode = 'HIGH' + return SECTION_COUNT + def register(): bpy.utils.register_class(ND_MT_fast_menu)