From 5e21302abff760de49d1e20ecd187da3f6b6889f Mon Sep 17 00:00:00 2001 From: TjgL Date: Fri, 24 Jan 2025 16:55:36 +0100 Subject: [PATCH] Added ammo display --- Content/Legumix/Player/BP_Play.uasset | 4 ++-- Content/Legumix/Player/HUD/WB_MainHud.uasset | 4 ++-- Content/Legumix/Weapon/Shotgun/BP_Shotgun.uasset | 4 ++-- Source/LegumeMix/Private/Player/LMPlayer.cpp | 16 ++++------------ Source/LegumeMix/Private/Weapon/LMWeaponBase.cpp | 1 + .../LegumeMix/Private/Weapon/LMWeaponManager.cpp | 6 ++++++ Source/LegumeMix/Public/Player/LMPlayer.h | 16 ++++++++++++++-- Source/LegumeMix/Public/Weapon/LMWeaponManager.h | 11 +++++++++-- 8 files changed, 40 insertions(+), 22 deletions(-) diff --git a/Content/Legumix/Player/BP_Play.uasset b/Content/Legumix/Player/BP_Play.uasset index cd9ccf5..50f85be 100644 --- a/Content/Legumix/Player/BP_Play.uasset +++ b/Content/Legumix/Player/BP_Play.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fb44ad5503f9723d8d3982501153a258736f914ab8d9b7c90fc5107d91ca8d06 -size 60081 +oid sha256:d33fb3d583b26fe2280e7a18d4d290dff5d8ab81fd61d2c00ce4342f411e51a7 +size 88178 diff --git a/Content/Legumix/Player/HUD/WB_MainHud.uasset b/Content/Legumix/Player/HUD/WB_MainHud.uasset index 96c7a0f..bfd8536 100644 --- a/Content/Legumix/Player/HUD/WB_MainHud.uasset +++ b/Content/Legumix/Player/HUD/WB_MainHud.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2e06fcaef99549326fa8abcb7ba18051b9d2463c4d7217af1cf01bf8de3a8907 -size 53918 +oid sha256:85f2aa819dadc172bd145befbaed168ed89a5d7f97be74a0c601f3ca02b737d4 +size 94904 diff --git a/Content/Legumix/Weapon/Shotgun/BP_Shotgun.uasset b/Content/Legumix/Weapon/Shotgun/BP_Shotgun.uasset index e33519d..fa3de52 100644 --- a/Content/Legumix/Weapon/Shotgun/BP_Shotgun.uasset +++ b/Content/Legumix/Weapon/Shotgun/BP_Shotgun.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9dd0a8e5040d5424636e6702e52106f5b214a756aa6be25262a44713f92200ac -size 56008 +oid sha256:8ee277b97db6e41a88b1881c97f10352040b92a750b60d39633d1cfe70789b77 +size 56079 diff --git a/Source/LegumeMix/Private/Player/LMPlayer.cpp b/Source/LegumeMix/Private/Player/LMPlayer.cpp index b00c0bd..38bf943 100644 --- a/Source/LegumeMix/Private/Player/LMPlayer.cpp +++ b/Source/LegumeMix/Private/Player/LMPlayer.cpp @@ -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); - -} - diff --git a/Source/LegumeMix/Private/Weapon/LMWeaponBase.cpp b/Source/LegumeMix/Private/Weapon/LMWeaponBase.cpp index 9b83164..0fea6c3 100644 --- a/Source/LegumeMix/Private/Weapon/LMWeaponBase.cpp +++ b/Source/LegumeMix/Private/Weapon/LMWeaponBase.cpp @@ -94,6 +94,7 @@ bool ALMWeaponBase::DefaultReload() // TODO: Use Animations OnDefaultReload(); GetWorldTimerManager().SetTimer(ReloadTimer, this, &ALMWeaponBase::AllowRefire, ReloadDelay); + Player->OnReload(); return true; } diff --git a/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp b/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp index 8e9e1b8..b158020 100644 --- a/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp +++ b/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp @@ -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(); } diff --git a/Source/LegumeMix/Public/Player/LMPlayer.h b/Source/LegumeMix/Public/Player/LMPlayer.h index 0093fad..f404d6c 100644 --- a/Source/LegumeMix/Public/Player/LMPlayer.h +++ b/Source/LegumeMix/Public/Player/LMPlayer.h @@ -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)) diff --git a/Source/LegumeMix/Public/Weapon/LMWeaponManager.h b/Source/LegumeMix/Public/Weapon/LMWeaponManager.h index b3959a3..0c451c3 100644 --- a/Source/LegumeMix/Public/Weapon/LMWeaponManager.h +++ b/Source/LegumeMix/Public/Weapon/LMWeaponManager.h @@ -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 AmmoData; - - };