From 527af292a5d131916d5ffd1e158b278322136647 Mon Sep 17 00:00:00 2001 From: Jonasz Bigda Date: Wed, 15 May 2024 15:37:00 +0200 Subject: [PATCH] PlayerController cleanup --- .../TerraformingAnubisPlayerController.cpp | 53 ++----------------- .../TerraformingAnubisPlayerController.h | 22 +------- 2 files changed, 6 insertions(+), 69 deletions(-) diff --git a/Source/TerraformingAnubis/TerraformingAnubisPlayerController.cpp b/Source/TerraformingAnubis/TerraformingAnubisPlayerController.cpp index ceed641..7efdc87 100644 --- a/Source/TerraformingAnubis/TerraformingAnubisPlayerController.cpp +++ b/Source/TerraformingAnubis/TerraformingAnubisPlayerController.cpp @@ -17,9 +17,6 @@ DEFINE_LOG_CATEGORY(LogTemplateCharacter); ATerraformingAnubisPlayerController::ATerraformingAnubisPlayerController() { bShowMouseCursor = true; - DefaultMouseCursor = EMouseCursor::Default; - CachedDestination = FVector::ZeroVector; - FollowTime = 0.f; } void ATerraformingAnubisPlayerController::BeginPlay() @@ -43,10 +40,7 @@ void ATerraformingAnubisPlayerController::SetupInputComponent() if (UEnhancedInputComponent* EnhancedInputComponent = Cast(InputComponent)) { // Setup mouse input events - EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Started, this, &ATerraformingAnubisPlayerController::OnInputStarted); - EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Triggered, this, &ATerraformingAnubisPlayerController::OnSetDestinationTriggered); - EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Completed, this, &ATerraformingAnubisPlayerController::OnSetDestinationReleased); - EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Canceled, this, &ATerraformingAnubisPlayerController::OnSetDestinationReleased); + EnhancedInputComponent->BindAction(ClickAction, ETriggerEvent::Started, this, &ATerraformingAnubisPlayerController::OnClick); } else { @@ -54,46 +48,7 @@ void ATerraformingAnubisPlayerController::SetupInputComponent() } } -void ATerraformingAnubisPlayerController::OnInputStarted() +void ATerraformingAnubisPlayerController::OnClick() { - StopMovement(); -} - -// Triggered every frame when the input is held down -void ATerraformingAnubisPlayerController::OnSetDestinationTriggered() -{ - // We flag that the input is being pressed - FollowTime += GetWorld()->GetDeltaSeconds(); - - // We look for the location in the world where the player has pressed the input - FHitResult Hit; - bool bHitSuccessful = false; - bHitSuccessful = GetHitResultUnderCursor(ECollisionChannel::ECC_Visibility, true, Hit); - - // If we hit a surface, cache the location - if (bHitSuccessful) - { - CachedDestination = Hit.Location; - } - - // Move towards mouse pointer or touch - APawn* ControlledPawn = GetPawn(); - if (ControlledPawn != nullptr) - { - FVector WorldDirection = (CachedDestination - ControlledPawn->GetActorLocation()).GetSafeNormal(); - ControlledPawn->AddMovementInput(WorldDirection, 1.0, false); - } -} - -void ATerraformingAnubisPlayerController::OnSetDestinationReleased() -{ - // If it was a short press - if (FollowTime <= ShortPressThreshold) - { - // We move there and spawn some particles - UAIBlueprintHelperLibrary::SimpleMoveToLocation(this, CachedDestination); - UNiagaraFunctionLibrary::SpawnSystemAtLocation(this, FXCursor, CachedDestination, FRotator::ZeroRotator, FVector(1.f, 1.f, 1.f), true, true, ENCPoolMethod::None, true); - } - - FollowTime = 0.f; -} + // +} \ No newline at end of file diff --git a/Source/TerraformingAnubis/TerraformingAnubisPlayerController.h b/Source/TerraformingAnubis/TerraformingAnubisPlayerController.h index 851e302..cdde367 100644 --- a/Source/TerraformingAnubis/TerraformingAnubisPlayerController.h +++ b/Source/TerraformingAnubis/TerraformingAnubisPlayerController.h @@ -22,40 +22,22 @@ class ATerraformingAnubisPlayerController : public APlayerController public: ATerraformingAnubisPlayerController(); - /** Time Threshold to know if it was a short press */ - UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input) - float ShortPressThreshold; - - /** FX Class that we will spawn when clicking */ - UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input) - UNiagaraSystem* FXCursor; - /** MappingContext */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) UInputMappingContext* DefaultMappingContext; /** Jump Input Action */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) - UInputAction* SetDestinationClickAction; + UInputAction* ClickAction; protected: - /** True if the controlled character should navigate to the mouse cursor. */ - uint32 bMoveToMouseCursor : 1; - virtual void SetupInputComponent() override; // To add mapping context virtual void BeginPlay(); - /** Input handlers for SetDestination action. */ - void OnInputStarted(); - void OnSetDestinationTriggered(); - void OnSetDestinationReleased(); - private: - FVector CachedDestination; - - float FollowTime; // For how long it has been pressed + void OnClick(); };