d065eb9498
* wip fixes for entity viewport icons displaying in the correct order and handling selection correctly Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * add additional comment about z value Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * move manual sorting and some small tidy-up Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * update comment Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * updates following initial round of PR feedback Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * additional changes to support tests for entity icon intersection Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * add support to enable/disable icons separately from helpers Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * final tests added and small tidy-up to display EntityId correctly Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * update some manipulator test framework calls after utility functions were moved Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * fix for implicit cast Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * move icon scale values to AZ_CVARS Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * fix failing tests caught in AR and update some naming conventions for tests Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * update naming convention for members of ProjectedViewportRay Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * update other references to ProjectedViewportRay Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * update more references to ProjectedViewportRay change Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * update menus for python tests Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com>
117 lines
4.7 KiB
C++
117 lines
4.7 KiB
C++
/*
|
|
* 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 <Tests/FocusMode/EditorFocusModeFixture.h>
|
|
|
|
#include <AzToolsFramework/Entity/EditorEntityHelpers.h>
|
|
|
|
#include <Tests/BoundsTestComponent.h>
|
|
|
|
namespace UnitTest
|
|
{
|
|
void ClearSelectedEntities()
|
|
{
|
|
AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
|
|
&AzToolsFramework::ToolsApplicationRequestBus::Events::SetSelectedEntities, AzToolsFramework::EntityIdList());
|
|
}
|
|
|
|
AzToolsFramework::EntityIdList EditorFocusModeFixture::GetSelectedEntities()
|
|
{
|
|
AzToolsFramework::EntityIdList selectedEntities;
|
|
AzToolsFramework::ToolsApplicationRequestBus::BroadcastResult(
|
|
selectedEntities, &AzToolsFramework::ToolsApplicationRequestBus::Events::GetSelectedEntities);
|
|
return selectedEntities;
|
|
}
|
|
|
|
void EditorFocusModeFixture::SetUpEditorFixtureImpl()
|
|
{
|
|
// Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is
|
|
// shared across the whole engine, if multiple tests are run in parallel, the saving could cause a crash
|
|
// in the unit tests.
|
|
AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequests::DisableSaveOnFinalize);
|
|
|
|
m_containerEntityInterface = AZ::Interface<AzToolsFramework::ContainerEntityInterface>::Get();
|
|
ASSERT_TRUE(m_containerEntityInterface != nullptr);
|
|
|
|
m_focusModeInterface = AZ::Interface<AzToolsFramework::FocusModeInterface>::Get();
|
|
ASSERT_TRUE(m_focusModeInterface != nullptr);
|
|
|
|
// register a simple component implementing BoundsRequestBus and EditorComponentSelectionRequestsBus
|
|
GetApplication()->RegisterComponentDescriptor(UnitTest::BoundsTestComponent::CreateDescriptor());
|
|
|
|
AzToolsFramework::EditorEntityContextRequestBus::BroadcastResult(
|
|
m_editorEntityContextId, &AzToolsFramework::EditorEntityContextRequestBus::Events::GetEditorEntityContextId);
|
|
|
|
GenerateTestHierarchy();
|
|
|
|
// Clear the focus, disabling focus mode
|
|
m_focusModeInterface->ClearFocusRoot(m_editorEntityContextId);
|
|
|
|
// Clear selection
|
|
ClearSelectedEntities();
|
|
}
|
|
|
|
void EditorFocusModeFixture::TearDownEditorFixtureImpl()
|
|
{
|
|
// Clear Container Entity preserved open states
|
|
m_containerEntityInterface->Clear(m_editorEntityContextId);
|
|
|
|
// Clear the focus, disabling focus mode
|
|
m_focusModeInterface->ClearFocusRoot(m_editorEntityContextId);
|
|
|
|
// Clear selection
|
|
ClearSelectedEntities();
|
|
}
|
|
|
|
void EditorFocusModeFixture::GenerateTestHierarchy()
|
|
{
|
|
/*
|
|
* City
|
|
* |_ Street
|
|
* |_ Car
|
|
* | |_ Passenger
|
|
* |_ SportsCar
|
|
* |_ Passenger
|
|
*/
|
|
|
|
m_entityMap[CityEntityName] = CreateEditorEntity(CityEntityName, AZ::EntityId());
|
|
m_entityMap[StreetEntityName] = CreateEditorEntity(StreetEntityName, m_entityMap[CityEntityName]);
|
|
m_entityMap[CarEntityName] = CreateEditorEntity(CarEntityName, m_entityMap[StreetEntityName]);
|
|
m_entityMap[Passenger1EntityName] = CreateEditorEntity(Passenger1EntityName, m_entityMap[CarEntityName]);
|
|
m_entityMap[SportsCarEntityName] = CreateEditorEntity(SportsCarEntityName, m_entityMap[StreetEntityName]);
|
|
m_entityMap[Passenger2EntityName] = CreateEditorEntity(Passenger2EntityName, m_entityMap[SportsCarEntityName]);
|
|
|
|
// Add a BoundsTestComponent to the Car entity.
|
|
AZ::Entity* entity = AzToolsFramework::GetEntityById(m_entityMap[CarEntityName]);
|
|
|
|
entity->Deactivate();
|
|
entity->CreateComponent<UnitTest::BoundsTestComponent>();
|
|
entity->Activate();
|
|
|
|
// Move the CarEntity so it's out of the way.
|
|
AZ::TransformBus::Event(m_entityMap[CarEntityName], &AZ::TransformBus::Events::SetWorldTranslation, WorldCarEntityPosition);
|
|
|
|
// Setup the camera so the Car entity is in view.
|
|
AzFramework::SetCameraTransform(
|
|
m_cameraState,
|
|
AZ::Transform::CreateFromQuaternionAndTranslation(
|
|
AZ::Quaternion::CreateFromEulerAnglesDegrees(AZ::Vector3(0.0f, 0.0f, 0.0f)), CameraPosition));
|
|
}
|
|
|
|
AZ::EntityId EditorFocusModeFixture::CreateEditorEntity(const char* name, AZ::EntityId parentId)
|
|
{
|
|
AZ::Entity* entity = nullptr;
|
|
UnitTest::CreateDefaultEditorEntity(name, &entity);
|
|
|
|
// Parent
|
|
AZ::TransformBus::Event(entity->GetId(), &AZ::TransformInterface::SetParent, parentId);
|
|
|
|
return entity->GetId();
|
|
}
|
|
} // namespace UnitTest
|