Files
UnrealEngineUWP/Engine/Source/Editor/DetailCustomizations/Private/EnvQueryParamInstanceCustomization.cpp

210 lines
6.8 KiB
C++
Raw Normal View History

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
#include "EnvQueryParamInstanceCustomization.h"
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
#include "Widgets/DeclarativeSyntaxSupport.h"
#include "Engine/GameViewportClient.h"
#include "Widgets/SBoxPanel.h"
#include "Styling/SlateTypes.h"
#include "Widgets/Text/STextBlock.h"
#include "Widgets/Input/SCheckBox.h"
#include "IDetailChildrenBuilder.h"
#include "DetailWidgetRow.h"
#include "DetailLayoutBuilder.h"
#include "EnvironmentQuery/EnvQueryTypes.h"
#include "Widgets/Input/SNumericEntryBox.h"
#define LOCTEXT_NAMESPACE "FEnvQueryCustomization"
TSharedRef<IPropertyTypeCustomization> FEnvQueryParamInstanceCustomization::MakeInstance( )
{
return MakeShareable(new FEnvQueryParamInstanceCustomization);
}
void FEnvQueryParamInstanceCustomization::CustomizeHeader( TSharedRef<class IPropertyHandle> StructPropertyHandle, class FDetailWidgetRow& HeaderRow, IPropertyTypeCustomizationUtils& StructCustomizationUtils )
{
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())
];
}
void FEnvQueryParamInstanceCustomization::CustomizeChildren( TSharedRef<class IPropertyHandle> StructPropertyHandle, class IDetailChildrenBuilder& StructBuilder, IPropertyTypeCustomizationUtils& StructCustomizationUtils )
{
StructBuilder.AddChildProperty(NameProp.ToSharedRef());
StructBuilder.AddChildProperty(TypeProp.ToSharedRef());
StructBuilder.AddChildContent(LOCTEXT("ValueLabel", "Value"))
.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 == EAIParamType::Float)
{
float FloatValue = 0.0f;
FPropertyAccess::Result PropResult = ValueProp->GetValue(FloatValue);
if (PropResult == FPropertyAccess::Success)
{
return FloatValue;
}
}
else if (ParamType == EAIParamType::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 == EAIParamType::Float)
{
ValueProp->SetValue(FloatValue);
CachedFloat = FloatValue;
}
else if (ParamType == EAIParamType::Int)
{
const int32 IntValue = FMath::TruncToInt(FloatValue);
const float StoreValue = *((float*)&IntValue);
ValueProp->SetValue(StoreValue);
CachedInt = IntValue;
}
}
ECheckBoxState FEnvQueryParamInstanceCustomization::GetParamBoolValue() const
{
if (ParamType == EAIParamType::Bool)
{
float StoreValue = 0.0f;
FPropertyAccess::Result PropResult = ValueProp->GetValue(StoreValue);
if (PropResult == FPropertyAccess::Success)
{
return (StoreValue > 0.0f) ? ECheckBoxState::Checked : ECheckBoxState::Unchecked;
}
}
return ECheckBoxState::Undetermined;
}
void FEnvQueryParamInstanceCustomization::OnParamBoolValueChanged(ECheckBoxState BoolValue) const
{
if (ParamType == EAIParamType::Bool)
{
const float StoreValue = (BoolValue == ECheckBoxState::Checked) ? 1.0f : -1.0f;
ValueProp->SetValue(StoreValue);
CachedBool = (BoolValue == ECheckBoxState::Checked);
}
}
EVisibility FEnvQueryParamInstanceCustomization::GetParamNumValueVisibility() const
{
return (ParamType == EAIParamType::Int || ParamType == EAIParamType::Float) ? EVisibility::Visible : EVisibility::Collapsed;
}
EVisibility FEnvQueryParamInstanceCustomization::GetParamBoolValueVisibility() const
{
return (ParamType == EAIParamType::Bool) ? EVisibility::Visible : EVisibility::Collapsed;
}
FText FEnvQueryParamInstanceCustomization::GetHeaderDesc() const
{
FString ParamName;
if (NameProp->GetValue(ParamName) == FPropertyAccess::Success)
{
switch (ParamType)
{
case EAIParamType::Float: return FText::FromString(FString::Printf(TEXT("%s = %s"), *ParamName, *FString::SanitizeFloat(CachedFloat)));
case EAIParamType::Int: return FText::FromString(FString::Printf(TEXT("%s = %d"), *ParamName, CachedInt));
case EAIParamType::Bool: return FText::FromString(FString::Printf(TEXT("%s = %s"), *ParamName, CachedBool ? TEXT("true") : TEXT("false")));
}
}
return FText::GetEmpty();
}
void FEnvQueryParamInstanceCustomization::InitCachedTypes()
{
CachedBool = false;
CachedFloat = 0.0f;
CachedInt = 0;
uint8 EnumValue = 0;
FPropertyAccess::Result PropResult = TypeProp->GetValue(EnumValue);
if (PropResult == FPropertyAccess::Success)
{
ParamType = (EAIParamType)EnumValue;
switch (ParamType)
{
case EAIParamType::Float: CachedFloat = GetParamNumValue().GetValue(); break;
case EAIParamType::Int: CachedInt = FMath::TruncToInt(GetParamNumValue().GetValue()); break;
case EAIParamType::Bool: CachedBool = (GetParamBoolValue() == ECheckBoxState::Checked); break;
}
}
}
void FEnvQueryParamInstanceCustomization::OnTypeChanged()
{
uint8 EnumValue = 0;
FPropertyAccess::Result PropResult = TypeProp->GetValue(EnumValue);
if (PropResult == FPropertyAccess::Success)
{
ParamType = (EAIParamType)EnumValue;
switch (ParamType)
{
case EAIParamType::Float: OnParamNumValueChanged(CachedFloat); break;
case EAIParamType::Int: OnParamNumValueChanged(CachedInt); break;
case EAIParamType::Bool: OnParamBoolValueChanged(CachedBool ? ECheckBoxState::Checked : ECheckBoxState::Unchecked); break;
}
}
}
#undef LOCTEXT_NAMESPACE