ColliderContainerWidget.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 <AzCore/std/smart_ptr/unique_ptr.h>
  11. #include <AzCore/RTTI/TypeInfo.h>
  12. #include <AzFramework/Physics/SimulatedBodies/RigidBody.h>
  13. #include <AzFramework/Physics/Ragdoll.h>
  14. #include <AzFramework/Physics/Character.h>
  15. #include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
  16. #include <MCore/Source/Command.h>
  17. #include <MCore/Source/MCoreCommandManager.h>
  18. #include <AzQtComponents/Components/Widgets/Card.h>
  19. #include <EMotionFX/Source/PhysicsSetup.h>
  20. #include <EMotionFX/Tools/EMotionStudio/EMStudioSDK/Source/EMStudioPlugin.h>
  21. #include <QPushButton>
  22. #include <QWidget>
  23. #endif
  24. QT_FORWARD_DECLARE_CLASS(QVBoxLayout)
  25. namespace AZ
  26. {
  27. class SerializeContext;
  28. }
  29. namespace EMotionFX
  30. {
  31. class Actor;
  32. class ActorInstance;
  33. class Node;
  34. class ObjectEditor;
  35. class ColliderWidget;
  36. class ColliderPropertyNotify
  37. : public AzToolsFramework::IPropertyEditorNotify
  38. {
  39. public:
  40. ColliderPropertyNotify(ColliderWidget* colliderWidget);
  41. void BeforePropertyModified(AzToolsFramework::InstanceDataNode* node) override;
  42. void AfterPropertyModified(AzToolsFramework::InstanceDataNode* node) override;
  43. void SetPropertyEditingActive([[maybe_unused]] AzToolsFramework::InstanceDataNode* node) override {}
  44. void SetPropertyEditingComplete(AzToolsFramework::InstanceDataNode* node) override;
  45. void SealUndoStack() override {}
  46. private:
  47. MCore::CommandGroup m_commandGroup;
  48. ColliderWidget* m_colliderWidget;
  49. };
  50. class ColliderWidget
  51. : public AzQtComponents::Card
  52. {
  53. Q_OBJECT //AUTOMOC
  54. public:
  55. ColliderWidget(QIcon* icon, QWidget* parent, AZ::SerializeContext* serializeContext);
  56. void Update(Actor* actor, Node* joint, size_t colliderIndex, PhysicsSetup::ColliderConfigType colliderType, const AzPhysics::ShapeColliderPair& collider);
  57. void Update();
  58. void Reset();
  59. // Filter Reflected Properties
  60. void SetFilterString(QString filterString);
  61. // Returns true if any Node in the Reflected Property Editor is displayed
  62. bool HasDisplayedNodes() const;
  63. Actor* GetActor() const { return m_actor; };
  64. Node* GetJoint() const { return m_joint; }
  65. size_t GetColliderIndex() const { return m_colliderIndex; }
  66. PhysicsSetup::ColliderConfigType GetColliderType() const { return m_colliderType; }
  67. void InvalidateEditorValues();
  68. signals:
  69. void CopyCollider(size_t index);
  70. void PasteCollider(size_t index);
  71. void RemoveCollider(int colliderIndex);
  72. private slots:
  73. void OnCardContextMenu(const QPoint& position);
  74. void OnCopyCollider();
  75. void OnPasteCollider();
  76. void OnRemoveCollider();
  77. private:
  78. EMotionFX::ObjectEditor* m_editor;
  79. AZStd::unique_ptr<ColliderPropertyNotify> m_propertyNotify;
  80. Actor* m_actor = nullptr;
  81. PhysicsSetup::ColliderConfigType m_colliderType = PhysicsSetup::ColliderConfigType::Unknown;
  82. Node* m_joint = nullptr;
  83. size_t m_colliderIndex = MCORE_INVALIDINDEX32;
  84. AzPhysics::ShapeColliderPair m_collider;
  85. QIcon* m_icon;
  86. };
  87. class AddColliderButton
  88. : public QPushButton
  89. {
  90. Q_OBJECT //AUTOMOC
  91. public:
  92. AddColliderButton(const QString& text, QWidget* parent = nullptr,
  93. PhysicsSetup::ColliderConfigType copyToColliderType = PhysicsSetup::ColliderConfigType::Unknown,
  94. const AZStd::vector<AZ::TypeId>& supportedColliderTypes = {azrtti_typeid<Physics::BoxShapeConfiguration>(),
  95. azrtti_typeid<Physics::CapsuleShapeConfiguration>(),
  96. azrtti_typeid<Physics::SphereShapeConfiguration>()});
  97. signals:
  98. void AddCollider(AZ::TypeId colliderType);
  99. private slots:
  100. void OnCreateContextMenu();
  101. void OnAddColliderActionTriggered();
  102. void OnCopyColliderActionTriggered();
  103. private:
  104. AZStd::string GetNameForColliderType(AZ::TypeId colliderType) const;
  105. AZStd::vector<AZ::TypeId> m_supportedColliderTypes;
  106. PhysicsSetup::ColliderConfigType m_copyToColliderType = PhysicsSetup::ColliderConfigType::Unknown;
  107. };
  108. class ColliderContainerWidget
  109. : public QWidget
  110. {
  111. Q_OBJECT //AUTOMOC
  112. public:
  113. ColliderContainerWidget(const QIcon& colliderIcon, QWidget* parent = nullptr);
  114. ~ColliderContainerWidget();
  115. void Update(Actor* actor, Node* joint, PhysicsSetup::ColliderConfigType colliderType, const AzPhysics::ShapeColliderPairList& colliders, AZ::SerializeContext* serializeContext);
  116. void Update();
  117. void Reset();
  118. void SetFilterString(QString str);
  119. bool HasVisibleColliders() const;
  120. PhysicsSetup::ColliderConfigType ColliderType() { return m_colliderType; }
  121. void contextMenuEvent(QContextMenuEvent* event) override;
  122. static int s_layoutSpacing;
  123. signals:
  124. void CopyCollider(size_t index);
  125. void PasteCollider(size_t index, bool replace);
  126. void RemoveCollider(size_t index);
  127. private:
  128. Actor* m_actor = nullptr;
  129. PhysicsSetup::ColliderConfigType m_colliderType = PhysicsSetup::ColliderConfigType::Unknown;
  130. Node* m_joint = nullptr;
  131. QVBoxLayout* m_layout = nullptr;
  132. AZStd::vector<ColliderWidget*> m_colliderWidgets;
  133. QIcon m_colliderIcon;
  134. class ColliderEditedCallback
  135. : public MCore::Command::Callback
  136. {
  137. public:
  138. ColliderEditedCallback(ColliderContainerWidget* parent, bool executePreUndo, bool executePreCommand = false);
  139. bool Execute(MCore::Command* command, const MCore::CommandLine& commandLine);
  140. bool Undo(MCore::Command* command, const MCore::CommandLine& commandLine);
  141. private:
  142. ColliderContainerWidget* m_widget;
  143. };
  144. ColliderEditedCallback* m_commandCallback;
  145. };
  146. } // namespace EMotionFX