Преглед на файлове

Created property handler for asset ID and consolidated attributes between the different handlers

Signed-off-by: gadams3 <[email protected]>
gadams3 преди 3 години
родител
ревизия
1b58461112

+ 47 - 68
Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/PropertyAssetCtrl.cpp

@@ -787,7 +787,7 @@ namespace AzToolsFramework
         }
 
         QMessageBox::warning(GetActiveWindow(), tr("Unable to Edit Asset"),
-            tr("No callback is provided and no associated editor could be found."), QMessageBox::Ok, QMessageBox::Ok);
+            QObject::QObject::tr("No callback is provided and no associated editor could be found."), QMessageBox::Ok, QMessageBox::Ok);
     }
 
     void PropertyAssetCtrl::PopupAssetPicker()
@@ -1362,7 +1362,7 @@ namespace AzToolsFramework
         return newCtrl;
     }
 
-    void AssetPropertyHandlerDefault::ConsumeAttributeInternal(PropertyAssetCtrl* GUI, AZ::u32 attrib, PropertyAttributeReader* attrValue, const char* debugName)
+    void ConsumeAttributeForPropertyAssetCtrl(PropertyAssetCtrl* GUI, AZ::u32 attrib, PropertyAttributeReader* attrValue, const char* debugName)
     {
         (void)debugName;
 
@@ -1380,7 +1380,7 @@ namespace AzToolsFramework
             // This is assumed to be an Asset Browser path to a specific folder to be used as a default by the asset picker if provided
             GUI->SetDefaultDirectoryCallback(azdynamic_cast<PropertyAssetCtrl::DefaultDirectoryCallbackType*>(attrValue->GetAttribute()));
         }
-        else if (attrib == AZ_CRC("EditCallback", 0xb74f2ee1))
+        else if (attrib == AZ_CRC_CE("EditCallback"))
         {
             PropertyAssetCtrl::EditCallbackType* func = azdynamic_cast<PropertyAssetCtrl::EditCallbackType*>(attrValue->GetAttribute());
             if (func)
@@ -1393,7 +1393,7 @@ namespace AzToolsFramework
                 GUI->SetEditNotifyCallback(nullptr);
             }
         }
-        else if (attrib == AZ_CRC("EditButton", 0x898c35dc))
+        else if (attrib == AZ_CRC_CE("EditButton"))
         {
             GUI->SetEditButtonVisible(true);
 
@@ -1415,12 +1415,12 @@ namespace AzToolsFramework
                 GUI->SetEditButtonIcon(QIcon(path));
             }
         }
-        else if (attrib == AZ_CRC("EditDescription", 0x9b52634a))
+        else if (attrib == AZ_CRC_CE("EditDescription"))
         {
             AZStd::string buttonTooltip;
             if (attrValue->Read<AZStd::string>(buttonTooltip))
             {
-                GUI->SetEditButtonTooltip(tr(buttonTooltip.c_str()));
+                GUI->SetEditButtonTooltip(QObject::tr(buttonTooltip.c_str()));
             }
         }
         else if (attrib == AZ_CRC_CE("DisableEditButtonWhenNoAssetSelected"))
@@ -1577,7 +1577,7 @@ namespace AzToolsFramework
 
     void AssetPropertyHandlerDefault::ConsumeAttribute(PropertyAssetCtrl* GUI, AZ::u32 attrib, PropertyAttributeReader* attrValue, const char* debugName)
     {
-        ConsumeAttributeInternal(GUI, attrib, attrValue, debugName);
+        ConsumeAttributeForPropertyAssetCtrl(GUI, attrib, attrValue, debugName);
     }
 
     void AssetPropertyHandlerDefault::WriteGUIValuesIntoPropertyInternal(size_t index, PropertyAssetCtrl* GUI, property_t& instance, InstanceDataNode* node)
@@ -1625,10 +1625,9 @@ namespace AzToolsFramework
         return ReadValuesIntoGUIInternal(index, GUI, instance, node);
     }
 
-    QWidget* SimpleAssetPropertyHandlerDefault::CreateGUI(QWidget* pParent)
+    QWidget* AssetIdPropertyHandlerDefault::CreateGUI(QWidget* pParent)
     {
         PropertyAssetCtrl* newCtrl = aznew PropertyAssetCtrl(pParent);
-
         connect(newCtrl, &PropertyAssetCtrl::OnAssetIDChanged, this, [newCtrl](AZ::Data::AssetId newAssetID)
         {
             (void)newAssetID;
@@ -1638,69 +1637,45 @@ namespace AzToolsFramework
         return newCtrl;
     }
 
-    void SimpleAssetPropertyHandlerDefault::ConsumeAttribute(PropertyAssetCtrl* GUI, AZ::u32 attrib, PropertyAttributeReader* attrValue, const char* debugName)
+    void AssetIdPropertyHandlerDefault::ConsumeAttribute(PropertyAssetCtrl* GUI, AZ::u32 attrib, PropertyAttributeReader* attrValue, const char* debugName)
     {
-        Q_UNUSED(debugName);
-
-        if (attrib == AZ_CRC("BrowseIcon", 0x507d7a4f))
-        {
-            AZStd::string iconPath;
-            attrValue->Read<AZStd::string>(iconPath);
-
-            if (!iconPath.empty())
-            {
-                GUI->SetBrowseButtonIcon(QIcon(iconPath.c_str()));
-            }
-        }
-        else if (attrib == AZ_CRC("EditCallback", 0xb74f2ee1))
-        {
-            PropertyAssetCtrl::EditCallbackType* func = azdynamic_cast<PropertyAssetCtrl::EditCallbackType*>(attrValue->GetAttribute());
-            if (func)
-            {
-                GUI->SetEditButtonVisible(true);
-                GUI->SetEditNotifyCallback(func);
-            }
-            else
-            {
-                GUI->SetEditNotifyCallback(nullptr);
-            }
-        }
-        else if (attrib == AZ_CRC("EditButton", 0x898c35dc))
-        {
-            GUI->SetEditButtonVisible(true);
-
-            AZStd::string iconPath;
-            attrValue->Read<AZStd::string>(iconPath);
+        ConsumeAttributeForPropertyAssetCtrl(GUI, attrib, attrValue, debugName);
+    }
 
-            if (!iconPath.empty())
-            {
-                QString path(iconPath.c_str());
+    void AssetIdPropertyHandlerDefault::WriteGUIValuesIntoProperty(size_t index, PropertyAssetCtrl* GUI, property_t& instance, InstanceDataNode* node)
+    {
+        (void)index;
+        (void)node;
+        instance = GUI->GetSelectedAssetID();
+    }
 
-                if (!QFile::exists(path))
-                {
-                    AZ::IO::FixedMaxPathString engineRoot = AZ::Utils::GetEnginePath();
-                    QDir engineDir = !engineRoot.empty() ? QDir(QString(engineRoot.c_str())) : QDir::current();
+    bool AssetIdPropertyHandlerDefault::ReadValuesIntoGUI(size_t index, PropertyAssetCtrl* GUI, const property_t& instance, InstanceDataNode* node)
+    {
+        (void)index;
+        (void)node;
 
-                    path = engineDir.absoluteFilePath(iconPath.c_str());
-                }
+        GUI->blockSignals(true);
+        GUI->SetSelectedAssetID(instance);
+        GUI->SetEditNotifyTarget(node->GetParent()->GetInstance(0));
+        GUI->blockSignals(false);
+        return false;
+    }
 
-                GUI->SetEditButtonIcon(QIcon(path));
-            }
-        }
-        else if (attrib == AZ_CRC("EditDescription", 0x9b52634a))
-        {
-            AZStd::string buttonTooltip;
-            if (attrValue->Read<AZStd::string>(buttonTooltip))
-            {
-                GUI->SetEditButtonTooltip(tr(buttonTooltip.c_str()));
-            }
-        }
-        else if (attrib == AZ_CRC_CE("DisableEditButtonWhenNoAssetSelected"))
+    QWidget* SimpleAssetPropertyHandlerDefault::CreateGUI(QWidget* pParent)
+    {
+        PropertyAssetCtrl* newCtrl = aznew PropertyAssetCtrl(pParent);
+        connect(newCtrl, &PropertyAssetCtrl::OnAssetIDChanged, this, [newCtrl](AZ::Data::AssetId newAssetID)
         {
-            bool disableEditButtonWhenNoAssetSelected = false;
-            attrValue->Read<bool>(disableEditButtonWhenNoAssetSelected);
-            GUI->SetDisableEditButtonWhenNoAssetSelected(disableEditButtonWhenNoAssetSelected);
-        }
+            (void)newAssetID;
+            EBUS_EVENT(PropertyEditorGUIMessages::Bus, RequestWrite, newCtrl);
+            AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(&PropertyEditorGUIMessages::Bus::Handler::OnEditingFinished, newCtrl);
+        });
+        return newCtrl;
+    }
+
+    void SimpleAssetPropertyHandlerDefault::ConsumeAttribute(PropertyAssetCtrl* GUI, AZ::u32 attrib, PropertyAttributeReader* attrValue, const char* debugName)
+    {
+        ConsumeAttributeForPropertyAssetCtrl(GUI, attrib, attrValue, debugName);
     }
 
     void SimpleAssetPropertyHandlerDefault::WriteGUIValuesIntoProperty(size_t index, PropertyAssetCtrl* GUI, property_t& instance, InstanceDataNode* node)
@@ -1738,8 +1713,12 @@ namespace AzToolsFramework
 
     void RegisterAssetPropertyHandler()
     {
-        PropertyTypeRegistrationMessages::Bus::Broadcast(&PropertyTypeRegistrationMessages::RegisterPropertyType, aznew AssetPropertyHandlerDefault());
-        PropertyTypeRegistrationMessages::Bus::Broadcast(&PropertyTypeRegistrationMessages::RegisterPropertyType, aznew SimpleAssetPropertyHandlerDefault());
+        PropertyTypeRegistrationMessages::Bus::Broadcast(
+            &PropertyTypeRegistrationMessages::RegisterPropertyType, aznew AssetPropertyHandlerDefault());
+        PropertyTypeRegistrationMessages::Bus::Broadcast(
+            &PropertyTypeRegistrationMessages::RegisterPropertyType, aznew AssetIdPropertyHandlerDefault());
+        PropertyTypeRegistrationMessages::Bus::Broadcast(
+            &PropertyTypeRegistrationMessages::RegisterPropertyType, aznew SimpleAssetPropertyHandlerDefault());
     }
 }
 

+ 26 - 3
Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/PropertyAssetCtrl.hxx

@@ -270,6 +270,9 @@ namespace AzToolsFramework
         void UpdateEditButton();
     };
 
+    // Shared function that processes all attributes for any handler using PropertyAssetCtrl
+    void ConsumeAttributeForPropertyAssetCtrl(PropertyAssetCtrl* GUI, AZ::u32 attrib, PropertyAttributeReader* attrValue, const char* debugName);
+
     class AssetPropertyHandlerDefault
         : QObject
         , public PropertyHandler<AZ::Data::Asset<AZ::Data::AssetData>, PropertyAssetCtrl>
@@ -281,14 +284,13 @@ namespace AzToolsFramework
         AZ_CLASS_ALLOCATOR(AssetPropertyHandlerDefault, AZ::SystemAllocator, 0);
 
         virtual const AZ::Uuid& GetHandledType() const override;
-        virtual AZ::u32 GetHandlerName(void) const override { return AZ_CRC("Asset", 0x02af5a5c); }
+        virtual AZ::u32 GetHandlerName(void) const override { return AZ_CRC_CE("Asset"); }
         virtual bool IsDefaultHandler() const override { return true; }
         virtual QWidget* GetFirstInTabOrder(PropertyAssetCtrl* widget) override { return widget->GetFirstInTabOrder(); }
         virtual QWidget* GetLastInTabOrder(PropertyAssetCtrl* widget) override { return widget->GetLastInTabOrder(); }
         virtual void UpdateWidgetInternalTabbing(PropertyAssetCtrl* widget) override { widget->UpdateTabOrder(); }
 
         virtual QWidget* CreateGUI(QWidget* pParent) override;
-        static void ConsumeAttributeInternal(PropertyAssetCtrl* GUI, AZ::u32 attrib, PropertyAttributeReader* attrValue, const char* debugName);
         void ConsumeAttribute(PropertyAssetCtrl* GUI, AZ::u32 attrib, PropertyAttributeReader* attrValue, const char* debugName) override;
         static void WriteGUIValuesIntoPropertyInternal(size_t index, PropertyAssetCtrl* GUI, property_t& instance, InstanceDataNode* node);
         virtual void WriteGUIValuesIntoProperty(size_t index, PropertyAssetCtrl* GUI, property_t& instance, InstanceDataNode* node) override;
@@ -305,6 +307,27 @@ namespace AzToolsFramework
         }
     };
 
+    class AssetIdPropertyHandlerDefault
+        : QObject
+        , public PropertyHandler<AZ::Data::AssetId, PropertyAssetCtrl>
+    {
+        Q_OBJECT
+
+    public:
+        AZ_CLASS_ALLOCATOR(AssetIdPropertyHandlerDefault, AZ::SystemAllocator, 0);
+
+        virtual AZ::u32 GetHandlerName(void) const override { return AZ_CRC_CE("AssetId"); }
+        virtual bool IsDefaultHandler() const override { return true; }
+        virtual QWidget* GetFirstInTabOrder(PropertyAssetCtrl* widget) override { return widget->GetFirstInTabOrder(); }
+        virtual QWidget* GetLastInTabOrder(PropertyAssetCtrl* widget) override { return widget->GetLastInTabOrder(); }
+        virtual void UpdateWidgetInternalTabbing(PropertyAssetCtrl* widget) override { widget->UpdateTabOrder(); }
+
+        virtual QWidget* CreateGUI(QWidget* pParent) override;
+        virtual void ConsumeAttribute(PropertyAssetCtrl* GUI, AZ::u32 attrib, PropertyAttributeReader* attrValue, const char* debugName) override;
+        virtual void WriteGUIValuesIntoProperty(size_t index, PropertyAssetCtrl* GUI, property_t& instance, InstanceDataNode* node) override;
+        virtual bool ReadValuesIntoGUI(size_t index, PropertyAssetCtrl* GUI, const property_t& instance, InstanceDataNode* node)  override;
+    };
+
     class SimpleAssetPropertyHandlerDefault
         : QObject
         , public PropertyHandler<AzFramework::SimpleAssetReferenceBase, PropertyAssetCtrl>
@@ -315,7 +338,7 @@ namespace AzToolsFramework
     public:
         AZ_CLASS_ALLOCATOR(SimpleAssetPropertyHandlerDefault, AZ::SystemAllocator, 0);
 
-        virtual AZ::u32 GetHandlerName(void) const override { return AZ_CRC("SimpleAssetRef", 0x49f51d54); }
+        virtual AZ::u32 GetHandlerName(void) const override { return AZ_CRC_CE("SimpleAssetRef"); }
         virtual bool IsDefaultHandler() const override { return true; }
         virtual QWidget* GetFirstInTabOrder(PropertyAssetCtrl* widget) override { return widget->GetFirstInTabOrder(); }
         virtual QWidget* GetLastInTabOrder(PropertyAssetCtrl* widget) override { return widget->GetLastInTabOrder(); }

+ 2 - 2
Gems/GradientSignal/Code/Source/Editor/EditorStreamingImageAssetCtrl.cpp

@@ -138,8 +138,8 @@ namespace GradientSignal
 
     void StreamingImagePropertyHandler::ConsumeAttribute(StreamingImagePropertyAssetCtrl* GUI, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName)
     {
-        // Let the AssetPropertyHandlerDefault handle all of the attributes
-        AzToolsFramework::AssetPropertyHandlerDefault::ConsumeAttributeInternal(GUI, attrib, attrValue, debugName);
+        // Let ConsumeAttributeForPropertyAssetCtrl handle all of the attributes
+        AzToolsFramework::ConsumeAttributeForPropertyAssetCtrl(GUI, attrib, attrValue, debugName);
     }
 
     void StreamingImagePropertyHandler::WriteGUIValuesIntoProperty(size_t index, StreamingImagePropertyAssetCtrl* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* node)

+ 2 - 2
Gems/ScriptCanvas/Code/Editor/View/Widgets/SourceHandlePropertyAssetCtrl.cpp

@@ -120,8 +120,8 @@ namespace ScriptCanvasEditor
 
     void SourceHandlePropertyHandler::ConsumeAttribute(SourceHandlePropertyAssetCtrl* GUI, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName)
     {
-        // Let the AssetPropertyHandlerDefault handle all of the common attributes
-        AzToolsFramework::AssetPropertyHandlerDefault::ConsumeAttributeInternal(GUI, attrib, attrValue, debugName);
+        // Let ConsumeAttributeForPropertyAssetCtrl handle all of the common attributes
+        AzToolsFramework::ConsumeAttributeForPropertyAssetCtrl(GUI, attrib, attrValue, debugName);
 
         if (attrib == AZ::Edit::Attributes::SourceAssetFilterPattern)
         {