MotionSetNameHandler.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 "MotionSetNameHandler.h"
  9. #include <Integration/Assets/MotionSetAsset.h>
  10. #include <Integration/System/SystemCommon.h>
  11. #include <EMotionFX/Source/MotionSet.h>
  12. namespace EMotionFX
  13. {
  14. AZ_CLASS_ALLOCATOR_IMPL(MotionSetNameHandler, EditorAllocator)
  15. AZ::u32 MotionSetNameHandler::GetHandlerName() const
  16. {
  17. return AZ_CRC_CE("MotionSetName");
  18. }
  19. QWidget* MotionSetNameHandler::CreateGUI(QWidget* parent)
  20. {
  21. QComboBox* picker = new QComboBox(parent);
  22. connect(picker, &QComboBox::currentTextChanged, this, [picker]()
  23. {
  24. AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(
  25. &AzToolsFramework::PropertyEditorGUIMessages::Bus::Events::RequestWrite, picker);
  26. });
  27. return picker;
  28. }
  29. void MotionSetNameHandler::ConsumeAttribute(QComboBox* GUI, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, [[maybe_unused]] const char* debugName)
  30. {
  31. if (attrib == AZ::Edit::Attributes::ReadOnly)
  32. {
  33. bool value;
  34. if (attrValue->Read<bool>(value))
  35. {
  36. GUI->setEnabled(!value);
  37. }
  38. }
  39. else if (attrib == AZ_CRC_CE("MotionSetAsset"))
  40. {
  41. AZ::Data::Asset<Integration::MotionSetAsset>* value;
  42. if (attrValue->Read<AZ::Data::Asset<Integration::MotionSetAsset>*>(value))
  43. {
  44. m_motionSetAsset = value;
  45. }
  46. else
  47. {
  48. // emit a warning!
  49. AZ_WarningOnce("MotionSetNameHandler", false, "Failed to read 'MotionSetAsset' attribute from property '%s' into MotionSetNameHandler", debugName);
  50. }
  51. }
  52. }
  53. void MotionSetNameHandler::WriteGUIValuesIntoProperty(size_t index, QComboBox* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* node)
  54. {
  55. AZ_UNUSED(index);
  56. AZ_UNUSED(node);
  57. const QString& currentText = GUI->currentText();
  58. instance = AZStd::string(currentText.toUtf8().data(), currentText.length());
  59. }
  60. bool MotionSetNameHandler::ReadValuesIntoGUI(size_t index, QComboBox* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* node)
  61. {
  62. AZ_UNUSED(index);
  63. AZ_UNUSED(node);
  64. QSignalBlocker signalBlocker(GUI);
  65. GUI->clear();
  66. if (m_motionSetAsset && m_motionSetAsset->Get() && m_motionSetAsset->Get()->m_emfxMotionSet)
  67. {
  68. const AZStd::unique_ptr<EMotionFX::MotionSet>& emfxMotionSet = m_motionSetAsset->Get()->m_emfxMotionSet;
  69. AZStd::vector<const MotionSet*> motionSets;
  70. const bool isOwnedByRutime = emfxMotionSet->GetIsOwnedByRuntime();
  71. emfxMotionSet->RecursiveGetMotionSets(motionSets, isOwnedByRutime);
  72. for (const EMotionFX::MotionSet* motionSet : motionSets)
  73. {
  74. GUI->addItem(motionSet->GetName());
  75. }
  76. if (!instance.empty())
  77. {
  78. GUI->setCurrentText(instance.c_str());
  79. }
  80. else
  81. {
  82. // Choose the root motion set
  83. GUI->setCurrentText(emfxMotionSet->GetName());
  84. }
  85. }
  86. else if (!GUI->isEnabled() && !instance.empty())
  87. {
  88. // When the game is running, the handler is disabled but we still want to show the value
  89. GUI->addItem(instance.c_str());
  90. GUI->setCurrentText(instance.c_str());
  91. }
  92. return true;
  93. }
  94. } // namespace EMotionFX
  95. #include <Source/Editor/PropertyWidgets/moc_MotionSetNameHandler.cpp>