diff --git a/Content/Legumix/Player/BP_Player.uasset b/Content/Legumix/Player/BP_Player.uasset index 0f797c6..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:d13142befdccaf0a6e255f0ba55b1fbbfe764f1846950d8b6088aa3d00eca516 -size 34593 +oid sha256:a1b36ac7333d2d6b72f26ce3e384ba1dcee67208a17231d67c021037a7e9f4f0 +size 42647 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/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/Source/LegumeMix/Private/Player/LMPlayer.cpp b/Source/LegumeMix/Private/Player/LMPlayer.cpp index 135d138..517a912 100644 --- a/Source/LegumeMix/Private/Player/LMPlayer.cpp +++ b/Source/LegumeMix/Private/Player/LMPlayer.cpp @@ -2,6 +2,8 @@ #include "Player/LMPlayer.h" + +#include "Camera/CameraComponent.h" #include "Weapon/LMAmmo.h" #include "Weapon/LMWeaponManager.h" @@ -9,13 +11,14 @@ ALMPlayer::ALMPlayer() { // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it. 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); } // Called when the game starts or when spawned @@ -34,6 +37,19 @@ void ALMPlayer::PickUpAmmo(ALMAmmo* Ammo) } } +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); +} + // Called every frame void ALMPlayer::Tick(float DeltaTime) { 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/LMBazoucorn.cpp b/Source/LegumeMix/Private/Weapon/LMBazoucorn.cpp index 9cc48fa..89e6651 100644 --- a/Source/LegumeMix/Private/Weapon/LMBazoucorn.cpp +++ b/Source/LegumeMix/Private/Weapon/LMBazoucorn.cpp @@ -3,7 +3,7 @@ #include "Weapon\LMBazoucorn.h" -void ULMWeapon::Fire() +void UBazoucorn::Fire() { //Fire like a Bazoucorn } diff --git a/Source/LegumeMix/Private/Weapon/LMRadivolver.cpp b/Source/LegumeMix/Private/Weapon/LMRadivolver.cpp index 21d995a..ed3587e 100644 --- a/Source/LegumeMix/Private/Weapon/LMRadivolver.cpp +++ b/Source/LegumeMix/Private/Weapon/LMRadivolver.cpp @@ -3,7 +3,7 @@ #include "Weapon/LMRadivolver.h" -void ULMWeapon::Fire() +void ULMRadivolver::Fire() { //Fire like a Radivolver } diff --git a/Source/LegumeMix/Private/Weapon/LMWeapon.cpp b/Source/LegumeMix/Private/Weapon/LMWeapon.cpp index 16d8a30..375c413 100644 --- a/Source/LegumeMix/Private/Weapon/LMWeapon.cpp +++ b/Source/LegumeMix/Private/Weapon/LMWeapon.cpp @@ -5,6 +5,8 @@ void ULMWeapon::Initialize() { WeaponDataStructure =* WeaponRow.GetRow(TEXT("")); + + //Get FVector de la position de l'arme } bool ULMWeapon::HasAmmoInClip() diff --git a/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp b/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp index f54eb11..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) { @@ -21,19 +26,18 @@ void ULMWeaponManager::BeginPlay() { ULMWeapon* Instance = NewObject(this, Weapon); Weapons.Add(Instance); - - // TODO - // Instance->Initialize(); + + // Instance->Initialize(Mesh->GetRelativeLocation()); } } - + if (!Weapons.IsEmpty()) { SetWeapon(CurrentWeaponIndex); } } -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); @@ -41,33 +45,46 @@ 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) { if (Index < 0 || Index >= Weapons.Num()) { @@ -79,8 +96,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 55bf134..4027c1b 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; class ALMAmmo; @@ -32,10 +33,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/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/LMBazoucorn.h b/Source/LegumeMix/Public/Weapon/LMBazoucorn.h index 6d413c1..f869717 100644 --- a/Source/LegumeMix/Public/Weapon/LMBazoucorn.h +++ b/Source/LegumeMix/Public/Weapon/LMBazoucorn.h @@ -13,4 +13,5 @@ UCLASS(BlueprintType, Blueprintable) class LEGUMEMIX_API UBazoucorn : public ULMWeapon { GENERATED_BODY() + virtual void Fire() override; }; diff --git a/Source/LegumeMix/Public/Weapon/LMRadivolver.h b/Source/LegumeMix/Public/Weapon/LMRadivolver.h index 3261c68..b8879f6 100644 --- a/Source/LegumeMix/Public/Weapon/LMRadivolver.h +++ b/Source/LegumeMix/Public/Weapon/LMRadivolver.h @@ -13,4 +13,5 @@ UCLASS(BlueprintType, Blueprintable) class LEGUMEMIX_API ULMRadivolver : public ULMWeapon { GENERATED_BODY() + virtual void Fire() override; }; diff --git a/Source/LegumeMix/Public/Weapon/LMWeapon.h b/Source/LegumeMix/Public/Weapon/LMWeapon.h index d9c2e60..6e473b0 100644 --- a/Source/LegumeMix/Public/Weapon/LMWeapon.h +++ b/Source/LegumeMix/Public/Weapon/LMWeapon.h @@ -26,7 +26,7 @@ public: void Initialize(); - void Fire(); + virtual void Fire(); UFUNCTION(BlueprintCallable) void Reload(); //Reload current clip to max ammo in clip diff --git a/Source/LegumeMix/Public/Weapon/LMWeaponDataStructure.h b/Source/LegumeMix/Public/Weapon/LMWeaponDataStructure.h index df020c7..033939a 100644 --- a/Source/LegumeMix/Public/Weapon/LMWeaponDataStructure.h +++ b/Source/LegumeMix/Public/Weapon/LMWeaponDataStructure.h @@ -15,7 +15,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) EAmmoType 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..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,13 +31,16 @@ 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: virtual void BeginPlay() override;