diff --git a/Content/GameBP/UI/Settings/WB_NavigateSimpleEnvironments.uasset b/Content/GameBP/UI/Settings/WB_NavigateSimpleEnvironments.uasset index 524edc11..f201151d 100644 Binary files a/Content/GameBP/UI/Settings/WB_NavigateSimpleEnvironments.uasset and b/Content/GameBP/UI/Settings/WB_NavigateSimpleEnvironments.uasset differ diff --git a/Content/GameBP/UI/Settings/WB_SelectGoalMenu.uasset b/Content/GameBP/UI/Settings/WB_SelectGoalMenu.uasset index 3010558d..df9a00ed 100644 Binary files a/Content/GameBP/UI/Settings/WB_SelectGoalMenu.uasset and b/Content/GameBP/UI/Settings/WB_SelectGoalMenu.uasset differ diff --git a/Source/LuckyWorldV2/Private/UI/Settings/SelectGoalUserWidget.cpp b/Source/LuckyWorldV2/Private/UI/Settings/SelectGoalUserWidget.cpp index a30f8716..271b3d41 100644 --- a/Source/LuckyWorldV2/Private/UI/Settings/SelectGoalUserWidget.cpp +++ b/Source/LuckyWorldV2/Private/UI/Settings/SelectGoalUserWidget.cpp @@ -4,6 +4,11 @@ #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() { @@ -36,4 +41,160 @@ void USelectGoalUserWidget::NativeConstruct() GetComboBoxString()->SetSelectedIndex(bInitAddOption); } +} + +void USelectGoalUserWidget::DoSelectionChanged(const FString& SelectedItem) +{ + if (GetComboBoxString()) + { + if (GetComboBoxString()->GetSelectedIndex() != 0) + { + if (AllGoalListDataTable) + { + FString ContextString; + TArray RowNames = AllGoalListDataTable->GetRowNames(); + for (const FName& RowName : RowNames) + { + FAllGoalListData* AllGoalListData = AllGoalListDataTable->FindRow(RowName, ContextString); + if (AllGoalListData) + { + if (AllGoalListData->bIsActive) + { + UEnum* GoalTypeEnum = StaticEnum(); + 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(this, AllGoalListData->Widget); + if (CreatedUserWidget) + { + if (GetSizeBox()) + { + GetSizeBox()->AddChild(CreatedUserWidget); + } + } + } + } + else + { + if (CreatedUserWidget) + { + CreatedUserWidget->RemoveFromParent(); + CreatedUserWidget = nullptr; + } + } + + DoSendDetail(AllGoalListData->Example); + + ULuckyRobotsGameInstance* GameInstance = Cast(GetGameInstance()); + if (GameInstance) + { + GameInstance->bIsChanged = false; + } + + NavigateSimpleEnvironments = Cast(CreatedUserWidget); + + break; + } + } + } + } + } + } + else + { + if (CreatedUserWidget) + { + CreatedUserWidget->RemoveFromParent(); + CreatedUserWidget = nullptr; + } + } + } +} + +void USelectGoalUserWidget::DoCloseWindow() +{ + if (GetComboBoxString()) + { + GetComboBoxString()->SetSelectedIndex(bInitAddOption); + } + + ULuckyRobotsGameInstance* GameInstance = Cast(GetGameInstance()); + if (GameInstance) + { + if (GameInstance->GameUserWidget) + { + GameInstance->GameUserWidget->bIsGoalMenuVis = false; + } + } +} + +void USelectGoalUserWidget::DoAutoConfirm() +{ + if (GetComboBoxString()) + { + if (GetComboBoxString()->GetSelectedIndex() != 0) + { + auto UISubsystem = GetGameInstance()->GetSubsystem(); + if (UISubsystem) + { + UISubsystem->OnEndTracing.Broadcast(); + } + + ULuckyRobotsGameInstance* GameInstance = Cast(GetGameInstance()); + if (GameInstance) + { + GameInstance->UpdateTargetSelector(); + GameInstance->TempTask = FGoalsTaskData(); + } + + GetComboBoxString()->SetSelectedIndex(bInitAddOption); + + DoCloseWindow(); + } + } +} + +void USelectGoalUserWidget::DoAddGoalAndStopTracing() +{ + ULuckyRobotsGameInstance* GameInstance = Cast(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(GetGameInstance()); + if (GameInstance) + { + GameInstance->TempTask = FGoalsTaskData(); + } + + if (NavigateSimpleEnvironments) + { + NavigateSimpleEnvironments->BPClickSelectObjectBtn(); + } } \ No newline at end of file diff --git a/Source/LuckyWorldV2/Public/UI/Settings/SelectGoalUserWidget.h b/Source/LuckyWorldV2/Public/UI/Settings/SelectGoalUserWidget.h index f80955f2..9f15c6d5 100644 --- a/Source/LuckyWorldV2/Public/UI/Settings/SelectGoalUserWidget.h +++ b/Source/LuckyWorldV2/Public/UI/Settings/SelectGoalUserWidget.h @@ -8,6 +8,7 @@ class UComboBoxString; class UPathfindingSelectorUserWidget; +class USizeBox; /** * */ @@ -26,14 +27,39 @@ public: UPROPERTY(EditAnywhere, BlueprintReadWrite) UPathfindingSelectorUserWidget* NavigateSimpleEnvironments; + UPROPERTY(EditAnywhere, BlueprintReadWrite) + UUserWidget* CreatedUserWidget; + +public: + FTimerHandle DelayAddGoalTimerHandle; + public: UPROPERTY(EditAnywhere, BlueprintReadWrite) bool bInitAddOption; - public: - UFUNCTION(BlueprintCallable, BlueprintImplementableEvent) + UFUNCTION(BlueprintCallable) + void DoSelectionChanged(const FString& SelectedItem); + + UFUNCTION(BlueprintCallable) + void DoCloseWindow(); + + UFUNCTION(BlueprintCallable) void DoAutoConfirm(); + UFUNCTION(BlueprintCallable) + void DoAddGoalAndStopTracing(); + + void DelayAddGoal(); +public: UFUNCTION(BlueprintPure, BlueprintImplementableEvent) UComboBoxString* GetComboBoxString(); + + UFUNCTION(BlueprintPure, BlueprintImplementableEvent) + USizeBox* GetSizeBox(); + + UFUNCTION(BlueprintCallable, BlueprintImplementableEvent) + void DoSendDetail(const FString& Explanationn); + + UFUNCTION(BlueprintCallable, BlueprintImplementableEvent) + void DoSaveGoalsBTNClick(); };