Added ammo display

This commit is contained in:
TjgL 2025-01-24 16:55:36 +01:00
parent d29abeba74
commit 5e21302abf
8 changed files with 40 additions and 22 deletions

BIN
Content/Legumix/Player/BP_Play.uasset (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -31,7 +31,8 @@ ALMPlayer::ALMPlayer()
void ALMPlayer::BeginPlay()
{
Super::BeginPlay();
WeaponManager->WeaponFired.AddUniqueDynamic(this, &ALMPlayer::WeaponFired);
WeaponManager->WeaponSwitched.AddUniqueDynamic(this, &ALMPlayer::WeaponSwitched);
}
void ALMPlayer::PickUpAmmo(ALMAmmo* Ammo)
@ -78,6 +79,8 @@ void ALMPlayer::FireBullets(const FLMBulletInfo Settings)
FHitResult OutHit = FHitResult();
bool HitSomething = false;
OnFire();
DrawDebugLine(GetWorld(), Settings.Origin, Settings.Origin + (Settings.Direction * Settings.MaxDistance), FColor::Blue, false, 2.f);
for (int Shots = 0; Shots < Settings.BulletCount; Shots++)
@ -121,14 +124,3 @@ FVector ALMPlayer::GetWeaponFiringOrigin() const
FVector ALMPlayer::GetAimVector() const { return Camera->GetForwardVector(); }
void ALMPlayer::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void ALMPlayer::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}

View File

@ -94,6 +94,7 @@ bool ALMWeaponBase::DefaultReload()
// TODO: Use Animations
OnDefaultReload();
GetWorldTimerManager().SetTimer(ReloadTimer, this, &ALMWeaponBase::AllowRefire, ReloadDelay);
Player->OnReload();
return true;
}

View File

@ -120,7 +120,10 @@ void ULMWeaponManager::Fire()
ALMWeaponBase* Weapon = GetCurrentWeapon();
if (Weapon->State == EWeaponState::EWS_Idle)
{
Weapon->PrimaryFire();
WeaponFired.Broadcast();
}
}
void ULMWeaponManager::Reload()
@ -128,7 +131,9 @@ void ULMWeaponManager::Reload()
ALMWeaponBase* Weapon = GetCurrentWeapon();
if (Weapon->State == EWeaponState::EWS_Idle)
{
Weapon->Reload();
}
}
void ULMWeaponManager::SwitchWeapon(const int Direction)
@ -160,5 +165,6 @@ void ULMWeaponManager::SetWeapon(const int Index)
GetCurrentWeapon()->SetActorHiddenInGame(false);
GetCurrentWeapon()->OnEquip();
WeaponSwitched.Broadcast();
}

View File

@ -21,8 +21,6 @@ class LEGUMEMIX_API ALMPlayer : public ACharacter
public:
// Sets default values for this character's properties
ALMPlayer();
virtual void Tick(float DeltaTime) override;
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
UFUNCTION(BlueprintCallable)
void PickUpAmmo(ALMAmmo* Ammo);
@ -67,8 +65,22 @@ public:
UFUNCTION(BlueprintCallable)
FVector GetAimVector() const;
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent)
void WeaponFired();
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent)
void WeaponReloaded();
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent)
void WeaponSwitched();
UFUNCTION(BlueprintImplementableEvent)
void OnEnnemyHit();
UFUNCTION(BlueprintImplementableEvent, Category=Legumix)
void OnFire();
UFUNCTION(BlueprintImplementableEvent, Category=Legumix)
void OnReload();
private:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix, meta = (AllowPrivateAccess = true))

View File

@ -16,6 +16,9 @@ class LEGUMEMIX_API ULMWeaponManager : public UActorComponent
{
GENERATED_BODY()
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnWeaponFiredSignature);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnWeaponSwitchedSignature);
public:
ULMWeaponManager();
void SetArmsMesh(USkeletalMeshComponent* Mesh) { ArmsMesh = Mesh; }
@ -50,6 +53,12 @@ public:
UFUNCTION(BlueprintCallable, Category="Legumix|Ammo")
int RemoveAmmo(EAmmoType Ammo, int Count);
public:
UPROPERTY(BlueprintAssignable, BlueprintCallable, Category=Legumix)
FOnWeaponFiredSignature WeaponFired;
UPROPERTY(BlueprintAssignable, BlueprintCallable, Category=Legumix)
FOnWeaponFiredSignature WeaponSwitched;
protected:
virtual void BeginPlay() override;
// virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
@ -74,6 +83,4 @@ private:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Legumix|Ammo", meta=(AllowPrivateAccess=true))
TMap<EAmmoType, FLMAmmoData> AmmoData;
};