Update Dialogue System to Handle Voice Overs

This commit is contained in:
Philip W 2024-04-26 03:23:22 +01:00
parent 7bbbb5b830
commit a5e8a8db13
3 changed files with 14 additions and 2 deletions

View File

@ -4,7 +4,8 @@
#include "AC_PlayerDialogueInterpreter.h"
#include "DialogueAddItemNode.h"
#include "EndlessVendetta/EndlessVendettaCharacter.h"
#include "Components/AudioComponent.h"
#include "Kismet/GameplayStatics.h"
// Sets default values for this component's properties
@ -57,6 +58,9 @@ void UAC_PlayerDialogueInterpreter::StartDialogue(UDialogueTree* DialogueTree)
if (!IsValid(CurrentTextNode)) return;
CurrentCharacterSpeaking = *GetCharacterSpeakingFromEnum(CurrentTextNode->DialogueCharacterSpeaking);
OnStartDialogue.Broadcast(CurrentTextNode);
if (IsValid(CurrentTextNode->DialogueVoiceOver))
CurrentVoiceOverAudioComponent = UGameplayStatics::SpawnSound2D(
GetWorld(), CurrentTextNode->DialogueVoiceOver, 1.f, 1.f, 0.f, nullptr, false, false);
if (APlayerController* PlayerController = GetWorld()->GetFirstPlayerController())
{
@ -72,6 +76,7 @@ void UAC_PlayerDialogueInterpreter::NextDialogue()
if (IsValid(CurrentChoiceNode)) return;
if (IsValid(CurrentTextNode))
{
CurrentVoiceOverAudioComponent->Stop();
if (CurrentTextNode->ChildrenNodes.Num() == 0)
{
EndDialogue();
@ -137,6 +142,7 @@ void UAC_PlayerDialogueInterpreter::NextDialogue()
void UAC_PlayerDialogueInterpreter::MakeChoiceDialogue(const int Choice)
{
if (!IsValid(CurrentChoiceNode)) return;
CurrentVoiceOverAudioComponent->Stop();
if (Cast<UDialogueChoiceNode>(CurrentChoiceNode->ChildrenNodes[Choice]))
{
CurrentChoiceNode = Cast<UDialogueChoiceNode>(CurrentChoiceNode->ChildrenNodes[Choice]);
@ -166,6 +172,8 @@ void UAC_PlayerDialogueInterpreter::EndDialogue()
CurrentTextNode = nullptr;
CurrentAddItemNode = nullptr;
CurrentCharacterSpeaking = FDialogueCharacter();
CurrentVoiceOverAudioComponent->Stop();
CurrentVoiceOverAudioComponent = nullptr;
if (APlayerController* PlayerController = GetWorld()->GetFirstPlayerController())
{

View File

@ -53,6 +53,8 @@ private:
UPROPERTY()
UDialogueAddItemNode* CurrentAddItemNode;
FDialogueCharacter* GetCharacterSpeakingFromEnum(ECharacterSpeaking CharacterSpeakingEnum) const;
UPROPERTY()
UAudioComponent* CurrentVoiceOverAudioComponent;
public:
// Called every frame

View File

@ -29,6 +29,8 @@ public:
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Dialogue")
ECharacterSpeaking DialogueCharacterSpeaking = ECharacterSpeaking::Character1;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Dialogue")
USoundBase* DialogueVoiceOver;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Choice Requirement")
TArray<EDialogueFlag> RequiredFlags;
@ -44,7 +46,7 @@ public:
TArray<EItem> LacksItemsByEnumID;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Choice Requirement")
TArray<int> LacksItemsByID;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Choice Requirement")
FText RequirementPreText = FText::FromString("None");