style: apply clang format

This commit is contained in:
2025-10-10 20:58:22 +02:00
parent ea4fa7bbe6
commit 9938181043
8 changed files with 115 additions and 60 deletions

View File

@@ -8,6 +8,16 @@ public class UTAD_UI : ModuleRules
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "NavigationSystem", "AIModule", "Niagara", "EnhancedInput" });
PublicDependencyModuleNames.AddRange(new string[]
{
"Core",
"CoreUObject",
"Engine",
"InputCore",
"NavigationSystem",
"AIModule",
"Niagara",
"EnhancedInput"
});
}
}

View File

@@ -3,7 +3,6 @@
#include "UTAD_UI.h"
#include "Modules/ModuleManager.h"
IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, UTAD_UI, "UTAD_UI" );
IMPLEMENT_PRIMARY_GAME_MODULE(FDefaultGameModuleImpl, UTAD_UI, "UTAD_UI");
DEFINE_LOG_CATEGORY(LogUTAD_UI)

View File

@@ -18,34 +18,41 @@ AUTAD_UICharacter::AUTAD_UICharacter()
// Don't rotate character to camera direction
bUseControllerRotationPitch = false;
bUseControllerRotationYaw = false;
bUseControllerRotationRoll = false;
bUseControllerRotationYaw = false;
bUseControllerRotationRoll = false;
// Configure character movement
GetCharacterMovement()->bOrientRotationToMovement = true; // Rotate character to moving direction
GetCharacterMovement()->RotationRate = FRotator(0.f, 640.f, 0.f);
GetCharacterMovement()->bConstrainToPlane = true;
GetCharacterMovement()->bOrientRotationToMovement =
true; // Rotate character to moving direction
GetCharacterMovement()->RotationRate = FRotator(0.f, 640.f, 0.f);
GetCharacterMovement()->bConstrainToPlane = true;
GetCharacterMovement()->bSnapToPlaneAtStart = true;
// Create a camera boom...
CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
CameraBoom =
CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
CameraBoom->SetupAttachment(RootComponent);
CameraBoom->SetUsingAbsoluteRotation(true); // Don't want arm to rotate when character does
CameraBoom->SetUsingAbsoluteRotation(
true); // Don't want arm to rotate when character does
CameraBoom->TargetArmLength = 800.f;
CameraBoom->SetRelativeRotation(FRotator(-60.f, 0.f, 0.f));
CameraBoom->bDoCollisionTest = false; // Don't want to pull camera in when it collides with level
CameraBoom->bDoCollisionTest =
false; // Don't want to pull camera in when it collides with level
// Create a camera...
TopDownCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("TopDownCamera"));
TopDownCameraComponent->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);
TopDownCameraComponent->bUsePawnControlRotation = false; // Camera does not rotate relative to arm
TopDownCameraComponent =
CreateDefaultSubobject<UCameraComponent>(TEXT("TopDownCamera"));
TopDownCameraComponent->SetupAttachment(CameraBoom,
USpringArmComponent::SocketName);
TopDownCameraComponent->bUsePawnControlRotation =
false; // Camera does not rotate relative to arm
// Activate ticking in order to update the cursor every frame.
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.bStartWithTickEnabled = true;
}
void AUTAD_UICharacter::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
Super::Tick(DeltaSeconds);
}

View File

@@ -18,17 +18,24 @@ public:
virtual void Tick(float DeltaSeconds) override;
/** Returns TopDownCameraComponent subobject **/
FORCEINLINE class UCameraComponent* GetTopDownCameraComponent() const { return TopDownCameraComponent; }
FORCEINLINE class UCameraComponent* GetTopDownCameraComponent() const
{
return TopDownCameraComponent;
}
/** Returns CameraBoom subobject **/
FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }
FORCEINLINE class USpringArmComponent* GetCameraBoom() const
{
return CameraBoom;
}
private:
/** Top down camera */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera,
meta = (AllowPrivateAccess = "true"))
class UCameraComponent* TopDownCameraComponent;
/** Camera boom positioning the camera above the character */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera,
meta = (AllowPrivateAccess = "true"))
class USpringArmComponent* CameraBoom;
};

View File

@@ -11,16 +11,19 @@ AUTAD_UIGameMode::AUTAD_UIGameMode()
PlayerControllerClass = AUTAD_UIPlayerController::StaticClass();
// set default pawn class to our Blueprinted character
static ConstructorHelpers::FClassFinder<APawn> PlayerPawnBPClass(TEXT("/Game/TopDown/Blueprints/BP_TopDownCharacter"));
static ConstructorHelpers::FClassFinder<APawn> PlayerPawnBPClass(
TEXT("/Game/TopDown/Blueprints/BP_TopDownCharacter"));
if (PlayerPawnBPClass.Class != nullptr)
{
DefaultPawnClass = PlayerPawnBPClass.Class;
}
// set default controller to our Blueprinted controller
static ConstructorHelpers::FClassFinder<APlayerController> PlayerControllerBPClass(TEXT("/Game/TopDown/Blueprints/BP_TopDownPlayerController"));
if(PlayerControllerBPClass.Class != NULL)
static ConstructorHelpers::FClassFinder<APlayerController>
PlayerControllerBPClass(
TEXT("/Game/TopDown/Blueprints/BP_TopDownPlayerController"));
if (PlayerControllerBPClass.Class != NULL)
{
PlayerControllerClass = PlayerControllerBPClass.Class;
}
}
}

View File

@@ -14,6 +14,3 @@ class AUTAD_UIGameMode : public AGameModeBase
public:
AUTAD_UIGameMode();
};

View File

@@ -16,15 +16,15 @@ DEFINE_LOG_CATEGORY(LogTemplateCharacter);
AUTAD_UIPlayerController::AUTAD_UIPlayerController()
{
bShowMouseCursor = true;
bShowMouseCursor = true;
DefaultMouseCursor = EMouseCursor::Default;
CachedDestination = FVector::ZeroVector;
FollowTime = 0.f;
CachedDestination = FVector::ZeroVector;
FollowTime = 0.f;
}
void AUTAD_UIPlayerController::BeginPlay()
{
// Call the base class
// Call the base class
Super::BeginPlay();
}
@@ -34,29 +34,52 @@ void AUTAD_UIPlayerController::SetupInputComponent()
Super::SetupInputComponent();
// Add Input Mapping Context
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer()))
if (UEnhancedInputLocalPlayerSubsystem* Subsystem =
ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(
GetLocalPlayer()))
{
Subsystem->AddMappingContext(DefaultMappingContext, 0);
}
// Set up action bindings
if (UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(InputComponent))
if (UEnhancedInputComponent* EnhancedInputComponent =
Cast<UEnhancedInputComponent>(InputComponent))
{
// Setup mouse input events
EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Started, this, &AUTAD_UIPlayerController::OnInputStarted);
EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Triggered, this, &AUTAD_UIPlayerController::OnSetDestinationTriggered);
EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Completed, this, &AUTAD_UIPlayerController::OnSetDestinationReleased);
EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Canceled, this, &AUTAD_UIPlayerController::OnSetDestinationReleased);
EnhancedInputComponent->BindAction(
SetDestinationClickAction, ETriggerEvent::Started, this,
&AUTAD_UIPlayerController::OnInputStarted);
EnhancedInputComponent->BindAction(
SetDestinationClickAction, ETriggerEvent::Triggered, this,
&AUTAD_UIPlayerController::OnSetDestinationTriggered);
EnhancedInputComponent->BindAction(
SetDestinationClickAction, ETriggerEvent::Completed, this,
&AUTAD_UIPlayerController::OnSetDestinationReleased);
EnhancedInputComponent->BindAction(
SetDestinationClickAction, ETriggerEvent::Canceled, this,
&AUTAD_UIPlayerController::OnSetDestinationReleased);
// Setup touch input events
EnhancedInputComponent->BindAction(SetDestinationTouchAction, ETriggerEvent::Started, this, &AUTAD_UIPlayerController::OnInputStarted);
EnhancedInputComponent->BindAction(SetDestinationTouchAction, ETriggerEvent::Triggered, this, &AUTAD_UIPlayerController::OnTouchTriggered);
EnhancedInputComponent->BindAction(SetDestinationTouchAction, ETriggerEvent::Completed, this, &AUTAD_UIPlayerController::OnTouchReleased);
EnhancedInputComponent->BindAction(SetDestinationTouchAction, ETriggerEvent::Canceled, this, &AUTAD_UIPlayerController::OnTouchReleased);
EnhancedInputComponent->BindAction(
SetDestinationTouchAction, ETriggerEvent::Started, this,
&AUTAD_UIPlayerController::OnInputStarted);
EnhancedInputComponent->BindAction(
SetDestinationTouchAction, ETriggerEvent::Triggered, this,
&AUTAD_UIPlayerController::OnTouchTriggered);
EnhancedInputComponent->BindAction(
SetDestinationTouchAction, ETriggerEvent::Completed, this,
&AUTAD_UIPlayerController::OnTouchReleased);
EnhancedInputComponent->BindAction(
SetDestinationTouchAction, ETriggerEvent::Canceled, this,
&AUTAD_UIPlayerController::OnTouchReleased);
}
else
{
UE_LOG(LogTemplateCharacter, Error, TEXT("'%s' Failed to find an Enhanced Input Component! This template is built to use the Enhanced Input system. If you intend to use the legacy system, then you will need to update this C++ file."), *GetNameSafe(this));
UE_LOG(
LogTemplateCharacter, Error,
TEXT(
"'%s' Failed to find an Enhanced Input Component! This template is built to use the Enhanced Input system. If you intend to use the legacy system, then you will need to update this C++ file."),
*GetNameSafe(this));
}
}
@@ -70,17 +93,20 @@ void AUTAD_UIPlayerController::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
// We look for the location in the world where the player has pressed the
// input
FHitResult Hit;
bool bHitSuccessful = false;
bool bHitSuccessful = false;
if (bIsTouch)
{
bHitSuccessful = GetHitResultUnderFinger(ETouchIndex::Touch1, ECollisionChannel::ECC_Visibility, true, Hit);
bHitSuccessful = GetHitResultUnderFinger(
ETouchIndex::Touch1, ECollisionChannel::ECC_Visibility, true, Hit);
}
else
{
bHitSuccessful = GetHitResultUnderCursor(ECollisionChannel::ECC_Visibility, true, Hit);
bHitSuccessful = GetHitResultUnderCursor(
ECollisionChannel::ECC_Visibility, true, Hit);
}
// If we hit a surface, cache the location
@@ -88,12 +114,14 @@ void AUTAD_UIPlayerController::OnSetDestinationTriggered()
{
CachedDestination = Hit.Location;
}
// Move towards mouse pointer or touch
APawn* ControlledPawn = GetPawn();
if (ControlledPawn != nullptr)
{
FVector WorldDirection = (CachedDestination - ControlledPawn->GetActorLocation()).GetSafeNormal();
FVector WorldDirection =
(CachedDestination - ControlledPawn->GetActorLocation())
.GetSafeNormal();
ControlledPawn->AddMovementInput(WorldDirection, 1.0, false);
}
}
@@ -104,8 +132,11 @@ void AUTAD_UIPlayerController::OnSetDestinationReleased()
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);
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;

View File

@@ -31,15 +31,18 @@ public:
UNiagaraSystem* FXCursor;
/** MappingContext */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true"))
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input,
meta = (AllowPrivateAccess = "true"))
UInputMappingContext* DefaultMappingContext;
/** Jump Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true"))
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input,
meta = (AllowPrivateAccess = "true"))
UInputAction* SetDestinationClickAction;
/** Jump Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true"))
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input,
meta = (AllowPrivateAccess = "true"))
UInputAction* SetDestinationTouchAction;
protected:
@@ -47,7 +50,7 @@ protected:
uint32 bMoveToMouseCursor : 1;
virtual void SetupInputComponent() override;
// To add mapping context
virtual void BeginPlay();
@@ -61,8 +64,6 @@ protected:
private:
FVector CachedDestination;
bool bIsTouch; // Is it a touch device
bool bIsTouch; // Is it a touch device
float FollowTime; // For how long it has been pressed
};