Don't write clever code

This commit is contained in:
Maximilian Fajnberg 2022-06-05 22:44:34 +02:00
parent aa02fb8093
commit 28a226e35d
3 changed files with 71 additions and 42 deletions

View File

@ -54,16 +54,11 @@ void AAdventureCameraPawn::GetTheDamnViewport()
void AAdventureCameraPawn::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
// quick fix for edgescrolling after viewport resizing.
//
//TickIncrement++;
//if (TickIncrement >= 60) {
// TickIncrement = 0;
// ViewSize = Viewport->Viewport->GetSizeXY();
//}
if (IsValid(FollowPawn)) { if (FollowPawn->bIsMoving) { FollowAdvPawn(DeltaTime); } }
if (IsValid(FollowPawn)) {
if (FollowPawn->bIsMoving) {
FollowAdvPawn(DeltaTime);
}
}
}
// Called to bind functionality to input
@ -101,18 +96,18 @@ void AAdventureCameraPawn::EdgeScrollSide(float AxisValue)
float mousePosY = mouseY / ViewSize.Y;
float VertAccelleration = GetInputAxisValue("Mouse Y") * (ScrollAccelleration * .75);
if (mousePosX <= ESASize) // if in LEFT area
if (mousePosX <= ESASize) // in LEFT area
{
////// Scroll LEFT
float SpeedX = (mousePosX * ESAMinBoundSlope + ESAMinBoundIntercept) * BaseScrollSpeed;
AddActorLocalOffset(FVector(-SpeedX, 0, 0));
if (mousePosY > .005) // if not touching TOP EDGE
if (mousePosY > .005) // not touching TOP EDGE
{
AddActorLocalOffset(FVector(0, -VertAccelleration, 0));
}
if (AxisValue < .0 && mousePosX <= .005) // if mouse moving LEFT and touching EDGE
if (AxisValue < .0 && mousePosX <= .005) // mouse moving LEFT && touching EDGE
{
////// Add LEFT accelleration
SpeedX = AxisValue * ScrollAccelleration;
@ -120,18 +115,18 @@ void AAdventureCameraPawn::EdgeScrollSide(float AxisValue)
}
}
if (mousePosX >= 1-ESASize) // if in RIGHT area
if (mousePosX >= 1-ESASize) // in RIGHT area
{
////// Scroll RIGHT
float SpeedX = (mousePosX * ESAMaxBoundSlope + ESAMaxBoundIntercept) * BaseScrollSpeed;
AddActorLocalOffset(FVector(SpeedX, 0, 0));
if (mousePosY < .995) // if not touching BOT EDGE
if (mousePosY < .995) // not touching BOT EDGE
{
AddActorLocalOffset(FVector(0, -VertAccelleration, 0));
}
if (AxisValue > .0 && mousePosX >= .995) // if mouse moving RIGHT and touching EDGE
if (AxisValue > .0 && mousePosX >= .995) // mouse moving RIGHT && touching EDGE
{
////// Add RIGHT accelleration
SpeedX = AxisValue * ScrollAccelleration;
@ -149,18 +144,18 @@ void AAdventureCameraPawn::EdgeScrollVert(float AxisValue)
float mousePosX = mouseX / ViewSize.X;
float SideAccelleration = GetInputAxisValue("Mouse X") * (ScrollAccelleration * .75);
if (mousePosY <= ESASize) // if in TOP area
if (mousePosY <= ESASize) // in TOP area
{
////// Scroll TOP
float SpeedY = (mousePosY * ESAMinBoundSlope + ESAMinBoundIntercept) * BaseScrollSpeed;
AddActorLocalOffset(FVector(0, -SpeedY, 0));
if (mousePosX > .005) // if not touching EDGE
if (mousePosX > .005) // not touching EDGE
{
AddActorLocalOffset(FVector(SideAccelleration, 0, 0));
}
if (AxisValue > .0 && mousePosY <= .005) // if mouse moving TOP and touching EDGE
if (AxisValue > .0 && mousePosY <= .005) // mouse moving TOP && touching EDGE
{
////// Add TOP accelleration
SpeedY = AxisValue * ScrollAccelleration;
@ -168,18 +163,18 @@ void AAdventureCameraPawn::EdgeScrollVert(float AxisValue)
}
}
if (mousePosY >= 1-ESASize) // if in BOTTOM area
if (mousePosY >= 1-ESASize) // in BOTTOM area
{
////// Scroll BOTTOM
float SpeedY = (mousePosY * ESAMaxBoundSlope + ESAMaxBoundIntercept) * BaseScrollSpeed;
AddActorLocalOffset(FVector(0, SpeedY, 0));
if (mousePosX < .995) // if not touching BOT EDGE
if (mousePosX < .995) // not touching BOT EDGE
{
AddActorLocalOffset(FVector(SideAccelleration, 0, 0));
}
if (AxisValue < .0 && mousePosY >= .995) // if mouse moving BOTTOM and touching EDGE
if (AxisValue < .0 && mousePosY >= .995) // mouse moving BOTTOM && touching EDGE
{
////// add BOTTOM accelleration
SpeedY = AxisValue * ScrollAccelleration;

View File

@ -25,28 +25,62 @@ AMovementArrow::AMovementArrow()
}
}
void AMovementArrow::SetVariant(FHexVector InVector, FHexVector OutVector) {
void AMovementArrow::SetVariant(FHexVector InVec, FHexVector OutVec) {
int32 InVectorIndex = MapRef->UnitVectors.Find(InVector);
int32 OutVectorIndex = MapRef->UnitVectors.Find(OutVector);
int32 VariantIndex;
int32 InVecIndex = MapRef->UnitVectors.Find(InVec);
SceneComponent->SetRelativeRotation(FRotator(0, InVecIndex * 60.f, 0));
int32 OutVecIndex = MapRef->UnitVectors.Find(OutVec);
int32 BackMotion = (InVecIndex + 3) % 6;
if (BackMotion < 0) { BackMotion = (((InVecIndex + 3) % 6) + 6) % 6; } // c++ modulus weirdness
if (InVecIndex < BackMotion && OutVecIndex > BackMotion) {
OutVecIndex--; }
if (InVecIndex > BackMotion && OutVecIndex < BackMotion) {
InVecIndex--; }
int32 VariantIndex = (OutVecIndex - InVecIndex) % 5;
if (VariantIndex < 0) { VariantIndex = ((OutVecIndex - InVecIndex) % 5 + 5) % 5; } // c++ modulus weirdness
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();
}

View File

@ -36,7 +36,7 @@ public:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Variant")
TArray<UStaticMeshComponent*> MeshVariants;
UFUNCTION(BlueprintCallable, Category = "Variant")
void SetVariant(FHexVector InVec, FHexVector OutVec);
void SetVariant(FHexVector InVector, FHexVector OutVector);
protected:
// Called when the game starts or when spawned