Skip to content

Commit

Permalink
Try To Fix Addon
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo committed Dec 21, 2021
1 parent 1be64c8 commit c1ef864
Show file tree
Hide file tree
Showing 4 changed files with 237 additions and 46 deletions.
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def draw(self, item, layout, context):
register_classes.extend(nodes._sockets)

def register():
print(f'Registering Bricky Nodes...')
for c in register_classes:
print(f'Registering Class: {c.__name__}')
bpy.utils.register_class(c)

node_items = []
Expand Down
6 changes: 6 additions & 0 deletions nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@ def draw_buttons(self, context, layout):
data.prop(controller, 'mode', text='')
data.prop(controller, 'module', text='')
parts.prop(controller, 'use_debug', text='D', toggle=True)
if self.target_object and not self.show_info:
footer = main.box()
footer.label(text=f'Applied To: {self.target_object.name}')


class BNActuatorNode(bpy.types.Node, BNBasicNode):
Expand Down Expand Up @@ -628,6 +631,9 @@ def draw_buttons(self, context, layout):
}
body = main.box()
draw_types.get(actuator.type)(actuator, body)
if self.target_object and not self.show_info:
footer = main.box()
footer.label(text=f'Applied To: {self.target_object.name}')

def draw_action(self, act, body):
main = body.row()
Expand Down
97 changes: 52 additions & 45 deletions ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,51 +284,7 @@ def copy_contents(self):
'height',
'min',
'max',
'damping',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'damping'
]


Expand Down Expand Up @@ -414,3 +370,54 @@ class BNUpdateTree(bpy.types.Operator):
def execute(self, context):
bge_bricknodes.nodes.update_all_trees(self, context)
return {'FINISHED'}


class NLAddPropertyOperator(bpy.types.Operator):
bl_idname = "bricknodes.add_game_prop"
bl_label = "Add Game Property"
bl_options = {'REGISTER', 'UNDO'}
bl_description = "Adds a property available to the UPBGE"

@classmethod
def poll(cls, context):
return True

def execute(self, context):
bpy.ops.object.game_property_new()
return {'FINISHED'}


class NLMovePropertyOperator(bpy.types.Operator):
bl_idname = "bricknodes.move_game_prop"
bl_label = "Move Game Property"
bl_description = "Move Game Property"
bl_options = {'REGISTER', 'UNDO'}
index: bpy.props.IntProperty()
direction: bpy.props.StringProperty()

@classmethod
def poll(cls, context):
return True

def execute(self, context):
bpy.ops.object.game_property_move(
index=self.index,
direction=self.direction
)
return {'FINISHED'}


class NLRemovePropertyOperator(bpy.types.Operator):
bl_idname = "bricknodes.remove_game_prop"
bl_label = "Add Game Property"
bl_description = "Remove this property"
bl_options = {'REGISTER', 'UNDO'}
index: bpy.props.IntProperty()

@classmethod
def poll(cls, context):
return True

def execute(self, context):
bpy.ops.object.game_property_remove(index=self.index)
return {'FINISHED'}
178 changes: 178 additions & 0 deletions ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,181 @@ def update(self):
from_brick.link(to_brick)

self.compare_links = compare_links

class BGE_PT_GamePropertyPanel(bpy.types.Panel):
bl_label = "Game Properties"
bl_space_type = "NODE_EDITOR"
bl_region_type = "UI"
bl_category = "Node"

@classmethod
def poll(cls, context):
ob = context.active_object
enabled = (context.space_data.tree_type == BGEBrickTree.bl_idname)
return ob and ob.name and enabled

def draw_tree_prop(self, prop, index, box, show_movers):
col = box.column()
name = prop.name.split('__')[-1]
text = 'Logic Tree'
opts_row = col.row()
opts_row.label(text=text)
val_row = col.row()
val_row.label(text=name)
val_row.prop(prop, 'value', text='Start')
if show_movers:
self.add_movers(index, opts_row)

def add_movers(self, index, layout):
movers = layout.row(align=True)
move_up = movers.operator(
bge_bricknodes.ops.NLMovePropertyOperator.bl_idname,
text='',
icon='TRIA_UP'
)
move_up.direction = 'UP'
move_down = movers.operator(
bge_bricknodes.ops.NLMovePropertyOperator.bl_idname,
text='',
icon='TRIA_DOWN'
)
move_down.direction = 'DOWN'
move_down.index = move_up.index = index

def draw(self, context):
layout = self.layout
column = layout.column()
obj = bpy.context.object
column.operator(
bge_bricknodes.ops.NLAddPropertyOperator.bl_idname,
text="Add Game Property",
icon='PLUS'
)
options = column.row()
show_hidden = context.scene.prop_filter.show_hidden
collapse_trees = context.scene.prop_filter.collapse_trees
do_filter = context.scene.prop_filter.do_filter
prop_type = context.scene.prop_filter.filter_by
prop_name = context.scene.prop_filter.filter_name
show_trees = context.scene.prop_filter.show_trees

hide_icon = 'HIDE_OFF' if show_hidden else 'HIDE_ON'
collapse_icon = 'LOCKED' if collapse_trees else 'UNLOCKED'
options.prop(
context.scene.prop_filter,
'do_filter',
icon='FILTER',
text=''
)
options.prop(
context.scene.prop_filter,
'show_hidden',
icon=hide_icon,
text=''
)
options.prop(
context.scene.prop_filter,
'show_trees',
icon='OUTLINER',
text=''
)
options.prop(
context.scene.prop_filter,
'collapse_trees',
icon=collapse_icon,
text=''
)

if do_filter:
column.prop(context.scene.prop_filter, 'filter_by', text='')
if prop_type == 'NAME' and do_filter:
column.prop(
context.scene.prop_filter,
'filter_name',
text='',
icon='VIEWZOOM'
)
if not obj:
return

show_movers = show_hidden and show_trees and not do_filter

props = [prop for prop in obj.game.properties]
for prop in obj.game.properties:
if not show_hidden and prop.name.startswith('_'):
continue
is_tree = prop.name.startswith('NL__')
if is_tree and not show_trees:
continue
has_name = prop_name in prop.name
if do_filter:
if prop_type == 'NAME':
if not has_name:
continue
elif prop_type == 'TREES':
if not is_tree:
continue
elif prop.type != prop_type or is_tree:
continue
index = props.index(prop)
column.separator()
box = column.box()
if is_tree and collapse_trees:
self.draw_tree_prop(prop, index, box, show_movers)
continue
entry = box.column()
row_title = entry.row()
row_title.prop(prop, 'name', text='')
row_title.prop(prop, 'show_debug', text='', icon='INFO')
if show_movers:
self.add_movers(index, row_title)
remove = row_title.operator(
bge_bricknodes.ops.NLRemovePropertyOperator.bl_idname,
text='',
icon='X'
)
remove.index = index
row_info = entry.row()
row_info.prop(prop, 'type', text='')
row_info.prop(prop, 'value', text='Value')
context.region.tag_redraw()


class BGEBN_PT_GameComponentPanel(bpy.types.Panel):
bl_label = "Components"
bl_space_type = "NODE_EDITOR"
bl_region_type = "UI"
bl_category = "Node"
# module = bpy.StringProperty()

@classmethod
def poll(cls, context):
ob = context.active_object
enabled = (context.space_data.tree_type == BGEBrickTree.bl_idname)
return ob and ob.name and enabled

def draw(self, context):
layout = self.layout

ob = context.active_object
game = ob.game

row = layout.row()
row.operator("logic.python_component_register", text="Register", icon="PLUS")
row.operator("logic.python_component_create", text="Create", icon="PLUS")

for i, c in enumerate(game.components):
box = layout.box()
row = box.row()
row.prop(c, "show_expanded", text="", emboss=False)
row.label(text=c.name)
row.operator("logic.python_component_reload", text="", icon='RECOVER_LAST').index = i
row.operator("logic.python_component_remove", text="", icon='X').index = i

if c.show_expanded and len(c.properties) > 0:
box = box.box()
for prop in c.properties:
row = box.row()
row.label(text=prop.name)
col = row.column()
col.prop(prop, "value", text="")

0 comments on commit c1ef864

Please sign in to comment.