WIP: Brush assets project #106303

Draft
Julian Eisel wants to merge 392 commits from brush-assets-project into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
3 changed files with 52 additions and 48 deletions
Showing only changes of commit 41db6c889d - Show all commits

View File

@ -174,7 +174,7 @@ AssetCatalogFilter AssetCatalogService::create_catalog_filter(
Set<CatalogID> known_catalog_ids; Set<CatalogID> known_catalog_ids;
matching_catalog_ids.add(active_catalog_id); matching_catalog_ids.add(active_catalog_id);
const AssetCatalog *active_catalog = find_catalog(active_catalog_id); const AssetCatalog *active_catalog = this->find_catalog(active_catalog_id);
/* This cannot just iterate over tree items to get all the required data, because tree items only /* This cannot just iterate over tree items to get all the required data, because tree items only
* represent single UUIDs. It could be used to get the main UUIDs of the children, though, and * represent single UUIDs. It could be used to get the main UUIDs of the children, though, and
@ -626,7 +626,7 @@ void AssetCatalogService::create_missing_catalogs()
} }
/* The parent doesn't exist, so create it and queue it up for checking its parent. */ /* The parent doesn't exist, so create it and queue it up for checking its parent. */
AssetCatalog *parent_catalog = create_catalog(parent_path); AssetCatalog *parent_catalog = this->create_catalog(parent_path);
parent_catalog->flags.has_unsaved_changes = true; parent_catalog->flags.has_unsaved_changes = true;
paths_to_check.insert(parent_path); paths_to_check.insert(parent_path);
@ -651,7 +651,7 @@ void AssetCatalogService::undo()
redo_snapshots_.append(std::move(catalog_collection_)); redo_snapshots_.append(std::move(catalog_collection_));
catalog_collection_ = undo_snapshots_.pop_last(); catalog_collection_ = undo_snapshots_.pop_last();
rebuild_tree(); this->rebuild_tree();
AssetLibraryService::get()->rebuild_all_library(); AssetLibraryService::get()->rebuild_all_library();
} }
@ -681,8 +681,8 @@ std::unique_ptr<AssetCatalogCollection> AssetCatalogCollection::deep_copy() cons
auto copy = std::make_unique<AssetCatalogCollection>(); auto copy = std::make_unique<AssetCatalogCollection>();
copy->has_unsaved_changes_ = this->has_unsaved_changes_; copy->has_unsaved_changes_ = this->has_unsaved_changes_;
copy->catalogs_ = copy_catalog_map(this->catalogs_); copy->catalogs_ = this->copy_catalog_map(this->catalogs_);
copy->deleted_catalogs_ = copy_catalog_map(this->deleted_catalogs_); copy->deleted_catalogs_ = this->copy_catalog_map(this->deleted_catalogs_);
if (catalog_definition_file_) { if (catalog_definition_file_) {
copy->catalog_definition_file_ = catalog_definition_file_->copy_and_remap( copy->catalog_definition_file_ = catalog_definition_file_->copy_and_remap(

View File

@ -30,37 +30,37 @@ AssetCatalogPath::AssetCatalogPath(AssetCatalogPath &&other_path) noexcept
uint64_t AssetCatalogPath::hash() const uint64_t AssetCatalogPath::hash() const
{ {
std::hash<std::string> hasher{}; std::hash<std::string> hasher{};
return hasher(this->path_); return hasher(path_);
} }
uint64_t AssetCatalogPath::length() const uint64_t AssetCatalogPath::length() const
{ {
return this->path_.length(); return path_.length();
} }
const char *AssetCatalogPath::c_str() const const char *AssetCatalogPath::c_str() const
{ {
return this->path_.c_str(); return path_.c_str();
} }
const std::string &AssetCatalogPath::str() const const std::string &AssetCatalogPath::str() const
{ {
return this->path_; return path_;
} }
StringRefNull AssetCatalogPath::name() const StringRefNull AssetCatalogPath::name() const
{ {
const size_t last_sep_index = this->path_.rfind(SEPARATOR); const size_t last_sep_index = path_.rfind(SEPARATOR);
if (last_sep_index == std::string::npos) { if (last_sep_index == std::string::npos) {
return StringRefNull(this->path_); return StringRefNull(path_);
} }
return StringRefNull(this->path_.c_str() + last_sep_index + 1); return StringRefNull(path_.c_str() + last_sep_index + 1);
} }
bool AssetCatalogPath::operator==(const AssetCatalogPath &other_path) const bool AssetCatalogPath::operator==(const AssetCatalogPath &other_path) const
{ {
return this->path_ == other_path.path_; return path_ == other_path.path_;
} }
bool AssetCatalogPath::operator!=(const AssetCatalogPath &other_path) const bool AssetCatalogPath::operator!=(const AssetCatalogPath &other_path) const
@ -70,7 +70,7 @@ bool AssetCatalogPath::operator!=(const AssetCatalogPath &other_path) const
bool AssetCatalogPath::operator<(const AssetCatalogPath &other_path) const bool AssetCatalogPath::operator<(const AssetCatalogPath &other_path) const
{ {
return this->path_ < other_path.path_; return path_ < other_path.path_;
} }
AssetCatalogPath AssetCatalogPath::operator/(const AssetCatalogPath &path_to_append) const AssetCatalogPath AssetCatalogPath::operator/(const AssetCatalogPath &path_to_append) const
@ -84,13 +84,13 @@ AssetCatalogPath AssetCatalogPath::operator/(const AssetCatalogPath &path_to_app
} }
std::stringstream new_path; std::stringstream new_path;
new_path << this->path_ << SEPARATOR << path_to_append.path_; new_path << path_ << SEPARATOR << path_to_append.path_;
return AssetCatalogPath(new_path.str()); return AssetCatalogPath(new_path.str());
} }
AssetCatalogPath::operator bool() const AssetCatalogPath::operator bool() const
{ {
return !this->path_.empty(); return !path_.empty();
} }
std::ostream &operator<<(std::ostream &stream, const AssetCatalogPath &path_to_append) std::ostream &operator<<(std::ostream &stream, const AssetCatalogPath &path_to_append)
@ -142,7 +142,7 @@ bool AssetCatalogPath::is_contained_in(const AssetCatalogPath &other_path) const
return true; return true;
} }
if (this->path_ == other_path.path_) { if (path_ == other_path.path_) {
/* Weak is-in relation: equal paths contain each other. */ /* Weak is-in relation: equal paths contain each other. */
return true; return true;
} }
@ -154,7 +154,7 @@ bool AssetCatalogPath::is_contained_in(const AssetCatalogPath &other_path) const
} }
/* Create StringRef to be able to use .startswith(). */ /* Create StringRef to be able to use .startswith(). */
const StringRef this_path(this->path_); const StringRef this_path(path_);
const bool prefix_ok = this_path.startswith(other_path.path_); const bool prefix_ok = this_path.startswith(other_path.path_);
const char next_char = this_path[other_path.length()]; const char next_char = this_path[other_path.length()];
return prefix_ok && next_char == SEPARATOR; return prefix_ok && next_char == SEPARATOR;
@ -165,18 +165,18 @@ AssetCatalogPath AssetCatalogPath::parent() const
if (!*this) { if (!*this) {
return AssetCatalogPath(""); return AssetCatalogPath("");
} }
std::string::size_type last_sep_index = this->path_.rfind(SEPARATOR); std::string::size_type last_sep_index = path_.rfind(SEPARATOR);
if (last_sep_index == std::string::npos) { if (last_sep_index == std::string::npos) {
return AssetCatalogPath(""); return AssetCatalogPath("");
} }
return AssetCatalogPath(this->path_.substr(0, last_sep_index)); return AssetCatalogPath(path_.substr(0, last_sep_index));
} }
void AssetCatalogPath::iterate_components(ComponentIteratorFn callback) const void AssetCatalogPath::iterate_components(ComponentIteratorFn callback) const
{ {
const char *next_slash_ptr; const char *next_slash_ptr;
for (const char *path_component = this->path_.data(); path_component && path_component[0]; for (const char *path_component = path_.data(); path_component && path_component[0];
/* Jump to one after the next slash if there is any. */ /* Jump to one after the next slash if there is any. */
path_component = next_slash_ptr ? next_slash_ptr + 1 : nullptr) path_component = next_slash_ptr ? next_slash_ptr + 1 : nullptr)
{ {
@ -215,7 +215,7 @@ AssetCatalogPath AssetCatalogPath::rebase(const AssetCatalogPath &from_path,
} }
/* When from_path = "test", we need to skip "test/" to get the rest of the path, hence the +1. */ /* When from_path = "test", we need to skip "test/" to get the rest of the path, hence the +1. */
const StringRef suffix = StringRef(this->path_).substr(from_path.length() + 1); const StringRef suffix = StringRef(path_).substr(from_path.length() + 1);
const AssetCatalogPath path_suffix(suffix); const AssetCatalogPath path_suffix(suffix);
return to_path / path_suffix; return to_path / path_suffix;
} }

View File

@ -278,7 +278,7 @@ void AssetCatalogTreeViewItem::on_activate(bContext & /*C*/)
void AssetCatalogTreeViewItem::build_row(uiLayout &row) void AssetCatalogTreeViewItem::build_row(uiLayout &row)
{ {
const std::string label_override = catalog_item_.has_unsaved_changes() ? (label_ + "*") : label_; const std::string label_override = catalog_item_.has_unsaved_changes() ? (label_ + "*") : label_;
add_label(row, label_override); this->add_label(row, label_override);
if (!is_hovered()) { if (!is_hovered()) {
return; return;
@ -332,7 +332,7 @@ void AssetCatalogTreeViewItem::build_context_menu(bContext &C, uiLayout &column)
bool AssetCatalogTreeViewItem::supports_renaming() const bool AssetCatalogTreeViewItem::supports_renaming() const
{ {
const AssetCatalogTreeView &tree_view = static_cast<const AssetCatalogTreeView &>( const AssetCatalogTreeView &tree_view = static_cast<const AssetCatalogTreeView &>(
get_tree_view()); this->get_tree_view());
return !asset::catalogs_read_only(*tree_view.asset_library_); return !asset::catalogs_read_only(*tree_view.asset_library_);
} }
@ -342,7 +342,7 @@ bool AssetCatalogTreeViewItem::rename(const bContext &C, StringRefNull new_name)
BasicTreeViewItem::rename(C, new_name); BasicTreeViewItem::rename(C, new_name);
const AssetCatalogTreeView &tree_view = static_cast<const AssetCatalogTreeView &>( const AssetCatalogTreeView &tree_view = static_cast<const AssetCatalogTreeView &>(
get_tree_view()); this->get_tree_view());
asset::catalog_rename(tree_view.asset_library_, catalog_item_.get_catalog_id(), new_name); asset::catalog_rename(tree_view.asset_library_, catalog_item_.get_catalog_id(), new_name);
return true; return true;
} }
@ -356,7 +356,7 @@ std::unique_ptr<ui::AbstractViewItemDragController> AssetCatalogTreeViewItem::
create_drag_controller() const create_drag_controller() const
{ {
return std::make_unique<AssetCatalogDragController>( return std::make_unique<AssetCatalogDragController>(
static_cast<AssetCatalogTreeView &>(get_tree_view()), catalog_item_); static_cast<AssetCatalogTreeView &>(this->get_tree_view()), catalog_item_);
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
@ -371,11 +371,11 @@ bool AssetCatalogDropTarget::can_drop(const wmDrag &drag, const char **r_disable
{ {
if (drag.type == WM_DRAG_ASSET_CATALOG) { if (drag.type == WM_DRAG_ASSET_CATALOG) {
const asset_system::AssetLibrary &library = get_asset_library(); const asset_system::AssetLibrary &library = get_asset_library();
if (!can_modify_catalogs(library, r_disabled_hint)) { if (!this->can_modify_catalogs(library, r_disabled_hint)) {
return false; return false;
} }
const AssetCatalog *drag_catalog = get_drag_catalog(drag, library); const AssetCatalog *drag_catalog = this->get_drag_catalog(drag, library);
/* NOTE: Technically it's not an issue to allow this (the catalog will just receive a new /* NOTE: Technically it's not an issue to allow this (the catalog will just receive a new
* path and the catalog system will generate missing parents from the path). But it does * path and the catalog system will generate missing parents from the path). But it does
* appear broken to users, so disabling entirely. */ * appear broken to users, so disabling entirely. */
@ -399,15 +399,15 @@ bool AssetCatalogDropTarget::can_drop(const wmDrag &drag, const char **r_disable
std::string AssetCatalogDropTarget::drop_tooltip(const ui::DragInfo &drag_info) const std::string AssetCatalogDropTarget::drop_tooltip(const ui::DragInfo &drag_info) const
{ {
if (drag_info.drag_data.type == WM_DRAG_ASSET_CATALOG) { if (drag_info.drag_data.type == WM_DRAG_ASSET_CATALOG) {
return drop_tooltip_asset_catalog(drag_info.drag_data); return this->drop_tooltip_asset_catalog(drag_info.drag_data);
} }
return drop_tooltip_asset_list(drag_info.drag_data); return this->drop_tooltip_asset_list(drag_info.drag_data);
} }
std::string AssetCatalogDropTarget::drop_tooltip_asset_catalog(const wmDrag &drag) const std::string AssetCatalogDropTarget::drop_tooltip_asset_catalog(const wmDrag &drag) const
{ {
BLI_assert(drag.type == WM_DRAG_ASSET_CATALOG); BLI_assert(drag.type == WM_DRAG_ASSET_CATALOG);
const AssetCatalog *src_catalog = get_drag_catalog(drag, get_asset_library()); const AssetCatalog *src_catalog = this->get_drag_catalog(drag, get_asset_library());
return fmt::format( return fmt::format(
TIP_("Move catalog {} into {}"), src_catalog->path.name(), catalog_item_.get_name()); TIP_("Move catalog {} into {}"), src_catalog->path.name(), catalog_item_.get_name());
@ -439,14 +439,14 @@ std::string AssetCatalogDropTarget::drop_tooltip_asset_list(const wmDrag &drag)
bool AssetCatalogDropTarget::on_drop(bContext *C, const ui::DragInfo &drag) const bool AssetCatalogDropTarget::on_drop(bContext *C, const ui::DragInfo &drag) const
{ {
if (drag.drag_data.type == WM_DRAG_ASSET_CATALOG) { if (drag.drag_data.type == WM_DRAG_ASSET_CATALOG) {
return drop_asset_catalog_into_catalog( return this->drop_asset_catalog_into_catalog(
drag.drag_data, get_view<AssetCatalogTreeView>(), catalog_item_.get_catalog_id()); drag.drag_data, this->get_view<AssetCatalogTreeView>(), catalog_item_.get_catalog_id());
} }
return drop_assets_into_catalog(C, return this->drop_assets_into_catalog(C,
get_view<AssetCatalogTreeView>(), this->get_view<AssetCatalogTreeView>(),
drag.drag_data, drag.drag_data,
catalog_item_.get_catalog_id(), catalog_item_.get_catalog_id(),
catalog_item_.get_simple_name()); catalog_item_.get_simple_name());
} }
bool AssetCatalogDropTarget::drop_asset_catalog_into_catalog( bool AssetCatalogDropTarget::drop_asset_catalog_into_catalog(
@ -539,7 +539,7 @@ bool AssetCatalogDropTarget::can_modify_catalogs(const asset_system::AssetLibrar
asset_system::AssetLibrary &AssetCatalogDropTarget::get_asset_library() const asset_system::AssetLibrary &AssetCatalogDropTarget::get_asset_library() const
{ {
return *get_view<AssetCatalogTreeView>().asset_library_; return *this->get_view<AssetCatalogTreeView>().asset_library_;
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
@ -565,7 +565,7 @@ void *AssetCatalogDragController::create_drag_data() const
void AssetCatalogDragController::on_drag_start() void AssetCatalogDragController::on_drag_start()
{ {
AssetCatalogTreeView &tree_view_ = get_view<AssetCatalogTreeView>(); AssetCatalogTreeView &tree_view_ = this->get_view<AssetCatalogTreeView>();
tree_view_.activate_catalog_by_id(catalog_item_.get_catalog_id()); tree_view_.activate_catalog_by_id(catalog_item_.get_catalog_id());
} }
@ -577,11 +577,15 @@ void AssetCatalogTreeViewAllItem::build_row(uiLayout &row)
PointerRNA *props; PointerRNA *props;
UI_but_extra_operator_icon_add( UI_but_extra_operator_icon_add(reinterpret_cast<uiBut *>(this->view_item_button()),
(uiBut *)view_item_button(), "ASSET_OT_catalogs_save", WM_OP_INVOKE_DEFAULT, ICON_FILE_TICK); "ASSET_OT_catalogs_save",
WM_OP_INVOKE_DEFAULT,
ICON_FILE_TICK);
props = UI_but_extra_operator_icon_add( props = UI_but_extra_operator_icon_add(reinterpret_cast<uiBut *>(this->view_item_button()),
(uiBut *)view_item_button(), "ASSET_OT_catalog_new", WM_OP_INVOKE_DEFAULT, ICON_ADD); "ASSET_OT_catalog_new",
WM_OP_INVOKE_DEFAULT,
ICON_ADD);
/* No parent path to use the root level. */ /* No parent path to use the root level. */
RNA_string_set(props, "parent_path", nullptr); RNA_string_set(props, "parent_path", nullptr);
} }
@ -602,7 +606,7 @@ bool AssetCatalogTreeViewAllItem::DropTarget::can_drop(const wmDrag &drag,
if (drag.type != WM_DRAG_ASSET_CATALOG) { if (drag.type != WM_DRAG_ASSET_CATALOG) {
return false; return false;
} }
asset_system::AssetLibrary &library = *get_view<AssetCatalogTreeView>().asset_library_; asset_system::AssetLibrary &library = *this->get_view<AssetCatalogTreeView>().asset_library_;
if (!AssetCatalogDropTarget::can_modify_catalogs(library, r_disabled_hint)) { if (!AssetCatalogDropTarget::can_modify_catalogs(library, r_disabled_hint)) {
return false; return false;
} }
@ -621,7 +625,7 @@ std::string AssetCatalogTreeViewAllItem::DropTarget::drop_tooltip(
{ {
BLI_assert(drag_info.drag_data.type == WM_DRAG_ASSET_CATALOG); BLI_assert(drag_info.drag_data.type == WM_DRAG_ASSET_CATALOG);
const AssetCatalog *drag_catalog = AssetCatalogDropTarget::get_drag_catalog( const AssetCatalog *drag_catalog = AssetCatalogDropTarget::get_drag_catalog(
drag_info.drag_data, *get_view<AssetCatalogTreeView>().asset_library_); drag_info.drag_data, *this->get_view<AssetCatalogTreeView>().asset_library_);
return fmt::format(TIP_("Move catalog {} to the top level of the tree"), return fmt::format(TIP_("Move catalog {} to the top level of the tree"),
drag_catalog->path.name()); drag_catalog->path.name());
@ -633,7 +637,7 @@ bool AssetCatalogTreeViewAllItem::DropTarget::on_drop(bContext * /*C*/,
BLI_assert(drag.drag_data.type == WM_DRAG_ASSET_CATALOG); BLI_assert(drag.drag_data.type == WM_DRAG_ASSET_CATALOG);
return AssetCatalogDropTarget::drop_asset_catalog_into_catalog( return AssetCatalogDropTarget::drop_asset_catalog_into_catalog(
drag.drag_data, drag.drag_data,
get_view<AssetCatalogTreeView>(), this->get_view<AssetCatalogTreeView>(),
/* No value to drop into the root level. */ /* No value to drop into the root level. */
std::nullopt); std::nullopt);
} }
@ -676,7 +680,7 @@ bool AssetCatalogTreeViewUnassignedItem::DropTarget::on_drop(bContext *C,
{ {
/* Assign to nil catalog ID. */ /* Assign to nil catalog ID. */
return AssetCatalogDropTarget::drop_assets_into_catalog( return AssetCatalogDropTarget::drop_assets_into_catalog(
C, get_view<AssetCatalogTreeView>(), drag.drag_data, CatalogID{}); C, this->get_view<AssetCatalogTreeView>(), drag.drag_data, CatalogID{});
} }
} // namespace blender::ed::asset_browser } // namespace blender::ed::asset_browser