Update Dialogue System to Handle Voice Overs
This commit is contained in:
		
							parent
							
								
									7bbbb5b830
								
							
						
					
					
						commit
						a5e8a8db13
					
				| @ -4,7 +4,8 @@ | |||||||
| #include "AC_PlayerDialogueInterpreter.h" | #include "AC_PlayerDialogueInterpreter.h" | ||||||
| 
 | 
 | ||||||
| #include "DialogueAddItemNode.h" | #include "DialogueAddItemNode.h" | ||||||
| #include "EndlessVendetta/EndlessVendettaCharacter.h" | #include "Components/AudioComponent.h" | ||||||
|  | #include "Kismet/GameplayStatics.h" | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| // Sets default values for this component's properties
 | // Sets default values for this component's properties
 | ||||||
| @ -57,6 +58,9 @@ void UAC_PlayerDialogueInterpreter::StartDialogue(UDialogueTree* DialogueTree) | |||||||
| 	if (!IsValid(CurrentTextNode)) return; | 	if (!IsValid(CurrentTextNode)) return; | ||||||
| 	CurrentCharacterSpeaking = *GetCharacterSpeakingFromEnum(CurrentTextNode->DialogueCharacterSpeaking); | 	CurrentCharacterSpeaking = *GetCharacterSpeakingFromEnum(CurrentTextNode->DialogueCharacterSpeaking); | ||||||
| 	OnStartDialogue.Broadcast(CurrentTextNode); | 	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()) | 	if (APlayerController* PlayerController = GetWorld()->GetFirstPlayerController()) | ||||||
| 	{ | 	{ | ||||||
| @ -72,6 +76,7 @@ void UAC_PlayerDialogueInterpreter::NextDialogue() | |||||||
| 	if (IsValid(CurrentChoiceNode)) return; | 	if (IsValid(CurrentChoiceNode)) return; | ||||||
| 	if (IsValid(CurrentTextNode)) | 	if (IsValid(CurrentTextNode)) | ||||||
| 	{ | 	{ | ||||||
|  | 		CurrentVoiceOverAudioComponent->Stop(); | ||||||
| 		if (CurrentTextNode->ChildrenNodes.Num() == 0) | 		if (CurrentTextNode->ChildrenNodes.Num() == 0) | ||||||
| 		{ | 		{ | ||||||
| 			EndDialogue(); | 			EndDialogue(); | ||||||
| @ -137,6 +142,7 @@ void UAC_PlayerDialogueInterpreter::NextDialogue() | |||||||
| void UAC_PlayerDialogueInterpreter::MakeChoiceDialogue(const int Choice) | void UAC_PlayerDialogueInterpreter::MakeChoiceDialogue(const int Choice) | ||||||
| { | { | ||||||
| 	if (!IsValid(CurrentChoiceNode)) return; | 	if (!IsValid(CurrentChoiceNode)) return; | ||||||
|  | 	CurrentVoiceOverAudioComponent->Stop(); | ||||||
| 	if (Cast<UDialogueChoiceNode>(CurrentChoiceNode->ChildrenNodes[Choice])) | 	if (Cast<UDialogueChoiceNode>(CurrentChoiceNode->ChildrenNodes[Choice])) | ||||||
| 	{ | 	{ | ||||||
| 		CurrentChoiceNode = Cast<UDialogueChoiceNode>(CurrentChoiceNode->ChildrenNodes[Choice]); | 		CurrentChoiceNode = Cast<UDialogueChoiceNode>(CurrentChoiceNode->ChildrenNodes[Choice]); | ||||||
| @ -166,6 +172,8 @@ void UAC_PlayerDialogueInterpreter::EndDialogue() | |||||||
| 	CurrentTextNode = nullptr; | 	CurrentTextNode = nullptr; | ||||||
| 	CurrentAddItemNode = nullptr; | 	CurrentAddItemNode = nullptr; | ||||||
| 	CurrentCharacterSpeaking = FDialogueCharacter(); | 	CurrentCharacterSpeaking = FDialogueCharacter(); | ||||||
|  | 	CurrentVoiceOverAudioComponent->Stop(); | ||||||
|  | 	CurrentVoiceOverAudioComponent = nullptr; | ||||||
| 
 | 
 | ||||||
| 	if (APlayerController* PlayerController = GetWorld()->GetFirstPlayerController()) | 	if (APlayerController* PlayerController = GetWorld()->GetFirstPlayerController()) | ||||||
| 	{ | 	{ | ||||||
|  | |||||||
| @ -53,6 +53,8 @@ private: | |||||||
| 	UPROPERTY() | 	UPROPERTY() | ||||||
| 	UDialogueAddItemNode* CurrentAddItemNode; | 	UDialogueAddItemNode* CurrentAddItemNode; | ||||||
| 	FDialogueCharacter* GetCharacterSpeakingFromEnum(ECharacterSpeaking CharacterSpeakingEnum) const; | 	FDialogueCharacter* GetCharacterSpeakingFromEnum(ECharacterSpeaking CharacterSpeakingEnum) const; | ||||||
|  | 	UPROPERTY() | ||||||
|  | 	UAudioComponent* CurrentVoiceOverAudioComponent; | ||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
| 	// Called every frame
 | 	// Called every frame
 | ||||||
|  | |||||||
| @ -29,6 +29,8 @@ public: | |||||||
| 
 | 
 | ||||||
| 	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Dialogue") | 	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Dialogue") | ||||||
| 	ECharacterSpeaking DialogueCharacterSpeaking = ECharacterSpeaking::Character1; | 	ECharacterSpeaking DialogueCharacterSpeaking = ECharacterSpeaking::Character1; | ||||||
|  | 	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Dialogue") | ||||||
|  | 	USoundBase* DialogueVoiceOver; | ||||||
| 
 | 
 | ||||||
| 	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Choice Requirement") | 	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Choice Requirement") | ||||||
| 	TArray<EDialogueFlag> RequiredFlags; | 	TArray<EDialogueFlag> RequiredFlags; | ||||||
| @ -44,7 +46,7 @@ public: | |||||||
| 	TArray<EItem> LacksItemsByEnumID; | 	TArray<EItem> LacksItemsByEnumID; | ||||||
| 	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Choice Requirement") | 	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Choice Requirement") | ||||||
| 	TArray<int> LacksItemsByID; | 	TArray<int> LacksItemsByID; | ||||||
| 	 | 
 | ||||||
| 	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Choice Requirement") | 	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Choice Requirement") | ||||||
| 	FText RequirementPreText = FText::FromString("None"); | 	FText RequirementPreText = FText::FromString("None"); | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user