Skip to content

Commit

Permalink
Added operator code for custom editor header
Browse files Browse the repository at this point in the history
  • Loading branch information
MrClock8163 committed Aug 13, 2022
1 parent 0f3867c commit e5aa112
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ def draw(self,context):
ui.MCFG_GT_NodeSetupPresetItem,
ui.MCFG_UL_ModelSelectionList,
ui.MCFG_UL_NodeSetupPresetList,
ui.MCFG_OT_NewConfig,
ui.MCFG_OT_BonesFromModel,
ui.MCFG_OT_SectionsFromModel,
ui.MCFG_OT_ReportBox,
Expand Down Expand Up @@ -626,6 +627,7 @@ def register():
# Menus
bpy.types.NODE_MT_editor_menus.append(ui.draw_header)
bpy.types.TEXT_MT_templates.append(ui.draw_menu)
# bpy.types.NODE_HT_header.draw = ui.draw_header_override

print("Register done")

Expand Down Expand Up @@ -675,6 +677,7 @@ def unregister():
print("\tmenus")
bpy.types.NODE_MT_editor_menus.remove(ui.draw_header)
bpy.types.TEXT_MT_templates.remove(ui.draw_menu)
# bpy.types.NODE_HT_header.draw = ui.orig_node_header

print("Unregister done")

Expand Down
40 changes: 39 additions & 1 deletion ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,28 @@ def draw_item(self,context,layout,data,item,icon,active_data,active_propname,ind
layout.alignment = 'CENTER'
layout.label(text=item.name,icon=icon)

class MCFG_OT_NewConfig(bpy.types.Operator):
# Description string
'''Create new model config node tree'''

# Mandatory variables
bl_label = "New Config"
bl_idname = "mcfg.newconfig"

# Standard functions
@classmethod
def poll(cls, context):
return context.space_data.type == 'NODE_EDITOR' and context.space_data.tree_type == 'MCFG_N_Tree'

def execute(self,context):

editorSpace = context.space_data
newTree = bpy.data.node_groups.new("Model Config",'MCFG_N_Tree')
newTree.use_fake_user = True
editorSpace.node_tree = newTree

return {'FINISHED'}

class MCFG_OT_BonesFromModel(bpy.types.Operator):
# Description string
'''Create bones from model selections'''
Expand Down Expand Up @@ -653,4 +675,20 @@ def draw_menu(self,context):
layout.separator()
layout.label(text="Arma 3 model config editor")
layout.menu("MCFG_MT_TemplatesNodeScript")
layout.menu("MCFG_MT_TemplatesSetupPresets")
layout.menu("MCFG_MT_TemplatesSetupPresets")

# Original node editor header draw function
orig_node_header = bpy.types.NODE_HT_header.draw

def draw_header_override(self,context): # THIS STILL NEEDS TO BE LOOKED INTO REGARDING ADDON CONFLICTS
from bl_ui.space_node import NODE_MT_editor_menus

if context.space_data.type != 'NODE_EDITOR' or context.space_data.tree_type != 'MCFG_N_Tree':
orig_node_header(self,context)
return

self.layout.template_header()
NODE_MT_editor_menus.draw_collapsible(context,self.layout)
self.layout.separator_spacer()
self.layout.template_ID(context.space_data,"node_tree",new="mcfg.newconfig",open="mcfg.import")
self.layout.separator_spacer()

0 comments on commit e5aa112

Please sign in to comment.