You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.2 KiB
64 lines
2.2 KiB
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
#include "ManageSquadPlayerController.h"
|
|
|
|
#include "ManageSquadGameState.h"
|
|
|
|
AManageSquadPlayerController::AManageSquadPlayerController() {
|
|
SetShowMouseCursor(true);
|
|
}
|
|
|
|
void AManageSquadPlayerController::SetupInputComponent() {
|
|
Super::SetupInputComponent();
|
|
InputComponent->BindAction("MyAction", IE_Pressed, this,
|
|
&AManageSquadPlayerController::OnLeftMouseClick);
|
|
}
|
|
|
|
void AManageSquadPlayerController::OnLeftMouseClick() {
|
|
UE_LOG(LogTemp, Warning, TEXT("Mouse clicked"));
|
|
FHitResult HitResult;
|
|
bool const IsHitResult = GetHitResultUnderCursorForObjects(
|
|
TArray<TEnumAsByte<EObjectTypeQuery>>{ObjectTypeQuery1}, false,
|
|
HitResult);
|
|
if (!IsHitResult)
|
|
return;
|
|
|
|
UE_LOG(LogTemp, Warning, TEXT("Got hit result"));
|
|
// auto const NewlySelectedLocation = HitResult.Location;
|
|
AManageSquadTrooper *NewlySelectedTrooper = dynamic_cast
|
|
<AManageSquadTrooper *>(
|
|
HitResult.GetActor());
|
|
|
|
if (NewlySelectedTrooper == nullptr || !NewlySelectedTrooper->
|
|
IsValidLowLevel()) {
|
|
// we selected something that is not a trooper (or trooper in shitty state...)
|
|
UE_LOG(LogTemp, Warning, TEXT("Not a trooper"));
|
|
return;
|
|
}
|
|
// skip re-selection
|
|
if (SelectedTrooper == NewlySelectedTrooper) {
|
|
UE_LOG(LogTemp, Warning, TEXT("Skip reselection"));
|
|
return;
|
|
}
|
|
UE_LOG(LogTemp, Warning, TEXT("Trooper"));
|
|
switch (NewlySelectedTrooper->GetType()) {
|
|
case ETrooperType::TROOPER_SAMPLE:
|
|
if (SelectedTrooper) {
|
|
UE_LOG(LogTemp, Warning, TEXT("Trooper replacement"));
|
|
SelectedTrooper->ChangeSkeletalMesh(NewlySelectedTrooper);
|
|
dynamic_cast<AManageSquadGameState *>(
|
|
GetWorld()->GetGameState())->ChangeSquad(
|
|
SelectedTrooper->GetIndex(),
|
|
NewlySelectedTrooper->GetIndex()
|
|
);
|
|
}
|
|
break;
|
|
case ETrooperType::TROOPER_IN_SQUAD:
|
|
SelectedTrooper = NewlySelectedTrooper;
|
|
UE_LOG(LogTemp, Warning, TEXT("Changed selection"));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|