@ -16,6 +16,7 @@
# include <AzToolsFramework/Prefab/Instance/InstanceEntityMapperInterface.h>
# include <AzToolsFramework/Prefab/PrefabFocusNotificationBus.h>
# include <AzToolsFramework/Prefab/PrefabFocusUndo.h>
# include <AzToolsFramework/Prefab/PrefabSystemComponentInterface.h>
namespace AzToolsFramework : : Prefab
{
@ -79,7 +80,7 @@ namespace AzToolsFramework::Prefab
auto editUndo = aznew PrefabFocusUndo ( " Edit Prefab " ) ;
editUndo - > Capture ( entityId ) ;
editUndo - > SetParent ( undoBatch . GetUndoBatch ( ) ) ;
ToolsApplicationRequestBus: : Broadcast ( & ToolsApplicationRequestBus : : Events : : RunRedoSeparately , editUndo ) ;
FocusOnPrefabInstanceOwningEntityId( entityId ) ;
}
return AZ : : Success ( ) ;
@ -94,9 +95,7 @@ namespace AzToolsFramework::Prefab
InstanceOptionalReference focusedInstance = m_instanceFocusHierarchy [ index ] ;
FocusOnOwningPrefab ( focusedInstance - > get ( ) . GetContainerEntityId ( ) ) ;
return AZ : : Success ( ) ;
return FocusOnOwningPrefab ( focusedInstance - > get ( ) . GetContainerEntityId ( ) ) ;
}
PrefabFocusOperationResult PrefabFocusHandler : : FocusOnPrefabInstanceOwningEntityId ( AZ : : EntityId entityId )
@ -255,7 +254,7 @@ namespace AzToolsFramework::Prefab
void PrefabFocusHandler : : OnEntityInfoUpdatedName ( AZ : : EntityId entityId , [[maybe_unused]] const AZStd : : string & name )
{
// Determine if the entityId is the container for any of the instances in the vector
// Determine if the entityId is the container for any of the instances in the vector .
auto result = AZStd : : find_if (
m_instanceFocusHierarchy . begin ( ) , m_instanceFocusHierarchy . end ( ) ,
[ entityId ] ( const InstanceOptionalReference & instance )
@ -279,6 +278,25 @@ namespace AzToolsFramework::Prefab
PrefabFocusNotificationBus : : Broadcast ( & PrefabFocusNotifications : : OnPrefabFocusChanged ) ;
}
void PrefabFocusHandler : : OnPrefabTemplateDirtyFlagUpdated ( TemplateId templateId , [[maybe_unused]] bool status )
{
// Determine if the templateId matches any of the instances in the vector.
auto result = AZStd : : find_if (
m_instanceFocusHierarchy . begin ( ) , m_instanceFocusHierarchy . end ( ) ,
[ templateId ] ( const InstanceOptionalReference & instance )
{
return ( instance - > get ( ) . GetTemplateId ( ) = = templateId ) ;
}
) ;
if ( result ! = m_instanceFocusHierarchy . end ( ) )
{
// Refresh the path and notify changes.
RefreshInstanceFocusPath ( ) ;
PrefabFocusNotificationBus : : Broadcast ( & PrefabFocusNotifications : : OnPrefabFocusChanged ) ;
}
}
void PrefabFocusHandler : : RefreshInstanceFocusList ( )
{
m_instanceFocusHierarchy . clear ( ) ;
@ -293,17 +311,42 @@ namespace AzToolsFramework::Prefab
currentInstance = currentInstance - > get ( ) . GetParentInstance ( ) ;
}
// Invert the vector, since we need the top instance to be at index 0
// Invert the vector, since we need the top instance to be at index 0 .
AZStd : : reverse ( m_instanceFocusHierarchy . begin ( ) , m_instanceFocusHierarchy . end ( ) ) ;
}
void PrefabFocusHandler : : RefreshInstanceFocusPath ( )
{
auto prefabSystemComponentInterface = AZ : : Interface < PrefabSystemComponentInterface > : : Get ( ) ;
m_instanceFocusPath . clear ( ) ;
size_t index = 0 ;
size_t maxIndex = m_instanceFocusHierarchy . size ( ) - 1 ;
for ( const InstanceOptionalReference & instance : m_instanceFocusHierarchy )
{
m_instanceFocusPath . Append ( instance - > get ( ) . GetContainerEntity ( ) - > get ( ) . GetName ( ) ) ;
AZStd : : string prefabName ;
if ( index < maxIndex )
{
// Get the filename without the extension (stem).
prefabName = instance - > get ( ) . GetTemplateSourcePath ( ) . Stem ( ) . Native ( ) ;
}
else
{
// Get the full filename.
prefabName = instance - > get ( ) . GetTemplateSourcePath ( ) . Filename ( ) . Native ( ) ;
}
if ( prefabSystemComponentInterface - > IsTemplateDirty ( instance - > get ( ) . GetTemplateId ( ) ) )
{
prefabName + = " * " ;
}
m_instanceFocusPath . Append ( prefabName ) ;
+ + index ;
}
}