Merge branch 'mnaumov/FixingEOOrdering' of https://github.com/aws-lumberyard-dev/o3de into mnaumov/FixingEOOrdering_signofffix

Signed-off-by: Mikhail Naumov <mnaumov@amazon.com>
This commit is contained in:
Mikhail Naumov
2022-01-19 15:01:21 -06:00
parent 5cac67bfad
commit 3506a39759
5 changed files with 26 additions and 19 deletions
@@ -201,11 +201,8 @@ namespace AzToolsFramework
//! Fired after the EditorEntityContext fails to export the root level slice to the game stream
virtual void OnSaveStreamForGameFailure(AZStd::string_view /*failureString*/) {}
//! Fired when the user triggers a clone of ComponentEntity object(s), before operation begins
virtual void OnEntitiesAboutToBeCloned() {}
//! Fires when the user triggers a clone of ComponentEntity object(s)), after operation completes
virtual void OnEntitiesCloned() {}
//! Preserve entity order when re-parenting entities
virtual void ForceAddEntitiesToBack(bool /*forceAddToBack*/) {}
};
@@ -1157,7 +1157,7 @@ namespace AzToolsFramework
bool CloneInstantiatedEntities(const EntityIdSet& entitiesToClone, EntityIdSet& clonedEntities)
{
EditorEntityContextNotificationBus::Broadcast(&EditorEntityContextNotification::OnEntitiesAboutToBeCloned);
EditorEntityContextNotificationBus::Broadcast(&EditorEntityContextNotification::ForceAddEntitiesToBack, true);
ScopedUndoBatch undoBatch("Clone Selection");
// Track the mapping of source to cloned entity. This both helps make sure that an entity is not accidentally
@@ -1199,7 +1199,7 @@ namespace AzToolsFramework
// Also replace the selection with the entities that have been cloned.
Internal::UpdateUndoStackAndSelectClonedEntities(allEntityClonesContainer.m_entities, undoBatch);
EditorEntityContextNotificationBus::Broadcast(&EditorEntityContextNotification::OnEntitiesCloned);
EditorEntityContextNotificationBus::Broadcast(&EditorEntityContextNotification::ForceAddEntitiesToBack, false);
for (const AZ::Entity* entity : allEntityClonesContainer.m_entities)
{
@@ -643,14 +643,9 @@ namespace AzToolsFramework
}
}
void EditorEntityModel::OnEntitiesAboutToBeCloned()
void EditorEntityModel::ForceAddEntitiesToBack(bool forceAddToBack)
{
m_forceAddToBack = true;
}
void EditorEntityModel::OnEntitiesCloned()
{
m_forceAddToBack = false;
m_forceAddToBack = forceAddToBack;
}
void EditorEntityModel::ChildEntityOrderArrayUpdated()
@@ -94,9 +94,7 @@ namespace AzToolsFramework
void OnEntityStreamLoadBegin() override;
void OnEntityStreamLoadSuccess() override;
void OnEntityStreamLoadFailed() override;
void OnEntitiesAboutToBeCloned() override;
void OnEntitiesCloned() override;
void ForceAddEntitiesToBack(bool forceAddToBack) override;
////////////////////////////////////////////////
// AzFramework::EntityContextEventBus::Handler
@@ -11,6 +11,7 @@
#include <AzCore/JSON/writer.h>
#include <AzCore/Serialization/Json/JsonSerialization.h>
#include <AzCore/Utils/TypeHash.h>
#include <AzCore/std/sort.h>
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
#include <AzToolsFramework/ContainerEntity/ContainerEntityInterface.h>
@@ -83,6 +84,20 @@ namespace AzToolsFramework
return AZ::Failure(findCommonRootOutcome.TakeError());
}
// order entities by their respective position within Entity Outliner
EditorEntitySortRequestBus::Event(
commonRootEntityId,
[&topLevelEntities](EditorEntitySortRequestBus::Events* sortRequests)
{
AZStd::sort(
topLevelEntities.begin(), topLevelEntities.end(),
[&sortRequests](AZ::Entity* entity1, AZ::Entity* entity2)
{
return sortRequests->GetChildEntityIndex(entity1->GetId()) <
sortRequests->GetChildEntityIndex(entity2->GetId());
});
});
AZ::EntityId containerEntityId;
InstanceOptionalReference instanceToCreate;
@@ -153,8 +168,6 @@ namespace AzToolsFramework
}
// Create the Prefab
AZ_Assert(filePath.IsAbsolute(), "CreatePrefabInMemory requires an absolute file path.");
instanceToCreate = prefabEditorEntityOwnershipInterface->CreatePrefab(
entities, AZStd::move(instancePtrs), m_prefabLoaderInterface->GenerateRelativePath(filePath),
commonRootEntityOwningInstance);
@@ -172,6 +185,7 @@ namespace AzToolsFramework
// Parent the non-container top level entities to the container entity.
// Parenting the top level container entities will be done during the creation of links.
EditorEntityContextNotificationBus::Broadcast(&EditorEntityContextNotification::ForceAddEntitiesToBack, true);
for (AZ::Entity* topLevelEntity : topLevelEntities)
{
if (!IsInstanceContainerEntity(topLevelEntity->GetId()))
@@ -179,6 +193,7 @@ namespace AzToolsFramework
AZ::TransformBus::Event(topLevelEntity->GetId(), &AZ::TransformBus::Events::SetParent, containerEntityId);
}
}
EditorEntityContextNotificationBus::Broadcast(&EditorEntityContextNotification::ForceAddEntitiesToBack, false);
// Update the template of the instance since the entities are modified since the template creation.
Prefab::PrefabDom serializedInstance;
@@ -279,6 +294,8 @@ namespace AzToolsFramework
CreatePrefabResult PrefabPublicHandler::CreatePrefabInDisk(const EntityIdList& entityIds, AZ::IO::PathView filePath)
{
AZ_Assert(filePath.IsAbsolute(), "CreatePrefabInDisk requires an absolute file path.");
auto result = CreatePrefabInMemory(entityIds, filePath);
if (result.IsSuccess())
{