Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions DialogueBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TSharedRef<SWidget> UDialogueTextBlock::RebuildWidget()

MyRichTextBlock =
SNew(SRichTextBlock)
.TextStyle(bOverrideDefaultStyle ? &DefaultTextStyleOverride : &DefaultTextStyle)
.TextStyle(&GetCurrentDefaultTextStyle())
.Marshaller(TextMarshaller)
.CreateSlateTextLayout(
FCreateSlateTextLayout::CreateWeakLambda(this, [this] (SWidget* InOwner, const FTextBlockStyle& InDefaultTextStyle) mutable
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -258,4 +271,13 @@ FString UDialogueBox::CalculateSegments()
}

return Result;
}
}

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("? "));
}
4 changes: 4 additions & 0 deletions DialogueBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -86,6 +89,7 @@ class FLAME_API UDialogueBox : public UUserWidget

void CalculateWrappedString();
FString CalculateSegments();
bool EndsWithPunctuation(const FString& s);

UPROPERTY()
FText CurrentLine;
Expand Down