ScriptCanvasAssetIdDataInterface.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 <GraphCanvas/Components/NodePropertyDisplay/AssetIdDataInterface.h>
  10. #include <Editor/GraphCanvas/DataInterfaces/ScriptCanvasDataInterface.h>
  11. #include <AzCore/Asset/AssetCommon.h>
  12. #include <AzCore/Slice/SliceAsset.h>
  13. #include <QWidget>
  14. #include <QMenu>
  15. #include <QAction>
  16. namespace ScriptCanvasEditor
  17. {
  18. class ScriptCanvasAssetIdDataInterface
  19. : public ScriptCanvasDataInterface<GraphCanvas::AssetIdDataInterface>
  20. {
  21. public:
  22. AZ_CLASS_ALLOCATOR(ScriptCanvasAssetIdDataInterface, AZ::SystemAllocator);
  23. ScriptCanvasAssetIdDataInterface(const AZ::EntityId& nodeId, const ScriptCanvas::SlotId& slotId)
  24. : ScriptCanvasDataInterface(nodeId, slotId)
  25. {
  26. m_assetType = AZ::Uuid::CreateNull();
  27. m_stringFilter = "*.*";
  28. }
  29. ~ScriptCanvasAssetIdDataInterface() = default;
  30. // AssetIdDataInterface
  31. AZ::Data::AssetId GetAssetId() const override
  32. {
  33. const ScriptCanvas::Datum* object = GetSlotObject();
  34. if (object)
  35. {
  36. const AZ::Data::AssetId* retVal = object->GetAs<AZ::Data::AssetId>();
  37. if (retVal)
  38. {
  39. return (*retVal);
  40. }
  41. }
  42. return AZ::Data::AssetId();
  43. }
  44. void SetAssetId(const AZ::Data::AssetId& assetId) override
  45. {
  46. ScriptCanvas::ModifiableDatumView datumView;
  47. ModifySlotObject(datumView);
  48. if (datumView.IsValid())
  49. {
  50. datumView.SetAs(assetId);
  51. PostUndoPoint();
  52. PropertyGridRequestBus::Broadcast(&PropertyGridRequests::RefreshPropertyGrid);
  53. }
  54. }
  55. AZ::Data::AssetType GetAssetType() const override
  56. {
  57. return m_assetType;
  58. }
  59. AZStd::string GetStringFilter() const override
  60. {
  61. return m_stringFilter;
  62. }
  63. void SetAssetType(AZ::Data::AssetType assetType) override
  64. {
  65. m_assetType = assetType;
  66. }
  67. void SetStringFilter(const AZStd::string& stringFilter) override
  68. {
  69. m_stringFilter = stringFilter;
  70. }
  71. AZ::Data::AssetType m_assetType;
  72. AZStd::string m_stringFilter;
  73. };
  74. }