diff --git a/Content/BP_ButtonDecorator.uasset b/Content/BP_ButtonDecorator.uasset new file mode 100644 index 0000000..540cf6e Binary files /dev/null and b/Content/BP_ButtonDecorator.uasset differ diff --git a/Content/BP_ImageDecoratorToAdd.uasset b/Content/BP_ImageDecoratorToAdd.uasset new file mode 100644 index 0000000..29ab891 Binary files /dev/null and b/Content/BP_ImageDecoratorToAdd.uasset differ diff --git a/Content/BP_SampleRichTextBlockTooltipDecorator.uasset b/Content/BP_SampleRichTextBlockTooltipDecorator.uasset index fef8c49..a6f6743 100644 Binary files a/Content/BP_SampleRichTextBlockTooltipDecorator.uasset and b/Content/BP_SampleRichTextBlockTooltipDecorator.uasset differ diff --git a/Content/DT_RIchTextImageTest.uasset b/Content/DT_RIchTextImageTest.uasset new file mode 100644 index 0000000..151dd1e Binary files /dev/null and b/Content/DT_RIchTextImageTest.uasset differ diff --git a/Content/DT_RichTextButtons.uasset b/Content/DT_RichTextButtons.uasset new file mode 100644 index 0000000..24435c6 Binary files /dev/null and b/Content/DT_RichTextButtons.uasset differ diff --git a/Content/DT_SampleTextStyleSet.uasset b/Content/DT_SampleTextStyleSet.uasset index 1fafd9d..880b08f 100644 Binary files a/Content/DT_SampleTextStyleSet.uasset and b/Content/DT_SampleTextStyleSet.uasset differ diff --git a/Content/M_ImageTest.uasset b/Content/M_ImageTest.uasset new file mode 100644 index 0000000..7c3b040 Binary files /dev/null and b/Content/M_ImageTest.uasset differ diff --git a/Content/Maps/SampleMap.umap b/Content/Maps/SampleMap.umap index 99bf9df..c873d5d 100644 Binary files a/Content/Maps/SampleMap.umap and b/Content/Maps/SampleMap.umap differ diff --git a/Content/WBP_SampleHUD.uasset b/Content/WBP_SampleHUD.uasset index 6c73a12..4857370 100644 Binary files a/Content/WBP_SampleHUD.uasset and b/Content/WBP_SampleHUD.uasset differ diff --git a/Content/W_TooltipTest.uasset b/Content/W_TooltipTest.uasset new file mode 100644 index 0000000..5728acb Binary files /dev/null and b/Content/W_TooltipTest.uasset differ diff --git a/Source/Sample/RichTextBlockButtonDecorator.cpp b/Source/Sample/RichTextBlockButtonDecorator.cpp new file mode 100644 index 0000000..6434724 --- /dev/null +++ b/Source/Sample/RichTextBlockButtonDecorator.cpp @@ -0,0 +1,87 @@ + +#include "RichTextBlockButtonDecorator.h" +#include "Widgets/SToolTip.h" +#include "Widgets/Text/STextBlock.h" +#include "Widgets/Input/SButton.h" + +///////////////////////////////////////////////////// + +class FRichInlineButton : public FRichTextDecorator +{ +public: + FRichInlineButton(URichTextBlock* InOwner, URichTextBlockButtonDecorator* InDecorator) + : FRichTextDecorator(InOwner) + , Decorator(InDecorator) + { + } + + // Only valid if text is: Some text + virtual bool Supports(const FTextRunParseResults& RunParseResult, const FString& Text) const override + { + if (RunParseResult.Name == TEXT("button") && RunParseResult.MetaData.Contains(TEXT("id"))) + { + const FTextRange& IdRange = RunParseResult.MetaData[TEXT("id")]; + const FString TagId = Text.Mid(IdRange.BeginIndex, IdRange.EndIndex - IdRange.BeginIndex); + + const bool bWarnIfMissing = false; + return Decorator->FindButtonSet(*TagId, bWarnIfMissing) != nullptr; + } + + return false; + } + +protected: + + virtual TSharedPtr CreateDecoratorWidget(const FTextRunInfo& InRunInfo, const FTextBlockStyle& InTextStyle) const override + { + const bool bWarnIfMissing = true; + const FRichButtonRow* ButtonSet = Decorator->FindButtonSet(*InRunInfo.MetaData[TEXT("id")], bWarnIfMissing); + + if (!ensure(ButtonSet)) + return TSharedPtr(); + + FString TextString; + if (const FString* Text = InRunInfo.MetaData.Find(TEXT("text"))) + TextString = *Text; + + return SNew(SButton) + .ButtonStyle(&ButtonSet->ButtonStyle) + //.ForegroundColor(FLinearColor::White) + //.OnClicked(this, &FPaperTileMapDetailsCustomization::OnPromoteToAssetButtonClicked) + .Content() + [ + SNew(STextBlock) + .TextStyle(&ButtonSet->ButtonTextStyle) + .Text(FText::FromString(TextString)) + ]; + } + +private: + URichTextBlockButtonDecorator* Decorator; +}; + +///////////////////////////////////////////////////// +// URichTextBlockButtonDecorator + +URichTextBlockButtonDecorator::URichTextBlockButtonDecorator(const FObjectInitializer& ObjectInitializer) + : Super(ObjectInitializer) +{ +} + +// Return our custom class for creating the inline widget +TSharedPtr URichTextBlockButtonDecorator::CreateDecorator(URichTextBlock* InOwner) +{ + return MakeShareable(new FRichInlineButton(InOwner, this)); +} + +// find button set +FRichButtonRow* URichTextBlockButtonDecorator::FindButtonSet(FName TagOrId, bool bWarnIfMissing) +{ + if (ButtonSet == nullptr) + return nullptr; + + FString ContextString; + return ButtonSet->FindRow(TagOrId, ContextString, bWarnIfMissing); +} + +///////////////////////////////////////////////////// diff --git a/Source/Sample/RichTextBlockButtonDecorator.h b/Source/Sample/RichTextBlockButtonDecorator.h new file mode 100644 index 0000000..ae2b902 --- /dev/null +++ b/Source/Sample/RichTextBlockButtonDecorator.h @@ -0,0 +1,59 @@ +#pragma once + +#include "CoreMinimal.h" + +#include "Engine/DataTable.h" + +#include "Styling/SlateTypes.h" +#include "Fonts/SlateFontInfo.h" + +#include "Framework/Text/ITextDecorator.h" +#include "Components/RichTextBlockDecorator.h" + +#include "RichTextBlockButtonDecorator.generated.h" + +/** Simple struct for rich text styles */ +USTRUCT(Blueprintable, BlueprintType) +struct FRichButtonRow : public FTableRowBase +{ + GENERATED_USTRUCT_BODY() + +public: + + // button style + UPROPERTY(EditAnywhere, Category = Appearance) + FButtonStyle ButtonStyle; + + //UPROPERTY(EditAnywhere, Category = Appearance) + //FSlateColor ButtonForegroundColor; + + // Style used for button's text + UPROPERTY(EditAnywhere, Category = Appearance) + FTextBlockStyle ButtonTextStyle; +}; + +/** + * Allows you to setup a button decorator. + * This can be subclassed as a blueprint. + * + * Understands the format