PropertySlotComponent.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 <Components/Slots/Property/PropertySlotComponent.h>
  9. #include <Components/Slots/Property/PropertySlotLayoutComponent.h>
  10. #include <Components/Slots/SlotConnectionFilterComponent.h>
  11. #include <Components/StylingComponent.h>
  12. #include <GraphCanvas/Components/Connections/ConnectionFilters/ConnectionFilters.h>
  13. namespace GraphCanvas
  14. {
  15. //////////////////////////
  16. // PropertySlotComponent
  17. //////////////////////////
  18. void PropertySlotComponent::Reflect(AZ::ReflectContext* reflectContext)
  19. {
  20. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflectContext);
  21. if (serializeContext)
  22. {
  23. serializeContext->Class<PropertySlotComponent, SlotComponent>()
  24. ->Version(1)
  25. ->Field("PropertyId", &PropertySlotComponent::m_propertyId)
  26. ;
  27. }
  28. }
  29. AZ::Entity* PropertySlotComponent::CreatePropertySlot(const AZ::EntityId& nodeId, const AZ::Crc32& propertyId, const SlotConfiguration& slotConfiguration)
  30. {
  31. AZ::Entity* entity = SlotComponent::CreateCoreSlotEntity();
  32. entity->CreateComponent<PropertySlotComponent>(propertyId, slotConfiguration);
  33. entity->CreateComponent<PropertySlotLayoutComponent>();
  34. AZStd::string styleClass;
  35. StyledEntityRequestBus::EventResult(styleClass, nodeId, &StyledEntityRequests::GetClass);
  36. entity->CreateComponent<StylingComponent>(Styling::Elements::PropertySlot, nodeId, styleClass);
  37. SlotConnectionFilterComponent* connectionFilter = entity->CreateComponent<SlotConnectionFilterComponent>();
  38. // We don't want to accept any connections.
  39. connectionFilter->AddFilter(aznew SlotTypeFilter(ConnectionFilterType::Include));
  40. return entity;
  41. }
  42. PropertySlotComponent::PropertySlotComponent()
  43. : SlotComponent(SlotTypes::PropertySlot)
  44. {
  45. if (m_slotConfiguration.m_slotGroup == SlotGroups::Invalid)
  46. {
  47. m_slotConfiguration.m_slotGroup = SlotGroups::PropertyGroup;
  48. }
  49. }
  50. PropertySlotComponent::PropertySlotComponent(const AZ::Crc32& propertyId, const SlotConfiguration& slotConfiguration)
  51. : SlotComponent(SlotTypes::PropertySlot, slotConfiguration)
  52. , m_propertyId(propertyId)
  53. {
  54. if (m_slotConfiguration.m_slotGroup == SlotGroups::Invalid)
  55. {
  56. m_slotConfiguration.m_slotGroup = SlotGroups::PropertyGroup;
  57. }
  58. }
  59. PropertySlotComponent::~PropertySlotComponent()
  60. {
  61. }
  62. void PropertySlotComponent::Init()
  63. {
  64. SlotComponent::Init();
  65. }
  66. void PropertySlotComponent::Activate()
  67. {
  68. SlotComponent::Activate();
  69. PropertySlotRequestBus::Handler::BusConnect(GetEntityId());
  70. }
  71. void PropertySlotComponent::Deactivate()
  72. {
  73. SlotComponent::Deactivate();
  74. PropertySlotRequestBus::Handler::BusDisconnect();
  75. }
  76. int PropertySlotComponent::GetLayoutPriority() const
  77. {
  78. // Going to want property slots to always be at the top of a display group.
  79. return std::numeric_limits<int>().max();
  80. }
  81. void PropertySlotComponent::SetLayoutPriority(int priority)
  82. {
  83. AZ_UNUSED(priority);
  84. }
  85. const AZ::Crc32& PropertySlotComponent::GetPropertyId() const
  86. {
  87. return m_propertyId;
  88. }
  89. AZ::Entity* PropertySlotComponent::ConstructConnectionEntity(const Endpoint&, const Endpoint&, bool)
  90. {
  91. AZ_Error("Graph Canvas", false, "Property slots cannot have connections.");
  92. return nullptr;
  93. }
  94. }