Files
UnrealEngineUWP/Engine/Source/Editor/GraphEditor/Private/StateMachineConnectionDrawingPolicy.cpp
Marc Audy b8d61c189f Copying //UE4/Dev-Framework to Dev-Main (//UE4/Dev-Main) @ 2944217
#lockdown Nick.Penwarden

==========================
MAJOR FEATURES + CHANGES
==========================

Change 2899855 on 2016/03/08 by Marc.Audy

	Merging //UE4/Dev-Main to Dev-Framework (//UE4/Dev-Framework) @ 2899785

Change 2926689 on 2016/03/29 by Jeff.Farris

	AAIController::SetFocus() will now implicitly clear any location focus at the same priority.

	UE-27975

	#rb john.abercrombie

Change 2926690 on 2016/03/29 by Jeff.Farris

	Using wildcard operator with the "KismetEvent" or "ke" console commands will now only trigger the event on objects in the world in which it was triggered. Prevents badness with running events on things like CDOs and editor actors. (UE-23106)

Change 2926691 on 2016/03/29 by mason.seay

	Content for testing collision on scaled components

Change 2926692 on 2016/03/29 by Jeff.Farris

	- FixupDeltaSeconds now considers time dilation when clamping.
	- Acceptable range for time dilation values is now a config parameter on WorldSettings
	- Acceptable range for undilated frame times is now a config parameter on WorldSettings

	(UE-27815)

	#rb marc.audy

Change 2926711 on 2016/03/29 by Ori.Cohen

	Fix constraint rendering when scaling a cosntraint actor

	#JIRA UE-28691, UE-28700
	#rb Lina.Halper

Change 2926745 on 2016/03/29 by Lukasz.Furman

	navigation filters can now be instantiated per querier - usually AI agent
	required for FORT-21372

Change 2926789 on 2016/03/29 by Ori.Cohen

	Downgrade check to ensure for 2d physics during a hard shutdown

	#rb Michael.Noland

Change 2926859 on 2016/03/29 by Ori.Cohen

	Fix red herring warnings of not locking physx scenes during hard shutdown.

	#JIRA UE-28747
	#rb Michael.Noland

Change 2927444 on 2016/03/30 by Thomas.Sarkanen

	Fixed Blueprint compiler errors when resetting timer handles

	Added basic support for 64-bit int/uint terms to Blueprint. This allows the use of opaque 64-bit integer types inside of BlueprintType structs, it in no way means that 64-bit ints are fully supported in Blueprint.
	Corrected a left-over formatting oversight when converting a FTimerHandle to a string.
	Added new by-ref "Clear and Invalidate Timer by Handle" function to Blueprint system library & deprecated old version.

	#rb Maciej.Mroz (and a few others!)
	#jira UE-28833 - Unresolved compiler error for B_Pickups blueprint in Fortnite

Change 2927520 on 2016/03/30 by Jurre.deBaare

	Should not allow skeletal mesh components mobility to be set to static, but detach instead

	#fix Added CanHaveStaticMobility to SceneComponent class, and check this when trying to propogate Static mobility to parent component
	#jira UE-26364

Change 2927533 on 2016/03/30 by Jurre.deBaare

	Static Mesh Merge tool: when merging from multiple blueprints, fails to combine same materials
	#fix Material index remapping was part of if-clause where it shouldn't be
	#jira UE-23827

	Static Mesh Merge tool, failed to combine physics data if using complex
	#fix Required copying the SectionInfoMap from source static meshes

	HLOD/MergeActor - Vertex Colours are not correctly propagated to negatively scaled meshes
	#fix had to re-order function calls
	#jira UE-28316

	#rb James.Golding

Change 2927535 on 2016/03/30 by Ori.Cohen

	Make sub-stepping run on game thread

	#JIRA UE-24011
	#rb Gil.Gribb

Change 2927537 on 2016/03/30 by Jurre.deBaare

	Warning message when HLOD mesh > 65536 vertices

	#jira UE-22365
	#fix added messages when building proxy mesh

Change 2927691 on 2016/03/30 by Jeff.Farris

	Fixed potential PlayerState leak (UE-22700)

Change 2927692 on 2016/03/30 by Lina.Halper

	Allow it to select any name they want other than just restrict to what we have.

	- I think it may not be the best solution but with current widget built, you can't even clear name, which is problem.

	- Other solution is to add "Clear" as a name, and when that gets entered, we just clear it, but then the X button is odd and no purpose being there.

	- I think we should just allow them to choose if they don't like it but with suggestions.

	#rb: Ori.Cohen
	#jira UE-27786
	#code review: Benn.Gallagher

Change 2927853 on 2016/03/30 by Lina.Halper

[CL 2944273 by Marc Audy in Main branch]
2016-04-14 16:25:11 -04:00

180 lines
6.6 KiB
C++

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "GraphEditorCommon.h"
#include "StateMachineConnectionDrawingPolicy.h"
#include "AnimationStateNodes/SGraphNodeAnimTransition.h"
#include "AnimStateTransitionNode.h"
#include "AnimStateEntryNode.h"
/////////////////////////////////////////////////////
// FStateMachineConnectionDrawingPolicy
FStateMachineConnectionDrawingPolicy::FStateMachineConnectionDrawingPolicy(int32 InBackLayerID, int32 InFrontLayerID, float ZoomFactor, const FSlateRect& InClippingRect, FSlateWindowElementList& InDrawElements, UEdGraph* InGraphObj)
: FConnectionDrawingPolicy(InBackLayerID, InFrontLayerID, ZoomFactor, InClippingRect, InDrawElements)
, GraphObj(InGraphObj)
{
}
void FStateMachineConnectionDrawingPolicy::DetermineWiringStyle(UEdGraphPin* OutputPin, UEdGraphPin* InputPin, /*inout*/ FConnectionParams& Params)
{
Params.AssociatedPin1 = OutputPin;
Params.AssociatedPin2 = InputPin;
Params.WireThickness = 1.5f;
if (InputPin)
{
if (UAnimStateTransitionNode* TransNode = Cast<UAnimStateTransitionNode>(InputPin->GetOwningNode()))
{
Params.WireColor = SGraphNodeAnimTransition::StaticGetTransitionColor(TransNode, HoveredPins.Contains(InputPin));
Params.bUserFlag1 = TransNode->Bidirectional;
}
}
const bool bDeemphasizeUnhoveredPins = HoveredPins.Num() > 0;
if (bDeemphasizeUnhoveredPins)
{
ApplyHoverDeemphasis(OutputPin, InputPin, /*inout*/ Params.WireThickness, /*inout*/ Params.WireColor);
}
}
void FStateMachineConnectionDrawingPolicy::DetermineLinkGeometry(
FArrangedChildren& ArrangedNodes,
TSharedRef<SWidget>& OutputPinWidget,
UEdGraphPin* OutputPin,
UEdGraphPin* InputPin,
/*out*/ FArrangedWidget*& StartWidgetGeometry,
/*out*/ FArrangedWidget*& EndWidgetGeometry
)
{
if (UAnimStateEntryNode* EntryNode = Cast<UAnimStateEntryNode>(OutputPin->GetOwningNode()))
{
StartWidgetGeometry = PinGeometries->Find(OutputPinWidget);
UAnimStateNodeBase* State = CastChecked<UAnimStateNodeBase>(InputPin->GetOwningNode());
int32 StateIndex = NodeWidgetMap.FindChecked(State);
EndWidgetGeometry = &(ArrangedNodes[StateIndex]);
}
else if (UAnimStateTransitionNode* TransNode = Cast<UAnimStateTransitionNode>(InputPin->GetOwningNode()))
{
UAnimStateNodeBase* PrevState = TransNode->GetPreviousState();
UAnimStateNodeBase* NextState = TransNode->GetNextState();
if ((PrevState != NULL) && (NextState != NULL))
{
int32* PrevNodeIndex = NodeWidgetMap.Find(PrevState);
int32* NextNodeIndex = NodeWidgetMap.Find(NextState);
if ((PrevNodeIndex != NULL) && (NextNodeIndex != NULL))
{
StartWidgetGeometry = &(ArrangedNodes[*PrevNodeIndex]);
EndWidgetGeometry = &(ArrangedNodes[*NextNodeIndex]);
}
}
}
else
{
StartWidgetGeometry = PinGeometries->Find(OutputPinWidget);
if (TSharedRef<SGraphPin>* pTargetWidget = PinToPinWidgetMap.Find(InputPin))
{
TSharedRef<SGraphPin> InputWidget = *pTargetWidget;
EndWidgetGeometry = PinGeometries->Find(InputWidget);
}
}
}
void FStateMachineConnectionDrawingPolicy::Draw(TMap<TSharedRef<SWidget>, FArrangedWidget>& InPinGeometries, FArrangedChildren& ArrangedNodes)
{
// Build an acceleration structure to quickly find geometry for the nodes
NodeWidgetMap.Empty();
for (int32 NodeIndex = 0; NodeIndex < ArrangedNodes.Num(); ++NodeIndex)
{
FArrangedWidget& CurWidget = ArrangedNodes[NodeIndex];
TSharedRef<SGraphNode> ChildNode = StaticCastSharedRef<SGraphNode>(CurWidget.Widget);
NodeWidgetMap.Add(ChildNode->GetNodeObj(), NodeIndex);
}
// Now draw
FConnectionDrawingPolicy::Draw(InPinGeometries, ArrangedNodes);
}
void FStateMachineConnectionDrawingPolicy::DrawPreviewConnector(const FGeometry& PinGeometry, const FVector2D& StartPoint, const FVector2D& EndPoint, UEdGraphPin* Pin)
{
FConnectionParams Params;
DetermineWiringStyle(Pin, nullptr, /*inout*/ Params);
const FVector2D SeedPoint = EndPoint;
const FVector2D AdjustedStartPoint = FGeometryHelper::FindClosestPointOnGeom(PinGeometry, SeedPoint);
DrawSplineWithArrow(AdjustedStartPoint, EndPoint, Params);
}
void FStateMachineConnectionDrawingPolicy::DrawSplineWithArrow(const FVector2D& StartAnchorPoint, const FVector2D& EndAnchorPoint, const FConnectionParams& Params)
{
Internal_DrawLineWithArrow(StartAnchorPoint, EndAnchorPoint, Params);
// Is the connection bidirectional?
if (Params.bUserFlag1)
{
Internal_DrawLineWithArrow(EndAnchorPoint, StartAnchorPoint, Params);
}
}
void FStateMachineConnectionDrawingPolicy::Internal_DrawLineWithArrow(const FVector2D& StartAnchorPoint, const FVector2D& EndAnchorPoint, const FConnectionParams& Params)
{
//@TODO: Should this be scaled by zoom factor?
const float LineSeparationAmount = 4.5f;
const FVector2D DeltaPos = EndAnchorPoint - StartAnchorPoint;
const FVector2D UnitDelta = DeltaPos.GetSafeNormal();
const FVector2D Normal = FVector2D(DeltaPos.Y, -DeltaPos.X).GetSafeNormal();
// Come up with the final start/end points
const FVector2D DirectionBias = Normal * LineSeparationAmount;
const FVector2D LengthBias = ArrowRadius.X * UnitDelta;
const FVector2D StartPoint = StartAnchorPoint + DirectionBias + LengthBias;
const FVector2D EndPoint = EndAnchorPoint + DirectionBias - LengthBias;
// Draw a line/spline
DrawConnection(WireLayerID, StartPoint, EndPoint, Params);
// Draw the arrow
const FVector2D ArrowDrawPos = EndPoint - ArrowRadius;
const float AngleInRadians = FMath::Atan2(DeltaPos.Y, DeltaPos.X);
FSlateDrawElement::MakeRotatedBox(
DrawElementsList,
ArrowLayerID,
FPaintGeometry(ArrowDrawPos, ArrowImage->ImageSize * ZoomFactor, ZoomFactor),
ArrowImage,
ClippingRect,
ESlateDrawEffect::None,
AngleInRadians,
TOptional<FVector2D>(),
FSlateDrawElement::RelativeToElement,
Params.WireColor
);
}
void FStateMachineConnectionDrawingPolicy::DrawSplineWithArrow(const FGeometry& StartGeom, const FGeometry& EndGeom, const FConnectionParams& Params)
{
// Get a reasonable seed point (halfway between the boxes)
const FVector2D StartCenter = FGeometryHelper::CenterOf(StartGeom);
const FVector2D EndCenter = FGeometryHelper::CenterOf(EndGeom);
const FVector2D SeedPoint = (StartCenter + EndCenter) * 0.5f;
// Find the (approximate) closest points between the two boxes
const FVector2D StartAnchorPoint = FGeometryHelper::FindClosestPointOnGeom(StartGeom, SeedPoint);
const FVector2D EndAnchorPoint = FGeometryHelper::FindClosestPointOnGeom(EndGeom, SeedPoint);
DrawSplineWithArrow(StartAnchorPoint, EndAnchorPoint, Params);
}
FVector2D FStateMachineConnectionDrawingPolicy::ComputeSplineTangent(const FVector2D& Start, const FVector2D& End) const
{
const FVector2D Delta = End - Start;
const FVector2D NormDelta = Delta.GetSafeNormal();
return NormDelta;
}