DynamicOrderingDynamicSlotComponent.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 <GraphCanvas/Components/Nodes/NodeBus.h>
  9. #include <ScriptCanvas/Core/Slot.h>
  10. #include <Editor/GraphCanvas/Components/DynamicOrderingDynamicSlotComponent.h>
  11. #include <Editor/Include/ScriptCanvas/GraphCanvas/MappingBus.h>
  12. namespace ScriptCanvasEditor
  13. {
  14. ////////////////////////////////////////
  15. // DynamicOrderingDynamicSlotComponent
  16. ////////////////////////////////////////
  17. void DynamicOrderingDynamicSlotComponent::Reflect(AZ::ReflectContext* reflectContext)
  18. {
  19. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflectContext);
  20. if (serializeContext)
  21. {
  22. serializeContext->Class<DynamicOrderingDynamicSlotComponent, DynamicSlotComponent>()
  23. ->Version(0)
  24. ;
  25. }
  26. }
  27. DynamicOrderingDynamicSlotComponent::DynamicOrderingDynamicSlotComponent()
  28. : DynamicSlotComponent()
  29. , m_deserialized(false)
  30. {
  31. }
  32. DynamicOrderingDynamicSlotComponent::DynamicOrderingDynamicSlotComponent(GraphCanvas::SlotGroup slotGroup)
  33. : DynamicSlotComponent(slotGroup)
  34. , m_deserialized(false)
  35. {
  36. }
  37. void DynamicOrderingDynamicSlotComponent::OnSystemTick()
  38. {
  39. if (GetScriptCanvasNodeId().IsValid())
  40. {
  41. SlotMappingRequests* requestInterface = SlotMappingRequestBus::FindFirstHandler(GetEntityId());
  42. if (requestInterface)
  43. {
  44. AZStd::vector<ScriptCanvas::Slot*> scriptSlots;
  45. ScriptCanvas::NodeRequestBus::EventResult(scriptSlots, GetScriptCanvasNodeId(), &ScriptCanvas::NodeRequests::ModAllSlots);
  46. for (int i = 0; i < scriptSlots.size(); ++i)
  47. {
  48. // Higher means it goes first. So we need to inverse our number.
  49. int priority = static_cast<int>(scriptSlots.size()) - i;
  50. ScriptCanvas::SlotId scriptCanvasSlotId = scriptSlots[i]->GetId();
  51. GraphCanvas::SlotId graphCanvasSlotId = requestInterface->MapToGraphCanvasId(scriptCanvasSlotId);
  52. if (graphCanvasSlotId.IsValid())
  53. {
  54. GraphCanvas::SlotRequestBus::Event(graphCanvasSlotId, &GraphCanvas::SlotRequests::SetLayoutPriority, priority);
  55. }
  56. }
  57. }
  58. }
  59. AZ::SystemTickBus::Handler::BusDisconnect();
  60. }
  61. void DynamicOrderingDynamicSlotComponent::OnSceneSet(const AZ::EntityId& sceneId)
  62. {
  63. DynamicSlotComponent::OnSceneSet(sceneId);
  64. if (m_deserialized)
  65. {
  66. AZ::SystemTickBus::Handler::BusConnect();
  67. }
  68. }
  69. void DynamicOrderingDynamicSlotComponent::OnSceneMemberDeserialized(const AZ::EntityId& graphId, const GraphCanvas::GraphSerialization& serializationTarget)
  70. {
  71. DynamicSlotComponent::OnSceneMemberDeserialized(graphId, serializationTarget);
  72. m_deserialized = true;
  73. }
  74. void DynamicOrderingDynamicSlotComponent::OnSlotsReordered()
  75. {
  76. DynamicSlotComponent::OnSlotsReordered();
  77. AZ::SystemTickBus::Handler::BusConnect();
  78. }
  79. void DynamicOrderingDynamicSlotComponent::StopQueueSlotUpdates()
  80. {
  81. DynamicSlotComponent::StopQueueSlotUpdates();
  82. if (GetScriptCanvasNodeId().IsValid())
  83. {
  84. OnSystemTick();
  85. }
  86. }
  87. void DynamicOrderingDynamicSlotComponent::ConfigureGraphCanvasSlot([[maybe_unused]] const ScriptCanvas::Slot* slot, [[maybe_unused]] const GraphCanvas::SlotId& graphCanvasSlotId)
  88. {
  89. AZ::SystemTickBus::Handler::BusConnect();
  90. }
  91. }