3
0

ScriptCanvasContextMenus.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. #if !defined(Q_MOC_RUN)
  10. #include <AzCore/Component/Entity.h>
  11. #include <AzCore/Math/Vector2.h>
  12. #include <QMenu>
  13. #include <QWidgetAction>
  14. #include <GraphCanvas/Widgets/EditorContextMenu/EditorContextMenu.h>
  15. #include <GraphCanvas/Widgets/EditorContextMenu/ContextMenus/SceneContextMenu.h>
  16. #include <GraphCanvas/Widgets/EditorContextMenu/ContextMenus/ConnectionContextMenu.h>
  17. #include <GraphCanvas/Widgets/EditorContextMenu/ContextMenus/SlotContextMenu.h>
  18. #include <GraphCanvas/Widgets/EditorContextMenu/ContextMenus/NodeContextMenu.h>
  19. #include <GraphCanvas/Widgets/EditorContextMenu/ContextMenuActions/SceneMenuActions/SceneContextMenuAction.h>
  20. #include <GraphCanvas/Widgets/EditorContextMenu/ContextMenuActions/SlotMenuActions/SlotContextMenuAction.h>
  21. #include <GraphCanvas/Widgets/EditorContextMenu/ContextMenuActions/NodeMenuActions/NodeContextMenuAction.h>
  22. #endif
  23. namespace ScriptCanvasEditor
  24. {
  25. class NodePaletteModel;
  26. //////////////////
  27. // CustomActions
  28. //////////////////
  29. class EndpointSelectionAction
  30. : public QAction
  31. {
  32. Q_OBJECT
  33. public:
  34. AZ_CLASS_ALLOCATOR(EndpointSelectionAction, AZ::SystemAllocator);
  35. EndpointSelectionAction(const GraphCanvas::Endpoint& endpoint);
  36. ~EndpointSelectionAction() = default;
  37. const GraphCanvas::Endpoint& GetEndpoint() const;
  38. private:
  39. GraphCanvas::Endpoint m_endpoint;
  40. };
  41. class RemoveUnusedVariablesMenuAction
  42. : public GraphCanvas::SceneContextMenuAction
  43. {
  44. public:
  45. AZ_CLASS_ALLOCATOR(RemoveUnusedVariablesMenuAction, AZ::SystemAllocator);
  46. RemoveUnusedVariablesMenuAction(QObject* parent);
  47. virtual ~RemoveUnusedVariablesMenuAction() = default;
  48. bool IsInSubMenu() const override;
  49. AZStd::string GetSubMenuPath() const override;
  50. using GraphCanvas::SceneContextMenuAction::RefreshAction;
  51. void RefreshAction(const GraphCanvas::GraphId& graphId, const AZ::EntityId& targetId) override;
  52. using GraphCanvas::SceneContextMenuAction::TriggerAction;
  53. GraphCanvas::ContextMenuAction::SceneReaction TriggerAction(const GraphCanvas::GraphId& graphId, const AZ::Vector2& scenePos) override;
  54. };
  55. class ConvertVariableNodeToReferenceAction
  56. : public GraphCanvas::ContextMenuAction
  57. {
  58. Q_OBJECT
  59. public:
  60. AZ_CLASS_ALLOCATOR(ConvertVariableNodeToReferenceAction, AZ::SystemAllocator);
  61. ConvertVariableNodeToReferenceAction(QObject* parent);
  62. virtual ~ConvertVariableNodeToReferenceAction() = default;
  63. GraphCanvas::ActionGroupId GetActionGroupId() const override;
  64. using GraphCanvas::ContextMenuAction::RefreshAction;
  65. void RefreshAction(const GraphCanvas::GraphId& graphId, const AZ::EntityId& targetId) override;
  66. using GraphCanvas::ContextMenuAction::TriggerAction;
  67. GraphCanvas::ContextMenuAction::SceneReaction TriggerAction(const GraphCanvas::GraphId& graphId, const AZ::Vector2& scenePos) override;
  68. private:
  69. AZ::EntityId m_targetId;
  70. };
  71. class SlotManipulationMenuAction
  72. : public GraphCanvas::ContextMenuAction
  73. {
  74. Q_OBJECT
  75. public:
  76. AZ_CLASS_ALLOCATOR(SlotManipulationMenuAction, AZ::SystemAllocator);
  77. SlotManipulationMenuAction(AZStd::string_view actionName, QObject* parent);
  78. static ScriptCanvas::Slot* GetScriptCanvasSlot(const GraphCanvas::Endpoint& endpoint) ;
  79. };
  80. class ConvertReferenceToVariableNodeAction
  81. : public SlotManipulationMenuAction
  82. {
  83. Q_OBJECT
  84. public:
  85. AZ_CLASS_ALLOCATOR(ConvertReferenceToVariableNodeAction, AZ::SystemAllocator);
  86. ConvertReferenceToVariableNodeAction(QObject* parent);
  87. virtual ~ConvertReferenceToVariableNodeAction() = default;
  88. GraphCanvas::ActionGroupId GetActionGroupId() const override;
  89. using SlotManipulationMenuAction::RefreshAction;
  90. void RefreshAction(const GraphCanvas::GraphId& graphId, const AZ::EntityId& targetId) override;
  91. using SlotManipulationMenuAction::TriggerAction;
  92. GraphCanvas::ContextMenuAction::SceneReaction TriggerAction(const GraphCanvas::GraphId& graphId, const AZ::Vector2& scenePos) override;
  93. private:
  94. AZ::EntityId m_targetId;
  95. };
  96. class ExposeSlotMenuAction
  97. : public GraphCanvas::SlotContextMenuAction
  98. {
  99. public:
  100. AZ_CLASS_ALLOCATOR(ExposeSlotMenuAction, AZ::SystemAllocator);
  101. ExposeSlotMenuAction(QObject* parent);
  102. virtual ~ExposeSlotMenuAction() = default;
  103. using GraphCanvas::SlotContextMenuAction::RefreshAction;
  104. void RefreshAction(const GraphCanvas::GraphId& graphId, const AZ::EntityId& targetId) override;
  105. using GraphCanvas::SlotContextMenuAction::TriggerAction;
  106. GraphCanvas::ContextMenuAction::SceneReaction TriggerAction(const GraphCanvas::GraphId& graphId, const AZ::Vector2& scenePos) override;
  107. protected:
  108. void CreateNodeling(const GraphCanvas::GraphId& graphId, AZ::EntityId scriptCanvasGraphId, GraphCanvas::GraphId slotId, const AZ::Vector2& scenePos, GraphCanvas::ConnectionType connectionType);
  109. };
  110. class SetDataSlotTypeMenuAction
  111. : public GraphCanvas::SlotContextMenuAction
  112. {
  113. public:
  114. AZ_CLASS_ALLOCATOR(SetDataSlotTypeMenuAction, AZ::SystemAllocator);
  115. explicit SetDataSlotTypeMenuAction(QObject* parent);
  116. virtual ~SetDataSlotTypeMenuAction() = default;
  117. static bool IsSupportedSlotType(const AZ::EntityId& slotId);
  118. using GraphCanvas::SlotContextMenuAction::RefreshAction;
  119. void RefreshAction(const GraphCanvas::GraphId& graphId, const AZ::EntityId& targetId) override;
  120. using GraphCanvas::SlotContextMenuAction::TriggerAction;
  121. GraphCanvas::ContextMenuAction::SceneReaction TriggerAction(const GraphCanvas::GraphId& graphId, const AZ::Vector2& scenePos) override;
  122. private:
  123. ScriptCanvas::Slot* GetSlot(const GraphCanvas::GraphId& graphId, const AZ::EntityId& targetId);
  124. };
  125. //! Context Menu Action for Creating an AzEventHandler node from a data slot of a Behavior Method node
  126. //! which returns an AZ::Event<Params...> type
  127. class CreateAzEventHandlerSlotMenuAction
  128. : public GraphCanvas::SlotContextMenuAction
  129. {
  130. public:
  131. AZ_CLASS_ALLOCATOR(CreateAzEventHandlerSlotMenuAction, AZ::SystemAllocator);
  132. CreateAzEventHandlerSlotMenuAction(QObject* parent);
  133. using GraphCanvas::SlotContextMenuAction::RefreshAction;
  134. void RefreshAction(const GraphCanvas::GraphId& graphId, const AZ::EntityId& targetId) override;
  135. using GraphCanvas::SlotContextMenuAction::TriggerAction;
  136. GraphCanvas::ContextMenuAction::SceneReaction TriggerAction(const GraphCanvas::GraphId& graphId, const AZ::Vector2& scenePos) override;
  137. static const AZ::BehaviorMethod* FindBehaviorMethodWithAzEventReturn(const GraphCanvas::GraphId& graphId, AZ::EntityId targetId);
  138. protected:
  139. const AZ::BehaviorMethod* m_methodWithAzEventReturn{};
  140. GraphCanvas::Endpoint m_methodNodeAzEventEndpoint;
  141. };
  142. /////////////////
  143. // ContextMenus
  144. /////////////////
  145. class SceneContextMenu
  146. : public GraphCanvas::SceneContextMenu
  147. {
  148. Q_OBJECT
  149. public:
  150. AZ_CLASS_ALLOCATOR(SceneContextMenu, AZ::SystemAllocator);
  151. SceneContextMenu(const NodePaletteModel& nodePaletteModel, AzToolsFramework::AssetBrowser::AssetBrowserFilterModel* assetModel);
  152. ~SceneContextMenu() = default;
  153. void ResetSourceSlotFilter();
  154. void FilterForSourceSlot(const AZ::EntityId& scriptCanvasGraphId, const AZ::EntityId& sourceSlotId);
  155. // EditConstructContextMenu
  156. void OnRefreshActions(const GraphCanvas::GraphId& graphId, const AZ::EntityId& targetMemberId) override;
  157. ////
  158. void SetupDisplayForProposal();
  159. protected:
  160. AZ::EntityId m_sourceSlotId;
  161. };
  162. class ConnectionContextMenu
  163. : public GraphCanvas::ConnectionContextMenu
  164. {
  165. Q_OBJECT
  166. public:
  167. AZ_CLASS_ALLOCATOR(ConnectionContextMenu, AZ::SystemAllocator);
  168. ConnectionContextMenu(const NodePaletteModel& nodePaletteModel, AzToolsFramework::AssetBrowser::AssetBrowserFilterModel* assetModel);
  169. ~ConnectionContextMenu() = default;
  170. protected:
  171. void OnRefreshActions(const GraphCanvas::GraphId& graphId, const AZ::EntityId& targetMemberId);
  172. private:
  173. AZ::EntityId m_connectionId;
  174. };
  175. //////////////////////////
  176. // RenameFunctionDefinitionNode
  177. //////////////////////////
  178. class NodeDescriptorComponent;
  179. //! Context menu to rename a node
  180. class RenameFunctionDefinitionNodeAction
  181. : public GraphCanvas::NodeContextMenuAction
  182. {
  183. public:
  184. AZ_CLASS_ALLOCATOR(RenameFunctionDefinitionNodeAction, AZ::SystemAllocator);
  185. RenameFunctionDefinitionNodeAction(NodeDescriptorComponent* descriptor, QObject* parent);
  186. virtual ~RenameFunctionDefinitionNodeAction() = default;
  187. using GraphCanvas::NodeContextMenuAction::RefreshAction;
  188. void RefreshAction(const GraphCanvas::GraphId& graphId, const AZ::EntityId& targetId) override;
  189. using GraphCanvas::NodeContextMenuAction::TriggerAction;
  190. GraphCanvas::ContextMenuAction::SceneReaction TriggerAction(const GraphCanvas::GraphId& graphId, const AZ::Vector2& scenePos) override;
  191. NodeDescriptorComponent* m_descriptor;
  192. };
  193. }