2014-12-07 19:09:38 -05:00
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
2014-03-14 14:13:41 -04:00
# include "DetailCustomizationsPrivatePCH.h"
# include "GuidStructCustomization.h"
# define LOCTEXT_NAMESPACE "FGuidStructCustomization"
2014-06-04 10:16:14 -04:00
/* IPropertyTypeCustomization interface
2014-03-14 14:13:41 -04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2014-06-04 11:16:24 -04:00
void FGuidStructCustomization : : CustomizeHeader ( TSharedRef < class IPropertyHandle > StructPropertyHandle , class FDetailWidgetRow & HeaderRow , IPropertyTypeCustomizationUtils & StructCustomizationUtils )
2014-03-14 14:13:41 -04:00
{
PropertyHandle = StructPropertyHandle ;
InputValid = true ;
2014-05-07 11:15:00 -04:00
TSharedPtr < SWidget > QuickSetSlotContent ;
2014-03-14 14:13:41 -04:00
2014-05-07 11:15:00 -04:00
// create quick-set menu if needed
if ( PropertyHandle - > IsEditConst ( ) )
{
QuickSetSlotContent = SNullWidget : : NullWidget ;
}
else
{
FMenuBuilder QuickSetMenuBuilder ( true , nullptr ) ;
{
FUIAction GenerateAction ( FExecuteAction : : CreateSP ( this , & FGuidStructCustomization : : HandleGuidActionClicked , EPropertyEditorGuidActions : : Generate ) ) ;
QuickSetMenuBuilder . AddMenuEntry ( LOCTEXT ( " GenerateAction " , " Generate " ) , LOCTEXT ( " GenerateActionHint " , " Generate a new random globally unique identifier (GUID). " ) , FSlateIcon ( ) , GenerateAction ) ;
FUIAction InvalidateAction ( FExecuteAction : : CreateSP ( this , & FGuidStructCustomization : : HandleGuidActionClicked , EPropertyEditorGuidActions : : Invalidate ) ) ;
QuickSetMenuBuilder . AddMenuEntry ( LOCTEXT ( " InvalidateAction " , " Invalidate " ) , LOCTEXT ( " InvalidateActionHint " , " Set an invalid globally unique identifier (GUID). " ) , FSlateIcon ( ) , InvalidateAction ) ;
}
QuickSetSlotContent = SNew ( SComboButton )
. ContentPadding ( FMargin ( 6.0 , 2.0 ) )
. MenuContent ( )
[
QuickSetMenuBuilder . MakeWidget ( )
] ;
2014-03-14 14:13:41 -04:00
}
// create struct header
2014-05-07 11:15:00 -04:00
HeaderRow
. NameContent ( )
[
StructPropertyHandle - > CreatePropertyNameWidget ( )
]
. ValueContent ( )
. MinDesiredWidth ( 325.0f )
. MaxDesiredWidth ( 325.0f )
[
SNew ( SHorizontalBox )
2014-03-14 14:13:41 -04:00
2014-05-07 11:15:00 -04:00
+ SHorizontalBox : : Slot ( )
. FillWidth ( 1.0f )
[
// text box
SAssignNew ( TextBox , SEditableTextBox )
. ClearKeyboardFocusOnCommit ( false )
. IsEnabled ( ! PropertyHandle - > IsEditConst ( ) )
. ForegroundColor ( this , & FGuidStructCustomization : : HandleTextBoxForegroundColor )
. OnTextChanged ( this , & FGuidStructCustomization : : HandleTextBoxTextChanged )
. OnTextCommitted ( this , & FGuidStructCustomization : : HandleTextBoxTextCommited )
. SelectAllTextOnCommit ( true )
. Text ( this , & FGuidStructCustomization : : HandleTextBoxText )
]
2014-03-14 14:13:41 -04:00
2014-05-07 11:15:00 -04:00
+ SHorizontalBox : : Slot ( )
. AutoWidth ( )
[
// quick set menu
QuickSetSlotContent . ToSharedRef ( )
]
] ;
2014-03-14 14:13:41 -04:00
}
2014-06-04 11:16:24 -04:00
void FGuidStructCustomization : : CustomizeChildren ( TSharedRef < class IPropertyHandle > StructPropertyHandle , class IDetailChildrenBuilder & StructBuilder , IPropertyTypeCustomizationUtils & StructCustomizationUtils )
2014-03-14 14:13:41 -04:00
{
// do nothing
}
/* FGuidStructCustomization implementation
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void FGuidStructCustomization : : SetGuidValue ( const FGuid & Guid )
{
for ( uint32 ChildIndex = 0 ; ChildIndex < 4 ; + + ChildIndex )
{
TSharedRef < IPropertyHandle > ChildHandle = PropertyHandle - > GetChildHandle ( ChildIndex ) . ToSharedRef ( ) ;
ChildHandle - > SetValue ( ( int32 ) Guid [ ChildIndex ] ) ;
}
}
/* FGuidStructCustomization callbacks
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void FGuidStructCustomization : : HandleGuidActionClicked ( EPropertyEditorGuidActions : : Type Action )
{
if ( Action = = EPropertyEditorGuidActions : : Generate )
{
SetGuidValue ( FGuid : : NewGuid ( ) ) ;
}
else if ( Action = = EPropertyEditorGuidActions : : Invalidate )
{
SetGuidValue ( FGuid ( ) ) ;
}
}
FSlateColor FGuidStructCustomization : : HandleTextBoxForegroundColor ( ) const
{
if ( InputValid )
{
2014-11-18 09:57:20 -05:00
static const FName InvertedForegroundName ( " InvertedForeground " ) ;
return FEditorStyle : : GetSlateColor ( InvertedForegroundName ) ;
2014-03-14 14:13:41 -04:00
}
return FLinearColor : : Red ;
}
FText FGuidStructCustomization : : HandleTextBoxText ( ) const
{
TArray < void * > RawData ;
PropertyHandle - > AccessRawData ( RawData ) ;
if ( RawData . Num ( ) ! = 1 )
{
return LOCTEXT ( " MultipleValues " , " Multiple Values " ) ;
}
2015-01-27 13:00:47 -05:00
if ( RawData [ 0 ] = = nullptr )
{
return FText : : GetEmpty ( ) ;
}
2014-03-14 14:13:41 -04:00
return FText : : FromString ( ( ( FGuid * ) RawData [ 0 ] ) - > ToString ( EGuidFormats : : DigitsWithHyphensInBraces ) ) ;
}
void FGuidStructCustomization : : HandleTextBoxTextChanged ( const FText & NewText )
{
FGuid Guid ;
InputValid = FGuid : : Parse ( NewText . ToString ( ) , Guid ) ;
}
void FGuidStructCustomization : : HandleTextBoxTextCommited ( const FText & NewText , ETextCommit : : Type CommitInfo )
{
FGuid ParsedGuid ;
if ( FGuid : : Parse ( NewText . ToString ( ) , ParsedGuid ) )
{
SetGuidValue ( ParsedGuid ) ;
}
}
# undef LOCTEXT_NAMESPACE