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/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..db464e5 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); } @@ -105,14 +106,42 @@ 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())); +} + +FDialoguePath UDialogueNPC::CreateDialogueChoice(FDialoguePath PreviousDialoguePath) +{ + return FDialoguePath(); +} + +bool UDialogueNPC::GotoDialoguePath(FString PathId) +{ + for (FDialoguePath DialogPath : 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) { - 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..4b6f2f9 100644 --- a/Source/the_twilight_abyss/Dialogue/DialogueNPC.h +++ b/Source/the_twilight_abyss/Dialogue/DialogueNPC.h @@ -16,6 +16,30 @@ enum class EChoices : uint8 Choice3 UMETA(DisplayName="Choice 3"), }; +USTRUCT(BlueprintType) +struct FDialoguePath +{ + GENERATED_BODY() + + UPROPERTY() + TArray Dialogue; + + FDialoguePath() + { + Dialogue.Add("#ROOT"); + } + + FDialoguePath(FString Id) + { + Dialogue.Add(Id); + } + + explicit FDialoguePath(TArray Dialogue) + { + this->Dialogue = Dialogue; + } +}; + UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) class THE_TWILIGHT_ABYSS_API UDialogueNPC : public UActorComponent { @@ -29,7 +53,9 @@ public: FString NPCName; UPROPERTY() - TArray Dialogue; + TArray DialoguePaths; + + TArray CurrentDialoguePath; UPROPERTY(EditAnywhere) float TextAnimationSpeed = 0.05f; @@ -75,7 +101,19 @@ public: void EndDialogue(); UFUNCTION(BlueprintPure) - TArray AddDialogue(FText TextInput, TArray DialogueArrayInput); + 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 DialogueArray);