From cf540b6f44c7e439505a29d8d2ce4989c4ae8232 Mon Sep 17 00:00:00 2001 From: amzn-sean <75276488+amzn-sean@users.noreply.github.com> Date: Thu, 18 Nov 2021 09:57:29 +0000 Subject: [PATCH] Defaulting the joint setup display to ON instead of OFF (#5696) Signed-off-by: amzn-sean <75276488+amzn-sean@users.noreply.github.com> --- .../Code/Editor/EditorJointConfiguration.cpp | 58 ++++++++++++++++++- .../Code/Editor/EditorJointConfiguration.h | 16 ++++- .../Code/Source/EditorBallJointComponent.cpp | 2 +- .../Code/Source/EditorHingeJointComponent.cpp | 2 +- 4 files changed, 72 insertions(+), 6 deletions(-) diff --git a/Gems/PhysX/Code/Editor/EditorJointConfiguration.cpp b/Gems/PhysX/Code/Editor/EditorJointConfiguration.cpp index 02e684de63..166c44de22 100644 --- a/Gems/PhysX/Code/Editor/EditorJointConfiguration.cpp +++ b/Gems/PhysX/Code/Editor/EditorJointConfiguration.cpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace { @@ -213,7 +214,7 @@ namespace PhysX if (auto* serializeContext = azrtti_cast(context)) { serializeContext->Class() - ->Version(4, &EditorJointConfig::VersionConverter) + ->Version(5, &EditorJointConfig::VersionConverter) ->Field("Local Position", &EditorJointConfig::m_localPosition) ->Field("Local Rotation", &EditorJointConfig::m_localRotation) ->Field("Parent Entity", &EditorJointConfig::m_leadEntity) @@ -228,6 +229,12 @@ namespace PhysX if (auto* editContext = serializeContext->GetEditContext()) { + editContext->Enum("Joint Display Setup State", "Options for displaying joint setup.") + ->Value("Never", EditorJointConfig::DisplaySetupState::Never) + ->Value("Selected", EditorJointConfig::DisplaySetupState::Selected) + ->Value("Always", EditorJointConfig::DisplaySetupState::Always) + ; + editContext->Class( "PhysX Joint Configuration", "") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") @@ -244,8 +251,11 @@ namespace PhysX ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorJointConfig::ValidateLeadEntityId) ->DataElement(0, &PhysX::EditorJointConfig::m_selfCollide, "Lead-Follower Collide" , "When active, the lead and follower pair will collide with each other.") - ->DataElement(0, &PhysX::EditorJointConfig::m_displayJointSetup, "Display Setup in Viewport" - , "Display joint setup in the viewport.") + ->DataElement( + AZ::Edit::UIHandlers::ComboBox, &PhysX::EditorJointConfig::m_displayJointSetup, "Display Setup in Viewport" + , "Never = Not shown." + "Select = Show setup display when entity is selected." + "Always = Always show setup display.") ->Attribute(AZ::Edit::Attributes::ReadOnly, &EditorJointConfig::IsInComponentMode) ->DataElement(0, &PhysX::EditorJointConfig::m_selectLeadOnSnap, "Select Lead on Snap" , "Select lead entity on snap to position in component mode.") @@ -306,6 +316,23 @@ namespace PhysX m_followerEntity); } + bool EditorJointConfig::ShowSetupDisplay() const + { + switch(m_displayJointSetup) + { + case DisplaySetupState::Always: + return true; + case DisplaySetupState::Selected: + { + bool showSetup = false; + AzToolsFramework::EditorEntityInfoRequestBus::EventResult( + showSetup, m_followerEntity, &AzToolsFramework::EditorEntityInfoRequests::IsSelected); + return showSetup; + } + } + return false; + } + bool EditorJointConfig::IsInComponentMode() const { return m_inComponentMode; @@ -343,6 +370,31 @@ namespace PhysX } } + // convert m_displayJointSetup from a bool to the enum with the option Never,Selected,Always show joint setup helpers. + if (classElement.GetVersion() <= 4) + { + // get the current bool setting and remove it. + bool oldSetting = false; + const int displayJointSetupIndex = classElement.FindElement(AZ_CRC_CE("Display Debug")); + if (displayJointSetupIndex >= 0) + { + AZ::SerializeContext::DataElementNode& elementNode = classElement.GetSubElement(displayJointSetupIndex); + elementNode.GetData(oldSetting); + classElement.RemoveElement(displayJointSetupIndex); + } + + //if the old setting was on set it to 'Selected'. otherwise 'Never' + if (oldSetting) + { + classElement.AddElementWithData(context, "Display Debug", EditorJointConfig::DisplaySetupState::Selected); + } + else + { + classElement.AddElementWithData(context, "Display Debug", EditorJointConfig::DisplaySetupState::Never); + } + } + + return result; } diff --git a/Gems/PhysX/Code/Editor/EditorJointConfiguration.h b/Gems/PhysX/Code/Editor/EditorJointConfiguration.h index 89ab31e4a7..f3dcd4afed 100644 --- a/Gems/PhysX/Code/Editor/EditorJointConfiguration.h +++ b/Gems/PhysX/Code/Editor/EditorJointConfiguration.h @@ -100,12 +100,21 @@ namespace PhysX AZ_TYPE_INFO(EditorJointConfig, "{8A966D65-CA97-4786-A13C-ACAA519D97EA}"); static void Reflect(AZ::ReflectContext* context); + enum class DisplaySetupState : AZ::u8 + { + Never = 0, + Selected, + Always + }; + void SetLeadEntityId(AZ::EntityId leadEntityId); JointGenericProperties ToGenericProperties() const; JointComponentConfiguration ToGameTimeConfig() const; + bool ShowSetupDisplay() const; + bool m_breakable = false; - bool m_displayJointSetup = false; + DisplaySetupState m_displayJointSetup = DisplaySetupState::Selected; bool m_inComponentMode = false; bool m_selectLeadOnSnap = true; bool m_selfCollide = false; @@ -129,3 +138,8 @@ namespace PhysX }; } // namespace PhysX + +namespace AZ +{ + AZ_TYPE_INFO_SPECIALIZE(PhysX::EditorJointConfig::DisplaySetupState, "{17EBE6BD-289A-4326-8A24-DCE3B7FEC51E}"); +} // namespace AZ diff --git a/Gems/PhysX/Code/Source/EditorBallJointComponent.cpp b/Gems/PhysX/Code/Source/EditorBallJointComponent.cpp index fa71fa0061..d7065a869d 100644 --- a/Gems/PhysX/Code/Source/EditorBallJointComponent.cpp +++ b/Gems/PhysX/Code/Source/EditorBallJointComponent.cpp @@ -215,7 +215,7 @@ namespace PhysX { EditorJointComponent::DisplayEntityViewport(viewportInfo, debugDisplay); - if (!m_config.m_displayJointSetup && + if (!m_config.ShowSetupDisplay() && !m_config.m_inComponentMode) { return; diff --git a/Gems/PhysX/Code/Source/EditorHingeJointComponent.cpp b/Gems/PhysX/Code/Source/EditorHingeJointComponent.cpp index 1b575074e2..f009c990b4 100644 --- a/Gems/PhysX/Code/Source/EditorHingeJointComponent.cpp +++ b/Gems/PhysX/Code/Source/EditorHingeJointComponent.cpp @@ -211,7 +211,7 @@ namespace PhysX { EditorJointComponent::DisplayEntityViewport(viewportInfo, debugDisplay); - if (!m_config.m_displayJointSetup && + if (!m_config.ShowSetupDisplay() && !m_config.m_inComponentMode) { return;