feat(Blenvy): ui improvements & fixes for assets for blueprints & levels

* fixed broken removal of assets
 * added visual indication of prevention of adding the same asset twice
 * removed "asset type" selection, useless
 * improved & streamlined UI
 * related tweaks
This commit is contained in:
kaosat.dev 2024-06-05 11:17:49 +02:00
parent f9cb6de4bc
commit edd3d3150f
7 changed files with 68 additions and 40 deletions

View File

@ -20,8 +20,20 @@ def upsert_asset(scene_or_collection, asset):
new_asset.name = asset["name"]
new_asset.path = asset["path"]
def remove_asset(scene_or_collection, asset):
scene_or_collection.user_assets.remove(scene_or_collection.user_assets.find(asset["path"]))
def remove_asset(scene_or_collection, ref_asset):
print("to remove", ref_asset["path"], scene_or_collection.user_assets.find(ref_asset["path"]), scene_or_collection.user_assets)
removal_index = -1
for index, asset in enumerate(scene_or_collection.user_assets):
print("asset in list", asset.name, asset.path)
if asset.path == ref_asset["path"]:
print("FOUND", index)
removal_index = index
break
#scene_or_collection.user_assets.find(lambda x,y : print(x))
if removal_index != -1 :
print("REMOVE")
scene_or_collection.user_assets.remove(removal_index)
#scene_or_collection.user_assets.remove(scene_or_collection.user_assets.find(ref_asset["path"]))
def does_asset_exist(scene_or_collection, ref_asset):
user_assets = getattr(scene_or_collection, 'user_assets', [])

View File

@ -32,7 +32,7 @@ class AssetsRegistry(PropertyGroup):
asset_path_selector: StringProperty(
name="asset path",
description="path of asset to add",
subtype='FILE_PATH'
#subtype='FILE_PATH'
) # type: ignore

View File

@ -115,12 +115,14 @@ class OT_remove_bevy_asset(Operator):
def execute(self, context):
print("REMOVE ASSET", self.target_name, self.target_type, self.asset_path)
assets = []
blueprint_assets = self.target_type == 'BLUEPRINT'
if blueprint_assets:
target = bpy.data.collections[self.target_name]
else:
target = bpy.data.scenes[self.target_name]
print("removing this", target)
remove_asset(target, {"path": self.asset_path})
return {'FINISHED'}
@ -128,6 +130,7 @@ class OT_remove_bevy_asset(Operator):
import os
from bpy_extras.io_utils import ImportHelper
from pathlib import Path
class OT_Add_asset_filebrowser(Operator, ImportHelper):
"""Browse for asset files"""
@ -142,7 +145,7 @@ class OT_Add_asset_filebrowser(Operator, ImportHelper):
) # type: ignore
# Filters files
filter_glob: StringProperty(options={'HIDDEN'}, default='*.jpg;*.jpeg;*.png;*.bmp') # type: ignore
filter_glob: StringProperty(options={'HIDDEN'}, default='*.*') # type: ignore
def execute(self, context):
blenvy = context.window_manager.blenvy
@ -157,9 +160,13 @@ class OT_Add_asset_filebrowser(Operator, ImportHelper):
assets_registry = context.window_manager.assets_registry
assets_registry.asset_path_selector = asset_path
if assets_registry.asset_name_selector == "":
assets_registry.asset_name_selector = Path(os.path.basename(asset_path)).stem
print("SELECTED ASSET PATH", asset_path)
return {'FINISHED'}

View File

@ -1,34 +1,38 @@
from types import SimpleNamespace
import bpy
from .assets_scan import get_main_scene_assets_tree
from .asset_helpers import get_user_assets
from .asset_helpers import get_user_assets, does_asset_exist
def draw_assets(layout, name, title, asset_registry, target_type, target_name, editable=True, user_assets= [], generated_assets = []):
header, panel = layout.panel(f"assets{name}", default_closed=False)
header.label(text=title)
header.label(text=title, icon="ASSET_MANAGER")
if panel:
if editable:
row = panel.row()
blueprint_assets = target_type == 'BLUEPRINT'
if blueprint_assets:
target = bpy.data.collections[target_name]
else:
target = bpy.data.scenes[target_name]
add_possible = does_asset_exist(target, {"path": asset_registry.asset_path_selector}) #"name": asset_registry.asset_name_selector,
row.alert = add_possible
row.prop(asset_registry, "asset_name_selector", text="")
row.prop(asset_registry, "asset_type_selector", text="")
row.label(text=asset_registry.asset_path_selector)
asset_selector = row.operator(operator="asset.open_filebrowser", text="", icon="FILE_FOLDER")
if asset_registry.asset_type_selector == 'IMAGE':
asset_selector.filter_glob = '*.jpg;*.jpeg;*.png;*.bmp'
if asset_registry.asset_type_selector == 'MODEL':
asset_selector.filter_glob="*.glb;*.gltf"
if asset_registry.asset_type_selector == 'TEXT':
asset_selector.filter_glob="*.txt;*.md;*.ron;*.json"
if asset_registry.asset_type_selector == 'AUDIO':
asset_selector.filter_glob="*.mp3;*.wav;*.flac"
add_asset_layout = row.column()
add_asset_layout.enabled = not add_possible
add_asset = row.operator(operator="bevyassets.add", text="", icon="ADD")
add_asset = add_asset_layout.operator(operator="bevyassets.add", text="", icon="ADD")
add_asset.target_type = target_type
add_asset.target_name = target_name
add_asset.asset_name = asset_registry.asset_name_selector
add_asset.asset_type = asset_registry.asset_type_selector
add_asset.asset_path = asset_registry.asset_path_selector
panel.separator()
for asset in user_assets:

View File

@ -26,24 +26,30 @@ class GLTF_PT_auto_export_blueprints_list(bpy.types.Panel):
blueprint_registry.refresh_blueprints()
for blueprint in blueprint_registry.blueprints_data.blueprints:
row = layout.row()
row.label(icon="RIGHTARROW")
row.label(text=blueprint.name)
row.prop(blueprint.collection, "always_export")
header, panel = layout.box().panel(f"blueprint_assets{blueprint.name}", default_closed=True)
if header:
header.label(text=blueprint.name)
header.prop(blueprint.collection, "always_export")
if blueprint.local:
select_blueprint = row.operator(operator="blueprint.select", text="", icon="RESTRICT_SELECT_OFF")
select_blueprint = header.operator(operator="blueprint.select", text="", icon="RESTRICT_SELECT_OFF")
if blueprint.collection and blueprint.collection.name:
select_blueprint.blueprint_collection_name = blueprint.collection.name
select_blueprint.blueprint_scene_name = blueprint.scene.name
if panel:
split = panel.split(factor=0.005)
col = split.column()
col.label(text=" ")
col = split.column()
if blueprint.local:
user_assets = get_user_assets(blueprint.collection)
draw_assets(layout=layout, name=blueprint.name, title="Assets", asset_registry=asset_registry, user_assets=user_assets, target_type="BLUEPRINT", target_name=blueprint.name)
draw_assets(layout=col, name=blueprint.name, title="Assets", asset_registry=asset_registry, user_assets=user_assets, target_type="BLUEPRINT", target_name=blueprint.name)
else:
assets = get_user_assets(blueprint.collection)
draw_assets(layout=layout, name=blueprint.name, title="Assets", asset_registry=asset_registry, user_assets=user_assets, target_type="BLUEPRINT", target_name=blueprint.name, editable=False)
row.label(text="External")
draw_assets(layout=col, name=blueprint.name, title="Assets", asset_registry=asset_registry, user_assets=user_assets, target_type="BLUEPRINT", target_name=blueprint.name, editable=False)
panel.label(text="External")

View File

@ -58,12 +58,12 @@ class BLENVY_PT_SidePanel(bpy.types.Panel):
tool_switch_components.tool = "BLUEPRINTS"
target = row.box() if active_mode == 'LEVELS' else row
tool_switch_components = target.operator(operator="bevy.tooling_switch", text="", icon="PACKAGE")
tool_switch_components = target.operator(operator="bevy.tooling_switch", text="", icon="ASSET_MANAGER")
tool_switch_components.tool = "LEVELS"
target = row.box() if active_mode == 'ASSETS' else row
'''target = row.box() if active_mode == 'ASSETS' else row
tool_switch_components = target.operator(operator="bevy.tooling_switch", text="", icon="ASSET_MANAGER")
tool_switch_components.tool = "ASSETS"
tool_switch_components.tool = "ASSETS"'''
target = row.box() if active_mode == 'SETTINGS' else row
tool_switch_components = target.operator(operator="bevy.tooling_switch", text="", icon="SETTINGS")

View File

@ -28,9 +28,9 @@ class Blenvy_levels(bpy.types.Panel):
for scene_selector in blenvy.main_scenes:
scene = bpy.data.scenes[scene_selector.name]
header, panel = layout.box().panel(f"assets{scene.name}", default_closed=False)
header, panel = layout.box().panel(f"level_assets{scene.name}", default_closed=False)
if header:
header.label(text=scene.name, icon="HIDE_OFF")
header.label(text=scene.name)#, icon="HIDE_OFF")
header.prop(scene, "always_export")
select_level = header.operator(operator="level.select", text="", icon="RESTRICT_SELECT_OFF")
select_level.level_name = scene.name
@ -53,7 +53,6 @@ class Blenvy_levels(bpy.types.Panel):
col.label(text=" ")
col = split.column()
#col.label(text="col in row 2")
scene_assets_panel = draw_assets(layout=col, name=f"{scene.name}_assets", title=f"Assets", asset_registry=asset_registry, user_assets=user_assets, target_type="SCENE", target_name=scene.name)