diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/FocusMode/FocusModeNotificationBus.h b/Code/Framework/AzToolsFramework/AzToolsFramework/FocusMode/FocusModeNotificationBus.h index e42c02fe3b..a16bb9a3ef 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/FocusMode/FocusModeNotificationBus.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/FocusMode/FocusModeNotificationBus.h @@ -13,12 +13,16 @@ namespace AzToolsFramework { + //! Used to notify when the editor focus changes. class FocusModeNotifications : public AZ::EBusTraits { - public: - virtual ~FocusModeNotifications() = default; + protected: + ~FocusModeNotifications() = default; + public: + //! Triggered when the editor focus is changed to a different entity. + //! @param entityId The entity the focus has been moved to. virtual void OnEditorFocusChanged(AZ::EntityId entityId) = 0; }; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusHandler.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusHandler.cpp index 7d4ca36458..6135f35df5 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusHandler.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusHandler.cpp @@ -79,7 +79,7 @@ namespace AzToolsFramework::Prefab return AZ::Failure(AZStd::string("Prefab Focus Handler: invalid instance to focus on.")); } - if (&m_focusedInstance->get() != &focusedInstance->get()) + if (!m_focusedInstance.has_value() || &m_focusedInstance->get() != &focusedInstance->get()) { m_focusedInstance = focusedInstance; m_focusedTemplateId = focusedInstance->get().GetTemplateId(); @@ -90,8 +90,7 @@ namespace AzToolsFramework::Prefab AzToolsFramework::SelectEntity(containerEntityId); // Focus on the descendants of the container entity - FocusModeInterface* focusModeInterface = AZ::Interface::Get(); - if (focusModeInterface) + if (FocusModeInterface* focusModeInterface = AZ::Interface::Get()) { focusModeInterface->SetFocusRoot(containerEntityId); } @@ -104,17 +103,17 @@ namespace AzToolsFramework::Prefab return AZ::Success(); } - TemplateId PrefabFocusHandler::GetFocusedPrefabTemplateId() + TemplateId PrefabFocusHandler::GetFocusedPrefabTemplateId() const { return m_focusedTemplateId; } - InstanceOptionalReference PrefabFocusHandler::GetFocusedPrefabInstance() + InstanceOptionalReference PrefabFocusHandler::GetFocusedPrefabInstance() const { return m_focusedInstance; } - bool PrefabFocusHandler::IsOwningPrefabBeingFocused(AZ::EntityId entityId) + bool PrefabFocusHandler::IsOwningPrefabBeingFocused(AZ::EntityId entityId) const { if (!m_focusedInstance.has_value()) { @@ -132,12 +131,12 @@ namespace AzToolsFramework::Prefab return instance.has_value() && (&instance->get() == &m_focusedInstance->get()); } - const AZ::IO::Path& PrefabFocusHandler::GetPrefabFocusPath() + const AZ::IO::Path& PrefabFocusHandler::GetPrefabFocusPath() const { return m_instanceFocusPath; } - const int PrefabFocusHandler::GetPrefabFocusPathLength() + const int PrefabFocusHandler::GetPrefabFocusPathLength() const { return aznumeric_cast(m_instanceFocusVector.size()); } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusHandler.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusHandler.h index 7dd22eda08..0362e2d66d 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusHandler.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusHandler.h @@ -30,16 +30,16 @@ namespace AzToolsFramework::Prefab PrefabFocusHandler(); ~PrefabFocusHandler(); - // PrefabFocusInterface override ... + // PrefabFocusInterface overrides ... PrefabFocusOperationResult FocusOnOwningPrefab(AZ::EntityId entityId) override; PrefabFocusOperationResult FocusOnPathIndex(int index) override; - TemplateId GetFocusedPrefabTemplateId() override; - InstanceOptionalReference GetFocusedPrefabInstance() override; - bool IsOwningPrefabBeingFocused(AZ::EntityId entityId) override; - const AZ::IO::Path& GetPrefabFocusPath() override; - const int GetPrefabFocusPathLength() override; + TemplateId GetFocusedPrefabTemplateId() const override; + InstanceOptionalReference GetFocusedPrefabInstance() const override; + bool IsOwningPrefabBeingFocused(AZ::EntityId entityId) const override; + const AZ::IO::Path& GetPrefabFocusPath() const override; + const int GetPrefabFocusPathLength() const override; - // EditorEntityContextNotificationBus... + // EditorEntityContextNotificationBus overrides ... void OnEntityStreamLoadSuccess() override; private: diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusInterface.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusInterface.h index 0084a2ef2e..3efd2d4deb 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusInterface.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusInterface.h @@ -33,22 +33,22 @@ namespace AzToolsFramework::Prefab virtual PrefabFocusOperationResult FocusOnPathIndex(int index) = 0; //! Returns the template id of the instance the prefab system is focusing on. - virtual TemplateId GetFocusedPrefabTemplateId() = 0; + virtual TemplateId GetFocusedPrefabTemplateId() const = 0; //! Returns a reference to the instance the prefab system is focusing on. - virtual InstanceOptionalReference GetFocusedPrefabInstance() = 0; + virtual InstanceOptionalReference GetFocusedPrefabInstance() const = 0; //! Returns whether the entity belongs to the instance that is being focused on, or one of its descendants. //! @param entityId The entityId of the queried entity. //! @return true if the entity belongs to the focused instance or one of its descendants, false otherwise. - virtual bool IsOwningPrefabBeingFocused(AZ::EntityId entityId) = 0; + virtual bool IsOwningPrefabBeingFocused(AZ::EntityId entityId) const = 0; //! Returns the path from the root instance to the currently focused instance. //! @return A path composed from the names of the container entities for the instance path. - virtual const AZ::IO::Path& GetPrefabFocusPath() = 0; + virtual const AZ::IO::Path& GetPrefabFocusPath() const = 0; //! Returns the size of the path to the currently focused instance. - virtual const int GetPrefabFocusPathLength() = 0; + virtual const int GetPrefabFocusPathLength() const = 0; }; } // namespace AzToolsFramework::Prefab diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusNotificationBus.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusNotificationBus.h index 5eda6ff2e3..aa27d87013 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusNotificationBus.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusNotificationBus.h @@ -9,14 +9,19 @@ #pragma once #include +#include namespace AzToolsFramework::Prefab { - class PrefabFocusNotifications : public AZ::EBusTraits + //! Used to notify when the editor focus changes. + class PrefabFocusNotifications + : public AZ::EBusTraits { - public: - virtual ~PrefabFocusNotifications() = default; + protected: + ~PrefabFocusNotifications() = default; + public: + //! Triggered when the editor focus is changed to a different prefab. virtual void OnPrefabFocusChanged() = 0; }; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabViewportFocusPathHandler.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabViewportFocusPathHandler.cpp index c83c0016be..c1dd66ec7f 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabViewportFocusPathHandler.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabViewportFocusPathHandler.cpp @@ -49,9 +49,7 @@ namespace AzToolsFramework::Prefab connect(m_backButton, &QToolButton::clicked, this, [&]() { - int length = m_prefabFocusInterface->GetPrefabFocusPathLength(); - - if (length > 1) + if (int length = m_prefabFocusInterface->GetPrefabFocusPathLength(); length > 1) { m_prefabFocusInterface->FocusOnPathIndex(length - 2); } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabViewportFocusPathHandler.h b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabViewportFocusPathHandler.h index c874c7249f..5ce76d78ec 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabViewportFocusPathHandler.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabViewportFocusPathHandler.h @@ -29,7 +29,7 @@ namespace AzToolsFramework::Prefab void Initialize(AzQtComponents::BreadCrumbs* breadcrumbsWidget, QToolButton* backButton); - // PrefabFocusNotificationBus... + // PrefabFocusNotificationBus overrides ... void OnPrefabFocusChanged() override; private: