From f380b6c358ef82f76a3bfa6ac9718a3e0e89dd1c Mon Sep 17 00:00:00 2001 From: TjgL Date: Tue, 21 Jan 2025 16:52:55 +0100 Subject: [PATCH] Implemented weapon switching --- .../Legumix/Player/BP_PlayerController.uasset | 4 +- Content/Legumix/Player/Input/IA_Scroll.uasset | 3 ++ .../Legumix/Player/Input/IMC_Default.uasset | 4 +- .../Private/Player/LMPlayerController.cpp | 7 ++++ .../Private/Weapon/LMWeaponManager.cpp | 37 ++++++++++++------- .../Public/Player/LMPlayerController.h | 4 ++ .../LegumeMix/Public/Weapon/LMWeaponManager.h | 6 ++- 7 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 Content/Legumix/Player/Input/IA_Scroll.uasset diff --git a/Content/Legumix/Player/BP_PlayerController.uasset b/Content/Legumix/Player/BP_PlayerController.uasset index 70cbdfd..fac88f9 100644 --- a/Content/Legumix/Player/BP_PlayerController.uasset +++ b/Content/Legumix/Player/BP_PlayerController.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6a919743f7fbc6ec885b5d01157fdf18ce01885039406dbb482584129be4a0a0 -size 21190 +oid sha256:7651a3b0a3adbaa6cc2aa4907c29a4a112d232a215f9b9511f30f258f4ed83e8 +size 21387 diff --git a/Content/Legumix/Player/Input/IA_Scroll.uasset b/Content/Legumix/Player/Input/IA_Scroll.uasset new file mode 100644 index 0000000..b0f1bee --- /dev/null +++ b/Content/Legumix/Player/Input/IA_Scroll.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a644a26da4bb581689db8d5718d28cce453de39fb11ff18e5ddc428d7efbd221 +size 1588 diff --git a/Content/Legumix/Player/Input/IMC_Default.uasset b/Content/Legumix/Player/Input/IMC_Default.uasset index 064fac7..ee7bc6a 100644 --- a/Content/Legumix/Player/Input/IMC_Default.uasset +++ b/Content/Legumix/Player/Input/IMC_Default.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d49fb1f06fa5933d889da18c924c6bcbb92e213c6d7b54a29ef88406943d9396 -size 8619 +oid sha256:6c8b22e84568896085079b948cb41a5f2440fa9b67b6130412762911f838490d +size 9304 diff --git a/Source/LegumeMix/Private/Player/LMPlayerController.cpp b/Source/LegumeMix/Private/Player/LMPlayerController.cpp index 27bed09..47a8bba 100644 --- a/Source/LegumeMix/Private/Player/LMPlayerController.cpp +++ b/Source/LegumeMix/Private/Player/LMPlayerController.cpp @@ -26,6 +26,7 @@ void ALMPlayerController::SetupInputComponent() Input->BindAction(LookAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Look); Input->BindAction(FireAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Fire); Input->BindAction(ReloadAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Reload); + Input->BindAction(ScrollAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Scroll); } } @@ -57,3 +58,9 @@ void ALMPlayerController::Reload(const FInputActionValue& InputValue) { LegumixPlayer->GetWeaponManager()->Reload(); } + +void ALMPlayerController::Scroll(const FInputActionValue& InputValue) +{ + const float ScrollAmount = InputValue.Get(); + LegumixPlayer->GetWeaponManager()->SwitchWeapon(ScrollAmount); +} diff --git a/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp b/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp index f026708..2717c4b 100644 --- a/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp +++ b/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp @@ -37,7 +37,7 @@ void ULMWeaponManager::Initialize(USkeletalMeshComponent* Mesh) } } -void ULMWeaponManager::AddAmmoType(uint8 AmmoType, int AmmoCount) +void ULMWeaponManager::AddAmmoType(EAmmoType AmmoType, int AmmoCount) { FString Debug = FString::Printf(TEXT("Adding %i ammo of type %i"), AmmoCount, AmmoType); GEngine->AddOnScreenDebugMessage(1, 1.f, FColor::Cyan, Debug); @@ -45,36 +45,47 @@ void ULMWeaponManager::AddAmmoType(uint8 AmmoType, int AmmoCount) for (const auto Weapon : Weapons) { // TODO : match weapon ammo type - if (!Weapon) + if (Weapon->WeaponDataStructure.AmmoType == AmmoType) continue; - // TODO - // Weapon.AddAmmo(AmmoCount); + Weapon->AddAmmo(AmmoCount); } } void ULMWeaponManager::Fire() { - // ULMWeapon* Weapon = GetCurrentWeapon(); + ULMWeapon* Weapon = GetCurrentWeapon(); GEngine->AddOnScreenDebugMessage(2, 1.f, FColor::Cyan, "Fire"); - // TODO + Weapon->Fire(); } void ULMWeaponManager::Reload() { GEngine->AddOnScreenDebugMessage(3, 1.f, FColor::Cyan, "Reloading"); - - // ULMWeapon* Weapon = GetCurrentWeapon(); - // TODO - // Weapon->Reload(); + ULMWeapon* Weapon = GetCurrentWeapon(); + Weapon->Reload(); } -void ULMWeaponManager::SetWeapon(int Index) +void ULMWeaponManager::SwitchWeapon(const int Direction) +{ + const int NewIndex = Direction + CurrentWeaponIndex; + if (NewIndex >= 0 && NewIndex < Weapons.Num()) + { + SetWeapon(NewIndex); + } + else + { + if (NewIndex < 0) + SetWeapon(Weapons.Num() - 1); + else + SetWeapon(0); + } +} + +void ULMWeaponManager::SetWeapon(const int Index) { - UE_LOG(LogTemp, Warning, TEXT("Test")) - if (Index < 0 || Index >= Weapons.Num()) { GEngine->AddOnScreenDebugMessage(INDEX_NONE, 5, FColor::Red, "Invalid Weapon Index"); diff --git a/Source/LegumeMix/Public/Player/LMPlayerController.h b/Source/LegumeMix/Public/Player/LMPlayerController.h index cd05666..dcf4e56 100644 --- a/Source/LegumeMix/Public/Player/LMPlayerController.h +++ b/Source/LegumeMix/Public/Player/LMPlayerController.h @@ -41,6 +41,9 @@ private: UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = true)) TObjectPtr ReloadAction; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = true)) + TObjectPtr ScrollAction; UPROPERTY(BlueprintReadOnly, meta = (AllowPrivateAccess = true)) TObjectPtr LegumixPlayer; @@ -51,4 +54,5 @@ private: void Look(const FInputActionValue& InputValue); void Fire(const FInputActionValue& InputValue); void Reload(const FInputActionValue& InputValue); + void Scroll(const FInputActionValue& InputValue); }; diff --git a/Source/LegumeMix/Public/Weapon/LMWeaponManager.h b/Source/LegumeMix/Public/Weapon/LMWeaponManager.h index 821a8e3..7103bfb 100644 --- a/Source/LegumeMix/Public/Weapon/LMWeaponManager.h +++ b/Source/LegumeMix/Public/Weapon/LMWeaponManager.h @@ -3,6 +3,7 @@ #pragma once #include "CoreMinimal.h" +#include "LMAmmo.h" #include "Components/ActorComponent.h" #include "LMWeaponManager.generated.h" @@ -30,14 +31,15 @@ public: void SetWeapon(int Index); UFUNCTION(BlueprintCallable, Category="Legumix") - void AddAmmoType(uint8 AmmoType, int AmmoCount); + void AddAmmoType(EAmmoType AmmoType, int AmmoCount); UFUNCTION(BlueprintCallable, Category="Legumix") void Fire(); UFUNCTION(BlueprintCallable, Category="Legumix") void Reload(); - + void SwitchWeapon(int Direction); + void Initialize(USkeletalMeshComponent* Mesh); protected: