From b016998bcb7d074e664a03601556fa9759bcf8dc Mon Sep 17 00:00:00 2001 From: Leo Date: Sun, 5 Jul 2020 11:29:21 +0200 Subject: [PATCH] Add Object Node Update & Help Panel --- __init__.py | 3 +++ basicnodes/__init__.py | 46 +++++++++++++++++++++++++++++++++++++++--- game/bgelogic.py | 11 ++++++---- ops/__init__.py | 18 +++++++++++++++++ ui/__init__.py | 33 ++++++++++++++++++++++++++++++ 5 files changed, 104 insertions(+), 7 deletions(-) diff --git a/__init__.py b/__init__.py index 8ecc123..c7b2399 100644 --- a/__init__.py +++ b/__init__.py @@ -414,6 +414,8 @@ def draw(self, context): ops.NLPopupTemplatesOperator, ops.NLAddonPatreonButton, ops.NLAddonGithubButton, + ops.NLBGEDocsButton, + ops.NLUPBGEDocsButton, NLNodeTreeReference ] @@ -429,6 +431,7 @@ def draw(self, context): ui.BGE_PT_LogicPanel, ui.BGE_PT_LogicTreeInfoPanel, ui.BGE_PT_GamePropertyPanel, + ui.BGE_PT_HelpPanel, # ui.BGEGameComponentPanel, ui.BGE_PT_GamePropertyPanel3DView, ui.BGE_PT_PropertiesPanelObject, diff --git a/basicnodes/__init__.py b/basicnodes/__init__.py index d402cc4..4566458 100644 --- a/basicnodes/__init__.py +++ b/basicnodes/__init__.py @@ -875,6 +875,43 @@ def get_unlinked_value(self): _sockets.append(NLGameObjectSocket) +class NLGameObjectNameSocket(bpy.types.NodeSocket, NetLogicSocketType): + bl_idname = "NLGameObjectNameSocket" + bl_label = "Object" + value: bpy.props.PointerProperty( + name='Object', + type=bpy.types.Object, + update=update_tree_code + ) + + def draw_color(self, context, node): + return PARAM_OBJ_SOCKET_COLOR + + def draw(self, context, layout, node, text): + if self.is_output: + layout.label(text=self.name) + elif self.is_linked: + layout.label(text=self.name) + else: + col = layout.column(align=False) + col.label(text=self.name) + col.prop_search( + self, + 'value', + bpy.context.scene, + 'objects', + icon='NONE', + text='' + ) + + def get_unlinked_value(self): + if isinstance(self.value, bpy.types.Object): + return '"{}"'.format(self.value.name) + + +_sockets.append(NLGameObjectNameSocket) + + class NLCollectionSocket(bpy.types.NodeSocket, NetLogicSocketType): bl_idname = "NLCollectionSocket" bl_label = "Collection" @@ -4677,15 +4714,18 @@ class NLAddObjectActionNode(bpy.types.Node, NLActionNode): def init(self, context): NLActionNode.init(self, context) self.inputs.new(NLConditionSocket.bl_idname, "Condition") - self.inputs.new(NLQuotedStringFieldSocket.bl_idname, "Name") + self.inputs.new(NLGameObjectNameSocket.bl_idname, "Object to Add") + self.inputs.new(NLGameObjectSocket.bl_idname, "Copy Data From (Optional)") self.inputs.new(NLPositiveIntegerFieldSocket.bl_idname, "Life") self.outputs.new(NLConditionSocket.bl_idname, "Done") self.outputs.new(NLGameObjectSocket.bl_idname, "Added Object") def get_netlogic_class_name(self): return "bgelogic.ActionAddObject" - def get_input_sockets_field_names(self): return ["condition", "name", "life"] + def get_input_sockets_field_names(self): return ["condition", "name", 'reference', "life"] def get_output_socket_varnames(self): return ['OUT', 'OBJ'] + + _nodes.append(NLAddObjectActionNode) @@ -5707,7 +5747,7 @@ def get_nonsocket_fields(self): return [("local", lambda : "True" if self.local class NLActionApplyLocation(bpy.types.Node, NLActionNode): bl_idname = "NLActionApplyLocation" - bl_label = "Apply Location" + bl_label = "Apply Movement" nl_category = "Transformation" local: bpy.props.BoolProperty(default=True, update=update_tree_code) diff --git a/game/bgelogic.py b/game/bgelogic.py index 3116eec..11fc895 100644 --- a/game/bgelogic.py +++ b/game/bgelogic.py @@ -4097,9 +4097,10 @@ def evaluate(self): class ActionAddObject(ActionCell): def __init__(self): ActionCell.__init__(self) + self.condition = None self.name = None + self.reference = None self.life = None - self.condition = None self.done = False self.obj = False self.OBJ = LogicNetworkSubCell(self, self._get_obj) @@ -4117,16 +4118,18 @@ def evaluate(self): if condition_value is LogicNetworkCell.STATUS_WAITING: return if not condition_value: - self._set_ready() return life_value = self.get_parameter_value(self.life) name_value = self.get_parameter_value(self.name) + self._set_ready() if life_value is LogicNetworkCell.STATUS_WAITING: return + reference_value = self.get_parameter_value(self.reference) + if reference_value is LogicNetworkCell.STATUS_WAITING: + return if name_value is LogicNetworkCell.STATUS_WAITING: return scene = bge.logic.getCurrentScene() - self._set_ready() if none_or_invalid(scene): return if life_value is None: @@ -4134,7 +4137,7 @@ def evaluate(self): if name_value is None: return try: - self.obj = scene.addObject(name_value, None, life_value) + self.obj = scene.addObject(name_value, reference_value, life_value) except ValueError: debug( "ActionAddObject: cannot find {}.".format( diff --git a/ops/__init__.py b/ops/__init__.py index 9facc1f..e6b3f97 100644 --- a/ops/__init__.py +++ b/ops/__init__.py @@ -1014,6 +1014,24 @@ def execute(self, context): return {"FINISHED"} +class NLBGEDocsButton(bpy.types.Operator): + bl_idname = "bge_netlogic.bge_docs" + bl_label = "Blender Game Engine Documentation" + + def execute(self, context): + webbrowser.open('https://docs.blender.org/api/2.79/') + return {"FINISHED"} + + +class NLUPBGEDocsButton(bpy.types.Operator): + bl_idname = "bge_netlogic.upbge_docs" + bl_label = "UPBGE Documentation" + + def execute(self, context): + webbrowser.open('https://upbge-docs.readthedocs.io/en/latest/') + return {"FINISHED"} + + class NLAddonGithubButton(bpy.types.Operator): bl_idname = "bge_netlogic.github" bl_label = "GitHub" diff --git a/ui/__init__.py b/ui/__init__.py index af50b44..12b8790 100644 --- a/ui/__init__.py +++ b/ui/__init__.py @@ -552,6 +552,7 @@ def poll(cls, context): def draw(self, context): layout = self.layout + layout.scale_y = 1.4 layout.operator( bge_netlogic.ops.NLPopupTemplatesOperator.bl_idname, text="Custom Nodes Templates..." @@ -566,6 +567,38 @@ def draw(self, context): ) +class BGE_PT_HelpPanel(bpy.types.Panel): + bl_label = "Help & Documentation" + bl_space_type = "NODE_EDITOR" + bl_region_type = "UI" + bl_category = "Help & Documentation" + _current_tree = None + + @classmethod + def poll(cls, context): + enabled = (context.space_data.tree_type == BGELogicTree.bl_idname) + if enabled and (context.space_data.edit_tree is not None): + bge_netlogic._consume_update_tree_code_queue() + if not bge_netlogic._tree_code_writer_started: + bge_netlogic._tree_code_writer_started = True + bpy.ops.bgenetlogic.treecodewriter_operator() + return enabled + + def draw(self, context): + layout = self.layout + layout.scale_y = 1.4 + layout.operator( + bge_netlogic.ops.NLBGEDocsButton.bl_idname, + text="Blender Game Engine", + icon='MENU_PANEL' + ) + layout.operator( + bge_netlogic.ops.NLUPBGEDocsButton.bl_idname, + text="UPBGE", + icon='MENU_PANEL' + ) + + def update_tree_code(self, context): bge_netlogic.update_current_tree_code()