Files
UnrealEngineUWP/Engine/Source/Editor/MovieSceneTools/Public/PropertyTrackEditor.h
robert manuszewski d1443992e1 Deprecating ANY_PACKAGE.
This change consists of multiple changes:

Core:
- Deprecation of ANY_PACKAGE macro. Added ANY_PACKAGE_DEPRECATED macro which can still be used for backwards compatibility purposes (only used in CoreUObject)
- Deprecation of StaticFindObjectFast* functions that take bAnyPackage parameter
- Added UStruct::GetStructPathName function that returns FTopLevelAssetPath representing the path name (package + object FName, super quick compared to UObject::GetPathName) + wrapper UClass::GetClassPathName to make it look better when used with UClasses
- Added (Static)FindFirstObject* functions that find a first object given its Name (no Outer). These functions are used in places I consider valid to do global UObject (UClass) lookups like parsing command line parameters / checking for unique object names
- Added static UClass::TryFindType function which serves a similar purpose as FindFirstObject however it's going to throw a warning (with a callstack / maybe ensure in the future?) if short class name is provided. This function is used  in places that used to use short class names but now should have been converted to use path names to catch any potential regressions and or edge cases I missed.
- Added static UClass::TryConvertShortNameToPathName utility function
- Added static UClass::TryFixShortClassNameExportPath utility function
- Object text export paths will now also include class path (Texture2D'/Game/Textures/Grass.Grass' -> /Script/Engine.Texture2D'/Game/Textures/Grass.Grass')
- All places that manually generated object export paths for objects will now use FObjectPropertyBase::GetExportPath
- Added a new startup test that checks for short type names in UClass/FProperty MetaData values

AssetRegistry:
- Deprecated any member variables (FAssetData / FARFilter) or functions that use FNames to represent class names and replaced them with FTopLevelAssetPath
- Added new member variables and new function overloads that use FTopLevelAssetPath to represent class names
- This also applies to a few other modules' APIs to match AssetRegistry changes

Everything else:
- Updated code that used ANY_PACKAGE (depending on the use case) to use FindObject(nullptr, PathToObject), UClass::TryFindType (used when path name is expected, warns if it's a short name) or FindFirstObject (usually for finding types based on user input but there's been a few legitimate use cases not related to user input)
- Updated code that used AssetRegistry API to use FTopLevelAssetPaths and USomeClass::StaticClass()->GetClassPathName() instead of GetFName()
- Updated meta data and hardcoded FindObject(ANY_PACKAGE, "EEnumNameOrClassName") calls to use path names

#jira UE-99463
#rb many.people
[FYI] Marcus.Wassmer
#preflight 629248ec2256738f75de9b32

#codereviewnumbers 20320742, 20320791, 20320799, 20320756, 20320809, 20320830, 20320840, 20320846, 20320851, 20320863, 20320780, 20320765, 20320876, 20320786

#ROBOMERGE-OWNER: robert.manuszewski
#ROBOMERGE-AUTHOR: robert.manuszewski
#ROBOMERGE-SOURCE: CL 20430220 via CL 20433854 via CL 20435474 via CL 20435484
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v949-20362246)

[CL 20448496 by robert manuszewski in ue5-main branch]
2022-06-01 03:46:59 -04:00

261 lines
8.9 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "UObject/ObjectMacros.h"
#include "UObject/Class.h"
#include "Templates/SubclassOf.h"
#include "KeyPropertyParams.h"
#include "ISequencer.h"
#include "MovieSceneTrack.h"
#include "UObject/Package.h"
#include "MovieSceneTrackEditor.h"
#include "KeyframeTrackEditor.h"
#include "ISequencerObjectChangeListener.h"
#include "AnimatedPropertyKey.h"
#include "Tracks/MovieScenePropertyTrack.h"
/**
* Tools for animatable property types such as floats ands vectors
*/
template<typename TrackType>
class FPropertyTrackEditor
: public FKeyframeTrackEditor<TrackType>
{
public:
/**
* Constructor
*
* @param InSequencer The sequencer instance to be used by this tool
*/
FPropertyTrackEditor( TSharedRef<ISequencer> InSequencer )
: FKeyframeTrackEditor<TrackType>( InSequencer )
{ }
/**
* Constructor
*
* @param InSequencer The sequencer instance to be used by this tool
* @param InWatchedPropertyTypes A list of property types that this editor can animate
*/
FPropertyTrackEditor( TSharedRef<ISequencer> InSequencer, TArrayView<const FAnimatedPropertyKey> InWatchedPropertyTypes )
: FKeyframeTrackEditor<TrackType>( InSequencer )
{
for (const FAnimatedPropertyKey& Key : InWatchedPropertyTypes)
{
AddWatchedProperty(Key);
}
}
~FPropertyTrackEditor()
{
TSharedPtr<ISequencer> SequencerPtr = FMovieSceneTrackEditor::GetSequencer();
if ( SequencerPtr.IsValid() )
{
ISequencerObjectChangeListener& ObjectChangeListener = SequencerPtr->GetObjectChangeListener();
for ( FAnimatedPropertyKey PropertyKey : WatchedProperties )
{
ObjectChangeListener.GetOnAnimatablePropertyChanged( PropertyKey ).RemoveAll( this );
}
}
}
public:
//~ ISequencerTrackEditor interface
virtual bool SupportsSequence(UMovieSceneSequence* InSequence) const override
{
return true;
}
virtual bool SupportsType( TSubclassOf<UMovieSceneTrack> Type ) const override
{
return Type == TrackType::StaticClass();
}
protected:
/**
* Generates keys based on the new value from the property property change parameters.
*
* @param PropertyChangedParams Parameters associated with the property change.
* @param OutGeneratedKeys Array of keys that are generated from the changed property
*/
virtual void GenerateKeysFromPropertyChanged( const FPropertyChangedParams& PropertyChangedParams, UMovieSceneSection* SectionToKey, FGeneratedTrackKeys& OutGeneratedKeys ) = 0;
/** When true, this track editor will only be used on properties which have specified it as a custom track class. This is necessary to prevent duplicate
property change handling in cases where a custom track editor handles the same type of data as one of the standard track editors. */
virtual bool ForCustomizedUseOnly() { return false; }
/**
* Initialized values on a track after it's been created, but before any sections or keys have been added.
* @param NewTrack The newly created track.
* @param PropertyChangedParams The property change parameters which caused this track to be created.
*/
virtual void InitializeNewTrack( TrackType* NewTrack, FPropertyChangedParams PropertyChangedParams )
{
const FProperty* ChangedProperty = PropertyChangedParams.PropertyPath.GetLeafMostProperty().Property.Get();
if (ChangedProperty)
{
NewTrack->SetPropertyNameAndPath( ChangedProperty->GetFName(), PropertyChangedParams.GetPropertyPathString() );
#if WITH_EDITORONLY_DATA
FText DisplayText;
// Set up the appropriate name for the track from an array/nested struct index if necessary
for (int32 PropertyIndex = PropertyChangedParams.PropertyPath.GetNumProperties() - 1; PropertyIndex >= 0; --PropertyIndex)
{
const FPropertyInfo& Info = PropertyChangedParams.PropertyPath.GetPropertyInfo(PropertyIndex);
const FArrayProperty* ParentArrayProperty = PropertyIndex > 0 ? CastField<FArrayProperty>(PropertyChangedParams.PropertyPath.GetPropertyInfo(PropertyIndex - 1).Property.Get()) : nullptr;
FProperty* ArrayInnerProperty = Info.Property.Get();
if (ArrayInnerProperty && Info.ArrayIndex != INDEX_NONE)
{
DisplayText = FText::Format(NSLOCTEXT("PropertyTrackEditor", "DisplayTextArrayFormat", "{0} ({1}[{2}])"),
ChangedProperty->GetDisplayNameText(),
(ParentArrayProperty ? ParentArrayProperty : ArrayInnerProperty)->GetDisplayNameText(),
FText::AsNumber(Info.ArrayIndex)
);
break;
}
}
if (DisplayText.IsEmpty())
{
for (int32 PropertyIndex = PropertyChangedParams.PropertyPath.GetNumProperties() - 1; PropertyIndex >= 0; --PropertyIndex)
{
const FStructProperty* ParentStructProperty = PropertyIndex > 0 ? CastField<FStructProperty>(PropertyChangedParams.PropertyPath.GetPropertyInfo(PropertyIndex - 1).Property.Get()) : nullptr;
if (ParentStructProperty)
{
DisplayText = FText::Format(NSLOCTEXT("PropertyTrackEditor", "DisplayTextStructFormat", "{0} ({1})"),
ChangedProperty->GetDisplayNameText(),
ParentStructProperty->GetDisplayNameText()
);
break;
}
}
}
if (DisplayText.IsEmpty())
{
DisplayText = ChangedProperty->GetDisplayNameText();
}
NewTrack->SetDisplayName(DisplayText);
#endif
}
}
virtual UMovieSceneTrack* AddTrack(UMovieScene* FocusedMovieScene, const FGuid& ObjectHandle, TSubclassOf<class UMovieSceneTrack> TrackClass, FName UniqueTypeName) override
{
UMovieSceneTrack* Track = FocusedMovieScene->AddTrack(TrackClass, ObjectHandle);
if (UMovieScenePropertyTrack* PropertyTrack = Cast<UMovieScenePropertyTrack>(Track))
{
PropertyTrack->UniqueTrackName = UniqueTypeName;
}
return Track;
}
protected:
/** Adds a callback for property changes for the supplied property type name. */
void AddWatchedProperty( FAnimatedPropertyKey PropertyKey )
{
FMovieSceneTrackEditor::GetSequencer()->GetObjectChangeListener().GetOnAnimatablePropertyChanged( PropertyKey ).AddRaw( this, &FPropertyTrackEditor::OnAnimatedPropertyChanged );
WatchedProperties.Add( PropertyKey );
}
/**
* Called by the details panel when an animatable property changes
*
* @param InObjectsThatChanged List of objects that changed
* @param KeyPropertyParams Parameters for the property change.
*/
virtual void OnAnimatedPropertyChanged( const FPropertyChangedParams& PropertyChangedParams )
{
FMovieSceneTrackEditor::AnimatablePropertyChanged( FOnKeyProperty::CreateRaw( this, &FPropertyTrackEditor::OnKeyProperty, PropertyChangedParams ) );
}
private:
/** Adds a callback for property changes for the supplied property type name. */
void AddWatchedPropertyType( FName WatchedPropertyTypeName )
{
AddWatchedProperty(FAnimatedPropertyKey::FromPropertyTypeName(WatchedPropertyTypeName));
}
/** Get a customized track class from the property if there is one, otherwise return nullptr. */
TSubclassOf<UMovieSceneTrack> GetCustomizedTrackClass( const FProperty* Property )
{
// Look for a customized track class for this property on the meta data
const FString& MetaSequencerTrackClass = Property->GetMetaData( TEXT( "SequencerTrackClass" ) );
if ( !MetaSequencerTrackClass.IsEmpty() )
{
UClass* MetaClass = UClass::TryFindTypeSlow<UClass>(MetaSequencerTrackClass);
if ( !MetaClass )
{
MetaClass = LoadObject<UClass>( nullptr, *MetaSequencerTrackClass );
}
return MetaClass;
}
return nullptr;
}
/** Adds a key based on a property change. */
FKeyPropertyResult OnKeyProperty( FFrameNumber KeyTime, FPropertyChangedParams PropertyChangedParams )
{
FKeyPropertyResult KeyPropertyResult;
FProperty* Property = PropertyChangedParams.PropertyPath.GetLeafMostProperty().Property.Get();
if (!Property)
{
return KeyPropertyResult;
}
TSubclassOf<UMovieSceneTrack> CustomizedClass = GetCustomizedTrackClass( Property );
TSubclassOf<UMovieSceneTrack> TrackClass;
if (CustomizedClass != nullptr)
{
TrackClass = CustomizedClass;
}
else
{
TrackClass = TrackType::StaticClass();
}
FName UniqueName(*PropertyChangedParams.PropertyPath.ToString(TEXT(".")));
// If the track class has been customized for this property then it's possible this track editor doesn't support it,
// also check for track editors which should only be used for customization.
if ( SupportsType( TrackClass ) && ( ForCustomizedUseOnly() == false || *CustomizedClass != nullptr) )
{
auto GenerateKeys = [this, PropertyChangedParams](UMovieSceneSection* Section, FGeneratedTrackKeys& OutGeneratedKeys)
{
this->GenerateKeysFromPropertyChanged(PropertyChangedParams, Section, OutGeneratedKeys);
};
return this->AddKeysToObjects(
PropertyChangedParams.ObjectsThatChanged,
KeyTime,
PropertyChangedParams.KeyMode,
TrackClass,
UniqueName,
[&](TrackType* NewTrack) { InitializeNewTrack(NewTrack, PropertyChangedParams); },
GenerateKeys
);
}
else
{
return KeyPropertyResult;
}
}
private:
/** An array of property type names which are being watched for changes. */
TArray<FAnimatedPropertyKey> WatchedProperties;
};