diff --git a/Content/Assets/Textures/Crosshairs/Primary/Crosshair_Bottom.uasset b/Content/Assets/Textures/Crosshairs/Primary/Crosshair_Bottom.uasset new file mode 100644 index 0000000..957da0e Binary files /dev/null and b/Content/Assets/Textures/Crosshairs/Primary/Crosshair_Bottom.uasset differ diff --git a/Content/Assets/Textures/Crosshairs/Primary/Crosshair_Center.uasset b/Content/Assets/Textures/Crosshairs/Primary/Crosshair_Center.uasset new file mode 100644 index 0000000..e939fb7 Binary files /dev/null and b/Content/Assets/Textures/Crosshairs/Primary/Crosshair_Center.uasset differ diff --git a/Content/Assets/Textures/Crosshairs/Primary/Crosshair_Left.uasset b/Content/Assets/Textures/Crosshairs/Primary/Crosshair_Left.uasset new file mode 100644 index 0000000..748b07c Binary files /dev/null and b/Content/Assets/Textures/Crosshairs/Primary/Crosshair_Left.uasset differ diff --git a/Content/Assets/Textures/Crosshairs/Primary/Crosshair_Right.uasset b/Content/Assets/Textures/Crosshairs/Primary/Crosshair_Right.uasset new file mode 100644 index 0000000..0af5345 Binary files /dev/null and b/Content/Assets/Textures/Crosshairs/Primary/Crosshair_Right.uasset differ diff --git a/Content/Assets/Textures/Crosshairs/Primary/Crosshair_Top.uasset b/Content/Assets/Textures/Crosshairs/Primary/Crosshair_Top.uasset new file mode 100644 index 0000000..0d3dfef Binary files /dev/null and b/Content/Assets/Textures/Crosshairs/Primary/Crosshair_Top.uasset differ diff --git a/Content/Assets/Textures/Crosshairs/Primary/DefaultCrosshair.uasset b/Content/Assets/Textures/Crosshairs/Primary/DefaultCrosshair.uasset new file mode 100644 index 0000000..b3711cc Binary files /dev/null and b/Content/Assets/Textures/Crosshairs/Primary/DefaultCrosshair.uasset differ diff --git a/Content/Blueprints/GameModes/BP_BlasterGameMode.uasset b/Content/Blueprints/GameModes/BP_BlasterGameMode.uasset index 2455cb4..aa6573f 100644 Binary files a/Content/Blueprints/GameModes/BP_BlasterGameMode.uasset and b/Content/Blueprints/GameModes/BP_BlasterGameMode.uasset differ diff --git a/Content/Blueprints/HUD/BP_BlasterHUD.uasset b/Content/Blueprints/HUD/BP_BlasterHUD.uasset new file mode 100644 index 0000000..4e6c0da Binary files /dev/null and b/Content/Blueprints/HUD/BP_BlasterHUD.uasset differ diff --git a/Content/Blueprints/PlayerController/BP_BlasterPlayerController.uasset b/Content/Blueprints/PlayerController/BP_BlasterPlayerController.uasset new file mode 100644 index 0000000..0388b9b Binary files /dev/null and b/Content/Blueprints/PlayerController/BP_BlasterPlayerController.uasset differ diff --git a/Content/Blueprints/Weapon/BP_AssaultRifle.uasset b/Content/Blueprints/Weapon/BP_AssaultRifle.uasset index 21fc721..9064d82 100644 Binary files a/Content/Blueprints/Weapon/BP_AssaultRifle.uasset and b/Content/Blueprints/Weapon/BP_AssaultRifle.uasset differ diff --git a/Source/Blaster/Components/CombatComponent.cpp b/Source/Blaster/Components/CombatComponent.cpp index 5f7bf29..9d51a6e 100644 --- a/Source/Blaster/Components/CombatComponent.cpp +++ b/Source/Blaster/Components/CombatComponent.cpp @@ -4,6 +4,8 @@ #include "CombatComponent.h" #include "Blaster/Character/BlasterCharacter.h" +#include "Blaster/HUD/BlasterHUD.h" +#include "Blaster/PlayerController/BlasterPlayerController.h" #include "Blaster/Weapon/Weapon.h" #include "Engine/SkeletalMeshSocket.h" #include "GameFramework/CharacterMovementComponent.h" @@ -36,6 +38,47 @@ void UCombatComponent::BeginPlay() } } +void UCombatComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +{ + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + + SetHUDCrosshairs(DeltaTime); +} + +void UCombatComponent::SetHUDCrosshairs(float DeltaTime) +{ + if (Character == nullptr || Character->Controller == nullptr) return; + + Controller = Controller == nullptr ? Cast(Character->Controller) : Controller; + if (Controller) + { + HUD = HUD == nullptr ? Cast(Controller->GetHUD()) : HUD; + if (HUD) + { + FHUDPackage HUDPackage; + + if (EquippedWeapon) + { + HUDPackage.CrosshairsCenter = EquippedWeapon->CrosshairsCenter; + HUDPackage.CrosshairsLeft = EquippedWeapon->CrosshairsLeft; + HUDPackage.CrosshairsRight = EquippedWeapon->CrosshairsRight; + HUDPackage.CrosshairsTop = EquippedWeapon->CrosshairsTop; + HUDPackage.CrosshairsBottom = EquippedWeapon->CrosshairsBottom; + } + else + { + HUDPackage.CrosshairsCenter = nullptr; + HUDPackage.CrosshairsLeft = nullptr; + HUDPackage.CrosshairsRight = nullptr; + HUDPackage.CrosshairsTop = nullptr; + HUDPackage.CrosshairsBottom = nullptr; + } + + HUD->SetHUDPackage(HUDPackage); + } + } +} + void UCombatComponent::SetAiming(bool bIsAiming) { bAiming = bIsAiming; @@ -123,11 +166,6 @@ void UCombatComponent::MulticastFire_Implementation(const FVector_NetQuantize& T } } -void UCombatComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) -{ - Super::TickComponent(DeltaTime, TickType, ThisTickFunction); -} - void UCombatComponent::EquipWeapon(AWeapon* WeaponToEquip) { if (Character == nullptr || WeaponToEquip == nullptr) return; diff --git a/Source/Blaster/Components/CombatComponent.h b/Source/Blaster/Components/CombatComponent.h index a2a2a70..2e25cde 100644 --- a/Source/Blaster/Components/CombatComponent.h +++ b/Source/Blaster/Components/CombatComponent.h @@ -41,9 +41,13 @@ protected: void MulticastFire(const FVector_NetQuantize& TraceHitTarget); void TraceUnderCrosshairs(FHitResult& TraceHitResult); + + void SetHUDCrosshairs(float DeltaTime); private: class ABlasterCharacter* Character; + class ABlasterPlayerController* Controller; + class ABlasterHUD* HUD; UPROPERTY(ReplicatedUsing=OnRep_EquippedWeapon) class AWeapon* EquippedWeapon; diff --git a/Source/Blaster/HUD/BlasterHUD.cpp b/Source/Blaster/HUD/BlasterHUD.cpp new file mode 100644 index 0000000..2f7eece --- /dev/null +++ b/Source/Blaster/HUD/BlasterHUD.cpp @@ -0,0 +1,11 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "BlasterHUD.h" + +void ABlasterHUD::DrawHUD() +{ + Super::DrawHUD(); + + +} diff --git a/Source/Blaster/HUD/BlasterHUD.h b/Source/Blaster/HUD/BlasterHUD.h new file mode 100644 index 0000000..c12a473 --- /dev/null +++ b/Source/Blaster/HUD/BlasterHUD.h @@ -0,0 +1,38 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/HUD.h" +#include "BlasterHUD.generated.h" + +USTRUCT(BlueprintType) +struct FHUDPackage +{ + GENERATED_BODY() + +public: + UTexture2D* CrosshairsCenter; + UTexture2D* CrosshairsLeft; + UTexture2D* CrosshairsRight; + UTexture2D* CrosshairsTop; + UTexture2D* CrosshairsBottom; +}; + +/** + * + */ +UCLASS() +class BLASTER_API ABlasterHUD : public AHUD +{ + GENERATED_BODY() + +public: + virtual void DrawHUD() override; + +private: + FHUDPackage HUDPackage; + +public: + FORCEINLINE void SetHUDPackage(const FHUDPackage& Package) { HUDPackage = Package; }; +}; diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.cpp b/Source/Blaster/PlayerController/BlasterPlayerController.cpp new file mode 100644 index 0000000..1e0f308 --- /dev/null +++ b/Source/Blaster/PlayerController/BlasterPlayerController.cpp @@ -0,0 +1,5 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "BlasterPlayerController.h" + diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.h b/Source/Blaster/PlayerController/BlasterPlayerController.h new file mode 100644 index 0000000..1398b46 --- /dev/null +++ b/Source/Blaster/PlayerController/BlasterPlayerController.h @@ -0,0 +1,17 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/PlayerController.h" +#include "BlasterPlayerController.generated.h" + +/** + * + */ +UCLASS() +class BLASTER_API ABlasterPlayerController : public APlayerController +{ + GENERATED_BODY() + +}; diff --git a/Source/Blaster/Weapon/Weapon.h b/Source/Blaster/Weapon/Weapon.h index daaf321..2682438 100644 --- a/Source/Blaster/Weapon/Weapon.h +++ b/Source/Blaster/Weapon/Weapon.h @@ -27,6 +27,23 @@ public: void ShowPickupWidget(bool bShowWidget); virtual void Fire(const FVector& HitTarget); + // Textures for the weapon crosshairs + + UPROPERTY(EditAnywhere, Category= Crosshairs) + class UTexture2D* CrosshairsCenter; + + UPROPERTY(EditAnywhere, Category= Crosshairs) + class UTexture2D* CrosshairsLeft; + + UPROPERTY(EditAnywhere, Category= Crosshairs) + class UTexture2D* CrosshairsRight; + + UPROPERTY(EditAnywhere, Category= Crosshairs) + class UTexture2D* CrosshairsTop; + + UPROPERTY(EditAnywhere, Category= Crosshairs) + class UTexture2D* CrosshairsBottom; + protected: virtual void BeginPlay() override; @@ -69,6 +86,8 @@ private: UPROPERTY(EditAnywhere, Category= "Weapon Properties") TSubclassOf CasingClass; + + public: void SetWeaponState(EWeaponState State); FORCEINLINE USphereComponent* GetAreaSphere() const { return AreaSphere; }