diff --git a/Code/Editor/Core/LevelEditorMenuHandler.cpp b/Code/Editor/Core/LevelEditorMenuHandler.cpp index e568f05167..25467756ac 100644 --- a/Code/Editor/Core/LevelEditorMenuHandler.cpp +++ b/Code/Editor/Core/LevelEditorMenuHandler.cpp @@ -32,6 +32,7 @@ #include // AzToolsFramework +#include #include // AzQtComponents @@ -166,15 +167,14 @@ LevelEditorMenuHandler::LevelEditorMenuHandler(MainWindow* mainWindow, QtViewPan m_mainWindow->menuBar()->setNativeMenuBar(true); #endif - ComponentModeFramework::EditorComponentModeNotificationBus::Handler::BusConnect( - AzToolsFramework::GetEntityContextId()); + ViewportEditorModeNotificationsBus::Handler::BusConnect(GetEntityContextId()); EditorMenuRequestBus::Handler::BusConnect(); } LevelEditorMenuHandler::~LevelEditorMenuHandler() { EditorMenuRequestBus::Handler::BusDisconnect(); - ComponentModeFramework::EditorComponentModeNotificationBus::Handler::BusDisconnect(); + ViewportEditorModeNotificationsBus::Handler::BusDisconnect(); } void LevelEditorMenuHandler::Initialize() @@ -1186,30 +1186,38 @@ void LevelEditorMenuHandler::AddDisableActionInSimModeListener(QAction* action) })); } -void LevelEditorMenuHandler::EnteredComponentMode(const AZStd::vector& /*componentModeTypes*/) +void LevelEditorMenuHandler::OnEditorModeActivated( + [[maybe_unused]] const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) { - auto menuWrapper = m_actionManager->FindMenu(s_editMenuId); - if (!menuWrapper.isNull()) + if (mode == ViewportEditorMode::Component) { - // copy of menu actions - auto actions = menuWrapper.Get()->actions(); - // remove all non-reserved edit menu options - actions.erase( - std::remove_if(actions.begin(), actions.end(), [](QAction* action) - { - return !action->property("Reserved").toBool(); - }), - actions.end()); + auto menuWrapper = m_actionManager->FindMenu(s_editMenuId); + if (!menuWrapper.isNull()) + { + // copy of menu actions + auto actions = menuWrapper.Get()->actions(); + // remove all non-reserved edit menu options + actions.erase( + std::remove_if(actions.begin(), actions.end(), [](QAction* action) + { + return !action->property("Reserved").toBool(); + }), + actions.end()); - // clear and update the menu with new actions - menuWrapper.Get()->clear(); - menuWrapper.Get()->addActions(actions); + // clear and update the menu with new actions + menuWrapper.Get()->clear(); + menuWrapper.Get()->addActions(actions); + } } } -void LevelEditorMenuHandler::LeftComponentMode(const AZStd::vector& /*componentModeTypes*/) +void LevelEditorMenuHandler::OnEditorModeDeactivated( + [[maybe_unused]] const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) { - RestoreEditMenuToDefault(); + if (mode == ViewportEditorMode::Component) + { + RestoreEditMenuToDefault(); + } } void LevelEditorMenuHandler::AddEditMenuAction(QAction* action) diff --git a/Code/Editor/Core/LevelEditorMenuHandler.h b/Code/Editor/Core/LevelEditorMenuHandler.h index 5ac8e63786..ff03c7748c 100644 --- a/Code/Editor/Core/LevelEditorMenuHandler.h +++ b/Code/Editor/Core/LevelEditorMenuHandler.h @@ -18,7 +18,7 @@ #include #include "ActionManager.h" #include "QtViewPaneManager.h" -#include +#include #endif class MainWindow; @@ -28,7 +28,7 @@ struct QtViewPane; class LevelEditorMenuHandler : public QObject - , private AzToolsFramework::ComponentModeFramework::EditorComponentModeNotificationBus::Handler + , private AzToolsFramework::ViewportEditorModeNotificationsBus::Handler , private AzToolsFramework::EditorMenuRequestBus::Handler { Q_OBJECT @@ -88,9 +88,11 @@ private: void AddDisableActionInSimModeListener(QAction* action); - // EditorComponentModeNotificationBus - void EnteredComponentMode(const AZStd::vector& componentModeTypes) override; - void LeftComponentMode(const AZStd::vector& componentModeTypes) override; + // ViewportEditorModeNotificationsBus overrides ... + void OnEditorModeActivated( + const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) override; + void OnEditorModeDeactivated( + const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) override; // EditorMenuRequestBus void AddEditMenuAction(QAction* action) override; diff --git a/Code/Editor/Objects/ObjectManager.cpp b/Code/Editor/Objects/ObjectManager.cpp index f67cf24553..7057cc5b7b 100644 --- a/Code/Editor/Objects/ObjectManager.cpp +++ b/Code/Editor/Objects/ObjectManager.cpp @@ -30,6 +30,8 @@ #include "Plugins/ComponentEntityEditorPlugin/Objects/ComponentEntityObject.h" #include +#include +#include AZ_CVAR_EXTERNED(bool, ed_visibility_logTiming); @@ -107,14 +109,13 @@ CObjectManager::CObjectManager() m_objectsByName.reserve(1024); LoadRegistry(); - AzToolsFramework::ComponentModeFramework::EditorComponentModeNotificationBus::Handler::BusConnect( - AzToolsFramework::GetEntityContextId()); + AzToolsFramework::ViewportEditorModeNotificationsBus::Handler::BusConnect(AzToolsFramework::GetEntityContextId()); } ////////////////////////////////////////////////////////////////////////// CObjectManager::~CObjectManager() { - AzToolsFramework::ComponentModeFramework::EditorComponentModeNotificationBus::Handler::BusDisconnect(); + AzToolsFramework::ViewportEditorModeNotificationsBus::Handler::BusDisconnect(); m_bExiting = true; SaveRegistry(); @@ -2306,25 +2307,33 @@ void CObjectManager::SelectObjectInRect(CBaseObject* pObj, CViewport* view, HitC } } -void CObjectManager::EnteredComponentMode(const AZStd::vector& /*componentModeTypes*/) +void CObjectManager::OnEditorModeActivated( + [[maybe_unused]] const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) { - // hide current gizmo for entity (translate/rotate/scale) - IGizmoManager* gizmoManager = GetGizmoManager(); - const size_t gizmoCount = static_cast(gizmoManager->GetGizmoCount()); - for (size_t i = 0; i < gizmoCount; ++i) + if (mode == AzToolsFramework::ViewportEditorMode::Component) { - gizmoManager->RemoveGizmo(gizmoManager->GetGizmoByIndex(static_cast(i))); + // hide current gizmo for entity (translate/rotate/scale) + IGizmoManager* gizmoManager = GetGizmoManager(); + const size_t gizmoCount = static_cast(gizmoManager->GetGizmoCount()); + for (size_t i = 0; i < gizmoCount; ++i) + { + gizmoManager->RemoveGizmo(gizmoManager->GetGizmoByIndex(static_cast(i))); + } } } -void CObjectManager::LeftComponentMode(const AZStd::vector& /*componentModeTypes*/) +void CObjectManager::OnEditorModeDeactivated( + [[maybe_unused]] const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) { - // show translate/rotate/scale gizmo again - if (IGizmoManager* gizmoManager = GetGizmoManager()) + if (mode == AzToolsFramework::ViewportEditorMode::Component) { - if (CBaseObject* selectedObject = GetIEditor()->GetSelectedObject()) + // show translate/rotate/scale gizmo again + if (IGizmoManager* gizmoManager = GetGizmoManager()) { - gizmoManager->AddGizmo(new CAxisGizmo(selectedObject)); + if (CBaseObject* selectedObject = GetIEditor()->GetSelectedObject()) + { + gizmoManager->AddGizmo(new CAxisGizmo(selectedObject)); + } } } } diff --git a/Code/Editor/Objects/ObjectManager.h b/Code/Editor/Objects/ObjectManager.h index 0ad5d8323e..7fb2342e40 100644 --- a/Code/Editor/Objects/ObjectManager.h +++ b/Code/Editor/Objects/ObjectManager.h @@ -20,8 +20,9 @@ #include "ObjectManagerEventBus.h" #include -#include +#include #include +#include #include // forward declarations. @@ -58,7 +59,7 @@ public: */ class CObjectManager : public IObjectManager - , private AzToolsFramework::ComponentModeFramework::EditorComponentModeNotificationBus::Handler + , private AzToolsFramework::ViewportEditorModeNotificationsBus::Handler { public: //! Selection functor callback. @@ -329,9 +330,11 @@ private: void FindDisplayableObjects(DisplayContext& dc, bool bDisplay); - // EditorComponentModeNotificationBus - void EnteredComponentMode(const AZStd::vector& componentModeTypes) override; - void LeftComponentMode(const AZStd::vector& componentModeTypes) override; + // ViewportEditorModeNotificationsBus overrides ... + void OnEditorModeActivated( + const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) override; + void OnEditorModeDeactivated( + const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) override; private: typedef std::map Objects; diff --git a/Code/Editor/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerWidget.cpp b/Code/Editor/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerWidget.cpp index 9ed7c4a144..803deb3509 100644 --- a/Code/Editor/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerWidget.cpp +++ b/Code/Editor/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerWidget.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -267,8 +268,7 @@ OutlinerWidget::OutlinerWidget(QWidget* pParent, Qt::WindowFlags flags) ToolsApplicationEvents::Bus::Handler::BusConnect(); AzToolsFramework::EditorEntityContextNotificationBus::Handler::BusConnect(); AzToolsFramework::SliceEditorEntityOwnershipServiceNotificationBus::Handler::BusConnect(); - AzToolsFramework::ComponentModeFramework::EditorComponentModeNotificationBus::Handler::BusConnect( - AzToolsFramework::GetEntityContextId()); + AzToolsFramework::ViewportEditorModeNotificationsBus::Handler::BusConnect(AzToolsFramework::GetEntityContextId()); AzToolsFramework::EditorEntityInfoNotificationBus::Handler::BusConnect(); AzToolsFramework::EditorWindowUIRequestBus::Handler::BusConnect(); } @@ -276,7 +276,7 @@ OutlinerWidget::OutlinerWidget(QWidget* pParent, Qt::WindowFlags flags) OutlinerWidget::~OutlinerWidget() { AzToolsFramework::EditorWindowUIRequestBus::Handler::BusDisconnect(); - AzToolsFramework::ComponentModeFramework::EditorComponentModeNotificationBus::Handler::BusDisconnect(); + AzToolsFramework::ViewportEditorModeNotificationsBus::Handler::BusDisconnect(); AzToolsFramework::EditorEntityInfoNotificationBus::Handler::BusDisconnect(); AzToolsFramework::EditorPickModeNotificationBus::Handler::BusDisconnect(); EntityHighlightMessages::Bus::Handler::BusDisconnect(); @@ -1335,14 +1335,22 @@ void OutlinerWidget::SetEditorUiEnabled(bool enable) EnableUi(enable); } -void OutlinerWidget::EnteredComponentMode([[maybe_unused]] const AZStd::vector& componentModeTypes) +void OutlinerWidget::OnEditorModeActivated( + [[maybe_unused]] const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) { - EnableUi(false); + if (mode == AzToolsFramework::ViewportEditorMode::Component) + { + EnableUi(false); + } } -void OutlinerWidget::LeftComponentMode([[maybe_unused]] const AZStd::vector& componentModeTypes) +void OutlinerWidget::OnEditorModeDeactivated( + [[maybe_unused]] const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) { - EnableUi(true); + if (mode == AzToolsFramework::ViewportEditorMode::Component) + { + EnableUi(true); + } } void OutlinerWidget::OnSliceInstantiated(const AZ::Data::AssetId& /*sliceAssetId*/, AZ::SliceComponent::SliceInstanceAddress& sliceAddress, const AzFramework::SliceInstantiationTicket& /*ticket*/) diff --git a/Code/Editor/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerWidget.hxx b/Code/Editor/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerWidget.hxx index b29032a760..364ab05eb7 100644 --- a/Code/Editor/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerWidget.hxx +++ b/Code/Editor/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerWidget.hxx @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include @@ -58,7 +58,7 @@ class OutlinerWidget , private AzToolsFramework::EditorEntityContextNotificationBus::Handler , private AzToolsFramework::SliceEditorEntityOwnershipServiceNotificationBus::Handler , private AzToolsFramework::EditorEntityInfoNotificationBus::Handler - , private AzToolsFramework::ComponentModeFramework::EditorComponentModeNotificationBus::Handler + , private AzToolsFramework::ViewportEditorModeNotificationsBus::Handler , private AzToolsFramework::EditorWindowUIRequestBus::Handler { Q_OBJECT; @@ -105,9 +105,11 @@ private: void OnEntityInfoUpdatedAddChildEnd(AZ::EntityId /*parentId*/, AZ::EntityId /*childId*/) override; void OnEntityInfoUpdatedName(AZ::EntityId entityId, const AZStd::string& /*name*/) override; - // EditorComponentModeNotificationBus - void EnteredComponentMode(const AZStd::vector& componentModeTypes) override; - void LeftComponentMode(const AZStd::vector& componentModeTypes) override; + // ViewportEditorModeNotificationsBus overrides ... + void OnEditorModeActivated( + const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) override; + void OnEditorModeDeactivated( + const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) override; // EditorWindowUIRequestBus overrides void SetEditorUiEnabled(bool enable) override; diff --git a/Code/Editor/QtViewPaneManager.cpp b/Code/Editor/QtViewPaneManager.cpp index eff3a7331e..0f9fd480ca 100644 --- a/Code/Editor/QtViewPaneManager.cpp +++ b/Code/Editor/QtViewPaneManager.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -44,11 +45,54 @@ #include #include #include - #include #include "ShortcutDispatcher.h" +// Helper for EditorComponentModeNotifications to be used +// as a member instead of inheriting from EBus directly. +class ViewportEditorModeNotificationsBusImpl + : public AzToolsFramework::ViewportEditorModeNotificationsBus::Handler +{ + public: + /// Set the function to be called when entering ComponentMode. + void SetEnteredComponentModeFunc( + const AZStd::function& enteredComponentModeFunc) + { + m_enteredComponentModeFunc = enteredComponentModeFunc; + } + + /// Set the function to be called when leaving ComponentMode. + void SetLeftComponentModeFunc( + const AZStd::function& leftComponentModeFunc) + { + m_leftComponentModeFunc = leftComponentModeFunc; + } + + private: + // ViewportEditorModeNotificationsBus overrides ... + void OnEditorModeActivated( + const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) override + { + if (mode == AzToolsFramework::ViewportEditorMode::Component) + { + m_enteredComponentModeFunc(editorModeState); + } + } + + void OnEditorModeDeactivated( + const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) override + { + if (mode == AzToolsFramework::ViewportEditorMode::Component) + { + m_leftComponentModeFunc(editorModeState); + } + } + + AZStd::function m_enteredComponentModeFunc; ///< Function to call when entering ComponentMode. + AZStd::function m_leftComponentModeFunc; ///< Function to call when leaving ComponentMode. +}; + struct ViewLayoutState { QVector viewPanes; @@ -519,16 +563,17 @@ QtViewPaneManager::QtViewPaneManager(QObject* parent) , m_settings(nullptr) , m_restoreInProgress(false) , m_advancedDockManager(nullptr) + , m_componentModeNotifications(AZStd::make_unique()) { qRegisterMetaTypeStreamOperators("ViewLayoutState"); qRegisterMetaTypeStreamOperators >("QVector"); // view pane manager is interested when we enter/exit ComponentMode - m_componentModeNotifications.BusConnect(AzToolsFramework::GetEntityContextId()); + m_componentModeNotifications->BusConnect(AzToolsFramework::GetEntityContextId()); m_windowRequest.BusConnect(); - m_componentModeNotifications.SetEnteredComponentModeFunc( - [this](const AZStd::vector& /*componentModeTypes*/) + m_componentModeNotifications->SetEnteredComponentModeFunc( + [this](const AzToolsFramework::ViewportEditorModesInterface&) { // gray out panels when entering ComponentMode SetDefaultActionsEnabled(false, m_registeredPanes, [](QWidget* widget, bool on) @@ -537,8 +582,8 @@ QtViewPaneManager::QtViewPaneManager(QObject* parent) }); }); - m_componentModeNotifications.SetLeftComponentModeFunc( - [this](const AZStd::vector& /*componentModeTypes*/) + m_componentModeNotifications->SetLeftComponentModeFunc( + [this](const AzToolsFramework::ViewportEditorModesInterface&) { // enable panels again when leaving ComponentMode SetDefaultActionsEnabled(true, m_registeredPanes, [](QWidget* widget, bool on) @@ -563,7 +608,7 @@ QtViewPaneManager::QtViewPaneManager(QObject* parent) QtViewPaneManager::~QtViewPaneManager() { m_windowRequest.BusDisconnect(); - m_componentModeNotifications.BusDisconnect(); + m_componentModeNotifications->BusDisconnect(); } static bool lessThan(const QtViewPane& v1, const QtViewPane& v2) diff --git a/Code/Editor/QtViewPaneManager.h b/Code/Editor/QtViewPaneManager.h index 3ad1cc9cf7..fe568e5438 100644 --- a/Code/Editor/QtViewPaneManager.h +++ b/Code/Editor/QtViewPaneManager.h @@ -17,7 +17,6 @@ #include #include #include -#include #include #include @@ -34,6 +33,7 @@ #endif class QMainWindow; +class ViewportEditorModeNotificationsBusImpl; struct ViewLayoutState; namespace AzQtComponents @@ -245,9 +245,9 @@ private: QPointer m_advancedDockManager; - using EditorComponentModeNotificationBusImpl = AzToolsFramework::ComponentModeFramework::EditorComponentModeNotificationBusImpl; - EditorComponentModeNotificationBusImpl m_componentModeNotifications; //!< Helper for EditorComponentModeNotificationBus so - //!< QtViewPaneManager does not need to inherit directly from it. */ + AZStd::unique_ptr + m_componentModeNotifications; //!< Helper for EditorComponentModeNotificationBus so + //!< QtViewPaneManager does not need to inherit directly from it. */ using EditorWindowRequestBusImpl = AzToolsFramework::EditorWindowRequestBusImpl; EditorWindowRequestBusImpl m_windowRequest; //!< Helper for EditorWindowRequestBus so diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/API/ComponentModeCollectionInterface.h b/Code/Framework/AzToolsFramework/AzToolsFramework/API/ComponentModeCollectionInterface.h new file mode 100644 index 0000000000..39cd6bd6a3 --- /dev/null +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/API/ComponentModeCollectionInterface.h @@ -0,0 +1,28 @@ +/* + * 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 +#include +#include + +namespace AzToolsFramework +{ + //! The AZ::Interface for component mode collection queries. + class ComponentModeCollectionInterface + { + public: + AZ_RTTI(ComponentModeCollectionInterface, "{DFAA4450-BBCD-47C0-9B91-FEA2DBD9B152}"); + + virtual ~ComponentModeCollectionInterface() = default; + + //! Retrieves the list of all Component types (usually one). + virtual const AZStd::vector& GetComponentTypes() const = 0; + }; +} // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/API/ViewportEditorModeTrackerNotificationBus.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/API/ViewportEditorModeTrackerNotificationBus.cpp new file mode 100644 index 0000000000..278f9db950 --- /dev/null +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/API/ViewportEditorModeTrackerNotificationBus.cpp @@ -0,0 +1,27 @@ +/* + * 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 +#include + +namespace AzToolsFramework +{ + void ViewportEditorModeNotifications::Reflect(AZ::ReflectContext* context) + { + if (AZ::BehaviorContext* behaviorContext = azrtti_cast(context)) + { + behaviorContext->EBus("ViewportEditorModeNotificationsBus") + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation) + ->Attribute(AZ::Script::Attributes::Category, "Editor") + ->Attribute(AZ::Script::Attributes::Module, "editor") + ->Event("OnEditorModeActivated", &ViewportEditorModeNotifications::OnEditorModeActivated) + ->Event("OnEditorModeDeactivated", &ViewportEditorModeNotifications::OnEditorModeDeactivated) + ; + } + } +} // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/API/ViewportEditorModeTrackerNotificationBus.h b/Code/Framework/AzToolsFramework/AzToolsFramework/API/ViewportEditorModeTrackerNotificationBus.h index 4fcb891e61..4fb4191d45 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/API/ViewportEditorModeTrackerNotificationBus.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/API/ViewportEditorModeTrackerNotificationBus.h @@ -34,6 +34,8 @@ namespace AzToolsFramework class ViewportEditorModesInterface { public: + AZ_RTTI(ViewportEditorModesInterface, "{2421496C-4A46-41C9-8AEF-AE2B6E43E6CF}"); + virtual ~ViewportEditorModesInterface() = default; //! Returns true if the specified editor mode is active, otherwise false. @@ -52,6 +54,9 @@ namespace AzToolsFramework using BusIdType = ViewportEditorModeTrackerInfo::IdType; ////////////////////////////////////////////////////////////////////////// + AZ_RTTI(ViewportEditorModeNotifications, "{9469DE39-6C21-423C-94FA-EF3A9616B14F}", AZ::EBusTraits); + static void Reflect(AZ::ReflectContext* context); + //! Notifies subscribers of the a given viewport to the activation of the specified editor mode. virtual void OnEditorModeActivated([[maybe_unused]] const ViewportEditorModesInterface& editorModeState, [[maybe_unused]] ViewportEditorMode mode) { diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ComponentMode/ComponentModeCollection.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ComponentMode/ComponentModeCollection.cpp index df93e924b8..e816c0ce4c 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ComponentMode/ComponentModeCollection.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ComponentMode/ComponentModeCollection.cpp @@ -203,6 +203,11 @@ namespace AzToolsFramework } } + const AZStd::vector& ComponentModeCollection::GetComponentTypes() const + { + return m_activeComponentTypes; + } + void ComponentModeCollection::BeginComponentMode() { m_selectedComponentModeIndex = 0; @@ -211,13 +216,6 @@ namespace AzToolsFramework // notify listeners the editor has entered ComponentMode - listeners may // wish to modify state to indicate this (e.g. appearance, functionality etc.) - EditorComponentModeNotificationBus::Event( - GetEntityContextId(), &EditorComponentModeNotifications::EnteredComponentMode, - m_activeComponentTypes); - - // this call to activate the component mode editor state should eventually replace the bus call in - // ComponentModeCollection::BeginComponentMode() to EditorComponentModeNotifications::EnteredComponentMode - // such that all of the notifications for activating/deactivating the different editor modes are in a central location m_viewportEditorModeTracker->ActivateMode({ GetEntityContextId() }, ViewportEditorMode::Component); // enable actions for the first/primary ComponentMode @@ -288,14 +286,6 @@ namespace AzToolsFramework // notify listeners the editor has left ComponentMode - listeners may // wish to modify state to indicate this (e.g. appearance, functionality etc.) - EditorComponentModeNotificationBus::Event( - GetEntityContextId(), - &EditorComponentModeNotifications::LeftComponentMode, - m_activeComponentTypes); - - // this call to deactivate the component mode editor state should eventually replace the bus call in - // ComponentModeCollection::EndComponentMode() to EditorComponentModeNotifications::LeftComponentMode - // such that all of the notifications for activating/deactivating the different editor modes are in a central location m_viewportEditorModeTracker->DeactivateMode({ GetEntityContextId() }, ViewportEditorMode::Component); // clear stored modes and builders for this ComponentMode diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ComponentMode/ComponentModeCollection.h b/Code/Framework/AzToolsFramework/AzToolsFramework/ComponentMode/ComponentModeCollection.h index 9e299d2323..fb35ca8971 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ComponentMode/ComponentModeCollection.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ComponentMode/ComponentModeCollection.h @@ -9,6 +9,7 @@ #pragma once #include +#include #include #include @@ -21,6 +22,7 @@ namespace AzToolsFramework { /// Manages all individual ComponentModes for a single instance of Editor wide ComponentMode. class ComponentModeCollection + : public ComponentModeCollectionInterface { public: AZ_CLASS_ALLOCATOR_DECL @@ -89,6 +91,9 @@ namespace AzToolsFramework /// Called once each time a ComponentMode is added. void PopulateViewportUi(); + // ComponentModeCollectionInterface overrides ... + const AZStd::vector& GetComponentTypes() const override; + private: // Internal helper used by Select[|Prev|Next]ActiveComponentMode bool ActiveComponentModeChanged(const AZ::Uuid& previousComponentType); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ComponentMode/ComponentModeDelegate.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ComponentMode/ComponentModeDelegate.cpp index 325fc3909b..f0baeaea7e 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ComponentMode/ComponentModeDelegate.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ComponentMode/ComponentModeDelegate.cpp @@ -24,18 +24,8 @@ namespace AzToolsFramework : public EditorComponentModeNotificationBus::Handler , public AZ::BehaviorEBusHandler { - AZ_EBUS_BEHAVIOR_BINDER(EditorComponentModeNotificationBusHandler, "{AD2F4204-0913-4FC9-9A10-492538F60C70}", AZ::SystemAllocator, - EnteredComponentMode, LeftComponentMode, ActiveComponentModeChanged); - - void EnteredComponentMode(const AZStd::vector& componentTypes) override - { - Call(FN_EnteredComponentMode, componentTypes); - } - - void LeftComponentMode(const AZStd::vector& componentTypes) override - { - Call(FN_LeftComponentMode, componentTypes); - } + AZ_EBUS_BEHAVIOR_BINDER( + EditorComponentModeNotificationBusHandler, "{AD2F4204-0913-4FC9-9A10-492538F60C70}", AZ::SystemAllocator, ActiveComponentModeChanged); void ActiveComponentModeChanged(const AZ::Uuid& componentType) override { @@ -171,8 +161,6 @@ namespace AzToolsFramework ->Attribute(AZ::Script::Attributes::Category, "Editor") ->Attribute(AZ::Script::Attributes::Module, "editor") ->Handler() - ->Event("EnteredComponentMode", &EditorComponentModeNotifications::EnteredComponentMode) - ->Event("LeftComponentMode", &EditorComponentModeNotifications::LeftComponentMode) ->Event("ActiveComponentModeChanged", &EditorComponentModeNotifications::ActiveComponentModeChanged) ; } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ComponentMode/EditorComponentModeBus.h b/Code/Framework/AzToolsFramework/AzToolsFramework/ComponentMode/EditorComponentModeBus.h index 5be535e1ed..67a8291e22 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ComponentMode/EditorComponentModeBus.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ComponentMode/EditorComponentModeBus.h @@ -238,12 +238,6 @@ namespace AzToolsFramework using BusIdType = AzFramework::EntityContextId; static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById; - /// Called when Editor enters ComponentMode - pass the list of all Component types (usually one). - virtual void EnteredComponentMode(const AZStd::vector& componentTypes) = 0; - - /// Called when Editor leaves ComponentMode - pass the list of all Component types (usually one). - virtual void LeftComponentMode(const AZStd::vector& componentTypes) = 0; - /// Called when Tab is pressed to cycle the 'selected' ComponentMode (which shortcuts/actions are active). /// Also called when directly selecting a Component in the EntityOutliner. virtual void ActiveComponentModeChanged(const AZ::Uuid& /*componentType*/) {} @@ -255,42 +249,6 @@ namespace AzToolsFramework /// Type to inherit to implement EditorComponentModeNotifications. using EditorComponentModeNotificationBus = AZ::EBus; - /// Helper for EditorComponentModeNotifications to be used - /// as a member instead of inheriting from EBus directly. - class EditorComponentModeNotificationBusImpl - : public EditorComponentModeNotificationBus::Handler - { - public: - /// Set the function to be called when entering ComponentMode. - void SetEnteredComponentModeFunc( - const AZStd::function&)>& enteredComponentModeFunc) - { - m_enteredComponentModeFunc = enteredComponentModeFunc; - } - - /// Set the function to be called when leaving ComponentMode. - void SetLeftComponentModeFunc( - const AZStd::function&)>& leftComponentModeFunc) - { - m_leftComponentModeFunc = leftComponentModeFunc; - } - - private: - // EditorComponentModeNotificationBus - void EnteredComponentMode(const AZStd::vector& componentModeTypes) override - { - m_enteredComponentModeFunc(componentModeTypes); - } - - void LeftComponentMode(const AZStd::vector& componentModeTypes) override - { - m_leftComponentModeFunc(componentModeTypes); - } - - AZStd::function&)> m_enteredComponentModeFunc; ///< Function to call when entering ComponentMode. - AZStd::function&)> m_leftComponentModeFunc; ///< Function to call when leaving ComponentMode. - }; - /// Helper to answer if the Editor is in ComponentMode or not. inline bool InComponentMode() { diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerWidget.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerWidget.cpp index 689e5b5dc4..347057d9ba 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerWidget.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerWidget.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -291,8 +292,7 @@ namespace AzToolsFramework EntityOutlinerModelNotificationBus::Handler::BusConnect(); ToolsApplicationEvents::Bus::Handler::BusConnect(); EditorEntityContextNotificationBus::Handler::BusConnect(); - ComponentModeFramework::EditorComponentModeNotificationBus::Handler::BusConnect( - GetEntityContextId()); + ViewportEditorModeNotificationsBus::Handler::BusConnect(GetEntityContextId()); EditorEntityInfoNotificationBus::Handler::BusConnect(); Prefab::PrefabPublicNotificationBus::Handler::BusConnect(); EditorWindowUIRequestBus::Handler::BusConnect(); @@ -302,7 +302,7 @@ namespace AzToolsFramework { EditorWindowUIRequestBus::Handler::BusDisconnect(); Prefab::PrefabPublicNotificationBus::Handler::BusDisconnect(); - ComponentModeFramework::EditorComponentModeNotificationBus::Handler::BusDisconnect(); + ViewportEditorModeNotificationsBus::Handler::BusDisconnect(); EditorEntityInfoNotificationBus::Handler::BusDisconnect(); EditorPickModeNotificationBus::Handler::BusDisconnect(); EntityHighlightMessages::Bus::Handler::BusDisconnect(); @@ -1123,14 +1123,22 @@ namespace AzToolsFramework EnableUi(enable); } - void EntityOutlinerWidget::EnteredComponentMode([[maybe_unused]] const AZStd::vector& componentModeTypes) + void EntityOutlinerWidget::OnEditorModeActivated( + [[maybe_unused]] const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) { - EnableUi(false); + if (mode == ViewportEditorMode::Component) + { + EnableUi(false); + } } - void EntityOutlinerWidget::LeftComponentMode([[maybe_unused]] const AZStd::vector& componentModeTypes) + void EntityOutlinerWidget::OnEditorModeDeactivated( + [[maybe_unused]] const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) { - EnableUi(true); + if (mode == ViewportEditorMode::Component) + { + EnableUi(true); + } } void EntityOutlinerWidget::OnPrefabInstancePropagationBegin() diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerWidget.hxx b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerWidget.hxx index 78aced3587..dcf23b19c0 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerWidget.hxx +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Outliner/EntityOutlinerWidget.hxx @@ -14,7 +14,7 @@ #include #include -#include +#include #include #include #include @@ -58,7 +58,7 @@ namespace AzToolsFramework , private ToolsApplicationEvents::Bus::Handler , private EditorEntityContextNotificationBus::Handler , private EditorEntityInfoNotificationBus::Handler - , private ComponentModeFramework::EditorComponentModeNotificationBus::Handler + , private ViewportEditorModeNotificationsBus::Handler , private Prefab::PrefabPublicNotificationBus::Handler , private EditorWindowUIRequestBus::Handler { @@ -100,9 +100,11 @@ namespace AzToolsFramework void OnEntityInfoUpdatedAddChildEnd(AZ::EntityId /*parentId*/, AZ::EntityId /*childId*/) override; void OnEntityInfoUpdatedName(AZ::EntityId entityId, const AZStd::string& /*name*/) override; - // EditorComponentModeNotificationBus - void EnteredComponentMode(const AZStd::vector& componentModeTypes) override; - void LeftComponentMode(const AZStd::vector& componentModeTypes) override; + // ViewportEditorModeNotificationsBus overrides ... + void OnEditorModeActivated( + const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) override; + void OnEditorModeDeactivated( + const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) override; // PrefabPublicNotificationBus void OnPrefabInstancePropagationBegin() override; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/ComponentEditor.hxx b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/ComponentEditor.hxx index b2140868da..f450ec7ac9 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/ComponentEditor.hxx +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/ComponentEditor.hxx @@ -90,7 +90,6 @@ namespace AzToolsFramework void SetComponentOverridden(const bool overridden); - // Calls match EditorComponentModeNotificationBus - called from EntityPropertyEditor void EnteredComponentMode(const AZStd::vector& componentModeTypes); void LeftComponentMode(const AZStd::vector& componentModeTypes); void ActiveComponentModeChanged(const AZ::Uuid& componentType); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp index 87527502dd..ad62614770 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.cpp @@ -33,6 +33,7 @@ AZ_POP_DISABLE_WARNING #include #include #include +#include #include #include #include @@ -486,8 +487,12 @@ namespace AzToolsFramework , m_isSystemEntityEditor(false) , m_isLevelEntityEditor(isLevelEntityEditor) { + initEntityPropertyEditorResources(); + m_componentModeCollection = AZ::Interface::Get(); + AZ_Assert(m_componentModeCollection, "Could not retrieve component mode collection."); + m_prefabPublicInterface = AZ::Interface::Get(); AZ_Assert(m_prefabPublicInterface != nullptr, "EntityPropertyEditor requires a PrefabPublicInterface instance on Initialize."); @@ -5698,39 +5703,49 @@ namespace AzToolsFramework SaveComponentEditorState(); } - void EntityPropertyEditor::EnteredComponentMode(const AZStd::vector& componentModeTypes) + void EntityPropertyEditor::OnEditorModeActivated( + [[maybe_unused]] const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) { - DisableComponentActions(this, m_entityComponentActions); - SetPropertyEditorState(m_gui, false); - m_disabled = true; - - if (!componentModeTypes.empty()) + if (mode == AzToolsFramework::ViewportEditorMode::Component) { - m_componentEditorLastSelectedIndex = GetComponentEditorIndexFromType(componentModeTypes.front()); - } + DisableComponentActions(this, m_entityComponentActions); + SetPropertyEditorState(m_gui, false); + const auto& componentModeTypes = m_componentModeCollection->GetComponentTypes(); + m_disabled = true; + + if (!componentModeTypes.empty()) + { + m_componentEditorLastSelectedIndex = GetComponentEditorIndexFromType(componentModeTypes.front()); + } - for (auto componentEditor : m_componentEditors) - { - componentEditor->EnteredComponentMode(componentModeTypes); - } + for (auto componentEditor : m_componentEditors) + { + componentEditor->EnteredComponentMode(componentModeTypes); + } - // record the selected state after entering component mode - SaveComponentEditorState(); + // record the selected state after entering component mode + SaveComponentEditorState(); + } } - void EntityPropertyEditor::LeftComponentMode(const AZStd::vector& componentModeTypes) + void EntityPropertyEditor::OnEditorModeDeactivated( + [[maybe_unused]] const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) { - EnableComponentActions(this, m_entityComponentActions); - SetPropertyEditorState(m_gui, true); - m_disabled = false; - - for (auto componentEditor : m_componentEditors) + if (mode == AzToolsFramework::ViewportEditorMode::Component) { - componentEditor->LeftComponentMode(componentModeTypes); - } + EnableComponentActions(this, m_entityComponentActions); + SetPropertyEditorState(m_gui, true); + const auto& componentModeTypes = m_componentModeCollection->GetComponentTypes(); + m_disabled = false; - // record the selected state after leaving component mode - SaveComponentEditorState(); + for (auto componentEditor : m_componentEditors) + { + componentEditor->LeftComponentMode(componentModeTypes); + } + + // record the selected state after leaving component mode + SaveComponentEditorState(); + } } void EntityPropertyEditor::ActiveComponentModeChanged(const AZ::Uuid& componentType) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.hxx b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.hxx index 83b275b81a..5279cefa9f 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.hxx +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/EntityPropertyEditor.hxx @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -59,6 +60,7 @@ namespace AzToolsFramework { class ComponentEditor; class ComponentPaletteWidget; + class ComponentModeCollectionInterface; struct SourceControlFileInfo; namespace AssetBrowser @@ -108,6 +110,7 @@ namespace AzToolsFramework , public AzToolsFramework::EditorEntityContextNotificationBus::Handler , public AzToolsFramework::EntityPropertyEditorRequestBus::Handler , public AzToolsFramework::PropertyEditorEntityChangeNotificationBus::MultiHandler + , private AzToolsFramework::ViewportEditorModeNotificationsBus::Handler , public EditorInspectorComponentNotificationBus::MultiHandler , private AzToolsFramework::ComponentModeFramework::EditorComponentModeNotificationBus::Handler , public AZ::EntitySystemBus::Handler @@ -231,10 +234,14 @@ namespace AzToolsFramework ////////////////////////////////////////////////////////////////////////// // EditorComponentModeNotificationBus - void EnteredComponentMode(const AZStd::vector& componentModeTypes) override; - void LeftComponentMode(const AZStd::vector& componentModeTypes) override; void ActiveComponentModeChanged(const AZ::Uuid& componentType) override; + // ViewportEditorModeNotificationsBus overrides ... + void OnEditorModeActivated( + const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) override; + void OnEditorModeDeactivated( + const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) override; + // EntityPropertEditorRequestBus void GetSelectedAndPinnedEntities(EntityIdList& selectedEntityIds) override; void GetSelectedEntities(EntityIdList& selectedEntityIds) override; @@ -627,6 +634,8 @@ namespace AzToolsFramework float m_moveFadeSecondsRemaining; AZStd::vector m_indexMapOfMovedRow; + AzToolsFramework::ComponentModeCollectionInterface* m_componentModeCollection = nullptr; + // When m_initiatingPropertyChangeNotification is set to true, it means this EntityPropertyEditor is // broadcasting a change to all listeners about a property change for a given entity. This is needed // so that we don't update the values twice for this inspector diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.cpp index 8d30359562..a0d02f47e7 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.cpp @@ -129,7 +129,7 @@ namespace UnitTest using AzToolsFramework::ComponentModeFramework::EditorComponentModeNotificationBus; AzToolsFramework::EditorActionRequestBus::Handler::BusConnect(); - EditorComponentModeNotificationBus::Handler::BusConnect(GetEntityContextId()); + ViewportEditorModeNotificationsBus::Handler::BusConnect(GetEntityContextId()); m_defaultWidget.setFocus(); } @@ -137,18 +137,26 @@ namespace UnitTest { using AzToolsFramework::ComponentModeFramework::EditorComponentModeNotificationBus; - EditorComponentModeNotificationBus::Handler::BusDisconnect(); + ViewportEditorModeNotificationsBus::Handler::BusDisconnect(); AzToolsFramework::EditorActionRequestBus::Handler::BusDisconnect(); } - void TestEditorActions::EnteredComponentMode([[maybe_unused]] const AZStd::vector& componentTypes) + void TestEditorActions::OnEditorModeActivated( + [[maybe_unused]] const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) { - m_componentModeWidget.setFocus(); + if (mode == ViewportEditorMode::Component) + { + m_componentModeWidget.setFocus(); + } } - void TestEditorActions::LeftComponentMode([[maybe_unused]] const AZStd::vector& componentTypes) + void TestEditorActions::OnEditorModeDeactivated( + [[maybe_unused]] const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) { - m_defaultWidget.setFocus(); + if (mode == ViewportEditorMode::Component) + { + m_defaultWidget.setFocus(); + } } void TestEditorActions::AddActionViaBus(int id, QAction* action) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.h b/Code/Framework/AzToolsFramework/AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.h index c4aefecce5..4a7039423c 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.h @@ -23,9 +23,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -103,7 +103,7 @@ namespace UnitTest /// component mode editing. class TestEditorActions : private AzToolsFramework::EditorActionRequestBus::Handler - , private AzToolsFramework::ComponentModeFramework::EditorComponentModeNotificationBus::Handler + , private AzToolsFramework::ViewportEditorModeNotificationsBus::Handler { // EditorActionRequestBus ... void AddActionViaBus(int id, QAction* action) override; @@ -114,9 +114,11 @@ namespace UnitTest void AttachOverride(QWidget* /*object*/) override {} void DetachOverride() override {} - // EditorComponentModeNotificationBus ... - void EnteredComponentMode(const AZStd::vector& componentTypes) override; - void LeftComponentMode(const AZStd::vector& componentTypes) override; + // ViewportEditorModeNotificationsBus overrides ... + void OnEditorModeActivated( + const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) override; + void OnEditorModeDeactivated( + const AzToolsFramework::ViewportEditorModesInterface& editorModeState, AzToolsFramework::ViewportEditorMode mode) override; public: void Connect(); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorDefaultSelection.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorDefaultSelection.cpp index 1ad0ee8ff3..fafa1b3198 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorDefaultSelection.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorDefaultSelection.cpp @@ -27,6 +27,10 @@ namespace AzToolsFramework , m_viewportEditorModeTracker(viewportEditorModeTracker) , m_componentModeCollection(viewportEditorModeTracker) { + AZ_Assert( + AZ::Interface::Get() == nullptr, "Unexpected registration of component mode collection.") + AZ::Interface::Register(&m_componentModeCollection); + ActionOverrideRequestBus::Handler::BusConnect(GetEntityContextId()); ComponentModeFramework::ComponentModeSystemRequestBus::Handler::BusConnect(); @@ -40,6 +44,11 @@ namespace AzToolsFramework ComponentModeFramework::ComponentModeSystemRequestBus::Handler::BusDisconnect(); ActionOverrideRequestBus::Handler::BusDisconnect(); m_viewportEditorModeTracker->DeactivateMode({ GetEntityContextId() }, ViewportEditorMode::Default); + + AZ_Assert( + AZ::Interface::Get() != nullptr, + "Unexpected unregistration of component mode collection.") + AZ::Interface::Unregister(&m_componentModeCollection); } void EditorDefaultSelection::SetOverridePhantomWidget(QWidget* phantomOverrideWidget) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.cpp index ccb72e1d50..4c1fefc622 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.cpp @@ -1027,7 +1027,7 @@ namespace AzToolsFramework EditorTransformComponentSelectionRequestBus::Handler::BusConnect(entityContextId); ToolsApplicationNotificationBus::Handler::BusConnect(); Camera::EditorCameraNotificationBus::Handler::BusConnect(); - ComponentModeFramework::EditorComponentModeNotificationBus::Handler::BusConnect(entityContextId); + ViewportEditorModeNotificationsBus::Handler::BusConnect(entityContextId); EditorEntityContextNotificationBus::Handler::BusConnect(); EditorEntityVisibilityNotificationBus::Router::BusRouterConnect(); EditorEntityLockComponentNotificationBus::Router::BusRouterConnect(); @@ -1075,7 +1075,7 @@ namespace AzToolsFramework EditorEntityLockComponentNotificationBus::Router::BusRouterDisconnect(); EditorEntityVisibilityNotificationBus::Router::BusRouterDisconnect(); EditorEntityContextNotificationBus::Handler::BusDisconnect(); - ComponentModeFramework::EditorComponentModeNotificationBus::Handler::BusDisconnect(); + ViewportEditorModeNotificationsBus::Handler::BusDisconnect(); Camera::EditorCameraNotificationBus::Handler::BusDisconnect(); ToolsApplicationNotificationBus::Handler::BusDisconnect(); EditorTransformComponentSelectionRequestBus::Handler::BusDisconnect(); @@ -3707,22 +3707,30 @@ namespace AzToolsFramework m_selectedEntityIdsAndManipulatorsDirty = true; } - void EditorTransformComponentSelection::EnteredComponentMode([[maybe_unused]] const AZStd::vector& componentModeTypes) + void EditorTransformComponentSelection::OnEditorModeActivated( + [[maybe_unused]] const ViewportEditorModesInterface& editorModeState, ViewportEditorMode mode) { - SetAllViewportUiVisible(false); + if (mode == ViewportEditorMode::Component) + { + SetAllViewportUiVisible(false); - EditorEntityLockComponentNotificationBus::Router::BusRouterDisconnect(); - EditorEntityVisibilityNotificationBus::Router::BusRouterDisconnect(); - ToolsApplicationNotificationBus::Handler::BusDisconnect(); + EditorEntityLockComponentNotificationBus::Router::BusRouterDisconnect(); + EditorEntityVisibilityNotificationBus::Router::BusRouterDisconnect(); + ToolsApplicationNotificationBus::Handler::BusDisconnect(); + } } - void EditorTransformComponentSelection::LeftComponentMode([[maybe_unused]] const AZStd::vector& componentModeTypes) + void EditorTransformComponentSelection::OnEditorModeDeactivated( + [[maybe_unused]] const ViewportEditorModesInterface& editorModeState, ViewportEditorMode mode) { - SetAllViewportUiVisible(true); + if (mode == ViewportEditorMode::Component) + { + SetAllViewportUiVisible(true); - ToolsApplicationNotificationBus::Handler::BusConnect(); - EditorEntityVisibilityNotificationBus::Router::BusRouterConnect(); - EditorEntityLockComponentNotificationBus::Router::BusRouterConnect(); + ToolsApplicationNotificationBus::Handler::BusConnect(); + EditorEntityVisibilityNotificationBus::Router::BusRouterConnect(); + EditorEntityLockComponentNotificationBus::Router::BusRouterConnect(); + } } void EditorTransformComponentSelection::CreateEntityManipulatorDeselectCommand(ScopedUndoBatch& undoBatch) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.h b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.h index a0e87d9d6f..1e1cc6d2e1 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.h @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include @@ -153,7 +153,7 @@ namespace AzToolsFramework , private EditorTransformComponentSelectionRequestBus::Handler , private ToolsApplicationNotificationBus::Handler , private Camera::EditorCameraNotificationBus::Handler - , private ComponentModeFramework::EditorComponentModeNotificationBus::Handler + , private ViewportEditorModeNotificationsBus::Handler , private EditorEntityContextNotificationBus::Handler , private EditorEntityVisibilityNotificationBus::Router , private EditorEntityLockComponentNotificationBus::Router @@ -286,9 +286,9 @@ namespace AzToolsFramework // EditorContextLockComponentNotificationBus overrides ... void OnEntityLockChanged(bool locked) override; - // EditorComponentModeNotificationBus overrides ... - void EnteredComponentMode(const AZStd::vector& componentModeTypes) override; - void LeftComponentMode(const AZStd::vector& componentModeTypes) override; + // ViewportEditorModeNotificationsBus overrides ... + void OnEditorModeActivated(const ViewportEditorModesInterface& editorModeState, ViewportEditorMode mode) override; + void OnEditorModeDeactivated(const ViewportEditorModesInterface& editorModeState, ViewportEditorMode mode) override; // EditorEntityContextNotificationBus overrides ... void OnStartPlayInEditor() override; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/aztoolsframework_files.cmake b/Code/Framework/AzToolsFramework/AzToolsFramework/aztoolsframework_files.cmake index f09d4f9b72..74c5db3f5e 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/aztoolsframework_files.cmake +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/aztoolsframework_files.cmake @@ -30,12 +30,14 @@ set(FILES API/AssetDatabaseBus.h API/ComponentEntityObjectBus.h API/ComponentEntitySelectionBus.h + API/ComponentModeCollectionInterface.h API/EditorCameraBus.h API/EditorCameraBus.cpp API/EditorAnimationSystemRequestBus.h API/EditorEntityAPI.h API/EditorLevelNotificationBus.h API/ViewportEditorModeTrackerNotificationBus.h + API/ViewportEditorModeTrackerNotificationBus.cpp API/EditorVegetationRequestsBus.h API/EditorPythonConsoleBus.h API/EditorPythonRunnerRequestsBus.h