// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "CoreMinimal.h" #include "Containers/ArrayView.h" #include "Misc/TextFilterExpressionEvaluator.h" class ISkeletonTreeItem; enum class ESkeletonTreeFilterResult : int32; class FTextFilterExpressionEvaluator; /** Output struct for builders to use */ struct SKELETONEDITOR_API FSkeletonTreeBuilderOutput { FSkeletonTreeBuilderOutput(TArray>& InItems, TArray>& InLinearItems) : Items(InItems) , LinearItems(InLinearItems) {} /** * Add an item to the output * @param InItem The item to add * @param InParentName The name of the item's parent * @param InParentTypes The types of items to search. If this is empty all items will be searched. * @param bAddToHead Whether to add the item to the start or end of the parent's children array */ void Add(const TSharedPtr& InItem, const FName& InParentName, TArrayView InParentTypes, bool bAddToHead = false); /** * Add an item to the output * @param InItem The item to add * @param InParentName The name of the item's parent * @param InParentTypes The types of items to search. If this is empty all items will be searched. * @param bAddToHead Whether to add the item to the start or end of the parent's children array */ FORCEINLINE void Add(const TSharedPtr& InItem, const FName& InParentName, std::initializer_list InParentTypes, bool bAddToHead = false) { Add(InItem, InParentName, MakeArrayView(InParentTypes), bAddToHead); } /** * Add an item to the output * @param InItem The item to add * @param InParentName The name of the item's parent * @param InParentType The type of items to search. If this is NAME_None all items will be searched. * @param bAddToHead Whether to add the item to the start or end of the parent's children array */ void Add(const TSharedPtr& InItem, const FName& InParentName, const FName& InParentType, bool bAddToHead = false); /** * Find the item with the specified name * @param InName The item's name * @param InTypes The types of items to search. If this is empty all items will be searched. * @return the item found, or an invalid ptr if it was not found. */ TSharedPtr Find(const FName& InName, TArrayView InTypes) const; /** * Find the item with the specified name * @param InName The item's name * @param InTypes The types of items to search. If this is empty all items will be searched. * @return the item found, or an invalid ptr if it was not found. */ FORCEINLINE TSharedPtr Find(const FName& InName, std::initializer_list InTypes) const { return Find(InName, MakeArrayView(InTypes)); } /** * Find the item with the specified name * @param InName The item's name * @param InType The type of items to search. If this is NAME_None all items will be searched. * @return the item found, or an invalid ptr if it was not found. */ TSharedPtr Find(const FName& InName, const FName& InType) const; private: /** The items that are built by this builder */ TArray>& Items; /** A linearized list of all items in OutItems (for easier searching) */ TArray>& LinearItems; }; /** Basic filter used when re-filtering the tree */ struct FSkeletonTreeFilterArgs { FSkeletonTreeFilterArgs(TSharedPtr InTextFilter) : TextFilter(InTextFilter) , bFlattenHierarchyOnFilter(true) {} /** The text filter we are using, if any */ TSharedPtr TextFilter; /** Whether to flatten the hierarchy so filtered items appear in a linear list */ bool bFlattenHierarchyOnFilter; }; /** Delegate used to filter an item. */ DECLARE_DELEGATE_RetVal_TwoParams(ESkeletonTreeFilterResult, FOnFilterSkeletonTreeItem, const FSkeletonTreeFilterArgs& /*InArgs*/, const TSharedPtr& /*InItem*/); /** Interface to implement to provide custom build logic to skeleton trees */ class ISkeletonTreeBuilder : public TSharedFromThis { public: virtual ~ISkeletonTreeBuilder() {}; /** Setup this builder with links to the tree and preview scene */ virtual void Initialize(const TSharedRef& InSkeletonTree, const TSharedPtr& InPreviewScene, FOnFilterSkeletonTreeItem InOnFilterSkeletonTreeItem) = 0; /** * Build an array of skeleton tree items to display in the tree. * @param Output The items that are built by this builder */ virtual void Build(FSkeletonTreeBuilderOutput& Output) = 0; /** Apply filtering to the tree items */ virtual void Filter(const FSkeletonTreeFilterArgs& InArgs, const TArray>& InItems, TArray>& OutFilteredItems) = 0; /** Allows the builder to contribute to filtering an item */ virtual ESkeletonTreeFilterResult FilterItem(const FSkeletonTreeFilterArgs& InArgs, const TSharedPtr& InItem) = 0; /** Get whether this builder is showing bones */ virtual bool IsShowingBones() const = 0; /** Get whether this builder is showing bones */ virtual bool IsShowingSockets() const = 0; /** Get whether this builder is showing bones */ virtual bool IsShowingAttachedAssets() const = 0; };