2014-12-07 19:09:38 -05:00
|
|
|
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
|
2014-09-02 19:28:15 -04:00
|
|
|
|
|
|
|
|
#include "DetailCustomizationsPrivatePCH.h"
|
|
|
|
|
#include "TimespanStructCustomization.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define LOCTEXT_NAMESPACE "TimespanStructCustomization"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* IDetailCustomization interface
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void FTimespanStructCustomization::CustomizeChildren( TSharedRef<IPropertyHandle> StructPropertyHandle, class IDetailChildrenBuilder& StructBuilder, IPropertyTypeCustomizationUtils& StructCustomizationUtils )
|
|
|
|
|
{
|
|
|
|
|
/* do nothing */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FTimespanStructCustomization::CustomizeHeader( TSharedRef<IPropertyHandle> StructPropertyHandle, class FDetailWidgetRow& HeaderRow, IPropertyTypeCustomizationUtils& StructCustomizationUtils )
|
|
|
|
|
{
|
|
|
|
|
PropertyHandle = StructPropertyHandle;
|
|
|
|
|
|
|
|
|
|
HeaderRow
|
|
|
|
|
.NameContent()
|
|
|
|
|
[
|
|
|
|
|
StructPropertyHandle->CreatePropertyNameWidget()
|
|
|
|
|
]
|
|
|
|
|
.ValueContent()
|
|
|
|
|
.MaxDesiredWidth(0.0f)
|
|
|
|
|
.MinDesiredWidth(125.0f)
|
|
|
|
|
[
|
|
|
|
|
SNew(SEditableTextBox)
|
|
|
|
|
.ClearKeyboardFocusOnCommit(false)
|
|
|
|
|
.IsEnabled(!PropertyHandle->IsEditConst())
|
|
|
|
|
.ForegroundColor(this, &FTimespanStructCustomization::HandleTextBoxForegroundColor)
|
|
|
|
|
.OnTextChanged(this, &FTimespanStructCustomization::HandleTextBoxTextChanged)
|
|
|
|
|
.OnTextCommitted(this, &FTimespanStructCustomization::HandleTextBoxTextCommited)
|
|
|
|
|
.SelectAllTextOnCommit(true)
|
2015-03-09 09:00:40 -04:00
|
|
|
.Font( IPropertyTypeCustomizationUtils::GetRegularFont() )
|
2014-09-02 19:28:15 -04:00
|
|
|
.Text(this, &FTimespanStructCustomization::HandleTextBoxText)
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* FTimespanStructCustomization callbacks
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
FSlateColor FTimespanStructCustomization::HandleTextBoxForegroundColor( ) const
|
|
|
|
|
{
|
|
|
|
|
if (InputValid)
|
|
|
|
|
{
|
2014-11-18 09:57:20 -05:00
|
|
|
static const FName InvertedForegroundName("InvertedForeground");
|
|
|
|
|
return FEditorStyle::GetSlateColor(InvertedForegroundName);
|
2014-09-02 19:28:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FLinearColor::Red;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FText FTimespanStructCustomization::HandleTextBoxText( ) const
|
|
|
|
|
{
|
|
|
|
|
TArray<void*> RawData;
|
|
|
|
|
PropertyHandle->AccessRawData(RawData);
|
|
|
|
|
|
|
|
|
|
if (RawData.Num() != 1)
|
|
|
|
|
{
|
|
|
|
|
return LOCTEXT("MultipleValues", "Multiple Values");
|
|
|
|
|
}
|
2015-03-09 09:00:40 -04:00
|
|
|
else if( RawData[0] == nullptr )
|
|
|
|
|
{
|
|
|
|
|
return FText::GetEmpty();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return FText::FromString(((FTimespan*)RawData[0])->ToString());
|
|
|
|
|
}
|
2014-09-02 19:28:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FTimespanStructCustomization::HandleTextBoxTextChanged( const FText& NewText )
|
|
|
|
|
{
|
|
|
|
|
FTimespan Timespan;
|
|
|
|
|
InputValid = FTimespan::Parse(NewText.ToString(), Timespan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FTimespanStructCustomization::HandleTextBoxTextCommited( const FText& NewText, ETextCommit::Type CommitInfo )
|
|
|
|
|
{
|
|
|
|
|
FTimespan ParsedTimespan;
|
2014-12-03 06:31:35 -05:00
|
|
|
|
|
|
|
|
InputValid = FTimespan::Parse(NewText.ToString(), ParsedTimespan);
|
|
|
|
|
if (InputValid && PropertyHandle.IsValid())
|
2014-09-02 19:28:15 -04:00
|
|
|
{
|
|
|
|
|
TArray<void*> RawData;
|
|
|
|
|
PropertyHandle->AccessRawData(RawData);
|
|
|
|
|
|
2014-12-03 06:31:35 -05:00
|
|
|
PropertyHandle->NotifyPreChange();
|
2014-09-02 19:28:15 -04:00
|
|
|
for (auto RawDataInstance : RawData)
|
|
|
|
|
{
|
|
|
|
|
*(FTimespan*)RawDataInstance = ParsedTimespan;
|
|
|
|
|
}
|
2014-12-03 06:31:35 -05:00
|
|
|
PropertyHandle->NotifyPostChange();
|
2014-09-02 19:28:15 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#undef LOCTEXT_NAMESPACE
|