2015-10-30 13:23:09 +01:00
|
|
|
import bpy
|
2017-03-06 02:29:03 +01:00
|
|
|
from bpy.types import NodeTree
|
2015-10-30 13:23:09 +01:00
|
|
|
from bpy.props import *
|
2017-03-06 02:29:03 +01:00
|
|
|
import nodeitems_utils
|
|
|
|
from nodeitems_utils import NodeCategory
|
2017-03-15 12:30:14 +01:00
|
|
|
from arm.logicnode import *
|
2017-04-10 21:17:17 +02:00
|
|
|
import webbrowser
|
2017-03-06 02:29:03 +01:00
|
|
|
|
|
|
|
registered_nodes = []
|
2016-10-19 13:28:06 +02:00
|
|
|
|
2017-03-06 02:29:03 +01:00
|
|
|
class ArmLogicTree(NodeTree):
|
2016-09-28 00:00:59 +02:00
|
|
|
'''Logic nodes'''
|
|
|
|
bl_idname = 'ArmLogicTreeType'
|
|
|
|
bl_label = 'Logic Node Tree'
|
|
|
|
bl_icon = 'GAME'
|
2015-10-30 13:23:09 +01:00
|
|
|
|
2017-03-06 02:29:03 +01:00
|
|
|
class LogicNodeCategory(NodeCategory):
|
2016-09-28 00:00:59 +02:00
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
return context.space_data.tree_type == 'ArmLogicTreeType'
|
2016-08-14 21:08:01 +02:00
|
|
|
|
2017-03-06 02:29:03 +01:00
|
|
|
def register_nodes():
|
|
|
|
global registered_nodes
|
2016-08-14 21:08:01 +02:00
|
|
|
|
2017-03-06 02:29:03 +01:00
|
|
|
# Re-register all nodes for now..
|
|
|
|
if len(registered_nodes) > 0:
|
|
|
|
unregister_nodes()
|
2015-10-30 13:23:09 +01:00
|
|
|
|
2017-03-06 02:29:03 +01:00
|
|
|
for n in arm_nodes.nodes:
|
|
|
|
registered_nodes.append(n)
|
|
|
|
bpy.utils.register_class(n)
|
|
|
|
|
2018-10-29 02:41:06 +01:00
|
|
|
node_categories = []
|
|
|
|
|
|
|
|
for category in sorted(arm_nodes.category_items):
|
2018-10-29 18:09:46 +01:00
|
|
|
sorted_items=sorted(arm_nodes.category_items[category], key=lambda item: item.nodetype)
|
2018-10-29 02:41:06 +01:00
|
|
|
node_categories.append(
|
2018-10-29 18:09:46 +01:00
|
|
|
LogicNodeCategory('Logic' + category + 'Nodes', category, items=sorted_items)
|
2018-10-29 02:41:06 +01:00
|
|
|
)
|
2017-03-06 02:29:03 +01:00
|
|
|
|
2017-04-04 23:11:31 +02:00
|
|
|
nodeitems_utils.register_node_categories('ArmLogicNodes', node_categories)
|
2015-10-30 13:23:09 +01:00
|
|
|
|
2017-03-06 02:29:03 +01:00
|
|
|
def unregister_nodes():
|
|
|
|
global registered_nodes
|
|
|
|
for n in registered_nodes:
|
|
|
|
bpy.utils.unregister_class(n)
|
|
|
|
registered_nodes = []
|
2017-04-04 23:11:31 +02:00
|
|
|
nodeitems_utils.unregister_node_categories('ArmLogicNodes')
|
2015-10-30 13:23:09 +01:00
|
|
|
|
2017-04-10 21:17:17 +02:00
|
|
|
class ArmLogicNodePanel(bpy.types.Panel):
|
2018-06-12 00:26:52 +02:00
|
|
|
bl_label = 'Armory Logic Node'
|
2017-04-10 21:17:17 +02:00
|
|
|
bl_idname = 'ArmLogicNodePanel'
|
|
|
|
bl_space_type = 'NODE_EDITOR'
|
|
|
|
bl_region_type = 'UI'
|
|
|
|
|
|
|
|
def draw(self, context):
|
|
|
|
layout = self.layout
|
|
|
|
if context.active_node != None and context.active_node.bl_idname.startswith('LN'):
|
2018-06-15 00:30:40 +02:00
|
|
|
layout.prop(context.active_node, 'arm_logic_id')
|
2018-06-28 22:39:23 +02:00
|
|
|
layout.prop(context.active_node, 'arm_watch')
|
2017-04-10 21:17:17 +02:00
|
|
|
layout.operator('arm.open_node_source')
|
|
|
|
|
|
|
|
class ArmOpenNodeSource(bpy.types.Operator):
|
|
|
|
'''Expose Haxe source'''
|
|
|
|
bl_idname = 'arm.open_node_source'
|
|
|
|
bl_label = 'Open Node Source'
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
if context.active_node != None and context.active_node.bl_idname.startswith('LN'):
|
|
|
|
name = context.active_node.bl_idname[2:]
|
|
|
|
webbrowser.open('https://github.com/armory3d/armory/tree/master/Sources/armory/logicnode/' + name + '.hx')
|
|
|
|
return{'FINISHED'}
|
|
|
|
|
2015-10-30 13:23:09 +01:00
|
|
|
def register():
|
2017-03-15 12:30:14 +01:00
|
|
|
bpy.utils.register_class(ArmLogicTree)
|
2017-04-10 21:17:17 +02:00
|
|
|
bpy.utils.register_class(ArmLogicNodePanel)
|
|
|
|
bpy.utils.register_class(ArmOpenNodeSource)
|
2017-03-06 02:29:03 +01:00
|
|
|
register_nodes()
|
2015-10-30 13:23:09 +01:00
|
|
|
|
|
|
|
def unregister():
|
2017-03-06 02:29:03 +01:00
|
|
|
unregister_nodes()
|
2017-03-15 12:30:14 +01:00
|
|
|
bpy.utils.unregister_class(ArmLogicTree)
|
2017-04-10 21:17:17 +02:00
|
|
|
bpy.utils.unregister_class(ArmLogicNodePanel)
|
|
|
|
bpy.utils.unregister_class(ArmOpenNodeSource)
|