121 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			121 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
// Fill out your copyright notice in the Description page of Project Settings.
 | 
						|
 | 
						|
#pragma once
 | 
						|
 | 
						|
#include "CoreMinimal.h"
 | 
						|
#include "Components/ActorComponent.h"
 | 
						|
#include "Components/Button.h"
 | 
						|
#include "Components/TextBlock.h"
 | 
						|
#include "DialogueNPC.generated.h"
 | 
						|
 | 
						|
UENUM(BlueprintType)
 | 
						|
enum class EChoices : uint8
 | 
						|
{
 | 
						|
	Choice1 UMETA(DisplayName="Choice 1"),
 | 
						|
	Choice2 UMETA(DisplayName="Choice 2"),
 | 
						|
	Choice3 UMETA(DisplayName="Choice 3"),
 | 
						|
};
 | 
						|
 | 
						|
USTRUCT(BlueprintType)
 | 
						|
struct FDialoguePath
 | 
						|
{
 | 
						|
	GENERATED_BODY()
 | 
						|
 | 
						|
	UPROPERTY()
 | 
						|
	TArray<FString> Dialogue;
 | 
						|
 | 
						|
	FDialoguePath() 
 | 
						|
	{
 | 
						|
		Dialogue.Add("#ROOT");
 | 
						|
	}
 | 
						|
 | 
						|
	FDialoguePath(FString Id)
 | 
						|
	{
 | 
						|
		Dialogue.Add(Id);
 | 
						|
	}
 | 
						|
 | 
						|
	explicit FDialoguePath(TArray<FString> Dialogue)
 | 
						|
	{
 | 
						|
		this->Dialogue = Dialogue;
 | 
						|
	}
 | 
						|
};
 | 
						|
 | 
						|
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
 | 
						|
class THE_TWILIGHT_ABYSS_API UDialogueNPC : public UActorComponent
 | 
						|
{
 | 
						|
	GENERATED_BODY()
 | 
						|
 | 
						|
public:
 | 
						|
	// Sets default values for this component's properties
 | 
						|
	UDialogueNPC();
 | 
						|
 | 
						|
	UPROPERTY(EditAnywhere)
 | 
						|
	FString NPCName;
 | 
						|
	
 | 
						|
	UPROPERTY()
 | 
						|
	TArray<FDialoguePath> DialoguePaths;
 | 
						|
 | 
						|
	TArray<FString> CurrentDialoguePath;
 | 
						|
 | 
						|
	UPROPERTY(EditAnywhere)
 | 
						|
	float TextAnimationSpeed = 0.05f;
 | 
						|
 | 
						|
protected:
 | 
						|
	// Called when the game starts
 | 
						|
	virtual void BeginPlay() override;
 | 
						|
 | 
						|
	UPROPERTY()
 | 
						|
	TSubclassOf<UUserWidget> DialogueWidget;
 | 
						|
 | 
						|
private:
 | 
						|
	UPROPERTY()
 | 
						|
	UUserWidget* DialogueWidgetInstance;
 | 
						|
	
 | 
						|
	UPROPERTY()
 | 
						|
	UTextBlock* NPCNameText;
 | 
						|
 | 
						|
	UPROPERTY()
 | 
						|
	UTextBlock* DialogueText;
 | 
						|
	
 | 
						|
	UPROPERTY()
 | 
						|
	UButton* NextButton;
 | 
						|
 | 
						|
	int DialogueIndex = 1;
 | 
						|
	FString CurrentDialogue;
 | 
						|
 | 
						|
	UPROPERTY()
 | 
						|
	FTimerHandle TextAnimationTimerHandle;
 | 
						|
 | 
						|
	UFUNCTION()
 | 
						|
	void NextDialogue();
 | 
						|
	void NextCharacter();
 | 
						|
 | 
						|
public:
 | 
						|
	// Called every frame
 | 
						|
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
 | 
						|
 | 
						|
	UFUNCTION(BlueprintCallable)
 | 
						|
	void StartDialogue();
 | 
						|
 | 
						|
	UFUNCTION(BlueprintCallable)
 | 
						|
	void EndDialogue();
 | 
						|
 | 
						|
	UFUNCTION(BlueprintPure)
 | 
						|
	FDialoguePath CreateRootDialoguePath();
 | 
						|
 | 
						|
	UFUNCTION()
 | 
						|
	FDialoguePath CreateDialoguePath(FDialoguePath ParentDialoguePath);
 | 
						|
 | 
						|
	UFUNCTION(BlueprintPure)
 | 
						|
	FDialoguePath CreateDialogueChoice(FDialoguePath PreviousDialoguePath);
 | 
						|
 | 
						|
	UFUNCTION()
 | 
						|
	bool GotoDialoguePath(FString PathId);
 | 
						|
 | 
						|
	UFUNCTION(BlueprintPure)
 | 
						|
	FDialoguePath AddDialogue(FText TextInput, FDialoguePath DialoguePath);
 | 
						|
 | 
						|
	UFUNCTION(BlueprintCallable)
 | 
						|
	void GetFinalDialogue(TArray<FString> DialogueArray);
 | 
						|
};
 |