MotionSetMotionIdHandler.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
  11. #include <QWidget>
  12. #include <QPushButton>
  13. #include <QGridLayout>
  14. #include <QLabel>
  15. #include <AzQtComponents/Components/Widgets/SpinBox.h>
  16. #include <AzCore/std/utils.h>
  17. #include <AzCore/std/smart_ptr/unique_ptr.h>
  18. #include <AzCore/std/containers/list.h>
  19. #include <EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/MotionSetSelectionWindow.h>
  20. #endif
  21. namespace EMotionFX
  22. {
  23. class AnimGraphMotionNode;
  24. class IRandomMotionSelectionDataContainer
  25. {
  26. public:
  27. virtual float GetWeight(size_t id) const = 0;
  28. virtual float GetWeightSum() const = 0;
  29. virtual const AZStd::string& GetMotionId(size_t id) const = 0;
  30. };
  31. class MotionSelectionIdWidgetController
  32. {
  33. public:
  34. AZ_CLASS_ALLOCATOR_DECL
  35. MotionSelectionIdWidgetController(QGridLayout* layout,
  36. int graphicRowIndex,
  37. const IRandomMotionSelectionDataContainer* dataContainer,
  38. bool displayMotionSelectionWeight);
  39. size_t GetId() const;
  40. void Hide();
  41. void Show();
  42. void Update();
  43. void UpdateId(size_t id);
  44. void DestroyGuis();
  45. QLabel* m_labelMotion;
  46. AzQtComponents::DoubleSpinBox* m_randomWeightSpinbox;
  47. QLineEdit* m_normalizedProbabilityText;
  48. QPushButton* m_removeButton;
  49. static void ResetDisplayedRoundingError();
  50. private:
  51. size_t m_id = std::numeric_limits<size_t>::max();
  52. bool m_displayMotionSelectionWeight = false;
  53. const IRandomMotionSelectionDataContainer* m_dataContainer = nullptr;
  54. static float s_displayedRoundingError;
  55. };
  56. class MotionSetMotionIdPicker
  57. : public QWidget
  58. , public IRandomMotionSelectionDataContainer
  59. {
  60. Q_OBJECT
  61. public:
  62. AZ_CLASS_ALLOCATOR_DECL
  63. MotionSetMotionIdPicker(QWidget* parent, bool displaySelectionWeights);
  64. ~MotionSetMotionIdPicker();
  65. void SetMotionIds(const AZStd::vector<AZStd::string>& motions);
  66. void SetMotions(const AZStd::vector<AZStd::pair<AZStd::string, float>>& motions);
  67. const AZStd::vector<AZStd::pair<AZStd::string, float>>& GetMotions() const;
  68. AZStd::vector<AZStd::string> GetMotionIds() const;
  69. /// IDataContainer Implementation
  70. float GetWeight(size_t id) const override;
  71. float GetWeightSum() const override;
  72. const AZStd::string& GetMotionId(size_t id) const override;
  73. signals:
  74. void SelectionChanged();
  75. private slots:
  76. void OnPickClicked();
  77. void OnPickDialogAccept();
  78. void OnPickDialogReject();
  79. private:
  80. void InitializeWidgets();
  81. void HandleSelectedMotionsUpdate(const AZStd::vector<AZStd::string>& motionIds);
  82. void OnRemoveMotion(size_t id);
  83. void OnRandomWeightChanged(size_t id, double value);
  84. void UpdateGui();
  85. AZStd::list<AZStd::unique_ptr<MotionSelectionIdWidgetController>> m_motionWidgetControllers;
  86. /// Contains a list of pair of which the key is the motion Id, and the value is the random selection weight
  87. /// Please Note: this list contains the weights that are displayed in the GUIs, the stored data will contain
  88. /// the cumulative probability
  89. AZStd::vector<AZStd::pair<AZStd::string, float>> m_motions;
  90. QPushButton* m_pickButton = nullptr;
  91. QWidget* m_containerWidget = nullptr;
  92. QLineEdit* m_addMotionsLabel = nullptr;
  93. QGridLayout* m_motionsLayout = nullptr;
  94. float m_weightsSum = 0.0f;
  95. bool m_displaySelectionWeights = false;
  96. static const float s_defaultWeight;
  97. EMStudio::MotionSetSelectionWindow* m_motionPickWindow = nullptr;
  98. };
  99. class MotionIdRandomSelectionWeightsHandler
  100. : public QObject
  101. , public AzToolsFramework::PropertyHandler<AZStd::vector<AZStd::pair<AZStd::string, float>>, MotionSetMotionIdPicker>
  102. {
  103. Q_OBJECT
  104. public:
  105. AZ_CLASS_ALLOCATOR_DECL
  106. AZ::u32 GetHandlerName() const override;
  107. QWidget* CreateGUI(QWidget* parent) override;
  108. bool AutoDelete() const override { return false; }
  109. void ConsumeAttribute(MotionSetMotionIdPicker* widget, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName) override;
  110. void WriteGUIValuesIntoProperty(size_t index, MotionSetMotionIdPicker* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* node) override;
  111. bool ReadValuesIntoGUI(size_t index, MotionSetMotionIdPicker* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* node) override;
  112. };
  113. class MotionSetMultiMotionIdHandler
  114. : public QObject
  115. , public AzToolsFramework::PropertyHandler<AZStd::vector<AZStd::string>, MotionSetMotionIdPicker>
  116. {
  117. Q_OBJECT
  118. public:
  119. AZ_CLASS_ALLOCATOR_DECL
  120. AZ::u32 GetHandlerName() const override;
  121. QWidget* CreateGUI(QWidget* parent) override;
  122. bool AutoDelete() const override { return false; }
  123. void ConsumeAttribute(MotionSetMotionIdPicker* widget, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName) override;
  124. void WriteGUIValuesIntoProperty(size_t index, MotionSetMotionIdPicker* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* node) override;
  125. bool ReadValuesIntoGUI(size_t index, MotionSetMotionIdPicker* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* node) override;
  126. };
  127. } // namespace EMotionFX