Skip to content

Commit

Permalink
Created UFlowGraphEditorSettings, SFlowGraphNode_SubGraph
Browse files Browse the repository at this point in the history
followed by cosmetic tweaks of recent pull requests
  • Loading branch information
MothDoctor committed Nov 1, 2021
1 parent 91ee21d commit 524d0ab
Show file tree
Hide file tree
Showing 13 changed files with 220 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "Asset/FlowAssetEditor.h"
#include "Graph/FlowGraph.h"
#include "Graph/FlowGraphEditorSettings.h"
#include "Graph/FlowGraphSchema.h"
#include "Graph/FlowGraphSettings.h"
#include "Graph/FlowGraphUtils.h"
Expand All @@ -24,8 +25,6 @@ FConnectionDrawingPolicy* FFlowGraphConnectionDrawingPolicyFactory::CreateConnec
/////////////////////////////////////////////////////
// FFlowGraphConnectionDrawingPolicy

class UGraphEditorSettings;

FFlowGraphConnectionDrawingPolicy::FFlowGraphConnectionDrawingPolicy(int32 InBackLayerID, int32 InFrontLayerID, float ZoomFactor, const FSlateRect& InClippingRect, FSlateWindowElementList& InDrawElements, UEdGraph* InGraphObj)
: FConnectionDrawingPolicy(InBackLayerID, InFrontLayerID, ZoomFactor, InClippingRect, InDrawElements)
, GraphObj(InGraphObj)
Expand Down Expand Up @@ -77,7 +76,7 @@ void FFlowGraphConnectionDrawingPolicy::BuildPaths()
}
}

if (GraphObj && (UFlowGraphSettings::Get()->bHighlightInputWiresOfSelectedNodes || UFlowGraphSettings::Get()->bHighlightOutputWiresOfSelectedNodes))
if (GraphObj && (UFlowGraphEditorSettings::Get()->bHighlightInputWiresOfSelectedNodes || UFlowGraphEditorSettings::Get()->bHighlightOutputWiresOfSelectedNodes))
{
const TSharedPtr<FFlowAssetEditor> FlowAssetEditor = FFlowGraphUtils::GetFlowAssetEditor(GraphObj);
if (FlowAssetEditor.IsValid())
Expand All @@ -86,8 +85,8 @@ void FFlowGraphConnectionDrawingPolicy::BuildPaths()
{
for (UEdGraphPin* Pin : SelectedNode->Pins)
{
if ((Pin->Direction == EGPD_Input && UFlowGraphSettings::Get()->bHighlightInputWiresOfSelectedNodes)
|| (Pin->Direction == EGPD_Output && UFlowGraphSettings::Get()->bHighlightOutputWiresOfSelectedNodes))
if ((Pin->Direction == EGPD_Input && UFlowGraphEditorSettings::Get()->bHighlightInputWiresOfSelectedNodes)
|| (Pin->Direction == EGPD_Output && UFlowGraphEditorSettings::Get()->bHighlightOutputWiresOfSelectedNodes))
{
for (UEdGraphPin* LinkedPin : Pin->LinkedTo)
{
Expand All @@ -100,24 +99,18 @@ void FFlowGraphConnectionDrawingPolicy::BuildPaths()
}
}

void FFlowGraphConnectionDrawingPolicy::DrawConnection(int32 LayerId, const FVector2D& Start, const FVector2D& End,
const FConnectionParams& Params)
void FFlowGraphConnectionDrawingPolicy::DrawConnection(int32 LayerId, const FVector2D& Start, const FVector2D& End, const FConnectionParams& Params)
{
if (UFlowGraphSettings::Get()->ConnectionDrawType == EFlowConnectionDrawType::Default)
switch (UFlowGraphSettings::Get()->ConnectionDrawType)
{
FConnectionDrawingPolicy::DrawConnection(LayerId, Start, End, Params);
return;
case EFlowConnectionDrawType::Default:
FConnectionDrawingPolicy::DrawConnection(LayerId, Start, End, Params);
break;
case EFlowConnectionDrawType::Circuit:
DrawCircuitSpline(LayerId, Start, End, Params);
break;
default: ;
}

Internal_DrawCircuitSpline(LayerId, Start, End, Params);
}

void FFlowGraphConnectionDrawingPolicy::Draw(TMap<TSharedRef<SWidget>, FArrangedWidget>& InPinGeometries, FArrangedChildren& ArrangedNodes)
{
BuildPaths();

// Draw everything
FConnectionDrawingPolicy::Draw(InPinGeometries, ArrangedNodes);
}

// Give specific editor modes a chance to highlight this connection or darken non-interesting connections
Expand Down Expand Up @@ -175,28 +168,32 @@ void FFlowGraphConnectionDrawingPolicy::DetermineWiringStyle(UEdGraphPin* Output
}
}

void FFlowGraphConnectionDrawingPolicy::Internal_DrawCircuitSpline(const int32& LayerId, const FVector2D& Start, const FVector2D& End, const FConnectionParams& Params) const
void FFlowGraphConnectionDrawingPolicy::Draw(TMap<TSharedRef<SWidget>, FArrangedWidget>& InPinGeometries, FArrangedChildren& ArrangedNodes)
{
const FVector2D StartingPoint = FVector2D(Start.X + UFlowGraphSettings::Get()->ConnectionSpacing.X, Start.Y);
const FVector2D EndPoint = FVector2D(End.X - UFlowGraphSettings::Get()->ConnectionSpacing.Y, End.Y);
const FVector2D ControlPoint = Internal_GetControlPoint(StartingPoint, EndPoint);

BuildPaths();

FConnectionDrawingPolicy::Draw(InPinGeometries, ArrangedNodes);
}

void FFlowGraphConnectionDrawingPolicy::DrawCircuitSpline(const int32& LayerId, const FVector2D& Start, const FVector2D& End, const FConnectionParams& Params) const
{
const FVector2D StartingPoint = FVector2D(Start.X + UFlowGraphSettings::Get()->CircuitConnectionSpacing.X, Start.Y);
const FVector2D EndPoint = FVector2D(End.X - UFlowGraphSettings::Get()->CircuitConnectionSpacing.Y, End.Y);
const FVector2D ControlPoint = GetControlPoint(StartingPoint, EndPoint);

const FVector2D StartDirection = (Params.StartDirection == EGPD_Output) ? FVector2D(1.0f, 0.0f) : FVector2D(-1.0f, 0.0f);
const FVector2D EndDirection = (Params.EndDirection == EGPD_Input) ? FVector2D(1.0f, 0.0f) : FVector2D(-1.0f, 0.0f);

Internal_DrawCircuitConnection(LayerId, Start, StartDirection, StartingPoint, EndDirection, Params);
Internal_DrawCircuitConnection(LayerId, StartingPoint, StartDirection, ControlPoint, EndDirection, Params);
Internal_DrawCircuitConnection(LayerId, ControlPoint, StartDirection, EndPoint, EndDirection, Params);
Internal_DrawCircuitConnection(LayerId, EndPoint, StartDirection, End, EndDirection, Params);
DrawCircuitConnection(LayerId, Start, StartDirection, StartingPoint, EndDirection, Params);
DrawCircuitConnection(LayerId, StartingPoint, StartDirection, ControlPoint, EndDirection, Params);
DrawCircuitConnection(LayerId, ControlPoint, StartDirection, EndPoint, EndDirection, Params);
DrawCircuitConnection(LayerId, EndPoint, StartDirection, End, EndDirection, Params);
}

void FFlowGraphConnectionDrawingPolicy::Internal_DrawCircuitConnection(const int32& LayerId,
const FVector2D& Start, const FVector2D& StartDirection, const FVector2D& End, const FVector2D& EndDirection,
const FConnectionParams& Params) const
void FFlowGraphConnectionDrawingPolicy::DrawCircuitConnection(const int32& LayerId, const FVector2D& Start, const FVector2D& StartDirection, const FVector2D& End, const FVector2D& EndDirection, const FConnectionParams& Params) const
{
FSlateDrawElement::MakeDrawSpaceSpline(DrawElementsList, LayerId, Start, StartDirection, End, EndDirection,
Params.WireThickness, ESlateDrawEffect::None, Params.WireColor);

FSlateDrawElement::MakeDrawSpaceSpline(DrawElementsList, LayerId, Start, StartDirection, End, EndDirection, Params.WireThickness, ESlateDrawEffect::None, Params.WireColor);

if (Params.bDrawBubbles)
{
// This table maps distance along curve to alpha
Expand All @@ -212,7 +209,7 @@ void FFlowGraphConnectionDrawingPolicy::Internal_DrawCircuitConnection(const int

const float Time = (FPlatformTime::Seconds() - GStartTime);
const float BubbleOffset = FMath::Fmod(Time * BubbleSpeed, BubbleSpacing);
const int32 NumBubbles = FMath::CeilToInt(SplineLength/BubbleSpacing);
const int32 NumBubbles = FMath::CeilToInt(SplineLength / BubbleSpacing);
for (int32 i = 0; i < NumBubbles; ++i)
{
const float Distance = (static_cast<float>(i) * BubbleSpacing) + BubbleOffset;
Expand All @@ -222,36 +219,29 @@ void FFlowGraphConnectionDrawingPolicy::Internal_DrawCircuitConnection(const int
FVector2D BubblePos = FMath::CubicInterp(Start, StartDirection, End, EndDirection, Alpha);
BubblePos -= (BubbleSize * 0.5f);

FSlateDrawElement::MakeBox(
DrawElementsList,
LayerId,
FPaintGeometry( BubblePos, BubbleSize, ZoomFactor ),
BubbleImage,
ESlateDrawEffect::None,
Params.WireColor
);
FSlateDrawElement::MakeBox(DrawElementsList, LayerId, FPaintGeometry(BubblePos, BubbleSize, ZoomFactor), BubbleImage, ESlateDrawEffect::None, Params.WireColor);
}
}
}
}
}

FVector2D FFlowGraphConnectionDrawingPolicy::Internal_GetControlPoint(const FVector2D& Source, const FVector2D& Target)
FVector2D FFlowGraphConnectionDrawingPolicy::GetControlPoint(const FVector2D& Source, const FVector2D& Target)
{
const FVector2D Delta = Target - Source;
const float Tangent = FMath::Tan(UFlowGraphSettings::Get()->ConnectionAngle * (PI / 180.f));
const float Tangent = FMath::Tan(UFlowGraphSettings::Get()->CircuitConnectionAngle * (PI / 180.f));

const float DX = FMath::Abs(Delta.X);
const float DY = FMath::Abs(Delta.Y);
const float DeltaX = FMath::Abs(Delta.X);
const float DeltaY = FMath::Abs(Delta.Y);

const float SlopeWidth = DY / Tangent;
if (DX > SlopeWidth)
const float SlopeWidth = DeltaY / Tangent;
if (DeltaX > SlopeWidth)
{
return Delta.X > 0.f ? FVector2D(Target.X - SlopeWidth, Source.Y) : FVector2D(Source.X - SlopeWidth, Target.Y);
}

const float SlopeHeight = DX * Tangent;
if (DY > SlopeHeight)
const float SlopeHeight = DeltaX * Tangent;
if (DeltaY > SlopeHeight)
{
if (Delta.Y > 0.f)
{
Expand Down
14 changes: 14 additions & 0 deletions Source/FlowEditor/Private/Graph/FlowGraphEditorSettings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "Graph/FlowGraphEditorSettings.h"

#include "FlowAsset.h"

UFlowGraphEditorSettings::UFlowGraphEditorSettings(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
, bShowNodeClass(false)
, bShowSubGraphPreview(true)
, bShowSubGraphPath(true)
, SubGraphPreviewSize(FVector2D(640.f, 360.f))
, bHighlightInputWiresOfSelectedNodes(true)
, bHighlightOutputWiresOfSelectedNodes(false)
{
}
12 changes: 3 additions & 9 deletions Source/FlowEditor/Private/Graph/FlowGraphSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@

UFlowGraphSettings::UFlowGraphSettings(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
, ConnectionDrawType(EFlowConnectionDrawType::Default)
, ConnectionAngle(45.f)
, ConnectionSpacing(FVector2D(30.f))
, bShowAssetPathInNode(false)
, bShowGraphPreview(true)
, bShowGraphPathInPreview(true)
, GraphPreviewSize(FVector2D(640.f, 360.f))
, bExposeFlowAssetCreation(true)
, bExposeFlowNodeCreation(true)
, bShowAssetToolbarAboveLevelEditor(true)
Expand All @@ -20,15 +13,16 @@ UFlowGraphSettings::UFlowGraphSettings(const FObjectInitializer& ObjectInitializ
, NodeDescriptionBackground(FLinearColor(0.0625f, 0.0625f, 0.0625f, 1.0f))
, NodeStatusBackground(FLinearColor(0.12f, 0.12f, 0.12f, 1.0f))
, NodePreloadedBackground(FLinearColor(0.12f, 0.12f, 0.12f, 1.0f))
, ConnectionDrawType(EFlowConnectionDrawType::Default)
, CircuitConnectionAngle(45.f)
, CircuitConnectionSpacing(FVector2D(30.f))
, InactiveWireColor(FLinearColor(0.364f, 0.364f, 0.364f, 1.0f))
, InactiveWireThickness(1.5f)
, RecentWireDuration(3.0f)
, RecentWireColor(FLinearColor(1.0f, 0.05f, 0.0f, 1.0f))
, RecentWireThickness(6.0f)
, RecordedWireColor(FLinearColor(0.432f, 0.258f, 0.096f, 1.0f))
, RecordedWireThickness(3.5f)
, bHighlightInputWiresOfSelectedNodes(true)
, bHighlightOutputWiresOfSelectedNodes(false)
, SelectedWireColor(FLinearColor(0.984f, 0.482f, 0.010f, 1.0f))
, SelectedWireThickness(1.5f)
{
Expand Down
3 changes: 2 additions & 1 deletion Source/FlowEditor/Private/Graph/Nodes/FlowGraphNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Asset/FlowDebugger.h"
#include "FlowEditorCommands.h"
#include "Graph/FlowGraph.h"
#include "Graph/FlowGraphEditorSettings.h"
#include "Graph/FlowGraphSchema.h"
#include "Graph/FlowGraphSettings.h"
#include "Graph/Widgets/SFlowGraphNode.h"
Expand Down Expand Up @@ -561,7 +562,7 @@ FText UFlowGraphNode::GetNodeTitle(ENodeTitleType::Type TitleType) const
{
if (FlowNode)
{
if (UFlowGraphSettings::Get()->bShowAssetPathInNode)
if (UFlowGraphEditorSettings::Get()->bShowNodeClass)
{
FString CleanAssetName;
if (FlowNode->GetClass()->ClassGeneratedBy)
Expand Down
15 changes: 15 additions & 0 deletions Source/FlowEditor/Private/Graph/Nodes/FlowGraphNode_SubGraph.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "Graph/Nodes/FlowGraphNode_SubGraph.h"
#include "Graph/Widgets/SFlowGraphNode_SubGraph.h"

#include "Nodes/Route/FlowNode_SubGraph.h"

UFlowGraphNode_SubGraph::UFlowGraphNode_SubGraph(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
AssignedNodeClasses = {UFlowNode_SubGraph::StaticClass()};
}

TSharedPtr<SGraphNode> UFlowGraphNode_SubGraph::CreateVisualWidget()
{
return SNew(SFlowGraphNode_SubGraph, this);
}
52 changes: 5 additions & 47 deletions Source/FlowEditor/Private/Graph/Widgets/SFlowGraphNode.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "Graph/Widgets/SFlowGraphNode.h"
#include "FlowEditorStyle.h"
#include "Graph/FlowGraphEditorSettings.h"
#include "Graph/FlowGraphSettings.h"

#include "FlowAsset.h"
#include "Nodes/FlowNode.h"

#include "EdGraph/EdGraphPin.h"
Expand All @@ -14,19 +16,15 @@
#include "SCommentBubble.h"
#include "SGraphNode.h"
#include "SGraphPin.h"
#include "SlateOptMacros.h"
#include "SLevelOfDetailBranchNode.h"
#include "SNodePanel.h"
#include "SlateOptMacros.h"
#include "Styling/SlateColor.h"
#include "TutorialMetaData.h"
#include "FlowAsset.h"
#include "SGraphPreviewer.h"
#include "Nodes/Route/FlowNode_SubGraph.h"
#include "Widgets/Images/SImage.h"
#include "Widgets/Layout/SBorder.h"
#include "Widgets/SBoxPanel.h"
#include "Widgets/SOverlay.h"
#include "Widgets/SToolTip.h"

#define LOCTEXT_NAMESPACE "SFlowGraphNode"

Expand Down Expand Up @@ -256,7 +254,7 @@ void SFlowGraphNode::UpdateGraphNode()

this->ContentScale.Bind(this, &SGraphNode::GetContentScale);

TSharedPtr<SVerticalBox> InnerVerticalBox = SNew(SVerticalBox)
const TSharedPtr<SVerticalBox> InnerVerticalBox = SNew(SVerticalBox)
+ SVerticalBox::Slot()
.AutoHeight()
.HAlign(HAlign_Fill)
Expand Down Expand Up @@ -383,7 +381,7 @@ const FSlateBrush* SFlowGraphNode::GetNodeBodyBrush() const

void SFlowGraphNode::CreateStandardPinWidget(UEdGraphPin* Pin)
{
TSharedPtr<SGraphPin> NewPin = SNew(SFlowGraphPinExec, Pin);
const TSharedPtr<SGraphPin> NewPin = SNew(SFlowGraphPinExec, Pin);

if (!UFlowGraphSettings::Get()->bShowDefaultPinNames && FlowGraphNode->GetFlowNode())
{
Expand Down Expand Up @@ -468,46 +466,6 @@ FReply SFlowGraphNode::OnAddPin()

TSharedPtr<SToolTip> SFlowGraphNode::GetComplexTooltip()
{
if (UFlowGraphSettings::Get()->bShowGraphPreview)
{
if (UFlowNode_SubGraph* MySubGraphNode = Cast<UFlowNode_SubGraph>(FlowGraphNode->GetFlowNode()))
{
const UFlowAsset* AssetToEdit = Cast<UFlowAsset>(MySubGraphNode->GetAssetToEdit());
if (AssetToEdit && AssetToEdit->GetGraph())
{
TSharedPtr<SWidget> TitleBarWidget = SNullWidget::NullWidget;
if (UFlowGraphSettings::Get()->bShowGraphPathInPreview)
{
const FString AssetName = FString::Printf(TEXT(".%s"), *AssetToEdit->GetName());
const FString AssetPath = AssetToEdit->GetPathName().Replace(*AssetName, TEXT(""));
TitleBarWidget = SNew(SBox)
.Padding(10.f)
[
SNew(STextBlock)
.Text(FText::FromString(AssetPath))
];
}

return SNew(SToolTip)
[
SNew(SBox)
.WidthOverride(UFlowGraphSettings::Get()->GraphPreviewSize.X)
.HeightOverride(UFlowGraphSettings::Get()->GraphPreviewSize.Y)
[
SNew(SOverlay)
+SOverlay::Slot()
[
SNew(SGraphPreviewer, AssetToEdit->GetGraph())
.CornerOverlayText(LOCTEXT("FlowNodePreviewGraphOverlayText", "FLOW PREVIEW"))
.ShowGraphStateOverlay(false)
.TitleBar(TitleBarWidget)
]
]
];
}
}
}

return IDocumentation::Get()->CreateToolTip(TAttribute<FText>(this, &SGraphNode::GetNodeTooltip), nullptr, GraphNode->GetDocumentationLink(), GraphNode->GetDocumentationExcerptName());
}

Expand Down
Loading

0 comments on commit 524d0ab

Please sign in to comment.