Enable back button and introduce behavior

Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com>
This commit is contained in:
Danilo Aimini
2021-09-21 15:01:16 -07:00
parent 8ab409e4d2
commit 59d7cd6058
4 changed files with 29 additions and 4 deletions
@@ -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)
@@ -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;
@@ -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
@@ -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