123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- /*
- * 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 "ComponentModeTestDoubles.h"
- #include <AzCore/Serialization/SerializeContext.h>
- namespace AzToolsFramework
- {
- namespace ComponentModeFramework
- {
- AZ_CLASS_ALLOCATOR_IMPL(PlaceHolderComponentMode, AZ::SystemAllocator)
- AZ_CLASS_ALLOCATOR_IMPL(AnotherPlaceHolderComponentMode, AZ::SystemAllocator)
- AZ_CLASS_ALLOCATOR_IMPL(OverrideMouseInteractionComponentMode, AZ::SystemAllocator)
- void PlaceholderEditorComponent::Reflect(AZ::ReflectContext* context)
- {
- if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
- {
- serializeContext->Class<PlaceholderEditorComponent>()
- ->Version(0)
- ->Field("ComponentMode", &PlaceholderEditorComponent::m_componentModeDelegate);
- }
- }
- void PlaceholderEditorComponent::Activate()
- {
- EditorComponentBase::Activate();
- m_componentModeDelegate.ConnectWithSingleComponentMode<
- PlaceholderEditorComponent, PlaceHolderComponentMode>(
- AZ::EntityComponentIdPair(GetEntityId(), GetId()), nullptr);
- }
- void PlaceholderEditorComponent::Deactivate()
- {
- EditorComponentBase::Deactivate();
- m_componentModeDelegate.Disconnect();
- }
- void AnotherPlaceholderEditorComponent::Reflect(AZ::ReflectContext* context)
- {
- if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
- {
- serializeContext->Class<AnotherPlaceholderEditorComponent>()
- ->Version(0)
- ->Field("ComponentMode", &AnotherPlaceholderEditorComponent::m_componentModeDelegate);
- }
- }
- void AnotherPlaceholderEditorComponent::GetProvidedServices(
- AZ::ComponentDescriptor::DependencyArrayType& provided)
- {
- provided.push_back(AZ_CRC_CE("InterestingService"));
- }
- void AnotherPlaceholderEditorComponent::GetIncompatibleServices(
- AZ::ComponentDescriptor::DependencyArrayType& incompatible)
- {
- incompatible.push_back(AZ_CRC_CE("InterestingService"));
- }
- void AnotherPlaceholderEditorComponent::Activate()
- {
- EditorComponentBase::Activate();
- m_componentModeDelegate.ConnectWithSingleComponentMode<
- AnotherPlaceholderEditorComponent, PlaceHolderComponentMode>(
- AZ::EntityComponentIdPair(GetEntityId(), GetId()), nullptr);
- }
- void AnotherPlaceholderEditorComponent::Deactivate()
- {
- EditorComponentBase::Deactivate();
- m_componentModeDelegate.Disconnect();
- }
- void DependentPlaceholderEditorComponent::Reflect(AZ::ReflectContext* context)
- {
- if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
- {
- serializeContext->Class<DependentPlaceholderEditorComponent>()
- ->Version(0)
- ->Field("ComponentMode", &DependentPlaceholderEditorComponent::m_componentModeDelegate);
- }
- }
- void DependentPlaceholderEditorComponent::Activate()
- {
- EditorComponentBase::Activate();
- // connect the ComponentMode delegate to this entity/component id pair
- m_componentModeDelegate.Connect<DependentPlaceholderEditorComponent>(AZ::EntityComponentIdPair(GetEntityId(), GetId()), nullptr);
- // setup the ComponentMode(s) to add for the editing of this Component (in this case Spline and Tube ComponentModes)
- m_componentModeDelegate.SetAddComponentModeCallback([this](const AZ::EntityComponentIdPair& entityComponentIdPair)
- {
- using namespace AzToolsFramework::ComponentModeFramework;
- // builder for PlaceHolderComponentMode for DependentPlaceholderEditorComponent
- const auto placeholdComponentModeBuilder =
- CreateComponentModeBuilder<DependentPlaceholderEditorComponent, PlaceHolderComponentMode>(
- entityComponentIdPair);
- // must have AnotherPlaceholderEditorComponent when using DependentPlaceholderEditorComponent
- const auto componentId = GetEntity()->FindComponent<AnotherPlaceholderEditorComponent>()->GetId();
- const auto anotherPlaceholdComponentModeBuilder =
- CreateComponentModeBuilder<AnotherPlaceholderEditorComponent, AnotherPlaceHolderComponentMode>(
- AZ::EntityComponentIdPair(GetEntityId(), componentId));
- // aggregate builders
- const auto entityAndComponentModeBuilder =
- EntityAndComponentModeBuilders(
- GetEntityId(), { placeholdComponentModeBuilder, anotherPlaceholdComponentModeBuilder });
- // updates modes to add when entering ComponentMode
- ComponentModeSystemRequestBus::Broadcast(
- &ComponentModeSystemRequests::AddComponentModes, entityAndComponentModeBuilder);
- });
- }
- void DependentPlaceholderEditorComponent::Deactivate()
- {
- EditorComponentBase::Deactivate();
- m_componentModeDelegate.Disconnect();
- }
- void IncompatiblePlaceholderEditorComponent::Reflect(AZ::ReflectContext* context)
- {
- if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
- {
- serializeContext->Class<IncompatiblePlaceholderEditorComponent>()
- ->Version(0)
- ->Field("ComponentMode", &IncompatiblePlaceholderEditorComponent::m_componentModeDelegate);
- }
- }
- void IncompatiblePlaceholderEditorComponent::GetProvidedServices(
- AZ::ComponentDescriptor::DependencyArrayType& provided)
- {
- provided.push_back(AZ_CRC_CE("InterestingService"));
- }
- void IncompatiblePlaceholderEditorComponent::GetIncompatibleServices(
- AZ::ComponentDescriptor::DependencyArrayType& incompatible)
- {
- incompatible.push_back(AZ_CRC_CE("InterestingService"));
- }
- void IncompatiblePlaceholderEditorComponent::Activate()
- {
- EditorComponentBase::Activate();
- m_componentModeDelegate.ConnectWithSingleComponentMode<
- IncompatiblePlaceholderEditorComponent, AnotherPlaceHolderComponentMode>(
- AZ::EntityComponentIdPair(GetEntityId(), GetId()), nullptr);
- }
- void IncompatiblePlaceholderEditorComponent::Deactivate()
- {
- EditorComponentBase::Deactivate();
- m_componentModeDelegate.Disconnect();
- }
- ComponentModeActionSignalNotificationChecker::ComponentModeActionSignalNotificationChecker(int busId)
- {
- ComponentModeActionSignalNotificationBus::Handler::BusConnect(busId);
- }
- ComponentModeActionSignalNotificationChecker::~ComponentModeActionSignalNotificationChecker()
- {
- ComponentModeActionSignalNotificationBus::Handler::BusDisconnect();
- }
- void ComponentModeActionSignalNotificationChecker::OnActionTriggered()
- {
- m_counter++;
- }
- PlaceHolderComponentMode::PlaceHolderComponentMode(
- const AZ::EntityComponentIdPair& entityComponentIdPair, AZ::Uuid componentType)
- : EditorBaseComponentMode(entityComponentIdPair, componentType)
- {
- ComponentModeActionSignalRequestBus::Handler::BusConnect(entityComponentIdPair);
- }
- PlaceHolderComponentMode::~PlaceHolderComponentMode()
- {
- ComponentModeActionSignalRequestBus::Handler::BusDisconnect();
- }
- AZStd::vector<AzToolsFramework::ActionOverride> PlaceHolderComponentMode::PopulateActionsImpl()
- {
- const AZ::Crc32 placeHolderComponentModeAction = AZ_CRC_CE("org.o3de.action.placeholder.test");
- return AZStd::vector<AzToolsFramework::ActionOverride>
- {
- // setup an event to notify us when an action fires
- AzToolsFramework::ActionOverride()
- .SetUri(placeHolderComponentModeAction)
- .SetKeySequence(QKeySequence(Qt::Key_Space))
- .SetTitle("Test action")
- .SetTip("This is a test action")
- .SetEntityComponentIdPair(AZ::EntityComponentIdPair(GetEntityId(), GetComponentId()))
- .SetCallback([this]()
- {
- ComponentModeActionSignalNotificationBus::Event(
- m_componentModeActionSignalNotificationBusId, &ComponentModeActionSignalNotifications::OnActionTriggered);
- })
- };
- }
- AZStd::string PlaceHolderComponentMode::GetComponentModeName() const
- {
- return "PlaceHolder Edit Mode";
- }
- AZ::Uuid PlaceHolderComponentMode::GetComponentModeType() const
- {
- return azrtti_typeid<PlaceHolderComponentMode>();
- }
- void PlaceHolderComponentMode::SetComponentModeActionNotificationBusToNotify(const int busId)
- {
- m_componentModeActionSignalNotificationBusId = busId;
- }
- AnotherPlaceHolderComponentMode::AnotherPlaceHolderComponentMode(
- const AZ::EntityComponentIdPair& entityComponentIdPair, AZ::Uuid componentType)
- : EditorBaseComponentMode(entityComponentIdPair, componentType) {}
- AZStd::string AnotherPlaceHolderComponentMode::GetComponentModeName() const
- {
- return "AnotherPlaceHolder Edit Mode";
- }
- AZ::Uuid AnotherPlaceHolderComponentMode::GetComponentModeType() const
- {
- return azrtti_typeid<AnotherPlaceHolderComponentMode>();
- }
- OverrideMouseInteractionComponentMode::OverrideMouseInteractionComponentMode(
- const AZ::EntityComponentIdPair& entityComponentIdPair, AZ::Uuid componentType)
- : EditorBaseComponentMode(entityComponentIdPair, componentType) {}
- AZStd::string OverrideMouseInteractionComponentMode::GetComponentModeName() const
- {
- return "OverrideMouseInteraction Edit Mode";
- }
- AZ::Uuid OverrideMouseInteractionComponentMode::GetComponentModeType() const
- {
- return azrtti_typeid<OverrideMouseInteractionComponentMode>();
- }
- } // namespace ComponentModeFramework
- } // namespace AzToolsFramework
|