Skip to content

Commit

Permalink
Add Object Node Update & Help Panel
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo committed Jul 5, 2020
1 parent e28a337 commit b016998
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 7 deletions.
3 changes: 3 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ def draw(self, context):
ops.NLPopupTemplatesOperator,
ops.NLAddonPatreonButton,
ops.NLAddonGithubButton,
ops.NLBGEDocsButton,
ops.NLUPBGEDocsButton,
NLNodeTreeReference
]

Expand All @@ -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,
Expand Down
46 changes: 43 additions & 3 deletions basicnodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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)

Expand Down
11 changes: 7 additions & 4 deletions game/bgelogic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -4117,24 +4118,26 @@ 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:
return
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(
Expand Down
18 changes: 18 additions & 0 deletions ops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
33 changes: 33 additions & 0 deletions ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
Expand All @@ -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()

Expand Down

0 comments on commit b016998

Please sign in to comment.