Files
LuckyWorld/Source/LuckyWorldV2/Private/UI/Settings/AllRandomUserWidget.cpp

64 lines
1.6 KiB
C++
Raw Normal View History

2025-04-14 19:36:02 +08:00
// Fill out your copyright notice in the Description page of Project Settings.
#include "UI/Settings/AllRandomUserWidget.h"
2025-04-17 23:30:37 +08:00
#include "Subsystem/UISubsystem.h"
#include "Components/WrapBox.h"
#include "Core/LuckyRobotsGameInstance.h"
#include "UI/Settings/ObjectsListUserWidget.h"
2025-04-14 19:36:02 +08:00
2025-04-17 23:30:37 +08:00
void UAllRandomUserWidget::NativeConstruct()
{
Super::NativeConstruct();
SetVisibility(ESlateVisibility::Hidden);
auto UISubsystem = GetGameInstance()->GetSubsystem<UUISubsystem>();
if (UISubsystem)
{
UISubsystem->OnAllRandomMenuStateChanged.AddDynamic(this, &UAllRandomUserWidget::DoAllRandomMenuStateChanged);
}
DoUpdateItemList(EItemCategory::Furniture);
}
void UAllRandomUserWidget::DoAllRandomMenuStateChanged(bool open)
{
if (open)
{
DoOpen();
SetVisibility(ESlateVisibility::Visible);
}
else
{
SetVisibility(ESlateVisibility::Hidden);
}
}
void UAllRandomUserWidget::DoUpdateItemList(EItemCategory ItemCategory)
{
if (GetWrapBox() && ObjectsListUserWidgetClass)
{
GetWrapBox()->ClearChildren();
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
if (GameInstance)
{
TArray<FSelectableItemData> SelectableItemList = GameInstance->GetSelectableItemList(ItemCategory);
for (auto SelectableItem : SelectableItemList)
{
UObjectsListUserWidget* ObjectsListUserWidget = CreateWidget<UObjectsListUserWidget>(this, ObjectsListUserWidgetClass);
if (ObjectsListUserWidget)
{
ObjectsListUserWidget->SelectableItemData = SelectableItem;
GetWrapBox()->AddChild(ObjectsListUserWidget);
}
}
}
}
}
void UAllRandomUserWidget::DoOpen()
{
DoUpdateItemList(EItemCategory::Furniture);
}