3
0

MotionDataHandler.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 "MotionDataHandler.h"
  9. #include <Integration/Assets/MotionSetAsset.h>
  10. #include <Integration/System/SystemCommon.h>
  11. #include <EMotionFX/Source/MotionData/MotionDataFactory.h>
  12. #include <EMotionFX/Source/MotionData/MotionData.h>
  13. #include <EMotionFX/Source/MotionManager.h>
  14. #include <EMotionFX/Source/EMotionFXManager.h>
  15. namespace EMotionFX
  16. {
  17. AZ_CLASS_ALLOCATOR_IMPL(MotionDataHandler, EditorAllocator)
  18. AZ::u32 MotionDataHandler::GetHandlerName() const
  19. {
  20. return AZ_CRC("MotionData");
  21. }
  22. QWidget* MotionDataHandler::CreateGUI(QWidget* parent)
  23. {
  24. QComboBox* picker = new QComboBox(parent);
  25. connect(picker, &QComboBox::currentTextChanged, this, [picker]()
  26. {
  27. AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(
  28. &AzToolsFramework::PropertyEditorGUIMessages::Bus::Events::RequestWrite, picker);
  29. });
  30. return picker;
  31. }
  32. void MotionDataHandler::ConsumeAttribute(QComboBox* GUI, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, [[maybe_unused]] const char* debugName)
  33. {
  34. if (attrib == AZ::Edit::Attributes::ReadOnly)
  35. {
  36. bool value;
  37. if (attrValue->Read<bool>(value))
  38. {
  39. GUI->setEnabled(!value);
  40. }
  41. }
  42. }
  43. void MotionDataHandler::WriteGUIValuesIntoProperty(size_t index, QComboBox* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* node)
  44. {
  45. AZ_UNUSED(index);
  46. AZ_UNUSED(node);
  47. const int currentIndex = GUI->currentIndex();
  48. if (currentIndex == -1)
  49. {
  50. instance = m_typeIds[0];
  51. }
  52. else
  53. {
  54. instance = m_typeIds[currentIndex];
  55. }
  56. }
  57. bool MotionDataHandler::ReadValuesIntoGUI(size_t index, QComboBox* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* node)
  58. {
  59. AZ_UNUSED(index);
  60. AZ_UNUSED(node);
  61. QSignalBlocker signalBlocker(GUI);
  62. GUI->clear();
  63. m_typeIds.clear();
  64. GUI->addItem("Automatic (prefer performance if within memory limits)");
  65. m_typeIds.emplace_back(AZ::TypeId::CreateNull());
  66. const MotionDataFactory& factory = GetEMotionFX().GetMotionManager()->GetMotionDataFactory();
  67. for (size_t i = 0; i < factory.GetNumRegistered(); ++i)
  68. {
  69. GUI->addItem(factory.GetRegistered(i)->GetSceneSettingsName());
  70. m_typeIds.emplace_back(factory.GetRegistered(i)->RTTI_GetType());
  71. }
  72. if (instance.IsNull())
  73. {
  74. GUI->setCurrentIndex(0);
  75. }
  76. else
  77. {
  78. AZ::Outcome<size_t> motionIndex = factory.FindRegisteredIndexByTypeId(instance);
  79. if (motionIndex.IsSuccess())
  80. {
  81. GUI->setCurrentIndex(static_cast<int>(motionIndex.GetValue() + 1)); // +1 because we inserted an 'Automatic' one as first entry.
  82. }
  83. else
  84. {
  85. AZ_Warning("EMotionFX", false, "MotionData handler can't find the motion data with typeId '%s', selecting 'Automatic' instead", instance.ToString<AZStd::string>().c_str());
  86. GUI->setCurrentIndex(0);
  87. }
  88. }
  89. return true;
  90. }
  91. } // namespace EMotionFX
  92. #include <Source/Editor/PropertyWidgets/moc_MotionDataHandler.cpp>