Add basic weapon selection functionality
This commit is contained in:
		
							parent
							
								
									4c727e4a15
								
							
						
					
					
						commit
						1854d9c86b
					
				| @ -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 | ||||
|  | ||||
							
								
								
									
										
											BIN
										
									
								
								Content/Gamemode/BP_VampireGameInstance.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/Gamemode/BP_VampireGameInstance.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Content/Levels/MainMenu/MainMenu.umap
									 (Stored with Git LFS)
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/Levels/MainMenu/MainMenu.umap
									 (Stored with Git LFS)
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Content/Player/BP_PlayerCharacter.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/Player/BP_PlayerCharacter.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -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<AWeapon> StarterWeapon; | ||||
| 	 | ||||
| 	UPROPERTY(EditDefaultsOnly) | ||||
| 	TSoftObjectPtr<UWorld> MainMenuWorld; | ||||
| 
 | ||||
| 	UPROPERTY(EditDefaultsOnly) | ||||
| 	TSoftObjectPtr<UWorld> GameWorld; | ||||
| }; | ||||
|  | ||||
| @ -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<UVampireGameInstance>(GetGameInstance())) | ||||
| 	{ | ||||
| 		UWeaponInventoryComponent* weaponInventoryComponent = aPawn->GetComponentByClass< | ||||
| 			UWeaponInventoryComponent>(); | ||||
| 		 | ||||
| 		if (weaponInventoryComponent && gameInstance->StarterWeapon) | ||||
| 		{			 | ||||
| 			weaponInventoryComponent->initialInventory.Add(gameInstance->StarterWeapon); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void AVampirePlayerController::OnUnPossess() | ||||
|  | ||||
| @ -28,10 +28,13 @@ void UWeaponInventoryComponent::InitializeInventory() | ||||
| 	inventory.Empty(); | ||||
| 
 | ||||
| 	for (TSubclassOf<AWeapon> weapon : initialInventory) | ||||
| 	{ | ||||
| 		if (IsValid(weapon)) | ||||
| 		{ | ||||
| 			AddWeaponToInventory(weapon); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void UWeaponInventoryComponent::AddWeaponToInventory(TSubclassOf<AWeapon> Weapon) | ||||
| { | ||||
| @ -39,7 +42,6 @@ void UWeaponInventoryComponent::AddWeaponToInventory(TSubclassOf<AWeapon> Weapon | ||||
| 	SpawnParameters.Owner = GetOwner(); | ||||
| 	 | ||||
| 	AWeapon* weapon = GetWorld()->SpawnActor<AWeapon>(Weapon, GetOwner()->GetTransform(), SpawnParameters); | ||||
| 
 | ||||
| 	if (weapon->FollowPlayer) | ||||
| 	{ | ||||
| 		weapon->AttachToActor(GetOwner(), FAttachmentTransformRules::KeepRelativeTransform); | ||||
| @ -50,6 +52,7 @@ void UWeaponInventoryComponent::AddWeaponToInventory(TSubclassOf<AWeapon> Weapon | ||||
| 	} | ||||
| 	 | ||||
| 	inventory.Add(weapon); | ||||
| 	obtainableWeapons.Remove(Weapon); | ||||
| } | ||||
| 
 | ||||
| TArray<AWeapon*> UWeaponInventoryComponent::GetInventory() | ||||
|  | ||||
| @ -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<USphereComponent>(TEXT("Sphere Component")); | ||||
| 	SphereComponent->SetupAttachment(RootComponent); | ||||
| 	SetRootComponent(SphereComponent); | ||||
| 	SphereComponent->SetSphereRadius(150.0f); | ||||
| 	SphereComponent->SetCollisionProfileName(TEXT("Weapon")); | ||||
| 	 | ||||
|  | ||||
| @ -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<UVampireGameInstance>(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); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user