BlendTreeRotationLimitHandler.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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/BlendTreeRotationLimitHandler.h>
  9. #include <AzCore/Memory/SystemAllocator.h>
  10. #include <EMotionFX/Source/ConstraintTransformRotationAngles.h>
  11. #include <AzToolsFramework/API/ToolsApplicationAPI.h>
  12. namespace EMotionFX
  13. {
  14. AZ_CLASS_ALLOCATOR_IMPL(BlendTreeRotationLimitHandler, EditorAllocator);
  15. AZ_CLASS_ALLOCATOR_IMPL(BlendTreeRotationLimitContainerHandler, EditorAllocator);
  16. AZ_CLASS_ALLOCATOR_IMPL(RotationLimitWdget, EditorAllocator);
  17. AZ_CLASS_ALLOCATOR_IMPL(RotationLimitContainerWdget, EditorAllocator);
  18. const int RotationLimitWdget::s_decimalPlaces = 1;
  19. RotationLimitWdget::RotationLimitWdget([[maybe_unused]] QWidget* parent)
  20. {
  21. m_tooltipText = QString("Min %1 \xB0\n").arg((int)BlendTreeRotationLimitNode::RotationLimit::s_rotationLimitRangeMin);
  22. m_tooltipText += QString("Max %1 \xB0").arg((int)BlendTreeRotationLimitNode::RotationLimit::s_rotationLimitRangeMax);
  23. QHBoxLayout* hLayout = new QHBoxLayout(this);
  24. hLayout->setMargin(2);
  25. setLayout(hLayout);
  26. m_spinBoxMin = new AzQtComponents::DoubleSpinBox(this);
  27. layout()->addWidget(m_spinBoxMin);
  28. m_spinBoxMax = new AzQtComponents::DoubleSpinBox(this);
  29. layout()->addWidget(m_spinBoxMax);
  30. m_spinBoxMin->setRange(BlendTreeRotationLimitNode::RotationLimit::s_rotationLimitRangeMin, BlendTreeRotationLimitNode::RotationLimit::s_rotationLimitRangeMax);
  31. m_spinBoxMax->setRange(BlendTreeRotationLimitNode::RotationLimit::s_rotationLimitRangeMin, BlendTreeRotationLimitNode::RotationLimit::s_rotationLimitRangeMax);
  32. m_spinBoxMin->setDecimals(s_decimalPlaces);
  33. m_spinBoxMax->setDecimals(s_decimalPlaces);
  34. m_spinBoxMin->setToolTip(m_tooltipText);
  35. m_spinBoxMax->setToolTip(m_tooltipText);
  36. connect(m_spinBoxMin, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &RotationLimitWdget::HandleMinValueChanged);
  37. connect(m_spinBoxMax, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &RotationLimitWdget::HandleMaxValueChanged);
  38. }
  39. void RotationLimitWdget::SetRotationLimit(const BlendTreeRotationLimitNode::RotationLimit& rotationLimit)
  40. {
  41. m_rotationLimit = &rotationLimit;
  42. }
  43. void RotationLimitWdget::UpdateGui()
  44. {
  45. m_spinBoxMin->setValue(m_rotationLimit->GetLimitMin());
  46. m_spinBoxMax->setValue(m_rotationLimit->GetLimitMax());
  47. }
  48. void RotationLimitWdget::HandleMinValueChanged(double value)
  49. {
  50. m_spinBoxMin->setValue(value);
  51. if (m_spinBoxMin->value() <= m_spinBoxMax->value())
  52. {
  53. AzQtComponents::SpinBox::setHasError(m_spinBoxMax, false);
  54. AzQtComponents::SpinBox::setHasError(m_spinBoxMin, false);
  55. m_spinBoxMin->setToolTip(m_tooltipText);
  56. m_spinBoxMax->setToolTip(m_tooltipText);
  57. emit DataChanged();
  58. }
  59. else
  60. {
  61. AzQtComponents::SpinBox::setHasError(m_spinBoxMin, true);
  62. QString errorTooltip = QString("The value has to be less than or equal to %1 \xB0").arg(m_spinBoxMax->value());
  63. m_spinBoxMin->setToolTip(errorTooltip);
  64. }
  65. }
  66. void RotationLimitWdget::HandleMaxValueChanged(double value)
  67. {
  68. m_spinBoxMax->setValue(value);
  69. if (m_spinBoxMin->value() <= m_spinBoxMax->value())
  70. {
  71. AzQtComponents::SpinBox::setHasError(m_spinBoxMax, false);
  72. AzQtComponents::SpinBox::setHasError(m_spinBoxMin, false);
  73. m_spinBoxMin->setToolTip(m_tooltipText);
  74. m_spinBoxMax->setToolTip(m_tooltipText);
  75. emit DataChanged();
  76. }
  77. else
  78. {
  79. AzQtComponents::SpinBox::setHasError(m_spinBoxMax, true);
  80. QString errorTooltip = QString("The value has to be greater than or equal to %1 \xB0").arg(m_spinBoxMin->value());
  81. m_spinBoxMax->setToolTip(errorTooltip);
  82. }
  83. }
  84. float RotationLimitWdget::GetMin() const
  85. {
  86. return static_cast<float>(m_spinBoxMin->value());
  87. }
  88. float RotationLimitWdget::GetMax() const
  89. {
  90. return static_cast<float>(m_spinBoxMax->value());
  91. }
  92. QWidget* BlendTreeRotationLimitHandler::CreateGUI(QWidget* parent)
  93. {
  94. RotationLimitWdget* rotationLimitWdget = aznew RotationLimitWdget(parent);
  95. connect(rotationLimitWdget, &RotationLimitWdget::DataChanged, this, [rotationLimitWdget]()
  96. {
  97. AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(&AzToolsFramework::PropertyEditorGUIMessages::RequestWrite, rotationLimitWdget);
  98. });
  99. return rotationLimitWdget;
  100. }
  101. AZ::u32 BlendTreeRotationLimitHandler::GetHandlerName() const
  102. {
  103. return AZ_CRC("BlendTreeRotationLimitHandler", 0xc1af4ea8);
  104. }
  105. void BlendTreeRotationLimitHandler::ConsumeAttribute(RotationLimitWdget* /*widget*/, AZ::u32 /*attrib*/, AzToolsFramework::PropertyAttributeReader* /*attrValue*/, const char* /*debugName*/)
  106. {
  107. }
  108. void BlendTreeRotationLimitHandler::WriteGUIValuesIntoProperty(size_t /*index*/, RotationLimitWdget* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* /*node*/)
  109. {
  110. instance.SetMin(GUI->GetMin());
  111. instance.SetMax(GUI->GetMax());
  112. }
  113. bool BlendTreeRotationLimitHandler::ReadValuesIntoGUI(size_t /*index*/, RotationLimitWdget* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* /*node*/)
  114. {
  115. QSignalBlocker signalBlocker(GUI);
  116. GUI->SetRotationLimit(instance);
  117. GUI->UpdateGui();
  118. return true;
  119. }
  120. RotationLimitContainerWdget::RotationLimitContainerWdget([[maybe_unused]] QWidget* parent)
  121. {
  122. QHBoxLayout* hLayout = new QHBoxLayout(this);
  123. hLayout->setMargin(2);
  124. setLayout(hLayout);
  125. QLabel* headerColumn1 = new QLabel("Min angle \xB0", this);
  126. layout()->addWidget(headerColumn1);
  127. QLabel* headerColumn2 = new QLabel("Max angle \xB0", this);
  128. layout()->addWidget(headerColumn2);
  129. }
  130. QWidget* BlendTreeRotationLimitContainerHandler::CreateGUI(QWidget* parent)
  131. {
  132. RotationLimitContainerWdget* rotationLimitWdget = aznew RotationLimitContainerWdget(parent);
  133. return rotationLimitWdget;
  134. }
  135. AZ::u32 BlendTreeRotationLimitContainerHandler::GetHandlerName() const
  136. {
  137. return AZ_CRC("BlendTreeRotationLimitContainerHandler", 0xb2c775fb);
  138. }
  139. void BlendTreeRotationLimitContainerHandler::ConsumeAttribute(RotationLimitContainerWdget* /*widget*/, AZ::u32 /*attrib*/, AzToolsFramework::PropertyAttributeReader* /*attrValue*/, const char* /*debugName*/)
  140. { }
  141. void BlendTreeRotationLimitContainerHandler::WriteGUIValuesIntoProperty(size_t /*index*/, [[maybe_unused]] RotationLimitContainerWdget* GUI, [[maybe_unused]] property_t& instance, AzToolsFramework::InstanceDataNode* /*node*/)
  142. { }
  143. bool BlendTreeRotationLimitContainerHandler::ReadValuesIntoGUI(size_t /*index*/, [[maybe_unused]] RotationLimitContainerWdget* GUI, [[maybe_unused]] const property_t& instance, AzToolsFramework::InstanceDataNode* /*node*/)
  144. {
  145. return true;
  146. }
  147. }