Populate list view with starter weapons
This commit is contained in:
		
							parent
							
								
									4ff8d8eca3
								
							
						
					
					
						commit
						cb8ca1606a
					
				
							
								
								
									
										
											BIN
										
									
								
								Content/Weapons/FireWand/BP_FireWandWeapon.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/Weapons/FireWand/BP_FireWandWeapon.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Content/Widgets/LevelUp/BP_UpgradeButtonTemplate.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/Widgets/LevelUp/BP_UpgradeButtonTemplate.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Content/Widgets/MainMenu/BP_SelectWeaponWidget.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/Widgets/MainMenu/BP_SelectWeaponWidget.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Content/Widgets/MainMenu/BP_StarterButtonWIdget.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/Widgets/MainMenu/BP_StarterButtonWIdget.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -4,7 +4,10 @@ | ||||
| #include "SelectWeaponWidget.h" | ||||
| 
 | ||||
| #include "MainMenuWidget.h" | ||||
| #include "StarterWeaponButtonDataObject.h" | ||||
| #include "UpgradeButtonDataObject.h" | ||||
| #include "Components/Button.h" | ||||
| #include "Components/ListView.h" | ||||
| #include "Kismet/GameplayStatics.h" | ||||
| 
 | ||||
| void USelectWeaponWidget::NativeConstruct() | ||||
| @ -15,6 +18,17 @@ void USelectWeaponWidget::NativeConstruct() | ||||
| 	{ | ||||
| 		BackButton->OnClicked.AddUniqueDynamic(this, &USelectWeaponWidget::BackButtonClicked); | ||||
| 	} | ||||
| 
 | ||||
| 	if (UpgradesListView) | ||||
| 	{ | ||||
| 		// Get a list of weapons that the player owns that can be upgraded
 | ||||
| 		for (TSubclassOf<AWeapon> weapon : starterWeapons) | ||||
| 		{ | ||||
| 			UStarterWeaponButtonDataObject* Temp = NewObject<UStarterWeaponButtonDataObject>(this); | ||||
| 			Temp->SetData(weapon, this); | ||||
| 			UpgradesListView->AddItem(Temp); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void USelectWeaponWidget::BackButtonClicked() | ||||
|  | ||||
| @ -7,6 +7,7 @@ | ||||
| #include "SelectWeaponWidget.generated.h" | ||||
| 
 | ||||
| 
 | ||||
| class AWeapon; | ||||
| class UListView; | ||||
| class UButton; | ||||
| /**
 | ||||
| @ -24,6 +25,9 @@ public: | ||||
| 	UPROPERTY(BlueprintReadWrite, meta=(BindWidget)) | ||||
| 	UListView* UpgradesListView; | ||||
| 	 | ||||
| 	UPROPERTY(EditDefaultsOnly) | ||||
| 	TArray<TSubclassOf<AWeapon>> starterWeapons; | ||||
| 
 | ||||
| 	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) | ||||
| 	TSubclassOf<class UUserWidget> PreviousWidget; | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										37
									
								
								Source/vampires/Widgets/StarterWeaponButtonDataObject.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								Source/vampires/Widgets/StarterWeaponButtonDataObject.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,37 @@ | ||||
| // Louis Hobbs | 2024-2025
 | ||||
| 
 | ||||
| 
 | ||||
| #include "StarterWeaponButtonDataObject.h" | ||||
| 
 | ||||
| #include "vampires/Weapon.h" | ||||
| 
 | ||||
| void UStarterWeaponButtonDataObject::SetData(AWeapon* Weapon, UUserWidget* parent) | ||||
| { | ||||
| 	WeaponName = Weapon->Name; | ||||
| 	Description = Weapon->UpgradeDescriptions[Weapon->CurrentLevel]; | ||||
| 	WeaponIcon = Weapon->Icon; | ||||
| 	WeaponInstance = Weapon; | ||||
| 	Parent = parent; | ||||
| } | ||||
| 
 | ||||
| void UStarterWeaponButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent) | ||||
| { | ||||
| 	AWeapon* temp = NewObject<AWeapon>(this, Weapon); | ||||
| 	if (temp) | ||||
| 	{ | ||||
| 		WeaponName = temp->Name; | ||||
| 		Description = temp->Description; | ||||
| 		WeaponIcon = temp->Icon; | ||||
| 		WeaponTemplate = Weapon; | ||||
| 		Parent = parent; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void UStarterWeaponButtonDataObject::SetData(FText weaponName, FText description, TObjectPtr<UTexture2D> weaponIcon, | ||||
| 	UUserWidget* parent) | ||||
| { | ||||
| 	WeaponName = weaponName; | ||||
| 	Description = description; | ||||
| 	WeaponIcon = weaponIcon; | ||||
| 	Parent = parent; | ||||
| } | ||||
							
								
								
									
										39
									
								
								Source/vampires/Widgets/StarterWeaponButtonDataObject.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								Source/vampires/Widgets/StarterWeaponButtonDataObject.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,39 @@ | ||||
| // Louis Hobbs | 2024-2025
 | ||||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| #include "CoreMinimal.h" | ||||
| #include "UObject/Object.h" | ||||
| #include "StarterWeaponButtonDataObject.generated.h" | ||||
| 
 | ||||
| class AWeapon; | ||||
| /**
 | ||||
|  *  | ||||
|  */ | ||||
| UCLASS() | ||||
| class VAMPIRES_API UStarterWeaponButtonDataObject : public UObject | ||||
| { | ||||
| 	GENERATED_BODY() | ||||
| public: | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite) | ||||
| 	FText WeaponName; | ||||
| 
 | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite) | ||||
| 	FText Description; | ||||
| 
 | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite) | ||||
| 	TObjectPtr<UTexture2D> WeaponIcon; | ||||
| 
 | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite) | ||||
| 	TSubclassOf<AWeapon> WeaponTemplate; | ||||
| 
 | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite) | ||||
| 	TObjectPtr<AWeapon> WeaponInstance; | ||||
| 
 | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite) | ||||
| 	TObjectPtr<UUserWidget> Parent; | ||||
| 
 | ||||
| 	void SetData(AWeapon* Weapon, UUserWidget* parent); | ||||
| 	void SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent); | ||||
| 	void SetData(FText weaponName, FText description, TObjectPtr<UTexture2D> weaponIcon, UUserWidget* parent); | ||||
| }; | ||||
							
								
								
									
										37
									
								
								Source/vampires/Widgets/StarterWeaponButtonWidget.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								Source/vampires/Widgets/StarterWeaponButtonWidget.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,37 @@ | ||||
| // Louis Hobbs | 2024-2025
 | ||||
| 
 | ||||
| 
 | ||||
| #include "StarterWeaponButtonWidget.h" | ||||
| 
 | ||||
| #include "StarterWeaponButtonDataObject.h" | ||||
| #include "Components/Button.h" | ||||
| #include "Components/Image.h" | ||||
| #include "Components/TextBlock.h" | ||||
| 
 | ||||
| void UStarterWeaponButtonWidget::NativeConstruct() | ||||
| { | ||||
| 	Super::NativeConstruct(); | ||||
| } | ||||
| 
 | ||||
| void UStarterWeaponButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject) | ||||
| { | ||||
| 	UStarterWeaponButtonDataObject* Item = Cast<UStarterWeaponButtonDataObject>(ListItemObject); | ||||
| 	 | ||||
| 	if (Item) | ||||
| 	{ | ||||
| 		WeaponNameTextBlock->SetText(Item->WeaponName); | ||||
| 		DescriptionTextBlock->SetText(Item->Description); | ||||
| 		WeaponIcon->SetBrushFromTexture(Item->WeaponIcon); | ||||
| 		Parent = Item->Parent; | ||||
| 		WeaponTemplate = Item->WeaponTemplate; | ||||
| 
 | ||||
| 		if (Body) | ||||
| 		{ | ||||
| 			Body->OnClicked.AddUniqueDynamic(this, &UStarterWeaponButtonWidget::OnClicked); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void UStarterWeaponButtonWidget::OnClicked() | ||||
| { | ||||
| } | ||||
							
								
								
									
										49
									
								
								Source/vampires/Widgets/StarterWeaponButtonWidget.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								Source/vampires/Widgets/StarterWeaponButtonWidget.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,49 @@ | ||||
| // Louis Hobbs | 2024-2025
 | ||||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| #include "CoreMinimal.h" | ||||
| #include "Blueprint/IUserObjectListEntry.h" | ||||
| #include "Blueprint/UserWidget.h" | ||||
| #include "StarterWeaponButtonWidget.generated.h" | ||||
| 
 | ||||
| class AWeapon; | ||||
| class UTextBlock; | ||||
| class UImage; | ||||
| class UButton; | ||||
| /**
 | ||||
|  *  | ||||
|  */ | ||||
| UCLASS() | ||||
| class VAMPIRES_API UStarterWeaponButtonWidget : public UUserWidget, public IUserObjectListEntry | ||||
| { | ||||
| 	GENERATED_BODY() | ||||
| 
 | ||||
| public: | ||||
| 	UPROPERTY(EditDefaultsOnly, meta=(BindWidget)) | ||||
| 	TObjectPtr<UButton> Body; | ||||
| 
 | ||||
| 	UPROPERTY(EditDefaultsOnly, meta=(BindWidget)) | ||||
| 	TObjectPtr<UImage> WeaponIcon; | ||||
| 
 | ||||
| 	UPROPERTY(EditDefaultsOnly, meta=(BindWidget)) | ||||
| 	TObjectPtr<UTextBlock> WeaponNameTextBlock; | ||||
| 
 | ||||
| 	UPROPERTY(EditDefaultsOnly, meta=(BindWidget)) | ||||
| 	TObjectPtr<UTextBlock> DescriptionTextBlock; | ||||
| 
 | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite) | ||||
| 	TSubclassOf<AWeapon> WeaponTemplate; | ||||
| 
 | ||||
| 	UPROPERTY() | ||||
| 	TObjectPtr<UUserWidget> Parent; | ||||
| 
 | ||||
| protected: | ||||
| 	virtual void NativeConstruct() override; | ||||
| 
 | ||||
| 	virtual void NativeOnListItemObjectSet(UObject* ListItemObject) override; | ||||
| 
 | ||||
| private: | ||||
| 	UFUNCTION() | ||||
| 	virtual void OnClicked(); | ||||
| }; | ||||
| @ -64,6 +64,7 @@ public: | ||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite) | ||||
| 	TObjectPtr<AWeapon> WeaponInstance; | ||||
| 
 | ||||
| 	UPROPERTY() | ||||
| 	TObjectPtr<UUserWidget> Parent; | ||||
| 
 | ||||
| private: | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user