-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
273 lines (199 loc) · 7.26 KB
/
update.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
import bpy, os
from .material_slots import FindMaterialSlotInName
from .main_menu import CreatePakPreviewTexture
def PAK_Update_RefreshList(self, context):
"""
Triggers an update of the Texture List
"""
bpy.ops.pak.refresh_images()
return
def PAK_Update_EnableExport(self, context):
"""
Updates the "Enable Export" property for all selected images
"""
try:
addon_prefs = context.preferences.addons[__package__].preferences
file_data = bpy.data.objects[addon_prefs.pak_filedata_name].PAK_FileData
except KeyError:
return
if file_data.is_internal_update:
return
value = file_data.proxy_enable_export
if file_data.enable_multiselect:
for bundle in file_data.bundles:
if bundle.is_selected:
bundle.enable_export = value
else:
bundle = file_data.bundles[file_data.bundles_list_index].pak_items
for tex in bundle:
tex.PAK_Img.enable_export = value
return None
def PAK_Update_ExportLocation(self, context):
"""
Updates the "Export Location" property for all selected images
"""
try:
addon_prefs = context.preferences.addons[__package__].preferences
file_data = bpy.data.objects[addon_prefs.pak_filedata_name].PAK_FileData
except KeyError:
return
if file_data.is_internal_update:
return
value = file_data.proxy_export_location
if file_data.enable_multiselect:
for bundle in file_data.bundles:
if bundle.is_selected:
bundle.export_location = value
else:
bundle = file_data.bundles[file_data.bundles_list_index].pak_items
for tex in bundle:
tex.PAK_Img.export_location = value
return None
def PAK_Update_ExportFormat(self, context):
"""
Updates the "Export Format" property for all selected images
"""
try:
addon_prefs = context.preferences.addons[__package__].preferences
file_data = bpy.data.objects[addon_prefs.pak_filedata_name].PAK_FileData
except KeyError:
return
if file_data.is_internal_update:
return
value = file_data.proxy_export_format
if file_data.enable_multiselect:
for bundle in file_data.bundles:
if bundle.is_selected:
bundle.export_format = value
else:
bundle = file_data.bundles[file_data.bundles_list_index].pak_items
for tex in bundle:
tex.PAK_Img.export_format = value
return None
def PAK_Update_EnableBundles(self, context):
"""
Automatically refreshes the list when the Enable Bundles is toggled
in order to provide the right data.
"""
bpy.ops.pak.refresh_images()
def PAK_Update_TextureListItem_Name(self, context):
"""
Updates the name of a texture bundle from the list UI.
"""
# self in this context is the bundle being interacted with
try:
addon_prefs = context.preferences.addons[__package__].preferences
file_data = bpy.data.objects[addon_prefs.pak_filedata_name].PAK_FileData
except KeyError:
return
if file_data.is_internal_update:
return
value = self.name
if file_data.enable_bundles is not True:
for bundle_item in self.pak_items:
bundle_item.tex.name = value
else:
for bundle_item in self.pak_items:
tex = bundle_item.tex
name_parts = [n for n in os.path.splitext(tex.name)]
filename = name_parts.pop(0)
extension = ""
for text in name_parts:
extension += text
match = FindMaterialSlotInName(addon_prefs, filename, None,
file_data.case_sensitive_matching)
if match is not None:
new_name = value + match + extension
tex.name = new_name
else:
tex.name = value
def PAK_Update_TextureListItem_EnableExport(self, context):
"""
Updates the Enable Export property of a texture bundle from the list UI.
"""
try:
addon_prefs = context.preferences.addons[__package__].preferences
file_data = bpy.data.objects[addon_prefs.pak_filedata_name].PAK_FileData
except KeyError:
return
if file_data.is_internal_update:
return
value = self.enable_export
for bundle_item in self.pak_items:
bundle_item.tex.PAK_Img.enable_export = value
def PAK_Update_TextureListItem_ExportLocation(self, context):
"""
Updates the Export Location property of a texture bundle from the list UI.
"""
try:
addon_prefs = context.preferences.addons[__package__].preferences
file_data = bpy.data.objects[addon_prefs.pak_filedata_name].PAK_FileData
except KeyError:
return
if file_data.is_internal_update:
return
value = self.export_location
for bundle_item in self.pak_items:
bundle_item.tex.PAK_Img.export_location = value
def PAK_Update_TextureListItem_ExportFormat(self, context):
"""
Updates the Export Format property of a texture bundle from the list UI.
"""
try:
addon_prefs = context.preferences.addons[__package__].preferences
file_data = bpy.data.objects[addon_prefs.pak_filedata_name].PAK_FileData
except KeyError:
return
if file_data.is_internal_update:
return
value = self.export_format
for bundle_item in self.pak_items:
bundle_item.tex.PAK_Img.export_format = value
def PAK_Update_TextureListItem_IsSelected(self, context):
"""
Used to reset proxy export properties in the UI every time UI selection changes.
"""
try:
addon_prefs = context.preferences.addons[__package__].preferences
file_data = bpy.data.objects[addon_prefs.pak_filedata_name].PAK_FileData
except KeyError:
return
file_data.is_internal_update = True
file_data.proxy_enable_export = False
file_data.proxy_export_location = '0'
file_data.is_internal_update = False
def PAK_Update_TextureList_Preview(self, context):
"""
Updates the texture preview when the selection is changed.
"""
# If the list has no entries, the preview texture shouldn't have anything in it.
if len(self.bundles) == 0:
if self.preview_tex != None:
self.preview_tex.image = None
else:
self.preview_tex = None
return
sel_bundle = self.bundles[self.bundles_list_index]
sel_texture = sel_bundle.pak_items[0].tex
if self.preview_tex is None:
CreatePakPreviewTexture()
self.preview_tex.image = sel_bundle.pak_items[0].tex
pass
def PAK_Update_TextureList_PreviewColor(self, context):
sel_bundle = self.bundles[self.bundles_list_index]
sel_texture = sel_bundle.pak_items[0].tex
preview_rgb = self.preview_rgb
if self.preview_tex is None:
return
if 'R' in preview_rgb:
self.preview_tex.factor_red = 1
else:
self.preview_tex.factor_red = 0
if 'G' in preview_rgb:
self.preview_tex.factor_green = 1
else:
self.preview_tex.factor_green = 0
if 'B' in preview_rgb:
self.preview_tex.factor_blue = 1
else:
self.preview_tex.factor_blue = 0