StateTree: Added support for description and icon for BP nodes.

#rb Thomas.Sarkanen, Yoan.StAmant

[CL 33098383 by mikko mononen in ue5-main branch]
This commit is contained in:
mikko mononen
2024-04-19 05:44:13 -04:00
parent 6284e919f6
commit 19bc060246
12 changed files with 433 additions and 42 deletions

View File

@@ -47,10 +47,33 @@ bool FStateTreeBlueprintConditionWrapper::TestCondition(FStateTreeExecutionConte
#if WITH_EDITOR
FText FStateTreeBlueprintConditionWrapper::GetDescription(const FGuid& ID, FStateTreeDataView InstanceDataView, const IStateTreeBindingLookup& BindingLookup, EStateTreeNodeFormatting Formatting) const
{
if (ConditionClass)
FText Description;
if (const UStateTreeConditionBlueprintBase* Instance = InstanceDataView.GetPtr<UStateTreeConditionBlueprintBase>())
{
return ConditionClass->GetDisplayNameText();
Description = Instance->GetDescription(ID, InstanceDataView, BindingLookup, Formatting);
}
return FText::GetEmpty();
if (Description.IsEmpty() && ConditionClass)
{
Description = ConditionClass->GetDisplayNameText();
}
return Description;
}
FName FStateTreeBlueprintConditionWrapper::GetIconName() const
{
if (const UStateTreeNodeBlueprintBase* NodeCDO = GetDefault<const UStateTreeNodeBlueprintBase>(ConditionClass))
{
return NodeCDO->GetIconName();
}
return FStateTreeConditionBase::GetIconName();
}
FColor FStateTreeBlueprintConditionWrapper::GetIconColor() const
{
if (const UStateTreeNodeBlueprintBase* NodeCDO = GetDefault<const UStateTreeNodeBlueprintBase>(ConditionClass))
{
return NodeCDO->GetIconColor();
}
return FStateTreeConditionBase::GetIconColor();
}
#endif

View File

@@ -77,10 +77,33 @@ void FStateTreeBlueprintEvaluatorWrapper::Tick(FStateTreeExecutionContext& Conte
#if WITH_EDITOR
FText FStateTreeBlueprintEvaluatorWrapper::GetDescription(const FGuid& ID, FStateTreeDataView InstanceDataView, const IStateTreeBindingLookup& BindingLookup, EStateTreeNodeFormatting Formatting) const
{
if (EvaluatorClass)
FText Description;
if (const UStateTreeEvaluatorBlueprintBase* Instance = InstanceDataView.GetPtr<UStateTreeEvaluatorBlueprintBase>())
{
return EvaluatorClass->GetDisplayNameText();
Description = Instance->GetDescription(ID, InstanceDataView, BindingLookup, Formatting);
}
return FText::GetEmpty();
if (Description.IsEmpty() && EvaluatorClass)
{
Description = EvaluatorClass->GetDisplayNameText();
}
return Description;
}
FName FStateTreeBlueprintEvaluatorWrapper::GetIconName() const
{
if (const UStateTreeNodeBlueprintBase* NodeCDO = GetDefault<const UStateTreeNodeBlueprintBase>(EvaluatorClass))
{
return NodeCDO->GetIconName();
}
return FStateTreeEvaluatorBase::GetIconName();
}
FColor FStateTreeBlueprintEvaluatorWrapper::GetIconColor() const
{
if (const UStateTreeNodeBlueprintBase* NodeCDO = GetDefault<const UStateTreeNodeBlueprintBase>(EvaluatorClass))
{
return NodeCDO->GetIconColor();
}
return FStateTreeEvaluatorBase::GetIconColor();
}
#endif

View File

@@ -9,6 +9,13 @@
#include UE_INLINE_GENERATED_CPP_BY_NAME(StateTreeNodeBlueprintBase)
#define LOCTEXT_NAMESPACE "StateTree"
#if WITH_EDITOR
FGuid UStateTreeNodeBlueprintBase::CachedNodeID;
const IStateTreeBindingLookup* UStateTreeNodeBlueprintBase::CachedBindingLookup = nullptr;
#endif
UWorld* UStateTreeNodeBlueprintBase::GetWorld() const
{
// The items are duplicated as the State Tree execution context as outer, so this should be essentially the same as GetWorld() on StateTree context.
@@ -149,3 +156,58 @@ DEFINE_FUNCTION(UStateTreeNodeBlueprintBase::execGetPropertyReference)
Stack.MostRecentProperty = nullptr;
}
}
#if WITH_EDITOR
FText UStateTreeNodeBlueprintBase::GetDescription(const FGuid& ID, FStateTreeDataView InstanceDataView, const IStateTreeBindingLookup& BindingLookup, EStateTreeNodeFormatting Formatting) const
{
FText Result;
const FGuid OldCachedNodeID = CachedNodeID;
const IStateTreeBindingLookup* OldCachedBindingLookup = CachedBindingLookup;
CachedNodeID = ID;
CachedBindingLookup = &BindingLookup;
Result = Description;
if (Result.IsEmpty())
{
Result = ReceiveGetDescription(Formatting);
}
if (Result.IsEmpty())
{
Result = GetClass()->GetDisplayNameText();
}
CachedNodeID = OldCachedNodeID;
CachedBindingLookup = OldCachedBindingLookup;
return Result;
}
#endif
FText UStateTreeNodeBlueprintBase::GetPropertyDescriptionByPropertyName(FName PropertyName) const
{
FText Result;
#if WITH_EDITOR
// Try property binding first
if (CachedBindingLookup)
{
const FStateTreePropertyPath Path(CachedNodeID, PropertyName);
Result = CachedBindingLookup->GetBindingSourceDisplayName(Path);
}
// No binding, get the value.
if (Result.IsEmpty())
{
if (const FProperty* Property = GetClass()->FindPropertyByName(PropertyName))
{
FString Value;
Property->ExportText_InContainer(0, Value, this, this, nullptr, PPF_PropertyWindow | PPF_BlueprintDebugView);
Result = FText::FromString(Value);
}
}
#endif
return Result;
}
#undef LOCTEXT_NAMESPACE

View File

@@ -149,10 +149,33 @@ EStateTreeRunStatus FStateTreeBlueprintTaskWrapper::Tick(FStateTreeExecutionCont
#if WITH_EDITOR
FText FStateTreeBlueprintTaskWrapper::GetDescription(const FGuid& ID, FStateTreeDataView InstanceDataView, const IStateTreeBindingLookup& BindingLookup, EStateTreeNodeFormatting Formatting) const
{
if (TaskClass)
FText Description;
if (const UStateTreeTaskBlueprintBase* Instance = InstanceDataView.GetPtr<UStateTreeTaskBlueprintBase>())
{
return TaskClass->GetDisplayNameText();
Description = Instance->GetDescription(ID, InstanceDataView, BindingLookup, Formatting);
}
return FText::GetEmpty();
if (Description.IsEmpty() && TaskClass)
{
Description = TaskClass->GetDisplayNameText();
}
return Description;
}
FName FStateTreeBlueprintTaskWrapper::GetIconName() const
{
if (const UStateTreeNodeBlueprintBase* NodeCDO = GetDefault<const UStateTreeNodeBlueprintBase>(TaskClass))
{
return NodeCDO->GetIconName();
}
return FStateTreeTaskBase::GetIconName();
}
FColor FStateTreeBlueprintTaskWrapper::GetIconColor() const
{
if (const UStateTreeNodeBlueprintBase* NodeCDO = GetDefault<const UStateTreeNodeBlueprintBase>(TaskClass))
{
return NodeCDO->GetIconColor();
}
return FStateTreeTaskBase::GetIconColor();
}
#endif