203 lines
5.1 KiB
C++
203 lines
5.1 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "UI/Settings/SelectGoalUserWidget.h"
|
|
#include "SharedDef.h"
|
|
#include "Components/ComboBoxString.h"
|
|
#include "Components/SizeBox.h"
|
|
#include "Core/LuckyRobotsGameInstance.h"
|
|
#include "UI/Settings/PathfindingSelectorUserWidget.h"
|
|
#include "UI/GameUserWidget.h"
|
|
#include "Subsystem/UISubsystem.h"
|
|
|
|
void USelectGoalUserWidget::NativeConstruct()
|
|
{
|
|
Super::NativeConstruct();
|
|
|
|
bInitAddOption = false;
|
|
|
|
if (GetComboBoxString())
|
|
{
|
|
if (AllGoalListDataTable)
|
|
{
|
|
FString ContextString;
|
|
TArray<FName> RowNames = AllGoalListDataTable->GetRowNames();
|
|
for (const FName& RowName : RowNames)
|
|
{
|
|
FAllGoalListData* AllGoalListData = AllGoalListDataTable->FindRow<FAllGoalListData>(RowName, ContextString);
|
|
if (AllGoalListData)
|
|
{
|
|
if (AllGoalListData->bIsActive)
|
|
{
|
|
UEnum* GoalTypeEnum = StaticEnum<EGoalType>();
|
|
FString GoalTypeString = GoalTypeEnum->GetDisplayNameTextByIndex(int(AllGoalListData->GoalType)).ToString();
|
|
GetComboBoxString()->AddOption(GoalTypeString);
|
|
bInitAddOption = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
GetComboBoxString()->SetSelectedIndex(bInitAddOption);
|
|
}
|
|
}
|
|
|
|
void USelectGoalUserWidget::DoSelectionChanged(const FString& SelectedItem)
|
|
{
|
|
if (GetComboBoxString())
|
|
{
|
|
if (GetComboBoxString()->GetSelectedIndex() != 0)
|
|
{
|
|
if (AllGoalListDataTable)
|
|
{
|
|
FString ContextString;
|
|
TArray<FName> RowNames = AllGoalListDataTable->GetRowNames();
|
|
for (const FName& RowName : RowNames)
|
|
{
|
|
FAllGoalListData* AllGoalListData = AllGoalListDataTable->FindRow<FAllGoalListData>(RowName, ContextString);
|
|
if (AllGoalListData)
|
|
{
|
|
if (AllGoalListData->bIsActive)
|
|
{
|
|
UEnum* GoalTypeEnum = StaticEnum<EGoalType>();
|
|
FString GoalTypeString = GoalTypeEnum->GetDisplayNameTextByIndex(int(AllGoalListData->GoalType)).ToString();
|
|
if (GoalTypeString == SelectedItem)
|
|
{
|
|
if (AllGoalListData->Widget)
|
|
{
|
|
if (!CreatedUserWidget || (CreatedUserWidget && CreatedUserWidget->GetClass() != AllGoalListData->Widget))
|
|
{
|
|
if (CreatedUserWidget)
|
|
{
|
|
CreatedUserWidget->RemoveFromParent();
|
|
CreatedUserWidget = nullptr;
|
|
}
|
|
|
|
CreatedUserWidget = CreateWidget<UUserWidget>(this, AllGoalListData->Widget);
|
|
if (CreatedUserWidget)
|
|
{
|
|
if (GetSizeBox())
|
|
{
|
|
GetSizeBox()->AddChild(CreatedUserWidget);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (CreatedUserWidget)
|
|
{
|
|
CreatedUserWidget->RemoveFromParent();
|
|
CreatedUserWidget = nullptr;
|
|
}
|
|
}
|
|
|
|
DoSendDetail(AllGoalListData->Example);
|
|
|
|
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
|
if (GameInstance)
|
|
{
|
|
GameInstance->bIsChanged = false;
|
|
}
|
|
|
|
NavigateSimpleEnvironments = Cast<UPathfindingSelectorUserWidget>(CreatedUserWidget);
|
|
if (NavigateSimpleEnvironments)
|
|
{
|
|
NavigateSimpleEnvironments->OwnerSelectGoalUserWidget = this;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (CreatedUserWidget)
|
|
{
|
|
CreatedUserWidget->RemoveFromParent();
|
|
CreatedUserWidget = nullptr;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void USelectGoalUserWidget::DoCloseWindow()
|
|
{
|
|
if (GetComboBoxString())
|
|
{
|
|
GetComboBoxString()->SetSelectedIndex(bInitAddOption);
|
|
}
|
|
|
|
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
|
if (GameInstance)
|
|
{
|
|
if (GameInstance->GameUserWidget)
|
|
{
|
|
GameInstance->GameUserWidget->bIsGoalMenuVis = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
void USelectGoalUserWidget::DoAutoConfirm()
|
|
{
|
|
if (GetComboBoxString())
|
|
{
|
|
if (GetComboBoxString()->GetSelectedIndex() != 0)
|
|
{
|
|
auto UISubsystem = GetGameInstance()->GetSubsystem<UUISubsystem>();
|
|
if (UISubsystem)
|
|
{
|
|
UISubsystem->OnEndTracing.Broadcast();
|
|
}
|
|
|
|
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
|
if (GameInstance)
|
|
{
|
|
GameInstance->UpdateTargetSelector();
|
|
GameInstance->TempTask = FGoalsTaskData();
|
|
}
|
|
|
|
GetComboBoxString()->SetSelectedIndex(bInitAddOption);
|
|
|
|
DoCloseWindow();
|
|
}
|
|
}
|
|
}
|
|
|
|
void USelectGoalUserWidget::DoAddGoalAndStopTracing()
|
|
{
|
|
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
|
if (GameInstance)
|
|
{
|
|
if (GameInstance->bIsChanged)
|
|
{
|
|
if (GetComboBoxString())
|
|
{
|
|
if (GetComboBoxString()->GetSelectedIndex() != 0)
|
|
{
|
|
DoSaveGoalsBTNClick();
|
|
|
|
GetWorld()->GetTimerManager().ClearTimer(DelayAddGoalTimerHandle);
|
|
GetWorld()->GetTimerManager().SetTimer(DelayAddGoalTimerHandle, this, &USelectGoalUserWidget::DelayAddGoal, 0.2f, false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void USelectGoalUserWidget::DelayAddGoal()
|
|
{
|
|
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
|
if (GameInstance)
|
|
{
|
|
GameInstance->TempTask = FGoalsTaskData();
|
|
}
|
|
|
|
if (NavigateSimpleEnvironments)
|
|
{
|
|
NavigateSimpleEnvironments->ClickSelectObjectBtn();
|
|
}
|
|
} |