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 "EnvironmentQueryEditorPrivatePCH.h"
# include "ScopedTransaction.h"
2015-02-23 10:30:16 -05:00
# include "SGraphEditorActionMenuAI.h"
2014-05-29 17:06:50 -04:00
# include "EnvironmentQuery/EnvQueryTest.h"
# include "EnvironmentQuery/EnvQueryOption.h"
2015-03-12 12:28:20 -04:00
# include "EnvironmentQuery/Generators/EnvQueryGenerator_Composite.h"
2014-03-14 14:13:41 -04:00
2015-02-23 10:30:16 -05:00
# define LOCTEXT_NAMESPACE "EnvironmentQueryEditor"
2014-03-14 14:13:41 -04:00
2014-10-14 10:29:11 -04:00
UEnvironmentQueryGraphNode_Option : : UEnvironmentQueryGraphNode_Option ( const FObjectInitializer & ObjectInitializer )
: Super ( ObjectInitializer )
2014-03-14 14:13:41 -04:00
{
}
void UEnvironmentQueryGraphNode_Option : : AllocateDefaultPins ( )
{
UEdGraphPin * Inputs = CreatePin ( EGPD_Input , TEXT ( " Transition " ) , TEXT ( " " ) , NULL , false , false , TEXT ( " Out " ) ) ;
}
void UEnvironmentQueryGraphNode_Option : : PostPlacedNewNode ( )
{
2015-02-23 10:30:16 -05:00
UClass * NodeClass = ClassData . GetClass ( true ) ;
if ( NodeClass )
2014-03-14 14:13:41 -04:00
{
2015-02-23 10:30:16 -05:00
UEdGraph * MyGraph = GetGraph ( ) ;
UObject * GraphOwner = MyGraph ? MyGraph - > GetOuter ( ) : nullptr ;
if ( GraphOwner )
{
UEnvQueryOption * QueryOption = NewObject < UEnvQueryOption > ( GraphOwner ) ;
QueryOption - > Generator = NewObject < UEnvQueryGenerator > ( GraphOwner , NodeClass ) ;
QueryOption - > Generator - > UpdateNodeVersion ( ) ;
2014-03-14 14:13:41 -04:00
2015-02-23 10:30:16 -05:00
QueryOption - > SetFlags ( RF_Transactional ) ;
QueryOption - > Generator - > SetFlags ( RF_Transactional ) ;
NodeInstance = QueryOption ;
InitializeInstance ( ) ;
}
2014-03-14 14:13:41 -04:00
}
}
2014-04-23 19:29:53 -04:00
void UEnvironmentQueryGraphNode_Option : : ResetNodeOwner ( )
{
Super : : ResetNodeOwner ( ) ;
UEnvQueryOption * OptionInstance = Cast < UEnvQueryOption > ( NodeInstance ) ;
if ( OptionInstance & & OptionInstance - > Generator )
{
2015-02-23 10:30:16 -05:00
UObject * GraphOwner = GetGraph ( ) ? GetGraph ( ) - > GetOuter ( ) : nullptr ;
OptionInstance - > Generator - > Rename ( NULL , GraphOwner , REN_DontCreateRedirectors | REN_DoNotDirty ) ;
2014-04-23 19:29:53 -04:00
}
}
void UEnvironmentQueryGraphNode_Option : : PrepareForCopying ( )
{
Super : : PrepareForCopying ( ) ;
UEnvQueryOption * OptionInstance = Cast < UEnvQueryOption > ( NodeInstance ) ;
if ( OptionInstance & & OptionInstance - > Generator )
{
// Temporarily take ownership of the node instance, so that it is not deleted when cutting
OptionInstance - > Generator - > Rename ( NULL , this , REN_DontCreateRedirectors | REN_DoNotDirty ) ;
}
}
2014-04-23 18:30:37 -04:00
FText UEnvironmentQueryGraphNode_Option : : GetNodeTitle ( ENodeTitleType : : Type TitleType ) const
2014-03-14 14:13:41 -04:00
{
UEnvQueryOption * OptionInstance = Cast < UEnvQueryOption > ( NodeInstance ) ;
2014-04-23 18:30:37 -04:00
return OptionInstance ? OptionInstance - > GetDescriptionTitle ( ) : FText : : GetEmpty ( ) ;
2014-03-14 14:13:41 -04:00
}
2014-04-23 18:30:37 -04:00
FText UEnvironmentQueryGraphNode_Option : : GetDescription ( ) const
2014-03-14 14:13:41 -04:00
{
UEnvQueryOption * OptionInstance = Cast < UEnvQueryOption > ( NodeInstance ) ;
2014-04-23 18:30:37 -04:00
return OptionInstance ? OptionInstance - > GetDescriptionDetails ( ) : FText : : GetEmpty ( ) ;
2014-03-14 14:13:41 -04:00
}
void UEnvironmentQueryGraphNode_Option : : GetContextMenuActions ( const FGraphNodeContextMenuBuilder & Context ) const
{
Context . MenuBuilder - > AddSubMenu (
LOCTEXT ( " AddTest " , " Add Test... " ) ,
LOCTEXT ( " AddTestTooltip " , " Adds new test to generator " ) ,
FNewMenuDelegate : : CreateUObject ( this , & UEnvironmentQueryGraphNode_Option : : CreateAddTestSubMenu , ( UEdGraph * ) Context . Graph )
) ;
}
void UEnvironmentQueryGraphNode_Option : : CreateAddTestSubMenu ( class FMenuBuilder & MenuBuilder , UEdGraph * Graph ) const
{
2015-02-23 10:30:16 -05:00
TSharedRef < SGraphEditorActionMenuAI > Menu =
SNew ( SGraphEditorActionMenuAI )
2014-03-14 14:13:41 -04:00
. GraphObj ( Graph )
. GraphNode ( ( UEnvironmentQueryGraphNode_Option * ) this )
. AutoExpandActionMenu ( true ) ;
MenuBuilder . AddWidget ( Menu , FText ( ) , true ) ;
}
void UEnvironmentQueryGraphNode_Option : : CalculateWeights ( )
{
float MaxWeight = - 1.0f ;
2015-02-23 10:30:16 -05:00
for ( int32 Idx = 0 ; Idx < SubNodes . Num ( ) ; Idx + + )
2014-03-14 14:13:41 -04:00
{
2015-02-23 10:30:16 -05:00
UEnvironmentQueryGraphNode_Test * TestNode = Cast < UEnvironmentQueryGraphNode_Test > ( SubNodes [ Idx ] ) ;
if ( TestNode = = nullptr | | ! TestNode - > bTestEnabled )
2014-03-14 14:13:41 -04:00
{
continue ;
}
2015-02-23 10:30:16 -05:00
UEnvQueryTest * TestInstance = Cast < UEnvQueryTest > ( TestNode - > NodeInstance ) ;
2015-03-09 07:19:19 -04:00
if ( TestInstance & & ! TestInstance - > ScoringFactor . IsDynamic ( ) )
2014-03-14 14:13:41 -04:00
{
2015-03-09 07:19:19 -04:00
MaxWeight = FMath : : Max ( MaxWeight , FMath : : Abs ( TestInstance - > ScoringFactor . DefaultValue ) ) ;
2014-03-14 14:13:41 -04:00
}
}
if ( MaxWeight < = 0.0f )
{
MaxWeight = 1.0f ;
}
2015-02-23 10:30:16 -05:00
for ( int32 Idx = 0 ; Idx < SubNodes . Num ( ) ; Idx + + )
2014-03-14 14:13:41 -04:00
{
2015-02-23 10:30:16 -05:00
UEnvironmentQueryGraphNode_Test * TestNode = Cast < UEnvironmentQueryGraphNode_Test > ( SubNodes [ Idx ] ) ;
if ( TestNode = = NULL )
2014-03-14 14:13:41 -04:00
{
continue ;
}
2015-02-23 10:30:16 -05:00
UEnvQueryTest * TestInstance = Cast < UEnvQueryTest > ( TestNode - > NodeInstance ) ;
2015-03-09 07:19:19 -04:00
const bool bHasDynamic = TestInstance & & TestNode - > bTestEnabled & & TestInstance - > ScoringFactor . IsDynamic ( ) ;
2015-02-23 10:30:16 -05:00
const float NewWeight = ( TestInstance & & TestNode - > bTestEnabled ) ?
2015-03-09 07:19:19 -04:00
( TestInstance - > ScoringFactor . IsDynamic ( ) ? 1.0f : FMath : : Clamp ( FMath : : Abs ( TestInstance - > ScoringFactor . DefaultValue ) / MaxWeight , 0.0f , 1.0f ) ) :
2014-03-14 14:13:41 -04:00
- 1.0f ;
2015-03-09 07:19:19 -04:00
TestNode - > SetDisplayedWeight ( NewWeight , bHasDynamic ) ;
2014-03-14 14:13:41 -04:00
}
}
2015-03-12 12:26:19 -04:00
void UEnvironmentQueryGraphNode_Option : : UpdateNodeData ( )
{
UEnvQueryOption * OptionInstance = Cast < UEnvQueryOption > ( NodeInstance ) ;
UEnvQueryGenerator_Composite * CompositeGenerator = OptionInstance ? Cast < UEnvQueryGenerator_Composite > ( OptionInstance - > Generator ) : nullptr ;
if ( CompositeGenerator )
{
CompositeGenerator - > VerifyItemTypes ( ) ;
ErrorMessage = CompositeGenerator - > bHasMatchingItemType ? TEXT ( " " ) : LOCTEXT ( " NestedGeneratorMismatch " , " Nested generators must work on exactly the same item types! " ) . ToString ( ) ;
}
}
2014-03-14 14:13:41 -04:00
# undef LOCTEXT_NAMESPACE