Change notification buses to be addressed on EntityContextId, and connect the handlers to the default id. Request interfaces should not need that id as they can retrieve it from the entityId.

Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com>
monroegm-disable-blank-issue-2
Danilo Aimini 4 years ago
parent ce334f9443
commit c204aa1abe

@ -11,19 +11,28 @@
#include <AzCore/Component/EntityId.h> #include <AzCore/Component/EntityId.h>
#include <AzCore/EBus/EBus.h> #include <AzCore/EBus/EBus.h>
#include <AzFramework/Entity/EntityContext.h>
namespace AzToolsFramework namespace AzToolsFramework
{ {
//! Used to notify when the editor focus changes. //! Used to notify when the editor focus changes.
class FocusModeNotifications class FocusModeNotifications
: public AZ::EBusTraits : public AZ::EBusTraits
{ {
protected:
~FocusModeNotifications() = default;
public: public:
//////////////////////////////////////////////////////////////////////////
// EBusTraits overrides
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
using BusIdType = AzFramework::EntityContextId;
//////////////////////////////////////////////////////////////////////////
//! Triggered when the editor focus is changed to a different entity. //! Triggered when the editor focus is changed to a different entity.
//! @param entityId The entity the focus has been moved to. //! @param entityId The entity the focus has been moved to.
virtual void OnEditorFocusChanged(AZ::EntityId entityId) = 0; virtual void OnEditorFocusChanged(AZ::EntityId entityId) = 0;
protected:
~FocusModeNotifications() = default;
}; };
using FocusModeNotificationBus = AZ::EBus<FocusModeNotifications>; using FocusModeNotificationBus = AZ::EBus<FocusModeNotifications>;

@ -96,6 +96,10 @@ namespace AzToolsFramework::Prefab
else else
{ {
containerEntityId = AZ::EntityId(); containerEntityId = AZ::EntityId();
// Clear the selection
AzToolsFramework::SelectEntities({});
} }
// Focus on the descendants of the container entity // Focus on the descendants of the container entity

@ -17,12 +17,19 @@ namespace AzToolsFramework::Prefab
class PrefabFocusNotifications class PrefabFocusNotifications
: public AZ::EBusTraits : public AZ::EBusTraits
{ {
protected:
~PrefabFocusNotifications() = default;
public: public:
//////////////////////////////////////////////////////////////////////////
// EBusTraits overrides
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
using BusIdType = AzFramework::EntityContextId;
//////////////////////////////////////////////////////////////////////////
//! Triggered when the editor focus is changed to a different prefab. //! Triggered when the editor focus is changed to a different prefab.
virtual void OnPrefabFocusChanged() = 0; virtual void OnPrefabFocusChanged() = 0;
protected:
~PrefabFocusNotifications() = default;
}; };
using PrefabFocusNotificationBus = AZ::EBus<PrefabFocusNotifications>; using PrefabFocusNotificationBus = AZ::EBus<PrefabFocusNotifications>;

@ -39,7 +39,12 @@ namespace AzToolsFramework
AZ_Assert((m_editorEntityFrameworkInterface != nullptr), AZ_Assert((m_editorEntityFrameworkInterface != nullptr),
"EntityOutlinerTreeView requires a EditorEntityFrameworkInterface instance on Construction."); "EntityOutlinerTreeView requires a EditorEntityFrameworkInterface instance on Construction.");
FocusModeNotificationBus::Handler::BusConnect();
AzFramework::EntityContextId editorEntityContextId = AzFramework::EntityContextId::CreateNull();
AzToolsFramework::EditorEntityContextRequestBus::BroadcastResult(
editorEntityContextId, &AzToolsFramework::EditorEntityContextRequestBus::Events::GetEditorEntityContextId);
FocusModeNotificationBus::Handler::BusConnect(editorEntityContextId);
viewport()->setMouseTracking(true); viewport()->setMouseTracking(true);
} }

@ -6,15 +6,21 @@
* *
*/ */
#include <AzToolsFramework/Prefab/PrefabFocusInterface.h>
#include <AzToolsFramework/UI/Prefab/PrefabViewportFocusPathHandler.h> #include <AzToolsFramework/UI/Prefab/PrefabViewportFocusPathHandler.h>
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
#include <AzToolsFramework/Prefab/PrefabFocusInterface.h>
namespace AzToolsFramework::Prefab namespace AzToolsFramework::Prefab
{ {
PrefabViewportFocusPathHandler::PrefabViewportFocusPathHandler() PrefabViewportFocusPathHandler::PrefabViewportFocusPathHandler()
{ {
// Connect to Prefab Focus Notifications // Connect to Prefab Focus Notifications
PrefabFocusNotificationBus::Handler::BusConnect(); AzFramework::EntityContextId editorEntityContextId = AzFramework::EntityContextId::CreateNull();
AzToolsFramework::EditorEntityContextRequestBus::BroadcastResult(
editorEntityContextId, &AzToolsFramework::EditorEntityContextRequestBus::Events::GetEditorEntityContextId);
PrefabFocusNotificationBus::Handler::BusConnect(editorEntityContextId);
} }
PrefabViewportFocusPathHandler::~PrefabViewportFocusPathHandler() PrefabViewportFocusPathHandler::~PrefabViewportFocusPathHandler()

Loading…
Cancel
Save