From e6113eb9c53cbe59bee03a44b71a2b86a246740a Mon Sep 17 00:00:00 2001 From: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> Date: Tue, 25 Jan 2022 21:09:00 -0800 Subject: [PATCH] Add checks to handle failure in creating entity as a child of a read-only entity in TrackView and LandscapeCanvas (#7156) Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> --- Code/Editor/TrackView/TrackViewDialog.cpp | 7 +++- .../Code/Source/Editor/MainWindow.cpp | 32 +++++++++++++++++++ .../Code/Source/Editor/MainWindow.h | 4 +++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Code/Editor/TrackView/TrackViewDialog.cpp b/Code/Editor/TrackView/TrackViewDialog.cpp index d70cbad29e..034e12c098 100644 --- a/Code/Editor/TrackView/TrackViewDialog.cpp +++ b/Code/Editor/TrackView/TrackViewDialog.cpp @@ -1046,7 +1046,12 @@ void CTrackViewDialog::OnAddSequence() AzToolsFramework::ScopedUndoBatch undoBatch("Create TrackView Director Node"); sequenceManager->CreateSequence(sequenceName, sequenceType); CTrackViewSequence* newSequence = sequenceManager->GetSequenceByName(sequenceName); - AZ_Assert(newSequence, "Creating new sequence failed."); + + if (!newSequence) + { + return; + } + undoBatch.MarkEntityDirty(newSequence->GetSequenceComponentEntityId()); // make it the currently selected sequence diff --git a/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.cpp b/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.cpp index e58ea77373..8e3159969d 100644 --- a/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.cpp +++ b/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.cpp @@ -19,13 +19,16 @@ #include #include #include +#include #include #include +#include #include #include #include #include #include +#include #include #include @@ -37,6 +40,7 @@ // Qt #include +#include #include #include #include @@ -448,6 +452,8 @@ namespace LandscapeCanvasEditor return config; } + AzFramework::EntityContextId MainWindow::s_editorEntityContextId = AzFramework::EntityContextId::CreateNull(); + MainWindow::MainWindow(QWidget* parent) : GraphModelIntegration::EditorMainWindow(GetDefaultConfig(), parent) { @@ -470,9 +476,15 @@ namespace LandscapeCanvasEditor AZ::ComponentApplicationBus::BroadcastResult(m_serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext); AZ_Assert(m_serializeContext, "Failed to acquire application serialize context."); + AzToolsFramework::EditorEntityContextRequestBus::BroadcastResult( + s_editorEntityContextId, &AzToolsFramework::EditorEntityContextRequests::GetEditorEntityContextId); + m_prefabFocusPublicInterface = AZ::Interface::Get(); AZ_Assert(m_prefabFocusPublicInterface, "LandscapeCanvas - could not get PrefabFocusPublicInterface on construction."); + m_readOnlyEntityPublicInterface = AZ::Interface::Get(); + AZ_Assert(m_readOnlyEntityPublicInterface, "LandscapeCanvas - could not get ReadOnlyEntityPublicInterface on construction."); + const GraphCanvas::EditorId& editorId = GetEditorId(); // Register unique color palettes for our connections (data types) @@ -837,6 +849,26 @@ namespace LandscapeCanvasEditor { using namespace AzFramework::Terrain; + // Detect if it's possible to create a new entity in the current context + AZ::EntityId focusRootEntityId = m_prefabFocusPublicInterface->GetFocusedPrefabContainerEntityId(s_editorEntityContextId); + if (m_readOnlyEntityPublicInterface->IsReadOnly(focusRootEntityId)) + { + // Abort + CloseEditor(dockWidget->GetDockWidgetId()); + + QWidget* activeWindow = AzToolsFramework::GetActiveWindow(); + + QMessageBox::warning( + activeWindow, + QString("Landscape Canvas Asset Creation Error"), + QString("Could not create new Landscape Canvas asset under read-only entity."), + QMessageBox::Ok, + QMessageBox::Ok + ); + + return; + } + // Invoke the GraphCanvas base instead of the GraphModelIntegration::EditorMainWindow so that we // can do our own custom handling when opening an existing graph GraphCanvas::AssetEditorMainWindow::OnEditorOpened(dockWidget); diff --git a/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.h b/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.h index de6b10529d..09eb63d681 100644 --- a/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.h +++ b/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.h @@ -34,6 +34,8 @@ namespace AzToolsFramework { + class ReadOnlyEntityPublicInterface; + namespace Prefab { class PrefabFocusPublicInterface; @@ -261,7 +263,9 @@ namespace LandscapeCanvasEditor AZ::SerializeContext* m_serializeContext = nullptr; + static AzFramework::EntityContextId s_editorEntityContextId; AzToolsFramework::Prefab::PrefabFocusPublicInterface* m_prefabFocusPublicInterface = nullptr; + AzToolsFramework::ReadOnlyEntityPublicInterface* m_readOnlyEntityPublicInterface = nullptr; bool m_ignoreGraphUpdates = false; bool m_prefabPropagationInProgress = false;