LuckyWorldV2/Source/LuckyWorldV2/Private/UI/Settings/PathfindingSelectorUserWidget.cpp
martinluckyrobots 3f5bc9e1b1 Optimize some UI
2025-04-17 23:30:37 +08:00

64 lines
1.7 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "UI/Settings/PathfindingSelectorUserWidget.h"
#include "Gameplay/TargetSelector.h"
#include "Core/LuckyRobotsGameInstance.h"
#include "Subsystem/UISubsystem.h"
#include "UI/Settings/SelectGoalUserWidget.h"
void UPathfindingSelectorUserWidget::ClickSelectObjectBtn()
{
if (CreatedTargetSelector)
{
CreatedTargetSelector->Destroy();
CreatedTargetSelector = nullptr;
}
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
if (GameInstance)
{
FTransform SpawnPoint;
CreatedTargetSelector = GetWorld()->SpawnActorDeferred<ATargetSelector>(GameInstance->TargetSelectorClass, SpawnPoint, nullptr, nullptr,
ESpawnActorCollisionHandlingMethod::AlwaysSpawn);
if (CreatedTargetSelector)
{
CreatedTargetSelector->FinishSpawning(SpawnPoint);
}
}
auto UISubsystem = GetGameInstance()->GetSubsystem<UUISubsystem>();
if (UISubsystem)
{
UISubsystem->OnStartTracing.Broadcast();
}
}
void UPathfindingSelectorUserWidget::AddGoal()
{
if (CreatedTargetSelector)
{
ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
if (GameInstance)
{
FGoalsTaskData addTempTask;
addTempTask.GoalType = EGoalType::NavigateSimpleEnvironments;
addTempTask.TargetLocation = CreatedTargetSelector->GetActorTransform();
GameInstance->TempTask = addTempTask;
GameInstance->bIsChanged = true;
}
auto UISubsystem = GetGameInstance()->GetSubsystem<UUISubsystem>();
if (UISubsystem)
{
UISubsystem->OnEndTracing.Broadcast();
}
if (OwnerSelectGoalUserWidget)
{
OwnerSelectGoalUserWidget->DoAddGoalAndStopTracing();
}
CreatedTargetSelector->bIsTracing = false;
}
}