NodeUtils.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 "NodeUtils.h"
  9. #include <GraphCanvas/Components/Nodes/NodeBus.h>
  10. #include <GraphCanvas/Components/Slots/SlotBus.h>
  11. #include <GraphCanvas/Components/DynamicOrderingDynamicSlotComponent.h>
  12. #include <ScriptCanvas/Core/ModifiableDatumView.h>
  13. #include <ScriptCanvas/Core/NodeBus.h>
  14. namespace ScriptCanvasEditor::Nodes
  15. {
  16. void UpdateSlotDatumLabel(const AZ::EntityId& graphCanvasNodeId, ScriptCanvas::SlotId scSlotId, const AZStd::string& name)
  17. {
  18. AZStd::any* userData = nullptr;
  19. GraphCanvas::NodeRequestBus::EventResult(userData, graphCanvasNodeId, &GraphCanvas::NodeRequests::GetUserData);
  20. AZ::EntityId scNodeEntityId = userData && userData->is<AZ::EntityId>() ? *AZStd::any_cast<AZ::EntityId>(userData) : AZ::EntityId();
  21. if (scNodeEntityId.IsValid())
  22. {
  23. ScriptCanvas::ModifiableDatumView datumView;
  24. ScriptCanvas::NodeRequestBus::Event(scNodeEntityId, &ScriptCanvas::NodeRequests::FindModifiableDatumView, scSlotId, datumView);
  25. datumView.RelabelDatum(name);
  26. }
  27. }
  28. void UpdateSlotDatumLabels(AZ::EntityId graphCanvasNodeId)
  29. {
  30. AZStd::vector<AZ::EntityId> graphCanvasSlotIds;
  31. GraphCanvas::NodeRequestBus::EventResult(graphCanvasSlotIds, graphCanvasNodeId, &GraphCanvas::NodeRequests::GetSlotIds);
  32. for (AZ::EntityId graphCanvasSlotId : graphCanvasSlotIds)
  33. {
  34. AZStd::any* slotUserData{};
  35. GraphCanvas::SlotRequestBus::EventResult(slotUserData, graphCanvasSlotId, &GraphCanvas::SlotRequests::GetUserData);
  36. if (auto scriptCanvasSlotId = AZStd::any_cast<ScriptCanvas::SlotId>(slotUserData))
  37. {
  38. AZStd::string slotName;
  39. GraphCanvas::SlotRequestBus::EventResult(slotName, graphCanvasSlotId, &GraphCanvas::SlotRequests::GetName);
  40. UpdateSlotDatumLabel(graphCanvasNodeId, *scriptCanvasSlotId, slotName);
  41. }
  42. }
  43. }
  44. }