From 59d7cd60583a782a50b564cc4ed436e21b992247 Mon Sep 17 00:00:00 2001 From: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> Date: Tue, 21 Sep 2021 15:01:16 -0700 Subject: [PATCH] Enable back button and introduce behavior Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> --- .../Prefab/PrefabFocusHandler.cpp | 5 +++++ .../Prefab/PrefabFocusHandler.h | 1 + .../Prefab/PrefabFocusInterface.h | 8 +++++--- .../Prefab/PrefabViewportFocusPathHandler.cpp | 19 ++++++++++++++++++- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusHandler.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusHandler.cpp index 276d76f848..f203d70e06 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusHandler.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusHandler.cpp @@ -127,6 +127,11 @@ namespace AzToolsFramework::Prefab return m_instanceFocusPath; } + const int PrefabFocusHandler::GetPrefabFocusPathLength() + { + return m_instanceFocusVector.size(); + } + void PrefabFocusHandler::OnEntityStreamLoadSuccess() { // Focus on the root prefab (AZ::EntityId() will default to it) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusHandler.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusHandler.h index 35ef9aba61..6e8e3ab3e8 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusHandler.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusHandler.h @@ -37,6 +37,7 @@ namespace AzToolsFramework::Prefab InstanceOptionalReference GetFocusedPrefabInstance() override; bool IsOwningPrefabBeingFocused(AZ::EntityId entityId) override; const AZ::IO::Path& GetPrefabFocusPath() override; + const int GetPrefabFocusPathLength() override; // EditorEntityContextNotificationBus... void OnEntityStreamLoadSuccess() override; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusInterface.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusInterface.h index 9f695f2bf7..0084a2ef2e 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusInterface.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabFocusInterface.h @@ -43,10 +43,12 @@ namespace AzToolsFramework::Prefab //! @return true if the entity belongs to the focused instance or one of its descendants, false otherwise. virtual bool IsOwningPrefabBeingFocused(AZ::EntityId entityId) = 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. + //! 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; + + //! Returns the size of the path to the currently focused instance. + virtual const int GetPrefabFocusPathLength() = 0; }; } // namespace AzToolsFramework::Prefab diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabViewportFocusPathHandler.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabViewportFocusPathHandler.cpp index 3ca3ec990f..dba5090170 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabViewportFocusPathHandler.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabViewportFocusPathHandler.cpp @@ -34,8 +34,9 @@ namespace AzToolsFramework::Prefab m_breadcrumbsWidget = breadcrumbsWidget; m_backButton = backButton; - m_backButton->setEnabled(false); + m_backButton->setVisible(false); + // If a part of the path is clicked, focus on that instance connect( m_breadcrumbsWidget, &AzQtComponents::BreadCrumbs::linkClicked, this, [&](const QString&, int linkIndex) @@ -43,12 +44,28 @@ namespace AzToolsFramework::Prefab m_prefabFocusInterface->FocusOnPathIndex(linkIndex); } ); + + // The back button will allow user to go one level up + connect(m_backButton, &QToolButton::clicked, this, + [&]() + { + int length = m_prefabFocusInterface->GetPrefabFocusPathLength(); + + if (length > 1) + { + m_prefabFocusInterface->FocusOnPathIndex(length - 2); + } + } + ); } void PrefabViewportFocusPathHandler::OnPrefabFocusChanged() { // Push new Path m_breadcrumbsWidget->pushPath(m_prefabFocusInterface->GetPrefabFocusPath().c_str()); + + // Only show the back icon button if the path has more than one element + m_backButton->setVisible(m_prefabFocusInterface->GetPrefabFocusPathLength() > 1); } } // namespace AzToolsFramework::Prefab