mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
Files
e59338fcbb052d40802ffaf991924b2aebf04341
110 lines
3.8 KiB
C++
110 lines
3.8 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|||
|
|||
#include "MaterialAttributePropertyDetails.h"
|
|||
#include "Widgets/Text/STextBlock.h"
|
|||
#include "MaterialShared.h"
|
|||
#include "DetailLayoutBuilder.h"
|
|||
#include "IDetailChildrenBuilder.h"
|
|||
#include "IDetailPropertyRow.h"
|
|||
#include "DetailCategoryBuilder.h"
|
|||
#include "PropertyCustomizationHelpers.h"
|
|||
#include "Widgets/Input/SComboBox.h"
|
|||
#include "Materials/MaterialExpressionGetMaterialAttributes.h"
|
|||
#include "Materials/MaterialExpressionSetMaterialAttributes.h"
|
|||
|
|||
TSharedRef<IDetailCustomization> FMaterialAttributePropertyDetails::MakeInstance()
|
|||
{
|
|||
return MakeShareable(new FMaterialAttributePropertyDetails);
|
|||
}
|
|||
|
|||
void FMaterialAttributePropertyDetails::CustomizeDetails(IDetailLayoutBuilder& DetailLayout)
|
|||
{
|
|||
// Populate combo boxes with material property list
|
|||
|
Copy up from Dev-Editor @10681378
#rb none
[CL 10837446 by Chris Gagnon in Dev-Tools-Staging branch]
|
FMaterialAttributeDefinitionMap::GetAttributeNameToIDList(AttributeNameToIDList);
|
||
|
|||
AttributeDisplayNameList.Empty(AttributeNameToIDList.Num());
|
|||
for (const TPair<FString, FGuid>& NameGUIDPair : AttributeNameToIDList)
|
|||
{
|
|||
AttributeDisplayNameList.Add(MakeShareable(new FString(NameGUIDPair.Key)));
|
|||
}
|
|||
|
|||
// Fetch root property we're dealing with
|
|||
TSharedPtr<IPropertyHandle> PropertyGetArray = DetailLayout.GetProperty(GET_MEMBER_NAME_CHECKED(UMaterialExpressionGetMaterialAttributes, AttributeGetTypes));
|
|||
TSharedPtr<IPropertyHandle> PropertySetArray = DetailLayout.GetProperty(GET_MEMBER_NAME_CHECKED(UMaterialExpressionSetMaterialAttributes, AttributeSetTypes));
|
|||
TSharedPtr<IPropertyHandle> PropertyArray;
|
|||
|
|||
if (PropertyGetArray->IsValidHandle())
|
|||
{
|
|||
PropertyArray = PropertyGetArray;
|
|||
}
|
|||
else if (PropertySetArray->IsValidHandle())
|
|||
{
|
|||
PropertyArray = PropertySetArray;
|
|||
}
|
|||
|
|||
check(PropertyArray->IsValidHandle());
|
|||
|
|||
// Add builder for children to handle array changes
|
|||
TSharedRef<FDetailArrayBuilder> ArrayChildBuilder = MakeShareable(new FDetailArrayBuilder(PropertyArray.ToSharedRef()));
|
|||
ArrayChildBuilder->OnGenerateArrayElementWidget(FOnGenerateArrayElementWidget::CreateSP(this, &FMaterialAttributePropertyDetails::OnBuildChild));
|
|||
|
|||
IDetailCategoryBuilder& AttributesCategory = DetailLayout.EditCategory("MaterialAttributes", FText::GetEmpty(), ECategoryPriority::Important);
|
|||
AttributesCategory.AddCustomBuilder(ArrayChildBuilder);
|
|||
}
|
|||
|
|||
void FMaterialAttributePropertyDetails::OnBuildChild(TSharedRef<IPropertyHandle> ChildHandle, int32 ElementIndex, IDetailChildrenBuilder& ChildrenBuilder)
|
|||
{
|
|||
// Add an overridden combo box
|
|||
IDetailPropertyRow& PropertyArrayRow = ChildrenBuilder.AddProperty(ChildHandle);
|
|||
|
|||
FPropertyComboBoxArgs ComboArgs(
|
|||
ChildHandle,
|
|||
FOnGetPropertyComboBoxStrings::CreateLambda([=](TArray<TSharedPtr<FString>>& OutComboBoxStrings, TArray<TSharedPtr<SToolTip>>& OutToolTips, TArray<bool>& OutRestrictedItems) -> void
|
|||
{
|
|||
OutComboBoxStrings = AttributeDisplayNameList;
|
|||
}),
|
|||
FOnGetPropertyComboBoxValue::CreateLambda( [=]() -> FString
|
|||
{
|
|||
FString AttributeName;
|
|||
if (ChildHandle->IsValidHandle())
|
|||
{
|
|||
// Convert attribute ID string to display name
|
|||
FString IDString; FGuid IDValue;
|
|||
ChildHandle->GetValueAsFormattedString(IDString);
|
|||
FGuid::ParseExact(IDString, EGuidFormats::Digits, IDValue);
|
|||
|
|||
AttributeName = FMaterialAttributeDefinitionMap::GetAttributeName(IDValue);
|
|||
}
|
|||
return AttributeName;
|
|||
}),
|
|||
FOnPropertyComboBoxValueSelected::CreateLambda( [=] (const FString& Selection)
|
|||
{
|
|||
if (ChildHandle->IsValidHandle())
|
|||
{
|
|||
// Convert display name to attribute ID
|
|||
for (const auto& NameIDPair : AttributeNameToIDList)
|
|||
{
|
|||
if (NameIDPair.Key == Selection)
|
|||
{
|
|||
ChildHandle->SetValueFromFormattedString(NameIDPair.Value.ToString(EGuidFormats::Digits));
|
|||
break;
|
|||
}
|
|||
}
|
|||
}
|
|||
})
|
|||
);
|
|||
ComboArgs.ShowSearchForItemCount = 1;
|
|||
|
|||
|
|||
PropertyArrayRow.CustomWidget()
|
|||
.NameContent()
|
|||
[
|
|||
ChildHandle->CreatePropertyNameWidget()
|
|||
]
|
|||
.ValueContent()
|
|||
[
|
|||
PropertyCustomizationHelpers::MakePropertyComboBox(ComboArgs)
|
|||
];
|
|||
}
|
|||
|