136 lines
4.1 KiB
C++
136 lines
4.1 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "UI/PHYAttributeGroupWidget.h"
|
|
|
|
#include UE_INLINE_GENERATED_CPP_BY_NAME(PHYAttributeGroupWidget)
|
|
|
|
#include "Blueprint/WidgetTree.h"
|
|
#include "Components/Border.h"
|
|
#include "Components/TextBlock.h"
|
|
#include "Components/VerticalBox.h"
|
|
#include "Components/VerticalBoxSlot.h"
|
|
#include "Engine/Texture2D.h"
|
|
#include "Fonts/SlateFontInfo.h"
|
|
#include "Styling/CoreStyle.h"
|
|
#include "Styling/SlateBrush.h"
|
|
#include "UI/PHYAttributeRowWidget.h"
|
|
#include "Widgets/SWidget.h"
|
|
|
|
namespace
|
|
{
|
|
const TCHAR* const AttributeGroupPaperTexturePath = TEXT("/Game/AGame/UI/Attributes/Textures/T_PHY_UI_PaperPanel.T_PHY_UI_PaperPanel");
|
|
const TCHAR* const AttributeGroupGoldRuleTexturePath = TEXT("/Game/AGame/UI/Attributes/Textures/T_PHY_UI_GoldRule.T_PHY_UI_GoldRule");
|
|
|
|
FSlateBrush MakeAttributeGroupBrush(const TCHAR* TexturePath, const FVector2D ImageSize, const FLinearColor Tint, const ESlateBrushDrawType::Type DrawAs = ESlateBrushDrawType::Box, const FMargin Margin = FMargin(0.08f))
|
|
{
|
|
FSlateBrush Brush;
|
|
Brush.DrawAs = DrawAs;
|
|
Brush.Margin = Margin;
|
|
Brush.ImageSize = ImageSize;
|
|
Brush.TintColor = FSlateColor(Tint);
|
|
if (UTexture2D* Texture = LoadObject<UTexture2D>(nullptr, TexturePath))
|
|
{
|
|
Brush.SetResourceObject(Texture);
|
|
}
|
|
return Brush;
|
|
}
|
|
}
|
|
|
|
UPHYAttributeGroupWidget::UPHYAttributeGroupWidget(const FObjectInitializer& ObjectInitializer)
|
|
: Super(ObjectInitializer)
|
|
{
|
|
}
|
|
|
|
TSharedRef<SWidget> UPHYAttributeGroupWidget::RebuildWidget()
|
|
{
|
|
BuildNativeWidgetTree();
|
|
return Super::RebuildWidget();
|
|
}
|
|
|
|
void UPHYAttributeGroupWidget::SynchronizeProperties()
|
|
{
|
|
Super::SynchronizeProperties();
|
|
UpdateGroupWidgets();
|
|
}
|
|
|
|
void UPHYAttributeGroupWidget::SetGroupTitle(FText InGroupTitle)
|
|
{
|
|
GroupTitle = MoveTemp(InGroupTitle);
|
|
UpdateGroupWidgets();
|
|
}
|
|
|
|
void UPHYAttributeGroupWidget::ClearRows()
|
|
{
|
|
if (RowsBox)
|
|
{
|
|
RowsBox->ClearChildren();
|
|
}
|
|
}
|
|
|
|
UPHYAttributeRowWidget* UPHYAttributeGroupWidget::AddRow(FText Label, FText Value, const bool bCanUpgrade)
|
|
{
|
|
BuildNativeWidgetTree();
|
|
|
|
if (!RowsBox || !WidgetTree)
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
UPHYAttributeRowWidget* RowWidget = WidgetTree->ConstructWidget<UPHYAttributeRowWidget>(UPHYAttributeRowWidget::StaticClass());
|
|
RowWidget->SetRow(MoveTemp(Label), MoveTemp(Value), bCanUpgrade);
|
|
if (UVerticalBoxSlot* RowSlot = RowsBox->AddChildToVerticalBox(RowWidget))
|
|
{
|
|
RowSlot->SetPadding(FMargin(0.0f, 2.0f));
|
|
}
|
|
return RowWidget;
|
|
}
|
|
|
|
void UPHYAttributeGroupWidget::BuildNativeWidgetTree()
|
|
{
|
|
if (!WidgetTree)
|
|
{
|
|
WidgetTree = NewObject<UWidgetTree>(this, TEXT("WidgetTree"), RF_Transient);
|
|
}
|
|
|
|
if (WidgetTree->RootWidget && TitleText && RowsBox)
|
|
{
|
|
return;
|
|
}
|
|
|
|
UBorder* RootBorder = WidgetTree->ConstructWidget<UBorder>(UBorder::StaticClass(), TEXT("RootBorder"));
|
|
RootBorder->SetBrushColor(FLinearColor::Transparent);
|
|
RootBorder->SetPadding(FMargin(14.0f, 8.0f));
|
|
WidgetTree->RootWidget = RootBorder;
|
|
|
|
UVerticalBox* RootBox = WidgetTree->ConstructWidget<UVerticalBox>(UVerticalBox::StaticClass(), TEXT("RootBox"));
|
|
RootBorder->SetContent(RootBox);
|
|
|
|
TitleText = WidgetTree->ConstructWidget<UTextBlock>(UTextBlock::StaticClass(), TEXT("TitleText"));
|
|
TitleText->SetFont(FSlateFontInfo(FCoreStyle::GetDefaultFont(), 19));
|
|
TitleText->SetColorAndOpacity(FSlateColor(FLinearColor(0.48f, 0.27f, 0.11f, 1.0f)));
|
|
if (UVerticalBoxSlot* TitleSlot = RootBox->AddChildToVerticalBox(TitleText))
|
|
{
|
|
TitleSlot->SetPadding(FMargin(2.0f, 0.0f, 0.0f, 2.0f));
|
|
}
|
|
|
|
UBorder* HeaderRule = WidgetTree->ConstructWidget<UBorder>(UBorder::StaticClass(), TEXT("HeaderRule"));
|
|
HeaderRule->SetBrush(MakeAttributeGroupBrush(AttributeGroupGoldRuleTexturePath, FVector2D(512.0f, 24.0f), FLinearColor(0.87f, 0.69f, 0.34f, 0.72f), ESlateBrushDrawType::Image, FMargin(0.0f)));
|
|
if (UVerticalBoxSlot* RuleSlot = RootBox->AddChildToVerticalBox(HeaderRule))
|
|
{
|
|
RuleSlot->SetPadding(FMargin(0.0f, 0.0f, 0.0f, 8.0f));
|
|
}
|
|
|
|
RowsBox = WidgetTree->ConstructWidget<UVerticalBox>(UVerticalBox::StaticClass(), TEXT("RowsBox"));
|
|
RootBox->AddChildToVerticalBox(RowsBox);
|
|
|
|
UpdateGroupWidgets();
|
|
}
|
|
|
|
void UPHYAttributeGroupWidget::UpdateGroupWidgets()
|
|
{
|
|
if (TitleText)
|
|
{
|
|
TitleText->SetText(GroupTitle);
|
|
}
|
|
}
|