From d1fab9f9a17be1228dbb916041daceafea6c3c29 Mon Sep 17 00:00:00 2001 From: PHILIP White Date: Thu, 9 Feb 2023 03:12:27 +0000 Subject: [PATCH] Updated DialogueNPC for Structs and Dialogue Paths --- Content/Dialogue/NPCTest.uasset | 4 ++-- .../Dialogue/DialogueNPC.cpp | 15 ++++++++------- .../the_twilight_abyss/Dialogue/DialogueNPC.h | 18 +++++++++++++++++- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Content/Dialogue/NPCTest.uasset b/Content/Dialogue/NPCTest.uasset index e33f5cc..ea42022 100644 --- a/Content/Dialogue/NPCTest.uasset +++ b/Content/Dialogue/NPCTest.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3d8d35e08f9a82472293b350e194a815b8e58c85084e33c6211de9f7c59a67a8 -size 47133 +oid sha256:5063f0083f2c76f077c87560989081c0c995807c84b556ecad3d464bcd30c236 +size 46832 diff --git a/Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp b/Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp index af4c7ba..31ab5ca 100644 --- a/Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp +++ b/Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp @@ -35,15 +35,15 @@ void UDialogueNPC::BeginPlay() void UDialogueNPC::NextDialogue() { //Dialogue Skip - if (CurrentDialogue.Len() < Dialogue[DialogueIndex].Len()) + if (CurrentDialogue.Len() < CurrentDialoguePath[DialogueIndex].Len()) { - CurrentDialogue = Dialogue[DialogueIndex]; + CurrentDialogue = CurrentDialoguePath[DialogueIndex]; DialogueText->SetText(FText::FromString(CurrentDialogue)); return; } DialogueIndex++; - if (DialogueIndex >= Dialogue.Num()) + if (DialogueIndex >= CurrentDialoguePath.Num()) { EndDialogue(); return; @@ -53,11 +53,11 @@ void UDialogueNPC::NextDialogue() void UDialogueNPC::NextCharacter() { - if (DialogueIndex >= Dialogue.Num()) return; + if (DialogueIndex >= CurrentDialoguePath.Num()) return; - if (CurrentDialogue.Len() < Dialogue[DialogueIndex].Len()) + if (CurrentDialogue.Len() < CurrentDialoguePath[DialogueIndex].Len()) { - CurrentDialogue.AppendChar(Dialogue[DialogueIndex][CurrentDialogue.Len()]); + CurrentDialogue.AppendChar(CurrentDialoguePath[DialogueIndex][CurrentDialogue.Len()]); DialogueText->SetText(FText::FromString(CurrentDialogue)); } } @@ -86,6 +86,7 @@ void UDialogueNPC::StartDialogue() DialogueIndex = 1; NPCNameText->SetText(FText::FromString(NPCName)); CurrentDialogue = ""; + CurrentDialoguePath = DialoguePaths[0].Dialogue; GetWorld()->GetTimerManager().SetTimer(TextAnimationTimerHandle, this, &UDialogueNPC::NextCharacter, TextAnimationSpeed, true); } @@ -114,5 +115,5 @@ TArray UDialogueNPC::AddDialogue(FText TextInput, TArray Dialo void UDialogueNPC::GetFinalDialogue(TArray DialogueArray) { - Dialogue = DialogueArray; + DialoguePaths.Add(FDialoguePath(DialogueArray)); } diff --git a/Source/the_twilight_abyss/Dialogue/DialogueNPC.h b/Source/the_twilight_abyss/Dialogue/DialogueNPC.h index eeb8276..a9afa2b 100644 --- a/Source/the_twilight_abyss/Dialogue/DialogueNPC.h +++ b/Source/the_twilight_abyss/Dialogue/DialogueNPC.h @@ -16,6 +16,20 @@ enum class EChoices : uint8 Choice3 UMETA(DisplayName="Choice 3"), }; +USTRUCT(BlueprintType) +struct FDialoguePath +{ + GENERATED_BODY() + + UPROPERTY() + TArray Dialogue; + + explicit FDialoguePath(const TArray Dialogue) + { + this->Dialogue = Dialogue; + } +}; + UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) class THE_TWILIGHT_ABYSS_API UDialogueNPC : public UActorComponent { @@ -29,7 +43,9 @@ public: FString NPCName; UPROPERTY() - TArray Dialogue; + TArray DialoguePaths; + + TArray CurrentDialoguePath; UPROPERTY(EditAnywhere) float TextAnimationSpeed = 0.05f;