diff --git a/Source/Nakatomi/PlayerCharacter.cpp b/Source/Nakatomi/PlayerCharacter.cpp index a1a67b1..10dd940 100644 --- a/Source/Nakatomi/PlayerCharacter.cpp +++ b/Source/Nakatomi/PlayerCharacter.cpp @@ -199,3 +199,73 @@ void APlayerCharacter::CalculateHits(TArray* hits) // 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 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 +} diff --git a/Source/Nakatomi/PlayerCharacter.h b/Source/Nakatomi/PlayerCharacter.h index 907c14d..83c244e 100644 --- a/Source/Nakatomi/PlayerCharacter.h +++ b/Source/Nakatomi/PlayerCharacter.h @@ -8,6 +8,7 @@ #include "InputActionValue.h" #include "EnhancedInputComponent.h" #include "NakatomiCharacter.h" +#include "Weapon.h" #include "PlayerCharacter.generated.h" class UInputAction; @@ -22,37 +23,6 @@ class NAKATOMI_API APlayerCharacter : public ANakatomiCharacter { 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: UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) @@ -79,6 +49,49 @@ public: UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) int MappingPriority = 0; + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) + TArray> DefaultWeaponInventory; + + UPROPERTY() + TArray 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 LookCallback(const FInputActionInstance& Instance); @@ -94,4 +107,18 @@ public: void SetWalkingCallback(const FInputActionInstance& Instance); void CalculateHits(TArray* hits); + + void SetInventoryToDefault(); + + void SelectInventorySlot(int slot); + + void InventoryIncrementCallback(const FInputActionInstance& Instance); + + void InventoryDecrementCallback(const FInputActionInstance& Instance); + + AWeapon* InitializeWeapon(TSubclassOf weapon); + + AWeapon* GetCurrentWeapon(); + + void SetCurrentWeapon(AWeapon* weapon); };