// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved. #include "KeyStructCustomization.h" #include "DetailWidgetRow.h" #include "SKeySelector.h" #include "UObject/UnrealType.h" #define LOCTEXT_NAMESPACE "FKeyStructCustomization" /* FKeyStructCustomization static interface *****************************************************************************/ TSharedRef FKeyStructCustomization::MakeInstance( ) { return MakeShareable(new FKeyStructCustomization); } /* IPropertyTypeCustomization interface *****************************************************************************/ void FKeyStructCustomization::CustomizeHeader( TSharedRef StructPropertyHandle, class FDetailWidgetRow& HeaderRow, IPropertyTypeCustomizationUtils& StructCustomizationUtils ) { PropertyHandle = StructPropertyHandle; // create struct header HeaderRow.NameContent() [ StructPropertyHandle->CreatePropertyNameWidget() ] .ValueContent() .MinDesiredWidth(125.0f) .MaxDesiredWidth(325.0f) [ SNew(SKeySelector) .CurrentKey(this, &FKeyStructCustomization::GetCurrentKey) .OnKeyChanged(this, &FKeyStructCustomization::OnKeyChanged) .Font(StructCustomizationUtils.GetRegularFont()) .AllowClear(!StructPropertyHandle->GetProperty()->HasAnyPropertyFlags(CPF_NoClear)) ]; } TOptional FKeyStructCustomization::GetCurrentKey() const { TArray StructPtrs; PropertyHandle->AccessRawData(StructPtrs); if (StructPtrs.Num() > 0) { FKey* SelectedKey = (FKey*)StructPtrs[0]; if (SelectedKey) { for(int32 StructPtrIndex = 1; StructPtrIndex < StructPtrs.Num(); ++StructPtrIndex) { if (*(FKey*)StructPtrs[StructPtrIndex] != *SelectedKey) { return TOptional(); } } return *SelectedKey; } } return FKey(); } void FKeyStructCustomization::OnKeyChanged(TSharedPtr SelectedKey) { PropertyHandle->SetValueFromFormattedString(SelectedKey->ToString()); } #undef LOCTEXT_NAMESPACE