107 lines
2.9 KiB
C++
107 lines
2.9 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 "Fonts/SlateFontInfo.h"
|
|
#include "Styling/CoreStyle.h"
|
|
#include "UI/PHYAttributeRowWidget.h"
|
|
#include "Widgets/SWidget.h"
|
|
|
|
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, 1.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(0.98f, 0.94f, 0.84f, 0.58f));
|
|
RootBorder->SetPadding(FMargin(14.0f, 10.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(), 17));
|
|
TitleText->SetColorAndOpacity(FSlateColor(FLinearColor(0.56f, 0.18f, 0.10f, 1.0f)));
|
|
if (UVerticalBoxSlot* TitleSlot = RootBox->AddChildToVerticalBox(TitleText))
|
|
{
|
|
TitleSlot->SetPadding(FMargin(0.0f, 0.0f, 0.0f, 6.0f));
|
|
}
|
|
|
|
RowsBox = WidgetTree->ConstructWidget<UVerticalBox>(UVerticalBox::StaticClass(), TEXT("RowsBox"));
|
|
RootBox->AddChildToVerticalBox(RowsBox);
|
|
|
|
UpdateGroupWidgets();
|
|
}
|
|
|
|
void UPHYAttributeGroupWidget::UpdateGroupWidgets()
|
|
{
|
|
if (TitleText)
|
|
{
|
|
TitleText->SetText(GroupTitle);
|
|
}
|
|
}
|