Compare commits

..

No commits in common. "eae0dbb80288621b686f34b620b6ba1fcf3c35dd" and "09d795600cc70cbdb6944f07c308226f9f233334" have entirely different histories.

10 changed files with 62 additions and 106 deletions

BIN
Content/Player/BP_PlayerCharacter.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Player/BP_PlayerController.uasset (Stored with Git LFS)

Binary file not shown.

View File

@ -1,7 +0,0 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Inputable.h"
// Add default functionality here for any IInputtable functions that are not pure virtual.

View File

@ -1,30 +0,0 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "Inputable.generated.h"
class UInputMappingContext;
// This class does not need to be modified.
UINTERFACE()
class UInputable : public UInterface
{
GENERATED_BODY()
};
/**
*
*/
class VAMPIRES_API IInputable
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
void Input_Move(FVector2D value);
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
UInputMappingContext* Input_GetInputMappingContext();
};

View File

@ -56,6 +56,31 @@ void APlayerCharacter::BeginPlay()
Super::BeginPlay();
}
void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
if (AVampirePlayerController* TankPlayerController = Cast<AVampirePlayerController>(GetController()))
{
if (UEnhancedInputLocalPlayerSubsystem* InputSystem = ULocalPlayer::GetSubsystem<
UEnhancedInputLocalPlayerSubsystem>(TankPlayerController->GetLocalPlayer()))
{
if (!InputMappingContext.IsNull())
{
InputSystem->AddMappingContext(InputMappingContext.LoadSynchronous(), 0);
}
}
}
if (UEnhancedInputComponent* Input = Cast<UEnhancedInputComponent>(PlayerInputComponent))
{
if (MovementAction)
{
Input->BindAction(MovementAction, ETriggerEvent::Triggered, this, &APlayerCharacter::MovementCallback);
}
}
}
UEXPComponent* APlayerCharacter::GetEXPComponent()
{
return EXPComponent;
@ -65,3 +90,14 @@ UGoldComponent* APlayerCharacter::GetGoldComponent()
{
return GoldComponent;
}
void APlayerCharacter::MovementCallback(const FInputActionInstance& Instance)
{
PreviousMovementDirection = Instance.GetValue().Get<FVector2D>();
if (PreviousMovementDirection.Size() != 0.0f)
{
AddMovementInput({0.0f, 1.0f, 0.0f}, PreviousMovementDirection.Y);
AddMovementInput({1.0f, 0.0f, 0.0f}, PreviousMovementDirection.X);
}
}

View File

@ -31,6 +31,12 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UCameraComponent* CameraComponent = nullptr;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TSoftObjectPtr<UInputMappingContext> InputMappingContext;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
UInputAction* MovementAction;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UEXPComponent* EXPComponent;
@ -45,14 +51,23 @@ public:
UPROPERTY(EditAnywhere)
UWidgetComponent* HealthBarWidgetComponent;
private:
FTimerHandle GarlicTimerHandle;
public:
APlayerCharacter();
protected:
virtual void BeginPlay() override;
public:
virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override;
UEXPComponent* GetEXPComponent();
UGoldComponent* GetGoldComponent();
private:
UFUNCTION()
void MovementCallback(const FInputActionInstance& Instance);
};

View File

@ -35,18 +35,11 @@ void AVampireCharacter::Tick(float DeltaTime)
}
void AVampireCharacter::Input_Move_Implementation(FVector2D value)
// Called to bind functionality to input
void AVampireCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
if (value.Size() != 0.0f)
{
AddMovementInput({0.0f, 1.0f, 0.0f}, value.Y);
AddMovementInput({1.0f, 0.0f, 0.0f}, value.X);
}
}
Super::SetupPlayerInputComponent(PlayerInputComponent);
UInputMappingContext* AVampireCharacter::Input_GetInputMappingContext_Implementation()
{
return InputMappingContext;
}
UHealthComponent* AVampireCharacter::GetHealthComponent()

View File

@ -3,16 +3,14 @@
#pragma once
#include "CoreMinimal.h"
#include "Inputable.h"
#include "GameFramework/Character.h"
#include "VampireCharacter.generated.h"
class UInputAction;
class UHealthComponent;
class UPaperFlipbookComponent;
UCLASS(Abstract)
class VAMPIRES_API AVampireCharacter : public ACharacter, public IInputable
UCLASS()
class VAMPIRES_API AVampireCharacter : public ACharacter
{
GENERATED_BODY()
@ -24,9 +22,6 @@ protected:
UPROPERTY()
UHealthComponent* HealthComponent;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TObjectPtr<UInputMappingContext> InputMappingContext;
public:
// Sets default values for this character's properties
AVampireCharacter();
@ -39,9 +34,8 @@ public:
// Called every frame
virtual void Tick(float DeltaTime) override;
virtual void Input_Move_Implementation(FVector2D value) override;
virtual UInputMappingContext* Input_GetInputMappingContext_Implementation() override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
UHealthComponent* GetHealthComponent();
};

View File

@ -3,10 +3,7 @@
#include "VampirePlayerController.h"
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "EXPComponent.h"
#include "Inputable.h"
#include "VampireGameMode.h"
#include "Blueprint/UserWidget.h"
#include "Kismet/GameplayStatics.h"
@ -16,14 +13,6 @@ void AVampirePlayerController::OnPossess(APawn* aPawn)
{
Super::OnPossess(aPawn);
if (UEnhancedInputLocalPlayerSubsystem* subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer()))
{
if (UKismetSystemLibrary::DoesImplementInterface(aPawn, UInputable::StaticClass()))
{
subsystem->AddMappingContext(IInputable::Execute_Input_GetInputMappingContext(aPawn), 0);
}
}
if (PlayerHUD)
{
currentPlayerHUD = CreateWidget<UHUDWidget, AVampirePlayerController*>(this, PlayerHUD.Get());
@ -58,29 +47,6 @@ void AVampirePlayerController::OnUnPossess()
GetWorld()->GetTimerManager().ClearTimer(pawnLifeTimeHandle);
}
void AVampirePlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
if (UEnhancedInputComponent* EIP = CastChecked<UEnhancedInputComponent>(InputComponent))
{
EIP->BindAction(MovementAction, ETriggerEvent::Triggered, this, &AVampirePlayerController::Move);
}
}
void AVampirePlayerController::Move(const FInputActionValue& MovementInput)
{
FVector2D movement = MovementInput.Get<FVector2D>();
if (APawn* pawn = GetPawn())
{
if (UKismetSystemLibrary::DoesImplementInterface(pawn, UInputable::StaticClass()))
{
IInputable::Execute_Input_Move(pawn, movement);
}
}
}
void AVampirePlayerController::UpdatePlayerEXPHUD(int exp, float currentLevelPercent)
{
if (currentPlayerHUD)

View File

@ -6,7 +6,6 @@
#include "GameFramework/PlayerController.h"
#include "VampirePlayerController.generated.h"
class UInputAction;
class UHUDWidget;
/**
*
@ -21,11 +20,6 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TSubclassOf<UHUDWidget> PlayerHUD = nullptr;
// Inputs
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
UInputAction* MovementAction;
private:
TObjectPtr<UHUDWidget> currentPlayerHUD = nullptr;
@ -37,11 +31,6 @@ protected:
virtual void OnUnPossess() override;
virtual void SetupInputComponent() override;
UFUNCTION()
void Move(const FInputActionValue& MovementInput);
UFUNCTION()
void UpdatePlayerEXPHUD(int exp, float currentLevelPercent);