BlendSpaceMotionHandler.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 <Editor/PropertyWidgets/BlendSpaceMotionHandler.h>
  9. #include <EMotionFX/Source/AnimGraphManager.h>
  10. #include <EMotionFX/Source/BlendSpaceManager.h>
  11. #include <EMotionFX/Source/EMotionFXManager.h>
  12. #include <QHBoxLayout>
  13. #include <QMessageBox>
  14. namespace EMotionFX
  15. {
  16. AZ_CLASS_ALLOCATOR_IMPL(BlendSpaceMotionPicker, EditorAllocator)
  17. AZ_CLASS_ALLOCATOR_IMPL(BlendSpaceMotionHandler, EditorAllocator)
  18. BlendSpaceMotionPicker::BlendSpaceMotionPicker(QWidget* parent)
  19. : QComboBox(parent)
  20. , m_blendSpaceNode(nullptr)
  21. {
  22. connect(this, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &BlendSpaceMotionPicker::OnCurrentIndexChanged);
  23. ReInit();
  24. }
  25. void BlendSpaceMotionPicker::SetBlendSpaceNode(BlendSpaceNode* blendSpaceNode)
  26. {
  27. m_blendSpaceNode = blendSpaceNode;
  28. ReInit();
  29. }
  30. void BlendSpaceMotionPicker::ReInit()
  31. {
  32. clear();
  33. if (m_blendSpaceNode)
  34. {
  35. const AZStd::vector<BlendSpaceNode::BlendSpaceMotion>& motions = m_blendSpaceNode->GetMotions();
  36. for (const BlendSpaceNode::BlendSpaceMotion& motion : motions)
  37. {
  38. addItem(motion.GetMotionId().c_str());
  39. }
  40. }
  41. }
  42. void BlendSpaceMotionPicker::OnCurrentIndexChanged([[maybe_unused]] int index)
  43. {
  44. emit MotionChanged();
  45. }
  46. void BlendSpaceMotionPicker::SetMotionId(AZStd::string motionId)
  47. {
  48. setCurrentText(motionId.c_str());
  49. }
  50. AZStd::string BlendSpaceMotionPicker::GetMotionId() const
  51. {
  52. return currentText().toUtf8().data();
  53. }
  54. //---------------------------------------------------------------------------------------------------------------------------------------------------------
  55. BlendSpaceMotionHandler::BlendSpaceMotionHandler()
  56. : QObject()
  57. , AzToolsFramework::PropertyHandler<AZStd::string, BlendSpaceMotionPicker>()
  58. , m_blendSpaceNode(nullptr)
  59. {
  60. }
  61. AZ::u32 BlendSpaceMotionHandler::GetHandlerName() const
  62. {
  63. return AZ_CRC("BlendSpaceMotion", 0x9be98fb7);
  64. }
  65. QWidget* BlendSpaceMotionHandler::CreateGUI(QWidget* parent)
  66. {
  67. BlendSpaceMotionPicker* picker = aznew BlendSpaceMotionPicker(parent);
  68. connect(picker, &BlendSpaceMotionPicker::MotionChanged, this, [picker]()
  69. {
  70. AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(
  71. &AzToolsFramework::PropertyEditorGUIMessages::Bus::Events::RequestWrite, picker);
  72. });
  73. return picker;
  74. }
  75. void BlendSpaceMotionHandler::ConsumeAttribute(BlendSpaceMotionPicker* GUI, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, [[maybe_unused]] const char* debugName)
  76. {
  77. if (attrValue)
  78. {
  79. m_blendSpaceNode = static_cast<BlendSpaceNode*>(attrValue->GetInstance());
  80. GUI->SetBlendSpaceNode(m_blendSpaceNode);
  81. }
  82. if (attrib == AZ::Edit::Attributes::ReadOnly)
  83. {
  84. bool value;
  85. if (attrValue->Read<bool>(value))
  86. {
  87. GUI->setEnabled(!value);
  88. }
  89. }
  90. }
  91. void BlendSpaceMotionHandler::WriteGUIValuesIntoProperty([[maybe_unused]] size_t index, BlendSpaceMotionPicker* GUI, property_t& instance, [[maybe_unused]] AzToolsFramework::InstanceDataNode* node)
  92. {
  93. instance = GUI->GetMotionId();
  94. }
  95. bool BlendSpaceMotionHandler::ReadValuesIntoGUI([[maybe_unused]] size_t index, BlendSpaceMotionPicker* GUI, const property_t& instance, [[maybe_unused]] AzToolsFramework::InstanceDataNode* node)
  96. {
  97. QSignalBlocker signalBlocker(GUI);
  98. GUI->SetMotionId(instance);
  99. return true;
  100. }
  101. } // namespace EMotionFX
  102. #include <Source/Editor/PropertyWidgets/moc_BlendSpaceMotionHandler.cpp>