Fix sprite asset selection in property editor (#384)
* Fix sprite asset selection in property editor * Linux compile fix * More fixes for the custom Sprite property handler * PR feedback to use existing constant image extension
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
#include "UiCanvasEditor_precompiled.h"
|
||||
#include "EditorCommon.h"
|
||||
#include "Sprite.h"
|
||||
|
||||
#include "PropertyHandlerSprite.h"
|
||||
|
||||
@@ -31,6 +32,8 @@
|
||||
|
||||
#include <LmbrCentral/Rendering/MaterialAsset.h>
|
||||
|
||||
#include <Atom/RPI.Edit/Common/AssetUtils.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMessageBox>
|
||||
|
||||
@@ -44,6 +47,7 @@ PropertySpriteCtrl::PropertySpriteCtrl(QWidget* parent)
|
||||
[ this ]([[maybe_unused]] AZ::Data::AssetId newAssetID)
|
||||
{
|
||||
EBUS_EVENT(AzToolsFramework::PropertyEditorGUIMessages::Bus, RequestWrite, this);
|
||||
AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(&AzToolsFramework::PropertyEditorGUIMessages::Bus::Handler::OnEditingFinished, m_propertyAssetCtrl);
|
||||
});
|
||||
|
||||
setAcceptDrops(true);
|
||||
@@ -150,7 +154,9 @@ void PropertyHandlerSprite::WriteGUIValuesIntoProperty(size_t index, PropertySpr
|
||||
AZStd::string assetPath;
|
||||
EBUS_EVENT_RESULT(assetPath, AZ::Data::AssetCatalogRequestBus, GetAssetPathById, GUI->GetPropertyAssetCtrl()->GetCurrentAssetID());
|
||||
|
||||
instance.SetAssetPath(assetPath.c_str());
|
||||
// Convert streaming image's product path to relative source path to assign to the SimpleAssetReference<Texture>
|
||||
AZStd::string sourcePath = CSprite::GetImageSourcePathFromProductPath(assetPath);
|
||||
instance.SetAssetPath(sourcePath.c_str());
|
||||
}
|
||||
|
||||
bool PropertyHandlerSprite::ReadValuesIntoGUI(size_t index, PropertySpriteCtrl* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* node)
|
||||
@@ -162,12 +168,26 @@ bool PropertyHandlerSprite::ReadValuesIntoGUI(size_t index, PropertySpriteCtrl*
|
||||
|
||||
ctrl->blockSignals(true);
|
||||
{
|
||||
ctrl->SetCurrentAssetType(instance.GetAssetType());
|
||||
// Set the asset type for the PropertyAssetCtrl.
|
||||
// Use the hardcoded streaming image asset type instead of the passed in instance's asset type
|
||||
// since the passed in type is the legacy SimpleAssetReference<Texture>, and the asset picker
|
||||
// does not associate this type with streaming images
|
||||
AZ::Data::AssetType assetType = AZ::AzTypeInfo<AZ::RPI::StreamingImageAsset>::Uuid();
|
||||
ctrl->SetCurrentAssetType(assetType);
|
||||
|
||||
AZ::Data::AssetId assetId;
|
||||
if (!instance.GetAssetPath().empty())
|
||||
{
|
||||
EBUS_EVENT_RESULT(assetId, AZ::Data::AssetCatalogRequestBus, GetAssetIdByPath, instance.GetAssetPath().c_str(), instance.GetAssetType(), false);
|
||||
// Get the image path from the SimpleAssetReference<Texture> and fix it up since CSprite still
|
||||
// allows user specified paths that have the .sprite extension or the deprecated .dds extension
|
||||
AZStd::string sourcePath = CSprite::GetImageSourcePathFromProductPath(instance.GetAssetPath());
|
||||
AZStd::string fixedUpSourcePath;
|
||||
CSprite::FixUpSourceImagePathFromUserDefinedPath(sourcePath, fixedUpSourcePath);
|
||||
|
||||
AZ::Data::AssetCatalogRequestBus::BroadcastResult(
|
||||
assetId, &AZ::Data::AssetCatalogRequestBus::Events::GenerateAssetIdTEMP,
|
||||
fixedUpSourcePath.c_str());
|
||||
assetId.m_subId = AZ::RPI::StreamingImageAsset::GetImageAssetSubId();
|
||||
}
|
||||
ctrl->SetSelectedAssetID(assetId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user