From 74ea72c76caf96b10072f8ccbd52176d24ca768c Mon Sep 17 00:00:00 2001 From: PHILIP WHITE Date: Mon, 20 Nov 2023 21:28:08 +0000 Subject: [PATCH] Add Custom Dialogue Graph for Dialogue Trees --- EndlessVendetta/EndlessVendetta.uproject | 5 ++ .../Source/EndlessVendetta.Target.cs | 6 +++ .../DialogueSystem/DialogueAddItemNode.cpp | 39 +++++++++++++++ .../DialogueSystem/DialogueAddItemNode.h | 24 ++++++++++ .../DialogueSystem/DialogueEdge.h | 16 +++++++ .../DialogueSystem/DialogueTextNode.cpp | 47 +++++++++++++++++++ .../DialogueSystem/DialogueTextNode.h | 34 ++++++++++++++ .../DialogueSystem/DialogueTree.cpp | 18 +++++++ .../DialogueSystem/DialogueTree.h | 20 ++++++++ .../EndlessVendetta/EndlessVendetta.Build.cs | 2 + .../Source/EndlessVendettaEditor.Target.cs | 6 +++ 11 files changed, 217 insertions(+) create mode 100644 EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueAddItemNode.cpp create mode 100644 EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueAddItemNode.h create mode 100644 EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueEdge.h create mode 100644 EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTextNode.cpp create mode 100644 EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTextNode.h create mode 100644 EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTree.cpp create mode 100644 EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTree.h diff --git a/EndlessVendetta/EndlessVendetta.uproject b/EndlessVendetta/EndlessVendetta.uproject index 340e263e..52239fa2 100644 --- a/EndlessVendetta/EndlessVendetta.uproject +++ b/EndlessVendetta/EndlessVendetta.uproject @@ -14,6 +14,11 @@ "CoreUObject", "UMG" ] + }, + { + "Name": "DialogueSystemEditor", + "Type": "Editor", + "LoadingPhase": "PostEngineInit" } ], "Plugins": [ diff --git a/EndlessVendetta/Source/EndlessVendetta.Target.cs b/EndlessVendetta/Source/EndlessVendetta.Target.cs index b31c5112..0bfa1565 100644 --- a/EndlessVendetta/Source/EndlessVendetta.Target.cs +++ b/EndlessVendetta/Source/EndlessVendetta.Target.cs @@ -11,5 +11,11 @@ public class EndlessVendettaTarget : TargetRules DefaultBuildSettings = BuildSettingsVersion.V2; IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_1; ExtraModuleNames.Add("EndlessVendetta"); + RegisterModulesCreatedByRider(); + } + + private void RegisterModulesCreatedByRider() + { + ExtraModuleNames.AddRange(new string[] { "DialogueSystemEditor" }); } } diff --git a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueAddItemNode.cpp b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueAddItemNode.cpp new file mode 100644 index 00000000..8adadbb7 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueAddItemNode.cpp @@ -0,0 +1,39 @@ +#include "DialogueAddItemNode.h" +#include "DialogueTree.h" + +#define LOCTEXT_NAMESPACE "UDialogueTextNode" + +UDialogueAddItemNode::UDialogueAddItemNode() +{ +#if WITH_EDITORONLY_DATA + CompatibleGraphType = UDialogueTree::StaticClass(); + + ContextMenuName = LOCTEXT("ConextMenuName", "Add Item Node"); +#endif +} + +#if WITH_EDITOR + +FText UDialogueAddItemNode::GetNodeTitle() const +{ + return Bruh; +} + +void UDialogueAddItemNode::SetNodeTitle(const FText& NewTitle) +{ + Bruh = NewTitle; +} + +FLinearColor UDialogueAddItemNode::GetBackgroundColor() const +{ + const UDialogueTree* DialogueTree = Cast(GetGraph()); + + if (DialogueTree == nullptr) + return Super::GetBackgroundColor(); + + return FLinearColor::Black; +} + +#endif + +#undef LOCTEXT_NAMESPACE diff --git a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueAddItemNode.h b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueAddItemNode.h new file mode 100644 index 00000000..b52856e6 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueAddItemNode.h @@ -0,0 +1,24 @@ +#pragma once + +#include "CoreMinimal.h" +#include "GenericGraphNode.h" +#include "DialogueAddItemNode.generated.h" + +UCLASS(Blueprintable) +class UDialogueAddItemNode : public UGenericGraphNode +{ + GENERATED_BODY() +public: + UDialogueAddItemNode(); + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Dialogue") + FText Bruh; + +#if WITH_EDITOR + virtual FText GetNodeTitle() const override; + + virtual void SetNodeTitle(const FText& NewTitle) override; + + virtual FLinearColor GetBackgroundColor() const override; +#endif +}; \ No newline at end of file diff --git a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueEdge.h b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueEdge.h new file mode 100644 index 00000000..72d6491b --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueEdge.h @@ -0,0 +1,16 @@ +#pragma once + +#include "CoreMinimal.h" +#include "GenericGraphEdge.h" +#include "DialogueEdge.generated.h" + + +UCLASS(Blueprintable) +class UDialogueEdge: public UGenericGraphEdge +{ + GENERATED_BODY() + +public: + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Dialogue") + FText Selection; +}; \ No newline at end of file diff --git a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTextNode.cpp b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTextNode.cpp new file mode 100644 index 00000000..8b61bba0 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTextNode.cpp @@ -0,0 +1,47 @@ +#include "DialogueTextNode.h" +#include "DialogueTree.h" + +#define LOCTEXT_NAMESPACE "UDialogueTextNode" + +UDialogueTextNode::UDialogueTextNode() +{ +#if WITH_EDITORONLY_DATA + CompatibleGraphType = UDialogueTree::StaticClass(); + + ContextMenuName = LOCTEXT("ConextMenuName", "Dialogue Node"); +#endif +} + +#if WITH_EDITOR + +FText UDialogueTextNode::GetNodeTitle() const +{ + return Text.IsEmpty() ? LOCTEXT("EmptyParagraph", "(Empty paragraph)") : Text; +} + +void UDialogueTextNode::SetNodeTitle(const FText& NewTitle) +{ + Text = NewTitle; +} + +FLinearColor UDialogueTextNode::GetBackgroundColor() const +{ + const UDialogueTree* DialogueTree = Cast(GetGraph()); + + if (DialogueTree == nullptr) + return Super::GetBackgroundColor(); + + switch (DialoguePosition) + { + case EDialoguePosition::Left: + return DialogueTree->LeftDialogueBgColor; + case EDialoguePosition::Right: + return DialogueTree->RightDialogueBgColor; + default: + return FLinearColor::Black; + } +} + +#endif + +#undef LOCTEXT_NAMESPACE \ No newline at end of file diff --git a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTextNode.h b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTextNode.h new file mode 100644 index 00000000..6ff78b28 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTextNode.h @@ -0,0 +1,34 @@ +#pragma once + +#include "CoreMinimal.h" +#include "GenericGraphNode.h" +#include "DialogueTextNode.generated.h" + +UENUM(BlueprintType) +enum class EDialoguePosition : uint8 +{ + Left, + Right +}; + +UCLASS(Blueprintable) +class UDialogueTextNode : public UGenericGraphNode +{ + GENERATED_BODY() +public: + UDialogueTextNode(); + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Dialogue") + FText Text; + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Dialogue") + EDialoguePosition DialoguePosition; + +#if WITH_EDITOR + virtual FText GetNodeTitle() const override; + + virtual void SetNodeTitle(const FText& NewTitle) override; + + virtual FLinearColor GetBackgroundColor() const override; +#endif +}; \ No newline at end of file diff --git a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTree.cpp b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTree.cpp new file mode 100644 index 00000000..903afba3 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTree.cpp @@ -0,0 +1,18 @@ +#include "DialogueTree.h" +#include "DialogueTextNode.h" +#include "DialogueEdge.h" + +#define LOCTEXT_NAMESPACE "DialogueSession" + +UDialogueTree::UDialogueTree() +{ + NodeType = UGenericGraphNode::StaticClass(); + EdgeType = UDialogueEdge::StaticClass(); + + LeftDialogueBgColor = FLinearColor::Black; + RightDialogueBgColor = FLinearColor(0.93f, 0.93f, 0.93f, 1.f); + + Name = "Dialogue Tree"; +} + +#undef LOCTEXT_NAMESPACE \ No newline at end of file diff --git a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTree.h b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTree.h new file mode 100644 index 00000000..8150ba61 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueTree.h @@ -0,0 +1,20 @@ +#pragma once + +#include "CoreMinimal.h" +#include "GenericGraph.h" +#include "DialogueTree.generated.h" + +UCLASS(Blueprintable) +class ENDLESSVENDETTA_API UDialogueTree: public UGenericGraph +{ + GENERATED_BODY() + +public: + UDialogueTree(); + + UPROPERTY(EditDefaultsOnly, Category = "Dialogue") + FLinearColor LeftDialogueBgColor; + + UPROPERTY(EditDefaultsOnly, Category = "Dialogue") + FLinearColor RightDialogueBgColor; +}; \ No newline at end of file diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendetta.Build.cs b/EndlessVendetta/Source/EndlessVendetta/EndlessVendetta.Build.cs index 3149aa96..8edf6d38 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendetta.Build.cs +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendetta.Build.cs @@ -13,5 +13,7 @@ public class EndlessVendetta : ModuleRules "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay", "EnhancedInput", "AIModule", "GameplayTasks", "NavigationSystem", "UMG", "Slate", "SlateCore", "Niagara", "NiagaraCore", "NiagaraShader" }); + + PrivateDependencyModuleNames.AddRange(new string[] { "GenericGraphRuntime" }); } } \ No newline at end of file diff --git a/EndlessVendetta/Source/EndlessVendettaEditor.Target.cs b/EndlessVendetta/Source/EndlessVendettaEditor.Target.cs index 2dc48be0..f57382d6 100644 --- a/EndlessVendetta/Source/EndlessVendettaEditor.Target.cs +++ b/EndlessVendetta/Source/EndlessVendettaEditor.Target.cs @@ -11,5 +11,11 @@ public class EndlessVendettaEditorTarget : TargetRules DefaultBuildSettings = BuildSettingsVersion.V2; IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_1; ExtraModuleNames.Add("EndlessVendetta"); + RegisterModulesCreatedByRider(); + } + + private void RegisterModulesCreatedByRider() + { + ExtraModuleNames.AddRange(new string[] { "DialogueSystemEditor" }); } }