123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545 |
- /*
- * 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/ComponentModeTestDoubles.h>
- #include <Tests/ComponentModeTestFixture.h>
- #include <AzCore/std/smart_ptr/make_shared.h>
- #include <AzCore/std/smart_ptr/shared_ptr.h>
- #include <AzFramework/Viewport/ViewportScreen.h>
- #include <AzTest/AzTest.h>
- #include <AzToolsFramework/API/EntityCompositionRequestBus.h>
- #include <AzToolsFramework/Application/ToolsApplication.h>
- #include <AzToolsFramework/ComponentMode/ComponentModeSwitcher.h>
- #include <AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.h>
- #include <AzToolsFramework/ViewportUi/ButtonGroup.h>
- #include <AzToolsFramework/ViewportUi/ViewportUiManager.h>
- #include <AzToolsFramework/ViewportUi/ViewportUiSwitcher.h>
- #include <AzToolsFramework/API/EntityCompositionRequestBus.h>
- namespace UnitTest
- {
- using AzToolsFramework::ComponentModeFramework::PlaceholderEditorComponent;
- using AzToolsFramework::ComponentModeFramework::AnotherPlaceholderEditorComponent;
- using AzToolsFramework::ComponentModeFramework::DependentPlaceholderEditorComponent;
- using ComponentModeSwitcher = AzToolsFramework::ComponentModeFramework::ComponentModeSwitcher;
- using ComponentModeSwitcherTestFixture = ComponentModeTestFixture;
- TEST_F(ComponentModeSwitcherTestFixture, AddingComponentsToEntityAddsComponentsToSwitcher)
- {
- // Given the setup of one entity with one component
- AZStd::shared_ptr<ComponentModeSwitcher> componentModeSwitcher = AZStd::make_shared<ComponentModeSwitcher>();
- AzToolsFramework::EditorTransformComponentSelectionRequestBus::Event(
- AzToolsFramework::GetEntityContextId(),
- &AzToolsFramework::EditorTransformComponentSelectionRequestBus::Events::OverrideComponentModeSwitcher,
- componentModeSwitcher);
- AZ::Entity* entity = nullptr;
- AZ::EntityId entityId = CreateDefaultEditorEntity("ComponentModeEntity", &entity);
- entity->Deactivate();
- entity->CreateComponent<PlaceholderEditorComponent>();
- entity->Activate();
- // When the entity is selected, expect the switcher to have one component
- const AzToolsFramework::EntityIdList entityIds = { entityId };
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
- &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, entityIds);
- EXPECT_EQ(1, componentModeSwitcher->GetComponentCount());
- // Then when another component is added to the entity, expect the switcher to have two components
- AzToolsFramework::EntityCompositionRequests::AddComponentsOutcome addComponentsOutcome;
- AzToolsFramework::EntityCompositionRequestBus::BroadcastResult(
- addComponentsOutcome,
- &AzToolsFramework::EntityCompositionRequests::AddComponentsToEntities,
- entityIds,
- AZ::ComponentTypeList{ AnotherPlaceholderEditorComponent::RTTI_Type() });
- EXPECT_EQ(2, componentModeSwitcher->GetComponentCount());
- }
- TEST_F(ComponentModeSwitcherTestFixture, RemovingComponentsFromEntityRemovesComponentsFromSwitcher)
- {
- // Given the set up of one entity selected with two components
- AZStd::shared_ptr<ComponentModeSwitcher> componentModeSwitcher = AZStd::make_shared<ComponentModeSwitcher>();
- AzToolsFramework::EditorTransformComponentSelectionRequestBus::Event(
- AzToolsFramework::GetEntityContextId(),
- &AzToolsFramework::EditorTransformComponentSelectionRequestBus::Events::OverrideComponentModeSwitcher,
- componentModeSwitcher);
- AZ::Entity* entity = nullptr;
- AZ::EntityId entityId = CreateDefaultEditorEntity("ComponentModeEntity", &entity);
- entity->Deactivate();
- entity->CreateComponent<PlaceholderEditorComponent>();
- AZ::Component* placeholder2 = entity->CreateComponent<AnotherPlaceholderEditorComponent>();
- entity->Activate();
- // When the user selects the entity, two components show up in the switcher
- const AzToolsFramework::EntityIdList entityIds = { entityId };
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
- &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, entityIds);
- EXPECT_EQ(2, componentModeSwitcher->GetComponentCount());
- // Then when the user removes a component, one component remains
- AzToolsFramework::EntityCompositionRequests::RemoveComponentsOutcome removeComponentsOutcome;
- AzToolsFramework::EntityCompositionRequestBus::BroadcastResult(
- removeComponentsOutcome,
- &AzToolsFramework::EntityCompositionRequests::RemoveComponents,
- AZ::Entity::ComponentArrayType{ placeholder2 });
- EXPECT_EQ(1, componentModeSwitcher->GetComponentCount());
- }
- TEST_F(ComponentModeSwitcherTestFixture, InstantaneousChangeOfEntitySelectionUpdatesSwitcherCorrectly)
- {
- // Given an entity with two components
- AZStd::shared_ptr<ComponentModeSwitcher> componentModeSwitcher = AZStd::make_shared<ComponentModeSwitcher>();
- AzToolsFramework::EditorTransformComponentSelectionRequestBus::Event(
- AzToolsFramework::GetEntityContextId(),
- &AzToolsFramework::EditorTransformComponentSelectionRequestBus::Events::OverrideComponentModeSwitcher,
- componentModeSwitcher);
- AZ::Entity* entity = nullptr;
- AZ::EntityId entityId = CreateDefaultEditorEntity("ComponentModeEntity", &entity);
- AZ::Entity* entity2 = nullptr;
- AZ::EntityId entityId2 = CreateDefaultEditorEntity("ComponentModeEntity", &entity2);
- entity->Deactivate();
- entity2->Deactivate();
- entity->CreateComponent<PlaceholderEditorComponent>();
- entity->CreateComponent<AnotherPlaceholderEditorComponent>();
- entity2->CreateComponent<AnotherPlaceholderEditorComponent>();
- entity->Activate();
- entity2->Activate();
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
- &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, AzToolsFramework::EntityIdList{ entityId });
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
- &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, AzToolsFramework::EntityIdList{ entityId2 });
- EXPECT_EQ(1, componentModeSwitcher->GetComponentCount());
- }
- TEST_F(ComponentModeSwitcherTestFixture, AddingDuplicateComponentsDoesNotAddComponentsToSwitcher)
- {
- // Given an entity with one component
- AZStd::shared_ptr<ComponentModeSwitcher> componentModeSwitcher = AZStd::make_shared<ComponentModeSwitcher>();
- AzToolsFramework::EditorTransformComponentSelectionRequestBus::Event(
- AzToolsFramework::GetEntityContextId(),
- &AzToolsFramework::EditorTransformComponentSelectionRequestBus::Events::OverrideComponentModeSwitcher,
- componentModeSwitcher);
- AZ::Entity* entity = nullptr;
- AZ::EntityId entityId = CreateDefaultEditorEntity("ComponentModeEntity", &entity);
- entity->Deactivate();
- entity->CreateComponent<PlaceholderEditorComponent>();
- entity->Activate();
- // When an entity is selected, there is one component added to the switcher
- const AzToolsFramework::EntityIdList entityIds = { entityId };
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
- &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, entityIds);
- EXPECT_EQ(1, componentModeSwitcher->GetComponentCount());
- // Then if the user adds an identical component, there is still one component on the switcher
- entity->Deactivate();
- entity->CreateComponent<PlaceholderEditorComponent>();
- entity->Activate();
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
- &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, entityIds);
- EXPECT_EQ(1, componentModeSwitcher->GetComponentCount());
- }
- TEST_F(ComponentModeSwitcherTestFixture, SelectingAndDeselectingEntitiesAddsAndRemovesComponentsFromSwitcher)
- {
- // Given an entity with multiple components
- AZStd::shared_ptr<ComponentModeSwitcher> componentModeSwitcher = AZStd::make_shared<ComponentModeSwitcher>();
- AzToolsFramework::EditorTransformComponentSelectionRequestBus::Event(
- AzToolsFramework::GetEntityContextId(),
- &AzToolsFramework::EditorTransformComponentSelectionRequestBus::Events::OverrideComponentModeSwitcher,
- componentModeSwitcher);
- AZ::Entity* entity = nullptr;
- AZ::EntityId entityId = CreateDefaultEditorEntity("ComponentModeEntity", &entity);
- entity->Deactivate();
- entity->CreateComponent<PlaceholderEditorComponent>();
- entity->CreateComponent<AnotherPlaceholderEditorComponent>();
- entity->Activate();
- // When the entity is selected, there are two components on the switcher
- const AzToolsFramework::EntityIdList entityIds = { entityId };
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
- &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, entityIds);
- EXPECT_EQ(2, componentModeSwitcher->GetComponentCount());
- // Then when the entity is deselected
- const AzToolsFramework::EntityIdList emptyIds = {};
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(&AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, emptyIds);
- EXPECT_EQ(0, componentModeSwitcher->GetComponentCount());
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
- &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, entityIds);
- EXPECT_EQ(2, componentModeSwitcher->GetComponentCount());
- }
- TEST_F(ComponentModeSwitcherTestFixture, AddIngMultipleEntitiesToSelectionWithSameComponentsKeepComponentsInSwitcher)
- {
- // Given two entities with different components
- AZStd::shared_ptr<ComponentModeSwitcher> componentModeSwitcher = AZStd::make_shared<ComponentModeSwitcher>();
- AzToolsFramework::EditorTransformComponentSelectionRequestBus::Event(
- AzToolsFramework::GetEntityContextId(),
- &AzToolsFramework::EditorTransformComponentSelectionRequestBus::Events::OverrideComponentModeSwitcher,
- componentModeSwitcher);
- AZ::Entity* entity = nullptr;
- AZ::Entity* entity2 = nullptr;
- AZ::EntityId entityId = CreateDefaultEditorEntity("ComponentModeEntity", &entity);
- AZ::EntityId entityId2 = CreateDefaultEditorEntity("ComponentModeEntity2", &entity2);
- entity->Deactivate();
- entity2->Deactivate();
- entity->CreateComponent<PlaceholderEditorComponent>();
- entity->CreateComponent<AnotherPlaceholderEditorComponent>();
- entity2->CreateComponent<PlaceholderEditorComponent>();
- entity->Activate();
- entity2->Activate();
- // When one entity is selected all associated components show up in the switcher
- AzToolsFramework::EntityIdList entityIds = { entityId };
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
- &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, entityIds);
- EXPECT_EQ(2, componentModeSwitcher->GetComponentCount());
- // Then if both entities are selected, only components that are shared between both entities show up
- entityIds = { entityId, entityId2 };
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
- &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, entityIds);
- EXPECT_EQ(1, componentModeSwitcher->GetComponentCount());
- }
- TEST_F(ComponentModeSwitcherTestFixture, AddingMultipleEntityToSelectionWithUniqueComponentsRemovesUniqueFromSwitcher)
- {
- // Given two entities with multiple components
- AZStd::shared_ptr<ComponentModeSwitcher> componentModeSwitcher = AZStd::make_shared<ComponentModeSwitcher>();
- AzToolsFramework::EditorTransformComponentSelectionRequestBus::Event(
- AzToolsFramework::GetEntityContextId(),
- &AzToolsFramework::EditorTransformComponentSelectionRequestBus::Events::OverrideComponentModeSwitcher,
- componentModeSwitcher);
- AZ::Entity* entity = nullptr;
- AZ::Entity* entity2 = nullptr;
- AZ::EntityId entityId = CreateDefaultEditorEntity("ComponentModeEntity", &entity);
- AZ::EntityId entityId2 = CreateDefaultEditorEntity("ComponentModeEntity2", &entity2);
- entity->Deactivate();
- entity2->Deactivate();
- entity->CreateComponent<PlaceholderEditorComponent>();
- entity2->CreateComponent<AnotherPlaceholderEditorComponent>();
- entity->Activate();
- entity2->Activate();
- // When one entity is selected the component shows up like normal
- AzToolsFramework::EntityIdList entityIds = { entityId };
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
- &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, entityIds);
- EXPECT_EQ(1, componentModeSwitcher->GetComponentCount());
- // When both entities are selected, if there are no common components, the switcher is empty
- entityIds = { entityId, entityId2 };
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
- &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, entityIds);
- EXPECT_EQ(0, componentModeSwitcher->GetComponentCount());
- }
- TEST_F(ComponentModeSwitcherTestFixture, DeselectingOneEntityWithMultipleEntitiesSelectedAddsRemovedComponents)
- {
- // Given two entities with different components
- AZStd::shared_ptr<ComponentModeSwitcher> componentModeSwitcher = AZStd::make_shared<ComponentModeSwitcher>();
- AzToolsFramework::EditorTransformComponentSelectionRequestBus::Event(
- AzToolsFramework::GetEntityContextId(),
- &AzToolsFramework::EditorTransformComponentSelectionRequestBus::Events::OverrideComponentModeSwitcher,
- componentModeSwitcher);
- AZ::Entity* entity = nullptr;
- AZ::Entity* entity2 = nullptr;
- AZ::EntityId entityId = CreateDefaultEditorEntity("ComponentModeEntity", &entity);
- AZ::EntityId entityId2 = CreateDefaultEditorEntity("ComponentModeEntity2", &entity2);
- entity->Deactivate();
- entity2->Deactivate();
- entity->CreateComponent<PlaceholderEditorComponent>();
- entity2->CreateComponent<AnotherPlaceholderEditorComponent>();
- entity->Activate();
- entity2->Activate();
- // When the both entities are selected, nothing shows up in the switcher as there are no common components
- AzToolsFramework::EntityIdList entityIds = { entityId };
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
- &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, entityIds);
- EXPECT_EQ(1, componentModeSwitcher->GetComponentCount());
- entityIds = { entityId, entityId2 };
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
- &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, entityIds);
- EXPECT_EQ(0, componentModeSwitcher->GetComponentCount());
- // When the second entity is removed from the selection, the switcher now has the component from the single entity selected
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(&AzToolsFramework::ToolsApplicationRequests::DeleteEntityById, entityId2);
- EXPECT_EQ(1, componentModeSwitcher->GetComponentCount());
- }
- TEST_F(ComponentModeSwitcherTestFixture, EnteringComponentModeChangesActiveComponent)
- {
- // Given an entity with two components
- AZStd::shared_ptr<ComponentModeSwitcher> componentModeSwitcher = AZStd::make_shared<ComponentModeSwitcher>();
- AzToolsFramework::EditorTransformComponentSelectionRequestBus::Event(
- AzToolsFramework::GetEntityContextId(),
- &AzToolsFramework::EditorTransformComponentSelectionRequestBus::Events::OverrideComponentModeSwitcher,
- componentModeSwitcher);
- AZ::Entity* entity = nullptr;
- AZ::EntityId entityId = CreateDefaultEditorEntity("ComponentModeEntity", &entity);
- entity->Deactivate();
- const AZ::Component* placeholder1 = entity->CreateComponent<PlaceholderEditorComponent>();
- entity->CreateComponent<AnotherPlaceholderEditorComponent>();
- entity->Activate();
- // When component mode is activated for a component in any way (through the switcher or the entity tab)
- const AzToolsFramework::EntityIdList entityIds = { entityId };
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
- &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, entityIds);
- AzToolsFramework::ComponentModeFramework::ComponentModeSystemRequestBus::Broadcast(
- &AzToolsFramework::ComponentModeFramework::ComponentModeSystemRequests::AddSelectedComponentModesOfType,
- placeholder1->GetUnderlyingComponentType());
- // Then the switchers active button is the component that component mode is active for
- auto activeComponent = componentModeSwitcher->GetActiveComponent()->GetId();
- EXPECT_EQ(activeComponent, placeholder1->GetId());
- }
- TEST_F(ComponentModeSwitcherTestFixture, LeavingComponentModeChangesActiveComponentToTransformMode)
- {
- // Given an entity with two components
- AZStd::shared_ptr<ComponentModeSwitcher> componentModeSwitcher = AZStd::make_shared<ComponentModeSwitcher>();
- AzToolsFramework::EditorTransformComponentSelectionRequestBus::Event(
- AzToolsFramework::GetEntityContextId(),
- &AzToolsFramework::EditorTransformComponentSelectionRequestBus::Events::OverrideComponentModeSwitcher,
- componentModeSwitcher);
- AZ::Entity* entity = nullptr;
- AZ::EntityId entityId = CreateDefaultEditorEntity("ComponentModeEntity", &entity);
- entity->Deactivate();
- entity->CreateComponent<PlaceholderEditorComponent>();
- const AZ::Component* placeholder2 = entity->CreateComponent<AnotherPlaceholderEditorComponent>();
- entity->Activate();
- const AzToolsFramework::EntityIdList entityIds = { entityId };
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
- &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, entityIds);
- // When component mode is de-activated for a component in any way (through the switcher or the entity tab)
- AzToolsFramework::ComponentModeFramework::ComponentModeSystemRequestBus::Broadcast(
- &AzToolsFramework::ComponentModeFramework::ComponentModeSystemRequests::AddSelectedComponentModesOfType,
- placeholder2->GetUnderlyingComponentType());
- auto activeComponent = componentModeSwitcher->GetActiveComponent()->GetId();
- EXPECT_EQ(activeComponent, placeholder2->GetId());
- AzToolsFramework::ComponentModeFramework::ComponentModeSystemRequestBus::Broadcast(
- &AzToolsFramework::ComponentModeFramework::ComponentModeSystemRequests::EndComponentMode);
- // Then the active switcher button should be the transform component (indicated by null)
- auto nullComponent = componentModeSwitcher->GetActiveComponent();
- EXPECT_EQ(nullComponent, nullptr);
- }
- TEST_F(ComponentModeSwitcherTestFixture, DisablingComponentRemovesComponentFromSwitcher)
- {
- // Given an entity with two components
- AZStd::shared_ptr<ComponentModeSwitcher> componentModeSwitcher = AZStd::make_shared<ComponentModeSwitcher>();
- AzToolsFramework::EditorTransformComponentSelectionRequestBus::Event(
- AzToolsFramework::GetEntityContextId(),
- &AzToolsFramework::EditorTransformComponentSelectionRequestBus::Events::OverrideComponentModeSwitcher,
- componentModeSwitcher);
- AZ::Entity* entity = nullptr;
- AZ::EntityId entityId = CreateDefaultEditorEntity("ComponentModeEntity", &entity);
- entity->Deactivate();
- AZStd::unique_ptr<AZ::Component> placeholder1{entity->CreateComponent<PlaceholderEditorComponent>()};
- entity->CreateComponent<AnotherPlaceholderEditorComponent>();
- entity->Activate();
- // When the entity is selected there should be two components in the switcher
- const AzToolsFramework::EntityIdList entityIds = { entityId };
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
- &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, entityIds);
- EXPECT_EQ(2, componentModeSwitcher->GetComponentCount());
- // Then if one component is disabled, there should only be one component on the switcher
- // Disabling the component removes it from the entity, which is why its ownership is maintained here in a
- // unique_ptr
- AzToolsFramework::EntityCompositionRequestBus::Broadcast(
- &AzToolsFramework::EntityCompositionRequests::DisableComponents, AZStd::vector<AZ::Component*>{ placeholder1.get() });
- EXPECT_EQ(1, componentModeSwitcher->GetComponentCount());
- entity->Deactivate();
- }
- TEST_F(ComponentModeSwitcherTestFixture, EnablingComponentAddsComponentToSwitcher)
- {
- // Given an entity with two components
- AZStd::shared_ptr<ComponentModeSwitcher> componentModeSwitcher = AZStd::make_shared<ComponentModeSwitcher>();
- AzToolsFramework::EditorTransformComponentSelectionRequestBus::Event(
- AzToolsFramework::GetEntityContextId(),
- &AzToolsFramework::EditorTransformComponentSelectionRequestBus::Events::OverrideComponentModeSwitcher,
- componentModeSwitcher);
-
- AZ::Entity* entity = nullptr;
- AZ::EntityId entityId = CreateDefaultEditorEntity("ComponentModeEntity", &entity);
- // connect to EditorDisabledCompositionRequestBus with entityId
- Connect(entityId);
- entity->Deactivate();
- AZ::Component* placeholder1 = entity->CreateComponent<PlaceholderEditorComponent>();
- entity->CreateComponent<AnotherPlaceholderEditorComponent>();
- entity->Activate();
- // When the component is disabled it doesn't show up in the switcher
- const AzToolsFramework::EntityIdList entityIds = { entityId };
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
- &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, entityIds);
- EXPECT_EQ(2, componentModeSwitcher->GetComponentCount());
- AzToolsFramework::EntityCompositionRequestBus::Broadcast(
- &AzToolsFramework::EntityCompositionRequests::DisableComponents, AZStd::vector<AZ::Component*>{ placeholder1 });
- AzToolsFramework::EditorDisabledCompositionRequestBus::Event(
- entityId, &AzToolsFramework::EditorDisabledCompositionRequests::AddDisabledComponent, placeholder1);
- EXPECT_EQ(1, componentModeSwitcher->GetComponentCount());
- AddDisabledComponentToBus(placeholder1);
- AzToolsFramework::EntityCompositionRequestBus::Broadcast(
- &AzToolsFramework::EntityCompositionRequests::EnableComponents, AZStd::vector<AZ::Component*>{ placeholder1 });
- EXPECT_EQ(2, componentModeSwitcher->GetComponentCount());
- Disconnect();
- }
- TEST_F(ComponentModeSwitcherTestFixture, SwitchingBetweenComponentsDoesNotSwitchToTransformFirst)
- {
- // Given an entity with two components
- AZStd::shared_ptr<ComponentModeSwitcher> componentModeSwitcher = AZStd::make_shared<ComponentModeSwitcher>();
- AzToolsFramework::EditorTransformComponentSelectionRequestBus::Event(
- AzToolsFramework::GetEntityContextId(),
- &AzToolsFramework::EditorTransformComponentSelectionRequestBus::Events::OverrideComponentModeSwitcher,
- componentModeSwitcher);
- AZ::Entity* entity = nullptr;
- AZ::EntityId entityId = CreateDefaultEditorEntity("ComponentModeEntity", &entity);
- entity->Deactivate();
- const AZ::Component* placeholder = entity->CreateComponent<AnotherPlaceholderEditorComponent>();
- const AZ::Component* dependentPlaceholder = entity->CreateComponent<DependentPlaceholderEditorComponent>();
- entity->Activate();
- const AzToolsFramework::EntityIdList entityIds = { entityId };
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
- &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, entityIds);
- AzToolsFramework::ComponentModeFramework::ComponentModeSystemRequestBus::Broadcast(
- &AzToolsFramework::ComponentModeFramework::ComponentModeSystemRequests::AddSelectedComponentModesOfType,
- dependentPlaceholder->GetUnderlyingComponentType());
- auto activeComponent = componentModeSwitcher->GetActiveComponent()->GetId();
- EXPECT_EQ(activeComponent, dependentPlaceholder->GetId());
- // When the user is in a dependent component mode and presses tab
- QTest::keyPress(&m_editorActions.m_componentModeWidget, Qt::Key_Tab);
- // The swticher changes to the next active component mode
- activeComponent = componentModeSwitcher->GetActiveComponent()->GetId();
- EXPECT_EQ(activeComponent, placeholder->GetId());
- }
- TEST_F(ComponentModeSwitcherTestFixture, SwitcherDoesNotChangeCompositionWhileInComponentMode)
- {
- // Given an entity with two components
- AZStd::shared_ptr<ComponentModeSwitcher> componentModeSwitcher = AZStd::make_shared<ComponentModeSwitcher>();
- AzToolsFramework::EditorTransformComponentSelectionRequestBus::Event(
- AzToolsFramework::GetEntityContextId(),
- &AzToolsFramework::EditorTransformComponentSelectionRequestBus::Events::OverrideComponentModeSwitcher,
- componentModeSwitcher);
- AZ::Entity* entity = nullptr;
- AZ::EntityId entityId = CreateDefaultEditorEntity("ComponentModeEntity", &entity);
- entity->Deactivate();
- const AZ::Component* placeholder = entity->CreateComponent<AnotherPlaceholderEditorComponent>();
- const AZ::Component* dependentPlaceholder = entity->CreateComponent<DependentPlaceholderEditorComponent>();
- entity->Activate();
- const AzToolsFramework::EntityIdList entityIds = { entityId };
- AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
- &AzToolsFramework::ToolsApplicationRequests::SetSelectedEntities, entityIds);
- // When the editor enters component mode
- AzToolsFramework::ComponentModeFramework::ComponentModeSystemRequestBus::Broadcast(
- &AzToolsFramework::ComponentModeFramework::ComponentModeSystemRequests::AddSelectedComponentModesOfType,
- dependentPlaceholder->GetUnderlyingComponentType());
- EXPECT_TRUE(AzToolsFramework::ComponentModeFramework::InComponentMode());
- EXPECT_EQ(componentModeSwitcher->GetComponentCount(), 2);
- // While in component mode
- AzFramework::ComponentModeDelegateNotificationBus::Broadcast(
- &AzFramework::ComponentModeDelegateNotificationBus::Events::OnComponentModeDelegateDisconnect, AZ::EntityComponentIdPair(entityId, placeholder->GetId()));
- EXPECT_EQ(componentModeSwitcher->GetComponentCount(), 2);
- }
- } // namespace UnitTest
|