2019-12-26 15:33:43 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2019-05-06 06:04:18 -04:00
# include "MaterialShadingModelCustomization.h"
# include "IPropertyUtilities.h"
# include "PropertyRestriction.h"
# include "Engine/EngineTypes.h"
# include "IDetailChildrenBuilder.h"
# include "DetailLayoutBuilder.h"
# include "DetailCategoryBuilder.h"
# include "DetailWidgetRow.h"
# include "IDetailPropertyRow.h"
# include "PropertyCustomizationHelpers.h"
2019-05-06 07:25:03 -04:00
# include "MaterialEditor/MaterialEditorInstanceConstant.h"
2019-05-06 10:04:01 -04:00
# include "Materials/Material.h"
2019-05-06 06:04:18 -04:00
TSharedRef < IPropertyTypeCustomization > FMaterialShadingModelCustomization : : MakeInstance ( )
{
return MakeShareable ( new FMaterialShadingModelCustomization ) ;
}
void FMaterialShadingModelCustomization : : CustomizeHeader ( TSharedRef < IPropertyHandle > PropertyHandle , class FDetailWidgetRow & HeaderRow , IPropertyTypeCustomizationUtils & CustomizationUtils )
{
// Hide special value by default
bool bShouldHideFromMaterialExpression = true ;
// This piece of code enables the use of the Shading Model material output pin through selecting "From Material Expression" in the Shading Model drop down menu.
if ( PropertyHandle - > GetNumOuterObjects ( ) = = 1 )
{
TArray < UObject * > OuterObjects ;
PropertyHandle - > GetOuterObjects ( OuterObjects ) ;
2019-05-06 07:25:03 -04:00
// Don't hide MSM_FromMaterialExpression on a UMaterial or on UMaterialEditorInstanceConstant
if ( OuterObjects [ 0 ] - > IsA < UMaterial > ( ) | | OuterObjects [ 0 ] - > IsA < UMaterialEditorInstanceConstant > ( ) )
2019-05-06 06:04:18 -04:00
{
bShouldHideFromMaterialExpression = false ;
}
}
// Add restrictin to property if asked for
if ( bShouldHideFromMaterialExpression )
{
TSharedPtr < FPropertyRestriction > EnumRestriction = MakeShareable ( new FPropertyRestriction ( NSLOCTEXT ( " MaterialShadingModel " , " FromMaterialExpression " , " FromMaterialExpression is only available on UMaterial " ) ) ) ;
const UEnum * const MaterialShadingModelEnum = StaticEnum < EMaterialShadingModel > ( ) ;
EnumRestriction - > AddHiddenValue ( MaterialShadingModelEnum - > GetNameStringByValue ( ( int64 ) EMaterialShadingModel : : MSM_FromMaterialExpression ) ) ;
PropertyHandle - > AddRestriction ( EnumRestriction . ToSharedRef ( ) ) ;
}
// Implement the copmbobox for the enum
HeaderRow
. NameContent ( )
[
PropertyHandle - > CreatePropertyNameWidget ( )
]
. ValueContent ( )
2019-05-12 16:42:05 -04:00
. MinDesiredWidth ( 150.0f ) // To fit the longer names
. MaxDesiredWidth ( 0.0f ) // Don't care
2019-05-06 06:04:18 -04:00
[
PropertyCustomizationHelpers : : MakePropertyComboBox ( PropertyHandle )
] ;
}