From 99707d1b73c6b9165e3e7ade1a4c99eb4e0448bc Mon Sep 17 00:00:00 2001 From: TjgL Date: Tue, 21 Jan 2025 16:32:31 +0100 Subject: [PATCH] Added player weapon display --- Content/Legumix/Player/BP_Player.uasset | 4 +-- .../Legumix/Weapon/BP_WeaponManager.uasset | 3 +++ .../Weapon/BP_WeaponManagerComponent.uasset | 3 --- Content/Legumix/Weapon/DT_WeaponData.uasset | 4 +-- Source/LegumeMix/Private/Player/LMPlayer.cpp | 25 +++++++++++++++---- .../Private/Weapon/LMWeaponManager.cpp | 17 +++++++++---- Source/LegumeMix/Public/Player/LMPlayer.h | 9 ++++++- .../Public/Weapon/LMWeaponDataStructure.h | 2 +- .../LegumeMix/Public/Weapon/LMWeaponManager.h | 2 ++ 9 files changed, 50 insertions(+), 19 deletions(-) create mode 100644 Content/Legumix/Weapon/BP_WeaponManager.uasset delete mode 100644 Content/Legumix/Weapon/BP_WeaponManagerComponent.uasset diff --git a/Content/Legumix/Player/BP_Player.uasset b/Content/Legumix/Player/BP_Player.uasset index 53b0c53..a92705a 100644 --- a/Content/Legumix/Player/BP_Player.uasset +++ b/Content/Legumix/Player/BP_Player.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2db256cc9494b901f3f24e4b4d66f8d720b60fba52d250d031e334c0cfd5b5fc -size 35424 +oid sha256:a1b36ac7333d2d6b72f26ce3e384ba1dcee67208a17231d67c021037a7e9f4f0 +size 42647 diff --git a/Content/Legumix/Weapon/BP_WeaponManager.uasset b/Content/Legumix/Weapon/BP_WeaponManager.uasset new file mode 100644 index 0000000..0d3685c --- /dev/null +++ b/Content/Legumix/Weapon/BP_WeaponManager.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:76dde9bd31fe7b9c92b2537215bc3a2b4fc67a3ea9fd83ccf9faa93d1af0d962 +size 15175 diff --git a/Content/Legumix/Weapon/BP_WeaponManagerComponent.uasset b/Content/Legumix/Weapon/BP_WeaponManagerComponent.uasset deleted file mode 100644 index d90bc05..0000000 --- a/Content/Legumix/Weapon/BP_WeaponManagerComponent.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:792b2f2ab7e6dc725e9fbb7d949aa7d8ac23483a5ce1508c109ad5973dd1c474 -size 14988 diff --git a/Content/Legumix/Weapon/DT_WeaponData.uasset b/Content/Legumix/Weapon/DT_WeaponData.uasset index b51c224..a6daba6 100644 --- a/Content/Legumix/Weapon/DT_WeaponData.uasset +++ b/Content/Legumix/Weapon/DT_WeaponData.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5cfe70137cb69fab53bd2763dd2e3dd1545953a6fa9d88e84cebbcccf6562962 -size 2501 +oid sha256:a4e50014771a56604730976892111daf8f7eceaaf986ef12884bc79b1b54bd5a +size 2838 diff --git a/Source/LegumeMix/Private/Player/LMPlayer.cpp b/Source/LegumeMix/Private/Player/LMPlayer.cpp index ea031d4..6d3e825 100644 --- a/Source/LegumeMix/Private/Player/LMPlayer.cpp +++ b/Source/LegumeMix/Private/Player/LMPlayer.cpp @@ -3,18 +3,20 @@ #include "Player/LMPlayer.h" +#include "Camera/CameraComponent.h" #include "Weapon/LMWeaponManager.h" ALMPlayer::ALMPlayer() { PrimaryActorTick.bCanEverTick = true; - - WeaponManager = CreateDefaultSubobject(TEXT("Weapon Manager")); + + Camera = CreateDefaultSubobject(TEXT("Camera")); + Camera->SetupAttachment(RootComponent); + Camera->bUsePawnControlRotation = true; + Camera->SetRelativeLocation(FVector(20, 0, 90)); WeaponSkeletalMeshComponent = CreateDefaultSubobject(TEXT("Weapon Mesh")); - WeaponSkeletalMeshComponent->SetupAttachment(GetMesh()); - - WeaponManager->SetWeaponMeshComponent(WeaponSkeletalMeshComponent); + WeaponSkeletalMeshComponent->SetupAttachment(Camera); } void ALMPlayer::BeginPlay() @@ -22,6 +24,19 @@ void ALMPlayer::BeginPlay() Super::BeginPlay(); } +void ALMPlayer::SetWeaponManager(ULMWeaponManager* Manager) +{ + UE_LOG(LogTemp, Warning, TEXT("Set weapon manager")) + if (!Manager) + { + GEngine->AddOnScreenDebugMessage(INDEX_NONE, 10.f, FColor::Red, TEXT("No Weapon Manager was given to the player !")); + return; + } + + WeaponManager = Manager; + WeaponManager->Initialize(WeaponSkeletalMeshComponent); +} + void ALMPlayer::Tick(float DeltaTime) { Super::Tick(DeltaTime); diff --git a/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp b/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp index f54eb11..f026708 100644 --- a/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp +++ b/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp @@ -21,12 +21,16 @@ void ULMWeaponManager::BeginPlay() { ULMWeapon* Instance = NewObject(this, Weapon); Weapons.Add(Instance); - - // TODO - // Instance->Initialize(); + + Instance->Initialize(); } } +} +void ULMWeaponManager::Initialize(USkeletalMeshComponent* Mesh) +{ + SetWeaponMeshComponent(Mesh); + if (!Weapons.IsEmpty()) { SetWeapon(CurrentWeaponIndex); @@ -69,6 +73,8 @@ void ULMWeaponManager::Reload() void ULMWeaponManager::SetWeapon(int Index) { + UE_LOG(LogTemp, Warning, TEXT("Test")) + if (Index < 0 || Index >= Weapons.Num()) { GEngine->AddOnScreenDebugMessage(INDEX_NONE, 5, FColor::Red, "Invalid Weapon Index"); @@ -79,8 +85,9 @@ void ULMWeaponManager::SetWeapon(int Index) if (WeaponMeshComponent) { - // TODO - // WeaponMeshComponent->SetSkeletalMesh() + GEngine->AddOnScreenDebugMessage(INDEX_NONE, 5, FColor::Red, "Has Mesh"); + + WeaponMeshComponent->SetSkeletalMeshAsset(GetCurrentWeapon()->WeaponDataStructure.MeshWeapon); } } diff --git a/Source/LegumeMix/Public/Player/LMPlayer.h b/Source/LegumeMix/Public/Player/LMPlayer.h index 49ddd12..6bd8424 100644 --- a/Source/LegumeMix/Public/Player/LMPlayer.h +++ b/Source/LegumeMix/Public/Player/LMPlayer.h @@ -6,6 +6,7 @@ #include "GameFramework/Character.h" #include "LMPlayer.generated.h" +class UCameraComponent; class ULMWeaponManager; UCLASS() @@ -25,10 +26,16 @@ public: UFUNCTION(BlueprintCallable) ULMWeaponManager* GetWeaponManager() { return WeaponManager; } + UFUNCTION(BlueprintCallable) + void SetWeaponManager(ULMWeaponManager* Manager); + private: - UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Legumix", meta = (AllowPrivateAccess = true)) + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Legumix", meta = (AllowPrivateAccess = true)) TObjectPtr WeaponManager; UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Legumix", meta = (AllowPrivateAccess = true)) TObjectPtr WeaponSkeletalMeshComponent; + + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Legumix", meta = (AllowPrivateAccess = true)) + TObjectPtr Camera; }; diff --git a/Source/LegumeMix/Public/Weapon/LMWeaponDataStructure.h b/Source/LegumeMix/Public/Weapon/LMWeaponDataStructure.h index 1fe5db6..053242a 100644 --- a/Source/LegumeMix/Public/Weapon/LMWeaponDataStructure.h +++ b/Source/LegumeMix/Public/Weapon/LMWeaponDataStructure.h @@ -14,7 +14,7 @@ struct FLMWeaponDataStructure : public FTableRowBase int MaxClipAmmo; // Max ammo in clip UPROPERTY(EditAnywhere, BlueprintReadWrite) - TObjectPtr MeshWeapon; //Mesh of the weapon display in the scene + TObjectPtr MeshWeapon; //Mesh of the weapon display in the scene //UPROPERTY(EditAnywhere, BlueprintReadWrite) //enum AmmoType; //Type of ammo, which ammo this weapon is using diff --git a/Source/LegumeMix/Public/Weapon/LMWeaponManager.h b/Source/LegumeMix/Public/Weapon/LMWeaponManager.h index 7a5caaf..821a8e3 100644 --- a/Source/LegumeMix/Public/Weapon/LMWeaponManager.h +++ b/Source/LegumeMix/Public/Weapon/LMWeaponManager.h @@ -37,6 +37,8 @@ public: UFUNCTION(BlueprintCallable, Category="Legumix") void Reload(); + + void Initialize(USkeletalMeshComponent* Mesh); protected: virtual void BeginPlay() override;