3
0

NodeContextMenu.cpp 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. // AZ
  9. #include <AzToolsFramework/API/ToolsApplicationAPI.h>
  10. // Qt
  11. #include <QAction>
  12. // GraphModel
  13. #include <GraphModel/GraphModelBus.h>
  14. // Landscape Canvas
  15. #include <Editor/Core/Core.h>
  16. #include <Editor/Nodes/BaseNode.h>
  17. #include <Editor/Menus/NodeContextMenu.h>
  18. namespace LandscapeCanvasEditor
  19. {
  20. // Select the corresponding Entities in the Editor based on the selected nodes in our scene graph
  21. QAction* GetNodeSelectInEditorAction(const AZ::EntityId& sceneId, QObject* parent)
  22. {
  23. // Retrieve the selected nodes in our scene
  24. GraphModel::NodePtrList nodeList;
  25. GraphModelIntegration::GraphControllerRequestBus::EventResult(nodeList, sceneId, &GraphModelIntegration::GraphControllerRequests::GetSelectedNodes);
  26. // Iterate through the selected nodes to find their corresponding vegetation entities
  27. AzToolsFramework::EntityIdList vegetationEntityIdsToSelect;
  28. for (const auto& node : nodeList)
  29. {
  30. if (!node)
  31. {
  32. continue;
  33. }
  34. auto baseNodePtr = static_cast<LandscapeCanvas::BaseNode*>(node.get());
  35. vegetationEntityIdsToSelect.push_back(baseNodePtr->GetVegetationEntityId());
  36. }
  37. QAction* action = new QAction({ vegetationEntityIdsToSelect.size() > 1 ? QObject::tr("Select Entities in Editor") : QObject::tr("Select Entity in Editor") }, parent);
  38. QString tooltip = QObject::tr("Select the corresponding Entity/Entities in the Editor for the selected node(s) in the graph");
  39. action->setToolTip(tooltip);
  40. action->setStatusTip(tooltip);
  41. QObject::connect(action,
  42. &QAction::triggered,
  43. [vegetationEntityIdsToSelect](bool)
  44. {
  45. // Set the new selection
  46. AzToolsFramework::ToolsApplicationRequestBus::Broadcast(&AzToolsFramework::ToolsApplicationRequestBus::Events::SetSelectedEntities, vegetationEntityIdsToSelect);
  47. });
  48. return action;
  49. }
  50. NodeContextMenu::NodeContextMenu(const AZ::EntityId& sceneId, QWidget* parent)
  51. : GraphCanvas::NodeContextMenu(LandscapeCanvas::LANDSCAPE_CANVAS_EDITOR_ID, parent)
  52. {
  53. AddMenuAction(GetNodeSelectInEditorAction(sceneId, this));
  54. }
  55. void NodeContextMenu::OnRefreshActions(const GraphCanvas::GraphId& graphId, const AZ::EntityId& targetMemberId)
  56. {
  57. GraphCanvas::NodeContextMenu::OnRefreshActions(graphId, targetMemberId);
  58. // Don't allow cut/copy/paste/duplicate on our area extender nodes because they can't
  59. // exist without being wrapped on an area (e.g. spawner) node
  60. GraphModel::NodePtr node;
  61. GraphModelIntegration::GraphControllerRequestBus::EventResult(node, graphId, &GraphModelIntegration::GraphControllerRequests::GetNodeById, targetMemberId);
  62. if (node)
  63. {
  64. auto baseNodePtr = static_cast<LandscapeCanvas::BaseNode*>(node.get());
  65. if (baseNodePtr->IsAreaExtender())
  66. {
  67. m_editActionGroup.SetCopyEnabled(false);
  68. m_editActionGroup.SetCutEnabled(false);
  69. m_editActionGroup.SetDuplicateEnabled(false);
  70. m_editActionGroup.SetPasteEnabled(false);
  71. }
  72. }
  73. }
  74. }