diff --git a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/AC_Dialogue.h b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/AC_Dialogue.h new file mode 100644 index 00000000..5d8635c0 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/AC_Dialogue.h @@ -0,0 +1,19 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "DialogueTree.h" +#include "Components/ActorComponent.h" +#include "AC_Dialogue.generated.h" + + +UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) +class ENDLESSVENDETTA_API UAC_Dialogue : public UActorComponent +{ + GENERATED_BODY() + +public: + UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category = "Dialogue") + UDialogueTree* DialogueTree; +}; diff --git a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/AC_PlayerDialogueInterpreter.cpp b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/AC_PlayerDialogueInterpreter.cpp new file mode 100644 index 00000000..72be7b3a --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/AC_PlayerDialogueInterpreter.cpp @@ -0,0 +1,75 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "AC_PlayerDialogueInterpreter.h" + + +// Sets default values for this component's properties +UAC_PlayerDialogueInterpreter::UAC_PlayerDialogueInterpreter() +{ + // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features + // off to improve performance if you don't need them. + PrimaryComponentTick.bCanEverTick = false; + + // ... +} + + +// Called when the game starts +void UAC_PlayerDialogueInterpreter::BeginPlay() +{ + Super::BeginPlay(); + + // ... +} + + +// Called every frame +void UAC_PlayerDialogueInterpreter::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +{ + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + + // ... +} + +void UAC_PlayerDialogueInterpreter::StartDialogue(UDialogueTree* DialogueTree) +{ + CurrentDialogueTree = DialogueTree; + CurrentTextNode = Cast(DialogueTree->RootNodes[0]->ChildrenNodes[0]); + OnStartDialogue.Broadcast(CurrentTextNode); +} + +void UAC_PlayerDialogueInterpreter::NextDialogue() +{ + if (IsValid(CurrentTextNode)) + { + if (Cast(CurrentTextNode->ChildrenNodes[0])) + { + CurrentTextNode = nullptr; + CurrentChoiceNode = Cast(CurrentTextNode->ChildrenNodes[0]); + OnChoiceDialogue.Broadcast(CurrentChoiceNode); + } + else + { + CurrentChoiceNode = nullptr; + CurrentTextNode = Cast(CurrentTextNode->ChildrenNodes[0]); + OnNextDialogue.Broadcast(CurrentTextNode); + } + } +} + +void UAC_PlayerDialogueInterpreter::MakeChoiceDialogue(const int Choice) +{ + if (Cast(CurrentTextNode->ChildrenNodes[Choice])) + { + CurrentTextNode = nullptr; + CurrentChoiceNode = Cast(CurrentTextNode->ChildrenNodes[Choice]); + OnChoiceDialogue.Broadcast(CurrentChoiceNode); + } + else + { + CurrentChoiceNode = nullptr; + CurrentTextNode = Cast(CurrentTextNode->ChildrenNodes[Choice]); + OnNextDialogue.Broadcast(CurrentTextNode); + } +} diff --git a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/AC_PlayerDialogueInterpreter.h b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/AC_PlayerDialogueInterpreter.h new file mode 100644 index 00000000..3f449ced --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/AC_PlayerDialogueInterpreter.h @@ -0,0 +1,57 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "DialogueChoiceNode.h" +#include "DialogueTextNode.h" +#include "Components/ActorComponent.h" +#include "AC_PlayerDialogueInterpreter.generated.h" + + +UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) +class ENDLESSVENDETTA_API UAC_PlayerDialogueInterpreter : public UActorComponent +{ + GENERATED_BODY() + +public: + // Sets default values for this component's properties + UAC_PlayerDialogueInterpreter(); + + DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnStartDialogue, UDialogueTextNode*, StartingNode); + + DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnNextDialogue, UDialogueTextNode*, NextNode); + + DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnChoiceDialogue, UDialogueChoiceNode*, ChoiceNode); + + UPROPERTY(BlueprintAssignable, Category = "Dialogue") + FOnStartDialogue OnStartDialogue; + UPROPERTY(BlueprintAssignable, Category = "Dialogue") + FOnNextDialogue OnNextDialogue; + UPROPERTY(BlueprintAssignable, Category = "Dialogue") + FOnChoiceDialogue OnChoiceDialogue; + + UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category = "Dialogue") + UDialogueTree* CurrentDialogueTree; + +protected: + // Called when the game starts + virtual void BeginPlay() override; + +private: + UPROPERTY() + UDialogueTextNode* CurrentTextNode; + UPROPERTY() + UDialogueChoiceNode* CurrentChoiceNode; + +public: + // Called every frame + virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; + + UFUNCTION(BlueprintCallable, Category = "Dialogue") + void StartDialogue(UDialogueTree* DialogueTree); + UFUNCTION(BlueprintCallable, Category = "Dialogue") + void NextDialogue(); + UFUNCTION(BlueprintCallable, Category = "Dialogue") + void MakeChoiceDialogue(int Choice); +}; diff --git a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueChoiceNode.cpp b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueChoiceNode.cpp new file mode 100644 index 00000000..2758d6af --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueChoiceNode.cpp @@ -0,0 +1,29 @@ +#include "DialogueChoiceNode.h" +#include "DialogueTree.h" + +#define LOCTEXT_NAMESPACE "UDialogueChoiceNode" + +UDialogueChoiceNode::UDialogueChoiceNode() +{ +#if WITH_EDITORONLY_DATA + CompatibleGraphType = UDialogueTree::StaticClass(); + + ContextMenuName = LOCTEXT("ConextMenuName", "Choice Node"); +#endif +} + +#if WITH_EDITOR + +FLinearColor UDialogueChoiceNode::GetBackgroundColor() const +{ + const UDialogueTree* DialogueTree = Cast(GetGraph()); + + if (DialogueTree == nullptr) + return Super::GetBackgroundColor(); + + return FLinearColor(1.f, 0.5f, 0.f, 1.f); +} + +#endif + +#undef LOCTEXT_NAMESPACE diff --git a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueChoiceNode.h b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueChoiceNode.h new file mode 100644 index 00000000..0b0550b2 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueChoiceNode.h @@ -0,0 +1,25 @@ +#pragma once + +#include "CoreMinimal.h" +#include "GenericGraphNode.h" +#include "DialogueChoiceNode.generated.h" + +UCLASS(Blueprintable) +class UDialogueChoiceNode : public UGenericGraphNode +{ + GENERATED_BODY() + +public: + UDialogueChoiceNode(); + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Dialogue") + FString Choice1Text = "None"; + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Dialogue") + FString Choice2Text = "None"; + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Dialogue") + FString Choice3Text = "None"; + +#if WITH_EDITOR + virtual FLinearColor GetBackgroundColor() const override; +#endif +}; diff --git a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueEdge.h b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueEdge.h index 72d6491b..ef92beff 100644 --- a/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueEdge.h +++ b/EndlessVendetta/Source/EndlessVendetta/DialogueSystem/DialogueEdge.h @@ -10,7 +10,7 @@ class UDialogueEdge: public UGenericGraphEdge { GENERATED_BODY() -public: - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Dialogue") - FText Selection; + // public: + // UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Dialogue") + // FText Selection; }; \ No newline at end of file