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
|
# SPDX-License-Identifier: GPL-2.0-or-later
# <pep8 compliant>
import bpy
from bpy.types import Header, Menu, Panel, UIList
class ASSETBROWSER_HT_header(Header):
bl_space_type = 'ASSET_BROWSER'
def draw(self, context):
layout = self.layout
space = context.space_data
layout.template_header()
ASSETBROWSER_MT_editor_menus.draw_collapsible(context, layout)
layout.separator_spacer()
layout.operator(
"screen.region_toggle",
text="",
icon='PREFERENCES',
depress=is_option_region_visible(context, space)
).region_type = 'UI'
def is_option_region_visible(context, space):
for region in context.area.regions:
if region.type == 'UI' and region.width <= 1:
return False
return True
class ASSETBROWSER_MT_editor_menus(Menu):
bl_idname = "ASSETBROWSER_MT_editor_menus"
bl_label = ""
def draw(self, _context):
layout = self.layout
layout.menu("ASSETBROWSER_MT_view")
layout.menu("ASSETBROWSER_MT_select")
layout.menu("ASSETBROWSER_MT_edit")
class ASSETBROWSER_MT_view(Menu):
bl_label = "View"
def draw(self, context):
layout = self.layout
st = context.space_data
layout.prop(st, "show_region_nav_bar", text="Navigation")
layout.separator()
layout.menu("INFO_MT_area")
class ASSETBROWSER_MT_select(Menu):
bl_label = "Select"
def draw(self, _context):
layout = self.layout
class ASSETBROWSER_MT_edit(Menu):
bl_label = "Edit"
def draw(self, _context):
layout = self.layout
layout.operator("asset.catalog_undo", text="Undo")
layout.operator("asset.catalog_redo", text="Redo")
class ASSETBROWSER_PT_metadata(Panel):
bl_space_type = 'ASSET_BROWSER'
bl_region_type = 'UI'
bl_label = "Asset Metadata"
bl_options = {'HIDE_HEADER'}
bl_category = 'Metadata'
def draw(self, context):
layout = self.layout
wm = context.window_manager
asset_handle = context.asset_handle
asset_file = asset_handle.file_data
if asset_handle is None:
layout.label(text="No active asset", icon='INFO')
return
asset_library_ref = context.asset_library_ref
asset_lib_path = bpy.types.AssetHandle.get_full_library_path(asset_file, asset_library_ref)
prefs = context.preferences
show_asset_debug_info = prefs.view.show_developer_ui and prefs.experimental.show_asset_debug_info
layout.use_property_split = True
layout.use_property_decorate = False # No animation.
if asset_handle.local_id:
# If the active file is an ID, use its name directly so renaming is possible from right here.
layout.prop(asset_handle.local_id, "name")
if show_asset_debug_info:
col = layout.column(align=True)
col.label(text="Asset Catalog:")
col.prop(asset_handle.local_id.asset_data, "catalog_id", text="UUID")
col.prop(asset_handle.local_id.asset_data, "catalog_simple_name", text="Simple Name")
else:
layout.prop(asset_file, "name")
if show_asset_debug_info:
col = layout.column(align=True)
col.enabled = False
col.label(text="Asset Catalog:")
col.prop(asset_file.asset_data, "catalog_id", text="UUID")
col.prop(asset_file.asset_data, "catalog_simple_name", text="Simple Name")
row = layout.row(align=True)
row.prop(wm, "asset_path_dummy", text="Source")
row.operator("asset.open_containing_blend_file", text="", icon='TOOL_SETTINGS')
layout.prop(asset_file.asset_data, "description")
layout.prop(asset_file.asset_data, "author")
class ASSETBROWSER_PT_metadata_preview(Panel):
bl_space_type = 'ASSET_BROWSER'
bl_region_type = 'UI'
bl_label = "Preview"
bl_category = 'Metadata'
def draw(self, context):
layout = self.layout
asset_handle = context.asset_handle
asset_file = asset_handle.file_data
row = layout.row()
box = row.box()
box.template_icon(icon_value=asset_file.preview_icon_id, scale=5.0)
col = row.column(align=True)
col.operator("ed.lib_id_load_custom_preview", icon='FILEBROWSER', text="")
col.separator()
col.operator("ed.lib_id_generate_preview", icon='FILE_REFRESH', text="")
col.menu("ASSETBROWSER_MT_metadata_preview_menu", icon='DOWNARROW_HLT', text="")
class ASSETBROWSER_MT_metadata_preview_menu(Menu):
bl_label = "Preview"
def draw(self, context):
layout = self.layout
layout.operator("ed.lib_id_generate_preview_from_object", text="Render Active Object")
class ASSETBROWSER_PT_metadata_tags(Panel):
bl_space_type = 'ASSET_BROWSER'
bl_region_type = 'UI'
bl_label = "Tags"
bl_category = 'Metadata'
def draw(self, context):
layout = self.layout
asset = context.asset_handle
asset_data = asset.file_data.asset_data
row = layout.row()
row.template_list("ASSETBROWSEROLD_UL_metadata_tags", "asset_tags", asset_data, "tags",
asset_data, "active_tag", rows=4)
col = row.column(align=True)
col.operator("asset.tag_add", icon='ADD', text="")
col.operator("asset.tag_remove", icon='REMOVE', text="")
class ASSETBROWSER_UL_metadata_tags(UIList):
def draw_item(self, _context, layout, _data, item, icon, _active_data, _active_propname, _index):
tag = item
row = layout.row(align=True)
# Non-editable entries would show grayed-out, which is bad in this specific case, so switch to mere label.
if tag.is_property_readonly("name"):
row.label(text=tag.name, icon_value=icon)
else:
row.prop(tag, "name", text="", emboss=False, icon_value=icon)
classes = (
ASSETBROWSER_HT_header,
ASSETBROWSER_MT_editor_menus,
ASSETBROWSER_MT_view,
ASSETBROWSER_MT_select,
ASSETBROWSER_MT_edit,
ASSETBROWSER_PT_metadata,
ASSETBROWSER_PT_metadata_preview,
ASSETBROWSER_MT_metadata_preview_menu,
ASSETBROWSER_PT_metadata_tags,
ASSETBROWSER_UL_metadata_tags,
)
if __name__ == "__main__": # only for live edit.
from bpy.utils import register_class
for cls in classes:
register_class(cls)
|