Optimize some UI

This commit is contained in:
martinluckyrobots
2025-04-17 23:30:37 +08:00
parent 6198dc374e
commit 3f5bc9e1b1
15 changed files with 210 additions and 11 deletions

View File

@ -2,4 +2,63 @@
#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;
}
}