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>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -19,13 +19,16 @@
|
||||
#include <AzToolsFramework/API/ComponentEntityObjectBus.h>
|
||||
#include <AzToolsFramework/API/EntityCompositionRequestBus.h>
|
||||
#include <AzToolsFramework/Commands/EntityStateCommand.h>
|
||||
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
|
||||
#include <AzToolsFramework/Entity/EditorEntityInfoBus.h>
|
||||
#include <AzToolsFramework/Entity/EditorEntityHelpers.h>
|
||||
#include <AzToolsFramework/Entity/ReadOnly/ReadOnlyEntityInterface.h>
|
||||
#include <AzToolsFramework/Prefab/PrefabFocusPublicInterface.h>
|
||||
#include <AzToolsFramework/PropertyTreeEditor/PropertyTreeEditor.h>
|
||||
#include <AzToolsFramework/ToolsComponents/EditorDisabledCompositionBus.h>
|
||||
#include <AzToolsFramework/ToolsComponents/EditorPendingCompositionBus.h>
|
||||
#include <AzToolsFramework/UI/ComponentPalette/ComponentPaletteUtil.hxx>
|
||||
#include <AzToolsFramework/UI/UICore/WidgetHelpers.h>
|
||||
#include <AzToolsFramework/Undo/UndoSystem.h>
|
||||
#include <IEditor.h>
|
||||
|
||||
@@ -37,6 +40,7 @@
|
||||
|
||||
// Qt
|
||||
#include <QApplication>
|
||||
#include <QMessageBox>
|
||||
#include <QStringList>
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
@@ -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<AzToolsFramework::Prefab::PrefabFocusPublicInterface>::Get();
|
||||
AZ_Assert(m_prefabFocusPublicInterface, "LandscapeCanvas - could not get PrefabFocusPublicInterface on construction.");
|
||||
|
||||
m_readOnlyEntityPublicInterface = AZ::Interface<AzToolsFramework::ReadOnlyEntityPublicInterface>::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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user