From 2e7c8a0fd2093eab3b6de9f607e0d6a175a56e47 Mon Sep 17 00:00:00 2001 From: John Date: Wed, 13 Oct 2021 18:49:49 +0100 Subject: [PATCH] Double click entity in prefab to enter FocusMode. Signed-off-by: John --- .../ViewportSelection/EditorHelpers.cpp | 37 +++++++++++++++++-- .../ViewportSelection/EditorHelpers.h | 20 +++++++++- .../EditorPickEntitySelection.cpp | 2 +- .../EditorTransformComponentSelection.cpp | 33 ++++++++++++----- 4 files changed, 76 insertions(+), 16 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorHelpers.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorHelpers.cpp index 3ce350287f..0311cdbd54 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorHelpers.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorHelpers.cpp @@ -114,6 +114,34 @@ namespace AzToolsFramework } } + EntityIdUnderCursor::EntityIdUnderCursor(AZ::EntityId entityId) + : m_entityId(entityId) + , m_rootEntityId(entityId) + { + } + + EntityIdUnderCursor::EntityIdUnderCursor(AZ::EntityId entityId, AZ::EntityId rootEntityId) + : m_entityId(entityId) + , m_rootEntityId(rootEntityId) + { + } + + AZ::EntityId EntityIdUnderCursor::GetEntityId() const + { + return m_entityId; + } + + AZ::EntityId EntityIdUnderCursor::GetRootEntityId() const + { + return m_rootEntityId; + } + + bool EntityIdUnderCursor::IsChildEntity() const + { + return m_entityId != m_rootEntityId; + } + + EditorHelpers::EditorHelpers(const EditorVisibleEntityDataCache* entityDataCache) : m_entityDataCache(entityDataCache) { @@ -125,7 +153,7 @@ namespace AzToolsFramework "Check that it is being correctly initialized."); } - AZ::EntityId EditorHelpers::HandleMouseInteraction( + EntityIdUnderCursor EditorHelpers::GetEntityIdUnderCursor( const AzFramework::CameraState& cameraState, const ViewportInteraction::MouseInteractionEvent& mouseInteraction) { AZ_PROFILE_FUNCTION(AzToolsFramework); @@ -189,7 +217,7 @@ namespace AzToolsFramework // Verify if the entity Id corresponds to an entity that is focused; if not, halt selection. if (!m_focusModeInterface->IsInFocusSubTree(entityIdUnderCursor)) { - return AZ::EntityId(); + return EntityIdUnderCursor(AZ::EntityId()); } // Container Entity support - if the entity that is being selected is part of a closed container, @@ -197,10 +225,11 @@ namespace AzToolsFramework ContainerEntityInterface* containerEntityInterface = AZ::Interface::Get(); if (containerEntityInterface) { - return containerEntityInterface->FindHighestSelectableEntity(entityIdUnderCursor); + const auto highestSelectableEntity = containerEntityInterface->FindHighestSelectableEntity(entityIdUnderCursor); + return EntityIdUnderCursor(entityIdUnderCursor, highestSelectableEntity); } - return entityIdUnderCursor; + return EntityIdUnderCursor(entityIdUnderCursor); } void EditorHelpers::DisplayHelpers( diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorHelpers.h b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorHelpers.h index a6a78a4e61..b9fc27971b 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorHelpers.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorHelpers.h @@ -29,6 +29,22 @@ namespace AzToolsFramework struct MouseInteractionEvent; } + //!< Represents the result of a query to find the id of the entity under the cursor (if any). + class EntityIdUnderCursor + { + public: + EntityIdUnderCursor(AZ::EntityId entityId); + EntityIdUnderCursor(AZ::EntityId entityId, AZ::EntityId rootEntityId); + + AZ::EntityId GetEntityId() const; + AZ::EntityId GetRootEntityId() const; + bool IsChildEntity() const; + + private: + AZ::EntityId m_entityId; //HandleMouseInteraction(cameraState, mouseInteraction); + m_cachedEntityIdUnderCursor = m_editorHelpers->GetEntityIdUnderCursor(cameraState, mouseInteraction).GetRootEntityId(); // when left clicking, if we successfully clicked an entity, assign that // to the entity field selected in the entity inspector (RPE) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.cpp index 7015a25ce1..a9e0d70a5b 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -1799,7 +1800,8 @@ namespace AzToolsFramework const AzFramework::ViewportId viewportId = mouseInteraction.m_mouseInteraction.m_interactionId.m_viewportId; const AzFramework::CameraState cameraState = GetCameraState(viewportId); - m_cachedEntityIdUnderCursor = m_editorHelpers->HandleMouseInteraction(cameraState, mouseInteraction); + const auto entityIdsUnderCursor = m_editorHelpers->GetEntityIdUnderCursor(cameraState, mouseInteraction); + m_cachedEntityIdUnderCursor = entityIdsUnderCursor.GetRootEntityId(); const auto selectClickEvent = ClickDetectorEventFromViewportInteraction(mouseInteraction); m_cursorState.SetCurrentPosition(mouseInteraction.m_mouseInteraction.m_mousePick.m_screenCoordinates); @@ -1825,8 +1827,6 @@ namespace AzToolsFramework } } - const AZ::EntityId entityIdUnderCursor = m_cachedEntityIdUnderCursor; - EditorContextMenuUpdate(m_contextMenu, mouseInteraction); m_boxSelect.HandleMouseInteraction(mouseInteraction); @@ -1842,6 +1842,21 @@ namespace AzToolsFramework return true; } + if (mouseInteraction.m_mouseEvent == ViewportInteraction::MouseEvent::DoubleClick && + mouseInteraction.m_mouseInteraction.m_mouseButtons.Left()) + { + if (entityIdsUnderCursor.IsChildEntity()) + { + auto prefabFocusInterface = AZ::Interface::Get(); + if (prefabFocusInterface) + { + // Focus on this prefab + prefabFocusInterface->FocusOnOwningPrefab(entityIdsUnderCursor.GetRootEntityId()); + return false; + } + } + } + bool stickySelect = false; ViewportInteraction::ViewportSettingsRequestBus::EventResult( stickySelect, viewportId, &ViewportInteraction::ViewportSettingsRequestBus::Events::StickySelectEnabled); @@ -1863,7 +1878,7 @@ namespace AzToolsFramework // select/deselect (add/remove) entities with ctrl held if (Input::AdditiveIndividualSelect(clickOutcome, mouseInteraction)) { - if (SelectDeselect(entityIdUnderCursor)) + if (SelectDeselect(m_cachedEntityIdUnderCursor)) { if (m_selectedEntityIds.empty()) { @@ -1877,13 +1892,13 @@ namespace AzToolsFramework if (!m_selectedEntityIds.empty()) { // group copying/alignment to specific entity - 'ditto' position/orientation for group - if (Input::GroupDitto(mouseInteraction) && PerformGroupDitto(entityIdUnderCursor)) + if (Input::GroupDitto(mouseInteraction) && PerformGroupDitto(m_cachedEntityIdUnderCursor)) { return false; } // individual copying/alignment to specific entity - 'ditto' position/orientation for individual - if (Input::IndividualDitto(mouseInteraction) && PerformIndividualDitto(entityIdUnderCursor)) + if (Input::IndividualDitto(mouseInteraction) && PerformIndividualDitto(m_cachedEntityIdUnderCursor)) { return false; } @@ -1898,7 +1913,7 @@ namespace AzToolsFramework // set manipulator pivot override translation or orientation (update manipulators) if (Input::ManipulatorDitto(clickOutcome, mouseInteraction)) { - PerformManipulatorDitto(entityIdUnderCursor); + PerformManipulatorDitto(m_cachedEntityIdUnderCursor); return false; } @@ -1913,11 +1928,11 @@ namespace AzToolsFramework { if (!stickySelect) { - ChangeSelectedEntity(entityIdUnderCursor); + ChangeSelectedEntity(m_cachedEntityIdUnderCursor); } else { - SelectDeselect(entityIdUnderCursor); + SelectDeselect(m_cachedEntityIdUnderCursor); } }