A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
ButtonListWidget.cpp
Go to the documentation of this file.
1// Copyright(c) Pixo Group. All Rights Reserved.
2
4
5#include "Components/VerticalBoxSlot.h"
6#include "UI/ButtonWidget.h"
8
10{
11 Super::NativeOnInitialized();
12
13 ensure(VerticalBoxButtons);
14 ensure(ConfirmButton);
15
17}
18
20{
21 Super::Init(WidgetInfo);
22
23 if (const UButtonsListWidgetInfo* ButtonListWidgetInfo = Cast<UButtonsListWidgetInfo, UBasicWidgetInfo>(WidgetInfo))
24 {
25 SpawnButtons(ButtonListWidgetInfo->DTButtonsList);
26
27 ConfirmButton->SetVisibility(ButtonListWidgetInfo->bConfirmButton ? ESlateVisibility::Visible : ESlateVisibility::Collapsed);
28 ConfirmButton->SetButtonName(FText::FromString(ButtonListWidgetInfo->ConfirmButtonLabel));
29
30 bConfirmSelection = ButtonListWidgetInfo->bConfirmSelection;
31 }
32}
33
35{
37 {
39 UMultipleSelectionResponseData* ResponseData = NewObject<UMultipleSelectionResponseData>();
40 ResponseData->SetNeedConfirmation(true);
41 OnConfirmEventDelegate.ExecuteIfBound(ResponseData);
42 }
43 else
44 {
45 UMultipleSelectionResponseData* ResponseData = NewObject<UMultipleSelectionResponseData>();
46 ResponseData->SetNeedConfirmation(false);
47 ResponseData->SelectedButtons = SelectedButtonsLabels.Array();
48 OnConfirmEventDelegate.ExecuteIfBound(ResponseData);
49 }
50}
51
53{
54 UE_LOG(LogTemp, Warning, TEXT("Select Button"));
55
56 for (auto Button : ButtonsArray)
57 {
58 if (!Button->GetButtonName().EqualTo(SelectedButtonName))
59 {
60 if (Button->GetType() == ButtonType::BT_None)
61 {
62 Button->ChangeButtonState(false);
63
64 SelectedButtonsLabels.Remove(Button->GetButtonName().ToString());
65 }
66 }
67 else
68 {
69 if (Button->GetState())
70 {
71 SelectedButtonsLabels.Add(SelectedButtonName.ToString());
72 }
73 else
74 {
75 SelectedButtonsLabels.Remove(SelectedButtonName.ToString());
76 }
77 }
78 }
79}
80
81void UButtonListWidget::SpawnButtons(const UDataTable* DTButtonsList)
82{
83 if (DTButtonsList)
84 {
85 TArray<FButtonInfo*> ButtonsInfo;
86 DTButtonsList->GetAllRows<FButtonInfo>(TEXT("[UAOCManager::Initialize_Implementation()] Expected RowStruct for this DT : FAOCProbability"), ButtonsInfo);
87 for (auto ButtonInfo : ButtonsInfo)
88 {
89 SpawnButtonInstance(ButtonInfo->ButtonName, ButtonInfo->CheckButton);
90 }
91 }
92}
93
94void UButtonListWidget::SpawnButtonInstance(FText ButtonName, bool CheckButton)
95{
96 UButtonWidget* Button = CheckButton ? CreateWidget<UCheckButtonWidget>(this, CheckButtonWidgetClass) : CreateWidget<UButtonWidget>(this, ButtonWidgetClass);
97 if (Button)
98 {
99 Button->SetButtonName(ButtonName);
100 ButtonsArray.Add(Button);
101 Button->OnClickEventDelegate.AddUniqueDynamic(this, &UButtonListWidget::SelectButtonEvent);
102
103 UVerticalBoxSlot* ButtonSlot = VerticalBoxButtons->AddChildToVerticalBox(Button);
104 ButtonSlot->SetPadding(ButtonPadding);
105 ButtonSlot->VerticalAlignment = EVerticalAlignment::VAlign_Fill;
106 ButtonSlot->HorizontalAlignment = EHorizontalAlignment::HAlign_Fill;
107 }
108}
void SetNeedConfirmation(bool Value)
Definition UIData.h:35
UDataAsset class representing basic widget information.
Definition UIData.h:56
virtual void SelectButtonEvent(FText SelectedButtonName)
Selects a button by its name and deselects other buttons.
bool bConfirmSelection
Should we check for any selected option before accept confirmation.
TSet< FString > SelectedButtonsLabels
virtual void OnClickConfirmEvent(FText ButtonName)
Event called when the confirm button is clicked.
TArray< UButtonWidget * > ButtonsArray
Holds all buttons which were spawned from Data Table.
virtual void SpawnButtonInstance(FText ButtonName, bool Checked)
Spawns an instance of a button with the specified name.
virtual void NativeOnInitialized() override
FConfirmEventDelegate OnConfirmEventDelegate
UVerticalBox * VerticalBoxButtons
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
virtual void SpawnButtons(const UDataTable *DTButtonsList)
Spawns buttons based on the provided data table.
UButtonWidget * ConfirmButton
UPROPERTY(BlueprintReadOnly, Category = "Buttons", meta = (BindWidget))
TSubclassOf< class UButtonWidget > CheckButtonWidgetClass
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Buttons")
virtual void Init(UBasicWidgetInfo *WidgetInfo) override
Initializes the widget with the provided widget information.
TSubclassOf< class UButtonWidget > ButtonWidgetClass
The class that will be used to spawning the buttons.
FMargin ButtonPadding
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Buttons")
Custom widget class representing a button.
virtual void ChangeButtonState(const bool bState)
Changes the state of the button .
void SetButtonName(const FText &Name)
UFUNCTION(BlueprintCallable)
FClickEventDelegate OnClickEventDelegate
UPROPERTY(BlueprintAssignable, BlueprintCallable, Category = "Delegate")
Data asset class representing information for a buttons list widget.
Definition UIData.h:188
UObject class representing multiple selection response data.
Definition UIData.h:260
TArray< FString > SelectedButtons
UPROPERTY()
Definition UIData.h:267
Struct representing button information.
Definition UIData.h:278