Add Inventory basic shell

This commit is contained in:
Louis Hobbs 2023-01-01 23:59:59 +00:00
parent 14bb9eef74
commit f002cfa870
2 changed files with 128 additions and 31 deletions

View File

@ -199,3 +199,73 @@ void APlayerCharacter::CalculateHits(TArray<FHitResult>* hits)
// TODO: Handle hits in a meaningful way // TODO: Handle hits in a meaningful way
} }
} }
void APlayerCharacter::SetInventoryToDefault()
{
if (WeaponInventory.Num() > 0)
{
for (size_t i = 0; i < WeaponInventory.Num(); i++)
{
WeaponInventory[i]->Destroy();
}
WeaponInventory.Empty();
}
for (size_t i = 0; i < DefaultWeaponInventory.Num(); i++)
{
if (DefaultWeaponInventory[i])
{
AWeapon* weapon = InitializeWeapon(DefaultWeaponInventory[i]);
WeaponInventory.AddUnique(weapon);
}
}
if (WeaponInventory.Num() > 0)
{
CurrentInventorySlot = 0;
SetCurrentWeapon(WeaponInventory[CurrentInventorySlot]);
}
}
void APlayerCharacter::SelectInventorySlot(int slot)
{
if (slot < WeaponInventory.Num())
{
CurrentInventorySlot = slot;
SetCurrentWeapon(WeaponInventory[CurrentInventorySlot]);
}
}
void APlayerCharacter::InventoryIncrementCallback(const FInputActionInstance& Instance)
{
SelectInventorySlot((CurrentInventorySlot + 1) % WeaponInventory.Num());
}
void APlayerCharacter::InventoryDecrementCallback(const FInputActionInstance& Instance)
{
if (CurrentInventorySlot - 1 < 0)
{
SelectInventorySlot(WeaponInventory.Num() - 1);
}
else
{
SelectInventorySlot((CurrentInventorySlot - 1) % WeaponInventory.Num());
}
}
AWeapon* APlayerCharacter::InitializeWeapon(TSubclassOf<class AWeapon> weapon)
{
// TODO: All logic to spawn weapon into level then deactivate it until needed
return nullptr;
}
AWeapon* APlayerCharacter::GetCurrentWeapon()
{
return CurrentWeapon;
}
void APlayerCharacter::SetCurrentWeapon(AWeapon* weapon)
{
// TODO: Add setting weapon logic here
}

View File

@ -8,6 +8,7 @@
#include "InputActionValue.h" #include "InputActionValue.h"
#include "EnhancedInputComponent.h" #include "EnhancedInputComponent.h"
#include "NakatomiCharacter.h" #include "NakatomiCharacter.h"
#include "Weapon.h"
#include "PlayerCharacter.generated.h" #include "PlayerCharacter.generated.h"
class UInputAction; class UInputAction;
@ -22,37 +23,6 @@ class NAKATOMI_API APlayerCharacter : public ANakatomiCharacter
{ {
GENERATED_BODY() GENERATED_BODY()
public:
// Sets default values for this character's properties
APlayerCharacter();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
private:
UPROPERTY()
USpringArmComponent* CameraBoom = nullptr;
UPROPERTY()
UCameraComponent* CameraComponent = nullptr;
float DefaultMovementSpeed;
protected:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
float SprintSpeedMultiplier = 2.0f;
public: public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
@ -79,6 +49,49 @@ public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
int MappingPriority = 0; int MappingPriority = 0;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TArray<TSubclassOf<class AWeapon>> DefaultWeaponInventory;
UPROPERTY()
TArray<AWeapon*> WeaponInventory;
// TODO: Add weapon switching actions
protected:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
float SprintSpeedMultiplier = 2.0f;
private:
UPROPERTY()
USpringArmComponent* CameraBoom = nullptr;
UPROPERTY()
UCameraComponent* CameraComponent = nullptr;
float DefaultMovementSpeed;
int CurrentInventorySlot = 0;
UPROPERTY()
AWeapon* CurrentWeapon = nullptr;
public:
// Sets default values for this character's properties
APlayerCharacter();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
void MovementCallback(const FInputActionInstance& Instance); void MovementCallback(const FInputActionInstance& Instance);
void LookCallback(const FInputActionInstance& Instance); void LookCallback(const FInputActionInstance& Instance);
@ -94,4 +107,18 @@ public:
void SetWalkingCallback(const FInputActionInstance& Instance); void SetWalkingCallback(const FInputActionInstance& Instance);
void CalculateHits(TArray<FHitResult>* hits); void CalculateHits(TArray<FHitResult>* hits);
void SetInventoryToDefault();
void SelectInventorySlot(int slot);
void InventoryIncrementCallback(const FInputActionInstance& Instance);
void InventoryDecrementCallback(const FInputActionInstance& Instance);
AWeapon* InitializeWeapon(TSubclassOf<class AWeapon> weapon);
AWeapon* GetCurrentWeapon();
void SetCurrentWeapon(AWeapon* weapon);
}; };