2019-12-26 15:33:43 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2015-05-29 13:15:40 -04:00
# include "CollectionAssetManagement.h"
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340)
#lockdown Nick.Penwarden
#rb none
==========================
MAJOR FEATURES + CHANGES
==========================
Change 3209340 on 2016/11/23 by Ben.Marsh
Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h.
Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms.
* Every header now includes everything it needs to compile.
* There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first.
* There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h.
* Every .cpp file includes its matching .h file first.
* This helps validate that each header is including everything it needs to compile.
* No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more.
* You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there.
* There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible.
* No engine code explicitly includes a precompiled header any more.
* We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies.
* PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files.
Tool used to generate this transform is at Engine\Source\Programs\IncludeTool.
[CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
# include "ISourceControlProvider.h"
# include "ISourceControlModule.h"
# include "ICollectionManager.h"
2015-05-29 13:15:40 -04:00
# include "CollectionManagerModule.h"
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340)
#lockdown Nick.Penwarden
#rb none
==========================
MAJOR FEATURES + CHANGES
==========================
Change 3209340 on 2016/11/23 by Ben.Marsh
Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h.
Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms.
* Every header now includes everything it needs to compile.
* There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first.
* There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h.
* Every .cpp file includes its matching .h file first.
* This helps validate that each header is including everything it needs to compile.
* No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more.
* You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there.
* There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible.
* No engine code explicitly includes a precompiled header any more.
* We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies.
* PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files.
Tool used to generate this transform is at Engine\Source\Programs\IncludeTool.
[CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
# include "Framework/Notifications/NotificationManager.h"
# include "Widgets/Notifications/SNotificationList.h"
2015-05-29 13:15:40 -04:00
# define LOCTEXT_NAMESPACE "ContentBrowser"
FCollectionAssetManagement : : FCollectionAssetManagement ( )
{
2015-06-01 10:04:42 -04:00
FCollectionManagerModule & CollectionManagerModule = FCollectionManagerModule : : GetModule ( ) ;
2015-05-29 13:15:40 -04:00
// Register the notifications we need in order to keep things up-to-date
OnCollectionRenamedHandle = CollectionManagerModule . Get ( ) . OnCollectionRenamed ( ) . AddRaw ( this , & FCollectionAssetManagement : : HandleCollectionRenamed ) ;
OnCollectionDestroyedHandle = CollectionManagerModule . Get ( ) . OnCollectionDestroyed ( ) . AddRaw ( this , & FCollectionAssetManagement : : HandleCollectionDestroyed ) ;
2015-07-07 10:31:39 -04:00
OnCollectionUpdatedHandle = CollectionManagerModule . Get ( ) . OnCollectionUpdated ( ) . AddRaw ( this , & FCollectionAssetManagement : : HandleCollectionUpdated ) ;
2022-09-16 20:57:34 -04:00
OnAssetsAddedHandle = CollectionManagerModule . Get ( ) . OnAssetsAddedToCollection ( ) . AddRaw ( this , & FCollectionAssetManagement : : HandleAssetsAddedToCollection ) ;
OnAssetsRemovedHandle = CollectionManagerModule . Get ( ) . OnAssetsRemovedFromCollection ( ) . AddRaw ( this , & FCollectionAssetManagement : : HandleAssetsRemovedFromCollection ) ;
2015-05-29 13:15:40 -04:00
}
FCollectionAssetManagement : : ~ FCollectionAssetManagement ( )
{
2015-06-01 10:04:42 -04:00
// Check IsModuleAvailable as we might be in the process of shutting down...
if ( FCollectionManagerModule : : IsModuleAvailable ( ) )
2015-05-29 13:15:40 -04:00
{
2015-06-01 10:04:42 -04:00
FCollectionManagerModule & CollectionManagerModule = FCollectionManagerModule : : GetModule ( ) ;
CollectionManagerModule . Get ( ) . OnCollectionRenamed ( ) . Remove ( OnCollectionRenamedHandle ) ;
CollectionManagerModule . Get ( ) . OnCollectionDestroyed ( ) . Remove ( OnCollectionDestroyedHandle ) ;
2015-07-07 10:31:39 -04:00
CollectionManagerModule . Get ( ) . OnCollectionUpdated ( ) . Remove ( OnCollectionUpdatedHandle ) ;
2022-09-16 20:57:34 -04:00
CollectionManagerModule . Get ( ) . OnAssetsAddedToCollection ( ) . Remove ( OnAssetsAddedHandle ) ;
CollectionManagerModule . Get ( ) . OnAssetsRemovedFromCollection ( ) . Remove ( OnAssetsRemovedHandle ) ;
2015-05-29 13:15:40 -04:00
}
}
void FCollectionAssetManagement : : SetCurrentAssets ( const TArray < FAssetData > & CurrentAssets )
{
CurrentAssetPaths . Empty ( ) ;
for ( const FAssetData & AssetData : CurrentAssets )
{
2022-09-10 00:02:37 -04:00
CurrentAssetPaths . Add ( AssetData . GetSoftObjectPath ( ) ) ;
2015-05-29 13:15:40 -04:00
}
UpdateAssetManagementState ( ) ;
}
2022-09-10 00:02:37 -04:00
void FCollectionAssetManagement : : SetCurrentAssetPaths ( const TArray < FSoftObjectPath > & CurrentAssets )
2020-06-23 18:40:00 -04:00
{
CurrentAssetPaths . Empty ( ) ;
CurrentAssetPaths . Append ( CurrentAssets ) ;
UpdateAssetManagementState ( ) ;
}
2015-05-29 13:15:40 -04:00
void FCollectionAssetManagement : : AddCurrentAssetsToCollection ( FCollectionNameType InCollectionKey )
{
2015-06-01 10:04:42 -04:00
FCollectionManagerModule & CollectionManagerModule = FCollectionManagerModule : : GetModule ( ) ;
2015-05-29 13:15:40 -04:00
2022-09-16 20:57:34 -04:00
const TArray < FSoftObjectPath > ObjectPaths = CurrentAssetPaths . Array ( ) ;
2015-05-29 13:15:40 -04:00
FText ResultText ;
bool bSuccess = false ;
{
int32 NumAdded = 0 ;
2024-04-19 18:17:59 -04:00
if ( CollectionManagerModule . Get ( ) . AddToCollection ( InCollectionKey . Name , InCollectionKey . Type , ObjectPaths , & NumAdded , & ResultText ) )
2015-05-29 13:15:40 -04:00
{
bSuccess = true ;
FFormatNamedArguments Args ;
Args . Add ( TEXT ( " Number " ) , NumAdded ) ;
Args . Add ( TEXT ( " CollectionName " ) , FText : : FromName ( InCollectionKey . Name ) ) ;
ResultText = FText : : Format ( LOCTEXT ( " CollectionAssetsAdded " , " Added {Number} asset(s) to {CollectionName} " ) , Args ) ;
}
}
if ( ! ResultText . IsEmpty ( ) )
{
FNotificationInfo Info ( ResultText ) ;
Info . bFireAndForget = true ;
Info . bUseLargeFont = false ;
TSharedPtr < SNotificationItem > Item = FSlateNotificationManager : : Get ( ) . AddNotification ( Info ) ;
if ( Item . IsValid ( ) )
{
Item - > SetCompletionState ( ( bSuccess ) ? SNotificationItem : : CS_Success : SNotificationItem : : CS_Fail ) ;
}
}
}
void FCollectionAssetManagement : : RemoveCurrentAssetsFromCollection ( FCollectionNameType InCollectionKey )
{
2015-06-01 10:04:42 -04:00
FCollectionManagerModule & CollectionManagerModule = FCollectionManagerModule : : GetModule ( ) ;
2015-05-29 13:15:40 -04:00
2022-09-16 20:57:34 -04:00
const TArray < FSoftObjectPath > ObjectPaths = CurrentAssetPaths . Array ( ) ;
2015-05-29 13:15:40 -04:00
FText ResultText ;
bool bSuccess = false ;
{
int32 NumRemoved = 0 ;
2024-04-19 18:17:59 -04:00
if ( CollectionManagerModule . Get ( ) . RemoveFromCollection ( InCollectionKey . Name , InCollectionKey . Type , ObjectPaths , & NumRemoved , & ResultText ) )
2015-05-29 13:15:40 -04:00
{
bSuccess = true ;
FFormatNamedArguments Args ;
Args . Add ( TEXT ( " Number " ) , NumRemoved ) ;
Args . Add ( TEXT ( " CollectionName " ) , FText : : FromName ( InCollectionKey . Name ) ) ;
ResultText = FText : : Format ( LOCTEXT ( " CollectionAssetsRemoved " , " Removed {Number} asset(s) from {CollectionName} " ) , Args ) ;
}
}
if ( ! ResultText . IsEmpty ( ) )
{
FNotificationInfo Info ( ResultText ) ;
Info . bFireAndForget = true ;
Info . bUseLargeFont = false ;
TSharedPtr < SNotificationItem > Item = FSlateNotificationManager : : Get ( ) . AddNotification ( Info ) ;
if ( Item . IsValid ( ) )
{
Item - > SetCompletionState ( ( bSuccess ) ? SNotificationItem : : CS_Success : SNotificationItem : : CS_Fail ) ;
}
}
}
bool FCollectionAssetManagement : : IsCollectionEnabled ( FCollectionNameType InCollectionKey ) const
{
// Non-local collections can only be changed if we have an available source control connection
const bool bCollectionWritable = ( InCollectionKey . Type = = ECollectionShareType : : CST_Local ) | | ( ISourceControlModule : : Get ( ) . IsEnabled ( ) & & ISourceControlModule : : Get ( ) . GetProvider ( ) . IsAvailable ( ) ) ;
return bCollectionWritable & & CurrentAssetPaths . Num ( ) > 0 ;
}
ECheckBoxState FCollectionAssetManagement : : GetCollectionCheckState ( FCollectionNameType InCollectionKey ) const
{
// If the collection exists in the map, then it means that the current selection contains at least one asset using that collection
const ECheckBoxState * FoundCheckState = AssetManagementState . Find ( InCollectionKey ) ;
if ( FoundCheckState )
{
return * FoundCheckState ;
}
// If the collection doesn't exist in the map, then it's assumed to be unused by the current selection (and thus unchecked)
return ECheckBoxState : : Unchecked ;
}
2023-05-16 13:02:13 -04:00
int32 FCollectionAssetManagement : : GetCurrentAssetCount ( ) const
{
return CurrentAssetPaths . Num ( ) ;
}
2015-05-29 13:15:40 -04:00
void FCollectionAssetManagement : : UpdateAssetManagementState ( )
{
2015-06-01 10:04:42 -04:00
FCollectionManagerModule & CollectionManagerModule = FCollectionManagerModule : : GetModule ( ) ;
2015-05-29 13:15:40 -04:00
AssetManagementState . Empty ( ) ;
if ( CurrentAssetPaths . Num ( ) = = 0 )
{
return ;
}
// The logic below is much simpler when only a single object is selected as we don't need to deal with set intersection
if ( CurrentAssetPaths . Num ( ) = = 1 )
{
TArray < FCollectionNameType > MatchedCollections ;
2022-09-16 20:57:34 -04:00
CollectionManagerModule . Get ( ) . GetCollectionsContainingObject ( * CurrentAssetPaths . CreateConstIterator ( ) , MatchedCollections , ECollectionRecursionFlags : : Self ) ;
2015-05-29 13:15:40 -04:00
for ( const FCollectionNameType & CollectionKey : MatchedCollections )
{
AssetManagementState . Add ( CollectionKey , ECheckBoxState : : Checked ) ;
}
2018-10-24 18:30:33 -04:00
MatchedCollections . Reset ( ) ;
2022-09-16 20:57:34 -04:00
CollectionManagerModule . Get ( ) . GetCollectionsContainingObject ( * CurrentAssetPaths . CreateConstIterator ( ) , MatchedCollections , ECollectionRecursionFlags : : Children ) ;
2018-10-24 18:30:33 -04:00
for ( const FCollectionNameType & CollectionKey : MatchedCollections )
{
if ( ! AssetManagementState . Contains ( CollectionKey ) )
{
AssetManagementState . Add ( CollectionKey , ECheckBoxState : : Undetermined ) ;
}
}
2015-05-29 13:15:40 -04:00
}
else
{
2022-09-16 20:57:34 -04:00
const TArray < FSoftObjectPath > ObjectPaths = CurrentAssetPaths . Array ( ) ;
TMap < FCollectionNameType , TArray < FSoftObjectPath > > CollectionsAndMatchedObjects ;
2015-05-29 13:15:40 -04:00
CollectionManagerModule . Get ( ) . GetCollectionsContainingObjects ( ObjectPaths , CollectionsAndMatchedObjects ) ;
2022-09-16 20:57:34 -04:00
for ( const TPair < FCollectionNameType , TArray < FSoftObjectPath > > & MatchedCollection : CollectionsAndMatchedObjects )
2015-05-29 13:15:40 -04:00
{
const FCollectionNameType & CollectionKey = MatchedCollection . Key ;
2022-09-16 20:57:34 -04:00
const TArray < FSoftObjectPath > & MatchedObjects = MatchedCollection . Value ;
2015-05-29 13:15:40 -04:00
// Collections that contain all of the selected assets are shown as checked, collections that only contain some of the selected assets are shown as undetermined
AssetManagementState . Add (
CollectionKey ,
( MatchedObjects . Num ( ) = = CurrentAssetPaths . Num ( ) ) ? ECheckBoxState : : Checked : ECheckBoxState : : Undetermined
) ;
}
}
}
void FCollectionAssetManagement : : HandleCollectionRenamed ( const FCollectionNameType & OriginalCollection , const FCollectionNameType & NewCollection )
{
if ( AssetManagementState . Contains ( OriginalCollection ) )
{
AssetManagementState . Add ( NewCollection , AssetManagementState [ OriginalCollection ] ) ;
AssetManagementState . Remove ( OriginalCollection ) ;
}
}
2015-07-07 10:31:39 -04:00
void FCollectionAssetManagement : : HandleCollectionUpdated ( const FCollectionNameType & Collection )
{
// Collection has changed in an unknown way - we need to update everything to be sure
UpdateAssetManagementState ( ) ;
}
2015-05-29 13:15:40 -04:00
void FCollectionAssetManagement : : HandleCollectionDestroyed ( const FCollectionNameType & Collection )
{
AssetManagementState . Remove ( Collection ) ;
}
2022-09-16 20:57:34 -04:00
void FCollectionAssetManagement : : HandleAssetsAddedToCollection ( const FCollectionNameType & Collection , TConstArrayView < FSoftObjectPath > AssetsAdded )
2015-05-29 13:15:40 -04:00
{
// Only need to update if one of the added assets belongs to our current selection set
bool bNeedsUpdate = false ;
2022-09-16 20:57:34 -04:00
for ( const FSoftObjectPath & AssetPath : AssetsAdded )
2015-05-29 13:15:40 -04:00
{
2022-09-16 20:57:34 -04:00
if ( CurrentAssetPaths . Contains ( AssetPath ) )
2015-05-29 13:15:40 -04:00
{
bNeedsUpdate = true ;
break ;
}
}
if ( bNeedsUpdate )
{
UpdateAssetManagementState ( ) ;
}
}
2022-09-16 20:57:34 -04:00
void FCollectionAssetManagement : : HandleAssetsRemovedFromCollection ( const FCollectionNameType & Collection , TConstArrayView < FSoftObjectPath > AssetsRemoved )
2015-05-29 13:15:40 -04:00
{
// Only need to update if one of the removed assets belongs to our current selection set
bool bNeedsUpdate = false ;
2022-09-16 20:57:34 -04:00
for ( const FSoftObjectPath & AssetPath : AssetsRemoved )
2015-05-29 13:15:40 -04:00
{
2022-09-16 20:57:34 -04:00
if ( CurrentAssetPaths . Contains ( AssetPath ) )
2015-05-29 13:15:40 -04:00
{
bNeedsUpdate = true ;
break ;
}
}
if ( bNeedsUpdate )
{
UpdateAssetManagementState ( ) ;
}
}
# undef LOCTEXT_NAMESPACE