Compare commits
No commits in common. "eae0dbb80288621b686f34b620b6ba1fcf3c35dd" and "09d795600cc70cbdb6944f07c308226f9f233334" have entirely different histories.
eae0dbb802
...
09d795600c
BIN
Content/Player/BP_PlayerCharacter.uasset (Stored with Git LFS)
BIN
Content/Player/BP_PlayerCharacter.uasset (Stored with Git LFS)
Binary file not shown.
BIN
Content/Player/BP_PlayerController.uasset (Stored with Git LFS)
BIN
Content/Player/BP_PlayerController.uasset (Stored with Git LFS)
Binary file not shown.
|
@ -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.
|
|
|
@ -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();
|
|
||||||
};
|
|
|
@ -56,6 +56,31 @@ void APlayerCharacter::BeginPlay()
|
||||||
Super::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()
|
UEXPComponent* APlayerCharacter::GetEXPComponent()
|
||||||
{
|
{
|
||||||
return EXPComponent;
|
return EXPComponent;
|
||||||
|
@ -65,3 +90,14 @@ UGoldComponent* APlayerCharacter::GetGoldComponent()
|
||||||
{
|
{
|
||||||
return GoldComponent;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -31,6 +31,12 @@ public:
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
UCameraComponent* CameraComponent = nullptr;
|
UCameraComponent* CameraComponent = nullptr;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
|
TSoftObjectPtr<UInputMappingContext> InputMappingContext;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
|
UInputAction* MovementAction;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
UEXPComponent* EXPComponent;
|
UEXPComponent* EXPComponent;
|
||||||
|
|
||||||
|
@ -45,14 +51,23 @@ public:
|
||||||
UPROPERTY(EditAnywhere)
|
UPROPERTY(EditAnywhere)
|
||||||
UWidgetComponent* HealthBarWidgetComponent;
|
UWidgetComponent* HealthBarWidgetComponent;
|
||||||
|
|
||||||
|
private:
|
||||||
|
FTimerHandle GarlicTimerHandle;
|
||||||
|
|
||||||
|
public:
|
||||||
APlayerCharacter();
|
APlayerCharacter();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override;
|
||||||
|
|
||||||
UEXPComponent* GetEXPComponent();
|
UEXPComponent* GetEXPComponent();
|
||||||
|
|
||||||
UGoldComponent* GetGoldComponent();
|
UGoldComponent* GetGoldComponent();
|
||||||
|
|
||||||
|
private:
|
||||||
|
UFUNCTION()
|
||||||
|
void MovementCallback(const FInputActionInstance& Instance);
|
||||||
};
|
};
|
||||||
|
|
|
@ -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)
|
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
||||||
{
|
|
||||||
AddMovementInput({0.0f, 1.0f, 0.0f}, value.Y);
|
|
||||||
AddMovementInput({1.0f, 0.0f, 0.0f}, value.X);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UInputMappingContext* AVampireCharacter::Input_GetInputMappingContext_Implementation()
|
|
||||||
{
|
|
||||||
return InputMappingContext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UHealthComponent* AVampireCharacter::GetHealthComponent()
|
UHealthComponent* AVampireCharacter::GetHealthComponent()
|
||||||
|
|
|
@ -3,16 +3,14 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "Inputable.h"
|
|
||||||
#include "GameFramework/Character.h"
|
#include "GameFramework/Character.h"
|
||||||
#include "VampireCharacter.generated.h"
|
#include "VampireCharacter.generated.h"
|
||||||
|
|
||||||
class UInputAction;
|
|
||||||
class UHealthComponent;
|
class UHealthComponent;
|
||||||
class UPaperFlipbookComponent;
|
class UPaperFlipbookComponent;
|
||||||
|
|
||||||
UCLASS(Abstract)
|
UCLASS()
|
||||||
class VAMPIRES_API AVampireCharacter : public ACharacter, public IInputable
|
class VAMPIRES_API AVampireCharacter : public ACharacter
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
@ -24,9 +22,6 @@ protected:
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
UHealthComponent* HealthComponent;
|
UHealthComponent* HealthComponent;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
|
||||||
TObjectPtr<UInputMappingContext> InputMappingContext;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Sets default values for this character's properties
|
// Sets default values for this character's properties
|
||||||
AVampireCharacter();
|
AVampireCharacter();
|
||||||
|
@ -39,9 +34,8 @@ public:
|
||||||
// Called every frame
|
// Called every frame
|
||||||
virtual void Tick(float DeltaTime) override;
|
virtual void Tick(float DeltaTime) override;
|
||||||
|
|
||||||
virtual void Input_Move_Implementation(FVector2D value) override;
|
// Called to bind functionality to input
|
||||||
|
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||||
virtual UInputMappingContext* Input_GetInputMappingContext_Implementation() override;
|
|
||||||
|
|
||||||
UHealthComponent* GetHealthComponent();
|
UHealthComponent* GetHealthComponent();
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,10 +3,7 @@
|
||||||
|
|
||||||
#include "VampirePlayerController.h"
|
#include "VampirePlayerController.h"
|
||||||
|
|
||||||
#include "EnhancedInputComponent.h"
|
|
||||||
#include "EnhancedInputSubsystems.h"
|
|
||||||
#include "EXPComponent.h"
|
#include "EXPComponent.h"
|
||||||
#include "Inputable.h"
|
|
||||||
#include "VampireGameMode.h"
|
#include "VampireGameMode.h"
|
||||||
#include "Blueprint/UserWidget.h"
|
#include "Blueprint/UserWidget.h"
|
||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
@ -16,14 +13,6 @@ void AVampirePlayerController::OnPossess(APawn* aPawn)
|
||||||
{
|
{
|
||||||
Super::OnPossess(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)
|
if (PlayerHUD)
|
||||||
{
|
{
|
||||||
currentPlayerHUD = CreateWidget<UHUDWidget, AVampirePlayerController*>(this, PlayerHUD.Get());
|
currentPlayerHUD = CreateWidget<UHUDWidget, AVampirePlayerController*>(this, PlayerHUD.Get());
|
||||||
|
@ -58,29 +47,6 @@ void AVampirePlayerController::OnUnPossess()
|
||||||
GetWorld()->GetTimerManager().ClearTimer(pawnLifeTimeHandle);
|
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)
|
void AVampirePlayerController::UpdatePlayerEXPHUD(int exp, float currentLevelPercent)
|
||||||
{
|
{
|
||||||
if (currentPlayerHUD)
|
if (currentPlayerHUD)
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
#include "GameFramework/PlayerController.h"
|
#include "GameFramework/PlayerController.h"
|
||||||
#include "VampirePlayerController.generated.h"
|
#include "VampirePlayerController.generated.h"
|
||||||
|
|
||||||
class UInputAction;
|
|
||||||
class UHUDWidget;
|
class UHUDWidget;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -21,11 +20,6 @@ public:
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
TSubclassOf<UHUDWidget> PlayerHUD = nullptr;
|
TSubclassOf<UHUDWidget> PlayerHUD = nullptr;
|
||||||
|
|
||||||
// Inputs
|
|
||||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
|
||||||
UInputAction* MovementAction;
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
TObjectPtr<UHUDWidget> currentPlayerHUD = nullptr;
|
TObjectPtr<UHUDWidget> currentPlayerHUD = nullptr;
|
||||||
|
@ -37,11 +31,6 @@ protected:
|
||||||
|
|
||||||
virtual void OnUnPossess() override;
|
virtual void OnUnPossess() override;
|
||||||
|
|
||||||
virtual void SetupInputComponent() override;
|
|
||||||
|
|
||||||
UFUNCTION()
|
|
||||||
void Move(const FInputActionValue& MovementInput);
|
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void UpdatePlayerEXPHUD(int exp, float currentLevelPercent);
|
void UpdatePlayerEXPHUD(int exp, float currentLevelPercent);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue