Implemented the PrefabViewportFocusPathHandler class, added a breadcrumb widget to the viewport toolbar to display the currently focused prefab path.

Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com>
This commit is contained in:
Danilo Aimini
2021-09-20 23:36:41 -07:00
parent 62f7fbb665
commit 8ab409e4d2
10 changed files with 231 additions and 15 deletions
+1 -3
View File
@@ -292,8 +292,6 @@ void CViewportTitleDlg::SetViewPane(CLayoutViewPane* pViewPane)
//////////////////////////////////////////////////////////////////////////
void CViewportTitleDlg::OnInitDialog()
{
m_ui->m_titleBtn->setText(m_title);
// Add a child parented to us that listens for r_displayInfo changes.
auto displayInfoHelper = new CViewportTitleDlgDisplayInfoHelper(this);
connect(displayInfoHelper, &CViewportTitleDlgDisplayInfoHelper::ViewportInfoStatusUpdated, this, &CViewportTitleDlg::UpdateDisplayInfo);
@@ -314,13 +312,13 @@ void CViewportTitleDlg::OnInitDialog()
m_cameraSpeed->setFixedWidth(width);
m_prefabViewportFocusPathHandler.Initialize(m_ui->m_prefabFocusPath, m_ui->m_prefabFocusBackButton);
}
//////////////////////////////////////////////////////////////////////////
void CViewportTitleDlg::SetTitle(const QString& title)
{
m_title = title;
m_ui->m_titleBtn->setText(m_title);
}
//////////////////////////////////////////////////////////////////////////
+3
View File
@@ -19,6 +19,7 @@
#include <QWidgetAction>
#include <QComboBox>
#include <AzToolsFramework/UI/Prefab/PrefabViewportFocusPathHandler.h>
#include <AzQtComponents/Components/Widgets/SpinBox.h>
#include <HMDBus.h>
@@ -176,6 +177,8 @@ protected:
QWidgetAction* m_gridSizeActionWidget = nullptr;
QWidgetAction* m_angleSizeActionWidget = nullptr;
AzToolsFramework::Prefab::PrefabViewportFocusPathHandler m_prefabViewportFocusPathHandler;
QScopedPointer<Ui::ViewportTitleDlg> m_ui;
};
+19 -10
View File
@@ -42,22 +42,25 @@
<number>0</number>
</property>
<item>
<widget class="QLabel" name="m_titleBtn">
<widget class="QToolButton" name="m_prefabFocusBackButton">
<property name="icon">
<iconset>
<normaloff>:/Breadcrumb/img/UI20/Breadcrumb/arrow_left-default.svg</normaloff>:/Breadcrumb/img/UI20/Breadcrumb/arrow_left-default.svg
</iconset>
</property>
<property name="toolTip">
<string>Back</string>
</property>
</widget>
</item>
<item>
<widget class="AzQtComponents::BreadCrumbs" name="m_prefabFocusPath">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
<property name="text">
<string>Static</string>
</property>
<property name="indent">
<number>11</number>
</property>
</widget>
</item>
<item>
@@ -129,6 +132,12 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>AzQtComponents::BreadCrumbs</class>
<extends>QWidget</extends>
<header>AzQtComponents/Components/Widgets/Breadcrumbs.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>AzQtComponents::ButtonDivider</class>
<extends>QWidget</extends>
@@ -11,6 +11,7 @@
#include <AzToolsFramework/Entity/PrefabEditorEntityOwnershipInterface.h>
#include <AzToolsFramework/Prefab/Instance/Instance.h>
#include <AzToolsFramework/Prefab/Instance/InstanceEntityMapperInterface.h>
#include <AzToolsFramework/Prefab/PrefabFocusNotificationBus.h>
namespace AzToolsFramework::Prefab
{
@@ -23,12 +24,14 @@ namespace AzToolsFramework::Prefab
"Instance Entity Mapper Interface could not be found. "
"Check that it is being correctly initialized.");
EditorEntityContextNotificationBus::Handler::BusConnect();
AZ::Interface<PrefabFocusInterface>::Register(this);
}
PrefabFocusHandler::~PrefabFocusHandler()
{
AZ::Interface<PrefabFocusInterface>::Unregister(this);
EditorEntityContextNotificationBus::Handler::BusDisconnect();
}
PrefabFocusOperationResult PrefabFocusHandler::FocusOnOwningPrefab(AZ::EntityId entityId)
@@ -55,8 +58,28 @@ namespace AzToolsFramework::Prefab
if (!focusedInstance.has_value())
{
return AZ::Failure(AZStd::string(
"Prefab Focus Handler: Couldn't find owning instance of entityId provided."));
return AZ::Failure(AZStd::string("Prefab Focus Handler: Couldn't find owning instance of entityId provided."));
}
if (&m_focusedInstance->get() != &focusedInstance->get())
{
m_focusedInstance = focusedInstance;
m_focusedTemplateId = focusedInstance->get().GetTemplateId();
s_focusModeInterface->SetFocusRoot(focusedInstance->get().GetContainerEntityId());
RefreshInstanceFocusList();
PrefabFocusNotificationBus::Broadcast(&PrefabFocusNotifications::OnPrefabFocusChanged);
}
return AZ::Success();
}
PrefabFocusOperationResult PrefabFocusHandler::FocusOnPathIndex(int index)
{
if (index < 0 || index >= m_instanceFocusVector.size())
{
return AZ::Failure(AZStd::string("Prefab Focus Handler: Invalid index on FocusOnPathIndex."));
}
m_focusedInstance = focusedInstance;
@@ -68,7 +91,13 @@ namespace AzToolsFramework::Prefab
focusModeInterface->SetFocusRoot(focusedInstance->get().GetContainerEntityId());
}
RefreshInstanceFocusList();
PrefabFocusNotificationBus::Broadcast(&PrefabFocusNotifications::OnPrefabFocusChanged);
}
return AZ::Success();
}
TemplateId PrefabFocusHandler::GetFocusedPrefabTemplateId()
@@ -93,4 +122,39 @@ namespace AzToolsFramework::Prefab
return instance.has_value() && (&instance->get() == &m_focusedInstance->get());
}
const AZ::IO::Path& PrefabFocusHandler::GetPrefabFocusPath()
{
return m_instanceFocusPath;
}
void PrefabFocusHandler::OnEntityStreamLoadSuccess()
{
// Focus on the root prefab (AZ::EntityId() will default to it)
FocusOnOwningPrefab(AZ::EntityId());
}
void PrefabFocusHandler::RefreshInstanceFocusList()
{
m_instanceFocusVector.clear();
m_instanceFocusPath.clear();
AZStd::list<InstanceOptionalReference> instanceFocusList;
// Use a support list to easily push front while traversing the prefab hierarchy
InstanceOptionalReference currentInstance = m_focusedInstance;
while (currentInstance.has_value())
{
instanceFocusList.push_front(currentInstance);
currentInstance = currentInstance->get().GetParentInstance();
}
// Populate internals using the support list
for (auto& instance : instanceFocusList)
{
m_instanceFocusPath.Append(instance->get().GetContainerEntity()->get().GetName());
m_instanceFocusVector.emplace_back(instance);
}
}
} // namespace AzToolsFramework::Prefab
@@ -10,6 +10,7 @@
#include <AzCore/Memory/SystemAllocator.h>
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
#include <AzToolsFramework/FocusMode/FocusModeInterface.h>
#include <AzToolsFramework/Prefab/PrefabFocusInterface.h>
#include <AzToolsFramework/Prefab/Template/Template.h>
@@ -21,6 +22,7 @@ namespace AzToolsFramework::Prefab
//! Handles Prefab Focus mode, determining which prefab file entity changes will target.
class PrefabFocusHandler final
: private PrefabFocusInterface
, private EditorEntityContextNotificationBus::Handler
{
public:
AZ_CLASS_ALLOCATOR(PrefabFocusHandler, AZ::SystemAllocator, 0);
@@ -30,13 +32,22 @@ namespace AzToolsFramework::Prefab
// PrefabFocusInterface override ...
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;
// EditorEntityContextNotificationBus...
void OnEntityStreamLoadSuccess() override;
private:
void RefreshInstanceFocusList();
InstanceOptionalReference m_focusedInstance;
TemplateId m_focusedTemplateId;
AZStd::vector<InstanceOptionalReference> m_instanceFocusVector;
AZ::IO::Path m_instanceFocusPath;
InstanceEntityMapperInterface* m_instanceEntityMapperInterface;
};
@@ -28,6 +28,10 @@ namespace AzToolsFramework::Prefab
//! @param entityId The entityId of the entity whose owning instance we want the prefab system to focus on.
virtual PrefabFocusOperationResult FocusOnOwningPrefab(AZ::EntityId entityId) = 0;
//! Set the focused prefab instance to the instance at position index of the current path.
//! @param index The index of the instance in the current path that we want the prefab system to focus on.
virtual PrefabFocusOperationResult FocusOnPathIndex(int index) = 0;
//! Returns the template id of the instance the prefab system is focusing on.
virtual TemplateId GetFocusedPrefabTemplateId() = 0;
@@ -38,6 +42,11 @@ namespace AzToolsFramework::Prefab
//! @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;
//! 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 const AZ::IO::Path& GetPrefabFocusPath() = 0;
};
} // namespace AzToolsFramework::Prefab
@@ -0,0 +1,25 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <AzCore/EBus/EBus.h>
namespace AzToolsFramework::Prefab
{
class PrefabFocusNotifications : public AZ::EBusTraits
{
public:
virtual ~PrefabFocusNotifications() = default;
virtual void OnPrefabFocusChanged() = 0;
};
using PrefabFocusNotificationBus = AZ::EBus<PrefabFocusNotifications>;
} // namespace AzToolsFramework::Prefab
@@ -0,0 +1,54 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <AzToolsFramework/Prefab/PrefabFocusInterface.h>
#include <AzToolsFramework/UI/Prefab/PrefabViewportFocusPathHandler.h>
namespace AzToolsFramework::Prefab
{
PrefabViewportFocusPathHandler::~PrefabViewportFocusPathHandler()
{
// Disconnect from Prefab Focus Notifications
PrefabFocusNotificationBus::Handler::BusDisconnect();
}
void PrefabViewportFocusPathHandler::Initialize(AzQtComponents::BreadCrumbs* breadcrumbsWidget, QToolButton* backButton)
{
// Get reference to the PrefabFocusInterface handler
m_prefabFocusInterface = AZ::Interface<PrefabFocusInterface>::Get();
if (m_prefabFocusInterface == nullptr)
{
AZ_Assert(false, "Prefab - could not get PrefabFocusInterface on PrefabViewportFocusPathHandler construction.");
return;
}
// Connect to Prefab Focus Notifications
PrefabFocusNotificationBus::Handler::BusConnect();
// Initialize Widgets
m_breadcrumbsWidget = breadcrumbsWidget;
m_backButton = backButton;
m_backButton->setEnabled(false);
connect(
m_breadcrumbsWidget, &AzQtComponents::BreadCrumbs::linkClicked, this,
[&](const QString&, int linkIndex)
{
m_prefabFocusInterface->FocusOnPathIndex(linkIndex);
}
);
}
void PrefabViewportFocusPathHandler::OnPrefabFocusChanged()
{
// Push new Path
m_breadcrumbsWidget->pushPath(m_prefabFocusInterface->GetPrefabFocusPath().c_str());
}
} // namespace AzToolsFramework::Prefab
@@ -0,0 +1,40 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <AzToolsFramework/Prefab/PrefabFocusNotificationBus.h>
#include <AzQtComponents/Components/Widgets/Breadcrumbs.h>
#include <QLayout>
#include <QToolButton>
namespace AzToolsFramework::Prefab
{
class PrefabFocusInterface;
class PrefabViewportFocusPathHandler
: public PrefabFocusNotificationBus::Handler
, private QObject
{
public:
~PrefabViewportFocusPathHandler();
void Initialize(AzQtComponents::BreadCrumbs* breadcrumbsWidget, QToolButton* backButton);
// PrefabFocusNotificationBus...
void OnPrefabFocusChanged() override;
private:
AzQtComponents::BreadCrumbs* m_breadcrumbsWidget = nullptr;
QToolButton* m_backButton = nullptr;
PrefabFocusInterface* m_prefabFocusInterface = nullptr;
};
} // namespace AzToolsFramework::Prefab
@@ -635,6 +635,7 @@ set(FILES
Prefab/PrefabFocusHandler.h
Prefab/PrefabFocusHandler.cpp
Prefab/PrefabFocusInterface.h
Prefab/PrefabFocusNotificationBus.h
Prefab/PrefabIdTypes.h
Prefab/PrefabLoader.h
Prefab/PrefabLoader.cpp
@@ -733,6 +734,8 @@ set(FILES
UI/Prefab/PrefabIntegrationInterface.h
UI/Prefab/PrefabUiHandler.h
UI/Prefab/PrefabUiHandler.cpp
UI/Prefab/PrefabViewportFocusPathHandler.h
UI/Prefab/PrefabViewportFocusPathHandler.cpp
PythonTerminal/ScriptHelpDialog.cpp
PythonTerminal/ScriptHelpDialog.h
PythonTerminal/ScriptHelpDialog.ui