Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linking fixes #229

Merged
merged 2 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ def draw(self, context, layout, panel):
sub_row.enabled = False
add_link_indicator(sub_row, self.backgroundTexture)

sub_row.context_pointer_set("hubs_component", self)
sub_row.context_pointer_set("host", self.backgroundTexture)
op = sub_row.operator("image.hubs_open_image", text='', icon='FILE_FOLDER')
row.context_pointer_set("hubs_component", self)
row.context_pointer_set("host", context.scene)
op = row.operator("image.hubs_open_image", text='', icon='FILE_FOLDER')
op.target_property = "backgroundTexture"

row = layout.row(align=True)
Expand All @@ -112,9 +112,9 @@ def draw(self, context, layout, panel):
sub_row.enabled = False
add_link_indicator(sub_row, self.envMapTexture)

sub_row.context_pointer_set("hubs_component", self)
sub_row.context_pointer_set("host", self.envMapTexture)
op = sub_row.operator("image.hubs_open_image", text='', icon='FILE_FOLDER')
row.context_pointer_set("hubs_component", self)
row.context_pointer_set("host", context.scene)
op = row.operator("image.hubs_open_image", text='', icon='FILE_FOLDER')
op.target_property = "envMapTexture"

layout.prop(data=self, property="toneMapping")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def poll(cls, context):

return host.hubs_component_loop_animation.active_track_key != -1

return True
return False

def execute(self, context):
panel_type = PanelType(context.panel.bl_context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ def draw(self, context, layout, panel):
sub_row.enabled = False
add_link_indicator(sub_row, self.envMapTexture)
row.context_pointer_set("hubs_component", self)
row.context_pointer_set("host", self.envMapTexture)
row.context_pointer_set("host", context.active_object)
op = row.operator("image.hubs_open_reflection_probe_envmap", text='', icon='FILE_FOLDER')
op.target_property = "envMapTexture"

Expand Down
66 changes: 52 additions & 14 deletions addons/io_hubs_addon/components/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,44 @@ class AddHubsComponent(Operator):
panel_type: StringProperty(name="panel_type")
component_name: StringProperty(name="component_name")

is_execute_poll = False

@classmethod
def poll(cls, context):
# main button poll
if hasattr(context, "panel"):
panel = getattr(context, 'panel')
panel_type = PanelType(panel.bl_context)
if panel_type == PanelType.SCENE:
if is_linked(context.scene):
cls.poll_message_set("Disabled: Cannot add components to linked scenes")
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set("Cannot add components to linked scenes")
return False
elif panel_type == PanelType.OBJECT:
if is_linked(context.active_object):
cls.poll_message_set("Disabled: Cannot add components to linked objects")
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set("Cannot add components to linked objects")
return False
elif panel_type == PanelType.MATERIAL:
if is_linked(context.active_object.active_material):
cls.poll_message_set("Disabled: Cannot add components to linked materials")
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set("Cannot add components to linked materials")
return False
elif panel_type == PanelType.BONE:
if is_linked(context.active_bone):
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set("Cannot add components to linked bones")
return False

return True
return True

# menu item poll
elif cls.is_execute_poll:
cls.is_execute_poll = False
return True

else:
return False

def execute(self, context):
if self.component_name == '':
Expand Down Expand Up @@ -187,6 +206,7 @@ def draw(self, context):
text="No components available for this object type")

bpy.context.window_manager.popup_menu(draw)
AddHubsComponent.is_execute_poll = True

return {'FINISHED'}

Expand All @@ -206,18 +226,28 @@ def poll(cls, context):
panel_type = PanelType(panel.bl_context)
if panel_type == PanelType.SCENE:
if is_linked(context.scene):
cls.poll_message_set("Disabled: Cannot remove components from linked scenes")
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set("Cannot remove components from linked scenes")
return False
elif panel_type == PanelType.OBJECT:
if is_linked(context.active_object):
cls.poll_message_set("Disabled: Cannot remove components from linked objects")
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set("Cannot remove components from linked objects")
return False
elif panel_type == PanelType.MATERIAL:
if is_linked(context.active_object.active_material):
cls.poll_message_set("Disabled: Cannot remove components from linked materials")
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set("Cannot remove components from linked materials")
return False
elif panel_type == PanelType.BONE:
if is_linked(context.active_bone):
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set("Cannot add components to linked bones")
return False

return True

return True
return False

def execute(self, context):
if self.component_name == '':
Expand Down Expand Up @@ -489,12 +519,17 @@ class CopyHubsComponent(Operator):

@classmethod
def poll(cls, context):
if is_linked(context.scene):
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set("Cannot copy components when in linked scenes")
return False

if hasattr(context, "panel"):
panel = getattr(context, 'panel')
panel_type = PanelType(panel.bl_context)
return panel_type != PanelType.SCENE

return True
return False

def get_selected_bones(self, context):
selected_bones = context.selected_pose_bones if context.mode == "POSE" else context.selected_editable_bones
Expand Down Expand Up @@ -536,6 +571,9 @@ def execute(self, context):
component_class = get_component_by_name(self.component_name)
component_id = component_class.get_id()
for dest_host in selected_hosts:
if is_linked(dest_host):
continue

if component_class.is_dep_only():
if not is_dep_required(dest_host, None, self.component_name):
continue
Expand Down Expand Up @@ -575,22 +613,22 @@ class OpenImage(Operator):
@ classmethod
def description(cls, context, properties):
description_text = "Load an external image "
ob = getattr(context, 'host')
if bpy.app.version < (3, 0, 0) and is_linked(ob):
if bpy.app.version < (3, 0, 0) and is_linked(context.host):
description_text += f"\nDisabled: {cls.disabled_message}"

return description_text

@ classmethod
def poll(cls, context):
if hasattr(context, "host"):
ob = getattr(context, 'host')
if is_linked(ob):
if is_linked(context.host):
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set(f"{cls.disabled_message}.")
return False

return True
return True

return False

def draw(self, context):
layout = self.layout
Expand Down
2 changes: 1 addition & 1 deletion addons/io_hubs_addon/components/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def redraw_component_ui(context):
def is_linked(datablock):
if not datablock:
return False
return bool(datablock.library or datablock.override_library)
return bool(datablock.id_data.library or datablock.id_data.override_library)


def update_image_editors(old_img, img):
Expand Down
20 changes: 19 additions & 1 deletion addons/io_hubs_addon/third_party/recast.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from mathutils import Matrix, Vector
from math import radians
from ..preferences import get_addon_pref
from ..components.utils import add_component, get_objects_with_component, has_component
from ..components.utils import add_component, get_objects_with_component, has_component, is_linked

import ctypes
import ctypes.util
Expand Down Expand Up @@ -309,6 +309,15 @@ class RecastNavMeshResetOperator(bpy.types.Operator):
bl_description = "Reset navigation mesh properties to default."
bl_options = {'REGISTER', 'UNDO'}

@classmethod
def poll(cls, context):
if is_linked(context.scene):
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set("Cannot reset navigation mesh settings when in a linked scene")
return False

return True

def execute(self, context):
scene = context.scene

Expand Down Expand Up @@ -338,6 +347,15 @@ class RecastNavMeshGenerateOperator(bpy.types.Operator):
bl_description = "Build navigation mesh from the selected objects using recast."
bl_options = {'REGISTER', 'UNDO'}

@classmethod
def poll(cls, context):
if is_linked(context.scene):
if bpy.app.version >= (3, 0, 0):
cls.poll_message_set("Cannot build a navigation mesh when in a linked scene")
return False

return True

def execute(self, context):
# bpy.ops.wm.call_menu(name="ADDITIVE_ANIMATION_insert_keyframe_menu")

Expand Down