2021-12-01 10:50:36 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2021-11-24 04:26:29 -05:00
|
|
|
|
|
|
|
|
#include "Blueprint/StateTreeConditionBlueprintBase.h"
|
2023-01-19 00:48:07 -05:00
|
|
|
#include "Blueprint/StateTreeNodeBlueprintBase.h"
|
2021-11-24 04:26:29 -05:00
|
|
|
#include "StateTreeExecutionContext.h"
|
2022-09-19 19:47:11 -04:00
|
|
|
#include "BlueprintNodeHelpers.h"
|
2021-11-24 04:26:29 -05:00
|
|
|
|
2022-09-28 01:06:15 -04:00
|
|
|
#include UE_INLINE_GENERATED_CPP_BY_NAME(StateTreeConditionBlueprintBase)
|
|
|
|
|
|
2021-11-24 04:26:29 -05:00
|
|
|
//----------------------------------------------------------------------//
|
|
|
|
|
// UStateTreeConditionBlueprintBase
|
|
|
|
|
//----------------------------------------------------------------------//
|
|
|
|
|
|
2022-09-19 19:47:11 -04:00
|
|
|
UStateTreeConditionBlueprintBase::UStateTreeConditionBlueprintBase(const FObjectInitializer& ObjectInitializer)
|
|
|
|
|
: Super(ObjectInitializer)
|
|
|
|
|
{
|
|
|
|
|
bHasTestCondition = BlueprintNodeHelpers::HasBlueprintFunction(TEXT("ReceiveTestCondition"), *this, *StaticClass());
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 04:04:58 -04:00
|
|
|
bool UStateTreeConditionBlueprintBase::TestCondition(FStateTreeExecutionContext& Context) const
|
2021-11-24 04:26:29 -05:00
|
|
|
{
|
2022-09-19 19:47:11 -04:00
|
|
|
if (bHasTestCondition)
|
|
|
|
|
{
|
2022-12-05 09:16:37 -05:00
|
|
|
// Cache the owner and event queue for the duration the condition is evaluated.
|
2023-01-23 12:48:04 -05:00
|
|
|
SetCachedInstanceDataFromContext(Context);
|
2022-12-05 09:16:37 -05:00
|
|
|
|
|
|
|
|
const bool bResult = ReceiveTestCondition();
|
|
|
|
|
|
2023-01-23 12:48:04 -05:00
|
|
|
ClearCachedInstanceData();
|
2022-12-05 09:16:37 -05:00
|
|
|
|
|
|
|
|
return bResult;
|
2022-09-19 19:47:11 -04:00
|
|
|
}
|
|
|
|
|
return false;
|
2021-11-24 04:26:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------//
|
|
|
|
|
// FStateTreeBlueprintConditionWrapper
|
|
|
|
|
//----------------------------------------------------------------------//
|
|
|
|
|
|
|
|
|
|
bool FStateTreeBlueprintConditionWrapper::TestCondition(FStateTreeExecutionContext& Context) const
|
|
|
|
|
{
|
2022-09-19 19:47:11 -04:00
|
|
|
UStateTreeConditionBlueprintBase* Condition = Context.GetInstanceDataPtr<UStateTreeConditionBlueprintBase>(*this);
|
|
|
|
|
check(Condition);
|
|
|
|
|
return Condition->TestCondition(Context);
|
2021-11-24 04:26:29 -05:00
|
|
|
}
|
2021-12-01 03:42:52 -05:00
|
|
|
|
2024-04-05 04:18:10 -04:00
|
|
|
#if WITH_EDITOR
|
|
|
|
|
FText FStateTreeBlueprintConditionWrapper::GetDescription(const FGuid& ID, FStateTreeDataView InstanceDataView, const IStateTreeBindingLookup& BindingLookup, EStateTreeNodeFormatting Formatting) const
|
|
|
|
|
{
|
2024-04-19 05:44:13 -04:00
|
|
|
FText Description;
|
|
|
|
|
if (const UStateTreeConditionBlueprintBase* Instance = InstanceDataView.GetPtr<UStateTreeConditionBlueprintBase>())
|
2024-04-05 04:18:10 -04:00
|
|
|
{
|
2024-04-19 05:44:13 -04:00
|
|
|
Description = Instance->GetDescription(ID, InstanceDataView, BindingLookup, Formatting);
|
2024-04-05 04:18:10 -04:00
|
|
|
}
|
2024-04-19 05:44:13 -04:00
|
|
|
if (Description.IsEmpty() && ConditionClass)
|
|
|
|
|
{
|
|
|
|
|
Description = ConditionClass->GetDisplayNameText();
|
|
|
|
|
}
|
|
|
|
|
return Description;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FName FStateTreeBlueprintConditionWrapper::GetIconName() const
|
|
|
|
|
{
|
2024-06-07 15:32:24 -04:00
|
|
|
if (ConditionClass)
|
2024-04-19 05:44:13 -04:00
|
|
|
{
|
2024-06-07 15:32:24 -04:00
|
|
|
if (const UStateTreeNodeBlueprintBase* NodeCDO = GetDefault<const UStateTreeNodeBlueprintBase>(ConditionClass))
|
|
|
|
|
{
|
|
|
|
|
return NodeCDO->GetIconName();
|
|
|
|
|
}
|
2024-04-19 05:44:13 -04:00
|
|
|
}
|
2024-06-07 15:32:24 -04:00
|
|
|
|
2024-04-19 05:44:13 -04:00
|
|
|
return FStateTreeConditionBase::GetIconName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FColor FStateTreeBlueprintConditionWrapper::GetIconColor() const
|
|
|
|
|
{
|
2024-06-07 15:32:24 -04:00
|
|
|
if (ConditionClass)
|
2024-04-19 05:44:13 -04:00
|
|
|
{
|
2024-06-07 15:32:24 -04:00
|
|
|
if (const UStateTreeNodeBlueprintBase* NodeCDO = GetDefault<const UStateTreeNodeBlueprintBase>(ConditionClass))
|
|
|
|
|
{
|
|
|
|
|
return NodeCDO->GetIconColor();
|
|
|
|
|
}
|
2024-04-19 05:44:13 -04:00
|
|
|
}
|
2024-06-07 15:32:24 -04:00
|
|
|
|
2024-04-19 05:44:13 -04:00
|
|
|
return FStateTreeConditionBase::GetIconColor();
|
2024-04-05 04:18:10 -04:00
|
|
|
}
|
|
|
|
|
#endif
|