-
-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathsollumz_preferences.py
More file actions
1324 lines (1093 loc) · 47.5 KB
/
sollumz_preferences.py
File metadata and controls
1324 lines (1093 loc) · 47.5 KB
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
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import bpy
from bpy.types import (
bpy_struct,
bpy_prop_array,
bpy_prop_collection,
PropertyGroup,
Operator,
UIList,
UILayout,
AddonPreferences,
)
from bpy.props import (
StringProperty,
IntProperty,
BoolProperty,
EnumProperty,
CollectionProperty,
PointerProperty,
FloatVectorProperty,
FloatProperty,
)
from bpy_extras.io_utils import ImportHelper
import rna_keymap_ui
import os
import ast
import textwrap
from typing import Optional, Any, TYPE_CHECKING
from configparser import ConfigParser
from pathlib import Path
from .known_paths import prefs_file_path, config_directory_path, data_directory_path
from .dependencies import IS_SZIO_NATIVE_AVAILABLE, PYMATERIA_REQUIRED_MSG
if TYPE_CHECKING:
from .iecontext import ImportSettings, ExportSettings
def _save_preferences_on_update(self, context):
_save_preferences()
def _on_update_thunk(self, context):
# Thunk to allow to override the callback
if cb := getattr(self, "_on_update", None):
cb(context)
class ExportSettingsBase:
def _on_update(self, context):
...
target_formats: bpy.props.EnumProperty(
name="Target Formats",
description="Formats to output during export",
items=(
(
"NATIVE", "Native",
"Binary resource format. The game's native format which can be used directly" +
("" if IS_SZIO_NATIVE_AVAILABLE else ".\n\n" + PYMATERIA_REQUIRED_MSG),
1
),
(
"CWXML", "CW XML",
"CodeWalker XML format. Human-readable text format but needs to be imported through CodeWalker before "
"it can be used by the game",
2
),
),
default={"NATIVE", "CWXML"},
options={"ENUM_FLAG"},
update=_on_update_thunk,
)
target_versions: bpy.props.EnumProperty(
name="Target Game Versions",
description=(
"Game versions to export for. If both are enabled, files are placed in separate 'gen8/' and 'gen9/' "
"subdirectories"
),
items=(
("GEN8", "Gen8", "GTAV Legacy", 1),
("GEN9", "Gen9", "GTAV Enhanced", 2),
),
default={"GEN8", "GEN9"},
options={"ENUM_FLAG"},
update=_on_update_thunk,
)
limit_to_selected: BoolProperty(
name="Limit to Selected",
description="Export selected and visible objects only",
default=True,
update=_on_update_thunk,
)
exclude_skeleton: BoolProperty(
name="Exclude Skeleton",
description="Exclude skeleton from export. Usually done with mp ped components",
default=False,
update=_on_update_thunk,
)
ymap_exclude_entities: BoolProperty(
name="Exclude Entities",
description="If enabled, ignore all Entities from the selected ymap(s)",
default=False,
update=_on_update_thunk,
)
ymap_box_occluders: BoolProperty(
name="Exclude Box Occluders",
description="If enabled, ignore all Box occluders from the selected ymap(s)",
default=False,
update=_on_update_thunk,
)
ymap_model_occluders: BoolProperty(
name="Exclude Model Occluders",
description="If enabled, ignore all Model occluders from the selected ymap(s)",
default=False,
update=_on_update_thunk,
)
ymap_car_generators: BoolProperty(
name="Exclude Car Generators",
description="If enabled, ignore all Car Generators from the selected ymap(s)",
default=False,
update=_on_update_thunk,
)
apply_transforms: BoolProperty(
name="Apply Parent Transforms",
description="Apply Drawable/Fragment scale and rotation",
default=False,
update=_on_update_thunk,
)
mesh_domain: EnumProperty(
name="Mesh Domain",
description="Domain considered for exporting meshes",
default="FACE_CORNER",
items=(
(
"FACE_CORNER", "Face Corner",
"Mesh is exported allowing each face corner to have their own set of "
"attributes. Recommended default setting."
),
(
"VERTEX", "Vertex",
"Mesh is exported only allowing a single set of attributes per vertex. Recommended for when it is important "
"that the vertex order and count remains the same during import and export, such as with MP freemode head "
"models.\n\n"
"If face corners attached to the vertex have different attributes (vertex colors, UVs, etc.), only the "
"attributes of one of the face corners is used. In the case of normals, the average of the face corner "
"normals is used."
)
),
update=_on_update_thunk,
)
def to_export_context_settings(self) -> "ExportSettings":
import itertools
from .iecontext import ExportSettings, VBBuilderDomain
from szio.gta5 import is_provider_available, AssetFormat, AssetVersion, AssetTarget
return ExportSettings(
targets=tuple(
t
for format_id, version_id in itertools.product(self.target_formats, self.target_versions)
if is_provider_available(t := AssetTarget(AssetFormat[format_id], AssetVersion[version_id]))
),
apply_transforms=self.apply_transforms,
exclude_skeleton=self.exclude_skeleton,
mesh_domain=VBBuilderDomain[self.mesh_domain],
)
class ImportSettingsBase:
def _on_update(self, context):
...
import_as_asset: BoolProperty(
name="Import To Asset Library",
description="Imports the selected file as an asset to the current blend file asset library",
default=False,
update=_on_update_thunk,
)
split_by_group: BoolProperty(
name="Split Mesh by Vertex Group",
description="Splits the mesh by the vertex groups",
default=True,
update=_on_update_thunk,
)
import_ext_skeleton: BoolProperty(
name="Import External Skeleton",
description="Imports the first found yft skeleton in the same folder as the selected file",
default=False,
update=_on_update_thunk,
)
frag_import_vehicle_windows: BoolProperty(
name="Import Window Shattermaps",
description=(
"Import vehicle window shattermaps as objects in the scene. If not imported, shattermaps will be "
"automatically generated on export (recommended)"
),
default=False,
update=_on_update_thunk,
)
ymap_skip_missing_entities: BoolProperty(
name="Skip Missing Entities",
description="If enabled, missing entities wont be created as an empty object",
default=True,
update=_on_update_thunk,
)
ymap_exclude_entities: BoolProperty(
name="Exclude Entities",
description="If enabled, ignore all entities from the selected ymap(s)",
default=False,
update=_on_update_thunk,
)
ymap_box_occluders: BoolProperty(
name="Exclude Box Occluders",
description="If enabled, ignore all Box occluders from the selected ymap(s)",
default=False,
update=_on_update_thunk,
)
ymap_model_occluders: BoolProperty(
name="Exclude Model Occluders",
description="If enabled, ignore all Model occluders from the selected ymap(s)",
default=False,
update=_on_update_thunk,
)
ymap_car_generators: BoolProperty(
name="Exclude Car Generators",
description="If enabled, ignore all Car Generators from the selected ymap(s)",
default=False,
update=_on_update_thunk,
)
ymap_instance_entities: BoolProperty(
name="Instance Entities",
description="If enabled, instance all entities from the selected ymap(s)",
default=False,
update=_on_update_thunk,
)
ytyp_mlo_instance_entities: BoolProperty(
name="Instance MLO Entities",
description=(
"If enabled, MLO entities will be linked to a copy of the object matching the archetype name, instead of"
"the object itself"
),
default=True,
update=_on_update_thunk,
)
textures_mode: EnumProperty(
name="Textures Mode",
description="How to handle textures during import",
items=(
("PACK", "Pack into Blend File (default)", "Pack textures into the .blend file (recommended)"),
("IMPORT_DIR", "Extract to Import Directory", "Extract textures to a directory next to the imported file"),
("CUSTOM_DIR", "Extract to Custom Directory", "Extract textures to a custom directory specified below"),
),
default="PACK",
update=_on_update_thunk,
)
textures_extract_custom_directory: StringProperty(
name="Custom Textures Directory",
description=(
"Custom directory for extracting textures. If not set, the import directory will be used as fallback."
),
subtype="DIR_PATH",
default="",
update=_on_update_thunk,
)
def to_import_context_settings(self) -> "ImportSettings":
from .iecontext import ImportSettings, ImportTexturesMode
textures_mode = ImportTexturesMode[self.textures_mode]
textures_extract_custom_dir=(
Path(bpy.path.abspath(self.textures_extract_custom_directory))
if self.textures_extract_custom_directory
else None
)
if textures_mode == ImportTexturesMode.CUSTOM_DIR and not textures_extract_custom_dir:
# If there is no custom directory set, fallback to the import directory.
textures_mode = ImportTexturesMode.IMPORT_DIR
return ImportSettings(
import_as_asset=self.import_as_asset,
split_by_group=self.split_by_group,
mlo_instance_entities=self.ytyp_mlo_instance_entities,
import_external_skeleton=self.import_ext_skeleton,
frag_import_vehicle_windows=self.frag_import_vehicle_windows,
textures_mode=textures_mode,
textures_extract_custom_directory=textures_extract_custom_dir,
)
class SollumzExportSettings(ExportSettingsBase, PropertyGroup):
def _on_update(self, context):
# Make sure there is always something selected in the target format/version
from szio.gta5 import is_provider_available, AssetFormat
if not self.target_formats or (not is_provider_available(AssetFormat.NATIVE) and "CWXML" not in self.target_formats):
self.target_formats = {"CWXML"}
return # the assignment above will trigger this callback again
if not self.target_versions:
self.target_versions = {"GEN8"}
return # the assignment above will trigger this callback again
_save_preferences_on_update(self, context)
class SollumzImportSettings(ImportSettingsBase, PropertyGroup):
def _on_update(self, context):
_save_preferences_on_update(self, context)
class SollumzThemeSettings(PropertyGroup):
def RGBAProperty(name: str, default: tuple[float, float, float]):
return FloatVectorProperty(
name=name,
subtype="COLOR",
min=0, max=1,
size=4,
default=default,
update=_save_preferences_on_update,
)
mlo_gizmo_room: RGBAProperty("Room", (0.31, 0.38, 1.0, 0.7))
mlo_gizmo_room_selected: RGBAProperty("Room Selected", (0.62, 0.76, 1.0, 0.9))
mlo_gizmo_portal: RGBAProperty("Portal", (0.45, 0.98, 0.55, 0.5))
mlo_gizmo_portal_selected: RGBAProperty("Portal Selected", (0.93, 1.0, 1.0, 0.7))
mlo_gizmo_portal_direction: RGBAProperty("Portal Direction Arrow", (0.0, 0.6, 1.0, 0.3))
mlo_gizmo_portal_direction_size: FloatProperty(name="Portal Direction Arrow Size", default=0.3, min=0.1, max=5.0)
mlo_gizmo_tcm: RGBAProperty("Timecycle Modifier", (0.45, 0.98, 0.55, 0.5))
mlo_gizmo_tcm_selected: RGBAProperty("Timecycle Modifier Selected", (0.93, 1.0, 1.0, 0.7))
cable_overlay_radius: RGBAProperty("Radius", (1.0, 0.0, 0.0, 1.0))
cloth_overlay_pinned: RGBAProperty("Pinned", (1.0, 0.65, 0.0, 0.5))
cloth_overlay_pinned_size: IntProperty(name="Pinned Size", default=12, min=1, max=50)
cloth_overlay_material_errors: RGBAProperty("Material Errors", (1.0, 0.05, 0.025, 0.45))
cloth_overlay_binding_errors: RGBAProperty("Binding Errors", (1.0, 0.05, 0.025, 0.75))
cloth_overlay_binding_errors_size: IntProperty(name="Binding Errors Size", default=12, min=1, max=50)
def reset(self):
for prop_name, annotation in SollumzThemeSettings.__annotations__.items():
setattr(self, prop_name, annotation.keywords["default"])
class SOLLUMZ_OT_prefs_theme_reset(Operator):
bl_idname = "sollumz.prefs_theme_reset"
bl_label = "Reset Theme"
bl_description = "Reset all theme settings to their default values"
def execute(self, context):
get_theme_settings(context).reset()
_save_preferences()
return {"FINISHED"}
class SzSharedTexturesDirectory(PropertyGroup):
path: StringProperty(
name="Path",
description="Path to a directory with textures",
subtype="DIR_PATH",
update=_save_preferences_on_update,
)
recursive: BoolProperty(
name="Recursive",
description="Search this directory recursively",
default=True,
update=_save_preferences_on_update,
)
class SOLLUMZ_UL_prefs_shared_textures_directories(UIList):
bl_idname = "SOLLUMZ_UL_prefs_shared_textures_directories"
def draw_item(
self, context, layout, data, item, icon, active_data, active_propname, index
):
layout.prop(item, "path", text="", emboss=False)
layout.prop(item, "recursive", text="", icon="OUTLINER")
class SOLLUMZ_OT_prefs_shared_textures_directory_add(Operator):
bl_idname = "sollumz.prefs_shared_textures_directory_add"
bl_label = "Add Shared Textures Directory"
bl_description = "Add a new directory to search textures in"
path: StringProperty(
name="Path",
description="Path to a directory with textures",
subtype="DIR_PATH",
)
recursive: BoolProperty(
name="Recursive",
description="Search this directory recursively",
default=True,
)
def execute(self, context):
prefs = get_addon_preferences(context)
d = prefs.shared_textures_directories.add()
d.path = self.path
d.recursive = self.recursive
prefs.shared_textures_directories_index = len(prefs.shared_textures_directories) - 1
_save_preferences()
return {"FINISHED"}
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_props_dialog(self)
class SOLLUMZ_OT_prefs_shared_textures_directory_remove(Operator):
bl_idname = "sollumz.prefs_shared_textures_directory_remove"
bl_label = "Remove Shared Textures Directory"
bl_description = "Remove the selected directory"
@classmethod
def poll(cls, context):
prefs = get_addon_preferences(context)
return 0 <= prefs.shared_textures_directories_index < len(prefs.shared_textures_directories)
def execute(self, context):
prefs = get_addon_preferences(context)
prefs.shared_textures_directories.remove(prefs.shared_textures_directories_index)
prefs.shared_textures_directories_index = max(prefs.shared_textures_directories_index - 1, 0)
_save_preferences()
return {"FINISHED"}
class SOLLUMZ_OT_prefs_shared_textures_directory_move_up(Operator):
bl_idname = "sollumz.prefs_shared_textures_directory_move_up"
bl_label = "Increase Shared Texture Directory Priority"
bl_description = "Increase search priority of this directory"
@classmethod
def poll(self, context):
prefs = get_addon_preferences(context)
return 0 < prefs.shared_textures_directories_index < len(prefs.shared_textures_directories)
def execute(self, context):
prefs = get_addon_preferences(context)
indexA = prefs.shared_textures_directories_index
indexB = prefs.shared_textures_directories_index - 1
prefs.swap_shared_textures_directories(indexA, indexB)
prefs.shared_textures_directories_index -= 1
return {"FINISHED"}
class SOLLUMZ_OT_prefs_shared_textures_directory_move_down(Operator):
bl_idname = "sollumz.prefs_shared_textures_directory_move_down"
bl_label = "Decrease Shared Texture Directory Priority"
bl_description = "Decrease search priority of this directory"
@classmethod
def poll(self, context):
prefs = get_addon_preferences(context)
return 0 <= prefs.shared_textures_directories_index < (len(prefs.shared_textures_directories) - 1)
def execute(self, context):
prefs = get_addon_preferences(context)
indexA = prefs.shared_textures_directories_index
indexB = prefs.shared_textures_directories_index + 1
prefs.swap_shared_textures_directories(indexA, indexB)
prefs.shared_textures_directories_index += 1
return {"FINISHED"}
def _update_name_tables():
import szio.gta5.jenkhash
nt_paths = [nt.path for nt in get_addon_preferences().name_table_paths]
cache_path = Path(data_directory_path()) / "nametable.cache"
szio.gta5.jenkhash.load_name_tables(nt_paths, cache_path)
def _on_update_name_tables(self, context):
_save_preferences_on_update(self, context)
_update_name_tables()
class SzNameTablePath(PropertyGroup):
path: StringProperty(
name="Path",
description="Path to a name table file",
subtype="FILE_PATH",
update=_on_update_name_tables,
)
# NOTE: this is here for forward compatibility to avoid breaking the preferences .ini, we will probably need to
# split the name tables for different contexts (e.g. GTA5, RDR2, drawable dictionaries) at some point. For
# now, they are all added to the same dictionary so default to GLOBAL.
category: EnumProperty(
items=(
("GLOBAL", "Global", "", "", 0),
),
default="GLOBAL",
)
class SOLLUMZ_UL_prefs_name_table_paths(UIList):
bl_idname = "SOLLUMZ_UL_prefs_name_table_paths"
def draw_item(
self, context, layout, data, item, icon, active_data, active_propname, index
):
layout.prop(item, "path", text="", emboss=False)
class SOLLUMZ_OT_prefs_name_table_path_add(Operator, ImportHelper):
bl_idname = "sollumz.prefs_name_table_path_add"
bl_label = "Add Name Tables"
bl_description = "Add new name tables"
directory: bpy.props.StringProperty(subtype="DIR_PATH", options={"HIDDEN", "SKIP_SAVE"})
files: bpy.props.CollectionProperty(
name="File Path",
type=bpy.types.OperatorFileListElement,
options={"HIDDEN", "SKIP_SAVE"}
)
filter_glob: bpy.props.StringProperty(
default="".join(f"*{ext};" for ext in (".txt", ".nametable")),
options={"HIDDEN", "SKIP_SAVE"},
maxlen=255,
)
def execute(self, context):
if not self.directory or len(self.files) == 0 or self.files[0].name == "":
# logger.info("No file selected for import!")
return {"CANCELLED"}
self.directory = bpy.path.abspath(self.directory)
from pathlib import Path
filenames = [f.name for f in self.files]
directory = Path(self.directory)
for filename in filenames:
filepath = (directory / filename).absolute()
prefs = get_addon_preferences(context)
d = prefs.name_table_paths.add()
d.path = str(filepath)
prefs.name_table_paths_index = len(prefs.name_table_paths) - 1
_save_preferences()
_update_name_tables()
return {"FINISHED"}
class SOLLUMZ_OT_prefs_name_table_path_remove(Operator):
bl_idname = "sollumz.prefs_name_table_path_remove"
bl_label = "Remove Name Table Path"
bl_description = "Remove the selected name table"
@classmethod
def poll(cls, context):
prefs = get_addon_preferences(context)
return 0 <= prefs.name_table_paths_index < len(prefs.name_table_paths)
def execute(self, context):
prefs = get_addon_preferences(context)
prefs.name_table_paths.remove(prefs.name_table_paths_index)
prefs.name_table_paths_index = max(prefs.name_table_paths_index - 1, 0)
_save_preferences()
_update_name_tables()
return {"FINISHED"}
class SzFavoriteEntry(PropertyGroup):
name: StringProperty(
name="Name",
)
class SollumzAddonPreferences(AddonPreferences):
bl_idname = __package__
def _on_show_version_update(self, context):
_save_preferences_on_update(self, context)
from .sollumz_ui import statusbar_register_draw, statusbar_unregister_draw
statusbar_unregister_draw()
if self.show_version_in_statusbar:
statusbar_register_draw()
show_version_in_statusbar: BoolProperty(
name="Show Sollumz Version in Status Bar",
description="Show the Sollumz version next to the Blender version in the status bar",
default=True,
update=_on_show_version_update
)
show_vertex_painter: BoolProperty(
name="Show Vertex Painter",
description="Show the Vertex Painter panel in General Tools (Includes Terrain Painter)",
default=True,
update=_save_preferences_on_update
)
extra_color_swatches: BoolProperty(
name="Extra Vertex Color Swatches",
description="Add 3 extra color swatches to the Vertex Painter Panel (Max 6)",
default=True,
update=_save_preferences_on_update
)
sollumz_icon_header: BoolProperty(
name="Show Sollumz icon",
description="Show the Sollumz icon in properties section headers",
default=True,
update=_save_preferences_on_update
)
use_text_name_as_mat_name: BoolProperty(
name="Use Texture Name as Material Name",
description="Use the name of the texture as the material name",
default=True,
update=_save_preferences_on_update
)
shader_preset_apply_textures: BoolProperty(
name="Apply Textures from Shader Preset",
description=(
"Enable to replace the material's existing textures with those from the shader preset. Disable to keep the "
"current textures unchanged"
),
default=True,
update=_save_preferences_on_update
)
default_flags_portal: IntProperty(
name="Default Portal Flags",
description="The default flags for MLO portals",
default=0,
update=_save_preferences_on_update
)
default_flags_room: IntProperty(
name="Default Room Flags",
description="The default flags for MLO rooms",
default=0,
update=_save_preferences_on_update
)
default_flags_entity: IntProperty(
name="Default Entity Flags",
description="The default flags for MLO entities",
default=0,
update=_save_preferences_on_update
)
default_flags_archetype: IntProperty(
name="Default Archetype Flags",
description="The default flags for archetypes",
default=0,
update=_save_preferences_on_update
)
default_sync_selection_enabled: BoolProperty(
name="Selection Sync Enabled by Default",
description="Enable archetype/entity selection sync by default in new scenes. Requires restart to take effect",
default=True,
update=_save_preferences_on_update
)
shared_textures_directories: CollectionProperty(
name="Shared Textures",
type=SzSharedTexturesDirectory,
)
shared_textures_directories_index: IntProperty(
name="Selected Shared Textures Directory",
min=0
)
name_table_paths: CollectionProperty(
name="Name Tables",
type=SzNameTablePath,
)
name_table_paths_index: IntProperty(
name="Selected Name Table",
min=0
)
favorite_shaders: CollectionProperty(
name="Favorite Shaders",
type=SzFavoriteEntry,
)
favorite_collision_materials: CollectionProperty(
name="Favorite Collision Materials",
type=SzFavoriteEntry,
)
# TODO: operator to create JSON from procedural.meta
# tree = ET.parse("procedural.meta")
# procids = [elem.text for elem in tree.getroot().findall("./procTagTable/Item/name")]
# with open("procids.json", "w") as f:
# json.dump(procids, f, separators=(',', ':'))
def _on_custom_procids_path_update(self, context):
_save_preferences_on_update(self, context)
from .ybn.properties import ProceduralIdEnumItems
ProceduralIdEnumItems.reload()
custom_procids_path: StringProperty(
name="Custom Procedural IDs",
description=(
"Path to a JSON file with a custom list of procedural IDs names (a JSON array of strings with 255 entries). "
"Useful if you are using a modified procedural.meta file"
),
subtype="FILE_PATH",
update=_on_custom_procids_path_update,
)
legacy_import_export: BoolProperty(
name="Legacy Import/Export",
description=(
"Use the legacy import/export system, which only supports CodeWalker XML format. "
"Enable this option only if you experience issues or errors with the new import/export system "
"with binary resource formats support"
),
default=False,
update=_save_preferences_on_update
)
popup_shown_install_dependencies: BoolProperty(
default=False,
update=_save_preferences_on_update
)
export_settings: PointerProperty(type=SollumzExportSettings, name="Export Settings")
import_settings: PointerProperty(type=SollumzImportSettings, name="Import Settings")
theme: PointerProperty(type=SollumzThemeSettings, name="Theme")
tab: EnumProperty(
items=(
("GENERAL", "General", "", "SETTINGS", 0),
("IMPORT_EXPORT", "Import / Export", "", "IMPORT", 1),
("KEYMAP", "Keymap", "", "KEY_TAB", 3),
("UI", "UI", "", "WINDOW", 4),
("THEME", "Theme", "", "COLOR", 5),
("ABOUT", "About", "", "INFO_LARGE", 6),
)
)
def swap_shared_textures_directories(self, indexA: int, indexB: int):
a = self.shared_textures_directories[indexA]
b = self.shared_textures_directories[indexB]
pathA, recA = a.path, a.recursive
pathB, recB = b.path, b.recursive
a.path, a.recursive = pathB, recB
b.path, b.recursive = pathA, recA
def _is_favorite(self, favorites, entry_name: str) -> bool:
for entry in favorites:
if entry.name == entry_name:
return True
return False
def _toggle_favorite(self, favorites, entry_name: str, favorite: bool):
found = None
for i, entry in enumerate(favorites):
if entry.name == entry_name:
found = i
break
updated = False
if favorite:
# Set as favorite
if found is None:
s = favorites.add()
s.name = entry_name
updated = True
else:
# Remove from favorites
if found is not None:
favorites.remove(found)
updated = True
if updated:
_save_preferences()
def is_favorite_shader(self, shader_name: str) -> bool:
return self._is_favorite(self.favorite_shaders, shader_name)
def is_favorite_collision_material(self, collision_material_name: str) -> bool:
return self._is_favorite(self.favorite_collision_materials, collision_material_name)
def toggle_favorite_shader(self, shader_name: str, favorite: bool):
self._toggle_favorite(self.favorite_shaders, shader_name, favorite)
def toggle_favorite_collision_material(self, collision_material_name: str, favorite: bool):
self._toggle_favorite(self.favorite_collision_materials, collision_material_name, favorite)
def draw(self, context):
layout = self.layout
layout.row().prop(self, "tab", expand=True)
# Based on CenterAlignMixIn from Blender's scripts/startup/bl_ui/space_userpref.py
width = context.region.width
ui_scale = context.preferences.system.ui_scale
# No horizontal margin if region is rather small.
is_wide = width > (550 * ui_scale)
layout.use_property_split = True
layout.use_property_decorate = False # No animation.
row = layout.row()
if is_wide:
row.label() # Needed so col below is centered.
col = row.column()
col.ui_units_x = 95
match self.tab:
case "GENERAL":
self.draw_general(context, col)
case "IMPORT_EXPORT":
self.draw_import_export(context, col)
case "KEYMAP":
self.draw_keymap(context, col)
case "UI":
self.draw_ui(context, col)
case "THEME":
self.draw_theme(context, col)
case "ABOUT":
self.draw_about(context, col)
if is_wide:
row.label() # Needed so col above is centered.
def draw_general(self, context, layout: UILayout):
layout.prop(self, "use_text_name_as_mat_name")
layout.prop(self, "shader_preset_apply_textures")
layout.prop(self, "default_sync_selection_enabled")
col = layout.column(align=True)
col.prop(self, "default_flags_portal", text="Default Flags for Portals")
col.prop(self, "default_flags_room", text="Rooms")
col.prop(self, "default_flags_entity", text="Entities")
col.prop(self, "default_flags_archetype", text="Archetypes")
from .sollumz_ui import draw_list_with_add_remove
layout.separator()
layout.label(text="Shared Textures")
row = layout.row()
self._draw_help_text(
context, row,
"Additional directories to search for textures when importing models. When a texture is not found in the "
"model's directory, these directories are searched in order for matching .dds files by name."
)
_, side_col = draw_list_with_add_remove(
layout,
SOLLUMZ_OT_prefs_shared_textures_directory_add.bl_idname,
SOLLUMZ_OT_prefs_shared_textures_directory_remove.bl_idname,
SOLLUMZ_UL_prefs_shared_textures_directories.bl_idname, "",
self, "shared_textures_directories",
self, "shared_textures_directories_index",
rows=4
)
side_col.separator()
subcol = side_col.column(align=True)
subcol.operator(SOLLUMZ_OT_prefs_shared_textures_directory_move_up.bl_idname, text="", icon="TRIA_UP")
subcol.operator(SOLLUMZ_OT_prefs_shared_textures_directory_move_down.bl_idname, text="", icon="TRIA_DOWN")
layout.separator()
layout.label(text="Name Tables")
row = layout.row()
self._draw_help_text(
context, row,
"Used to resolve hashed names. Accepts files where the names are separated by either "
"newlines (one name per line, .txt) or null characters (.nametable)."
)
draw_list_with_add_remove(
layout,
SOLLUMZ_OT_prefs_name_table_path_add.bl_idname,
SOLLUMZ_OT_prefs_name_table_path_remove.bl_idname,
SOLLUMZ_UL_prefs_name_table_paths.bl_idname, "",
self, "name_table_paths",
self, "name_table_paths_index",
rows=4
)
layout.separator()
if bpy.app.version >= (4, 1, 0):
header, body = layout.panel("prefs_general_advanced", default_closed=True)
else:
# Good enough to always display the panel contents when UILayout.panel is not available
header, body = layout, layout
header.label(text="Advanced")
if body:
# intentionally not using `body` here because it makes the panel look weird inside the prefs default box layout
layout.prop(self, "custom_procids_path")
def draw_import_export(self, context, layout: UILayout):
def _section_header(layout: UILayout, text: str):
_line_separator(layout)
row = layout.row()
row.alignment = "LEFT"
row.label(text="", icon="BLANK1")
row.label(text=text, icon="BLANK1")
sublayout = layout
width = context.region.width
ui_scale = context.preferences.system.ui_scale
use_two_column_layout = width > (800 * ui_scale)
if use_two_column_layout:
sublayout = layout.split(factor=0.5)
# Import settings
box = sublayout.box()
box.label(text="Import", icon="IMPORT")
settings = self.import_settings
box.prop(settings, "import_as_asset")
_section_header(box, text="Textures")
col = box.column(align=True)
col.prop(settings, "textures_mode", text="Mode")
if settings.textures_mode == "CUSTOM_DIR":
split = col.split(factor=0.4)
row = split.row()
if not settings.textures_extract_custom_directory:
row.alignment = "RIGHT"
row.alert = True
row.label(icon="ERROR", text="No directory set")
split.row().prop(settings, "textures_extract_custom_directory", text="")
_section_header(box, text="Fragment")
box.prop(settings, "split_by_group")
box.prop(settings, "frag_import_vehicle_windows")
_section_header(box, "Drawable Dictionary")
box.prop(settings, "import_ext_skeleton") # Drawable Dictionary
_section_header(box, "YTYP")
box.prop(settings, "ytyp_mlo_instance_entities")
_section_header(box, "YMAP")
box.prop(settings, "ymap_skip_missing_entities")
box.prop(settings, "ymap_exclude_entities")
box.prop(settings, "ymap_instance_entities")
box.prop(settings, "ymap_box_occluders")
box.prop(settings, "ymap_model_occluders")
box.prop(settings, "ymap_car_generators")
# Export settings
box = sublayout.box()
box.label(text="Export", icon="EXPORT")
settings = self.export_settings
if not self.legacy_import_export:
from szio.gta5 import AssetFormat, is_provider_available
row = box.row(align=True)
row.use_property_split = False
row.use_property_decorate = False
split = row.split(factor=0.4, align=True)
subrow = split.row(align=False)
subrow.alignment = "RIGHT"
subrow.label(text="Formats")
subrow = split.row(align=True)
for f in ("NATIVE", "CWXML"):
subsubrow = subrow.row(align=True)
subsubrow.enabled = is_provider_available(AssetFormat[f])
subsubrow.prop_enum(settings, "target_formats", f)
row = box.row(align=True)
row.use_property_split = False
row.use_property_decorate = False
split = row.split(factor=0.4, align=True)
subrow = split.row(align=False)
subrow.alignment = "RIGHT"
subrow.label(text="Versions")
subrow = split.row(align=True)
for f in ("GEN8", "GEN9"):
subrow.prop_enum(settings, "target_versions", f)
row = box.row(heading="Limit To")
row.prop(settings, "limit_to_selected", text="Selected Objects")
_section_header(box, "Drawable")
box.prop(settings, "apply_transforms")
box.prop(settings, "mesh_domain", expand=True)
_section_header(box, "Drawable Dictionary")
box.prop(settings, "exclude_skeleton")
_section_header(box, "YMAP")
box.prop(settings, "ymap_exclude_entities")
box.prop(settings, "ymap_box_occluders")