// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved. #include "MaterialProxySettingsCustomizations.h" #include "Misc/Attribute.h" #include "UObject/UnrealType.h" #include "Engine/MaterialMerging.h" #include "PropertyHandle.h" #include "IDetailChildrenBuilder.h" #include "DetailWidgetRow.h" #include "IDetailPropertyRow.h" #define LOCTEXT_NAMESPACE "MaterialProxySettingsCustomizations" TSharedRef FMaterialProxySettingsCustomizations::MakeInstance() { return MakeShareable(new FMaterialProxySettingsCustomizations); } void FMaterialProxySettingsCustomizations::CustomizeHeader(TSharedRef StructPropertyHandle, FDetailWidgetRow& HeaderRow, IPropertyTypeCustomizationUtils& CustomizationUtils) { HeaderRow. NameContent() [ StructPropertyHandle->CreatePropertyNameWidget() ] .ValueContent() [ StructPropertyHandle->CreatePropertyValueWidget() ]; } void FMaterialProxySettingsCustomizations::CustomizeChildren(TSharedRef StructPropertyHandle, class IDetailChildrenBuilder& ChildBuilder, IPropertyTypeCustomizationUtils& StructCustomizationUtils) { // Retrieve structure's child properties uint32 NumChildren; StructPropertyHandle->GetNumChildren( NumChildren ); TMap > PropertyHandles; for( uint32 ChildIndex = 0; ChildIndex < NumChildren; ++ChildIndex ) { TSharedRef ChildHandle = StructPropertyHandle->GetChildHandle( ChildIndex ).ToSharedRef(); const FName PropertyName = ChildHandle->GetProperty()->GetFName(); PropertyHandles.Add(PropertyName, ChildHandle); } // Retrieve special case properties EnumHandle = PropertyHandles.FindChecked(GET_MEMBER_NAME_CHECKED(FMaterialProxySettings, TextureSizingType)); TextureSizeHandle = PropertyHandles.FindChecked(GET_MEMBER_NAME_CHECKED(FMaterialProxySettings, TextureSize)); DiffuseTextureSizeHandle = PropertyHandles.FindChecked(GET_MEMBER_NAME_CHECKED(FMaterialProxySettings, DiffuseTextureSize)); NormalTextureSizeHandle = PropertyHandles.FindChecked(GET_MEMBER_NAME_CHECKED(FMaterialProxySettings, NormalTextureSize)); MetallicTextureSizeHandle = PropertyHandles.FindChecked(GET_MEMBER_NAME_CHECKED(FMaterialProxySettings, MetallicTextureSize)); RoughnessTextureSizeHandle = PropertyHandles.FindChecked(GET_MEMBER_NAME_CHECKED(FMaterialProxySettings, RoughnessTextureSize)); SpecularTextureSizeHandle = PropertyHandles.FindChecked(GET_MEMBER_NAME_CHECKED(FMaterialProxySettings, SpecularTextureSize)); EmissiveTextureSizeHandle = PropertyHandles.FindChecked(GET_MEMBER_NAME_CHECKED(FMaterialProxySettings, EmissiveTextureSize)); OpacityTextureSizeHandle = PropertyHandles.FindChecked(GET_MEMBER_NAME_CHECKED(FMaterialProxySettings, OpacityTextureSize)); OpacityMaskTextureSizeHandle = PropertyHandles.FindChecked(GET_MEMBER_NAME_CHECKED(FMaterialProxySettings, OpacityMaskTextureSize)); if (PropertyHandles.Contains(GET_MEMBER_NAME_CHECKED(FMaterialProxySettings, MaterialMergeType))) { MergeTypeHandle = PropertyHandles.FindChecked(GET_MEMBER_NAME_CHECKED(FMaterialProxySettings, MaterialMergeType)); } GutterSpaceHandle = PropertyHandles.FindChecked(GET_MEMBER_NAME_CHECKED(FMaterialProxySettings, GutterSpace)); auto Parent = StructPropertyHandle->GetParentHandle(); for( auto Iter(PropertyHandles.CreateConstIterator()); Iter; ++Iter ) { // Handle special property cases (done inside the loop to maintain order according to the struct if (Iter.Value() == DiffuseTextureSizeHandle || Iter.Value() == DiffuseTextureSizeHandle || Iter.Value() == NormalTextureSizeHandle || Iter.Value() == MetallicTextureSizeHandle || Iter.Value() == RoughnessTextureSizeHandle || Iter.Value() == SpecularTextureSizeHandle || Iter.Value() == EmissiveTextureSizeHandle || Iter.Value() == OpacityTextureSizeHandle || Iter.Value() == OpacityMaskTextureSizeHandle ) { IDetailPropertyRow& SizeRow = ChildBuilder.AddChildProperty(Iter.Value().ToSharedRef()); SizeRow.Visibility(TAttribute(this, &FMaterialProxySettingsCustomizations::AreManualOverrideTextureSizesEnabled)); } else if (Iter.Value() == TextureSizeHandle) { IDetailPropertyRow& SettingsRow = ChildBuilder.AddChildProperty(Iter.Value().ToSharedRef()); SettingsRow.Visibility(TAttribute(this, &FMaterialProxySettingsCustomizations::IsTextureSizeEnabled)); } else if (Iter.Value() == GutterSpaceHandle) { IDetailPropertyRow& SettingsRow = ChildBuilder.AddChildProperty(Iter.Value().ToSharedRef()); SettingsRow.Visibility(TAttribute(this, &FMaterialProxySettingsCustomizations::IsSimplygonMaterialMergingVisible)); } // Do not show the merge type property else if (Iter.Value() != MergeTypeHandle) { IDetailPropertyRow& SettingsRow = ChildBuilder.AddChildProperty(Iter.Value().ToSharedRef()); } } } EVisibility FMaterialProxySettingsCustomizations::AreManualOverrideTextureSizesEnabled() const { uint8 TypeValue; EnumHandle->GetValue(TypeValue); if (TypeValue == TextureSizingType_UseManualOverrideTextureSize) { return EVisibility::Visible; } return EVisibility::Hidden; } EVisibility FMaterialProxySettingsCustomizations::IsTextureSizeEnabled() const { uint8 TypeValue; EnumHandle->GetValue(TypeValue); if (TypeValue == TextureSizingType_UseSimplygonAutomaticSizing || TypeValue == TextureSizingType_UseManualOverrideTextureSize) { return EVisibility::Hidden; } return EVisibility::Visible; } EVisibility FMaterialProxySettingsCustomizations::IsSimplygonMaterialMergingVisible() const { uint8 MergeType = EMaterialMergeType::MaterialMergeType_Default; if (MergeTypeHandle.IsValid()) { MergeTypeHandle->GetValue(MergeType); } return ( MergeType == EMaterialMergeType::MaterialMergeType_Simplygon ) ? EVisibility::Visible : EVisibility::Hidden; } #undef LOCTEXT_NAMESPACE