AnimGraphParameterHandler.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 <EMotionFX/Source/AnimGraph.h>
  11. #include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
  12. #include <QWidget>
  13. #include <QPushButton>
  14. #endif
  15. namespace EMotionFX
  16. {
  17. class ObjectAffectedByParameterChanges;
  18. // Picker that allows to select one or more parameters (depending on mask mode) and affect the ports of the node
  19. // This Picker and its handlers are used by the BlendTreeParameterNode and the AnimGraphReferenceNode.
  20. //
  21. class AnimGraphParameterPicker
  22. : public QWidget
  23. {
  24. Q_OBJECT // AUTOMOC
  25. public:
  26. AZ_CLASS_ALLOCATOR_DECL
  27. AnimGraphParameterPicker(QWidget* parent, bool singleSelection = false, bool parameterMaskMode = false);
  28. void SetFilterTypes(const AZStd::vector<AZ::TypeId>& filterTypes) { m_filterTypes = filterTypes; }
  29. void SetAnimGraph(AnimGraph* animGraph) { m_animGraph = animGraph; }
  30. void SetObjectAffectedByParameterChanges(ObjectAffectedByParameterChanges* affectedObject);
  31. // Called to initialize the parameter names in the UI from values in the object
  32. void InitializeParameterNames(const AZStd::vector<AZStd::string>& parameterNames);
  33. // Called when the UI wants to update the parameter names
  34. void UpdateParameterNames(const AZStd::vector<AZStd::string>& parameterNames);
  35. const AZStd::vector<AZStd::string>& GetParameterNames() const;
  36. void SetSingleParameterName(const AZStd::string& parameterName);
  37. const AZStd::string GetSingleParameterName() const;
  38. signals:
  39. void ParametersChanged(const AZStd::vector<AZStd::string>& newParameters);
  40. private slots:
  41. void OnPickClicked();
  42. void OnResetClicked();
  43. void OnShrinkClicked();
  44. private:
  45. void UpdateInterface();
  46. AnimGraph* m_animGraph;
  47. ObjectAffectedByParameterChanges* m_affectedByParameterChanges;
  48. AZStd::vector<AZStd::string> m_parameterNames;
  49. AZStd::vector<AZ::TypeId> m_filterTypes;
  50. QPushButton* m_pickButton;
  51. QPushButton* m_resetButton;
  52. QPushButton* m_shrinkButton;
  53. bool m_singleSelection;
  54. bool m_parameterMaskMode;
  55. };
  56. class AnimGraphSingleParameterHandler
  57. : public QObject
  58. , public AzToolsFramework::PropertyHandler<AZStd::string, AnimGraphParameterPicker>
  59. {
  60. Q_OBJECT // AUTOMOC
  61. public:
  62. AZ_CLASS_ALLOCATOR_DECL
  63. AnimGraphSingleParameterHandler();
  64. AZ::u32 GetHandlerName() const override;
  65. QWidget* CreateGUI(QWidget* parent) override;
  66. bool AutoDelete() const override { return false; }
  67. void ConsumeAttribute(AnimGraphParameterPicker* widget, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName) override;
  68. void WriteGUIValuesIntoProperty(size_t index, AnimGraphParameterPicker* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* node) override;
  69. bool ReadValuesIntoGUI(size_t index, AnimGraphParameterPicker* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* node) override;
  70. protected:
  71. AnimGraph* m_animGraph;
  72. };
  73. class AnimGraphSingleNumberParameterHandler
  74. : public AnimGraphSingleParameterHandler
  75. {
  76. Q_OBJECT // AUTOMOC
  77. public:
  78. AZ_CLASS_ALLOCATOR_DECL
  79. AnimGraphSingleNumberParameterHandler();
  80. AZ::u32 GetHandlerName() const override;
  81. QWidget* CreateGUI(QWidget* parent) override;
  82. };
  83. class AnimGraphSingleVector2ParameterHandler
  84. : public AnimGraphSingleParameterHandler
  85. {
  86. Q_OBJECT // AUTOMOC
  87. public:
  88. AZ_CLASS_ALLOCATOR_DECL
  89. AnimGraphSingleVector2ParameterHandler();
  90. AZ::u32 GetHandlerName() const override;
  91. QWidget* CreateGUI(QWidget* parent) override;
  92. };
  93. class AnimGraphMultipleParameterHandler
  94. : public QObject
  95. , public AzToolsFramework::PropertyHandler<AZStd::vector<AZStd::string>, AnimGraphParameterPicker>
  96. {
  97. Q_OBJECT // AUTOMOC
  98. public:
  99. AZ_CLASS_ALLOCATOR_DECL
  100. AnimGraphMultipleParameterHandler();
  101. AZ::u32 GetHandlerName() const override;
  102. QWidget* CreateGUI(QWidget* parent) override;
  103. bool AutoDelete() const override { return false; }
  104. void ConsumeAttribute(AnimGraphParameterPicker* widget, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName) override;
  105. void WriteGUIValuesIntoProperty(size_t index, AnimGraphParameterPicker* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* node) override;
  106. bool ReadValuesIntoGUI(size_t index, AnimGraphParameterPicker* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* node) override;
  107. protected:
  108. AnimGraph* m_animGraph;
  109. };
  110. } // namespace EMotionFX