diff --git a/DialogueBox.cpp b/DialogueBox.cpp index 493fde9..e2f055f 100644 --- a/DialogueBox.cpp +++ b/DialogueBox.cpp @@ -18,7 +18,7 @@ TSharedRef UDialogueTextBlock::RebuildWidget() MyRichTextBlock = SNew(SRichTextBlock) - .TextStyle(bOverrideDefaultStyle ? &DefaultTextStyleOverride : &DefaultTextStyle) + .TextStyle(&GetCurrentDefaultTextStyle()) .Marshaller(TextMarshaller) .CreateSlateTextLayout( FCreateSlateTextLayout::CreateWeakLambda(this, [this] (SWidget* InOwner, const FTextBlockStyle& InDefaultTextStyle) mutable @@ -75,7 +75,7 @@ void UDialogueBox::PlayLine(const FText& InLine) FTimerDelegate Delegate; Delegate.BindUObject(this, &ThisClass::PlayNextLetter); - TimerManager.SetTimer(LetterTimer, Delegate, LetterPlayTime, true); + TimerManager.SetTimer(LetterTimer, Delegate, LetterPlayTime, false); SetVisibility(ESlateVisibility::SelfHitTestInvisible); } @@ -115,6 +115,19 @@ void UDialogueBox::PlayNextLetter() OnPlayLetter(); ++CurrentLetterIndex; + + if (EndsWithPunctuation(WrappedString)) + { + FTimerDelegate Delegate; + Delegate.BindUObject(this, &ThisClass::PlayNextLetter); + GetWorld()->GetTimerManager().SetTimer(LetterTimer, Delegate, PunctuationPauseTime, false); + } + else + { + FTimerDelegate Delegate; + Delegate.BindUObject(this, &ThisClass::PlayNextLetter); + GetWorld()->GetTimerManager().SetTimer(LetterTimer, Delegate, LetterPlayTime, false); + } } else { @@ -258,4 +271,13 @@ FString UDialogueBox::CalculateSegments() } return Result; -} \ No newline at end of file +} + +bool UDialogueBox::EndsWithPunctuation(const FString& s) +{ + return s.Len() > 2 && + (s.Right(2) == TEXT(". ") || + s.Right(2) == TEXT(", ") || + s.Right(2) == TEXT("! ") || + s.Right(2) == TEXT("? ")); +} diff --git a/DialogueBox.h b/DialogueBox.h index 7597a1a..e4f9e07 100644 --- a/DialogueBox.h +++ b/DialogueBox.h @@ -57,6 +57,9 @@ class FLAME_API UDialogueBox : public UUserWidget UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue Box") float LetterPlayTime = 0.025f; + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue Box") + float PunctuationPauseTime = 0.4f; + // The amount of time to wait after finishing the line before actually marking it completed. // This helps prevent accidentally progressing dialogue on short lines. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue Box") @@ -86,6 +89,7 @@ class FLAME_API UDialogueBox : public UUserWidget void CalculateWrappedString(); FString CalculateSegments(); + bool EndsWithPunctuation(const FString& s); UPROPERTY() FText CurrentLine;