Files
UnrealEngineUWP/Engine/Source/Developer/SettingsEditor/Private/Customizations/PerPlatformSettingsCustomization.cpp
michael noland c8dc8362b7 Prevent a crash when there is more than one kind of UPlatformSettings usage in a project
- Removed the problematic static that caused the crash and introduced a new caching system via a UPlatformSettingsManager class that keeps explicit references to the settings instead of adding them to the root
- Switched the platform names to be more consistently FName instead of roundtripping through FString

- Slightly unrelated: Added DeterminesOutputType metadata to FindParentWidgetOfType to avoid needing an extra cast in typical usage

#jira UE-142875
#rb nick.darnell
#preflight 620c788a252ef638b5806fd7

#ROBOMERGE-AUTHOR: michael.noland
#ROBOMERGE-SOURCE: CL 19060400 in //UE5/Release-5.0/... via CL 19076932
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v921-19075845)

[CL 19120907 by michael noland in ue5-main branch]
2022-02-24 14:23:31 -05:00

72 lines
2.9 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "PerPlatformSettingsCustomization.h"
#include "DetailWidgetRow.h"
#include "Widgets/SBoxPanel.h"
#include "Widgets/Images/SImage.h"
#include "EditorStyleSet.h"
#include "Engine/PlatformSettings.h"
#include "IDetailGroup.h"
#include "IDetailChildrenBuilder.h"
TSharedRef<IPropertyTypeCustomization> FPerPlatformSettingsCustomization::MakeInstance()
{
return MakeShareable(new FPerPlatformSettingsCustomization);
}
FPerPlatformSettingsCustomization::FPerPlatformSettingsCustomization()
{
}
void FPerPlatformSettingsCustomization::CustomizeHeader(TSharedRef<IPropertyHandle> PropertyHandle, FDetailWidgetRow& HeaderRow, IPropertyTypeCustomizationUtils& CustomizationUtils)
{
HeaderRow
.WholeRowContent()
.MaxDesiredWidth(TOptional<float>())
.MaxDesiredWidth(TOptional<float>())
[
PropertyHandle->CreatePropertyNameWidget()
];
}
void FPerPlatformSettingsCustomization::CustomizeChildren(TSharedRef<IPropertyHandle> PropertyHandle, IDetailChildrenBuilder& ChildBuilder, IPropertyTypeCustomizationUtils& CustomizationUtils)
{
TSharedPtr<IPropertyHandle> SettingsProperty = PropertyHandle->GetChildHandle(GET_MEMBER_NAME_CHECKED(FPerPlatformSettings, Settings));
TSharedPtr<IPropertyHandleArray> SettingsPropertyArray = SettingsProperty->AsArray();
uint32 NumSettings;
SettingsPropertyArray->GetNumElements(NumSettings);
for (uint32 Index = 0; Index < NumSettings; ++Index)
{
TSharedPtr<IPropertyHandle> PlatformSettingsProperty = SettingsPropertyArray->GetElement(Index);
if (PlatformSettingsProperty->IsValidHandle())
{
UObject* PlatformSettingsObject;
FPropertyAccess::Result Result = PlatformSettingsProperty->GetValue(PlatformSettingsObject);
if (Result == FPropertyAccess::Success)
{
if (UPlatformSettings* PlatformSettings = Cast<UPlatformSettings>(PlatformSettingsObject))
{
FAddPropertyParams Params = FAddPropertyParams()
.UniqueId(PlatformSettings->GetFName())
.AllowChildren(true)
.CreateCategoryNodes(false);
IDetailGroup& PlatformGroup = ChildBuilder.AddGroup(PlatformSettings->GetFName(), FText::FromName(PlatformSettings->GetPlatformIniName()));
TSharedPtr<IPropertyHandle> PlatformSettingsPropertyArrayEntry = PlatformSettingsProperty->GetChildHandle(0);
//FDetailWidgetRow& PlatformGroup = ChildBuilder.AddCustomRow(FText::FromString(PlatformSettings->GetPlatformIniName()));
uint32 PlatformPropertiesChildHandleCount;
PlatformSettingsPropertyArrayEntry->GetNumChildren(PlatformPropertiesChildHandleCount);
for (uint32 PlatformPropertyIndex = 0; PlatformPropertyIndex < PlatformPropertiesChildHandleCount; PlatformPropertyIndex++)
{
TSharedPtr<IPropertyHandle> PlatformPropertyHandle = PlatformSettingsPropertyArrayEntry->GetChildHandle(PlatformPropertyIndex);
PlatformGroup.AddPropertyRow(PlatformPropertyHandle.ToSharedRef());
}
}
}
}
}
}