CollapsedNodeGroupComponent.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. #pragma once
  9. #include <QParallelAnimationGroup>
  10. #include <QPropertyAnimation>
  11. #include <AzCore/Component/Component.h>
  12. #include <GraphCanvas/Components/GeometryBus.h>
  13. #include <GraphCanvas/Components/GraphCanvasPropertyBus.h>
  14. #include <GraphCanvas/Components/Nodes/Comment/CommentBus.h>
  15. #include <GraphCanvas/Components/Nodes/Group/NodeGroupBus.h>
  16. #include <GraphCanvas/Components/Nodes/NodeBus.h>
  17. #include <GraphCanvas/Components/Nodes/NodeConfiguration.h>
  18. #include <GraphCanvas/Components/SceneBus.h>
  19. #include <GraphCanvas/Components/VisualBus.h>
  20. #include <GraphCanvas/Utils/GraphUtils.h>
  21. #include <GraphCanvas/Utils/StateControllers/StackStateController.h>
  22. #include <GraphCanvas/Editor/EditorTypes.h>
  23. namespace GraphCanvas
  24. {
  25. class RedirectedSlotWatcher
  26. : public NodeNotificationBus::MultiHandler
  27. {
  28. public:
  29. RedirectedSlotWatcher() = default;
  30. ~RedirectedSlotWatcher();
  31. void ConfigureWatcher(const AZ::EntityId& collapsedGroupId);
  32. void RegisterEndpoint(const Endpoint& sourceEndpoint, const Endpoint& remappedEndpoint);
  33. // NodeNotificationBus
  34. void OnNodeAboutToBeDeleted() override;
  35. void OnSlotRemovedFromNode(const AZ::EntityId& slotId) override;
  36. ////
  37. private:
  38. void OnEndpointRemoved(Endpoint endpoint);
  39. AZStd::unordered_map<Endpoint, Endpoint> m_endpointMapping;
  40. AZ::EntityId m_collapsedGroupId;
  41. };
  42. // Node that represents a Node Group that has been collapsed.
  43. //
  44. // Will handle generating remapping the connections that cross over the visual border.
  45. class CollapsedNodeGroupComponent
  46. : public GraphCanvasPropertyComponent
  47. , public SceneMemberNotificationBus::Handler
  48. , public NodeNotificationBus::Handler
  49. , public CommentNotificationBus::Handler
  50. , public GeometryNotificationBus::Handler
  51. , public SceneNotificationBus::Handler
  52. , public VisualNotificationBus::Handler
  53. , public CollapsedNodeGroupRequestBus::Handler
  54. , public GroupableSceneMemberNotificationBus::Handler
  55. , public AZ::SystemTickBus::Handler
  56. {
  57. public:
  58. AZ_COMPONENT(CollapsedNodeGroupComponent, "{FFA874A1-0D14-4BF9-932D-FE1A285506E6}", GraphCanvasPropertyComponent);
  59. static void Reflect(AZ::ReflectContext*);
  60. static AZ::Entity* CreateCollapsedNodeGroupEntity(const CollapsedNodeGroupConfiguration& config);
  61. CollapsedNodeGroupComponent();
  62. CollapsedNodeGroupComponent(const CollapsedNodeGroupConfiguration& config);
  63. ~CollapsedNodeGroupComponent() override;
  64. // Component
  65. void Init() override;
  66. void Activate() override;
  67. void Deactivate() override;
  68. ////
  69. // SystemTickBus
  70. void OnSystemTick() override;
  71. ////
  72. // NodeNotifications
  73. void OnAddedToScene(const GraphId& graphId) override;
  74. void OnRemovedFromScene(const GraphId& graphId) override;
  75. ////
  76. // GeometryNotifications
  77. void OnBoundsChanged() override;
  78. void OnPositionChanged(const AZ::EntityId& targetEntity, const AZ::Vector2& position) override;
  79. ////
  80. // SceneNotifications
  81. void OnSceneMemberDragBegin() override;
  82. void OnSceneMemberDragComplete() override;
  83. ////
  84. // CommentNotifications
  85. void OnCommentChanged(const AZStd::string& comment) override;
  86. void OnBackgroundColorChanged(const AZ::Color& color) override;
  87. ////
  88. // VisualNotifications
  89. bool OnMouseDoubleClick(const QGraphicsSceneMouseEvent* mouseEvent) override;
  90. ////
  91. // CollapsedNodeGroupRequests
  92. void ExpandGroup() override;
  93. AZ::EntityId GetSourceGroup() const override;
  94. AZStd::vector< Endpoint > GetRedirectedEndpoints() const override;
  95. void ForceEndpointRedirection(const AZStd::vector< Endpoint >& endpoints) override;
  96. ////
  97. // GroupableSceneMemberNotifications
  98. void OnGroupChanged() override;
  99. ////
  100. // SceneMemberNotifications
  101. void OnSceneMemberHidden() override;
  102. void OnSceneMemberShown() override;
  103. ////
  104. private:
  105. void SetupGroupPosition(const GraphId& graphId);
  106. void CreateOccluder(const GraphId& graphId, const AZ::EntityId& initialElement);
  107. void TriggerExpandAnimation();
  108. void TriggerCollapseAnimation();
  109. void AnimateOccluder(bool isExpanding);
  110. void ConstructGrouping(const GraphId& graphId);
  111. void ReverseGrouping(const GraphId& graphId);
  112. void MoveGroupedElementsBy(const AZ::Vector2& offset);
  113. void MoveSubGraphBy(const GraphSubGraph& subGraph, const AZ::Vector2& offset);
  114. void OnAnimationFinished();
  115. SlotId CreateSlotRedirection(const GraphId& graphId, const Endpoint& slotId);
  116. SlotId InitializeRedirectionSlot(const SlotRedirectionConfiguration& configuration);
  117. void UpdateSystemTickBus();
  118. AZStd::unordered_set< Endpoint > m_forcedRedirections;
  119. AZStd::vector< SlotRedirectionConfiguration > m_redirections;
  120. SubGraphParsingResult m_containedSubGraphs;
  121. AZ::EntityId m_nodeGroupId;
  122. // Counter for how many frames to delay before beginning animations
  123. int m_animationDelayCounter;
  124. // Indicates if we are expanding in our animation or not.
  125. bool m_isExpandingOccluderAnimation;
  126. // Counter for how many frames to delay before destroying the occluder after the expansion animation.
  127. int m_occluderDestructionCounter;
  128. bool m_unhideOnAnimationComplete;
  129. bool m_deleteObjects;
  130. bool m_positionDirty;
  131. RedirectedSlotWatcher m_redirectedSlotWatcher;
  132. StackStateController<bool> m_ignorePositionChanges;
  133. StateSetter<bool> m_memberHiddenStateSetter;
  134. StateSetter<bool> m_memberDraggedStateSetter;
  135. AZ::Vector2 m_previousPosition;
  136. GraphicsEffectId m_effectId;
  137. QParallelAnimationGroup m_occluderAnimation;
  138. QPropertyAnimation* m_sizeAnimation;
  139. QPropertyAnimation* m_positionAnimation;
  140. QPropertyAnimation* m_opacityAnimation;
  141. };
  142. }