This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 140
/
Copy pathpreferences.py
632 lines (435 loc) · 22.6 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
import bpy
from bpy.props import IntProperty, StringProperty, CollectionProperty, BoolProperty, EnumProperty
import os
import rna_keymap_ui
from . properties import AppendMatsCollection
from . utils.ui import get_icon
from . utils.registration import activate, get_path, get_name
preferences_tabs = [("GENERAL", "常规", ""),
("KEYMAPS", "键盘映射", ""),
("ABOUT", "关于", "")]
links = [("Documentation", "https://machin3.io/MACHIN3tools/docs/", "INFO"),
("MACHINƎ.io", "https://machin3.io", "WORLD"),
("Youtube", "https://www.youtube.com/channel/UC4yaFzFDILd2yAqOWRuLOvA", "NONE"),
("Twitter", "https://twitter.com/machin3io", "NONE"),
("", "", ""),
("", "", ""),
("DECALmachine", "https://machin3.io/DECALmachine", "NONE"),
("MESHmachine", "https://machin3.io/MESHmachine", "NONE"),
("", "", ""),
("", "", ""),
("MACHINƎ @ Artstation", "https://www.artstation.com/artist/machin3", "NONE"),
("", "", ""),
]
# TODO: check if the append world/materials paths exist and make them abosolute
class MACHIN3toolsPreferences(bpy.types.AddonPreferences):
path = get_path()
bl_idname = get_name()
# APPENDMATS
def update_appendmatsname(self, context):
if self.avoid_update:
self.avoid_update = False
return
else:
if self.appendmatsname and self.appendmatsname not in self.appendmats:
am = self.appendmats.add()
am.name = self.appendmatsname
self.appendmatsIDX = len(self.appendmats) - 1
self.avoid_update = True
self.appendmatsname = ""
# CHECKS
def update_switchmatcap1(self, context):
if self.avoid_update:
self.avoid_update = False
return
matcaps = [mc.name for mc in context.preferences.studio_lights if os.path.basename(os.path.dirname(mc.path)) == "matcap"]
if self.switchmatcap1 not in matcaps:
self.avoid_update = True
self.switchmatcap1 = "没有找到"
def update_switchmatcap2(self, context):
if self.avoid_update:
self.avoid_update = False
return
matcaps = [mc.name for mc in context.preferences.studio_lights if os.path.basename(os.path.dirname(mc.path)) == "matcap"]
if self.switchmatcap2 not in matcaps:
self.avoid_update = True
self.switchmatcap2 = "没有找到"
def update_custom_preferences_keymap(self, context):
if self.custom_preferences_keymap:
kc = context.window_manager.keyconfigs.user
for km in kc.keymaps:
if km.is_user_modified:
self.custom_preferences_keymap = False
self.dirty_keymaps = True
return
self.dirty_keymaps = False
# RUNTIME TOOL ACTIVATION
def update_activate_smart_vert(self, context):
activate(self, register=self.activate_smart_vert, tool="smart_vert")
def update_activate_smart_edge(self, context):
activate(self, register=self.activate_smart_edge, tool="smart_edge")
def update_activate_smart_face(self, context):
activate(self, register=self.activate_smart_face, tool="smart_face")
def update_activate_clean_up(self, context):
activate(self, register=self.activate_clean_up, tool="clean_up")
def update_activate_clipping_toggle(self, context):
activate(self, register=self.activate_clipping_toggle, tool="clipping_toggle")
def update_activate_focus(self, context):
activate(self, register=self.activate_focus, tool="focus")
def update_activate_mirror(self, context):
activate(self, register=self.activate_mirror, tool="mirror")
def update_activate_align(self, context):
activate(self, register=self.activate_align, tool="align")
def update_activate_apply(self, context):
activate(self, register=self.activate_apply, tool="apply")
def update_activate_select(self, context):
activate(self, register=self.activate_select, tool="select")
def update_activate_mesh_cut(self, context):
activate(self, register=self.activate_mesh_cut, tool="mesh_cut")
def update_activate_customize(self, context):
activate(self, register=self.activate_customize, tool="customize")
def update_activate_filebrowser_tools(self, context):
activate(self, register=self.activate_filebrowser_tools, tool="filebrowser")
# RUNTIME PIE ACTIVATION
def update_activate_modes_pie(self, context):
activate(self, register=self.activate_modes_pie, tool="modes_pie")
def update_activate_save_pie(self, context):
activate(self, register=self.activate_save_pie, tool="save_pie")
def update_activate_shading_pie(self, context):
activate(self, register=self.activate_shading_pie, tool="shading_pie")
def update_activate_views_pie(self, context):
activate(self, register=self.activate_views_pie, tool="views_pie")
def update_activate_align_pie(self, context):
activate(self, register=self.activate_align_pie, tool="align_pie")
def update_activate_cursor_pie(self, context):
activate(self, register=self.activate_cursor_pie, tool="cursor_pie")
def update_activate_transform_pie(self, context):
activate(self, register=self.activate_transform_pie, tool="transform_pie")
def update_activate_collections_pie(self, context):
activate(self, register=self.activate_collections_pie, tool="collections_pie")
def update_activate_workspace_pie(self, context):
activate(self, register=self.activate_workspace_pie, tool="workspace_pie")
# RUNTIME MENU ACTIVATION
def update_activate_object_context_menu(self, context):
activate(self, register=self.activate_object_context_menu, tool="object_context_menu")
# PROPERTIES
appendworldpath: StringProperty(name="世界环境源 .blend", subtype='FILE_PATH')
appendworldname: StringProperty(name="世界环境名称")
appendmatspath: StringProperty(name="材质源 .blend", subtype='FILE_PATH')
appendmats: CollectionProperty(type=AppendMatsCollection)
appendmatsIDX: IntProperty()
appendmatsname: StringProperty(name="添加的材质名称", update=update_appendmatsname)
switchmatcap1: StringProperty(name="材质捕获 1", update=update_switchmatcap1)
switchmatcap2: StringProperty(name="材质捕获 2", update=update_switchmatcap2)
obj_mode_rotate_around_active: BoolProperty(name="围绕选择项旋转,但只在物体模式下", default=False)
toggle_cavity: BoolProperty(name="切换 空腔 / 曲率 在编辑模式下禁用 在物体模式下启用", default=True)
focus_view_transition: BoolProperty(name="视口平移运动", default=True)
custom_startup: BoolProperty(name="启动场景", default=True)
custom_workspaces: BoolProperty(name="工作区", default=False)
custom_theme: BoolProperty(name="主题", default=True)
custom_matcaps: BoolProperty(name="材质捕获 (Matcaps) 和默认着色", default=True)
custom_overlays: BoolProperty(name="叠加", default=True)
custom_preferences_interface: BoolProperty(name="首选项:界面", default=True)
custom_preferences_viewport: BoolProperty(name="首选项:视口", default=True)
custom_preferences_navigation: BoolProperty(name="首选项:导航", default=True)
custom_preferences_keymap: BoolProperty(name="首选项:键盘映射", default=False, update=update_custom_preferences_keymap)
custom_preferences_system: BoolProperty(name="首选项:系统", default=False)
custom_preferences_save: BoolProperty(name="首选项:保存和载入", default=True)
# MACHIN3tools
activate_smart_vert: BoolProperty(name="智能 点", default=True, update=update_activate_smart_vert)
activate_smart_edge: BoolProperty(name="智能 线", default=True, update=update_activate_smart_edge)
activate_smart_face: BoolProperty(name="智能 面", default=True, update=update_activate_smart_face)
activate_clean_up: BoolProperty(name="清理", default=True, update=update_activate_clean_up)
activate_clipping_toggle: BoolProperty(name="裁剪切换", default=True, update=update_activate_clipping_toggle)
activate_focus: BoolProperty(name="聚焦", default=True, update=update_activate_focus)
activate_mirror: BoolProperty(name="镜像", default=True, update=update_activate_mirror)
activate_align: BoolProperty(name="对齐", default=True, update=update_activate_align)
activate_apply: BoolProperty(name="应用", default=True, update=update_activate_apply)
activate_select: BoolProperty(name="选择", default=True, update=update_activate_select)
activate_mesh_cut: BoolProperty(name="网格切割", default=True, update=update_activate_mesh_cut)
activate_filebrowser_tools: BoolProperty(name="文件浏览器工具", default=True, update=update_activate_filebrowser_tools)
activate_customize: BoolProperty(name="自定义", default=False, update=update_activate_customize)
# MACHIN3pies
activate_modes_pie: BoolProperty(name="模式 的饼菜单", default=True, update=update_activate_modes_pie)
activate_save_pie: BoolProperty(name="保存 的饼菜单", default=True, update=update_activate_save_pie)
activate_shading_pie: BoolProperty(name="着色 的饼菜单", default=True, update=update_activate_shading_pie)
activate_views_pie: BoolProperty(name="视图 的饼菜单", default=True, update=update_activate_views_pie)
activate_align_pie: BoolProperty(name="对齐 的饼菜单", default=True, update=update_activate_align_pie)
activate_cursor_pie: BoolProperty(name="游标 的饼菜单", default=True, update=update_activate_cursor_pie)
activate_transform_pie: BoolProperty(name="变换 的饼菜单", default=True, update=update_activate_transform_pie)
activate_collections_pie: BoolProperty(name="集合 的饼菜单", default=True, update=update_activate_collections_pie)
activate_workspace_pie: BoolProperty(name="工作区 的饼菜单", default=False, update=update_activate_workspace_pie)
# MACHIN3menus
activate_object_context_menu: BoolProperty(name="对象上下文菜单", default=True, update=update_activate_object_context_menu)
# hidden
tabs: EnumProperty(name="Tabs", items=preferences_tabs, default="GENERAL")
avoid_update: BoolProperty(default=False)
dirty_keymaps: BoolProperty(default=False)
def draw(self, context):
layout=self.layout
# TAB BAR
column = layout.column(align=True)
row = column.row()
row.prop(self, "tabs", expand=True)
box = column.box()
if self.tabs == "GENERAL":
self.draw_general(box)
elif self.tabs == "KEYMAPS":
self.draw_keymaps(box)
elif self.tabs == "ABOUT":
self.draw_about(box)
def draw_general(self, box):
split = box.split()
# LEFT
b = split.box()
b.label(text="触发")
# MACHIN3tools
bb = b.box()
bb.label(text="工具")
column = bb.column()
row = column.split(factor=0.25)
row.prop(self, "activate_smart_vert", toggle=True)
row.label(text="智能顶点操作。")
row = column.split(factor=0.25)
row.prop(self, "activate_smart_edge", toggle=True)
row.label(text="智能边缘创建,操作和转换选中项。")
row = column.split(factor=0.25)
row.prop(self, "activate_smart_face", toggle=True)
row.label(text="智能平面创建和从面创建物体。")
row = column.split(factor=0.25)
row.prop(self, "activate_clean_up", toggle=True)
row.label(text="快速几何清理。")
row = column.split(factor=0.25)
row.prop(self, "activate_clipping_toggle", toggle=True)
row.label(text="视口裁剪平面切换。")
row = column.split(factor=0.25)
row.prop(self, "activate_focus", toggle=True)
row.label(text="与历史对象隔离。")
row = column.split(factor=0.25)
row.prop(self, "activate_mirror", toggle=True)
row.label(text="物体镜像 + 非镜像。")
row = column.split(factor=0.25)
row.prop(self, "activate_align", toggle=True)
row.label(text="物体每个轴的位置、旋转和比例对齐。")
row = column.split(factor=0.25)
row.prop(self, "activate_apply", toggle=True)
row.label(text="应用转换同时保持斜角宽度以及子转换不变。")
row = column.split(factor=0.25)
row.prop(self, "activate_select", toggle=True)
row.label(text="选择助手。")
row = column.split(factor=0.25)
row.prop(self, "activate_mesh_cut", toggle=True)
row.label(text="使用另一个相交对象切割网格。")
row = column.split(factor=0.25)
row.prop(self, "activate_filebrowser_tools", toggle=True)
row.label(text="Additional tools for the Filebrowser.")
row = column.split(factor=0.25)
row.prop(self, "activate_customize", toggle=True)
row.label(text="自定义各种 Blender 首选项,设置和键盘映射。")
# MACHIN3pies
bb = b.box()
bb.label(text="饼菜单")
column = bb.column()
row = column.split(factor=0.25)
row.prop(self, "activate_modes_pie", toggle=True)
row.label(text="快速模式更改。")
row = column.split(factor=0.25)
row.prop(self, "activate_save_pie", toggle=True)
row.label(text="保存,打开,追加。加载最近,上一个和下一个。追加世界环境和材质。")
row = column.split(factor=0.25)
row.prop(self, "activate_shading_pie", toggle=True)
row.label(text="控制着色,遮罩,EEVEE 和一些对象属性。")
row = column.split(factor=0.25)
row.prop(self, "activate_views_pie", toggle=True)
row.label(text="控制视图。创建和管理相机。")
row = column.split(factor=0.25)
row.prop(self, "activate_align_pie", toggle=True)
row.label(text="编辑网格和 UV 对齐方式。")
row = column.split(factor=0.25)
row.prop(self, "activate_cursor_pie", toggle=True)
row.label(text="游标和原心操作。")
row = column.split(factor=0.25)
row.prop(self, "activate_transform_pie", toggle=True)
row.label(text="Transform Orientations and Pivots.")
row = column.split(factor=0.25)
row.prop(self, "activate_collections_pie", toggle=True)
row.label(text="集合管理。")
row = column.split(factor=0.25)
row.prop(self, "activate_workspace_pie", toggle=True)
r = row.split(factor=0.4)
r.label(text="切换工作区。")
r.label(text="如果启用,请在 ui/pies.py 中对其进行自定义", icon="INFO")
# MACHIN3menus
bb = b.box()
bb.label(text="菜单")
column = bb.column()
row = column.split(factor=0.25)
row.prop(self, "activate_object_context_menu", toggle=True)
row.label(text="没有键盘映射的 对象上下文菜单,访问工具。")
# RIGHT
b = split.box()
b.label(text="设置")
# FOCUS
if getattr(bpy.types, "MACHIN3_OT_focus", False):
bb = b.box()
bb.label(text="Focus")
column = bb.column()
column.prop(self, "focus_view_transition")
# CUSTOMIZE
if getattr(bpy.types, "MACHIN3_OT_customize", False):
bb = b.box()
bb.label(text="自定义")
bbb = bb.box()
column = bbb.column()
row = column.row()
row.prop(self, "custom_startup")
row.prop(self, "custom_workspaces")
row.prop(self, "custom_theme")
row.prop(self, "custom_matcaps")
row.prop(self, "custom_overlays")
bbb = bb.box()
column = bbb.column()
row = column.row()
col = row.column()
col.prop(self, "custom_preferences_interface")
col.prop(self, "custom_preferences_viewport")
col = row.column()
col.prop(self, "custom_preferences_navigation")
col.prop(self, "custom_preferences_keymap")
col = row.column()
col.prop(self, "custom_preferences_system")
col.prop(self, "custom_preferences_save")
if self.dirty_keymaps:
row = column.row()
row.label(text="键盘映射已被修改,需要先恢复它们。", icon="ERROR")
row.operator("machin3.restore_keymaps", text="立刻恢复")
row.label()
column = bb.column()
row = column.row()
row.label()
row.operator("machin3.customize", text="Customize")
row.label()
# MODES PIE
if getattr(bpy.types, "MACHIN3_MT_modes_pie", False):
bb = b.box()
bb.label(text="模式 的饼菜单")
column = bb.column()
column.prop(self, "toggle_cavity")
# SAVE PIE
if getattr(bpy.types, "MACHIN3_MT_save_pie", False):
bb = b.box()
bb.label(text="保存 的饼菜单:追加世界环境和材质")
column = bb.column()
column.prop(self, "appendworldpath")
column.prop(self, "appendworldname")
column.separator()
column.prop(self, "appendmatspath")
column = bb.column()
row = column.row()
rows = len(self.appendmats) if len(self.appendmats) > 6 else 6
row.template_list("MACHIN3_UL_append_mats", "", self, "appendmats", self, "appendmatsIDX", rows=rows)
c = row.column(align=True)
c.operator("machin3.move_appendmat", text="", icon='TRIA_UP').direction = "UP"
c.operator("machin3.move_appendmat", text="", icon='TRIA_DOWN').direction = "DOWN"
c.separator()
c.operator("machin3.clear_appendmats", text="", icon='LOOP_BACK')
c.operator("machin3.remove_appendmat", text="", icon_value=get_icon('cancel'))
c.separator()
c.operator("machin3.populate_appendmats", text="", icon='MATERIAL')
c.operator("machin3.rename_appendmat", text="", icon='OUTLINER_DATA_FONT')
row = column.row()
row.prop(self, "appendmatsname")
row.operator("machin3.add_separator", text="", icon_value=get_icon('separator'))
# SHADING PIE
if getattr(bpy.types, "MACHIN3_MT_shading_pie", False):
bb = b.box()
bb.label(text="着色 的饼菜单:材质捕获开关")
column = bb.column()
row = column.row()
row.prop(self, "switchmatcap1")
row.prop(self, "switchmatcap2")
# NO SETTINGS
if not any([getattr(bpy.types, "MACHIN3_" + name, False) for name in ["MT_modes_pie", "MT_save_pie", "MT_shading_pie"]]):
b.label(text="没有工具或已激活带有设置的饼图菜单。")
def draw_keymaps(self, box):
wm = bpy.context.window_manager
# kc = wm.keyconfigs.addon
kc = wm.keyconfigs.user
from . registration import keys
split = box.split()
b = split.box()
b.label(text="工具")
if not self.draw_tool_keymaps(kc, keys, b):
b.label(text="没有可用的键盘映射,因为没有激活任何工具。")
b = split.box()
b.label(text="饼菜单")
if not self.draw_pie_keymaps(kc, keys, b):
b.label(text="未创建任何键盘映射,因为没有激活任何饼菜单。")
def draw_about(self, box):
column = box.column()
for idx, (text, url, icon) in enumerate(links):
if idx % 2 == 0:
row = column.row()
if text == "":
row.separator()
else:
row.operator("wm.url_open", text=text, icon=icon).url = url
else:
if text == "":
row.separator()
else:
row.operator("wm.url_open", text=text, icon=icon).url = url
def draw_tool_keymaps(self, kc, keysdict, layout):
drawn = False
for name in keysdict:
if "PIE" not in name:
keylist = keysdict.get(name)
if self.draw_keymap_items(kc, name, keylist, layout):
drawn = True
return drawn
def draw_pie_keymaps(self, kc, keysdict, layout):
drawn = False
for name in keysdict:
if "PIE" in name:
keylist = keysdict.get(name)
if self.draw_keymap_items(kc, name, keylist, layout):
drawn = True
return drawn
def draw_keymap_items(self, kc, name, keylist, layout):
drawn = False
for idx, item in enumerate(keylist):
keymap = item.get("keymap")
if keymap:
km = kc.keymaps.get(keymap)
kmi = None
if km:
idname = item.get("idname")
for kmitem in km.keymap_items:
if kmitem.idname == idname:
properties = item.get("properties")
if properties:
if all([getattr(kmitem.properties, name, None) == value for name, value in properties]):
kmi = kmitem
break
else:
kmi = kmitem
break
# draw keymap item
if kmi:
# multi kmi tools, will only have a single box, created for the first kmi
if idx == 0:
box = layout.box()
# single kmi tools, get their label from the title
if len(keylist) == 1:
label = name.title().replace("_", " ")
# multi kmi tools, get it from the label tag, while the title is printed once, before the first item
else:
if idx == 0:
box.label(text=name.title().replace("_", " "))
label = item.get("label")
row = box.split(factor=0.15)
row.label(text=label)
# layout.context_pointer_set("keymap", km)
rna_keymap_ui.draw_kmi(["ADDON", "USER", "DEFAULT"], kc, km, kmi, row, 0)
drawn = True
return drawn