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() void ALMPlayer::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
WeaponManager->WeaponFired.AddUniqueDynamic(this, &ALMPlayer::WeaponFired);
WeaponManager->WeaponSwitched.AddUniqueDynamic(this, &ALMPlayer::WeaponSwitched);
} }
void ALMPlayer::PickUpAmmo(ALMAmmo* Ammo) void ALMPlayer::PickUpAmmo(ALMAmmo* Ammo)
@ -78,6 +79,8 @@ void ALMPlayer::FireBullets(const FLMBulletInfo Settings)
FHitResult OutHit = FHitResult(); FHitResult OutHit = FHitResult();
bool HitSomething = false; bool HitSomething = false;
OnFire();
DrawDebugLine(GetWorld(), Settings.Origin, Settings.Origin + (Settings.Direction * Settings.MaxDistance), FColor::Blue, false, 2.f); DrawDebugLine(GetWorld(), Settings.Origin, Settings.Origin + (Settings.Direction * Settings.MaxDistance), FColor::Blue, false, 2.f);
for (int Shots = 0; Shots < Settings.BulletCount; Shots++) for (int Shots = 0; Shots < Settings.BulletCount; Shots++)
@ -121,14 +124,3 @@ FVector ALMPlayer::GetWeaponFiringOrigin() const
FVector ALMPlayer::GetAimVector() const { return Camera->GetForwardVector(); } 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 // TODO: Use Animations
OnDefaultReload(); OnDefaultReload();
GetWorldTimerManager().SetTimer(ReloadTimer, this, &ALMWeaponBase::AllowRefire, ReloadDelay); GetWorldTimerManager().SetTimer(ReloadTimer, this, &ALMWeaponBase::AllowRefire, ReloadDelay);
Player->OnReload();
return true; return true;
} }

View File

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

View File

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

View File

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