diff --git a/Content/Input/Actions/IA_WeaponSwitch.uasset b/Content/Input/Actions/IA_WeaponSwitch.uasset new file mode 100644 index 0000000..8fc0206 --- /dev/null +++ b/Content/Input/Actions/IA_WeaponSwitch.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:69fb02016ce62a4dca1a347a28c8c340856712ee75ece8211f61b34fd079dbde +size 1513 diff --git a/Content/Input/InputMappingContext.uasset b/Content/Input/InputMappingContext.uasset index 4d91964..6f8adae 100644 --- a/Content/Input/InputMappingContext.uasset +++ b/Content/Input/InputMappingContext.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:247279665e6f5fecf7430d0bdb52896c1aae05cb19c9bbb815dcfdef5624177a -size 12564 +oid sha256:a202b29c730ab629b30f7d68ef530e107901a18a9f345104f62b9ccbb1aaa2ac +size 13853 diff --git a/Content/Player/PlayerCharacter.uasset b/Content/Player/PlayerCharacter.uasset index 4d1b64b..f54bf2e 100644 --- a/Content/Player/PlayerCharacter.uasset +++ b/Content/Player/PlayerCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e7c46b9017224ae2a60fad721043f7786d5a1ad40253e0ef36cf323fea3a6d59 -size 31959 +oid sha256:c50e63e849de9b3e967762abaeaf3e5f319ba84d811b3cffd6985ae4aa5eb1a3 +size 32403 diff --git a/Source/Nakatomi/PlayerCharacter.cpp b/Source/Nakatomi/PlayerCharacter.cpp index 10dd940..8ad09f8 100644 --- a/Source/Nakatomi/PlayerCharacter.cpp +++ b/Source/Nakatomi/PlayerCharacter.cpp @@ -107,6 +107,11 @@ void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCom Input->BindAction(SprintAction, ETriggerEvent::Started, this, &APlayerCharacter::SetSprintingCallback); Input->BindAction(SprintAction, ETriggerEvent::Completed, this, &APlayerCharacter::SetWalkingCallback); } + + if (WeaponSwitchingAction) + { + Input->BindAction(WeaponSwitchingAction, ETriggerEvent::Triggered, this, &APlayerCharacter::WeaponSwitchingCallback); + } } } @@ -229,7 +234,7 @@ void APlayerCharacter::SetInventoryToDefault() } void APlayerCharacter::SelectInventorySlot(int slot) -{ +{ if (slot < WeaponInventory.Num()) { CurrentInventorySlot = slot; @@ -237,20 +242,40 @@ void APlayerCharacter::SelectInventorySlot(int slot) } } -void APlayerCharacter::InventoryIncrementCallback(const FInputActionInstance& Instance) +void APlayerCharacter::WeaponSwitchingCallback(const FInputActionInstance& Instance) { - SelectInventorySlot((CurrentInventorySlot + 1) % WeaponInventory.Num()); -} + float value = Instance.GetValue().Get(); -void APlayerCharacter::InventoryDecrementCallback(const FInputActionInstance& Instance) -{ - if (CurrentInventorySlot - 1 < 0) + if (value > 0) { - SelectInventorySlot(WeaponInventory.Num() - 1); + InventoryIncrement(); } else { - SelectInventorySlot((CurrentInventorySlot - 1) % WeaponInventory.Num()); + InventoryDecrement(); + } +} + +void APlayerCharacter::InventoryIncrement() +{ + if (WeaponInventory.Num() > 0) + { + SelectInventorySlot((CurrentInventorySlot + 1) % WeaponInventory.Num()); + } +} + +void APlayerCharacter::InventoryDecrement() +{ + if (WeaponInventory.Num() > 0) + { + if (CurrentInventorySlot - 1 < 0) + { + SelectInventorySlot(WeaponInventory.Num() - 1); + } + else + { + SelectInventorySlot((CurrentInventorySlot - 1) % WeaponInventory.Num()); + } } } diff --git a/Source/Nakatomi/PlayerCharacter.h b/Source/Nakatomi/PlayerCharacter.h index 83c244e..c907883 100644 --- a/Source/Nakatomi/PlayerCharacter.h +++ b/Source/Nakatomi/PlayerCharacter.h @@ -55,7 +55,8 @@ public: UPROPERTY() TArray WeaponInventory; - // TODO: Add weapon switching actions + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) + UInputAction* WeaponSwitchingAction; protected: @@ -112,9 +113,11 @@ public: void SelectInventorySlot(int slot); - void InventoryIncrementCallback(const FInputActionInstance& Instance); + void WeaponSwitchingCallback(const FInputActionInstance& Instance); - void InventoryDecrementCallback(const FInputActionInstance& Instance); + void InventoryIncrement(); + + void InventoryDecrement(); AWeapon* InitializeWeapon(TSubclassOf weapon);