void UBTTask_WaitAnswer::SetAnswer(UDialogueButton* DialogueButton)
{
	if (DialogueButton != nullptr && DialogueButton->GetChildrenCount() > 0)
	{
		UTextBlock* TextBlock = Cast<UTextBlock>(DialogueButton->GetChildAt(0));
		if (TextBlock)
		{
			SetAnswer(TextBlock->GetText());
		}
	}
}
Пример #2
0
void UChatboxWidget::AddChat(FString theText)
{
	UWidget* theTextWidget = FindFirstWidget(UTextBlock::StaticClass());
	if (theTextWidget)
	{
		UTextBlock* castedTextWidget = Cast<UTextBlock>(theTextWidget);
		castedTextWidget->SetText(FText::FromString(castedTextWidget->GetText().ToString() + "\n" + theText));
	}
	UWidget* theScrollWidget = FindFirstWidget(UScrollBox::StaticClass());
	if (theScrollWidget)
	{
		UScrollBox* castedScrollWidget = Cast<UScrollBox>(theScrollWidget);
		castedScrollWidget->SetScrollOffset(9999);
	}
}
void UBrainLevelSelectionMenuWidget::FillLevelsList(UScrollBox* container)
{
	UWorld* world = GetWorld();
	if (world)
	{
		FString path = FPaths::GameContentDir();
		path += "/FirstPerson/Maps";

		FString pathNFilter = path + "/" + "*.umap";
		IFileManager::Get().FindFiles(_levelList, *pathNFilter, true, true);

		FString mainMenuMap = FString("MainMenu.umap");
		_levelList.Remove(mainMenuMap);

		USlateWidgetStyleAsset* slateStyle = LoadObject<USlateWidgetStyleAsset>(nullptr, TEXT("/Game/FirstPerson/Menus/BrainButtonStyle.BrainButtonStyle"),nullptr,LOAD_None,nullptr);
		const FButtonStyle* btnStyle = slateStyle->GetStyle<FButtonStyle>();
		FLinearColor color = FLinearColor(1,0.255,0,1);
		FSlateColor slateColor = FSlateColor(color);

		for (FString name : _levelList)
		{
			UBrainLevelButtonWidget* btn = NewObject<UBrainLevelButtonWidget>(this);
			btn->WidgetStyle = *btnStyle;
			
			UTextBlock* text = NewObject<UTextBlock>(btn, FName("text"));
			text->ColorAndOpacity = slateColor;
			
			name.RemoveFromEnd(".umap");

			text->SetText(FText::FromString(name));
			btn->AddChild(text);
			container->AddChild(btn);
		}

		TArray<UPanelSlot*> slots = container->GetSlots();
		for (UPanelSlot* slot : slots)
		{
			if (UScrollBoxSlot* sSlot = Cast<UScrollBoxSlot>(slot))
				sSlot->SetPadding(FMargin(0, 0, 0, 5.0f));
		}
	}
}
void UBTTask_ShowPhrases::ShowNewChar()
{
	StringToDisplay.AppendChar(FullString[CurrentCharNum]);
	UTextBlock* StartPhraseTextBlock = Cast<UTextBlock>(DialoguePhraseSlot);
	if (StartPhraseTextBlock)
	{
		StartPhraseTextBlock->SetText(FText::Format(NSLOCTEXT("DialogueSystem", "ShowPhraseText", "{0}"), FText::FromString(StringToDisplay)));
	}
	CurrentCharNum++;
	if (CurrentCharNum >= FullString.Num() - 1)
	{
		float ShowingTime = DialogueTextOptions.UseGeneralTime ? DialogueTextOptions.GeneralShowingTime : DialogueTextOptions.Phrases[ShowingNumPhrase].ShowingTime;
		TimerDelegate = FTimerDelegate::CreateUObject(this, &UBTTask_ShowPhrases::ShowNewDialoguePhrase, false);
		OwnerActor->GetWorldTimerManager().SetTimer(TimerHandle, TimerDelegate, ShowingTime, false);
	}
	else
	{
		OwnerActor->GetWorldTimerManager().SetTimer(TimerHandle, TimerDelegate, DialogueTextOptions.Delay, false);
	}
};
EBTNodeResult::Type UBTTask_WaitAnswer::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	ClearAnswer();
	EBTNodeResult::Type NodeResult = !bAnswerDone ? EBTNodeResult::InProgress : NodeResult = EBTNodeResult::Succeeded;
	TimerCount = Timer;
	AActor* OwnerActor = OwnerComp.GetOwner();

	if (!DialogueWidget.IsNone())
	{
		FName WidgetKeyName = DialogueWidget.SelectedKeyName;
		BlackboardComp = OwnerComp.GetBlackboardComponent();
		Widget = Cast<UUserWidget>(BlackboardComp->GetValueAsObject(WidgetKeyName));
		WidgetComp = Cast<UWidgetComponent>(BlackboardComp->GetValueAsObject(WidgetKeyName));
		UDialogueButton* FirstButton = nullptr;

		if (!Widget && !WidgetComp)
		{
#if WITH_EDITOR
			FMessageLog("PIE").Error()
				->AddToken(FTextToken::Create(LOCTEXT("InvalidWidgetKey", "Invalid key for Dialogue Widget in ")))
				->AddToken(FUObjectToken::Create((UObject*)OwnerComp.GetCurrentTree()));
#endif
			return EBTNodeResult::Failed;
		}

		if (WidgetComp)
		{
			Widget = CreateWidget<UUserWidget>(GetWorld(), WidgetComp->GetWidgetClass());
			PlayerController = WidgetComp->GetUserWidgetObject()->GetOwningPlayer();
			bIsUserWidget = false;
		}
		else
		{
			bIsUserWidget = true;
			PlayerController = Widget->GetOwningPlayer();
		}

		if (Widget && Widget->IsInViewport())
		{
			Widget->RemoveFromParent();
		}
		if (!Widget)
		{
			NodeResult = EBTNodeResult::Failed;
		}
		else
		{
			WidgetTree = Widget->WidgetTree;
			UWidget* DialogueQuestionsSlot = WidgetTree->FindWidget(DialogueQuestionsSlotName);
			UPanelWidget* Panel = Cast<UPanelWidget>(DialogueQuestionsSlot);
			if (Panel)
			{
				TArray<UWidget*> Buttons;
				UDialogueButton* SampleButton = nullptr;
				UTextBlock* SampleTextBlock = nullptr;
				WidgetTree->GetChildWidgets(DialogueQuestionsSlot, Buttons);
				for (auto& elem : Buttons)
				{
					UDialogueButton* Button = Cast<UDialogueButton>(elem);
					if (Button)
					{
						SampleButton = Button;
						WidgetTree->RemoveWidget(elem);
					}
					UTextBlock* TextBlock = Cast<UTextBlock>(elem);
					if (TextBlock)
					{
						SampleTextBlock = TextBlock;
						WidgetTree->RemoveWidget(elem);
					}
				}
				if (SampleButton != nullptr && SampleTextBlock != nullptr)
				{
					const UBTNode* BTNode = GetParentNode();
					const UBTCompositeNode* CBTNode = Cast<UBTCompositeNode>(BTNode);
					Panel->SetVisibility(ESlateVisibility::Visible);
					if (CBTNode)
					{
						int32 ButtonNumber = 0;
						for (int32 Index = 0; Index != CBTNode->Children.Num(); ++Index)
						{
							auto& Child = CBTNode->Children[Index];
							UBTComposite_Question* Question = Cast<UBTComposite_Question>(Child.ChildComposite);
							bool bDecoratorOk = CBTNode->DoDecoratorsAllowExecution(OwnerComp, OwnerComp.GetActiveInstanceIdx(), Index);

							if(Question)
							{
								Question->bCanExecute = false;
								Question->bSelected = false;
							}
							if (
									Question
									&& Question->Children.Num() > 0
									&& Question->GetVisibility(PlayerController)
									&& Question->bVisible
									&& bDecoratorOk
								)
							{
								Question->bCanExecute = true;
								UDialogueButton *NewSampleButton = NewObject<UDialogueButton>(this, NAME_None, SampleButton->GetFlags(), SampleButton);
								UTextBlock *NewSampleTextBlock = NewObject<UTextBlock>(this, NAME_None, SampleTextBlock->GetFlags(), SampleTextBlock);

								ButtonNumber++;
								if (bUseGamepad)
								{
									NewSampleButton->IsFocusable = true;
									if (ButtonNumber == 1)
									{
										FirstButton = NewSampleButton;
									}
								}
								else
								{
									NewSampleButton->IsFocusable = false;
								}

								NewSampleTextBlock->SetText(FText::Format(NSLOCTEXT("DialogueSystem", "ButtonText", "{0}"), Question->QuestionThumbnail));
								UWidget* Oldtext = NewSampleButton->GetChildAt(0);
								NewSampleButton->WaitTask = this;
								NewSampleButton->RemoveChild(Oldtext);
								NewSampleButton->AddChild(NewSampleTextBlock);
								Panel->AddChild(NewSampleButton);
							}
						}
					}
				}
				// Event Listener
				UWidget* DialogueEventListener = WidgetTree->FindWidget(FName("DialogueEventListener"));
				if (DialogueEventListener != nullptr)
				{
					UDialogueEventListener* EventListener = Cast<UDialogueEventListener>(DialogueEventListener);
					if (EventListener)
					{
						EventListener->WaitAnswerNode = this;
					}
				}
			}
			if (bIsUserWidget)
			{
				Widget->AddToViewport();
			}
			else
			{
				WidgetComp->SetWidget(Widget);
				WidgetComp->SetVisibility(true);
			}
			PlayerController->bShowMouseCursor = !bUseGamepad;
			FInputModeUIOnly InputModeUIOnly;
			FInputModeGameAndUI InputModeGameAndUI;

			if (InputMode == EWidggetInputMode::UIOnly)
			{
				PlayerController->SetInputMode(InputModeUIOnly);
			}
			else
			{
				PlayerController->SetInputMode(InputModeGameAndUI);
			}
			if (bUseGamepad && Panel)
			{
				FirstButton->SetKeyboardFocus();
			}
			else
			{
				if (InputMode == EWidggetInputMode::UIOnly)
				{
					InputModeUIOnly.SetWidgetToFocus(Widget->TakeWidget());
				}
				else
				{
					InputModeGameAndUI.SetWidgetToFocus(Widget->TakeWidget());
				}
			}

		}

		// cinematic
		if (DialogueCinematicOptions.bPlayMatinee && !DialogueCinematicOptions.Matinee.Equals("None"))
		{
			for (TActorIterator<AMatineeActor> It(OwnerActor->GetWorld()); It; ++It)
			{
				MatineeActor = *It;
				if (MatineeActor && MatineeActor->GetName().Equals(DialogueCinematicOptions.Matinee))
				{
					MatineeActor->bLooping = DialogueCinematicOptions.bLoop;
					MatineeActor->Play();
					break;
				}
			}
		}

		// camera
		if (DialogueCameraOptions.bUseCamera)
		{
			if (!DialogueCameraOptions.CameraToView.IsNone() && !DialogueCameraOptions.PlayerCamera.IsNone())
			{
				FName CameraToViewKeyName = DialogueCameraOptions.CameraToView.SelectedKeyName;
				BlackboardComp = OwnerComp.GetBlackboardComponent();
				UCameraComponent* CameraToView = Cast<UCameraComponent>(BlackboardComp->GetValueAsObject(CameraToViewKeyName));

				FName PlayerCameraKeyName = DialogueCameraOptions.PlayerCamera.SelectedKeyName;
				PlayerCamera = Cast<UCameraComponent>(BlackboardComp->GetValueAsObject(PlayerCameraKeyName));

				if (PlayerCamera && CameraToView)
				{
					SaveDefaultCameraData(PlayerCamera);
					if (PlayerCamera == CameraToView)
					{
						PlayerCamera->SetWorldLocationAndRotation(DefaultCameraLocation, DefaultCameraRotation);
					}
					else
					{
						PlayerCamera->SetWorldLocationAndRotation(CameraToView->GetComponentLocation(), CameraToView->GetComponentRotation());
					}
				}
			}
		}
	}

	return NodeResult;
}
EBTNodeResult::Type UBTTask_ShowPhrases::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{	
	EBTNodeResult::Type NodeResult = ShowingNumPhrase <= PhrasesCount ? EBTNodeResult::InProgress : NodeResult = EBTNodeResult::Succeeded;
	// reset timer handle
	TimerHandle.Invalidate();
	//AudioComponent = NULL;
	
	if (!DialogueWidget.IsNone())
	{
		FName WidgetKeyName = DialogueWidget.SelectedKeyName;
		BlackboardComp = OwnerComp.GetBlackboardComponent();
		Widget = Cast<UUserWidget>(BlackboardComp->GetValueAsObject(WidgetKeyName));
		WidgetComp = Cast<UWidgetComponent>(BlackboardComp->GetValueAsObject(WidgetKeyName));
		OwnerActor = OwnerComp.GetOwner();

		if (!Widget && !WidgetComp)
		{
#if WITH_EDITOR
			FMessageLog("PIE").Error()
				->AddToken(FTextToken::Create(LOCTEXT("InvalidWidgetKey", "Invalid key for Dialogue Widget in ")))
				->AddToken(FUObjectToken::Create((UObject*)OwnerComp.GetCurrentTree()));
#endif
			return EBTNodeResult::Failed;
		}

		if (WidgetComp)
		{
			Widget = CreateWidget<UUserWidget>(GetWorld(), WidgetComp->GetWidgetClass());
			bIsUserWidget = false;
		}
		else
		{
			bIsUserWidget = true;
		}

		if (Widget && Widget->IsInViewport())
		{
			Widget->RemoveFromParent();
		}

		if (Widget && !Widget->IsInViewport())
		{
			UWidgetTree* WidgetTree = Widget->WidgetTree;
			UWidget* DialogueQuestionsSlot = WidgetTree->FindWidget(DialogueTextOptions.DialogueQuestionsSlotName);
			if (DialogueQuestionsSlot != nullptr)
			{
				DialogueQuestionsSlot->SetVisibility(ESlateVisibility::Hidden);
			}

			// text
			DialoguePhraseSlot = WidgetTree->FindWidget(DialogueTextOptions.DialoguePhraseSlotName);
			if (DialoguePhraseSlot != nullptr)
			{
				DialoguePhraseSlot->SetVisibility(ESlateVisibility::Visible);
				UTextBlock* StartPhraseTextBlock = Cast<UTextBlock>(DialoguePhraseSlot);
				if (StartPhraseTextBlock)
				{
					if (DialogueTextOptions.bShowTextPhrases)
					{
						PhrasesCount = DialogueTextOptions.Phrases.Num() - 1; // starts from 0
						if (ShowingNumPhrase > PhrasesCount)
						{
							ShowingNumPhrase = 0;
						}
						FText StartPhrase = DialogueTextOptions.Phrases.Num() > 0 ? DialogueTextOptions.Phrases[ShowingNumPhrase].Phrase : FText::GetEmpty();
						if (DialogueTextOptions.TextEffect == ETextEffect::NoEffect || DialogueTextOptions.Delay == 0.0f)
						{
							StartPhraseTextBlock->SetText(FText::Format(NSLOCTEXT("DialogueSystem", "ShowPhraseText", "{0}"), StartPhrase));
							float ShowingTime = DialogueTextOptions.UseGeneralTime ? DialogueTextOptions.GeneralShowingTime : DialogueTextOptions.Phrases[ShowingNumPhrase].ShowingTime;
							TimerDelegate = FTimerDelegate::CreateUObject(this, &UBTTask_ShowPhrases::ShowNewDialoguePhrase, false);
							OwnerActor->GetWorldTimerManager().SetTimer(TimerHandle, TimerDelegate, ShowingTime, false);
						}
						else
						{
							if (DialogueTextOptions.TextEffect == ETextEffect::Typewriter)
							{
								CurrentCharNum = 1; StringToDisplay = "";
								FullString = StartPhrase.ToString().GetCharArray();
								StringToDisplay.AppendChar(FullString[0]);
								if (StartPhraseTextBlock)
								{
									StartPhraseTextBlock->SetText(FText::Format(NSLOCTEXT("DialogueSystem", "ShowPhraseText", "{0}"), FText::FromString(StringToDisplay)));
								}
								TimerDelegate = FTimerDelegate::CreateUObject(this, &UBTTask_ShowPhrases::ShowNewChar);
								OwnerActor->GetWorldTimerManager().SetTimer(TimerHandle, TimerDelegate, DialogueTextOptions.Delay, false);
							}
						}
						// play phrase sound 
						if (DialogueTextOptions.Phrases[ShowingNumPhrase].SoundToPlay)
						{
							PhraseAudioComponent = UGameplayStatics::SpawnSound2D(GetWorld(), DialogueTextOptions.Phrases[ShowingNumPhrase].SoundToPlay);
						}
					}
					else
					{
						DialoguePhraseSlot->SetVisibility(ESlateVisibility::Hidden);
						bTextFinished = true;
					}
				}
			}
			// name
			DialogueNameSlot = WidgetTree->FindWidget(DialogueNameOptions.DialogueSpeakerNameSlotName);
			if (DialogueNameSlot != nullptr)
			{
				if (DialogueNameOptions.bShowName)
				{
					DialogueNameSlot->SetVisibility(ESlateVisibility::Visible);
					UTextBlock* NameTextBlock = Cast<UTextBlock>(DialogueNameSlot);
					if (NameTextBlock)
					{
						NameTextBlock->SetText(DialogueNameOptions.Name);
					}
				}
				else
				{
					DialogueNameSlot->SetVisibility(ESlateVisibility::Hidden);
				}
			}
			// image
			DialogueImageSlot = WidgetTree->FindWidget(DialogueImageOptions.DialogueSpeakerImageSlotName);
			if (DialogueImageSlot != nullptr)
			{
				if (DialogueImageOptions.bShowImage)
				{
					DialogueImageSlot->SetVisibility(ESlateVisibility::Visible);
					UImage* DialogueImage = Cast<UImage>(DialogueImageSlot);
					if (DialogueImage)
					{
						DialogueImage->SetBrushFromTexture(DialogueImageOptions.Image);
					}
				}
				else
				{
					DialogueImageSlot->SetVisibility(ESlateVisibility::Hidden);
				}
			}
			// general sound
			if (DialogueSoundOptions.bPlaySound)
			{
				if (DialogueSoundOptions.SoundToPlay)
				{
					GeneralAudioComponent = UGameplayStatics::SpawnSound2D(GetWorld(), DialogueSoundOptions.SoundToPlay);
				}
			}
			// camera
			if (DialogueCameraOptions.bUseCamera)
			{
				if (!DialogueCameraOptions.CameraToView.IsNone() && !DialogueCameraOptions.PlayerCamera.IsNone() && !DialogueCinematicOptions.bPlayMatinee)
				{
					FName CameraToViewKeyName = DialogueCameraOptions.CameraToView.SelectedKeyName;
					BlackboardComp = OwnerComp.GetBlackboardComponent();
					UCameraComponent* CameraToView = Cast<UCameraComponent>(BlackboardComp->GetValueAsObject(CameraToViewKeyName));

					FName PlayerCameraKeyName = DialogueCameraOptions.PlayerCamera.SelectedKeyName;
					PlayerCamera = Cast<UCameraComponent>(BlackboardComp->GetValueAsObject(PlayerCameraKeyName));

					if (PlayerCamera && CameraToView)
					{
						SaveDefaultCameraData(PlayerCamera);
						if (PlayerCamera == CameraToView)
						{
							PlayerCamera->SetWorldLocationAndRotation(DefaultCameraLocation, DefaultCameraRotation);
						}
						else
						{
							PlayerCamera->SetWorldLocationAndRotation(CameraToView->GetComponentLocation(), CameraToView->GetComponentRotation());
						}
					}
				}
				
			}
			// cinematic
			if (DialogueCinematicOptions.bPlayMatinee && !DialogueCinematicOptions.Matinee.Equals("None"))
			{
				for (TActorIterator<AMatineeActor> It(OwnerActor->GetWorld()); It; ++It)
				{
					MatineeActor = *It;
					if (MatineeActor && MatineeActor->GetName().Equals(DialogueCinematicOptions.Matinee))
					{
						MatineeActor->bLooping = DialogueCinematicOptions.bLoop;
						MatineeActor->Play();
						break;
					}
				}
			}

			// character animation
			if (DialogueCharacterAnimationOptions.bPlayAnimation && !DialogueCharacterAnimationOptions.Mesh.IsNone() && DialogueCharacterAnimationOptions.Animation != nullptr)
			{
				FName MeshKeyName = DialogueCharacterAnimationOptions.Mesh.SelectedKeyName;
				BlackboardComp = OwnerComp.GetBlackboardComponent();
				Mesh = Cast<USkeletalMeshComponent>(BlackboardComp->GetValueAsObject(MeshKeyName));
				if (Mesh)
				{
					UAnimInstance *AnimInst = Mesh->GetAnimInstance();
					if (AnimInst)
					{
						AnimInst->PlaySlotAnimationAsDynamicMontage(DialogueCharacterAnimationOptions.Animation, 
							DialogueCharacterAnimationOptions.AnimationBlendOptions.SlotNodeName,
							DialogueCharacterAnimationOptions.AnimationBlendOptions.BlendInTime,
							DialogueCharacterAnimationOptions.AnimationBlendOptions.BlendOutTime,
							DialogueCharacterAnimationOptions.AnimationBlendOptions.InPlayRate);
					}
					if (DialogueCharacterAnimationOptions.bWaitEndOfAnimation)
					{
						UAnimSequenceBase* SequenceBase = DialogueCharacterAnimationOptions.Animation;
						CharacterAnimationDuration = SequenceBase->SequenceLength / SequenceBase->RateScale;
					}
				}
				bCharacterAnimationStarted = true;
			}
			// Event Listener

			UWidget* DialogueEventListener = WidgetTree->FindWidget(FName("DialogueEventListener"));
			if (DialogueEventListener != nullptr)
			{
				UDialogueEventListener* EventListener = Cast<UDialogueEventListener>(DialogueEventListener);
				if (EventListener)
				{
					EventListener->ShowPhrasesNode = this;
				}
			}
	
			if (bIsUserWidget)
			{
				Widget->AddToViewport();
			}
			else
			{
				WidgetComp->SetWidget(Widget);
				WidgetComp->SetVisibility(true);
			}
			PlayerController = Widget->GetOwningPlayer();
			if (InputMode == EWidggetInputMode::UIOnly)
			{
				FInputModeUIOnly InputModeUIOnly;
				InputModeUIOnly.SetWidgetToFocus(Widget->TakeWidget());
				PlayerController->SetInputMode(InputModeUIOnly);
			}
			else
			{
				FInputModeGameAndUI InputModeGameAndUI;
				InputModeGameAndUI.SetWidgetToFocus(Widget->TakeWidget());
				PlayerController->SetInputMode(InputModeGameAndUI);
			}
		}
		else
		{
			bTextFinished = true;
			NodeResult = EBTNodeResult::Failed;
		}
	}
	
	return NodeResult;
}
void UBTTask_ShowPhrases::ShowNewDialoguePhrase(bool bSkip)
{
	if (bSkip && DialogueTextOptions.TextEffect == ETextEffect::Typewriter && !bShowingFullPhrase)
	{
		FText StartPhrase = DialogueTextOptions.Phrases[ShowingNumPhrase].Phrase;
		UTextBlock* StartPhraseTextBlock = Cast<UTextBlock>(DialoguePhraseSlot);
		if (StartPhraseTextBlock)
		{
			// first show hole phrase 
			UE_LOG(LogTemp, Warning, TEXT("#1"));
			StartPhraseTextBlock->SetText(FText::Format(NSLOCTEXT("DialogueSystem", "ShowPhraseText", "{0}"), StartPhrase));
			UE_LOG(LogTemp, Warning, TEXT("#1.1"));
			OwnerActor->GetWorldTimerManager().ClearTimer(TimerHandle);
			TimerDelegate = FTimerDelegate::CreateUObject(this, &UBTTask_ShowPhrases::ShowNewDialoguePhrase, false);
			float ShowingTime = DialogueTextOptions.UseGeneralTime ? DialogueTextOptions.GeneralShowingTime : DialogueTextOptions.Phrases[ShowingNumPhrase].ShowingTime;
			OwnerActor->GetWorldTimerManager().SetTimer(TimerHandle, TimerDelegate, ShowingTime, false);
		}
		bShowingFullPhrase = true;
		return;
	}
	ShowingNumPhrase++;
	if (ShowingNumPhrase <= PhrasesCount)
	{
		bTextFinished = false;
		FText StartPhrase = DialogueTextOptions.Phrases[ShowingNumPhrase].Phrase;
		UTextBlock* StartPhraseTextBlock = Cast<UTextBlock>(DialoguePhraseSlot);

		if (DialogueTextOptions.TextEffect == ETextEffect::Typewriter && DialogueTextOptions.Delay > 0)
		{
			OwnerActor->GetWorldTimerManager().ClearTimer(TimerHandle);
			CurrentCharNum = 1; StringToDisplay = "";
			FullString = StartPhrase.ToString().GetCharArray();
			StringToDisplay.AppendChar(FullString[0]);
			if (StartPhraseTextBlock)
			{
			UE_LOG(LogTemp, Warning, TEXT("#2"));
				StartPhraseTextBlock->SetText(FText::Format(NSLOCTEXT("DialogueSystem", "ShowPhraseText", "{0}"), FText::FromString(StringToDisplay)));
			UE_LOG(LogTemp, Warning, TEXT("#2.2"));
			}
			TimerDelegate = FTimerDelegate::CreateUObject(this, &UBTTask_ShowPhrases::ShowNewChar);
			OwnerActor->GetWorldTimerManager().SetTimer(TimerHandle, TimerDelegate, DialogueTextOptions.Delay, false);
		}
		else
		{
			if (StartPhraseTextBlock)
			{
			UE_LOG(LogTemp, Warning, TEXT("#3"));
				StartPhraseTextBlock->SetText(FText::Format(NSLOCTEXT("DialogueSystem", "ShowPhraseText", "{0}"), StartPhrase));
			UE_LOG(LogTemp, Warning, TEXT("#3.3"));
			}
			float ShowingTime = DialogueTextOptions.UseGeneralTime ? DialogueTextOptions.GeneralShowingTime : DialogueTextOptions.Phrases[ShowingNumPhrase].ShowingTime;
			OwnerActor->GetWorldTimerManager().SetTimer(TimerHandle, TimerDelegate, ShowingTime, false);
		}
		//phrase sound
		if (DialogueTextOptions.Phrases[ShowingNumPhrase].SoundToPlay)
		{
			PhraseAudioComponent->Deactivate();
			PhraseAudioComponent->DestroyComponent();
			PhraseAudioComponent = UGameplayStatics::SpawnSound2D(GetWorld(), DialogueTextOptions.Phrases[ShowingNumPhrase].SoundToPlay);
		}
		bShowingFullPhrase = false;
	}
	else
	{
		if (DialogueTextOptions.bHideLastPhrase)
		{
			if (DialoguePhraseSlot != nullptr)
			{
				DialoguePhraseSlot->SetVisibility(ESlateVisibility::Hidden);
			}
			if (DialogueNameSlot != nullptr)
			{
				DialogueNameSlot->SetVisibility(ESlateVisibility::Hidden);
			}
			if (DialogueImageSlot != nullptr)
			{
				DialogueImageSlot->SetVisibility(ESlateVisibility::Hidden);
			}
			if (!bIsUserWidget)
			{
				WidgetComp->SetVisibility(false);
				WidgetComp->SetActive(false);
			}
		}
		bTextFinished = true;
		if (DialogueTextOptions.Phrases[ShowingNumPhrase-1].SoundToPlay)
		{
			PhraseAudioComponent->Deactivate();
			PhraseAudioComponent->DestroyComponent();
		}
		if (GeneralAudioComponent != NULL && DialogueSoundOptions.bPlaySound && DialogueSoundOptions.bStopInEnd)
		{
			GeneralAudioComponent->Deactivate();
			GeneralAudioComponent->DestroyComponent();
		}

		// cinematic
		if (DialogueCinematicOptions.bPlayMatinee && MatineeActor)
		{
			MatineeActor->Stop();
		}
	}
}