[LYN-3412] Updated LandscapeCanvas component to properly serialize with prefabs. (#1224)

* [LYN-3412] Updated LandscapeCanvas component to properly serialize with prefabs.

* [LYN-3412] Updated PR with feedback.

* [LYN-3412] Reverted unintentional changes.

* [LYN-3412] Removed one more comment.

* [LYN-3412] Additional PR feedback fixed.
This commit is contained in:
cgalvan
2021-06-21 16:03:49 -05:00
committed by GitHub
parent a963cd3ac8
commit 46f8c7c1ba
9 changed files with 248 additions and 21 deletions
@@ -460,10 +460,10 @@ namespace LandscapeCanvasEditor
GraphCanvas::StyleManagerRequestBus::Event(editorId, &GraphCanvas::StyleManagerRequests::RegisterDataPaletteStyle, LandscapeCanvas::AreaTypeId, "VegetationAreaDataColorPalette");
LandscapeCanvas::LandscapeCanvasRequestBus::Handler::BusConnect();
AzToolsFramework::EditorEntityContextNotificationBus::Handler::BusConnect();
AzToolsFramework::EditorPickModeNotificationBus::Handler::BusConnect(AzToolsFramework::GetEntityContextId());
AzToolsFramework::EntityCompositionNotificationBus::Handler::BusConnect();
AzToolsFramework::ToolsApplicationNotificationBus::Handler::BusConnect();
AzToolsFramework::Prefab::PrefabPublicNotificationBus::Handler::BusConnect();
CrySystemEventBus::Handler::BusConnect();
AZ::EntitySystemBus::Handler::BusConnect();
@@ -480,6 +480,7 @@ namespace LandscapeCanvasEditor
{
AZ::EntitySystemBus::Handler::BusDisconnect();
CrySystemEventBus::Handler::BusDisconnect();
AzToolsFramework::Prefab::PrefabPublicNotificationBus::Handler::BusDisconnect();
AzToolsFramework::ToolsApplicationNotificationBus::Handler::BusDisconnect();
AzToolsFramework::EditorPickModeNotificationBus::Handler::BusDisconnect();
AzToolsFramework::EditorEntityContextNotificationBus::Handler::BusDisconnect();
@@ -883,6 +884,10 @@ namespace LandscapeCanvasEditor
if (landscapeCanvasComponent)
{
landscapeCanvasComponent->m_graph = *m_serializeContext->CloneObject(graph.get());
// Mark the Landscape Canvas entity as dirty so the changes to the graph will be picked up on the next save
AzToolsFramework::ScopedUndoBatch undo("Update Landscape Canvas Graph");
AzToolsFramework::ToolsApplicationRequests::Bus::Broadcast(&AzToolsFramework::ToolsApplicationRequests::Bus::Events::AddDirtyEntity, rootEntityId);
}
}
}
@@ -1572,7 +1577,7 @@ namespace LandscapeCanvasEditor
void MainWindow::HandleEditorEntityCreated(const AZ::EntityId& entityId, GraphCanvas::GraphId graphId)
{
if (m_ignoreGraphUpdates)
if (m_ignoreGraphUpdates || m_prefabPropagationInProgress)
{
return;
}
@@ -1622,6 +1627,11 @@ namespace LandscapeCanvasEditor
void MainWindow::OnEditorEntityDeleted(const AZ::EntityId& entityId)
{
if (m_prefabPropagationInProgress)
{
return;
}
m_queuedEntityDeletes.push_back(entityId);
QTimer::singleShot(0, [this, entityId]() {
@@ -2456,6 +2466,11 @@ namespace LandscapeCanvasEditor
void MainWindow::EntityParentChanged(AZ::EntityId entityId, AZ::EntityId newParentId, AZ::EntityId oldParentId)
{
if (m_prefabPropagationInProgress)
{
return;
}
GraphCanvas::GraphId oldGraphId = FindGraphContainingEntity(oldParentId);
GraphCanvas::GraphId newGraphId = FindGraphContainingEntity(newParentId);
@@ -2482,6 +2497,20 @@ namespace LandscapeCanvasEditor
}
}
void MainWindow::OnPrefabInstancePropagationBegin()
{
// Ignore graph updates during prefab propagation because the entities will be
// deleted and re-created, which would inadvertantly trigger our logic to close
// the graph when the corresponding entity is deleted.
m_prefabPropagationInProgress = true;
}
void MainWindow::OnPrefabInstancePropagationEnd()
{
// See comment above in OnPrefabInstancePropagationBegin
m_prefabPropagationInProgress = false;
}
void MainWindow::OnCryEditorEndCreate()
{
UpdateGraphEnabled();
@@ -2490,6 +2519,15 @@ namespace LandscapeCanvasEditor
void MainWindow::OnCryEditorEndLoad()
{
UpdateGraphEnabled();
AzToolsFramework::EditorEntityContextNotificationBus::Handler::BusConnect();
}
void MainWindow::OnCryEditorCloseScene()
{
UpdateGraphEnabled();
AzToolsFramework::EditorEntityContextNotificationBus::Handler::BusDisconnect();
}
void MainWindow::OnCryEditorSceneClosed()