From d1fab9f9a17be1228dbb916041daceafea6c3c29 Mon Sep 17 00:00:00 2001 From: PHILIP White Date: Thu, 9 Feb 2023 03:12:27 +0000 Subject: [PATCH 1/3] 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; From 9bfb07fbbacc54f98a6e411dec9b3c365fb29c90 Mon Sep 17 00:00:00 2001 From: PHILIP White Date: Thu, 9 Feb 2023 17:01:03 +0000 Subject: [PATCH 2/3] Updated DialogueNPC to Add Ids for Dialogue Paths --- .../Dialogue/DialogueNPC.cpp | 31 ++++++++++++++++--- .../the_twilight_abyss/Dialogue/DialogueNPC.h | 26 ++++++++++++++-- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp b/Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp index 31ab5ca..a62d7bb 100644 --- a/Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp +++ b/Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp @@ -106,11 +106,34 @@ void UDialogueNPC::EndDialogue() PlayerController->bShowMouseCursor = false; } -TArray UDialogueNPC::AddDialogue(FText TextInput, TArray DialogueArrayInput) +FDialoguePath UDialogueNPC::CreateRootDialoguePath() { - if (TextInput.IsEmpty()) return DialogueArrayInput; - DialogueArrayInput.Add(TextInput.ToString()); - return DialogueArrayInput; + return FDialoguePath(); +} + +FDialoguePath UDialogueNPC::CreateDialoguePath(FDialoguePath ParentDialoguePath) +{ + return FDialoguePath("#" + FString::FromInt(DialoguePaths.Num())); +} + +bool UDialogueNPC::GotoDialoguePath(FString PathId) +{ + for each (FDialoguePath DialogPath in DialoguePaths) + { + if (DialogPath.Dialogue[0] == PathId) + { + CurrentDialoguePath = DialogPath.Dialogue; + return true; + } + } + return false; +} + +FDialoguePath UDialogueNPC::AddDialogue(FText TextInput, FDialoguePath DialoguePath) +{ + if (TextInput.IsEmpty()) return DialoguePath; + DialoguePath.Dialogue.Add(TextInput.ToString()); + return DialoguePath; } void UDialogueNPC::GetFinalDialogue(TArray DialogueArray) diff --git a/Source/the_twilight_abyss/Dialogue/DialogueNPC.h b/Source/the_twilight_abyss/Dialogue/DialogueNPC.h index a9afa2b..f2a9409 100644 --- a/Source/the_twilight_abyss/Dialogue/DialogueNPC.h +++ b/Source/the_twilight_abyss/Dialogue/DialogueNPC.h @@ -24,7 +24,17 @@ struct FDialoguePath UPROPERTY() TArray Dialogue; - explicit FDialoguePath(const TArray Dialogue) + FDialoguePath() + { + Dialogue.Add("#ROOT"); + } + + FDialoguePath(FString Id) + { + Dialogue.Add(Id); + } + + explicit FDialoguePath(TArray Dialogue) { this->Dialogue = Dialogue; } @@ -91,7 +101,19 @@ public: void EndDialogue(); UFUNCTION(BlueprintPure) - TArray AddDialogue(FText TextInput, TArray DialogueArrayInput); + FDialoguePath CreateRootDialoguePath(); + + UFUNCTION() + FDialoguePath CreateDialoguePath(FDialoguePath ParentDialoguePath); + + UFUNCTION(BlueprintPure) + void CreateDialogueChoice(FDialoguePath PreviousDialoguePath); + + UFUNCTION() + bool GotoDialoguePath(FString PathId); + + UFUNCTION(BlueprintPure) + FDialoguePath AddDialogue(FText TextInput, FDialoguePath DialoguePath); UFUNCTION(BlueprintCallable) void GetFinalDialogue(TArray DialogueArray); From 26f21a9136ff94af448a7ffb1b85019915fa3557 Mon Sep 17 00:00:00 2001 From: PHILIP White Date: Mon, 20 Feb 2023 09:50:09 +0000 Subject: [PATCH 3/3] Updated DialogueNPC to use Ranged For Loops --- Content/Dialogue/DialogueTest.umap | 4 ++-- Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp | 7 ++++++- Source/the_twilight_abyss/Dialogue/DialogueNPC.h | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Content/Dialogue/DialogueTest.umap b/Content/Dialogue/DialogueTest.umap index f2a5797..9ce057c 100644 --- a/Content/Dialogue/DialogueTest.umap +++ b/Content/Dialogue/DialogueTest.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6f2c0cc2d73c9fd35cf193c48ae0546bd41a9a10dedfe8c60d504fe09b55e819 -size 41343 +oid sha256:10874d3de45d0093660a3b6e12561bc69214daafe2cd3072f9574c83f6cbc5d1 +size 40398 diff --git a/Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp b/Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp index a62d7bb..db464e5 100644 --- a/Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp +++ b/Source/the_twilight_abyss/Dialogue/DialogueNPC.cpp @@ -116,9 +116,14 @@ FDialoguePath UDialogueNPC::CreateDialoguePath(FDialoguePath ParentDialoguePath) return FDialoguePath("#" + FString::FromInt(DialoguePaths.Num())); } +FDialoguePath UDialogueNPC::CreateDialogueChoice(FDialoguePath PreviousDialoguePath) +{ + return FDialoguePath(); +} + bool UDialogueNPC::GotoDialoguePath(FString PathId) { - for each (FDialoguePath DialogPath in DialoguePaths) + for (FDialoguePath DialogPath : DialoguePaths) { if (DialogPath.Dialogue[0] == PathId) { diff --git a/Source/the_twilight_abyss/Dialogue/DialogueNPC.h b/Source/the_twilight_abyss/Dialogue/DialogueNPC.h index f2a9409..4b6f2f9 100644 --- a/Source/the_twilight_abyss/Dialogue/DialogueNPC.h +++ b/Source/the_twilight_abyss/Dialogue/DialogueNPC.h @@ -107,7 +107,7 @@ public: FDialoguePath CreateDialoguePath(FDialoguePath ParentDialoguePath); UFUNCTION(BlueprintPure) - void CreateDialogueChoice(FDialoguePath PreviousDialoguePath); + FDialoguePath CreateDialogueChoice(FDialoguePath PreviousDialoguePath); UFUNCTION() bool GotoDialoguePath(FString PathId);