Archived
1
0
Fork 0

Added list for groups, testing

This commit is contained in:
Augs 2018-05-25 20:17:43 +01:00
parent 0cf4666a0a
commit b82d901e10

View file

@ -26,8 +26,6 @@ from bpy.props import (BoolProperty,
PointerProperty,
)
class Header(Struct):
vertex_count = uint32
@ -78,8 +76,31 @@ class BlenderCollisionGroup:
CollisionType = uint16
GroupFlags = uint16
def __init__(self,MatList):
def __init__(self,MatList,ColType):
self.MaterialList = MatList
self.CollisionType=ColType
def ValidateGroup(): #Removes any materials that shouldn't be in the list
for mat in self.MaterialList:
if mat is None:
self.MaterialList.remove(mat)
continue
if mat.ColEditor is None: #If material doesn't have collision values remove it
self.MaterialList.remove(mat)
continue
if mat.ColEditor.ColType != self.CollisionType: #We need to do this after the above statement to avoid an exception
self.MaterialList.remove(mat)
def AddMaterial(Mat):
if mat.ColEditor.ColType == self.CollisionType:
self.MaterialList.append(Mat)
return "Material added"
return "Not the right collision type"
def RemoveMaterial(Mat):
if Mat in self.MaterialList:
MaterialList.remove(Mat)
@ -340,55 +361,7 @@ class CollisionPanel(Panel): #This panel houses the UI elements defined in the C
column2 = self.layout.column(align = True)
column2.prop(mat,"ColParameterField")
column2.enabled = mat.HasColParameterField #must have "Has ColParameter" checked
class GroupsPanel(Panel):
bl_label = "Edit Collision Groups"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_context = "object"
def draw(self, context):
layout = self.layout
mat = context.material
ob = context.object
slot = context.material_slot
space = context.space_data
if ob:
row = layout.row()
row.template_list("UI_UL_list", "", ob, "material_slots", ob, "active_material_index", rows=1)
col = row.column(align=True)
col.operator("colgroup.add", icon='ZOOMIN', text="")
col.operator("colgroup.remove", icon='ZOOMOUT', text="")
class AddGroup(bpy.types.Operator):
bl_idname = "colgroup.add"
bl_label = "Add group"
def execute(self, context):
return {'FINISHED'}
class RemoveGroup(bpy.types.Operator):
bl_idname = "colgroup.remove"
bl_label = "Remove group"
def execute(self, context):
return {'FINISHED'}
class CalculateGroups(bpy.types.Operator):
bl_idname = "groups.calculate"
bl_label = "Calculate groups"
def execute(self, context):
for mat in bpy.data.materials:
print(mat.name)
return {'FINISHED'}
def check_material(mat):
if mat is not None:
if mat.use_nodes:
@ -397,9 +370,104 @@ def check_material(mat):
return False
return True
return False
class MESH_UL_GroupsList(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index, flt_flag):
self.use_filter_show = True
classes = (ExportCOL,ImportCOL, CollisionPanel,CollisionProperties,GroupsPanel,CalculateGroups,AddGroup,RemoveGroup) #list of classes to register/unregister
if self.layout_type in {'DEFAULT', 'COMPACT'}:
split = layout.split(0.1)
split.prop(item, "Name", text="", emboss=False)
split = split.split(0.3)
split.prop(item, "ColType", text="", emboss=False)
elif self.layout_type in {'GRID'}:
pass
# Called once to filter/reorder items.
def filter_items(self, context, data, propname):#magic
col = getattr(data, propname)
filter_name = self.filter_name.lower()
flt_flags = [self.bitflag_filter_item if any(
filter_name in filter_set for filter_set in (
str(i), item.Name.lower()
)
)
else 0 for i, item in enumerate(col, 1)
]
if self.use_filter_sort_alpha:
flt_neworder = [x[1] for x in sorted(
zip(
[x[0] for x in sorted(enumerate(col), key=lambda x: x[1].Name)],
range(len(col))
)
)
]
else:
flt_neworder = []
return flt_flags, flt_neworder
def ListClick(self, context):
print(bpy.context.scene.CollisionGroupList[0].Name)
class GroupsPanel(Panel):
bl_label = "Edit Collision Groups"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_context = "object"
def draw(self, context):
layout = self.layout
ob = context.object
if ob:
row = layout.row()
row.template_list("MESH_UL_GroupsList", "", context.scene, "CollisionGroupList", context.scene, "CollisionGroup_idx")
col = row.column(align=True)
col.operator("colgroup.add", icon='ZOOMIN', text="")
col.operator("colgroup.remove", icon='ZOOMOUT', text="")
if len(context.scene.CollisionGroupList) > context.scene.CollisionGroup_idx:
print(SpecialGroupList[context.scene.CollisionGroup_idx])
class GroupsCollection(bpy.types.PropertyGroup):
Name = bpy.props.StringProperty()
ColType = bpy.props.IntProperty()
ColGroup = BlenderCollisionGroup([],0)
class AddGroup(bpy.types.Operator):
bl_idname = "colgroup.add"
bl_label = "Add group"
def execute(self, context):
NewBlenderGroup = BlenderCollisionGroup([],0)
item = bpy.context.scene.CollisionGroupList.add()
item.Name = "Untitled"
item.ColType = 0
global SpecialGroupList
SpecialGroupList.append(NewBlenderGroup)
return {'FINISHED'}
class RemoveGroup(bpy.types.Operator):
bl_idname = "colgroup.remove"
bl_label = "Remove group"
def execute(self, context):
bpy.context.scene.CollisionGroupList.remove(bpy.context.scene.CollisionGroup_idx)
global SpecialGroupList
SpecialGroupList.pop(bpy.context.scene.CollisionGroup_idx)
return {'FINISHED'}
classes = (ExportCOL,ImportCOL, CollisionPanel,CollisionProperties,GroupsPanel,AddGroup,RemoveGroup,GroupsCollection,MESH_UL_GroupsList) #list of classes to register/unregister
def register():
for i in classes:
register_class(i)
@ -407,6 +475,9 @@ def register():
bpy.types.INFO_MT_file_export.append(menu_export) #Add to export menu
bpy.types.INFO_MT_file_import.append(menu_import) #Add to import menu
Scene.CollisionGroupList = bpy.props.CollectionProperty(type=GroupsCollection)
Scene.CollisionGroup_idx = bpy.props.IntProperty(default=0)
def menu_export(self, context):
self.layout.operator(ExportCOL.bl_idname, text="Collision (.col)")
@ -419,6 +490,8 @@ def unregister():
unregister_class(i)
bpy.types.INFO_MT_file_export.remove(menu_export)
bpy.types.INFO_MT_file_import.remove(menu_import)
del Scene.CollisionGroupList
del Scene.CollisionGroup_idx