diff --git a/Config/DefaultEngine.ini b/Config/DefaultEngine.ini index bc0d674..98075a1 100644 --- a/Config/DefaultEngine.ini +++ b/Config/DefaultEngine.ini @@ -1,10 +1,10 @@ [/Script/EngineSettings.GameMapsSettings] -GameDefaultMap=/Game/Levels/Level.Level +GameDefaultMap=/Game/Levels/MainMenu/MainMenu.MainMenu GlobalDefaultGameMode=/Game/Gamemode/BP_DefaultGamemode.BP_DefaultGamemode_C -GameInstanceClass=/Script/vampires.VampireGameInstance -EditorStartupMap=/Game/Levels/Level.Level +GameInstanceClass=/Game/Gamemode/BP_VampireGameInstance.BP_VampireGameInstance_C +EditorStartupMap=/Game/Levels/MainMenu/MainMenu.MainMenu [/Script/WindowsTargetPlatform.WindowsTargetSettings] DefaultGraphicsRHI=DefaultGraphicsRHI_DX12 diff --git a/Content/Gamemode/BP_VampireGameInstance.uasset b/Content/Gamemode/BP_VampireGameInstance.uasset new file mode 100644 index 0000000..2b3dcec --- /dev/null +++ b/Content/Gamemode/BP_VampireGameInstance.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:868658f411a3523a9c120402f6a6c6671a28243399a06d33e614451af872042f +size 6160 diff --git a/Content/Levels/MainMenu/MainMenu.umap b/Content/Levels/MainMenu/MainMenu.umap index f32dbfb..9073b56 100644 --- a/Content/Levels/MainMenu/MainMenu.umap +++ b/Content/Levels/MainMenu/MainMenu.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1e39c0163e114af92ff16c96d5153b98c16c06f74e55f8c41b72c797dfe55ae5 -size 39988 +oid sha256:ce8d40b08b68d129bbbde8ac4fd8db652c26e4760492ffb875f7ab9ff1177631 +size 39425 diff --git a/Content/Player/BP_PlayerCharacter.uasset b/Content/Player/BP_PlayerCharacter.uasset index f1f887d..a0dca8e 100644 --- a/Content/Player/BP_PlayerCharacter.uasset +++ b/Content/Player/BP_PlayerCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:aba63d3d6c988550f47f719197bf9477c0efe6af4769d56c3cf7048a79f2b831 -size 57374 +oid sha256:6b39c5bc00aaf3367844a18035c0f953b1d689f81dba5e19f088314db6ec3e0f +size 58854 diff --git a/Source/vampires/VampireGameInstance.h b/Source/vampires/VampireGameInstance.h index 99fb4e8..15116b9 100644 --- a/Source/vampires/VampireGameInstance.h +++ b/Source/vampires/VampireGameInstance.h @@ -1,4 +1,4 @@ -// Louis Hobbs | 2024-2025 + // Louis Hobbs | 2024-2025 #pragma once @@ -6,12 +6,23 @@ #include "Engine/GameInstance.h" #include "VampireGameInstance.generated.h" +class AWeapon; /** * */ + UCLASS() class VAMPIRES_API UVampireGameInstance : public UGameInstance { GENERATED_BODY() +public: + + UPROPERTY() + TSubclassOf StarterWeapon; + UPROPERTY(EditDefaultsOnly) + TSoftObjectPtr MainMenuWorld; + + UPROPERTY(EditDefaultsOnly) + TSoftObjectPtr GameWorld; }; diff --git a/Source/vampires/VampirePlayerController.cpp b/Source/vampires/VampirePlayerController.cpp index f814d8b..fc12551 100644 --- a/Source/vampires/VampirePlayerController.cpp +++ b/Source/vampires/VampirePlayerController.cpp @@ -8,7 +8,10 @@ #include "EXPComponent.h" #include "GoldComponent.h" #include "Inputable.h" +#include "VampireGameInstance.h" #include "VampireGameMode.h" +#include "Weapon.h" +#include "WeaponInventoryComponent.h" #include "Blueprint/UserWidget.h" #include "Blueprint/WidgetBlueprintLibrary.h" #include "Kismet/GameplayStatics.h" @@ -58,6 +61,17 @@ void AVampirePlayerController::OnPossess(APawn* aPawn) currentPlayerHUD->AddToViewport(); } } + + if (UVampireGameInstance* gameInstance = Cast(GetGameInstance())) + { + UWeaponInventoryComponent* weaponInventoryComponent = aPawn->GetComponentByClass< + UWeaponInventoryComponent>(); + + if (weaponInventoryComponent && gameInstance->StarterWeapon) + { + weaponInventoryComponent->initialInventory.Add(gameInstance->StarterWeapon); + } + } } void AVampirePlayerController::OnUnPossess() diff --git a/Source/vampires/WeaponInventoryComponent.cpp b/Source/vampires/WeaponInventoryComponent.cpp index 22cf316..211a0fe 100644 --- a/Source/vampires/WeaponInventoryComponent.cpp +++ b/Source/vampires/WeaponInventoryComponent.cpp @@ -29,7 +29,10 @@ void UWeaponInventoryComponent::InitializeInventory() for (TSubclassOf weapon : initialInventory) { - AddWeaponToInventory(weapon); + if (IsValid(weapon)) + { + AddWeaponToInventory(weapon); + } } } @@ -39,7 +42,6 @@ void UWeaponInventoryComponent::AddWeaponToInventory(TSubclassOf Weapon SpawnParameters.Owner = GetOwner(); AWeapon* weapon = GetWorld()->SpawnActor(Weapon, GetOwner()->GetTransform(), SpawnParameters); - if (weapon->FollowPlayer) { weapon->AttachToActor(GetOwner(), FAttachmentTransformRules::KeepRelativeTransform); @@ -50,6 +52,7 @@ void UWeaponInventoryComponent::AddWeaponToInventory(TSubclassOf Weapon } inventory.Add(weapon); + obtainableWeapons.Remove(Weapon); } TArray UWeaponInventoryComponent::GetInventory() diff --git a/Source/vampires/Weapons/GarlicWeapon.cpp b/Source/vampires/Weapons/GarlicWeapon.cpp index f372538..49207a2 100644 --- a/Source/vampires/Weapons/GarlicWeapon.cpp +++ b/Source/vampires/Weapons/GarlicWeapon.cpp @@ -2,6 +2,8 @@ #include "GarlicWeapon.h" + +#include "MovieSceneTracksComponentTypes.h" #include "Components/SphereComponent.h" #include "vampires/EnemyCharacter.h" #include "vampires/HealthComponent.h" @@ -9,7 +11,7 @@ AGarlicWeapon::AGarlicWeapon() { SphereComponent = CreateDefaultSubobject(TEXT("Sphere Component")); - SphereComponent->SetupAttachment(RootComponent); + SetRootComponent(SphereComponent); SphereComponent->SetSphereRadius(150.0f); SphereComponent->SetCollisionProfileName(TEXT("Weapon")); diff --git a/Source/vampires/Widgets/StarterWeaponButtonWidget.cpp b/Source/vampires/Widgets/StarterWeaponButtonWidget.cpp index 99e2c22..c00dab3 100644 --- a/Source/vampires/Widgets/StarterWeaponButtonWidget.cpp +++ b/Source/vampires/Widgets/StarterWeaponButtonWidget.cpp @@ -4,9 +4,12 @@ #include "StarterWeaponButtonWidget.h" #include "StarterWeaponButtonDataObject.h" +#include "Blueprint/WidgetBlueprintLibrary.h" #include "Components/Button.h" #include "Components/Image.h" #include "Components/TextBlock.h" +#include "Kismet/GameplayStatics.h" +#include "vampires/VampireGameInstance.h" void UStarterWeaponButtonWidget::NativeConstruct() { @@ -34,4 +37,20 @@ void UStarterWeaponButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObje void UStarterWeaponButtonWidget::OnClicked() { + if (UVampireGameInstance* gameInstance = Cast(GetGameInstance())) + { + gameInstance->StarterWeapon = WeaponTemplate; + + if (!gameInstance->GameWorld.IsNull()) + { + UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), gameInstance->GameWorld); + + if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0)) + { + PlayerController->bShowMouseCursor = false; + UWidgetBlueprintLibrary::SetInputMode_GameOnly(PlayerController); + } + SetIsFocusable(false); + } + } }