Add Health and Gold Options to Level Up menu when there are no upgrades left
This commit is contained in:
parent
2d11a5c5bc
commit
804597fbff
@ -8,7 +8,6 @@
|
|||||||
#include "Components/ListView.h"
|
#include "Components/ListView.h"
|
||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
#include "UpgradeButtonDataObject.h"
|
#include "UpgradeButtonDataObject.h"
|
||||||
#include "EntitySystem/MovieSceneEntitySystemRunner.h"
|
|
||||||
#include "GameFramework/Character.h"
|
#include "GameFramework/Character.h"
|
||||||
#include "vampires/VampireCharacter.h"
|
#include "vampires/VampireCharacter.h"
|
||||||
#include "vampires/Weapon.h"
|
#include "vampires/Weapon.h"
|
||||||
@ -25,11 +24,17 @@ void ULevelUpWidget::NativeConstruct()
|
|||||||
|
|
||||||
if (UpgradesListView)
|
if (UpgradesListView)
|
||||||
{
|
{
|
||||||
ACharacter* Player = Cast<AVampireCharacter>( UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
|
ACharacter* Player = Cast<AVampireCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
|
||||||
if (!Player) return;
|
if (!Player)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
UWeaponInventoryComponent* InventoryComponent = Player->GetComponentByClass<UWeaponInventoryComponent>();
|
UWeaponInventoryComponent* InventoryComponent = Player->GetComponentByClass<UWeaponInventoryComponent>();
|
||||||
if (!InventoryComponent) return;
|
if (!InventoryComponent)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
TArray<AWeapon*> Inventory = InventoryComponent->GetInventory();
|
TArray<AWeapon*> Inventory = InventoryComponent->GetInventory();
|
||||||
TArray<UUpgradeButtonDataObject*> upgradeItems;
|
TArray<UUpgradeButtonDataObject*> upgradeItems;
|
||||||
@ -46,6 +51,23 @@ void ULevelUpWidget::NativeConstruct()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (upgradeItems.Num() == 0)
|
||||||
|
{
|
||||||
|
UUpgradeButtonDataObject* tempHealth = NewObject<UUpgradeButtonDataObject>(this);
|
||||||
|
tempHealth->SetData(FText::FromString("Health"),
|
||||||
|
FText::FromString("Recover 10% of your health"),
|
||||||
|
nullptr,
|
||||||
|
this);
|
||||||
|
upgradeItems.Add(tempHealth);
|
||||||
|
|
||||||
|
UUpgradeButtonDataObject* tempGold = NewObject<UUpgradeButtonDataObject>(this);
|
||||||
|
tempGold->SetData(FText::FromString("Gold"),
|
||||||
|
FText::FromString("Gain 10 gold"),
|
||||||
|
nullptr,
|
||||||
|
this);
|
||||||
|
upgradeItems.Add(tempGold);
|
||||||
|
}
|
||||||
|
|
||||||
UpgradesListView->SetListItems(upgradeItems);
|
UpgradesListView->SetListItems(upgradeItems);
|
||||||
}
|
}
|
||||||
SetIsFocusable(true);
|
SetIsFocusable(true);
|
||||||
|
@ -26,3 +26,12 @@ void UUpgradeButtonDataObject::SetData(TSubclassOf<AWeapon> Weapon, UUserWidget*
|
|||||||
Parent = parent;
|
Parent = parent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UUpgradeButtonDataObject::SetData(FText weaponName, FText description, TObjectPtr<UTexture2D> weaponIcon,
|
||||||
|
UUserWidget* parent)
|
||||||
|
{
|
||||||
|
WeaponName = weaponName;
|
||||||
|
Description = description;
|
||||||
|
WeaponIcon = weaponIcon;
|
||||||
|
Parent = parent;
|
||||||
|
}
|
||||||
|
@ -14,17 +14,17 @@ UCLASS(BlueprintType)
|
|||||||
class VAMPIRES_API UUpgradeButtonDataObject : public UObject
|
class VAMPIRES_API UUpgradeButtonDataObject : public UObject
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
FText WeaponName;
|
FText WeaponName;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
FText Description;
|
FText Description;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
TObjectPtr<UTexture2D> WeaponIcon;
|
TObjectPtr<UTexture2D> WeaponIcon;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
TSubclassOf<AWeapon> WeaponTemplate;
|
TSubclassOf<AWeapon> WeaponTemplate;
|
||||||
|
|
||||||
@ -36,4 +36,5 @@ public:
|
|||||||
|
|
||||||
void SetData(AWeapon* Weapon, UUserWidget* parent);
|
void SetData(AWeapon* Weapon, UUserWidget* parent);
|
||||||
void SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent);
|
void SetData(TSubclassOf<AWeapon> Weapon, UUserWidget* parent);
|
||||||
|
void SetData(FText weaponName, FText description, TObjectPtr<UTexture2D> weaponIcon, UUserWidget* parent);
|
||||||
};
|
};
|
||||||
|
@ -9,9 +9,10 @@
|
|||||||
#include "Components/Image.h"
|
#include "Components/Image.h"
|
||||||
#include "Components/TextBlock.h"
|
#include "Components/TextBlock.h"
|
||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
#include "Kismet/KismetSystemLibrary.h"
|
|
||||||
#include "vampires/Weapon.h"
|
#include "vampires/Weapon.h"
|
||||||
#include "UObject/UObjectBase.h"
|
#include "UObject/UObjectBase.h"
|
||||||
|
#include "vampires/GoldComponent.h"
|
||||||
|
#include "vampires/HealthComponent.h"
|
||||||
|
|
||||||
void UUpgradeButtonWidget::NativeConstruct()
|
void UUpgradeButtonWidget::NativeConstruct()
|
||||||
{
|
{
|
||||||
@ -31,14 +32,22 @@ void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
|
|||||||
|
|
||||||
if (Item->WeaponInstance != nullptr)
|
if (Item->WeaponInstance != nullptr)
|
||||||
{
|
{
|
||||||
UpgradeType = EUpgradeType::Upgrade;
|
UpgradeType = Upgrade;
|
||||||
WeaponInstance = Item->WeaponInstance;
|
WeaponInstance = Item->WeaponInstance;
|
||||||
}
|
}
|
||||||
else if (Item->WeaponTemplate != nullptr)
|
else if (Item->WeaponTemplate != nullptr)
|
||||||
{
|
{
|
||||||
UpgradeType = EUpgradeType::NewWeapon;
|
UpgradeType = NewWeapon;
|
||||||
WeaponTemplate = Item->WeaponTemplate;
|
WeaponTemplate = Item->WeaponTemplate;
|
||||||
}
|
}
|
||||||
|
else if (Item->WeaponName.ToString() == "Health")
|
||||||
|
{
|
||||||
|
UpgradeType = Health;
|
||||||
|
}
|
||||||
|
else if (Item->WeaponName.ToString() == "Gold")
|
||||||
|
{
|
||||||
|
UpgradeType = Gold;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (Body)
|
if (Body)
|
||||||
@ -46,28 +55,56 @@ void UUpgradeButtonWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
|
|||||||
Body->OnClicked.AddUniqueDynamic(this, &UUpgradeButtonWidget::OnClicked);
|
Body->OnClicked.AddUniqueDynamic(this, &UUpgradeButtonWidget::OnClicked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch (UpgradeType) {
|
switch (UpgradeType)
|
||||||
|
{
|
||||||
case Upgrade:
|
case Upgrade:
|
||||||
UpgradeTypeIcon->SetBrushFromTexture(UpgradeIcon);
|
UpgradeTypeIcon->SetBrushFromTexture(UpgradeIcon);
|
||||||
break;
|
break;
|
||||||
case NewWeapon:
|
case NewWeapon:
|
||||||
UpgradeTypeIcon->SetBrushFromTexture(NewWeaponIcon);
|
UpgradeTypeIcon->SetBrushFromTexture(NewWeaponIcon);
|
||||||
break;
|
break;
|
||||||
|
case Health:
|
||||||
|
UpgradeTypeIcon->SetBrushFromTexture(HealthIcon);
|
||||||
|
break;
|
||||||
|
case Gold:
|
||||||
|
UpgradeTypeIcon->SetBrushFromTexture(GoldIcon);
|
||||||
|
break;
|
||||||
default: ;
|
default: ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UUpgradeButtonWidget::OnClicked()
|
void UUpgradeButtonWidget::OnClicked()
|
||||||
{
|
{
|
||||||
switch (UpgradeType) {
|
APlayerController* playerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
|
||||||
|
|
||||||
|
switch (UpgradeType)
|
||||||
|
{
|
||||||
case Upgrade:
|
case Upgrade:
|
||||||
WeaponInstance->UpgradeWeapon();
|
WeaponInstance->UpgradeWeapon();
|
||||||
break;
|
break;
|
||||||
case NewWeapon:
|
case NewWeapon:
|
||||||
// TODO: Spawn weapon
|
// TODO: Spawn weapon
|
||||||
break;
|
break;
|
||||||
|
case Health:
|
||||||
|
if (playerController)
|
||||||
|
{
|
||||||
|
if (UHealthComponent* healthComponent = playerController->GetComponentByClass<UHealthComponent>())
|
||||||
|
{
|
||||||
|
healthComponent->RecoverHealth(healthComponent->GetMaxHealth() / 10.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Gold:
|
||||||
|
if (playerController)
|
||||||
|
{
|
||||||
|
if (UGoldComponent* goldComponent = playerController->GetComponentByClass<UGoldComponent>())
|
||||||
|
{
|
||||||
|
goldComponent->IncrementGold(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
default: ;
|
default: ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +112,7 @@ void UUpgradeButtonWidget::OnClicked()
|
|||||||
{
|
{
|
||||||
Parent->RemoveFromParent();
|
Parent->RemoveFromParent();
|
||||||
|
|
||||||
if (APlayerController* playerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
|
if (playerController)
|
||||||
{
|
{
|
||||||
UWidgetBlueprintLibrary::SetInputMode_GameOnly(playerController);
|
UWidgetBlueprintLibrary::SetInputMode_GameOnly(playerController);
|
||||||
playerController->bShowMouseCursor = false;
|
playerController->bShowMouseCursor = false;
|
||||||
|
@ -13,7 +13,9 @@ UENUM(BlueprintType)
|
|||||||
enum EUpgradeType
|
enum EUpgradeType
|
||||||
{
|
{
|
||||||
Upgrade,
|
Upgrade,
|
||||||
NewWeapon
|
NewWeapon,
|
||||||
|
Health,
|
||||||
|
Gold
|
||||||
};
|
};
|
||||||
|
|
||||||
class UTextBlock;
|
class UTextBlock;
|
||||||
@ -34,7 +36,7 @@ public:
|
|||||||
|
|
||||||
UPROPERTY(EditDefaultsOnly, meta=(BindWidget))
|
UPROPERTY(EditDefaultsOnly, meta=(BindWidget))
|
||||||
TObjectPtr<UImage> WeaponIcon;
|
TObjectPtr<UImage> WeaponIcon;
|
||||||
|
|
||||||
UPROPERTY(EditDefaultsOnly, meta=(BindWidget))
|
UPROPERTY(EditDefaultsOnly, meta=(BindWidget))
|
||||||
TObjectPtr<UTextBlock> WeaponNameTextBlock;
|
TObjectPtr<UTextBlock> WeaponNameTextBlock;
|
||||||
|
|
||||||
@ -47,6 +49,12 @@ public:
|
|||||||
UPROPERTY(EditDefaultsOnly)
|
UPROPERTY(EditDefaultsOnly)
|
||||||
TObjectPtr<UTexture2D> NewWeaponIcon;
|
TObjectPtr<UTexture2D> NewWeaponIcon;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly)
|
||||||
|
TObjectPtr<UTexture2D> HealthIcon;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly)
|
||||||
|
TObjectPtr<UTexture2D> GoldIcon;
|
||||||
|
|
||||||
UPROPERTY(EditDefaultsOnly)
|
UPROPERTY(EditDefaultsOnly)
|
||||||
TEnumAsByte<EUpgradeType> UpgradeType;
|
TEnumAsByte<EUpgradeType> UpgradeType;
|
||||||
|
|
||||||
@ -61,12 +69,12 @@ public:
|
|||||||
private:
|
private:
|
||||||
UPROPERTY(meta=(BindWidget))
|
UPROPERTY(meta=(BindWidget))
|
||||||
UImage* UpgradeTypeIcon;
|
UImage* UpgradeTypeIcon;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void NativeConstruct() override;
|
virtual void NativeConstruct() override;
|
||||||
|
|
||||||
virtual void NativeOnListItemObjectSet(UObject* ListItemObject) override;
|
virtual void NativeOnListItemObjectSet(UObject* ListItemObject) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
virtual void OnClicked();
|
virtual void OnClicked();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user