unreal/MovementArrow.cpp

90 lines
3.2 KiB
C++

#include "MovementArrow.h"
#include "AdventureMap.h"
// Sets default values
AMovementArrow::AMovementArrow()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
SceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Scene"));
RootComponent = SceneComponent;
MeshStraight = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Straight"));
MeshRight = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Right"));
MeshRightSharp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("RightSharp"));
MeshLeftSharp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("LeftSharp"));
MeshLeft = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Left"));
MeshVariants.Add(MeshStraight);
MeshVariants.Add(MeshRight);
MeshVariants.Add(MeshRightSharp);
MeshVariants.Add(MeshLeftSharp);
MeshVariants.Add(MeshLeft);
for (UStaticMeshComponent* Mesh : MeshVariants) {
Mesh->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepWorldTransform);
Mesh->ToggleVisibility();
}
}
void AMovementArrow::SetVariant(FHexVector InVector, FHexVector OutVector) {
int32 InVectorIndex = MapRef->UnitVectors.Find(InVector);
int32 OutVectorIndex = MapRef->UnitVectors.Find(OutVector);
int32 VariantIndex;
if (InVectorIndex == 0) {
if (OutVectorIndex == 0) { VariantIndex = 0; }
if (OutVectorIndex == 1) { VariantIndex = 1; }
if (OutVectorIndex == 2) { VariantIndex = 2; }
if (OutVectorIndex == 4) { VariantIndex = 3; }
if (OutVectorIndex == 5) { VariantIndex = 4; }
}
if (InVectorIndex == 1) {
if (OutVectorIndex == 0) { VariantIndex = 4; }
if (OutVectorIndex == 1) { VariantIndex = 0; }
if (OutVectorIndex == 2) { VariantIndex = 1; }
if (OutVectorIndex == 3) { VariantIndex = 2; }
if (OutVectorIndex == 5) { VariantIndex = 3; }
}
if (InVectorIndex == 2) {
if (OutVectorIndex == 0) { VariantIndex = 3; }
if (OutVectorIndex == 1) { VariantIndex = 4; }
if (OutVectorIndex == 2) { VariantIndex = 0; }
if (OutVectorIndex == 3) { VariantIndex = 1; }
if (OutVectorIndex == 4) { VariantIndex = 2; }
}
if (InVectorIndex == 3) {
if (OutVectorIndex == 1) { VariantIndex = 3; }
if (OutVectorIndex == 2) { VariantIndex = 4; }
if (OutVectorIndex == 3) { VariantIndex = 0; }
if (OutVectorIndex == 4) { VariantIndex = 1; }
if (OutVectorIndex == 5) { VariantIndex = 2; }
}
if (InVectorIndex == 4) {
if (OutVectorIndex == 0) { VariantIndex = 2; }
if (OutVectorIndex == 2) { VariantIndex = 3; }
if (OutVectorIndex == 3) { VariantIndex = 4; }
if (OutVectorIndex == 4) { VariantIndex = 0; }
if (OutVectorIndex == 5) { VariantIndex = 1; }
}
if (InVectorIndex == 5) {
if (OutVectorIndex == 0) { VariantIndex = 1; }
if (OutVectorIndex == 1) { VariantIndex = 2; }
if (OutVectorIndex == 3) { VariantIndex = 3; }
if (OutVectorIndex == 4) { VariantIndex = 4; }
if (OutVectorIndex == 5) { VariantIndex = 0; }
}
SceneComponent->SetRelativeRotation(FRotator(0, InVectorIndex * 60.f, 0));
MeshVariants[VariantIndex]->ToggleVisibility();
}
// Called when the game starts or when spawned
void AMovementArrow::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AMovementArrow::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}