RagdollJointLimitWidget.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #pragma once
  9. #if !defined(Q_MOC_RUN)
  10. #include <AzFramework/Physics/Ragdoll.h>
  11. #include <AzQtComponents/Components/Widgets/Card.h>
  12. #include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
  13. #include <MCore/Source/Command.h>
  14. #include <QModelIndex>
  15. #endif
  16. QT_FORWARD_DECLARE_CLASS(QComboBox)
  17. QT_FORWARD_DECLARE_CLASS(QCheckBox)
  18. QT_FORWARD_DECLARE_CLASS(QLabel)
  19. namespace EMotionFX
  20. {
  21. class ObjectEditor;
  22. class RagdollJointLimitWidget;
  23. class RagdollJointLimitPropertyNotify
  24. : public AzToolsFramework::IPropertyEditorNotify
  25. {
  26. public:
  27. // AzToolsFramework::IPropertyEditorNotify overrides ...
  28. void BeforePropertyModified([[maybe_unused]] AzToolsFramework::InstanceDataNode* node) override {};
  29. void AfterPropertyModified(AzToolsFramework::InstanceDataNode* node) override;
  30. void SetPropertyEditingActive([[maybe_unused]] AzToolsFramework::InstanceDataNode* node) override {}
  31. void SetPropertyEditingComplete([[maybe_unused]] AzToolsFramework::InstanceDataNode* node) override {};
  32. void SealUndoStack() override {}
  33. };
  34. class RagdollJointLimitWidget
  35. : public AzQtComponents::Card
  36. {
  37. Q_OBJECT //AUTOMOC
  38. public:
  39. explicit RagdollJointLimitWidget(const AZStd::string& copiedJointLimits, QWidget* parent = nullptr);
  40. ~RagdollJointLimitWidget() override;
  41. void Update(const QModelIndex& modelIndex);
  42. void Update() { Update(m_nodeIndex); }
  43. bool HasJointLimit() const;
  44. void InvalidateValues();
  45. signals:
  46. void JointLimitCopied(const AZStd::string& serializedJointLimits) const;
  47. void JointLimitTypeChanged() const;
  48. private slots:
  49. void OnJointTypeChanged(int index);
  50. void OnHasLimitStateChanged(int state);
  51. void OnCardContextMenu(const QPoint& position);
  52. private:
  53. Physics::RagdollNodeConfiguration* GetRagdollNodeConfig() const;
  54. void ChangeLimitType(const AZ::TypeId& type);
  55. void ChangeLimitType(int supportedTypeIndex);
  56. AZStd::unique_ptr<RagdollJointLimitPropertyNotify> m_propertyNotify;
  57. QModelIndex m_nodeIndex;
  58. QIcon m_cardHeaderIcon;
  59. EMotionFX::ObjectEditor* m_objectEditor;
  60. QCheckBox* m_hasLimitCheckbox;
  61. QLabel* m_typeLabel;
  62. QComboBox* m_typeComboBox;
  63. const AZStd::string& m_copiedJointLimits;
  64. static int s_leftMargin;
  65. static int s_textColumnWidth;
  66. class DEFINECOMMANDCALLBACK_API DataChangedCallback
  67. : public MCore::Command::Callback
  68. {
  69. MCORE_MEMORYOBJECTCATEGORY(DataChangedCallback, MCore::MCORE_DEFAULT_ALIGNMENT, MCore::MCORE_MEMCATEGORY_COMMANDSYSTEM);
  70. public:
  71. explicit DataChangedCallback(const RagdollJointLimitWidget* widget, bool executePreUndo, bool executePreCommand = false)
  72. : MCore::Command::Callback(executePreUndo, executePreCommand)
  73. , m_widget(widget)
  74. {}
  75. bool Execute(MCore::Command * command, const MCore::CommandLine & commandLine) override;
  76. bool Undo(MCore::Command * command, const MCore::CommandLine & commandLine) override;
  77. private:
  78. const RagdollJointLimitWidget* m_widget{};
  79. };
  80. AZStd::vector<AZStd::unique_ptr<MCore::Command::Callback>> m_commandCallbacks;
  81. friend class DataChangedCallback;
  82. };
  83. } // namespace EMotionFX