123 lines
3.5 KiB
C++
123 lines
3.5 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "UI/PHYAttributePageWidget.h"
|
|
|
|
#include UE_INLINE_GENERATED_CPP_BY_NAME(PHYAttributePageWidget)
|
|
|
|
#include "Blueprint/WidgetTree.h"
|
|
#include "Components/Border.h"
|
|
#include "Components/ScrollBox.h"
|
|
#include "Components/ScrollBoxSlot.h"
|
|
#include "Components/TextBlock.h"
|
|
#include "Components/UniformGridPanel.h"
|
|
#include "Components/UniformGridSlot.h"
|
|
#include "Components/VerticalBox.h"
|
|
#include "Components/VerticalBoxSlot.h"
|
|
#include "Fonts/SlateFontInfo.h"
|
|
#include "Styling/CoreStyle.h"
|
|
#include "UI/PHYAttributeGroupWidget.h"
|
|
#include "Widgets/SWidget.h"
|
|
|
|
UPHYAttributePageWidget::UPHYAttributePageWidget(const FObjectInitializer& ObjectInitializer)
|
|
: Super(ObjectInitializer)
|
|
{
|
|
}
|
|
|
|
TSharedRef<SWidget> UPHYAttributePageWidget::RebuildWidget()
|
|
{
|
|
BuildNativeWidgetTree();
|
|
return Super::RebuildWidget();
|
|
}
|
|
|
|
void UPHYAttributePageWidget::SynchronizeProperties()
|
|
{
|
|
Super::SynchronizeProperties();
|
|
UpdatePageWidgets();
|
|
}
|
|
|
|
void UPHYAttributePageWidget::SetPageTitle(FText InPageTitle)
|
|
{
|
|
PageTitle = MoveTemp(InPageTitle);
|
|
UpdatePageWidgets();
|
|
}
|
|
|
|
void UPHYAttributePageWidget::ClearGroups()
|
|
{
|
|
GroupCount = 0;
|
|
if (GroupsGrid)
|
|
{
|
|
GroupsGrid->ClearChildren();
|
|
}
|
|
}
|
|
|
|
UPHYAttributeGroupWidget* UPHYAttributePageWidget::AddGroup(FText GroupTitle)
|
|
{
|
|
BuildNativeWidgetTree();
|
|
|
|
if (!GroupsGrid || !WidgetTree)
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
UPHYAttributeGroupWidget* GroupWidget = WidgetTree->ConstructWidget<UPHYAttributeGroupWidget>(UPHYAttributeGroupWidget::StaticClass());
|
|
GroupWidget->SetGroupTitle(MoveTemp(GroupTitle));
|
|
UBorder* GroupPadding = WidgetTree->ConstructWidget<UBorder>(UBorder::StaticClass());
|
|
GroupPadding->SetBrushColor(FLinearColor(1.0f, 1.0f, 1.0f, 0.0f));
|
|
GroupPadding->SetPadding(FMargin(0.0f, 0.0f, 14.0f, 14.0f));
|
|
GroupPadding->SetContent(GroupWidget);
|
|
const int32 GroupIndex = GroupCount++;
|
|
if (UUniformGridSlot* GroupSlot = GroupsGrid->AddChildToUniformGrid(GroupPadding, GroupIndex / 2, GroupIndex % 2))
|
|
{
|
|
GroupSlot->SetHorizontalAlignment(HAlign_Fill);
|
|
GroupSlot->SetVerticalAlignment(VAlign_Top);
|
|
}
|
|
return GroupWidget;
|
|
}
|
|
|
|
void UPHYAttributePageWidget::BuildNativeWidgetTree()
|
|
{
|
|
if (!WidgetTree)
|
|
{
|
|
WidgetTree = NewObject<UWidgetTree>(this, TEXT("WidgetTree"), RF_Transient);
|
|
}
|
|
|
|
if (WidgetTree->RootWidget && TitleText && GroupsScrollBox && GroupsGrid)
|
|
{
|
|
return;
|
|
}
|
|
|
|
UVerticalBox* RootBox = WidgetTree->ConstructWidget<UVerticalBox>(UVerticalBox::StaticClass(), TEXT("RootBox"));
|
|
WidgetTree->RootWidget = RootBox;
|
|
|
|
TitleText = WidgetTree->ConstructWidget<UTextBlock>(UTextBlock::StaticClass(), TEXT("TitleText"));
|
|
TitleText->SetFont(FSlateFontInfo(FCoreStyle::GetDefaultFont(), 12));
|
|
TitleText->SetColorAndOpacity(FSlateColor(FLinearColor(0.42f, 0.18f, 0.08f, 0.0f)));
|
|
TitleText->SetVisibility(ESlateVisibility::Collapsed);
|
|
if (UVerticalBoxSlot* TitleSlot = RootBox->AddChildToVerticalBox(TitleText))
|
|
{
|
|
TitleSlot->SetPadding(FMargin(0.0f));
|
|
}
|
|
|
|
GroupsScrollBox = WidgetTree->ConstructWidget<UScrollBox>(UScrollBox::StaticClass(), TEXT("GroupsScrollBox"));
|
|
if (UVerticalBoxSlot* ScrollSlot = RootBox->AddChildToVerticalBox(GroupsScrollBox))
|
|
{
|
|
ScrollSlot->SetSize(FSlateChildSize(ESlateSizeRule::Fill));
|
|
}
|
|
|
|
GroupsGrid = WidgetTree->ConstructWidget<UUniformGridPanel>(UUniformGridPanel::StaticClass(), TEXT("GroupsGrid"));
|
|
if (UScrollBoxSlot* GroupsSlot = Cast<UScrollBoxSlot>(GroupsScrollBox->AddChild(GroupsGrid)))
|
|
{
|
|
GroupsSlot->SetPadding(FMargin(0.0f));
|
|
}
|
|
|
|
UpdatePageWidgets();
|
|
}
|
|
|
|
void UPHYAttributePageWidget::UpdatePageWidgets()
|
|
{
|
|
if (TitleText)
|
|
{
|
|
TitleText->SetText(PageTitle);
|
|
}
|
|
}
|