// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved. /*============================================================================= KeyStructCustomization.cpp: Implements the FKeyStructCustomization class. =============================================================================*/ #include "DetailCustomizationsPrivatePCH.h" #include "KeyStructCustomization.h" #include "ScopedTransaction.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; TArray StructPtrs; StructPropertyHandle->AccessRawData(StructPtrs); check(StructPtrs.Num() != 0); const FKey& SelectedKey = *(FKey*)StructPtrs[0]; bool bMultipleValues = false; for (int32 StructPtrIndex = 1; StructPtrIndex < StructPtrs.Num(); ++StructPtrIndex) { if (*(FKey*)StructPtrs[StructPtrIndex] != SelectedKey) { bMultipleValues = true; break; } } TSharedPtr InitialSelectedItem; TArray AllKeys; EKeys::GetAllKeys(AllKeys); for (FKey Key : AllKeys) { TSharedPtr InputKey = MakeShareable(new FKey(Key)); InputKeys.Add(InputKey); if (Key == SelectedKey) { InitialSelectedItem = InputKey; } } // create struct header HeaderRow.NameContent() [ StructPropertyHandle->CreatePropertyNameWidget() ] .ValueContent() .MinDesiredWidth(125.0f) .MaxDesiredWidth(325.0f) [ SNew(SHorizontalBox) + SHorizontalBox::Slot() .FillWidth(1.0f) [ // text box SNew(SComboBox< TSharedPtr >) .OptionsSource(&InputKeys) .InitiallySelectedItem(InitialSelectedItem) .OnGenerateWidget(this, &FKeyStructCustomization::OnGenerateComboWidget) .OnSelectionChanged(this, &FKeyStructCustomization::OnSelectionChanged) .Content() [ SAssignNew(TextBlock, STextBlock) .Text(bMultipleValues ? LOCTEXT("MultipleValues", "Multiple Values") : SelectedKey.GetDisplayName()) .Font(StructCustomizationUtils.GetRegularFont()) ] ] ]; } TSharedRef FKeyStructCustomization::OnGenerateComboWidget(TSharedPtr Key) { return SNew(STextBlock) .Text(Key->GetDisplayName()); } void FKeyStructCustomization::OnSelectionChanged(TSharedPtr SelectedItem, ESelectInfo::Type SelectInfo) { PropertyHandle->SetValueFromFormattedString(SelectedItem->ToString()); TextBlock->SetText(SelectedItem->GetDisplayName()); } #undef LOCTEXT_NAMESPACE