85 lines
2.9 KiB
C++
85 lines
2.9 KiB
C++
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|||
|
|
|
|||
|
|
#include "DialogueGraphSchema.h"
|
|||
|
|
#include "Node/DialogueGraphNode_Base.h"
|
|||
|
|
#include "Node/DialogueGraphNode_NPC.h"
|
|||
|
|
#include "Node/DialogueGraphNode_Player.h"
|
|||
|
|
#include "Node/DialogueGraphNode_Root.h"
|
|||
|
|
|
|||
|
|
#define LOCTEXT_NAMESPACE "DialogueGraphSchema"
|
|||
|
|
|
|||
|
|
UEdGraphNode* FDialogueGraphSchemaAction_NewNode::PerformAction(UEdGraph* ParentGraph, UEdGraphPin* FromPin, const FVector2D Location, bool bSelectNewNode)
|
|||
|
|
{
|
|||
|
|
UDialogueGraphNode_Base* NewNode = NewObject<UDialogueGraphNode_Base>(ParentGraph, ClassTemplate);
|
|||
|
|
NewNode->CreateNewGuid();
|
|||
|
|
NewNode->SetPostion(Location);
|
|||
|
|
NewNode->InitializeNodeData();
|
|||
|
|
NewNode->AllocateDefaultPins();
|
|||
|
|
|
|||
|
|
ParentGraph->Modify();
|
|||
|
|
ParentGraph->AddNode(NewNode, true, bSelectNewNode);
|
|||
|
|
|
|||
|
|
// 如果从某个Pin拖拽创建,自动连接
|
|||
|
|
if (FromPin && NewNode->Pins.Num() > 0)
|
|||
|
|
{
|
|||
|
|
for (UEdGraphPin* Pin : NewNode->Pins)
|
|||
|
|
{
|
|||
|
|
if (Pin->Direction != FromPin->Direction)
|
|||
|
|
{
|
|||
|
|
GetDefault<UDialogueGraphSchema>()->TryCreateConnection(FromPin, Pin);
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return NewNode;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void UDialogueGraphSchema::CreateDefaultNodesForGraph(UEdGraph& Graph) const
|
|||
|
|
{
|
|||
|
|
FGraphNodeCreator<UDialogueGraphNode_Root> NodeCreator(Graph);
|
|||
|
|
UDialogueGraphNode_Root* MyNode = NodeCreator.CreateNode(true, UDialogueGraphNode_Root::StaticClass());
|
|||
|
|
NodeCreator.Finalize();
|
|||
|
|
SetNodeMetaData(MyNode, FNodeMetadata::DefaultGraphNode);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void UDialogueGraphSchema::GetGraphContextActions(FGraphContextMenuBuilder& ContextMenuBuilder) const
|
|||
|
|
{
|
|||
|
|
// 添加npc对话节点
|
|||
|
|
TSharedPtr<FDialogueGraphSchemaAction_NewNode> NPCNodeAction = MakeShareable(new FDialogueGraphSchemaAction_NewNode(
|
|||
|
|
UDialogueGraphNode_NPC::StaticClass(),
|
|||
|
|
LOCTEXT("DialogueNode_NPC_Category", "NPC Dialogue"),
|
|||
|
|
LOCTEXT("DialogueNode_NPC_Desc", "NPC Dialogue Node"),
|
|||
|
|
LOCTEXT("DialogueNode_NPC_Tooltip", "Create a npc dialogue node")
|
|||
|
|
));
|
|||
|
|
ContextMenuBuilder.AddAction(NPCNodeAction);
|
|||
|
|
// 添加npc对话节点
|
|||
|
|
TSharedPtr<FDialogueGraphSchemaAction_NewNode> PlayerNodeAction = MakeShareable(new FDialogueGraphSchemaAction_NewNode(
|
|||
|
|
UDialogueGraphNode_Player::StaticClass(),
|
|||
|
|
LOCTEXT("DialogueNode_Player_Category", "Player Dialogue"),
|
|||
|
|
LOCTEXT("DialogueNode_Player_Desc", "Player Dialogue Node"),
|
|||
|
|
LOCTEXT("DialogueNode_Player_Tooltip", "Create a Player dialogue node")
|
|||
|
|
));
|
|||
|
|
ContextMenuBuilder.AddAction(PlayerNodeAction);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const FPinConnectionResponse UDialogueGraphSchema::CanCreateConnection(const UEdGraphPin* A, const UEdGraphPin* B) const
|
|||
|
|
{
|
|||
|
|
// 不能连接自己
|
|||
|
|
if (A->GetOwningNode() == B->GetOwningNode())
|
|||
|
|
{
|
|||
|
|
return FPinConnectionResponse(CONNECT_RESPONSE_DISALLOW, LOCTEXT("ConnectionSameNode", "Cannot connect to self"));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 必须一个输入一个输出
|
|||
|
|
if (A->Direction == B->Direction)
|
|||
|
|
{
|
|||
|
|
return FPinConnectionResponse(CONNECT_RESPONSE_DISALLOW, LOCTEXT("ConnectionSameDirection", "Must connect input to output"));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return FPinConnectionResponse(CONNECT_RESPONSE_MAKE, TEXT(""));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#undef LOCTEXT_NAMESPACE
|