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 "EnvQueryParamInstanceCustomization.h"
|
2014-10-14 22:50:06 -04:00
|
|
|
#include "SNumericEntryBox.h"
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
#define LOCTEXT_NAMESPACE "FEnvQueryCustomization"
|
|
|
|
|
|
2014-06-04 10:16:14 -04:00
|
|
|
TSharedRef<IPropertyTypeCustomization> FEnvQueryParamInstanceCustomization::MakeInstance( )
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
return MakeShareable(new FEnvQueryParamInstanceCustomization);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-04 11:16:24 -04:00
|
|
|
void FEnvQueryParamInstanceCustomization::CustomizeHeader( TSharedRef<class IPropertyHandle> StructPropertyHandle, class FDetailWidgetRow& HeaderRow, IPropertyTypeCustomizationUtils& StructCustomizationUtils )
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
NameProp = StructPropertyHandle->GetChildHandle(GET_MEMBER_NAME_CHECKED(FEnvNamedValue,ParamName));
|
|
|
|
|
TypeProp = StructPropertyHandle->GetChildHandle(GET_MEMBER_NAME_CHECKED(FEnvNamedValue,ParamType));
|
|
|
|
|
ValueProp = StructPropertyHandle->GetChildHandle(GET_MEMBER_NAME_CHECKED(FEnvNamedValue,Value));
|
|
|
|
|
|
|
|
|
|
FSimpleDelegate OnTypeChangedDelegate = FSimpleDelegate::CreateSP( this, &FEnvQueryParamInstanceCustomization::OnTypeChanged );
|
|
|
|
|
TypeProp->SetOnPropertyValueChanged(OnTypeChangedDelegate);
|
|
|
|
|
InitCachedTypes();
|
|
|
|
|
OnTypeChanged();
|
|
|
|
|
|
|
|
|
|
// create struct header
|
|
|
|
|
HeaderRow.NameContent()
|
|
|
|
|
[
|
|
|
|
|
StructPropertyHandle->CreatePropertyNameWidget()
|
|
|
|
|
]
|
|
|
|
|
.ValueContent()
|
|
|
|
|
[
|
|
|
|
|
SNew(STextBlock)
|
|
|
|
|
.Text(this, &FEnvQueryParamInstanceCustomization::GetHeaderDesc)
|
|
|
|
|
.Font(IDetailLayoutBuilder::GetDetailFont())
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-04 11:16:24 -04:00
|
|
|
void FEnvQueryParamInstanceCustomization::CustomizeChildren( TSharedRef<class IPropertyHandle> StructPropertyHandle, class IDetailChildrenBuilder& StructBuilder, IPropertyTypeCustomizationUtils& StructCustomizationUtils )
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
StructBuilder.AddChildProperty(NameProp.ToSharedRef());
|
|
|
|
|
StructBuilder.AddChildProperty(TypeProp.ToSharedRef());
|
|
|
|
|
|
2014-12-01 11:19:41 -05:00
|
|
|
StructBuilder.AddChildContent(LOCTEXT("ValueLabel", "Value"))
|
2014-03-14 14:13:41 -04:00
|
|
|
.NameContent()
|
|
|
|
|
[
|
|
|
|
|
ValueProp->CreatePropertyNameWidget()
|
|
|
|
|
]
|
|
|
|
|
.ValueContent()
|
|
|
|
|
[
|
|
|
|
|
SNew(SHorizontalBox)
|
|
|
|
|
+SHorizontalBox::Slot()
|
|
|
|
|
.Padding(0.0f, 2.0f, 5.0f, 2.0f)
|
|
|
|
|
[
|
|
|
|
|
SNew(SNumericEntryBox<float>)
|
|
|
|
|
.AllowSpin(false)
|
|
|
|
|
.Visibility(this, &FEnvQueryParamInstanceCustomization::GetParamNumValueVisibility)
|
|
|
|
|
.Value(this, &FEnvQueryParamInstanceCustomization::GetParamNumValue)
|
|
|
|
|
.OnValueChanged(this, &FEnvQueryParamInstanceCustomization::OnParamNumValueChanged)
|
|
|
|
|
]
|
|
|
|
|
+SHorizontalBox::Slot()
|
|
|
|
|
.Padding(0.0f, 2.0f, 5.0f, 2.0f)
|
|
|
|
|
[
|
|
|
|
|
SNew(SCheckBox)
|
|
|
|
|
.Visibility(this, &FEnvQueryParamInstanceCustomization::GetParamBoolValueVisibility)
|
|
|
|
|
.IsChecked(this, &FEnvQueryParamInstanceCustomization::GetParamBoolValue )
|
|
|
|
|
.OnCheckStateChanged(this, &FEnvQueryParamInstanceCustomization::OnParamBoolValueChanged )
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TOptional<float> FEnvQueryParamInstanceCustomization::GetParamNumValue() const
|
|
|
|
|
{
|
|
|
|
|
// Gets the actual aspect ratio property value
|
|
|
|
|
if (ParamType == EEnvQueryParam::Float)
|
|
|
|
|
{
|
|
|
|
|
float FloatValue = 0.0f;
|
|
|
|
|
FPropertyAccess::Result PropResult = ValueProp->GetValue(FloatValue);
|
|
|
|
|
if (PropResult == FPropertyAccess::Success)
|
|
|
|
|
{
|
|
|
|
|
return FloatValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ParamType == EEnvQueryParam::Int)
|
|
|
|
|
{
|
|
|
|
|
float StoreValue = 0.0f;
|
|
|
|
|
FPropertyAccess::Result PropResult = ValueProp->GetValue(StoreValue);
|
|
|
|
|
if (PropResult == FPropertyAccess::Success)
|
|
|
|
|
{
|
|
|
|
|
const int32 IntValue = *((int32*)&StoreValue);
|
|
|
|
|
return IntValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TOptional<float>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FEnvQueryParamInstanceCustomization::OnParamNumValueChanged(float FloatValue) const
|
|
|
|
|
{
|
|
|
|
|
if (ParamType == EEnvQueryParam::Float)
|
|
|
|
|
{
|
|
|
|
|
ValueProp->SetValue(FloatValue);
|
|
|
|
|
CachedFloat = FloatValue;
|
|
|
|
|
}
|
|
|
|
|
else if (ParamType == EEnvQueryParam::Int)
|
|
|
|
|
{
|
2014-05-06 06:26:25 -04:00
|
|
|
const int32 IntValue = FMath::TruncToInt(FloatValue);
|
2014-03-14 14:13:41 -04:00
|
|
|
const float StoreValue = *((float*)&IntValue);
|
|
|
|
|
ValueProp->SetValue(StoreValue);
|
|
|
|
|
CachedInt = IntValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-10 14:24:09 -05:00
|
|
|
ECheckBoxState FEnvQueryParamInstanceCustomization::GetParamBoolValue() const
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
if (ParamType == EEnvQueryParam::Bool)
|
|
|
|
|
{
|
|
|
|
|
float StoreValue = 0.0f;
|
|
|
|
|
FPropertyAccess::Result PropResult = ValueProp->GetValue(StoreValue);
|
|
|
|
|
if (PropResult == FPropertyAccess::Success)
|
|
|
|
|
{
|
2014-12-10 14:24:09 -05:00
|
|
|
return (StoreValue > 0.0f) ? ECheckBoxState::Checked : ECheckBoxState::Unchecked;
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-10 14:24:09 -05:00
|
|
|
return ECheckBoxState::Undetermined;
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-12-10 14:24:09 -05:00
|
|
|
void FEnvQueryParamInstanceCustomization::OnParamBoolValueChanged(ECheckBoxState BoolValue) const
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
if (ParamType == EEnvQueryParam::Bool)
|
|
|
|
|
{
|
2014-12-10 14:24:09 -05:00
|
|
|
const float StoreValue = (BoolValue == ECheckBoxState::Checked) ? 1.0f : -1.0f;
|
2014-03-14 14:13:41 -04:00
|
|
|
ValueProp->SetValue(StoreValue);
|
2014-12-10 14:24:09 -05:00
|
|
|
CachedBool = (BoolValue == ECheckBoxState::Checked);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EVisibility FEnvQueryParamInstanceCustomization::GetParamNumValueVisibility() const
|
|
|
|
|
{
|
|
|
|
|
return (ParamType == EEnvQueryParam::Int || ParamType == EEnvQueryParam::Float) ? EVisibility::Visible : EVisibility::Collapsed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EVisibility FEnvQueryParamInstanceCustomization::GetParamBoolValueVisibility() const
|
|
|
|
|
{
|
|
|
|
|
return (ParamType == EEnvQueryParam::Bool) ? EVisibility::Visible : EVisibility::Collapsed;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-07 09:52:40 -05:00
|
|
|
FText FEnvQueryParamInstanceCustomization::GetHeaderDesc() const
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
FString ParamName;
|
|
|
|
|
if (NameProp->GetValue(ParamName) == FPropertyAccess::Success)
|
|
|
|
|
{
|
|
|
|
|
switch (ParamType)
|
|
|
|
|
{
|
2015-01-07 09:52:40 -05:00
|
|
|
case EEnvQueryParam::Float: return FText::FromString(FString::Printf(TEXT("%s = %s"), *ParamName, *FString::SanitizeFloat(CachedFloat)));
|
|
|
|
|
case EEnvQueryParam::Int: return FText::FromString(FString::Printf(TEXT("%s = %d"), *ParamName, CachedInt));
|
|
|
|
|
case EEnvQueryParam::Bool: return FText::FromString(FString::Printf(TEXT("%s = %s"), *ParamName, CachedBool ? TEXT("true") : TEXT("false")));
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-07 09:52:40 -05:00
|
|
|
return FText::GetEmpty();
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FEnvQueryParamInstanceCustomization::InitCachedTypes()
|
|
|
|
|
{
|
|
|
|
|
CachedBool = false;
|
|
|
|
|
CachedFloat = 0.0f;
|
|
|
|
|
CachedInt = 0;
|
|
|
|
|
|
|
|
|
|
uint8 EnumValue = 0;
|
|
|
|
|
FPropertyAccess::Result PropResult = TypeProp->GetValue(EnumValue);
|
|
|
|
|
if (PropResult == FPropertyAccess::Success)
|
|
|
|
|
{
|
|
|
|
|
ParamType = (EEnvQueryParam::Type)EnumValue;
|
|
|
|
|
switch (ParamType)
|
|
|
|
|
{
|
|
|
|
|
case EEnvQueryParam::Float: CachedFloat = GetParamNumValue().GetValue(); break;
|
2014-05-06 06:26:25 -04:00
|
|
|
case EEnvQueryParam::Int: CachedInt = FMath::TruncToInt(GetParamNumValue().GetValue()); break;
|
2014-12-10 14:24:09 -05:00
|
|
|
case EEnvQueryParam::Bool: CachedBool = (GetParamBoolValue() == ECheckBoxState::Checked); break;
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FEnvQueryParamInstanceCustomization::OnTypeChanged()
|
|
|
|
|
{
|
|
|
|
|
uint8 EnumValue = 0;
|
|
|
|
|
FPropertyAccess::Result PropResult = TypeProp->GetValue(EnumValue);
|
|
|
|
|
if (PropResult == FPropertyAccess::Success)
|
|
|
|
|
{
|
|
|
|
|
ParamType = (EEnvQueryParam::Type)EnumValue;
|
|
|
|
|
switch (ParamType)
|
|
|
|
|
{
|
|
|
|
|
case EEnvQueryParam::Float: OnParamNumValueChanged(CachedFloat); break;
|
|
|
|
|
case EEnvQueryParam::Int: OnParamNumValueChanged(CachedInt); break;
|
2014-12-10 14:24:09 -05:00
|
|
|
case EEnvQueryParam::Bool: OnParamBoolValueChanged(CachedBool ? ECheckBoxState::Checked : ECheckBoxState::Unchecked); break;
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#undef LOCTEXT_NAMESPACE
|