Added property handler for SourceHandle type.

Signed-off-by: Chris Galvan <chgalvan@amazon.com>
This commit is contained in:
Chris Galvan
2021-11-19 14:52:45 -06:00
committed by Chris Burel
parent b4407e5044
commit befd84cf0b
5 changed files with 211 additions and 0 deletions
@@ -133,6 +133,8 @@ namespace AZ
const static AZ::Crc32 AllowClearAsset = AZ_CRC("AllowClearAsset", 0x24827182);
// Show the name of the asset that was produced from the source asset
const static AZ::Crc32 ShowProductAssetFileName = AZ_CRC("ShowProductAssetFileName");
//! Regular expression pattern filter for source files
const static AZ::Crc32 SourceAssetFilterPattern = AZ_CRC_CE("SourceAssetFilterPattern");
//! Component icon attributes
const static AZ::Crc32 Icon = AZ_CRC("Icon", 0x659429db);
@@ -22,6 +22,7 @@
#include <Editor/SystemComponent.h>
#include <Editor/View/Dialogs/NewGraphDialog.h>
#include <Editor/View/Dialogs/SettingsDialog.h>
#include <Editor/View/Widgets/SourceHandlePropertyAssetCtrl.h>
#include <Editor/View/Windows/MainWindow.h>
#include <GraphCanvas/GraphCanvasBus.h>
#include <LyViewPaneNames.h>
@@ -119,6 +120,7 @@ namespace ScriptCanvasEditor
PopulateEditorCreatableTypes();
AzToolsFramework::RegisterGenericComboBoxHandler<ScriptCanvas::VariableId>();
AzToolsFramework::PropertyTypeRegistrationMessages::Bus::Broadcast(&AzToolsFramework::PropertyTypeRegistrationMessages::RegisterPropertyType, aznew SourceHandlePropertyHandler());
SystemRequestBus::Handler::BusConnect();
ScriptCanvasExecutionBus::Handler::BusConnect();
@@ -0,0 +1,138 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <ScriptCanvas/Components/EditorUtils.h>
#include <Editor/View/Widgets/SourceHandlePropertyAssetCtrl.h>
#include <AzFramework/StringFunc/StringFunc.h>
#include <AzToolsFramework/AssetBrowser/AssetBrowserBus.h>
#include <AzToolsFramework/AssetBrowser/AssetBrowserEntry.h>
#include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
namespace ScriptCanvasEditor
{
SourceHandlePropertyAssetCtrl::SourceHandlePropertyAssetCtrl(QWidget* parent)
: AzToolsFramework::PropertyAssetCtrl(parent)
{
}
AzToolsFramework::AssetBrowser::AssetSelectionModel SourceHandlePropertyAssetCtrl::GetAssetSelectionModel()
{
auto selectionModel = AssetSelectionModel::SourceAssetTypeSelection(m_sourceAssetFilterPattern);
selectionModel.SetTitle(m_title);
return selectionModel;
}
void SourceHandlePropertyAssetCtrl::PopupAssetPicker()
{
// Request the AssetBrowser Dialog and set a type filter
AssetSelectionModel selection = GetAssetSelectionModel();
selection.SetSelectedFilePath(m_selectedSourcePath.c_str());
AZStd::string defaultDirectory;
if (m_defaultDirectoryCallback)
{
m_defaultDirectoryCallback->Invoke(m_editNotifyTarget, defaultDirectory);
selection.SetDefaultDirectory(defaultDirectory);
}
AssetBrowserComponentRequestBus::Broadcast(&AssetBrowserComponentRequests::PickAssets, selection, parentWidget());
if (selection.IsValid())
{
const auto source = azrtti_cast<const SourceAssetBrowserEntry*>(selection.GetResult());
AZ_Assert(source, "Incorrect entry type selected. Expected source.");
if (source)
{
SetSelectedSourcePath(source->GetFullPath());
}
}
}
void SourceHandlePropertyAssetCtrl::ClearAssetInternal()
{
SetSelectedSourcePath("");
PropertyAssetCtrl::ClearAssetInternal();
}
void SourceHandlePropertyAssetCtrl::SetSourceAssetFilterPattern(const QString& filterPattern)
{
m_sourceAssetFilterPattern = filterPattern;
}
AZ::IO::Path SourceHandlePropertyAssetCtrl::GetSelectedSourcePath() const
{
return m_selectedSourcePath;
}
void SourceHandlePropertyAssetCtrl::SetSelectedSourcePath(const AZ::IO::Path& sourcePath)
{
m_selectedSourcePath = sourcePath;
AZStd::string displayText;
if (!sourcePath.empty())
{
AzFramework::StringFunc::Path::GetFileName(sourcePath.c_str(), displayText);
}
m_browseEdit->setText(displayText.c_str());
// The AssetID gets ignored, the only important bit is triggering the change for the RequestWrite
emit OnAssetIDChanged(AZ::Data::AssetId());
}
QWidget* SourceHandlePropertyHandler::CreateGUI(QWidget* pParent)
{
SourceHandlePropertyAssetCtrl* newCtrl = aznew SourceHandlePropertyAssetCtrl(pParent);
connect(newCtrl, &SourceHandlePropertyAssetCtrl::OnAssetIDChanged, this, [newCtrl](AZ::Data::AssetId newAssetID)
{
(void)newAssetID;
AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(&AzToolsFramework::PropertyEditorGUIMessages::RequestWrite, newCtrl);
AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(&AzToolsFramework::PropertyEditorGUIMessages::OnEditingFinished, newCtrl);
});
return newCtrl;
}
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);
if (attrib == AZ::Edit::Attributes::SourceAssetFilterPattern)
{
AZStd::string filterPattern;
if (attrValue->Read<AZStd::string>(filterPattern))
{
GUI->SetSourceAssetFilterPattern(filterPattern.c_str());
}
}
}
void SourceHandlePropertyHandler::WriteGUIValuesIntoProperty(size_t index, SourceHandlePropertyAssetCtrl* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* node)
{
(void)index;
(void)node;
auto sourceHandle = SourceHandle(nullptr, {}, GUI->GetSelectedSourcePath());
instance = property_t(*CompleteDescription(sourceHandle));
}
bool SourceHandlePropertyHandler::ReadValuesIntoGUI(size_t index, SourceHandlePropertyAssetCtrl* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* node)
{
(void)index;
(void)node;
GUI->blockSignals(true);
GUI->SetSelectedSourcePath(instance.Path());
GUI->SetEditNotifyTarget(node->GetParent()->GetInstance(0));
GUI->blockSignals(false);
return false;
}
}
@@ -0,0 +1,67 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#if !defined(Q_MOC_RUN)
#include <AzToolsFramework/UI/PropertyEditor/PropertyAssetCtrl.hxx>
#include <Core/Core.h>
#endif
namespace ScriptCanvasEditor
{
class SourceHandlePropertyAssetCtrl
: public AzToolsFramework::PropertyAssetCtrl
{
Q_OBJECT
public:
AZ_CLASS_ALLOCATOR(SourceHandlePropertyAssetCtrl, AZ::SystemAllocator, 0);
SourceHandlePropertyAssetCtrl(QWidget* parent = nullptr);
AzToolsFramework::AssetBrowser::AssetSelectionModel GetAssetSelectionModel() override;
void PopupAssetPicker() override;
void ClearAssetInternal() override;
void SetSourceAssetFilterPattern(const QString& filterPattern);
AZ::IO::Path GetSelectedSourcePath() const;
void SetSelectedSourcePath(const AZ::IO::Path& sourcePath);
private:
//! A regular expression pattern for filtering by source assets
//! If this is set, the PropertyAssetCtrl will be dealing with source assets
//! instead of a specific asset type
QString m_sourceAssetFilterPattern;
AZ::IO::Path m_selectedSourcePath;
};
class SourceHandlePropertyHandler
: QObject
, public AzToolsFramework::PropertyHandler<SourceHandle, SourceHandlePropertyAssetCtrl>
{
Q_OBJECT
public:
AZ_CLASS_ALLOCATOR(SourceHandlePropertyHandler, AZ::SystemAllocator, 0);
AZ::u32 GetHandlerName(void) const override { return AZ_CRC_CE("SourceHandle"); }
bool IsDefaultHandler() const override { return true; }
QWidget* GetFirstInTabOrder(SourceHandlePropertyAssetCtrl* widget) override { return widget->GetFirstInTabOrder(); }
QWidget* GetLastInTabOrder(SourceHandlePropertyAssetCtrl* widget) override { return widget->GetLastInTabOrder(); }
void UpdateWidgetInternalTabbing(SourceHandlePropertyAssetCtrl* widget) override { widget->UpdateTabOrder(); }
QWidget* CreateGUI(QWidget* pParent) override;
void ConsumeAttribute(SourceHandlePropertyAssetCtrl* GUI, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName) override;
void WriteGUIValuesIntoProperty(size_t index, SourceHandlePropertyAssetCtrl* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* node) override;
bool ReadValuesIntoGUI(size_t index, SourceHandlePropertyAssetCtrl* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* node) override;
};
}
@@ -182,6 +182,8 @@ set(FILES
Editor/View/Widgets/ScriptCanvasNodePaletteDockWidget.h
Editor/View/Widgets/ScriptCanvasNodePaletteDockWidget.cpp
Editor/View/Widgets/ScriptCanvasNodePaletteToolbar.ui
Editor/View/Widgets/SourceHandlePropertyAssetCtrl.h
Editor/View/Widgets/SourceHandlePropertyAssetCtrl.cpp
Editor/View/Widgets/WidgetBus.h
Editor/View/Widgets/DataTypePalette/DataTypePaletteModel.cpp
Editor/View/Widgets/DataTypePalette/DataTypePaletteModel.h