From ad6479967f5f9eff2e011f064687f0ca612988dd Mon Sep 17 00:00:00 2001 From: greerdv Date: Thu, 6 May 2021 22:15:00 +0100 Subject: [PATCH] changing add NUS button from invisible to read only when NUS component already present --- .../ToolsComponents/TransformComponent.cpp | 36 +++---------------- .../ToolsComponents/TransformComponent.h | 16 +++------ 2 files changed, 10 insertions(+), 42 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/TransformComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/TransformComponent.cpp index e20c114b20..bca7dc08e2 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/TransformComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/TransformComponent.cpp @@ -45,23 +45,6 @@ namespace AzToolsFramework { namespace Components { - void AddNonUniformScaleButton::Reflect(AZ::ReflectContext* context) - { - if (AZ::SerializeContext* serializeContext = azrtti_cast(context)) - { - serializeContext->Class()-> - Version(1); - - if (AZ::EditContext* ptrEdit = serializeContext->GetEditContext()) - { - ptrEdit->Class("AddNonUniformScaleButton", "")-> - UIElement(AZ::Edit::UIHandlers::Button, "", "Add non-uniform scale component")-> - Attribute(AZ::Edit::Attributes::ButtonText, "Add non-uniform scale") - ; - } - } - } - namespace Internal { const AZ::u32 ParentEntityCRC = AZ_CRC("Parent Entity", 0x5b1b276c); @@ -1242,16 +1225,9 @@ namespace AzToolsFramework return nullptr; } - AZ::Crc32 TransformComponent::AddNonUniformScaleButtonVisibility() + bool TransformComponent::IsAddNonUniformScaleButtonReadOnly() { - // if there is a non-uniform scale component already, hide altogether - if (FindPresentOrPendingComponent(EditorNonUniformScaleComponent::TYPEINFO_Uuid())) - { - return AZ::Edit::PropertyVisibility::Hide; - } - - // otherwise, just show children - return AZ::Edit::PropertyVisibility::ShowChildrenOnly; + return FindPresentOrPendingComponent(EditorNonUniformScaleComponent::TYPEINFO_Uuid()) != nullptr; } AZ::Crc32 TransformComponent::OnAddNonUniformScaleButtonPressed() @@ -1290,8 +1266,6 @@ namespace AzToolsFramework void TransformComponent::Reflect(AZ::ReflectContext* context) { - AddNonUniformScaleButton::Reflect(context); - // reflect data for script, serialization, editing.. if (AZ::SerializeContext* serializeContext = azrtti_cast(context)) { @@ -1329,9 +1303,9 @@ namespace AzToolsFramework DataElement(AZ::Edit::UIHandlers::Default, &TransformComponent::m_editorTransform, "Values", "")-> Attribute(AZ::Edit::Attributes::ChangeNotify, &TransformComponent::TransformChanged)-> Attribute(AZ::Edit::Attributes::AutoExpand, true)-> - DataElement(AZ::Edit::UIHandlers::Default, &TransformComponent::m_addNonUniformScaleButton, "", "")-> - Attribute(AZ::Edit::Attributes::AutoExpand, true)-> - Attribute(AZ::Edit::Attributes::Visibility, &TransformComponent::AddNonUniformScaleButtonVisibility)-> + DataElement(AZ::Edit::UIHandlers::Button, &TransformComponent::m_addNonUniformScaleButton, "", "")-> + Attribute(AZ::Edit::Attributes::ButtonText, "Add non-uniform scale")-> + Attribute(AZ::Edit::Attributes::ReadOnly, &TransformComponent::IsAddNonUniformScaleButtonReadOnly)-> Attribute(AZ::Edit::Attributes::ChangeNotify, &TransformComponent::OnAddNonUniformScaleButtonPressed)-> DataElement(AZ::Edit::UIHandlers::ComboBox, &TransformComponent::m_parentActivationTransformMode, "Parent activation", "Configures relative transform behavior when parent activates.")-> diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/TransformComponent.h b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/TransformComponent.h index 783ecfc84f..3d1e1ed672 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/TransformComponent.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/TransformComponent.h @@ -32,15 +32,6 @@ namespace AzToolsFramework { namespace Components { - // this is a workaround for a bug which causes the button to appear with incorrect placement if added directly - // to the transform component - class AddNonUniformScaleButton - { - public: - AZ_TYPE_INFO(AddNonUniformScaleButton, "{92ECB8B6-DD25-4FC0-A5EE-4CEBAF51A780}") - static void Reflect(AZ::ReflectContext* context); - }; - /// Manages transform data as separate vector fields for editing purposes. /// The TransformComponent is referenced by other components in the same entity, it is not an asset. class TransformComponent @@ -239,7 +230,7 @@ namespace AzToolsFramework void CheckApplyCachedWorldTransform(const AZ::Transform& parentWorld); AZ::Component* FindPresentOrPendingComponent(AZ::Uuid componentUuid); - AZ::Crc32 AddNonUniformScaleButtonVisibility(); + bool IsAddNonUniformScaleButtonReadOnly(); AZ::Crc32 OnAddNonUniformScaleButtonPressed(); // Drives transform behavior when parent activates. See AZ::TransformConfig::ParentActivationTransformMode for details. @@ -273,7 +264,10 @@ namespace AzToolsFramework bool m_localTransformDirty = true; bool m_worldTransformDirty = true; bool m_isStatic = false; - AddNonUniformScaleButton m_addNonUniformScaleButton; + + // This is a workaround for a bug which causes the button to appear with incorrect placement if a UI + // element is used rather than a data element. + bool m_addNonUniformScaleButton = false; // Deprecated AZ::InterpolationMode m_interpolatePosition;