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>
monroegm-disable-blank-issue-2
Danilo Aimini 4 years ago committed by GitHub
parent 56e7e70735
commit e6113eb9c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1046,7 +1046,12 @@ void CTrackViewDialog::OnAddSequence()
AzToolsFramework::ScopedUndoBatch undoBatch("Create TrackView Director Node"); AzToolsFramework::ScopedUndoBatch undoBatch("Create TrackView Director Node");
sequenceManager->CreateSequence(sequenceName, sequenceType); sequenceManager->CreateSequence(sequenceName, sequenceType);
CTrackViewSequence* newSequence = sequenceManager->GetSequenceByName(sequenceName); CTrackViewSequence* newSequence = sequenceManager->GetSequenceByName(sequenceName);
AZ_Assert(newSequence, "Creating new sequence failed.");
if (!newSequence)
{
return;
}
undoBatch.MarkEntityDirty(newSequence->GetSequenceComponentEntityId()); undoBatch.MarkEntityDirty(newSequence->GetSequenceComponentEntityId());
// make it the currently selected sequence // make it the currently selected sequence

@ -19,13 +19,16 @@
#include <AzToolsFramework/API/ComponentEntityObjectBus.h> #include <AzToolsFramework/API/ComponentEntityObjectBus.h>
#include <AzToolsFramework/API/EntityCompositionRequestBus.h> #include <AzToolsFramework/API/EntityCompositionRequestBus.h>
#include <AzToolsFramework/Commands/EntityStateCommand.h> #include <AzToolsFramework/Commands/EntityStateCommand.h>
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
#include <AzToolsFramework/Entity/EditorEntityInfoBus.h> #include <AzToolsFramework/Entity/EditorEntityInfoBus.h>
#include <AzToolsFramework/Entity/EditorEntityHelpers.h> #include <AzToolsFramework/Entity/EditorEntityHelpers.h>
#include <AzToolsFramework/Entity/ReadOnly/ReadOnlyEntityInterface.h>
#include <AzToolsFramework/Prefab/PrefabFocusPublicInterface.h> #include <AzToolsFramework/Prefab/PrefabFocusPublicInterface.h>
#include <AzToolsFramework/PropertyTreeEditor/PropertyTreeEditor.h> #include <AzToolsFramework/PropertyTreeEditor/PropertyTreeEditor.h>
#include <AzToolsFramework/ToolsComponents/EditorDisabledCompositionBus.h> #include <AzToolsFramework/ToolsComponents/EditorDisabledCompositionBus.h>
#include <AzToolsFramework/ToolsComponents/EditorPendingCompositionBus.h> #include <AzToolsFramework/ToolsComponents/EditorPendingCompositionBus.h>
#include <AzToolsFramework/UI/ComponentPalette/ComponentPaletteUtil.hxx> #include <AzToolsFramework/UI/ComponentPalette/ComponentPaletteUtil.hxx>
#include <AzToolsFramework/UI/UICore/WidgetHelpers.h>
#include <AzToolsFramework/Undo/UndoSystem.h> #include <AzToolsFramework/Undo/UndoSystem.h>
#include <IEditor.h> #include <IEditor.h>
@ -37,6 +40,7 @@
// Qt // Qt
#include <QApplication> #include <QApplication>
#include <QMessageBox>
#include <QStringList> #include <QStringList>
#include <QTimer> #include <QTimer>
#include <QVBoxLayout> #include <QVBoxLayout>
@ -448,6 +452,8 @@ namespace LandscapeCanvasEditor
return config; return config;
} }
AzFramework::EntityContextId MainWindow::s_editorEntityContextId = AzFramework::EntityContextId::CreateNull();
MainWindow::MainWindow(QWidget* parent) MainWindow::MainWindow(QWidget* parent)
: GraphModelIntegration::EditorMainWindow(GetDefaultConfig(), parent) : GraphModelIntegration::EditorMainWindow(GetDefaultConfig(), parent)
{ {
@ -470,9 +476,15 @@ namespace LandscapeCanvasEditor
AZ::ComponentApplicationBus::BroadcastResult(m_serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext); AZ::ComponentApplicationBus::BroadcastResult(m_serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext);
AZ_Assert(m_serializeContext, "Failed to acquire application serialize context."); 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(); m_prefabFocusPublicInterface = AZ::Interface<AzToolsFramework::Prefab::PrefabFocusPublicInterface>::Get();
AZ_Assert(m_prefabFocusPublicInterface, "LandscapeCanvas - could not get PrefabFocusPublicInterface on construction."); 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(); const GraphCanvas::EditorId& editorId = GetEditorId();
// Register unique color palettes for our connections (data types) // Register unique color palettes for our connections (data types)
@ -837,6 +849,26 @@ namespace LandscapeCanvasEditor
{ {
using namespace AzFramework::Terrain; 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 // Invoke the GraphCanvas base instead of the GraphModelIntegration::EditorMainWindow so that we
// can do our own custom handling when opening an existing graph // can do our own custom handling when opening an existing graph
GraphCanvas::AssetEditorMainWindow::OnEditorOpened(dockWidget); GraphCanvas::AssetEditorMainWindow::OnEditorOpened(dockWidget);

@ -34,6 +34,8 @@
namespace AzToolsFramework namespace AzToolsFramework
{ {
class ReadOnlyEntityPublicInterface;
namespace Prefab namespace Prefab
{ {
class PrefabFocusPublicInterface; class PrefabFocusPublicInterface;
@ -261,7 +263,9 @@ namespace LandscapeCanvasEditor
AZ::SerializeContext* m_serializeContext = nullptr; AZ::SerializeContext* m_serializeContext = nullptr;
static AzFramework::EntityContextId s_editorEntityContextId;
AzToolsFramework::Prefab::PrefabFocusPublicInterface* m_prefabFocusPublicInterface = nullptr; AzToolsFramework::Prefab::PrefabFocusPublicInterface* m_prefabFocusPublicInterface = nullptr;
AzToolsFramework::ReadOnlyEntityPublicInterface* m_readOnlyEntityPublicInterface = nullptr;
bool m_ignoreGraphUpdates = false; bool m_ignoreGraphUpdates = false;
bool m_prefabPropagationInProgress = false; bool m_prefabPropagationInProgress = false;

Loading…
Cancel
Save