PropertyHandlerUiParticleFloatKeyframe.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 "EditorCommon.h"
  9. #include "PropertyHandlerUiParticleFloatKeyframe.h"
  10. #include <AzToolsFramework/UI/PropertyEditor/PropertyQTConstants.h>
  11. PropertyUiParticleFloatKeyframeCtrl::PropertyUiParticleFloatKeyframeCtrl(QWidget* parent)
  12. : QWidget(parent)
  13. {
  14. QVBoxLayout* vLayout = new QVBoxLayout(this);
  15. vLayout->setContentsMargins(0, 5, 0, 5);
  16. vLayout->setSpacing(2);
  17. QHBoxLayout* layout = new QHBoxLayout(this);
  18. layout->setContentsMargins(0, 0, 0, 0);
  19. layout->setSpacing(2);
  20. QHBoxLayout* layoutRow2 = new QHBoxLayout(this);
  21. layout->setContentsMargins(0, 0, 0, 0);
  22. layout->setSpacing(2);
  23. QLabel* timeLabel = new QLabel(parent);
  24. timeLabel->setText("Time");
  25. timeLabel->setObjectName("Time");
  26. layout->addWidget(timeLabel);
  27. m_timeCtrl = aznew AzToolsFramework::PropertyDoubleSpinCtrl(parent);
  28. m_timeCtrl->setMinimum(0.0f);
  29. m_timeCtrl->setMaximum(1.0f);
  30. m_timeCtrl->setStep(0.0f);
  31. m_timeCtrl->setMinimumWidth(AzToolsFramework::PropertyQTConstant_MinimumWidth);
  32. m_timeCtrl->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
  33. m_timeCtrl->setToolTip(tr("Time in the range [0,1]."));
  34. QObject::connect(m_timeCtrl, &AzToolsFramework::PropertyDoubleSpinCtrl::valueChanged, this, [this]()
  35. {
  36. AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(
  37. &AzToolsFramework::PropertyEditorGUIMessages::Bus::Events::RequestWrite, this);
  38. });
  39. layout->addWidget(m_timeCtrl);
  40. QLabel* multiplierLabel = new QLabel(parent);
  41. multiplierLabel->setText("Multiplier");
  42. multiplierLabel->setObjectName("Multiplier");
  43. layout->addWidget(multiplierLabel);
  44. m_multiplierCtrl = aznew AzToolsFramework::PropertyDoubleSpinCtrl(parent);
  45. m_multiplierCtrl->setMinimum(-100.0f);
  46. m_multiplierCtrl->setMinimumWidth(AzToolsFramework::PropertyQTConstant_MinimumWidth);
  47. m_multiplierCtrl->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
  48. QObject::connect(m_multiplierCtrl, &AzToolsFramework::PropertyDoubleSpinCtrl::valueChanged, this, [this]()
  49. {
  50. AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(
  51. &AzToolsFramework::PropertyEditorGUIMessages::Bus::Events::RequestWrite, this);
  52. });
  53. layout->addWidget(m_multiplierCtrl);
  54. AZStd::pair<AZ::s64, AZStd::string> easeInTangent;
  55. easeInTangent.first = static_cast<AZ::s64>(UiParticleEmitterInterface::ParticleKeyframeTangentType::EaseIn);
  56. easeInTangent.second = "Ease In";
  57. AZStd::pair<AZ::s64, AZStd::string> easeOutTangent;
  58. easeOutTangent.first = static_cast<AZ::s64>(UiParticleEmitterInterface::ParticleKeyframeTangentType::EaseOut);
  59. easeOutTangent.second = "Ease Out";
  60. AZStd::pair<AZ::s64, AZStd::string> linearTangent;
  61. linearTangent.first = static_cast<AZ::s64>(UiParticleEmitterInterface::ParticleKeyframeTangentType::Linear);
  62. linearTangent.second = "Linear";
  63. AZStd::pair<AZ::s64, AZStd::string> stepTangent;
  64. stepTangent.first = static_cast<AZ::s64>(UiParticleEmitterInterface::ParticleKeyframeTangentType::Step);
  65. stepTangent.second = "Step";
  66. QLabel* inTangentLabel = new QLabel(parent);
  67. inTangentLabel->setText("In tangent");
  68. inTangentLabel->setObjectName("In tangent");
  69. layoutRow2->addWidget(inTangentLabel);
  70. m_inTangentCtrl = aznew AzToolsFramework::PropertyEnumComboBoxCtrl(parent);
  71. m_inTangentCtrl->addEnumValue(easeInTangent);
  72. m_inTangentCtrl->addEnumValue(linearTangent);
  73. m_inTangentCtrl->addEnumValue(stepTangent);
  74. QObject::connect(m_inTangentCtrl, &AzToolsFramework::PropertyEnumComboBoxCtrl::valueChanged, this, [this]()
  75. {
  76. AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(
  77. &AzToolsFramework::PropertyEditorGUIMessages::Bus::Events::RequestWrite, this);
  78. });
  79. layoutRow2->addWidget(m_inTangentCtrl);
  80. QLabel* outTangentLabel = new QLabel(parent);
  81. outTangentLabel->setText("Out tangent");
  82. outTangentLabel->setObjectName("Out tangent");
  83. layoutRow2->addWidget(outTangentLabel);
  84. m_outTangentCtrl = aznew AzToolsFramework::PropertyEnumComboBoxCtrl(parent);
  85. m_outTangentCtrl->addEnumValue(easeOutTangent);
  86. m_outTangentCtrl->addEnumValue(linearTangent);
  87. m_outTangentCtrl->addEnumValue(stepTangent);
  88. QObject::connect(m_outTangentCtrl, &AzToolsFramework::PropertyEnumComboBoxCtrl::valueChanged, this, [this]()
  89. {
  90. AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(
  91. &AzToolsFramework::PropertyEditorGUIMessages::Bus::Events::RequestWrite, this);
  92. });
  93. layoutRow2->addWidget(m_outTangentCtrl);
  94. vLayout->addLayout(layout);
  95. vLayout->addLayout(layoutRow2);
  96. }
  97. void PropertyUiParticleFloatKeyframeCtrl::ConsumeAttribute(AZ::u32 /*attrib*/, AzToolsFramework::PropertyAttributeReader* /*attrValue*/, const char* /*debugName*/)
  98. {
  99. }
  100. AzToolsFramework::PropertyDoubleSpinCtrl* PropertyUiParticleFloatKeyframeCtrl::GetTimeCtrl()
  101. {
  102. return m_timeCtrl;
  103. }
  104. AzToolsFramework::PropertyDoubleSpinCtrl* PropertyUiParticleFloatKeyframeCtrl::GetMultiplierCtrl()
  105. {
  106. return m_multiplierCtrl;
  107. }
  108. AzToolsFramework::PropertyEnumComboBoxCtrl* PropertyUiParticleFloatKeyframeCtrl::GetInTangentCtrl()
  109. {
  110. return m_inTangentCtrl;
  111. }
  112. AzToolsFramework::PropertyEnumComboBoxCtrl* PropertyUiParticleFloatKeyframeCtrl::GetOutTangentCtrl()
  113. {
  114. return m_outTangentCtrl;
  115. }
  116. QWidget* PropertyHandlerUiParticleFloatKeyframe::CreateGUI(QWidget* pParent)
  117. {
  118. return aznew PropertyUiParticleFloatKeyframeCtrl(pParent);
  119. }
  120. void PropertyHandlerUiParticleFloatKeyframe::ConsumeAttribute(PropertyUiParticleFloatKeyframeCtrl* GUI, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName)
  121. {
  122. GUI->ConsumeAttribute(attrib, attrValue, debugName);
  123. }
  124. void PropertyHandlerUiParticleFloatKeyframe::WriteGUIValuesIntoProperty(size_t /*index*/, PropertyUiParticleFloatKeyframeCtrl* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* /*node*/)
  125. {
  126. instance.time = aznumeric_cast<float>(GUI->GetTimeCtrl()->value());
  127. instance.multiplier = aznumeric_cast<float>(GUI->GetMultiplierCtrl()->value());
  128. instance.inTangent = static_cast<UiParticleEmitterInterface::ParticleKeyframeTangentType>(GUI->GetInTangentCtrl()->value());
  129. instance.outTangent = static_cast<UiParticleEmitterInterface::ParticleKeyframeTangentType>(GUI->GetOutTangentCtrl()->value());
  130. }
  131. bool PropertyHandlerUiParticleFloatKeyframe::ReadValuesIntoGUI(size_t /*index*/, PropertyUiParticleFloatKeyframeCtrl* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* /*node*/)
  132. {
  133. GUI->blockSignals(true);
  134. {
  135. GUI->GetTimeCtrl()->setValue(instance.time);
  136. GUI->GetMultiplierCtrl()->setValue(instance.multiplier);
  137. GUI->GetInTangentCtrl()->setValue(static_cast<AZ::s64>(instance.inTangent));
  138. GUI->GetOutTangentCtrl()->setValue(static_cast<AZ::s64>(instance.outTangent));
  139. }
  140. GUI->blockSignals(false);
  141. return false;
  142. }
  143. AZ::EntityId PropertyHandlerUiParticleFloatKeyframe::GetParentEntityId(AzToolsFramework::InstanceDataNode* node, size_t index)
  144. {
  145. while (node)
  146. {
  147. if ((node->GetClassMetadata()) && (node->GetClassMetadata()->m_azRtti))
  148. {
  149. if (node->GetClassMetadata()->m_azRtti->IsTypeOf(AZ::Component::RTTI_Type()))
  150. {
  151. return static_cast<AZ::Component*>(node->GetInstance(index))->GetEntityId();
  152. }
  153. }
  154. node = node->GetParent();
  155. }
  156. return AZ::EntityId();
  157. }
  158. void PropertyHandlerUiParticleFloatKeyframe::Register()
  159. {
  160. AzToolsFramework::PropertyTypeRegistrationMessages::Bus::Broadcast(
  161. &AzToolsFramework::PropertyTypeRegistrationMessages::Bus::Events::RegisterPropertyType,
  162. aznew PropertyHandlerUiParticleFloatKeyframe());
  163. }
  164. #include <moc_PropertyHandlerUiParticleFloatKeyframe.cpp>