Updated DialogueNPC for Structs and Dialogue Paths

This commit is contained in:
Philip W 2023-02-09 03:12:27 +00:00
parent a16de31aa2
commit d1fab9f9a1
3 changed files with 27 additions and 10 deletions

BIN
Content/Dialogue/NPCTest.uasset (Stored with Git LFS)

Binary file not shown.

View File

@ -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<FString> UDialogueNPC::AddDialogue(FText TextInput, TArray<FString> Dialo
void UDialogueNPC::GetFinalDialogue(TArray<FString> DialogueArray)
{
Dialogue = DialogueArray;
DialoguePaths.Add(FDialoguePath(DialogueArray));
}

View File

@ -16,6 +16,20 @@ enum class EChoices : uint8
Choice3 UMETA(DisplayName="Choice 3"),
};
USTRUCT(BlueprintType)
struct FDialoguePath
{
GENERATED_BODY()
UPROPERTY()
TArray<FString> Dialogue;
explicit FDialoguePath(const TArray<FString> 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<FString> Dialogue;
TArray<FDialoguePath> DialoguePaths;
TArray<FString> CurrentDialoguePath;
UPROPERTY(EditAnywhere)
float TextAnimationSpeed = 0.05f;