ComponentModeTestDoubles.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "ComponentModeTestDoubles.h"
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. namespace AzToolsFramework
  11. {
  12. namespace ComponentModeFramework
  13. {
  14. AZ_CLASS_ALLOCATOR_IMPL(PlaceHolderComponentMode, AZ::SystemAllocator)
  15. AZ_CLASS_ALLOCATOR_IMPL(AnotherPlaceHolderComponentMode, AZ::SystemAllocator)
  16. AZ_CLASS_ALLOCATOR_IMPL(OverrideMouseInteractionComponentMode, AZ::SystemAllocator)
  17. void PlaceholderEditorComponent::Reflect(AZ::ReflectContext* context)
  18. {
  19. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  20. {
  21. serializeContext->Class<PlaceholderEditorComponent>()
  22. ->Version(0)
  23. ->Field("ComponentMode", &PlaceholderEditorComponent::m_componentModeDelegate);
  24. }
  25. }
  26. void PlaceholderEditorComponent::Activate()
  27. {
  28. EditorComponentBase::Activate();
  29. m_componentModeDelegate.ConnectWithSingleComponentMode<
  30. PlaceholderEditorComponent, PlaceHolderComponentMode>(
  31. AZ::EntityComponentIdPair(GetEntityId(), GetId()), nullptr);
  32. }
  33. void PlaceholderEditorComponent::Deactivate()
  34. {
  35. EditorComponentBase::Deactivate();
  36. m_componentModeDelegate.Disconnect();
  37. }
  38. void AnotherPlaceholderEditorComponent::Reflect(AZ::ReflectContext* context)
  39. {
  40. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  41. {
  42. serializeContext->Class<AnotherPlaceholderEditorComponent>()
  43. ->Version(0)
  44. ->Field("ComponentMode", &AnotherPlaceholderEditorComponent::m_componentModeDelegate);
  45. }
  46. }
  47. void AnotherPlaceholderEditorComponent::GetProvidedServices(
  48. AZ::ComponentDescriptor::DependencyArrayType& provided)
  49. {
  50. provided.push_back(AZ_CRC_CE("InterestingService"));
  51. }
  52. void AnotherPlaceholderEditorComponent::GetIncompatibleServices(
  53. AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  54. {
  55. incompatible.push_back(AZ_CRC_CE("InterestingService"));
  56. }
  57. void AnotherPlaceholderEditorComponent::Activate()
  58. {
  59. EditorComponentBase::Activate();
  60. m_componentModeDelegate.ConnectWithSingleComponentMode<
  61. AnotherPlaceholderEditorComponent, PlaceHolderComponentMode>(
  62. AZ::EntityComponentIdPair(GetEntityId(), GetId()), nullptr);
  63. }
  64. void AnotherPlaceholderEditorComponent::Deactivate()
  65. {
  66. EditorComponentBase::Deactivate();
  67. m_componentModeDelegate.Disconnect();
  68. }
  69. void DependentPlaceholderEditorComponent::Reflect(AZ::ReflectContext* context)
  70. {
  71. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  72. {
  73. serializeContext->Class<DependentPlaceholderEditorComponent>()
  74. ->Version(0)
  75. ->Field("ComponentMode", &DependentPlaceholderEditorComponent::m_componentModeDelegate);
  76. }
  77. }
  78. void DependentPlaceholderEditorComponent::Activate()
  79. {
  80. EditorComponentBase::Activate();
  81. // connect the ComponentMode delegate to this entity/component id pair
  82. m_componentModeDelegate.Connect<DependentPlaceholderEditorComponent>(AZ::EntityComponentIdPair(GetEntityId(), GetId()), nullptr);
  83. // setup the ComponentMode(s) to add for the editing of this Component (in this case Spline and Tube ComponentModes)
  84. m_componentModeDelegate.SetAddComponentModeCallback([this](const AZ::EntityComponentIdPair& entityComponentIdPair)
  85. {
  86. using namespace AzToolsFramework::ComponentModeFramework;
  87. // builder for PlaceHolderComponentMode for DependentPlaceholderEditorComponent
  88. const auto placeholdComponentModeBuilder =
  89. CreateComponentModeBuilder<DependentPlaceholderEditorComponent, PlaceHolderComponentMode>(
  90. entityComponentIdPair);
  91. // must have AnotherPlaceholderEditorComponent when using DependentPlaceholderEditorComponent
  92. const auto componentId = GetEntity()->FindComponent<AnotherPlaceholderEditorComponent>()->GetId();
  93. const auto anotherPlaceholdComponentModeBuilder =
  94. CreateComponentModeBuilder<AnotherPlaceholderEditorComponent, AnotherPlaceHolderComponentMode>(
  95. AZ::EntityComponentIdPair(GetEntityId(), componentId));
  96. // aggregate builders
  97. const auto entityAndComponentModeBuilder =
  98. EntityAndComponentModeBuilders(
  99. GetEntityId(), { placeholdComponentModeBuilder, anotherPlaceholdComponentModeBuilder });
  100. // updates modes to add when entering ComponentMode
  101. ComponentModeSystemRequestBus::Broadcast(
  102. &ComponentModeSystemRequests::AddComponentModes, entityAndComponentModeBuilder);
  103. });
  104. }
  105. void DependentPlaceholderEditorComponent::Deactivate()
  106. {
  107. EditorComponentBase::Deactivate();
  108. m_componentModeDelegate.Disconnect();
  109. }
  110. void IncompatiblePlaceholderEditorComponent::Reflect(AZ::ReflectContext* context)
  111. {
  112. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  113. {
  114. serializeContext->Class<IncompatiblePlaceholderEditorComponent>()
  115. ->Version(0)
  116. ->Field("ComponentMode", &IncompatiblePlaceholderEditorComponent::m_componentModeDelegate);
  117. }
  118. }
  119. void IncompatiblePlaceholderEditorComponent::GetProvidedServices(
  120. AZ::ComponentDescriptor::DependencyArrayType& provided)
  121. {
  122. provided.push_back(AZ_CRC_CE("InterestingService"));
  123. }
  124. void IncompatiblePlaceholderEditorComponent::GetIncompatibleServices(
  125. AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  126. {
  127. incompatible.push_back(AZ_CRC_CE("InterestingService"));
  128. }
  129. void IncompatiblePlaceholderEditorComponent::Activate()
  130. {
  131. EditorComponentBase::Activate();
  132. m_componentModeDelegate.ConnectWithSingleComponentMode<
  133. IncompatiblePlaceholderEditorComponent, AnotherPlaceHolderComponentMode>(
  134. AZ::EntityComponentIdPair(GetEntityId(), GetId()), nullptr);
  135. }
  136. void IncompatiblePlaceholderEditorComponent::Deactivate()
  137. {
  138. EditorComponentBase::Deactivate();
  139. m_componentModeDelegate.Disconnect();
  140. }
  141. ComponentModeActionSignalNotificationChecker::ComponentModeActionSignalNotificationChecker(int busId)
  142. {
  143. ComponentModeActionSignalNotificationBus::Handler::BusConnect(busId);
  144. }
  145. ComponentModeActionSignalNotificationChecker::~ComponentModeActionSignalNotificationChecker()
  146. {
  147. ComponentModeActionSignalNotificationBus::Handler::BusDisconnect();
  148. }
  149. void ComponentModeActionSignalNotificationChecker::OnActionTriggered()
  150. {
  151. m_counter++;
  152. }
  153. PlaceHolderComponentMode::PlaceHolderComponentMode(
  154. const AZ::EntityComponentIdPair& entityComponentIdPair, AZ::Uuid componentType)
  155. : EditorBaseComponentMode(entityComponentIdPair, componentType)
  156. {
  157. ComponentModeActionSignalRequestBus::Handler::BusConnect(entityComponentIdPair);
  158. }
  159. PlaceHolderComponentMode::~PlaceHolderComponentMode()
  160. {
  161. ComponentModeActionSignalRequestBus::Handler::BusDisconnect();
  162. }
  163. AZStd::vector<AzToolsFramework::ActionOverride> PlaceHolderComponentMode::PopulateActionsImpl()
  164. {
  165. const AZ::Crc32 placeHolderComponentModeAction = AZ_CRC_CE("org.o3de.action.placeholder.test");
  166. return AZStd::vector<AzToolsFramework::ActionOverride>
  167. {
  168. // setup an event to notify us when an action fires
  169. AzToolsFramework::ActionOverride()
  170. .SetUri(placeHolderComponentModeAction)
  171. .SetKeySequence(QKeySequence(Qt::Key_Space))
  172. .SetTitle("Test action")
  173. .SetTip("This is a test action")
  174. .SetEntityComponentIdPair(AZ::EntityComponentIdPair(GetEntityId(), GetComponentId()))
  175. .SetCallback([this]()
  176. {
  177. ComponentModeActionSignalNotificationBus::Event(
  178. m_componentModeActionSignalNotificationBusId, &ComponentModeActionSignalNotifications::OnActionTriggered);
  179. })
  180. };
  181. }
  182. AZStd::string PlaceHolderComponentMode::GetComponentModeName() const
  183. {
  184. return "PlaceHolder Edit Mode";
  185. }
  186. AZ::Uuid PlaceHolderComponentMode::GetComponentModeType() const
  187. {
  188. return azrtti_typeid<PlaceHolderComponentMode>();
  189. }
  190. void PlaceHolderComponentMode::SetComponentModeActionNotificationBusToNotify(const int busId)
  191. {
  192. m_componentModeActionSignalNotificationBusId = busId;
  193. }
  194. AnotherPlaceHolderComponentMode::AnotherPlaceHolderComponentMode(
  195. const AZ::EntityComponentIdPair& entityComponentIdPair, AZ::Uuid componentType)
  196. : EditorBaseComponentMode(entityComponentIdPair, componentType) {}
  197. AZStd::string AnotherPlaceHolderComponentMode::GetComponentModeName() const
  198. {
  199. return "AnotherPlaceHolder Edit Mode";
  200. }
  201. AZ::Uuid AnotherPlaceHolderComponentMode::GetComponentModeType() const
  202. {
  203. return azrtti_typeid<AnotherPlaceHolderComponentMode>();
  204. }
  205. OverrideMouseInteractionComponentMode::OverrideMouseInteractionComponentMode(
  206. const AZ::EntityComponentIdPair& entityComponentIdPair, AZ::Uuid componentType)
  207. : EditorBaseComponentMode(entityComponentIdPair, componentType) {}
  208. AZStd::string OverrideMouseInteractionComponentMode::GetComponentModeName() const
  209. {
  210. return "OverrideMouseInteraction Edit Mode";
  211. }
  212. AZ::Uuid OverrideMouseInteractionComponentMode::GetComponentModeType() const
  213. {
  214. return azrtti_typeid<OverrideMouseInteractionComponentMode>();
  215. }
  216. } // namespace ComponentModeFramework
  217. } // namespace AzToolsFramework