Add event for when the run name changes

This commit is contained in:
Steve Streeting 2023-01-09 13:10:48 +00:00
parent 068810dc61
commit 9aad397561
2 changed files with 12 additions and 1 deletions

View File

@ -147,12 +147,19 @@ void UTypewriterTextWidget::PlayNextLetter()
return; return;
} }
FString WrappedString = CalculateSegments(&CurrentRunName); FString NewRunName;
const FString WrappedString = CalculateSegments(&NewRunName);
if (IsValid(LineText)) if (IsValid(LineText))
{ {
LineText->SetText(FText::FromString(WrappedString)); LineText->SetText(FText::FromString(WrappedString));
} }
if (NewRunName != CurrentRunName)
{
CurrentRunName = NewRunName;
OnTypewriterRunNameChanged.Broadcast(this, NewRunName);
}
// 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)
{ {

View File

@ -18,6 +18,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); DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnTypewriterLetterAdded, class UTypewriterTextWidget*, Widget);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnTypewriterRunNameChanged, class UTypewriterTextWidget*, Widget, const FString&, NewRunName);
/** /**
* 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.
*/ */
@ -62,6 +63,9 @@ public:
/// Event called when one or more new letters have been displayed /// Event called when one or more new letters have been displayed
UPROPERTY(BlueprintAssignable) UPROPERTY(BlueprintAssignable)
FOnTypewriterLetterAdded OnTypewriterLetterAdded; FOnTypewriterLetterAdded OnTypewriterLetterAdded;
/// Event called when the "run name" of the text changes aka the rich text style markup. Also called when reverts to default.
FOnTypewriterRunNameChanged OnTypewriterRunNameChanged;
UPROPERTY(BlueprintReadOnly, meta = (BindWidget)) UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
URichTextBlockForTypewriter* LineText; URichTextBlockForTypewriter* LineText;