Implemented weapon switching

This commit is contained in:
TjgL 2025-01-21 16:52:55 +01:00
parent 4361f1ebf2
commit f380b6c358
7 changed files with 46 additions and 19 deletions

Binary file not shown.

BIN
Content/Legumix/Player/Input/IA_Scroll.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

View File

@ -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<float>();
LegumixPlayer->GetWeaponManager()->SwitchWeapon(ScrollAmount);
}

View File

@ -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");

View File

@ -41,6 +41,9 @@ private:
UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = true))
TObjectPtr<UInputAction> ReloadAction;
UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = true))
TObjectPtr<UInputAction> ScrollAction;
UPROPERTY(BlueprintReadOnly, meta = (AllowPrivateAccess = true))
TObjectPtr<ALMPlayer> 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);
};

View File

@ -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: