Skip to content

Commit e5aa112

Browse files
author
MrClock8163
committed
Added operator code for custom editor header
1 parent 0f3867c commit e5aa112

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ def draw(self,context):
499499
ui.MCFG_GT_NodeSetupPresetItem,
500500
ui.MCFG_UL_ModelSelectionList,
501501
ui.MCFG_UL_NodeSetupPresetList,
502+
ui.MCFG_OT_NewConfig,
502503
ui.MCFG_OT_BonesFromModel,
503504
ui.MCFG_OT_SectionsFromModel,
504505
ui.MCFG_OT_ReportBox,
@@ -626,6 +627,7 @@ def register():
626627
# Menus
627628
bpy.types.NODE_MT_editor_menus.append(ui.draw_header)
628629
bpy.types.TEXT_MT_templates.append(ui.draw_menu)
630+
# bpy.types.NODE_HT_header.draw = ui.draw_header_override
629631

630632
print("Register done")
631633

@@ -675,6 +677,7 @@ def unregister():
675677
print("\tmenus")
676678
bpy.types.NODE_MT_editor_menus.remove(ui.draw_header)
677679
bpy.types.TEXT_MT_templates.remove(ui.draw_menu)
680+
# bpy.types.NODE_HT_header.draw = ui.orig_node_header
678681

679682
print("Unregister done")
680683

ui.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,28 @@ def draw_item(self,context,layout,data,item,icon,active_data,active_propname,ind
122122
layout.alignment = 'CENTER'
123123
layout.label(text=item.name,icon=icon)
124124

125+
class MCFG_OT_NewConfig(bpy.types.Operator):
126+
# Description string
127+
'''Create new model config node tree'''
128+
129+
# Mandatory variables
130+
bl_label = "New Config"
131+
bl_idname = "mcfg.newconfig"
132+
133+
# Standard functions
134+
@classmethod
135+
def poll(cls, context):
136+
return context.space_data.type == 'NODE_EDITOR' and context.space_data.tree_type == 'MCFG_N_Tree'
137+
138+
def execute(self,context):
139+
140+
editorSpace = context.space_data
141+
newTree = bpy.data.node_groups.new("Model Config",'MCFG_N_Tree')
142+
newTree.use_fake_user = True
143+
editorSpace.node_tree = newTree
144+
145+
return {'FINISHED'}
146+
125147
class MCFG_OT_BonesFromModel(bpy.types.Operator):
126148
# Description string
127149
'''Create bones from model selections'''
@@ -653,4 +675,20 @@ def draw_menu(self,context):
653675
layout.separator()
654676
layout.label(text="Arma 3 model config editor")
655677
layout.menu("MCFG_MT_TemplatesNodeScript")
656-
layout.menu("MCFG_MT_TemplatesSetupPresets")
678+
layout.menu("MCFG_MT_TemplatesSetupPresets")
679+
680+
# Original node editor header draw function
681+
orig_node_header = bpy.types.NODE_HT_header.draw
682+
683+
def draw_header_override(self,context): # THIS STILL NEEDS TO BE LOOKED INTO REGARDING ADDON CONFLICTS
684+
from bl_ui.space_node import NODE_MT_editor_menus
685+
686+
if context.space_data.type != 'NODE_EDITOR' or context.space_data.tree_type != 'MCFG_N_Tree':
687+
orig_node_header(self,context)
688+
return
689+
690+
self.layout.template_header()
691+
NODE_MT_editor_menus.draw_collapsible(context,self.layout)
692+
self.layout.separator_spacer()
693+
self.layout.template_ID(context.space_data,"node_tree",new="mcfg.newconfig",open="mcfg.import")
694+
self.layout.separator_spacer()

0 commit comments

Comments
 (0)