118 lines
2.5 KiB
C++
118 lines
2.5 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 "Components/Image.h"
|
|
#include "DialogueNPC.generated.h"
|
|
|
|
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
|
|
class UDialoguePath : public UObject
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
UPROPERTY(BlueprintReadWrite)
|
|
TArray<FString> Dialogue;
|
|
|
|
UPROPERTY(BlueprintReadWrite)
|
|
TArray<UDialoguePath*> Choices;
|
|
};
|
|
|
|
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()
|
|
UDialoguePath* RootDialoguePath;
|
|
UPROPERTY()
|
|
UDialoguePath* CurrentDialoguePath;
|
|
TArray<FString> CurrentDialogueStringPath;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
UTexture2D* NPCPortrait;
|
|
|
|
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()
|
|
UImage* NPCPortraitImage;
|
|
UPROPERTY()
|
|
UButton* Choice1Button;
|
|
UPROPERTY()
|
|
UButton* Choice2Button;
|
|
UPROPERTY()
|
|
UButton* Choice3Button;
|
|
UPROPERTY()
|
|
UTextBlock* Choice1Text;
|
|
UPROPERTY()
|
|
UTextBlock* Choice2Text;
|
|
UPROPERTY()
|
|
UTextBlock* Choice3Text;
|
|
|
|
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(BlueprintCallable)
|
|
UDialoguePath* CreateRootDialoguePath();
|
|
|
|
UFUNCTION(BlueprintCallable)
|
|
UDialoguePath* AddDialogue(UDialoguePath* DialoguePath, FText TextInput);
|
|
UFUNCTION(BlueprintCallable)
|
|
void AddChoices(UDialoguePath* ParentPath, FText ChoiceText1, FText ChoiceText2, FText ChoiceText3,
|
|
UDialoguePath*& ChoicePath1, UDialoguePath*& ChoicePath2, UDialoguePath*& ChoicePath3);
|
|
|
|
UFUNCTION()
|
|
void Choice1();
|
|
UFUNCTION()
|
|
void Choice2();
|
|
UFUNCTION()
|
|
void Choice3();
|
|
};
|