From 60dd37cb250a5f155b4f8cfebe681ceea3fff343 Mon Sep 17 00:00:00 2001 From: Patrick Dulebohn Date: Thu, 3 Mar 2022 08:20:39 -0500 Subject: [PATCH] Some additions and updates More code to setup the future export and object definition updates to differentiate better --- korman/properties/modifiers/gui.py | 53 ++++++++++++++++++++++++++---- korman/ui/modifiers/gui.py | 6 ++-- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/korman/properties/modifiers/gui.py b/korman/properties/modifiers/gui.py index 37cc377..7e223c4 100644 --- a/korman/properties/modifiers/gui.py +++ b/korman/properties/modifiers/gui.py @@ -86,12 +86,21 @@ class ImageLibraryItem(bpy.types.PropertyGroup): options=set()) +gui_pfms = { + "filename" = "xDialogToggle.py", + "attribs": ( + { 'id': 1, 'type': "ptAttribActivator", 'name': "actGUIClickable" }, + { 'id': 4, 'type': "ptAttribString", 'name': "pagename" }, + ) +} + + class PlasmaGUIDialogModifier(PlasmaModifierProperties): pl_id = "guidialogmod" bl_category = "GUI" - bl_label = "GUI Dialog" - bl_description = "Brings up a custom GUI dialog" + bl_label = "Custom GUI Dialog" + bl_description = "Brings up a custom GUI dialog modifier" bl_icon = "VIEWZOOM" versions = EnumProperty(name="Export Targets", @@ -100,12 +109,12 @@ class PlasmaGUIDialogModifier(PlasmaModifierProperties): options={"ENUM_FLAG"}, default={"pvMoul", "pvPots", "pvPrime"}) - clickable = PointerProperty(name="GUI Clickable", + gui_clickable = PointerProperty(name="GUI Clickable", description="Object to click to initiate GUI", type=bpy.types.Object, poll=idprops.poll_mesh_objects, options=set()) - region = PointerProperty(name="GUI Click Region", + gui_region = PointerProperty(name="GUI Click Region", description="GUI clickable region", type=bpy.types.Object, poll=idprops.poll_mesh_objects, @@ -115,7 +124,7 @@ class PlasmaGUIDialogModifier(PlasmaModifierProperties): type=bpy.types.Object, poll=idprops.poll_mesh_objects, options=set()) - button = PointerProperty(name="GUI Button", + gui_button = PointerProperty(name="GUI Button", description="Object to click to deactivate GUI (optional)", type=bpy.types.Object, poll=idprops.poll_mesh_objects, @@ -124,7 +133,7 @@ class PlasmaGUIDialogModifier(PlasmaModifierProperties): def sanity_check(self): if self.gui_object is None: raise ExportError("{}: GUI Dialog modifier requires a GUI Object!", self.id_data.name) - elif self.click is None: + elif self.gui_clickable is None: raise ExportError("{}: GUI Dialog modifier requires a clickable!", self.id_data.name) def pre_export(self, exporter, bo): @@ -134,6 +143,38 @@ class PlasmaGUIDialogModifier(PlasmaModifierProperties): exporter.report.port("Object '{}' has a GUI Dialog not enabled for export to the selected engine. Skipping.", bo.name, version, indent=2) return + # create GUI click region if one is not provided + if self.gui_region is None: + with utils.bmesh_object("{}_GUI_ClkRgn".format(self.key_name)) as (gui_rgn_obj, bm): + bmesh.ops.create_cube(bm, size=(6.0)) + bmesh.ops.transform(bm, matrix=mathutils.Matrix.Translation(bo.matrix_world.translation - gui_rgn_obj.matrix_world.translation), + space=gui_rgn_obj.matrix_world, verts=bm.verts) + gui_rgn_obj.plasma_object.enabled = True + gui_rgn_obj.hide_render = True + yield gui_rgn_obj + else: + # Use the GUI region provided + gui_rgn_obj = self.gui_region + + def logicwiz(self, bo, tree, age_name, version, gui_rgn_obj): + guinode = self._create_python_file_node(tree, gui_pfms["filename"], gui_pfms["attribs"]) + self._create_python_nodes(bo, tree.nodes, guinode, age_name, gui_rgn_obj) + + def export(self, exporter, bo): + + + def _create_python_nodes(self, gui_clickable, nodes, guinode, age_name, gui_region): + clickable_region = nodes.new("PlasmaClickableRegionNode") + clickable_region.region_object = gui_region + + clickable = nodes.new("PlasmaClickableNode") + clickable.clickable_object = self.clickable + clickable.find_input_socket("facing").allow_simple = False + clickable.link_input(clickable_region, "satisfies", "region") + clickable.link_output(guinode, "satisfies", "actGUIClickable") + + gui_name = nodes.new("PlasmaAttribStringNode") + gui_name.value = self.gui_object.name class PlasmaImageLibraryModifier(PlasmaModifierProperties): diff --git a/korman/ui/modifiers/gui.py b/korman/ui/modifiers/gui.py index cfa2d26..dd714ca 100644 --- a/korman/ui/modifiers/gui.py +++ b/korman/ui/modifiers/gui.py @@ -37,13 +37,13 @@ def guidialogmod(modifier, layout, context): layout.label("GUI Objects:") main_col.label("Required:") col = main_col.column() - col.prop(modifier, "clickable", text="Clickable") + col.prop(modifier, "gui_clickable", text="Clickable") col.prop(modifier, "gui_object", text="GUI Object") main_col.separator() main_col.label("Optional:") col = main_col.column(align=True) - col.prop(modifier, "region", text="Click Region") - col.prop(modifier, "button", text="GUI Button") + col.prop(modifier, "gui_region", text="Click Region") + col.prop(modifier, "gui_button", text="GUI Button") def imagelibmod(modifier, layout, context): ui_list.draw_modifier_list(layout, "ImageListUI", modifier, "images", "active_image_index", rows=3, maxrows=6)