diff --git a/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.cpp b/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.cpp index 4574b938f6..ce9eab5f7e 100644 --- a/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.cpp +++ b/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -448,6 +449,9 @@ namespace LandscapeCanvasEditor AZ::ComponentApplicationBus::BroadcastResult(m_serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext); AZ_Assert(m_serializeContext, "Failed to acquire application serialize context."); + m_prefabFocusPublicInterface = AZ::Interface::Get(); + AZ_Assert(m_prefabFocusPublicInterface, "LandscapeCanvas - could not get PrefabFocusPublicInterface on construction."); + const GraphCanvas::EditorId& editorId = GetEditorId(); // Register unique color palettes for our connections (data types) @@ -459,6 +463,7 @@ namespace LandscapeCanvasEditor AzToolsFramework::EditorPickModeNotificationBus::Handler::BusConnect(AzToolsFramework::GetEntityContextId()); AzToolsFramework::EntityCompositionNotificationBus::Handler::BusConnect(); AzToolsFramework::ToolsApplicationNotificationBus::Handler::BusConnect(); + AzToolsFramework::Prefab::PrefabFocusNotificationBus::Handler::BusConnect(AzToolsFramework::GetEntityContextId()); AzToolsFramework::Prefab::PrefabPublicNotificationBus::Handler::BusConnect(); CrySystemEventBus::Handler::BusConnect(); AZ::EntitySystemBus::Handler::BusConnect(); @@ -484,6 +489,7 @@ namespace LandscapeCanvasEditor AZ::EntitySystemBus::Handler::BusDisconnect(); CrySystemEventBus::Handler::BusDisconnect(); AzToolsFramework::Prefab::PrefabPublicNotificationBus::Handler::BusDisconnect(); + AzToolsFramework::Prefab::PrefabFocusNotificationBus::Handler::BusDisconnect(); AzToolsFramework::ToolsApplicationNotificationBus::Handler::BusDisconnect(); AzToolsFramework::EditorPickModeNotificationBus::Handler::BusDisconnect(); AzToolsFramework::EditorEntityContextNotificationBus::Handler::BusDisconnect(); @@ -2500,6 +2506,24 @@ namespace LandscapeCanvasEditor } } + void MainWindow::OnPrefabFocusChanged() + { + // Make sure to close any open graphs that aren't currently in prefab focus + // to prevent the user from making modifications outside of the allowed focus scope + AZStd::vector dockWidgetsToClose; + for (auto [entityId, dockWidgetId] : m_dockWidgetsByEntity) + { + if (!m_prefabFocusPublicInterface->IsOwningPrefabBeingFocused(entityId)) + { + dockWidgetsToClose.push_back(dockWidgetId); + } + } + for (auto dockWidgetId : dockWidgetsToClose) + { + CloseEditor(dockWidgetId); + } + } + void MainWindow::OnPrefabInstancePropagationBegin() { // Ignore graph updates during prefab propagation because the entities will be diff --git a/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.h b/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.h index e0fb2d8e10..de6b10529d 100644 --- a/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.h +++ b/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -31,6 +32,14 @@ #include #endif +namespace AzToolsFramework +{ + namespace Prefab + { + class PrefabFocusPublicInterface; + } +} + namespace LandscapeCanvasEditor { //////////////////////////////////////////////////////////////////////// @@ -81,6 +90,7 @@ namespace LandscapeCanvasEditor , private AzToolsFramework::EntityCompositionNotificationBus::Handler , private AzToolsFramework::PropertyEditorEntityChangeNotificationBus::MultiHandler , private AzToolsFramework::ToolsApplicationNotificationBus::Handler + , private AzToolsFramework::Prefab::PrefabFocusNotificationBus::Handler , private AzToolsFramework::Prefab::PrefabPublicNotificationBus::Handler , private CrySystemEventBus::Handler { @@ -181,6 +191,9 @@ namespace LandscapeCanvasEditor void EntityParentChanged(AZ::EntityId entityId, AZ::EntityId newParentId, AZ::EntityId oldParentId) override; //////////////////////////////////////////////////////////////////////// + //! PrefabFocusNotificationBus overrides + void OnPrefabFocusChanged() override; + //! PrefabPublicNotificationBus overrides void OnPrefabInstancePropagationBegin() override; void OnPrefabInstancePropagationEnd() override; @@ -248,6 +261,8 @@ namespace LandscapeCanvasEditor AZ::SerializeContext* m_serializeContext = nullptr; + AzToolsFramework::Prefab::PrefabFocusPublicInterface* m_prefabFocusPublicInterface = nullptr; + bool m_ignoreGraphUpdates = false; bool m_prefabPropagationInProgress = false; bool m_inObjectPickMode = false;