diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/FocusMode/FocusModeSystemComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/FocusMode/FocusModeSystemComponent.cpp index 19bde5f3a8..e45b817bd5 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/FocusMode/FocusModeSystemComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/FocusMode/FocusModeSystemComponent.cpp @@ -71,8 +71,7 @@ namespace AzToolsFramework return; } - if (auto tracker = AZ::Interface::Get(); - tracker != nullptr) + if (auto tracker = AZ::Interface::Get()) { if (!m_focusRoot.IsValid() && entityId.IsValid()) { diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorHelpers.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorHelpers.cpp index c67352d02f..f193aa669c 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorHelpers.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorHelpers.cpp @@ -114,36 +114,30 @@ namespace AzToolsFramework } } - EntityIdUnderCursor::EntityIdUnderCursor(AZ::EntityId entityId) + CursorEntityIdQuery::CursorEntityIdQuery(AZ::EntityId entityId, AZ::EntityId rootEntityId) : m_entityId(entityId) - , m_rootEntityId(entityId) + , m_containerAncestorEntityId(rootEntityId) { } - EntityIdUnderCursor::EntityIdUnderCursor(AZ::EntityId entityId, AZ::EntityId rootEntityId) - : m_entityId(entityId) - , m_rootEntityId(rootEntityId) - { - } - - AZ::EntityId EntityIdUnderCursor::GetEntityId() const + AZ::EntityId CursorEntityIdQuery::EntityIdUnderCursor() const { return m_entityId; } - AZ::EntityId EntityIdUnderCursor::GetRootEntityId() const + AZ::EntityId CursorEntityIdQuery::ContainerAncestorEntityId() const { - return m_rootEntityId; + return m_containerAncestorEntityId; } - bool EntityIdUnderCursor::IsPrefabEntity() const + bool CursorEntityIdQuery::HasContainerAncestorEntityId() const { - if (m_entityId == AZ::EntityId()) + if (m_entityId.IsValid()) { - return false; + return m_entityId != m_containerAncestorEntityId; } - return m_entityId != m_rootEntityId; + return false; } @@ -158,7 +152,7 @@ namespace AzToolsFramework "Check that it is being correctly initialized."); } - EntityIdUnderCursor EditorHelpers::GetEntityIdUnderCursor( + CursorEntityIdQuery EditorHelpers::FindEntityIdUnderCursor( const AzFramework::CameraState& cameraState, const ViewportInteraction::MouseInteractionEvent& mouseInteraction) { AZ_PROFILE_FUNCTION(AzToolsFramework); @@ -222,7 +216,7 @@ namespace AzToolsFramework // Verify if the entity Id corresponds to an entity that is focused; if not, halt selection. if (!IsSelectableAccordingToFocusMode(entityIdUnderCursor)) { - return EntityIdUnderCursor(AZ::EntityId()); + return CursorEntityIdQuery(AZ::EntityId(), AZ::EntityId()); } // Container Entity support - if the entity that is being selected is part of a closed container, @@ -230,10 +224,10 @@ namespace AzToolsFramework if (ContainerEntityInterface* containerEntityInterface = AZ::Interface::Get()) { const auto highestSelectableEntity = containerEntityInterface->FindHighestSelectableEntity(entityIdUnderCursor); - return EntityIdUnderCursor(entityIdUnderCursor, highestSelectableEntity); + return CursorEntityIdQuery(entityIdUnderCursor, highestSelectableEntity); } - return EntityIdUnderCursor(entityIdUnderCursor); + return CursorEntityIdQuery(entityIdUnderCursor, AZ::EntityId()); } void EditorHelpers::DisplayHelpers( diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorHelpers.h b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorHelpers.h index 43282180db..c399847c0b 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorHelpers.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorHelpers.h @@ -30,27 +30,25 @@ namespace AzToolsFramework } //!< Represents the result of a query to find the id of the entity under the cursor (if any). - class EntityIdUnderCursor + class CursorEntityIdQuery { public: - EntityIdUnderCursor(AZ::EntityId entityId); - EntityIdUnderCursor(AZ::EntityId entityId, AZ::EntityId rootEntityId); + CursorEntityIdQuery(AZ::EntityId entityId, AZ::EntityId rootEntityId); //! Returns the entity id under the cursor (if any). //! @note In the case of no entity id under the cursor, an invalid entity id is returned. - AZ::EntityId GetEntityId() const; + AZ::EntityId EntityIdUnderCursor() const; - //! Returns the root entity id if the entity id under the cursor is part of a prefab, otherwise returns the entity id. + //! Returns the topmost container entity id in the hierarchy if the entity id under the cursor is inside a container entity, otherwise returns the entity id. //! @note In the case of no entity id under the cursor, an invalid entity id is returned. - AZ::EntityId GetRootEntityId() const; + AZ::EntityId ContainerAncestorEntityId() const; - //! Returns true if the entity id under the cursor is part of a prefab, otherwise false. - //! @note In the case of no entity id under the cursor, false is returned. - bool IsPrefabEntity() const; + //! Returns true if the query has a container ancestor entity id, otherwise false. + bool HasContainerAncestorEntityId() const; private: AZ::EntityId m_entityId; //GetEntityIdUnderCursor(cameraState, mouseInteraction).GetRootEntityId(); + m_cachedEntityIdUnderCursor = m_editorHelpers->FindEntityIdUnderCursor(cameraState, mouseInteraction).ContainerAncestorEntityId(); // 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 b2b8d9733e..e970745d0c 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportSelection/EditorTransformComponentSelection.cpp @@ -1800,8 +1800,8 @@ namespace AzToolsFramework const AzFramework::ViewportId viewportId = mouseInteraction.m_mouseInteraction.m_interactionId.m_viewportId; const AzFramework::CameraState cameraState = GetCameraState(viewportId); - const auto entityIdsUnderCursor = m_editorHelpers->GetEntityIdUnderCursor(cameraState, mouseInteraction); - m_cachedEntityIdUnderCursor = entityIdsUnderCursor.GetRootEntityId(); + const auto cursorEntityIdQuery = m_editorHelpers->FindEntityIdUnderCursor(cameraState, mouseInteraction); + m_cachedEntityIdUnderCursor = cursorEntityIdQuery.ContainerAncestorEntityId(); const auto selectClickEvent = ClickDetectorEventFromViewportInteraction(mouseInteraction); m_cursorState.SetCurrentPosition(mouseInteraction.m_mouseInteraction.m_mousePick.m_screenCoordinates); @@ -1842,16 +1842,16 @@ namespace AzToolsFramework return true; } + const AZ::EntityId entityIdUnderCursor = m_cachedEntityIdUnderCursor; + if (mouseInteraction.m_mouseEvent == ViewportInteraction::MouseEvent::DoubleClick && mouseInteraction.m_mouseInteraction.m_mouseButtons.Left()) { - if (entityIdsUnderCursor.IsPrefabEntity()) + if (cursorEntityIdQuery.HasContainerAncestorEntityId()) { - auto prefabFocusInterface = AZ::Interface::Get(); - if (prefabFocusInterface) + if (auto prefabFocusInterface = AZ::Interface::Get()) { - // Focus on this prefab - prefabFocusInterface->FocusOnOwningPrefab(entityIdsUnderCursor.GetRootEntityId()); + prefabFocusInterface->FocusOnOwningPrefab(cursorEntityIdQuery.ContainerAncestorEntityId()); return false; } } @@ -1878,7 +1878,7 @@ namespace AzToolsFramework // select/deselect (add/remove) entities with ctrl held if (Input::AdditiveIndividualSelect(clickOutcome, mouseInteraction)) { - if (SelectDeselect(m_cachedEntityIdUnderCursor)) + if (SelectDeselect(entityIdUnderCursor)) { if (m_selectedEntityIds.empty()) { @@ -1892,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(m_cachedEntityIdUnderCursor)) + if (Input::GroupDitto(mouseInteraction) && PerformGroupDitto(entityIdUnderCursor)) { return false; } // individual copying/alignment to specific entity - 'ditto' position/orientation for individual - if (Input::IndividualDitto(mouseInteraction) && PerformIndividualDitto(m_cachedEntityIdUnderCursor)) + if (Input::IndividualDitto(mouseInteraction) && PerformIndividualDitto(entityIdUnderCursor)) { return false; } @@ -1913,7 +1913,7 @@ namespace AzToolsFramework // set manipulator pivot override translation or orientation (update manipulators) if (Input::ManipulatorDitto(clickOutcome, mouseInteraction)) { - PerformManipulatorDitto(m_cachedEntityIdUnderCursor); + PerformManipulatorDitto(entityIdUnderCursor); return false; } @@ -1928,11 +1928,11 @@ namespace AzToolsFramework { if (!stickySelect) { - ChangeSelectedEntity(m_cachedEntityIdUnderCursor); + ChangeSelectedEntity(entityIdUnderCursor); } else { - SelectDeselect(m_cachedEntityIdUnderCursor); + SelectDeselect(entityIdUnderCursor); } }