-
Notifications
You must be signed in to change notification settings - Fork 39
/
preferences.py
132 lines (112 loc) · 5.17 KB
/
preferences.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import os
import bpy
from bpy_extras.io_utils import ImportHelper
from .utils.util import drawMultilineLabel, getPreferences
from .consts import ADDON_NAME
class DirectoryProperty(bpy.types.PropertyGroup):
directory: bpy.props.StringProperty(name="", subtype='DIR_PATH')
class SelectDirectory(bpy.types.Operator, ImportHelper):
"""Select Directory"""
bl_idname = "n2b.select_asset_dir"
bl_label = "Select Directory"
filename_ext = ""
dirpath : bpy.props.StringProperty(name = "", description="Choose directory:", subtype='DIR_PATH')
settingsType: bpy.props.IntProperty()
def execute(self, context):
directory = os.path.dirname(self.filepath)
if self.settingsType == 0:
newDir = getPreferences().assetDirs.add()
elif self.settingsType == 1:
newDir = getPreferences().assetBlendDirs.add()
elif self.settingsType == 2:
newDir = getPreferences().textureDirs.add()
else:
print("Invalid settingsType")
return {'CANCELLED'}
newDir.directory = directory
return {'FINISHED'}
class RemoveDirectory(bpy.types.Operator):
"""Remove Directory"""
bl_idname = "n2b.remove_asset_dir"
bl_label = "Remove Directory"
settingsType: bpy.props.IntProperty()
index : bpy.props.IntProperty()
def execute(self, context):
if self.settingsType == 0:
getPreferences().assetDirs.remove(self.index)
elif self.settingsType == 1:
getPreferences().assetBlendDirs.remove(self.index)
elif self.settingsType == 2:
getPreferences().textureDirs.remove(self.index)
else:
print("Invalid settingsType")
return {'CANCELLED'}
return {'FINISHED'}
ArmatureDisplayTypeEnum = [
("DEFAULT", "Default", ""),
("OCTAHEDRAL", "Octahedral", ""),
("STICK", "Stick", ""),
("BBONE", "B-Bone", ""),
("ENVELOPE", "Envelope", ""),
("WIRE", "Wire", "")
]
class N2B2NPreferences(bpy.types.AddonPreferences):
bl_idname = ADDON_NAME
assetDirs: bpy.props.CollectionProperty(type=DirectoryProperty)
assetBlendDirs: bpy.props.CollectionProperty(type=DirectoryProperty)
textureDirs: bpy.props.CollectionProperty(type=DirectoryProperty)
armatureDefaultDisplayType: bpy.props.EnumProperty(name="Armature Display Type", items=ArmatureDisplayTypeEnum, default="DEFAULT")
armatureDefaultInFront: bpy.props.BoolProperty(name="Armature Default In Front", default=False)
def draw(self, context):
layout: bpy.types.UILayout = self.layout
box = layout.box()
box.label(text="Default Armature Viewport Display Options:")
row = box.row()
row.label(text="Display Type:")
row.prop(self, "armatureDefaultDisplayType", text="")
row = box.row()
row.label(text="In Front:")
row.prop(self, "armatureDefaultInFront", text="")
# asset dirs selection
box = layout.box()
drawMultilineLabel(context, "Assign extracted cpk directories below if you wish to enable bounding box visualization with layout import", box)
for i, assetDir in enumerate(self.assetDirs):
row = box.row(align=True)
row.prop(self.assetDirs[i], "directory", text="")
remOp = row.operator(RemoveDirectory.bl_idname, text="", icon="X")
remOp.index = i
remOp.settingsType = 0
addOp = box.operator(SelectDirectory.bl_idname, text="Add Directory", icon="FILE_FOLDER")
addOp.settingsType = 0
# asset blend dirs selection
box = layout.box()
drawMultilineLabel(context, "Assign downloaded blend directories below if you wish to enable full model visualization with layout import", box)
for i, assetDir in enumerate(self.assetBlendDirs):
row = box.row(align=True)
row.prop(self.assetBlendDirs[i], "directory", text="")
remOp = row.operator(RemoveDirectory.bl_idname, text="", icon="X")
remOp.index = i
remOp.settingsType = 1
addOp = box.operator(SelectDirectory.bl_idname, text="Add Directory", icon="FILE_FOLDER")
addOp.settingsType = 1
# asset dirs selection
box = layout.box()
drawMultilineLabel(context, "Assign extracted texture directories below for applying textures not included locally in DTT/DAT files", box)
for i, textureDir in enumerate(self.textureDirs):
row = box.row(align=True)
row.prop(self.textureDirs[i], "directory", text="")
remOp = row.operator(RemoveDirectory.bl_idname, text="", icon="X")
remOp.index = i
remOp.settingsType = 2
addOp = box.operator(SelectDirectory.bl_idname, text="Add Directory", icon="FILE_FOLDER")
addOp.settingsType = 2
def register():
bpy.utils.register_class(DirectoryProperty)
bpy.utils.register_class(SelectDirectory)
bpy.utils.register_class(RemoveDirectory)
bpy.utils.register_class(N2B2NPreferences)
def unregister():
bpy.utils.unregister_class(DirectoryProperty)
bpy.utils.unregister_class(SelectDirectory)
bpy.utils.unregister_class(RemoveDirectory)
bpy.utils.unregister_class(N2B2NPreferences)