Merge branch 'master' into line-splitting

This commit is contained in:
Jonas Bötel 2023-04-20 15:03:55 +08:00 committed by GitHub
commit e4ec937f1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 6 deletions

View File

@ -116,8 +116,24 @@ void UTypewriterTextWidget::PlayNextLinePart(float Speed)
bHasMoreLineParts = false;
bHasFinishedPlaying = false;
LineText->SetText(FText());
if (bFirstPlayLine)
{
// Delay the very first PlayLine after construction, CalculateWrappedString is not reliable until a couple
// of UI geometry updates. At first the geometry is 0, then it's just wrong, and then finally it settles.
FTimerHandle TempHandle;
FTimerDelegate DelayDelegate;
DelayDelegate.BindUObject(this, &ThisClass::StartPlayLine);
TimerManager.SetTimer(TempHandle, DelayDelegate, 0.2f, false);
}
else
{
StartPlayLine();
}
}
}
void UTypewriterTextWidget::StartPlayLine()
{
CalculateWrappedString(RemainingLinePart);
if (NumberOfLines > MaxNumberOfLines)
@ -136,10 +152,15 @@ void UTypewriterTextWidget::PlayNextLinePart(float Speed)
FTimerDelegate Delegate;
Delegate.BindUObject(this, &ThisClass::PlayNextLetter);
FTimerManager& TimerManager = GetWorld()->GetTimerManager();
TimerManager.SetTimer(LetterTimer, Delegate, LetterPlayTime/CurrentPlaySpeed, true);
SetVisibility(ESlateVisibility::SelfHitTestInvisible);
}
bFirstPlayLine = false;
PlayNextLetter();
}
void UTypewriterTextWidget::SkipToLineEnd()
@ -158,6 +179,13 @@ void UTypewriterTextWidget::SkipToLineEnd()
OnLineFinishedPlaying();
}
void UTypewriterTextWidget::NativeConstruct()
{
Super::NativeConstruct();
bFirstPlayLine = true;
}
void UTypewriterTextWidget::PlayNextLetter()
{
// Incorporate pauses as a multiple of play timer (may not be exact but close enough)

View File

@ -119,6 +119,8 @@ public:
const FString& GetCurrentRunName() const { return CurrentRunName; }
protected:
virtual void NativeConstruct() override;
/// Called when on or more letters are added, if subclasses want to override
UFUNCTION(BlueprintImplementableEvent, Category = "Typewriter")
void OnPlayLetter();
@ -141,6 +143,7 @@ private:
int CalculateMaxLength();
void CalculateWrappedString(const FString& CurrentLineString);
FString CalculateSegments(FString* OutCurrentRunName);
void StartPlayLine();
UPROPERTY()
FText CurrentLine;
@ -173,4 +176,5 @@ private:
FTimerHandle LetterTimer;
float CurrentPlaySpeed = 1;
float PauseTime = 0;
bool bFirstPlayLine = true;
};