2023-09-26 17:00:30 -04:00
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "Tangible.h"
|
|
|
|
|
#include "TangibleManager.h"
|
2024-02-02 15:48:27 -05:00
|
|
|
#include "IntegrationGameModeBase.h"
|
2023-09-26 17:00:30 -04:00
|
|
|
|
2024-01-24 14:51:21 -05:00
|
|
|
#define DEFAULT_BLUEPRINT (TEXT("TangibleStaticMesh"))
|
2024-09-24 18:58:13 -04:00
|
|
|
#define LOCTEXT_NAMESPACE "Luprex Tangible"
|
2024-01-24 14:51:21 -05:00
|
|
|
|
2023-09-26 17:00:30 -04:00
|
|
|
UlxTangible::UlxTangible()
|
|
|
|
|
{
|
2023-09-28 14:32:48 -04:00
|
|
|
Manager = nullptr;
|
2023-09-26 19:26:09 -04:00
|
|
|
TangibleId = -1;
|
2023-09-28 14:32:48 -04:00
|
|
|
CurrentActor = nullptr;
|
2024-01-24 14:51:21 -05:00
|
|
|
ActorBlueprintName = TEXT("");
|
2023-09-26 19:26:09 -04:00
|
|
|
NearAccordingToLuprex = false;
|
2023-09-28 14:32:48 -04:00
|
|
|
NearAccordingToUnreal = false;
|
2023-09-26 17:00:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UlxTangible::Init(UlxTangibleManager* tm, int64 id)
|
|
|
|
|
{
|
|
|
|
|
Manager = tm;
|
|
|
|
|
TangibleId = id;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-30 13:06:10 -05:00
|
|
|
#pragma optimize("", off)
|
2024-01-24 14:51:21 -05:00
|
|
|
void UlxTangible::SetActorBlueprint(const FString &name) {
|
2023-09-26 17:00:30 -04:00
|
|
|
// If we're already of the right class, do nothing.
|
2024-01-24 14:51:21 -05:00
|
|
|
if (ActorBlueprintName == name) {
|
2023-09-26 17:00:30 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-24 14:51:21 -05:00
|
|
|
// Get the blueprint.
|
|
|
|
|
// If the blueprint doesn't exist, or doesn't implement
|
|
|
|
|
// TangibleInterface, then use the fallback blueprint.
|
|
|
|
|
UClass *blueprint = Manager->GetTangibleClass(name);
|
|
|
|
|
if ((!name.IsEmpty()) && (blueprint == nullptr)) {
|
|
|
|
|
blueprint = Manager->GetTangibleClass(DEFAULT_BLUEPRINT);
|
|
|
|
|
check(blueprint != nullptr);
|
|
|
|
|
}
|
2023-09-26 17:00:30 -04:00
|
|
|
|
|
|
|
|
// If there's already an actor, delete it.
|
|
|
|
|
if (CurrentActor != nullptr) {
|
|
|
|
|
// Remove the tangible component. This is probably
|
|
|
|
|
// unnecessary, but it makes it more likely that we'll
|
|
|
|
|
// catch bugs early.
|
|
|
|
|
UlxTangibleComponent* comp = CurrentActor->GetComponentByClass<UlxTangibleComponent>();
|
|
|
|
|
if (comp != nullptr) {
|
|
|
|
|
comp->DestroyComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now destroy the actor itself. According to various
|
|
|
|
|
// documents I've read online, it may be necessary to take
|
|
|
|
|
// further steps to delete the object. Not clear.
|
2024-03-25 14:50:06 -04:00
|
|
|
CurrentActor->Destroy();
|
|
|
|
|
|
|
|
|
|
// If this actor previously was posessed by a player controller,
|
|
|
|
|
// then it's not posessed anymore, because there is no actor any more.
|
|
|
|
|
if (Manager->PossessedTangible == this) {
|
|
|
|
|
Manager->PossessedTangible = nullptr;
|
|
|
|
|
};
|
2023-09-26 17:00:30 -04:00
|
|
|
}
|
|
|
|
|
|
2024-01-24 14:51:21 -05:00
|
|
|
// Update the blueprint name
|
|
|
|
|
ActorBlueprintName = name;
|
2023-09-26 17:00:30 -04:00
|
|
|
|
|
|
|
|
// Now create a new actor, unless the BP is nullptr.
|
2024-01-24 14:51:21 -05:00
|
|
|
if (blueprint != nullptr) {
|
2023-09-26 17:00:30 -04:00
|
|
|
UWorld* w = Manager->GetWorld();
|
2024-02-02 15:48:27 -05:00
|
|
|
FActorSpawnParameters params;
|
|
|
|
|
|
|
|
|
|
// Currently, the actor is spawned at (0,0,0), which is not good.
|
|
|
|
|
// We should spawn at the actor's current location. I'll get to it
|
|
|
|
|
// eventually.
|
|
|
|
|
FTransform transform;
|
|
|
|
|
transform.SetLocation(FVector(0,0,0));
|
|
|
|
|
transform.SetRotation(FQuat(FRotator(0,0,0)));
|
|
|
|
|
|
|
|
|
|
// Create the actor at the specified location even if there's something in the way.
|
2024-01-30 13:06:10 -05:00
|
|
|
params.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
2024-02-02 15:48:27 -05:00
|
|
|
|
|
|
|
|
// Normally, SpawnActor runs the BeginPlay entry point. We
|
|
|
|
|
// want to delay that until after we've had a chance to set
|
|
|
|
|
// up the TangibleComponent.
|
|
|
|
|
params.bDeferConstruction = true;
|
|
|
|
|
AActor* a = w->SpawnActor(blueprint, &transform, params);
|
2024-01-30 13:06:10 -05:00
|
|
|
check(a != nullptr);
|
2023-09-26 17:00:30 -04:00
|
|
|
|
|
|
|
|
// Insert a TangibleComponent into the actor.
|
2024-02-02 15:48:27 -05:00
|
|
|
// Link the actor to its tangible, and the tangible to its actor.
|
2023-09-26 17:00:30 -04:00
|
|
|
UActorComponent* ac = a->AddComponentByClass(UlxTangibleComponent::StaticClass(), false, FTransform::Identity, false);
|
|
|
|
|
UlxTangibleComponent* tc = Cast<UlxTangibleComponent>(ac);
|
|
|
|
|
check(tc != nullptr);
|
|
|
|
|
tc->Tangible = this;
|
|
|
|
|
CurrentActor = a;
|
2024-02-02 15:48:27 -05:00
|
|
|
|
|
|
|
|
// This executes the BeginPlay entry point. We have to do this here
|
|
|
|
|
// because we deferred it in SpawnActor.
|
|
|
|
|
a->FinishSpawning(transform, true);
|
2023-09-26 17:00:30 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-28 14:32:48 -04:00
|
|
|
void UlxTangible::UpdateAnimationQueue(std::string_view aq) {
|
|
|
|
|
AnimTracker.Update(aq);
|
2024-02-13 16:49:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UlxTangible::MaybeExecuteAnimStateChanged() {
|
2023-10-02 15:48:42 -04:00
|
|
|
int limit = 3;
|
|
|
|
|
while (AnimTracker.IsChanged()) {
|
|
|
|
|
if (limit == 0) break;
|
|
|
|
|
limit -= 1;
|
|
|
|
|
AnimTracker.ClearChanged();
|
2024-01-24 14:51:21 -05:00
|
|
|
FString blueprint = AnimTracker.GetCurrentBlueprintName();
|
|
|
|
|
if (blueprint.IsEmpty()) blueprint = DEFAULT_BLUEPRINT;
|
|
|
|
|
SetActorBlueprint(blueprint);
|
2024-08-29 17:46:12 -04:00
|
|
|
IlxTangibleInterface::Execute_AnimationQueueChanged(GetActor());
|
2023-09-28 14:32:48 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FVector UlxTangible::GetLocation() const {
|
|
|
|
|
if (CurrentActor == nullptr) {
|
|
|
|
|
return FVector(0,0,0);
|
|
|
|
|
} else {
|
|
|
|
|
return CurrentActor->GetActorLocation();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UlxTangible::Destroy() {
|
2024-01-24 14:51:21 -05:00
|
|
|
SetActorBlueprint("");
|
2023-09-28 14:32:48 -04:00
|
|
|
Manager = nullptr;
|
|
|
|
|
TangibleId = -1;
|
|
|
|
|
CurrentActor = nullptr;
|
2024-01-24 14:51:21 -05:00
|
|
|
ActorBlueprintName = "";
|
2023-09-28 14:32:48 -04:00
|
|
|
AnimTracker.Clear();
|
|
|
|
|
NearAccordingToLuprex = false;
|
|
|
|
|
NearAccordingToUnreal = false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-03 21:57:40 -04:00
|
|
|
UlxTangible *UlxTangible::GetActorTangible(AActor *actor) {
|
2023-09-26 17:00:30 -04:00
|
|
|
UlxTangibleComponent* comp = actor->GetComponentByClass<UlxTangibleComponent>();
|
|
|
|
|
check(comp != nullptr);
|
2023-10-02 15:48:42 -04:00
|
|
|
UlxTangible *result = comp->Tangible.Get();
|
|
|
|
|
check(result != nullptr);
|
|
|
|
|
return result;
|
2023-09-26 17:00:30 -04:00
|
|
|
}
|
|
|
|
|
|
2023-10-02 15:48:42 -04:00
|
|
|
void UlxTangible::GetCurrentAnimation(AActor *target, FlxAnimationStep &step) {
|
|
|
|
|
step = GetActorTangible(target)->AnimTracker.GetCurrentAnimation();
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 14:59:48 -04:00
|
|
|
void UlxTangible::FinishedAnimation(AActor *target, const FlxAnimationStep &step, bool autoxyz, bool autofacing, bool autoplane) {
|
|
|
|
|
UlxTangible *tan = GetActorTangible(target);
|
|
|
|
|
if (autoxyz) step.AutoUpdateXYZ(target);
|
|
|
|
|
if (autofacing) step.AutoUpdateFacing(target);
|
|
|
|
|
if (autoplane) step.AutoUpdatePlane(&(tan->Plane));
|
|
|
|
|
tan->AnimTracker.FinishedAnimation(step.Hash);
|
2023-10-02 15:48:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FString UlxTangible::GetTangiblePlane(AActor* target) {
|
|
|
|
|
return GetActorTangible(target)->Plane.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UlxTangible::SetTangiblePlane(AActor* target, const FString& plane) {
|
|
|
|
|
GetActorTangible(target)->Plane = FName(plane);
|
2023-09-26 17:00:30 -04:00
|
|
|
}
|
|
|
|
|
|
2024-02-02 15:48:27 -05:00
|
|
|
bool UlxTangible::IsCurrentPlayer(AActor* target) {
|
|
|
|
|
UlxTangible *tan = GetActorTangible(target);
|
|
|
|
|
AIntegrationGameModeBase *gamemode = tan->Manager->GetGameMode();
|
|
|
|
|
return (tan->TangibleId == gamemode->PlayerId);
|
2024-02-16 15:48:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UlxTangible::SetAutoFinish(AActor *target, const FString &action, const FVector &xyz) {
|
|
|
|
|
UlxTangible *tan = GetActorTangible(target);
|
|
|
|
|
tan->AnimTracker.SetAutoFinish(action, xyz);
|
2024-08-29 17:46:12 -04:00
|
|
|
}
|
|
|
|
|
|