64 lines
1.7 KiB
C++
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;
|
|
}
|
|
} |