mirror of
https://github.com/sinbad/StevesUEHelpers.git
synced 2025-02-23 17:45:23 +00:00
Add access to run name and delegate for letter added
Also tidy up some duplicated code
This commit is contained in:
parent
cb8a830d54
commit
068810dc61
@ -76,6 +76,7 @@ void UTypewriterTextWidget::PlayLine(const FText& InLine, float Speed)
|
|||||||
TimerManager.ClearTimer(LetterTimer);
|
TimerManager.ClearTimer(LetterTimer);
|
||||||
|
|
||||||
CurrentLine = InLine;
|
CurrentLine = InLine;
|
||||||
|
CurrentRunName = "";
|
||||||
CurrentLetterIndex = 0;
|
CurrentLetterIndex = 0;
|
||||||
CachedLetterIndex = 0;
|
CachedLetterIndex = 0;
|
||||||
CurrentSegmentIndex = 0;
|
CurrentSegmentIndex = 0;
|
||||||
@ -128,7 +129,7 @@ void UTypewriterTextWidget::SkipToLineEnd()
|
|||||||
CurrentLetterIndex = MaxLetterIndex - 1;
|
CurrentLetterIndex = MaxLetterIndex - 1;
|
||||||
if (IsValid(LineText))
|
if (IsValid(LineText))
|
||||||
{
|
{
|
||||||
LineText->SetText(FText::FromString(CalculateSegments()));
|
LineText->SetText(FText::FromString(CalculateSegments(nullptr)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bHasFinishedPlaying = true;
|
bHasFinishedPlaying = true;
|
||||||
@ -146,26 +147,21 @@ void UTypewriterTextWidget::PlayNextLetter()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FString WrappedString = CalculateSegments();
|
FString WrappedString = CalculateSegments(&CurrentRunName);
|
||||||
|
if (IsValid(LineText))
|
||||||
|
{
|
||||||
|
LineText->SetText(FText::FromString(WrappedString));
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: How do we keep indexing of text i18n-friendly?
|
// TODO: How do we keep indexing of text i18n-friendly?
|
||||||
if (CurrentLetterIndex < MaxLetterIndex)
|
if (CurrentLetterIndex < MaxLetterIndex)
|
||||||
{
|
{
|
||||||
if (IsValid(LineText))
|
|
||||||
{
|
|
||||||
LineText->SetText(FText::FromString(WrappedString));
|
|
||||||
}
|
|
||||||
|
|
||||||
OnPlayLetter();
|
OnPlayLetter();
|
||||||
|
OnTypewriterLetterAdded.Broadcast(this);
|
||||||
++CurrentLetterIndex;
|
++CurrentLetterIndex;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (IsValid(LineText))
|
|
||||||
{
|
|
||||||
LineText->SetText(FText::FromString(CalculateSegments()));
|
|
||||||
}
|
|
||||||
|
|
||||||
FTimerManager& TimerManager = GetWorld()->GetTimerManager();
|
FTimerManager& TimerManager = GetWorld()->GetTimerManager();
|
||||||
TimerManager.ClearTimer(LetterTimer);
|
TimerManager.ClearTimer(LetterTimer);
|
||||||
|
|
||||||
@ -272,7 +268,7 @@ void UTypewriterTextWidget::CalculateWrappedString()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FString UTypewriterTextWidget::CalculateSegments()
|
FString UTypewriterTextWidget::CalculateSegments(FString* OutCurrentRunName)
|
||||||
{
|
{
|
||||||
FString Result = CachedSegmentText;
|
FString Result = CachedSegmentText;
|
||||||
|
|
||||||
@ -341,6 +337,18 @@ FString UTypewriterTextWidget::CalculateSegments()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (OutCurrentRunName)
|
||||||
|
{
|
||||||
|
if (CurrentSegmentIndex < Segments.Num())
|
||||||
|
{
|
||||||
|
*OutCurrentRunName = Segments[CurrentSegmentIndex].RunInfo.Name;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*OutCurrentRunName = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
|
|
||||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnTypewriterLineFinished, class UTypewriterTextWidget*, Widget);
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnTypewriterLineFinished, class UTypewriterTextWidget*, Widget);
|
||||||
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnTypewriterLetterAdded, class UTypewriterTextWidget*, Widget);
|
||||||
/**
|
/**
|
||||||
* A text block that exposes more information about text layout for typewriter widget.
|
* A text block that exposes more information about text layout for typewriter widget.
|
||||||
*/
|
*/
|
||||||
@ -58,6 +59,10 @@ public:
|
|||||||
UPROPERTY(BlueprintAssignable)
|
UPROPERTY(BlueprintAssignable)
|
||||||
FOnTypewriterLineFinished OnTypewriterLineFinished;
|
FOnTypewriterLineFinished OnTypewriterLineFinished;
|
||||||
|
|
||||||
|
/// Event called when one or more new letters have been displayed
|
||||||
|
UPROPERTY(BlueprintAssignable)
|
||||||
|
FOnTypewriterLetterAdded OnTypewriterLetterAdded;
|
||||||
|
|
||||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||||
URichTextBlockForTypewriter* LineText;
|
URichTextBlockForTypewriter* LineText;
|
||||||
|
|
||||||
@ -95,23 +100,35 @@ public:
|
|||||||
UFUNCTION(BlueprintCallable, Category = "Typewriter")
|
UFUNCTION(BlueprintCallable, Category = "Typewriter")
|
||||||
void SkipToLineEnd();
|
void SkipToLineEnd();
|
||||||
|
|
||||||
|
/// Get the name of the current rich text run, if any
|
||||||
|
const FString& GetCurrentRunName() const { return CurrentRunName; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/// Called when on or more letters are added, if subclasses want to override
|
||||||
UFUNCTION(BlueprintImplementableEvent, Category = "Typewriter")
|
UFUNCTION(BlueprintImplementableEvent, Category = "Typewriter")
|
||||||
void OnPlayLetter();
|
void OnPlayLetter();
|
||||||
|
|
||||||
UFUNCTION(BlueprintImplementableEvent, Category = "Typewriter")
|
UFUNCTION(BlueprintImplementableEvent, Category = "Typewriter")
|
||||||
void OnLineFinishedPlaying();
|
void OnLineFinishedPlaying();
|
||||||
|
|
||||||
|
/// Name of the current rich text run, if any
|
||||||
|
/// Can be used to identify the style of the most recently played letter
|
||||||
|
UPROPERTY(BlueprintReadOnly, Category = "Typewriter")
|
||||||
|
FString CurrentRunName;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void PlayNextLetter();
|
void PlayNextLetter();
|
||||||
static bool IsSentenceTerminator(TCHAR Letter);
|
static bool IsSentenceTerminator(TCHAR Letter);
|
||||||
|
|
||||||
void CalculateWrappedString();
|
void CalculateWrappedString();
|
||||||
FString CalculateSegments();
|
FString CalculateSegments(FString* OutCurrentRunName);
|
||||||
|
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
FText CurrentLine;
|
FText CurrentLine;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct FTypewriterTextSegment
|
struct FTypewriterTextSegment
|
||||||
{
|
{
|
||||||
FString Text;
|
FString Text;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user