From 99707d1b73c6b9165e3e7ade1a4c99eb4e0448bc Mon Sep 17 00:00:00 2001 From: TjgL Date: Tue, 21 Jan 2025 16:32:31 +0100 Subject: [PATCH 1/3] 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; From f380b6c358ef82f76a3bfa6ac9718a3e0e89dd1c Mon Sep 17 00:00:00 2001 From: TjgL Date: Tue, 21 Jan 2025 16:52:55 +0100 Subject: [PATCH 2/3] Implemented weapon switching --- .../Legumix/Player/BP_PlayerController.uasset | 4 +- Content/Legumix/Player/Input/IA_Scroll.uasset | 3 ++ .../Legumix/Player/Input/IMC_Default.uasset | 4 +- .../Private/Player/LMPlayerController.cpp | 7 ++++ .../Private/Weapon/LMWeaponManager.cpp | 37 ++++++++++++------- .../Public/Player/LMPlayerController.h | 4 ++ .../LegumeMix/Public/Weapon/LMWeaponManager.h | 6 ++- 7 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 Content/Legumix/Player/Input/IA_Scroll.uasset diff --git a/Content/Legumix/Player/BP_PlayerController.uasset b/Content/Legumix/Player/BP_PlayerController.uasset index 70cbdfd..fac88f9 100644 --- a/Content/Legumix/Player/BP_PlayerController.uasset +++ b/Content/Legumix/Player/BP_PlayerController.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6a919743f7fbc6ec885b5d01157fdf18ce01885039406dbb482584129be4a0a0 -size 21190 +oid sha256:7651a3b0a3adbaa6cc2aa4907c29a4a112d232a215f9b9511f30f258f4ed83e8 +size 21387 diff --git a/Content/Legumix/Player/Input/IA_Scroll.uasset b/Content/Legumix/Player/Input/IA_Scroll.uasset new file mode 100644 index 0000000..b0f1bee --- /dev/null +++ b/Content/Legumix/Player/Input/IA_Scroll.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a644a26da4bb581689db8d5718d28cce453de39fb11ff18e5ddc428d7efbd221 +size 1588 diff --git a/Content/Legumix/Player/Input/IMC_Default.uasset b/Content/Legumix/Player/Input/IMC_Default.uasset index 064fac7..ee7bc6a 100644 --- a/Content/Legumix/Player/Input/IMC_Default.uasset +++ b/Content/Legumix/Player/Input/IMC_Default.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d49fb1f06fa5933d889da18c924c6bcbb92e213c6d7b54a29ef88406943d9396 -size 8619 +oid sha256:6c8b22e84568896085079b948cb41a5f2440fa9b67b6130412762911f838490d +size 9304 diff --git a/Source/LegumeMix/Private/Player/LMPlayerController.cpp b/Source/LegumeMix/Private/Player/LMPlayerController.cpp index 27bed09..47a8bba 100644 --- a/Source/LegumeMix/Private/Player/LMPlayerController.cpp +++ b/Source/LegumeMix/Private/Player/LMPlayerController.cpp @@ -26,6 +26,7 @@ void ALMPlayerController::SetupInputComponent() Input->BindAction(LookAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Look); Input->BindAction(FireAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Fire); Input->BindAction(ReloadAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Reload); + Input->BindAction(ScrollAction, ETriggerEvent::Triggered, this, &ALMPlayerController::Scroll); } } @@ -57,3 +58,9 @@ void ALMPlayerController::Reload(const FInputActionValue& InputValue) { LegumixPlayer->GetWeaponManager()->Reload(); } + +void ALMPlayerController::Scroll(const FInputActionValue& InputValue) +{ + const float ScrollAmount = InputValue.Get(); + LegumixPlayer->GetWeaponManager()->SwitchWeapon(ScrollAmount); +} diff --git a/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp b/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp index f026708..2717c4b 100644 --- a/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp +++ b/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp @@ -37,7 +37,7 @@ void ULMWeaponManager::Initialize(USkeletalMeshComponent* Mesh) } } -void ULMWeaponManager::AddAmmoType(uint8 AmmoType, int AmmoCount) +void ULMWeaponManager::AddAmmoType(EAmmoType AmmoType, int AmmoCount) { FString Debug = FString::Printf(TEXT("Adding %i ammo of type %i"), AmmoCount, AmmoType); GEngine->AddOnScreenDebugMessage(1, 1.f, FColor::Cyan, Debug); @@ -45,36 +45,47 @@ void ULMWeaponManager::AddAmmoType(uint8 AmmoType, int AmmoCount) for (const auto Weapon : Weapons) { // TODO : match weapon ammo type - if (!Weapon) + if (Weapon->WeaponDataStructure.AmmoType == AmmoType) continue; - // TODO - // Weapon.AddAmmo(AmmoCount); + Weapon->AddAmmo(AmmoCount); } } void ULMWeaponManager::Fire() { - // ULMWeapon* Weapon = GetCurrentWeapon(); + ULMWeapon* Weapon = GetCurrentWeapon(); GEngine->AddOnScreenDebugMessage(2, 1.f, FColor::Cyan, "Fire"); - // TODO + Weapon->Fire(); } void ULMWeaponManager::Reload() { GEngine->AddOnScreenDebugMessage(3, 1.f, FColor::Cyan, "Reloading"); - - // ULMWeapon* Weapon = GetCurrentWeapon(); - // TODO - // Weapon->Reload(); + ULMWeapon* Weapon = GetCurrentWeapon(); + Weapon->Reload(); } -void ULMWeaponManager::SetWeapon(int Index) +void ULMWeaponManager::SwitchWeapon(const int Direction) +{ + const int NewIndex = Direction + CurrentWeaponIndex; + if (NewIndex >= 0 && NewIndex < Weapons.Num()) + { + SetWeapon(NewIndex); + } + else + { + if (NewIndex < 0) + SetWeapon(Weapons.Num() - 1); + else + SetWeapon(0); + } +} + +void ULMWeaponManager::SetWeapon(const int Index) { - UE_LOG(LogTemp, Warning, TEXT("Test")) - if (Index < 0 || Index >= Weapons.Num()) { GEngine->AddOnScreenDebugMessage(INDEX_NONE, 5, FColor::Red, "Invalid Weapon Index"); diff --git a/Source/LegumeMix/Public/Player/LMPlayerController.h b/Source/LegumeMix/Public/Player/LMPlayerController.h index cd05666..dcf4e56 100644 --- a/Source/LegumeMix/Public/Player/LMPlayerController.h +++ b/Source/LegumeMix/Public/Player/LMPlayerController.h @@ -41,6 +41,9 @@ private: UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = true)) TObjectPtr ReloadAction; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = true)) + TObjectPtr ScrollAction; UPROPERTY(BlueprintReadOnly, meta = (AllowPrivateAccess = true)) TObjectPtr LegumixPlayer; @@ -51,4 +54,5 @@ private: void Look(const FInputActionValue& InputValue); void Fire(const FInputActionValue& InputValue); void Reload(const FInputActionValue& InputValue); + void Scroll(const FInputActionValue& InputValue); }; diff --git a/Source/LegumeMix/Public/Weapon/LMWeaponManager.h b/Source/LegumeMix/Public/Weapon/LMWeaponManager.h index 821a8e3..7103bfb 100644 --- a/Source/LegumeMix/Public/Weapon/LMWeaponManager.h +++ b/Source/LegumeMix/Public/Weapon/LMWeaponManager.h @@ -3,6 +3,7 @@ #pragma once #include "CoreMinimal.h" +#include "LMAmmo.h" #include "Components/ActorComponent.h" #include "LMWeaponManager.generated.h" @@ -30,14 +31,15 @@ public: void SetWeapon(int Index); UFUNCTION(BlueprintCallable, Category="Legumix") - void AddAmmoType(uint8 AmmoType, int AmmoCount); + void AddAmmoType(EAmmoType AmmoType, int AmmoCount); UFUNCTION(BlueprintCallable, Category="Legumix") void Fire(); UFUNCTION(BlueprintCallable, Category="Legumix") void Reload(); - + void SwitchWeapon(int Direction); + void Initialize(USkeletalMeshComponent* Mesh); protected: From 43b88bdae92e139fd24576d330b431cfeb39d72e Mon Sep 17 00:00:00 2001 From: TjgL Date: Tue, 21 Jan 2025 17:05:20 +0100 Subject: [PATCH 3/3] Added Mesh relative location to the weapon --- Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp b/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp index 2717c4b..e955737 100644 --- a/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp +++ b/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp @@ -14,6 +14,11 @@ ULMWeaponManager::ULMWeaponManager() void ULMWeaponManager::BeginPlay() { Super::BeginPlay(); +} + +void ULMWeaponManager::Initialize(USkeletalMeshComponent* Mesh) +{ + SetWeaponMeshComponent(Mesh); for (auto Weapon : StartingWeapons) { @@ -22,14 +27,9 @@ void ULMWeaponManager::BeginPlay() ULMWeapon* Instance = NewObject(this, Weapon); Weapons.Add(Instance); - Instance->Initialize(); + // Instance->Initialize(Mesh->GetRelativeLocation()); } } -} - -void ULMWeaponManager::Initialize(USkeletalMeshComponent* Mesh) -{ - SetWeaponMeshComponent(Mesh); if (!Weapons.IsEmpty()) {