diff --git a/Content/Blueprints/HUD/WBP_CharacterOverlay.uasset b/Content/Blueprints/HUD/WBP_CharacterOverlay.uasset index b31c20a..18c0edc 100644 Binary files a/Content/Blueprints/HUD/WBP_CharacterOverlay.uasset and b/Content/Blueprints/HUD/WBP_CharacterOverlay.uasset differ diff --git a/Source/Blaster/Components/CombatComponent.cpp b/Source/Blaster/Components/CombatComponent.cpp index 7e3468e..6cf456e 100644 --- a/Source/Blaster/Components/CombatComponent.cpp +++ b/Source/Blaster/Components/CombatComponent.cpp @@ -25,6 +25,7 @@ void UCombatComponent::GetLifetimeReplicatedProps(TArray& Out Super::GetLifetimeReplicatedProps(OutLifetimeProps); DOREPLIFETIME(UCombatComponent, EquippedWeapon); + DOREPLIFETIME_CONDITION(UCombatComponent, CarriedAmmo, COND_OwnerOnly); DOREPLIFETIME(UCombatComponent, bAiming); } @@ -216,6 +217,10 @@ bool UCombatComponent::CanFire() return !EquippedWeapon->IsEmpty() || !bCanFire; } +void UCombatComponent::OnRep_CarriedAmmo() +{ +} + void UCombatComponent::ServerFire_Implementation(const FVector_NetQuantize& TraceHitTarget) { MulticastFire(TraceHitTarget); diff --git a/Source/Blaster/Components/CombatComponent.h b/Source/Blaster/Components/CombatComponent.h index ce1fc43..c8c8686 100644 --- a/Source/Blaster/Components/CombatComponent.h +++ b/Source/Blaster/Components/CombatComponent.h @@ -4,6 +4,7 @@ #include "CoreMinimal.h" #include "Blaster/HUD/BlasterHUD.h" +#include "Blaster/Weapon/WeaponTypes.h" #include "Components/ActorComponent.h" #include "CombatComponent.generated.h" @@ -100,4 +101,13 @@ private: void FireTimerFinished(); bool CanFire(); + + // Carried ammo for the currently equipped weapon + UPROPERTY(ReplicatedUsing=OnRep_CarriedAmmo) + int32 CarriedAmmo; + + UFUNCTION() + void OnRep_CarriedAmmo(); + + TMap CarriedAmmoMap; }; diff --git a/Source/Blaster/HUD/CharacterOverlay.h b/Source/Blaster/HUD/CharacterOverlay.h index e996edf..58c181f 100644 --- a/Source/Blaster/HUD/CharacterOverlay.h +++ b/Source/Blaster/HUD/CharacterOverlay.h @@ -31,4 +31,7 @@ public: UPROPERTY(meta = (BindWidget)) UTextBlock* WeaponAmmoValue; + UPROPERTY(meta = (BindWidget)) + UTextBlock* CarriedAmmoValue; + }; diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.cpp b/Source/Blaster/PlayerController/BlasterPlayerController.cpp index ada3f41..7c1ed29 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.cpp +++ b/Source/Blaster/PlayerController/BlasterPlayerController.cpp @@ -89,3 +89,18 @@ void ABlasterPlayerController::SetHUDWeaponAmmo(int32 Ammo) BlasterHUD->CharacterOverlay->WeaponAmmoValue->SetText(FText::FromString(WeaponAmmoAmount)); } } + +void ABlasterPlayerController::SetHUDCarriedAmmo(int32 Ammo) +{ + BlasterHUD = BlasterHUD == nullptr ? Cast(GetHUD()) : BlasterHUD; + bool bHUDValid = + BlasterHUD && + BlasterHUD->CharacterOverlay && + BlasterHUD->CharacterOverlay->CarriedAmmoValue; + + if (bHUDValid) + { + const FString CarriedAmmoAmount = FString::Printf(TEXT("%d"), Ammo); + BlasterHUD->CharacterOverlay->CarriedAmmoValue->SetText(FText::FromString(CarriedAmmoAmount)); + } +} diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.h b/Source/Blaster/PlayerController/BlasterPlayerController.h index ace19be..44d3b9b 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.h +++ b/Source/Blaster/PlayerController/BlasterPlayerController.h @@ -20,6 +20,7 @@ public: void SetHUDScore(float Score); void SetHUDDefeats(int32 Defeats); void SetHUDWeaponAmmo(int32 Ammo); + void SetHUDCarriedAmmo(int32 Ammo); virtual void OnPossess(APawn* InPawn) override; protected: diff --git a/Source/Blaster/Weapon/WeaponTypes.h b/Source/Blaster/Weapon/WeaponTypes.h new file mode 100644 index 0000000..cd36a2a --- /dev/null +++ b/Source/Blaster/Weapon/WeaponTypes.h @@ -0,0 +1,9 @@ +#pragma once + +UENUM(BlueprintType) +enum class EWeaponType: uint8 +{ + EWT_AssaultRifle UMETA(DisplayName="Assault Rifle"), + + EWT_MAX UMETA(DisplayName="DefaultMAX") +}; \ No newline at end of file