Update Dialogue Tree for Proper Choice Interpretation
This commit is contained in:
parent
adc5787b43
commit
5145b69009
@ -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;
|
||||
};
|
@ -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<UDialogueTextNode>(DialogueTree->RootNodes[0]->ChildrenNodes[0]);
|
||||
OnStartDialogue.Broadcast(CurrentTextNode);
|
||||
}
|
||||
|
||||
void UAC_PlayerDialogueInterpreter::NextDialogue()
|
||||
{
|
||||
if (IsValid(CurrentTextNode))
|
||||
{
|
||||
if (Cast<UDialogueChoiceNode>(CurrentTextNode->ChildrenNodes[0]))
|
||||
{
|
||||
CurrentTextNode = nullptr;
|
||||
CurrentChoiceNode = Cast<UDialogueChoiceNode>(CurrentTextNode->ChildrenNodes[0]);
|
||||
OnChoiceDialogue.Broadcast(CurrentChoiceNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentChoiceNode = nullptr;
|
||||
CurrentTextNode = Cast<UDialogueTextNode>(CurrentTextNode->ChildrenNodes[0]);
|
||||
OnNextDialogue.Broadcast(CurrentTextNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UAC_PlayerDialogueInterpreter::MakeChoiceDialogue(const int Choice)
|
||||
{
|
||||
if (Cast<UDialogueChoiceNode>(CurrentTextNode->ChildrenNodes[Choice]))
|
||||
{
|
||||
CurrentTextNode = nullptr;
|
||||
CurrentChoiceNode = Cast<UDialogueChoiceNode>(CurrentTextNode->ChildrenNodes[Choice]);
|
||||
OnChoiceDialogue.Broadcast(CurrentChoiceNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentChoiceNode = nullptr;
|
||||
CurrentTextNode = Cast<UDialogueTextNode>(CurrentTextNode->ChildrenNodes[Choice]);
|
||||
OnNextDialogue.Broadcast(CurrentTextNode);
|
||||
}
|
||||
}
|
@ -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);
|
||||
};
|
@ -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<UDialogueTree>(GetGraph());
|
||||
|
||||
if (DialogueTree == nullptr)
|
||||
return Super::GetBackgroundColor();
|
||||
|
||||
return FLinearColor(1.f, 0.5f, 0.f, 1.f);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#undef LOCTEXT_NAMESPACE
|
@ -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
|
||||
};
|
@ -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;
|
||||
};
|
Loading…
Reference in New Issue
Block a user